@zayne-labs/ui-react 0.8.2 → 0.8.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.
|
@@ -227,7 +227,7 @@ function CarouselIndicatorGroup(props) {
|
|
|
227
227
|
{
|
|
228
228
|
"data-id": "Carousel Indicators",
|
|
229
229
|
className: cnMerge(
|
|
230
|
-
"absolute bottom-[25px] z-
|
|
230
|
+
"absolute bottom-[25px] z-[2] flex w-full items-center justify-center gap-[15px]",
|
|
231
231
|
className
|
|
232
232
|
)
|
|
233
233
|
},
|
|
@@ -243,12 +243,11 @@ function CarouselIndicator(props) {
|
|
|
243
243
|
return /* @__PURE__ */ React3.createElement("li", { className: cnMerge("inline-flex", classNames?.base) }, /* @__PURE__ */ React3.createElement(
|
|
244
244
|
"button",
|
|
245
245
|
{
|
|
246
|
-
"data-active": currentIndex === currentSlide,
|
|
247
246
|
type: "button",
|
|
248
247
|
onClick: () => goToSlide(currentIndex),
|
|
249
248
|
className: cnMerge(
|
|
250
249
|
"size-[6px] rounded-[50%]",
|
|
251
|
-
classNames?.
|
|
250
|
+
classNames?.base,
|
|
252
251
|
currentIndex === currentSlide && ["w-[35px] rounded-[5px]", classNames?.isActive]
|
|
253
252
|
)
|
|
254
253
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/carousel/carousel-store-context.tsx","../../../../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"],"names":["React","React2"],"mappings":";;;;;;;;;AASA,IAAM,CAAC,QAAA,EAAU,uBAAuB,CAAA,GAAI,oBAAoC,CAAA;AAAA,EAC/E,QAAU,EAAA,kBAAA;AAAA,EACV,IAAM,EAAA,sBAAA;AAAA,EACN,YAAc,EAAA;AACf,CAAC,CAAA;AAGD,IAAM,mBAAA,GAAsB,CAC3B,WACI,KAAA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,0BAAA;AAAA,QACA,UAAY,EAAA,MAAA;AAAA,QACZ,YAAiB,KAAA,YAAA,IAAgB,CAAC,wBAAA,EAA0B,YAAY,QAAQ;AAAA;AACjF;AAAA,GAEF,CAAA;AAEF;;;AC7OA,IAAA,sBAAA,GAAA;AAAA,QAAA,CAAA,sBAAA,EAAA;AAAA,EAAA,MAAA,EAAA,MAAA,cAAA;AAAA,EAAA,OAAA,EAAA,MAAA,eAAA;AAAA,EAAA,OAAA,EAAA,MAAA,eAAA;AAAA,EAAA,QAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,SAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,cAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,IAAA,EAAA,MAAA,YAAA;AAAA,EAAA,SAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\n\nimport { useConstant } from \"@zayne-labs/toolkit-react\";\nimport { createZustandContext } from \"@zayne-labs/toolkit-react/zustand\";\nimport type { PrettyOmit } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect } from \"react\";\nimport { create } from \"zustand\";\nimport type { CarouselProviderProps, CarouselStore, ImagesType } from \"./types\";\n\nconst [Provider, useCarouselStoreContext] = createZustandContext<CarouselStore>({\n\thookName: \"useCarouselStore\",\n\tname: \"CarouselStoreContext\",\n\tproviderName: \"CarouselContextProvider\",\n});\n\n// CarouselStore Creation\nconst createCarouselStore = <TImages extends ImagesType>(\n\tstoreValues: PrettyOmit<CarouselProviderProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = storeValues;\n\n\tconst useInitCarouselStore = create<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 useInitCarouselStore;\n};\n\nconst useCarousel = <TImages extends ImagesType>(\n\tprops: Omit<CarouselProviderProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = props;\n\n\tconst useInitCarouselStore = useConstant(() => createCarouselStore({ images, onSlideBtnClick }));\n\n\t// == To set images again when a page is mounted, preventing stale images from previous page\n\tuseEffect(() => {\n\t\tuseInitCarouselStore.setState({ images });\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- useInitCarouselStore is stable\n\t}, [images]);\n\n\treturn useInitCarouselStore;\n};\n\n// == Provider Component\nfunction CarouselContextProvider<TImages extends ImagesType>(props: CarouselProviderProps<TImages>) {\n\tconst { children, images, onSlideBtnClick } = props;\n\n\tconst useInitCarouselStore = useCarousel({ images, onSlideBtnClick });\n\n\treturn <Provider value={useInitCarouselStore}>{children}</Provider>;\n}\n\n// eslint-disable-next-line react-refresh/only-export-components -- It's fine\nexport { useCarouselStoreContext, CarouselContextProvider };\n","import * as React from \"react\";\n\nconst 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\nexport { ChevronLeftIcon };\n","import { useAnimationInterval, useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { useState } from \"react\";\nimport { useCarouselStoreContext } from \"./carousel-store-context\";\n\ntype CarouselOptions = {\n\tautoSlideInterval?: number;\n\thasAutoSlide?: boolean;\n\tshouldPauseOnHover?: boolean;\n};\n\nconst useCarouselOptions = (options: CarouselOptions = {}) => {\n\tconst { autoSlideInterval = 5000, hasAutoSlide = false, shouldPauseOnHover = false } = options;\n\n\tconst { goToNextSlide } = useCarouselStoreContext((state) => state.actions);\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: 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 * as React from \"react\";\n\nimport { getElementList } from \"@/components/common/for\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport type { MyCustomCss, PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { useCarouselStoreContext } from \"./carousel-store-context\";\nimport { ChevronLeftIcon } from \"./icons\";\nimport type {\n\tCarouselButtonsProps,\n\tCarouselContentProps,\n\tCarouselControlProps,\n\tCarouselIndicatorProps,\n\tCarouselWrapperProps,\n\tOtherCarouselProps,\n} from \"./types\";\nimport { useCarouselOptions } from \"./useCarouselOptions\";\n\n// TODO - Add dragging and swiping support\nexport function CarouselContent<TElement extends React.ElementType = \"article\">(\n\tprops: PolymorphicProps<TElement, CarouselContentProps>\n) {\n\tconst {\n\t\tas: HtmlElement = \"article\",\n\t\tautoSlideInterval,\n\t\tchildren,\n\t\tclassNames,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t} = props;\n\n\tconst { pauseAutoSlide, resumeAutoSlide } = useCarouselOptions({\n\t\tautoSlideInterval,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t});\n\n\t// FIXME - Prevent touch swipe on mobile using a cover element or allow swipe but it must update the state appriopriately\n\treturn (\n\t\t<HtmlElement\n\t\t\tdata-id=\"Carousel\"\n\t\t\tclassName={cnMerge(\"relative select-none\", classNames?.base)}\n\t\t\tonMouseEnter={pauseAutoSlide}\n\t\t\tonMouseLeave={resumeAutoSlide}\n\t\t>\n\t\t\t<div\n\t\t\t\tdata-id=\"Scroll Container\"\n\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\"flex size-full overflow-x-scroll [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n\t\t\t\t\tclassNames?.scrollContainer\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t</HtmlElement>\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\ttype=\"button\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"z-30 flex h-full w-fit items-center\",\n\t\t\t\tvariant === \"prev\" ? \"justify-start\" : \"justify-end\",\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<div className={cnMerge(\"absolute inset-0 flex justify-between\", classNames?.base)}>\n\t\t\t{icon?.iconType ? (\n\t\t\t\t<>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\t\ticon.iconType === \"nextIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon.icon}\n\t\t\t\t\t/>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\t\ticon.iconType === \"prevIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon.icon}\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: classNames?.iconContainer,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon?.prev}\n\t\t\t\t\t/>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: classNames?.iconContainer,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon?.next}\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n\nexport function CarouselItemGroup<TArrayItem>(props: CarouselWrapperProps<TArrayItem>) {\n\tconst { children, className, each, render } = props;\n\n\tconst [ItemList] = getElementList(\"base\");\n\tconst currentSlide = useCarouselStoreContext((state) => state.currentSlide);\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArrayItem[]));\n\n\treturn (\n\t\t<ul\n\t\t\tdata-id=\"Carousel Image Wrapper\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t`flex w-full shrink-0 snap-center [transform:translate3d(var(--translate-distance),0,0)]\n\t\t\t\t[transition:transform_800ms_ease]`,\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 MyCustomCss as MyCustomCss\n\t\t\t}\n\t\t>\n\t\t\t{typeof render === \"function\" ? (\n\t\t\t\t<ItemList each={images} render={render} />\n\t\t\t) : (\n\t\t\t\t<ItemList each={images}>{children}</ItemList>\n\t\t\t)}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselItem({ children, className, ...restOfProps }: OtherCarouselProps) {\n\treturn (\n\t\t<li\n\t\t\tclassName={cnMerge(\"flex w-full shrink-0 snap-center justify-center\", 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: PolymorphicProps<TElement, OtherCarouselProps>\n) {\n\tconst { as: HtmlElement = \"div\", children, className } = props;\n\n\treturn (\n\t\t<HtmlElement data-id=\"Carousel Caption\" className={cnMerge(\"absolute z-10\", className)}>\n\t\t\t{children}\n\t\t</HtmlElement>\n\t);\n}\n\nexport function CarouselIndicatorGroup<TArrayItem>(props: CarouselWrapperProps<TArrayItem>) {\n\tconst { children, className, each, render } = props;\n\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArrayItem[]));\n\tconst [IndicatorList] = getElementList(\"base\");\n\n\treturn (\n\t\t<ul\n\t\t\tdata-id=\"Carousel Indicators\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"absolute bottom-[25px] z-10 flex w-full items-center justify-center gap-[15px]\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t>\n\t\t\t{typeof render === \"function\" ? (\n\t\t\t\t<IndicatorList each={images} render={render} />\n\t\t\t) : (\n\t\t\t\t<IndicatorList each={images}>{children}</IndicatorList>\n\t\t\t)}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselIndicator(props: CarouselIndicatorProps) {\n\tconst { classNames, currentIndex } = props;\n\n\tconst {\n\t\tactions: { goToSlide },\n\t\tcurrentSlide,\n\t} = useCarouselStoreContext((state) => state);\n\n\treturn (\n\t\t<li className={cnMerge(\"inline-flex\", classNames?.base)}>\n\t\t\t<button\n\t\t\t\tdata-active={currentIndex === currentSlide}\n\t\t\t\ttype=\"button\"\n\t\t\t\tonClick={() => goToSlide(currentIndex)}\n\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\"size-[6px] rounded-[50%]\",\n\t\t\t\t\tclassNames?.button,\n\t\t\t\t\tcurrentIndex === currentSlide && [\"w-[35px] rounded-[5px]\", classNames?.isActive]\n\t\t\t\t)}\n\t\t\t/>\n\t\t</li>\n\t);\n}\n","export { CarouselContextProvider as Root } from \"./carousel-store-context\";\nexport {\n\tCarouselContent as Content,\n\tCarouselControls as Controls,\n\tCarouselButton as Button,\n\tCarouselItem as Item,\n\tCarouselItemGroup as ItemGroup,\n\tCarouselCaption as Caption,\n\tCarouselIndicator as Indicator,\n\tCarouselIndicatorGroup as IndicatorGroup,\n} from \"./carousel\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/carousel/carousel-store-context.tsx","../../../../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"],"names":["React","React2"],"mappings":";;;;;;;;;AASA,IAAM,CAAC,QAAA,EAAU,uBAAuB,CAAA,GAAI,oBAAoC,CAAA;AAAA,EAC/E,QAAU,EAAA,kBAAA;AAAA,EACV,IAAM,EAAA,sBAAA;AAAA,EACN,YAAc,EAAA;AACf,CAAC,CAAA;AAGD,IAAM,mBAAA,GAAsB,CAC3B,WACI,KAAA;AACJ,EAAM,MAAA,EAAE,MAAQ,EAAA,eAAA,EAAoB,GAAA,WAAA;AAEpC,EAAA,MAAM,oBAAuB,GAAA,MAAA,EAAiC,CAAA,CAAC,KAAK,GAAS,MAAA;AAAA,IAC5E,YAAc,EAAA,CAAA;AAAA,IACd,MAAA;AAAA,IACA,QAAA,EAAU,OAAO,MAAS,GAAA,CAAA;AAAA;AAAA,IAG1B,OAAS,EAAA;AAAA;AAAA,MAGR,eAAe,MAAM;AACpB,QAAA,MAAM,EAAE,YAAA,EAAc,QAAS,EAAA,GAAI,GAAI,EAAA;AACvC,QAAA,MAAM,EAAE,SAAA,EAAc,GAAA,GAAA,EAAM,CAAA,OAAA;AAE5B,QAAA,IAAI,iBAAiB,QAAU,EAAA;AAC9B,UAAA,SAAA,CAAU,CAAC,CAAA;AACX,UAAA;AAAA;AAGD,QAAA,SAAA,CAAU,eAAe,CAAC,CAAA;AAAA,OAC3B;AAAA,MAEA,mBAAmB,MAAM;AACxB,QAAA,MAAM,EAAE,YAAA,EAAc,QAAS,EAAA,GAAI,GAAI,EAAA;AACvC,QAAA,MAAM,EAAE,SAA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AAS,kBAAkB,KAA+B,EAAA;AAChE,EAAM,MAAA,EAAE,UAAY,EAAA,YAAA,EAAiB,GAAA,KAAA;AAErC,EAAM,MAAA;AAAA,IACL,OAAA,EAAS,EAAE,SAAU,EAAA;AAAA,IACrB;AAAA,GACG,GAAA,uBAAA,CAAwB,CAAC,KAAA,KAAU,KAAK,CAAA;AAE5C,EAAA,4CACE,IAAG,EAAA,EAAA,SAAA,EAAW,QAAQ,aAAe,EAAA,UAAA,EAAY,IAAI,CACrD,EAAA,kBAAA,MAAA,CAAA,aAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACA,IAAK,EAAA,QAAA;AAAA,MACL,OAAA,EAAS,MAAM,SAAA,CAAU,YAAY,CAAA;AAAA,MACrC,SAAW,EAAA,OAAA;AAAA,QACV,0BAAA;AAAA,QACA,UAAY,EAAA,IAAA;AAAA,QACZ,YAAiB,KAAA,YAAA,IAAgB,CAAC,wBAAA,EAA0B,YAAY,QAAQ;AAAA;AACjF;AAAA,GAEF,CAAA;AAEF;;;AC5OA,IAAA,sBAAA,GAAA;AAAA,QAAA,CAAA,sBAAA,EAAA;AAAA,EAAA,MAAA,EAAA,MAAA,cAAA;AAAA,EAAA,OAAA,EAAA,MAAA,eAAA;AAAA,EAAA,OAAA,EAAA,MAAA,eAAA;AAAA,EAAA,QAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,SAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,cAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,IAAA,EAAA,MAAA,YAAA;AAAA,EAAA,SAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\n\nimport { useConstant } from \"@zayne-labs/toolkit-react\";\nimport { createZustandContext } from \"@zayne-labs/toolkit-react/zustand\";\nimport type { PrettyOmit } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect } from \"react\";\nimport { create } from \"zustand\";\nimport type { CarouselProviderProps, CarouselStore, ImagesType } from \"./types\";\n\nconst [Provider, useCarouselStoreContext] = createZustandContext<CarouselStore>({\n\thookName: \"useCarouselStore\",\n\tname: \"CarouselStoreContext\",\n\tproviderName: \"CarouselContextProvider\",\n});\n\n// CarouselStore Creation\nconst createCarouselStore = <TImages extends ImagesType>(\n\tstoreValues: PrettyOmit<CarouselProviderProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = storeValues;\n\n\tconst useInitCarouselStore = create<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 useInitCarouselStore;\n};\n\nconst useCarousel = <TImages extends ImagesType>(\n\tprops: Omit<CarouselProviderProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = props;\n\n\tconst useInitCarouselStore = useConstant(() => createCarouselStore({ images, onSlideBtnClick }));\n\n\t// == To set images again when a page is mounted, preventing stale images from previous page\n\tuseEffect(() => {\n\t\tuseInitCarouselStore.setState({ images });\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- useInitCarouselStore is stable\n\t}, [images]);\n\n\treturn useInitCarouselStore;\n};\n\n// == Provider Component\nfunction CarouselContextProvider<TImages extends ImagesType>(props: CarouselProviderProps<TImages>) {\n\tconst { children, images, onSlideBtnClick } = props;\n\n\tconst useInitCarouselStore = useCarousel({ images, onSlideBtnClick });\n\n\treturn <Provider value={useInitCarouselStore}>{children}</Provider>;\n}\n\n// eslint-disable-next-line react-refresh/only-export-components -- It's fine\nexport { useCarouselStoreContext, CarouselContextProvider };\n","import * as React from \"react\";\n\nexport 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 { useCarouselStoreContext } from \"./carousel-store-context\";\n\ntype CarouselOptions = {\n\tautoSlideInterval?: number;\n\thasAutoSlide?: boolean;\n\tshouldPauseOnHover?: boolean;\n};\n\nconst useCarouselOptions = (options: CarouselOptions = {}) => {\n\tconst { autoSlideInterval = 5000, hasAutoSlide = false, shouldPauseOnHover = false } = options;\n\n\tconst { goToNextSlide } = useCarouselStoreContext((state) => state.actions);\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: 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 * as React from \"react\";\n\nimport { getElementList } from \"@/components/common/for\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport type { MyCustomCss, PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { useCarouselStoreContext } from \"./carousel-store-context\";\nimport { ChevronLeftIcon } from \"./icons\";\nimport type {\n\tCarouselButtonsProps,\n\tCarouselContentProps,\n\tCarouselControlProps,\n\tCarouselIndicatorProps,\n\tCarouselWrapperProps,\n\tOtherCarouselProps,\n} from \"./types\";\nimport { useCarouselOptions } from \"./useCarouselOptions\";\n\n// TODO - Add dragging and swiping support\nexport function CarouselContent<TElement extends React.ElementType = \"article\">(\n\tprops: PolymorphicProps<TElement, CarouselContentProps>\n) {\n\tconst {\n\t\tas: HtmlElement = \"article\",\n\t\tautoSlideInterval,\n\t\tchildren,\n\t\tclassNames,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t} = props;\n\n\tconst { pauseAutoSlide, resumeAutoSlide } = useCarouselOptions({\n\t\tautoSlideInterval,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t});\n\n\t// FIXME - Prevent touch swipe on mobile using a cover element or allow swipe but it must update the state appropriately\n\treturn (\n\t\t<HtmlElement\n\t\t\tdata-id=\"Carousel\"\n\t\t\tclassName={cnMerge(\"relative select-none\", classNames?.base)}\n\t\t\tonMouseEnter={pauseAutoSlide}\n\t\t\tonMouseLeave={resumeAutoSlide}\n\t\t>\n\t\t\t<div\n\t\t\t\tdata-id=\"Scroll Container\"\n\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\"flex size-full overflow-x-scroll [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n\t\t\t\t\tclassNames?.scrollContainer\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t</HtmlElement>\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\ttype=\"button\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"z-30 flex h-full w-fit items-center\",\n\t\t\t\tvariant === \"prev\" ? \"justify-start\" : \"justify-end\",\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<div className={cnMerge(\"absolute inset-0 flex justify-between\", classNames?.base)}>\n\t\t\t{icon?.iconType ? (\n\t\t\t\t<>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\t\ticon.iconType === \"nextIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon.icon}\n\t\t\t\t\t/>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\t\ticon.iconType === \"prevIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon.icon}\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: classNames?.iconContainer,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon?.prev}\n\t\t\t\t\t/>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: classNames?.iconContainer,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon?.next}\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n\nexport function CarouselItemGroup<TArrayItem>(props: CarouselWrapperProps<TArrayItem>) {\n\tconst { children, className, each, render } = props;\n\n\tconst [ItemList] = getElementList(\"base\");\n\tconst currentSlide = useCarouselStoreContext((state) => state.currentSlide);\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArrayItem[]));\n\n\treturn (\n\t\t<ul\n\t\t\tdata-id=\"Carousel Image Wrapper\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t`flex w-full shrink-0 snap-center [transform:translate3d(var(--translate-distance),0,0)]\n\t\t\t\t[transition:transform_800ms_ease]`,\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 MyCustomCss as MyCustomCss\n\t\t\t}\n\t\t>\n\t\t\t{typeof render === \"function\" ? (\n\t\t\t\t<ItemList each={images} render={render} />\n\t\t\t) : (\n\t\t\t\t<ItemList each={images}>{children}</ItemList>\n\t\t\t)}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselItem({ children, className, ...restOfProps }: OtherCarouselProps) {\n\treturn (\n\t\t<li\n\t\t\tclassName={cnMerge(\"flex w-full shrink-0 snap-center justify-center\", 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: PolymorphicProps<TElement, OtherCarouselProps>\n) {\n\tconst { as: HtmlElement = \"div\", children, className } = props;\n\n\treturn (\n\t\t<HtmlElement data-id=\"Carousel Caption\" className={cnMerge(\"absolute z-10\", className)}>\n\t\t\t{children}\n\t\t</HtmlElement>\n\t);\n}\n\nexport function CarouselIndicatorGroup<TArrayItem>(props: CarouselWrapperProps<TArrayItem>) {\n\tconst { children, className, each, render } = props;\n\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArrayItem[]));\n\tconst [IndicatorList] = getElementList(\"base\");\n\n\treturn (\n\t\t<ul\n\t\t\tdata-id=\"Carousel Indicators\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"absolute bottom-[25px] z-[2] flex w-full items-center justify-center gap-[15px]\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t>\n\t\t\t{typeof render === \"function\" ? (\n\t\t\t\t<IndicatorList each={images} render={render} />\n\t\t\t) : (\n\t\t\t\t<IndicatorList each={images}>{children}</IndicatorList>\n\t\t\t)}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselIndicator(props: CarouselIndicatorProps) {\n\tconst { classNames, currentIndex } = props;\n\n\tconst {\n\t\tactions: { goToSlide },\n\t\tcurrentSlide,\n\t} = useCarouselStoreContext((state) => state);\n\n\treturn (\n\t\t<li className={cnMerge(\"inline-flex\", classNames?.base)}>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tonClick={() => goToSlide(currentIndex)}\n\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\"size-[6px] rounded-[50%]\",\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tcurrentIndex === currentSlide && [\"w-[35px] rounded-[5px]\", classNames?.isActive]\n\t\t\t\t)}\n\t\t\t/>\n\t\t</li>\n\t);\n}\n","export { CarouselContextProvider as Root } from \"./carousel-store-context\";\nexport {\n\tCarouselContent as Content,\n\tCarouselControls as Controls,\n\tCarouselButton as Button,\n\tCarouselItem as Item,\n\tCarouselItemGroup as ItemGroup,\n\tCarouselCaption as Caption,\n\tCarouselIndicator as Indicator,\n\tCarouselIndicatorGroup as IndicatorGroup,\n} from \"./carousel\";\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { DiscriminatedRenderProps, InferProps, GetSlotComponentProps } from '@zayne-labs/toolkit-react/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { FileMeta, FileValidationErrorContext, FileValidationOptions } from '@zayne-labs/toolkit-core';
|
|
4
4
|
import { Prettify } from '@zayne-labs/toolkit-type-helpers';
|
|
5
5
|
|
|
6
6
|
type RootProps = InferProps<HTMLElement> & {
|
|
@@ -11,33 +11,57 @@ type RootProps = InferProps<HTMLElement> & {
|
|
|
11
11
|
};
|
|
12
12
|
type InputProps = InferProps<"input">;
|
|
13
13
|
type FileWithPreview = {
|
|
14
|
+
/**
|
|
15
|
+
* File object or file metadata
|
|
16
|
+
*/
|
|
14
17
|
file: File | FileMeta;
|
|
18
|
+
/**
|
|
19
|
+
* Unique ID for the file
|
|
20
|
+
*/
|
|
15
21
|
id: string;
|
|
16
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Preview URL for the file
|
|
24
|
+
* - Will be undefined if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image
|
|
25
|
+
* - Can also be undefined if `URL.createObjectURL` fails
|
|
26
|
+
*/
|
|
27
|
+
preview: string | undefined;
|
|
17
28
|
};
|
|
18
|
-
type
|
|
29
|
+
type DropZoneState = {
|
|
30
|
+
/**
|
|
31
|
+
* List of validation errors
|
|
32
|
+
*/
|
|
19
33
|
errors: FileValidationErrorContext[];
|
|
34
|
+
/**
|
|
35
|
+
* List of files with their preview URLs and unique IDs
|
|
36
|
+
*/
|
|
20
37
|
filesWithPreview: FileWithPreview[];
|
|
38
|
+
/**
|
|
39
|
+
* Whether or not a file is currently being dragged over the drop zone
|
|
40
|
+
*/
|
|
21
41
|
isDragging: boolean;
|
|
22
42
|
};
|
|
23
43
|
type ChangeOrDragEvent = React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>;
|
|
24
|
-
type
|
|
44
|
+
type DropZoneActions = {
|
|
25
45
|
addFiles: (fileList: File[] | FileList | null, event?: ChangeOrDragEvent) => void;
|
|
26
46
|
clearErrors: () => void;
|
|
27
47
|
clearFiles: () => void;
|
|
28
|
-
dropZoneState: FileUploadState;
|
|
29
|
-
getInputProps: (inputProps?: InputProps) => InputProps;
|
|
30
|
-
getResolvedChildren: () => React.ReactNode;
|
|
31
|
-
getRootProps: (rootProps?: RootProps) => RootProps;
|
|
32
48
|
handleDragEnter: (event: React.DragEvent<HTMLElement>) => void;
|
|
33
49
|
handleDragLeave: (event: React.DragEvent<HTMLElement>) => void;
|
|
34
50
|
handleDragOver: (event: React.DragEvent<HTMLElement>) => void;
|
|
35
|
-
handleFileUpload: (event:
|
|
36
|
-
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
51
|
+
handleFileUpload: (event: ChangeOrDragEvent) => void;
|
|
37
52
|
openFilePicker: () => void;
|
|
38
|
-
removeFile: (
|
|
53
|
+
removeFile: (fileToRemoveOrId: string | FileWithPreview) => void;
|
|
54
|
+
};
|
|
55
|
+
type RenderProps = {
|
|
56
|
+
dropZoneActions: DropZoneActions;
|
|
57
|
+
dropZoneState: DropZoneState;
|
|
58
|
+
getInputProps: (inputProps?: InputProps) => InputProps;
|
|
59
|
+
getRootProps: (rootProps?: RootProps) => RootProps;
|
|
60
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
61
|
+
};
|
|
62
|
+
type UseDropZoneResult = RenderProps & {
|
|
63
|
+
getResolvedChildren: () => React.ReactNode;
|
|
39
64
|
};
|
|
40
|
-
type RenderProps = Omit<UseDropZoneResult, "getResolvedChildren">;
|
|
41
65
|
type DropZoneRenderProps = DiscriminatedRenderProps<React.ReactNode | ((props: RenderProps) => React.ReactNode)>;
|
|
42
66
|
type UseDropZoneProps = DropZoneRenderProps & {
|
|
43
67
|
/**
|
|
@@ -55,6 +79,11 @@ type UseDropZoneProps = DropZoneRenderProps & {
|
|
|
55
79
|
* @default true
|
|
56
80
|
*/
|
|
57
81
|
disallowDuplicates?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to disallow preview for non-image files
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
86
|
+
disallowPreviewForNonImageFiles?: boolean;
|
|
58
87
|
/**
|
|
59
88
|
* Extra props to pass to the input element
|
|
60
89
|
*/
|
|
@@ -128,4 +157,4 @@ declare namespace dropZoneParts {
|
|
|
128
157
|
export { DropZoneImagePreview as ImagePreview, DropZoneRoot as Root };
|
|
129
158
|
}
|
|
130
159
|
|
|
131
|
-
export { dropZoneParts as DropZone, DropZoneImagePreview, DropZoneRoot, type
|
|
160
|
+
export { dropZoneParts as DropZone, DropZoneImagePreview, DropZoneRoot, type DropZoneState, type FileWithPreview, type InputProps, type RootProps, type UseDropZoneProps, useDropZone };
|
|
@@ -4,7 +4,7 @@ import { __export } from '../../chunk-PZ5AY32C.js';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { isValidElement, Fragment, useRef, useState, useCallback } from 'react';
|
|
6
6
|
import { withSlotNameAndSymbol, getSlotMap, mergeTwoProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
|
|
7
|
-
import { isArray, isFile, isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
7
|
+
import { isArray, isString, isFile, isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
8
8
|
import { toArray, handleFileValidation, createImagePreview } from '@zayne-labs/toolkit-core';
|
|
9
9
|
import { useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
10
10
|
|
|
@@ -14,11 +14,15 @@ var generateUniqueId = (file) => {
|
|
|
14
14
|
}
|
|
15
15
|
return `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;
|
|
16
16
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
var createObjectURL = (file, disallowPreviewForNonImageFiles) => {
|
|
18
|
+
if (disallowPreviewForNonImageFiles && !file.type.startsWith("image/")) return;
|
|
19
|
+
return createImagePreview(file);
|
|
20
|
+
};
|
|
21
|
+
var clearObjectURL = (fileWithPreview, disallowPreviewForNonImageFiles) => {
|
|
22
|
+
if (!isFile(fileWithPreview?.file)) return;
|
|
23
|
+
if (disallowPreviewForNonImageFiles && !fileWithPreview.file.type.startsWith("image/")) return;
|
|
24
|
+
if (!fileWithPreview.preview) return;
|
|
25
|
+
URL.revokeObjectURL(fileWithPreview.preview);
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
// src/components/ui/drop-zone/use-drop-zone.ts
|
|
@@ -28,6 +32,7 @@ var useDropZone = (props) => {
|
|
|
28
32
|
children,
|
|
29
33
|
classNames,
|
|
30
34
|
disallowDuplicates = true,
|
|
35
|
+
disallowPreviewForNonImageFiles = true,
|
|
31
36
|
extraInputProps,
|
|
32
37
|
extraRootProps,
|
|
33
38
|
initialFiles,
|
|
@@ -81,7 +86,7 @@ var useDropZone = (props) => {
|
|
|
81
86
|
const filesWithPreview = validFiles.map((file) => ({
|
|
82
87
|
file,
|
|
83
88
|
id: generateUniqueId(file),
|
|
84
|
-
preview:
|
|
89
|
+
preview: createObjectURL(file, disallowPreviewForNonImageFiles)
|
|
85
90
|
}));
|
|
86
91
|
if (event) {
|
|
87
92
|
onUpload?.({ event, filesWithPreview });
|
|
@@ -97,7 +102,9 @@ var useDropZone = (props) => {
|
|
|
97
102
|
inputRef.current && (inputRef.current.value = "");
|
|
98
103
|
});
|
|
99
104
|
const clearFiles = useCallbackRef(() => {
|
|
100
|
-
dropZoneState.filesWithPreview.forEach(
|
|
105
|
+
dropZoneState.filesWithPreview.forEach(
|
|
106
|
+
(fileWithPreview) => clearObjectURL(fileWithPreview, disallowPreviewForNonImageFiles)
|
|
107
|
+
);
|
|
101
108
|
const newFileUploadState = {
|
|
102
109
|
...dropZoneState,
|
|
103
110
|
errors: [],
|
|
@@ -107,10 +114,13 @@ var useDropZone = (props) => {
|
|
|
107
114
|
setDropZoneState(newFileUploadState);
|
|
108
115
|
inputRef.current && (inputRef.current.value = "");
|
|
109
116
|
});
|
|
110
|
-
const removeFile = useCallbackRef((
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
const removeFile = useCallbackRef((fileToRemoveOrId) => {
|
|
118
|
+
const actualFileToRemove = isString(fileToRemoveOrId) ? dropZoneState.filesWithPreview.find((file) => file.id === fileToRemoveOrId) : fileToRemoveOrId;
|
|
119
|
+
if (!actualFileToRemove) return;
|
|
120
|
+
clearObjectURL(actualFileToRemove, disallowPreviewForNonImageFiles);
|
|
121
|
+
const newFilesWithPreview = dropZoneState.filesWithPreview.filter(
|
|
122
|
+
(file) => file.id !== actualFileToRemove.id
|
|
123
|
+
);
|
|
114
124
|
onFilesChange?.({ filesWithPreview: newFilesWithPreview });
|
|
115
125
|
setDropZoneState({
|
|
116
126
|
...dropZoneState,
|
|
@@ -226,19 +236,21 @@ var useDropZone = (props) => {
|
|
|
226
236
|
]
|
|
227
237
|
);
|
|
228
238
|
const renderProps = {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
239
|
+
dropZoneActions: {
|
|
240
|
+
addFiles,
|
|
241
|
+
clearErrors,
|
|
242
|
+
clearFiles,
|
|
243
|
+
handleDragEnter,
|
|
244
|
+
handleDragLeave,
|
|
245
|
+
handleDragOver,
|
|
246
|
+
handleFileUpload,
|
|
247
|
+
openFilePicker,
|
|
248
|
+
removeFile
|
|
249
|
+
},
|
|
232
250
|
dropZoneState,
|
|
233
251
|
getInputProps,
|
|
234
252
|
getRootProps,
|
|
235
|
-
|
|
236
|
-
handleDragLeave,
|
|
237
|
-
handleDragOver,
|
|
238
|
-
handleFileUpload,
|
|
239
|
-
inputRef,
|
|
240
|
-
openFilePicker,
|
|
241
|
-
removeFile
|
|
253
|
+
inputRef
|
|
242
254
|
};
|
|
243
255
|
const selectedChildren = children ?? render;
|
|
244
256
|
const getResolvedChildren = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/drop-zone/utils.ts","../../../../src/components/ui/drop-zone/use-drop-zone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx","../../../../src/components/ui/drop-zone/drop-zone-parts.ts"],"names":["ReactFragment"],"mappings":";;;;;;;;;;AAIO,IAAM,gBAAA,GAAmB,CAAC,IAAkC,KAAA;AAClE,EAAI,IAAA,CAAC,MAAO,CAAA,IAAI,CAAG,EAAA;AAClB,IAAA,OAAO,IAAK,CAAA,EAAA;AAAA;AAGb,EAAA,OAAO,GAAG,IAAK,CAAA,IAAI,CAAK,EAAA,EAAA,IAAA,CAAK,MAAM,WAAY,CAAA,GAAA,EAAK,CAAC,KAAK,MAAO,CAAA,UAAA,GAAa,KAAM,CAAA,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;AAC1F,CAAA;AAEO,IAAM,cAAA,GAAiB,CAAC,UAA4C,KAAA;AAC1E,EAAM,MAAA,oBAAA,GAAuB,OAAO,UAAY,EAAA,IAAI,KAAK,UAAW,CAAA,IAAA,CAAK,IAAK,CAAA,UAAA,CAAW,QAAQ,CAAA;AAEjG,E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A,GAAuB,sBAA0C,SAAS;;;AC3DvF,IAAA,uBAAA,GAAA;AAAA,QAAA,CAAA,uBAAA,EAAA;AAAA,EAAA,YAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import type { FileMeta } from \"@zayne-labs/toolkit-core\";\nimport { isFile } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { FileWithPreview } from \"./use-drop-zone\";\n\nexport const generateUniqueId = (file: File | FileMeta): string => {\n\tif (!isFile(file)) {\n\t\treturn file.id;\n\t}\n\n\treturn `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;\n};\n\nexport const clearObjectURL = (fileObject: FileWithPreview | undefined) => {\n\tconst shouldClearObjectURL = isFile(fileObject?.file) && fileObject.file.type.startsWith(\"image/\");\n\n\tif (fileObject?.preview && shouldClearObjectURL) {\n\t\tURL.revokeObjectURL(fileObject.preview);\n\t}\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { dataAttr } from \"@/lib/utils/common\";\nimport { toArray } from \"@zayne-labs/toolkit-core\";\nimport {\n\ttype FileMeta,\n\ttype FileValidationErrorContext,\n\ttype FileValidationOptions,\n\tcreateImagePreview,\n\thandleFileValidation,\n} from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport {\n\ttype DiscriminatedRenderProps,\n\ttype InferProps,\n\tcomposeRefs,\n\tmergeTwoProps,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { type Prettify, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { clearObjectURL, generateUniqueId } from \"./utils\";\n\nexport type RootProps = InferProps<HTMLElement> & {\n\tclassNames?: {\n\t\tbase?: string;\n\t\tisDragging?: string;\n\t};\n};\n\nexport type InputProps = InferProps<\"input\">;\n\nexport type FileWithPreview = {\n\tfile: File | FileMeta;\n\tid: string;\n\tpreview?: string;\n};\n\nexport type FileUploadState = {\n\terrors: FileValidationErrorContext[];\n\tfilesWithPreview: FileWithPreview[];\n\tisDragging: boolean;\n};\n\ntype ChangeOrDragEvent = React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>;\n\ntype UseDropZoneResult = {\n\taddFiles: (fileList: File[] | FileList | null, event?: ChangeOrDragEvent) => void;\n\tclearErrors: () => void;\n\tclearFiles: () => void;\n\tdropZoneState: FileUploadState;\n\tgetInputProps: (inputProps?: InputProps) => InputProps;\n\tgetResolvedChildren: () => React.ReactNode;\n\tgetRootProps: (rootProps?: RootProps) => RootProps;\n\thandleDragEnter: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragLeave: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragOver: (event: React.DragEvent<HTMLElement>) => void;\n\thandleFileUpload: (event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>) => void;\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n\topenFilePicker: () => void;\n\tremoveFile: (id: string) => void;\n};\n\ntype RenderProps = Omit<UseDropZoneResult, \"getResolvedChildren\">;\n\ntype DropZoneRenderProps = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: RenderProps) => React.ReactNode)\n>;\n\nexport type UseDropZoneProps = DropZoneRenderProps & {\n\t/**\n\t * Allowed file types to be uploaded.\n\t */\n\tallowedFileTypes?: string[];\n\n\t/**\n\t * CSS classes to apply to the various parts of the drop zone\n\t */\n\tclassNames?: Prettify<RootProps[\"classNames\"] & { input?: string }>;\n\n\t/**\n\t * Whether to disallow duplicate files\n\t * @default true\n\t */\n\tdisallowDuplicates?: boolean;\n\n\t/**\n\t * Extra props to pass to the input element\n\t */\n\textraInputProps?: InputProps;\n\n\t/**\n\t * Extra props to pass to the root element\n\t */\n\textraRootProps?: RootProps;\n\n\t/**\n\t * Initial files to populate the drop zone\n\t */\n\tinitialFiles?: FileMeta | FileMeta[] | null;\n\n\t/**\n\t * Maximum number of files that can be uploaded.\n\t */\n\tmaxFileCount?: number;\n\n\t/**\n\t * Maximum file size in MB\n\t */\n\tmaxFileSize?: number;\n\n\t/**\n\t * Whether to allow multiple files to be uploaded\n\t */\n\tmultiple?: boolean;\n\n\t/**\n\t * Callback function to be called when internal files state changes\n\t */\n\tonFilesChange?: (context: { filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called when new files are uploaded\n\t */\n\tonUpload?: (context: { event: ChangeOrDragEvent; filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called on each file upload as they occur\n\t */\n\tonUploadError?: FileValidationOptions[\"onError\"];\n\n\t/**\n\t * Callback function to be called once after all file upload errors have occurred\n\t */\n\tonUploadErrors?: FileValidationOptions[\"onErrors\"];\n\n\t/**\n\t * Callback function to be called on file upload success\n\t */\n\tonUploadSuccess?: FileValidationOptions[\"onSuccess\"];\n\n\t/**\n\t * Custom validator function to handle file validation\n\t */\n\tvalidator?: FileValidationOptions[\"validator\"];\n};\n\nexport const useDropZone = (props?: UseDropZoneProps): UseDropZoneResult => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tchildren,\n\t\tclassNames,\n\t\tdisallowDuplicates = true,\n\t\textraInputProps,\n\t\textraRootProps,\n\t\tinitialFiles,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrors,\n\t\tonUploadSuccess,\n\t\trender,\n\t\tvalidator,\n\t} = props ?? {};\n\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst initialFileArray = toArray(initialFiles).filter(Boolean);\n\n\tconst [dropZoneState, setDropZoneState] = useState<FileUploadState>({\n\t\terrors: [],\n\t\tfilesWithPreview: initialFileArray.map((fileMeta) => ({\n\t\t\tfile: fileMeta,\n\t\t\tid: fileMeta.id,\n\t\t\tpreview: fileMeta.url,\n\t\t})),\n\t\tisDragging: false,\n\t});\n\n\tconst toggleIsDragging = (value: boolean) => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, isDragging: value }));\n\t};\n\n\tconst addFiles: UseDropZoneResult[\"addFiles\"] = useCallbackRef((fileList, event) => {\n\t\tif (!fileList || fileList.length === 0) {\n\t\t\tconsole.warn(\"No file selected!\");\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear existing errors when new files are uploaded\n\t\tclearErrors();\n\n\t\t// In single file mode, clear existing files first\n\t\tif (!multiple) {\n\t\t\tclearFiles();\n\t\t}\n\n\t\tconst { errors, validFiles } = handleFileValidation({\n\t\t\texistingFiles: dropZoneState.filesWithPreview.map((fileWithPreview) => fileWithPreview.file),\n\t\t\tnewFiles: fileList,\n\t\t\tonError: onUploadError,\n\t\t\tonErrors: onUploadErrors,\n\t\t\tonSuccess: onUploadSuccess,\n\t\t\tvalidationSettings: { allowedFileTypes, disallowDuplicates, maxFileCount, maxFileSize },\n\t\t\tvalidator,\n\t\t});\n\n\t\tif (validFiles.length === 0) {\n\t\t\tsetDropZoneState((prevState) => ({ ...prevState, errors }));\n\t\t\treturn;\n\t\t}\n\n\t\tconst filesWithPreview: FileWithPreview[] = validFiles.map((file) => ({\n\t\t\tfile,\n\t\t\tid: generateUniqueId(file),\n\t\t\tpreview: createImagePreview({ file }),\n\t\t}));\n\n\t\t// == Only call onUpload callback if event is provided, which indicates that new files were uploaded from an event handler\n\n\t\tif (event) {\n\t\t\tonUpload?.({ event, filesWithPreview });\n\t\t}\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors,\n\t\t\t...(event?.type === \"drop\" && { isDragging: false }),\n\t\t\tfilesWithPreview: multiple\n\t\t\t\t? [...dropZoneState.filesWithPreview, ...filesWithPreview]\n\t\t\t\t: filesWithPreview,\n\t\t} satisfies FileUploadState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after adding files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst clearFiles: UseDropZoneResult[\"clearFiles\"] = useCallbackRef(() => {\n\t\t// == Clean up object URLs if any\n\t\tdropZoneState.filesWithPreview.forEach((fileObject) => clearObjectURL(fileObject));\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: [],\n\t\t} satisfies FileUploadState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after clearing files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst removeFile: UseDropZoneResult[\"removeFile\"] = useCallbackRef((id) => {\n\t\tconst fileToRemove = dropZoneState.filesWithPreview.find((fileObject) => fileObject.id === id);\n\n\t\tclearObjectURL(fileToRemove);\n\n\t\tconst newFilesWithPreview = dropZoneState.filesWithPreview.filter((file) => file.id !== id);\n\n\t\tonFilesChange?.({ filesWithPreview: newFilesWithPreview });\n\n\t\tsetDropZoneState({\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: newFilesWithPreview,\n\t\t});\n\t});\n\n\tconst clearErrors: UseDropZoneResult[\"clearErrors\"] = useCallbackRef(() => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, errors: [] }));\n\t});\n\n\tconst handleFileUpload: UseDropZoneResult[\"handleFileUpload\"] = useCallbackRef((event) => {\n\t\tif (event.defaultPrevented) return;\n\n\t\tif (inputRef.current?.disabled) return;\n\n\t\tif (event.type === \"drop\") {\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t}\n\n\t\tconst fileList =\n\t\t\tevent.type === \"drop\"\n\t\t\t\t? (event as React.DragEvent).dataTransfer.files\n\t\t\t\t: (event as React.ChangeEvent<HTMLInputElement>).target.files;\n\n\t\t// == In single file mode, only use the first file\n\t\tif (!multiple) {\n\t\t\tconst firstFile = fileList?.[0];\n\n\t\t\tfirstFile && addFiles([firstFile], event);\n\n\t\t\treturn;\n\t\t}\n\n\t\taddFiles(fileList, event);\n\t});\n\n\tconst handleDragEnter: UseDropZoneResult[\"handleDragEnter\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragOver: UseDropZoneResult[\"handleDragOver\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragLeave: UseDropZoneResult[\"handleDragLeave\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(false);\n\t});\n\n\tconst openFilePicker: UseDropZoneResult[\"openFilePicker\"] = useCallbackRef(() => {\n\t\tinputRef.current?.click();\n\t});\n\n\tconst getRootProps: UseDropZoneResult[\"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\"relative isolate flex flex-col\",\n\t\t\t\t\tmergedRootProps.className,\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tdropZoneState.isDragging && [\n\t\t\t\t\t\t\"opacity-60\",\n\t\t\t\t\t\tclassNames?.isDragging,\n\t\t\t\t\t\trootProps?.classNames?.isDragging,\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"root\",\n\t\t\t\t\"data-slot\": \"dropzone-root\",\n\t\t\t\tonDragEnter: handleDragEnter,\n\t\t\t\tonDragLeave: handleDragLeave,\n\t\t\t\tonDragOver: handleDragOver,\n\t\t\t\tonDrop: handleFileUpload,\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclassNames?.base,\n\t\t\tclassNames?.isDragging,\n\t\t\textraRootProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleDragEnter,\n\t\t\thandleDragLeave,\n\t\t\thandleDragOver,\n\t\t\thandleFileUpload,\n\t\t]\n\t);\n\n\tconst getInputProps: UseDropZoneResult[\"getInputProps\"] = useCallback(\n\t\t(inputProps) => {\n\t\t\tconst mergedInputProps = mergeTwoProps(extraInputProps, inputProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedInputProps,\n\t\t\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : mergedInputProps.accept,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\t\t\tclassNames?.input,\n\t\t\t\t\tmergedInputProps.className\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"input\",\n\t\t\t\t\"data-slot\": \"dropzone-input\",\n\t\t\t\tmultiple: multiple ?? mergedInputProps.multiple,\n\t\t\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\t\t\tmergedInputProps.onChange?.(event);\n\t\t\t\t\thandleFileUpload(event);\n\t\t\t\t},\n\t\t\t\tref: composeRefs([inputRef, mergedInputProps.ref]),\n\t\t\t\ttype: \"file\",\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tallowedFileTypes,\n\t\t\tclassNames?.input,\n\t\t\textraInputProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleFileUpload,\n\t\t\tmultiple,\n\t\t]\n\t);\n\n\tconst renderProps = {\n\t\taddFiles,\n\t\tclearErrors,\n\t\tclearFiles,\n\t\tdropZoneState,\n\t\tgetInputProps,\n\t\tgetRootProps,\n\t\thandleDragEnter,\n\t\thandleDragLeave,\n\t\thandleDragOver,\n\t\thandleFileUpload,\n\t\tinputRef,\n\t\topenFilePicker,\n\t\tremoveFile,\n\t} satisfies RenderProps;\n\n\tconst selectedChildren = children ?? render;\n\n\tconst getResolvedChildren = () => {\n\t\treturn isFunction(selectedChildren) ? selectedChildren(renderProps) : selectedChildren;\n\t};\n\n\treturn {\n\t\t...renderProps,\n\t\tgetResolvedChildren,\n\t};\n};\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport {\n\ttype GetSlotComponentProps,\n\tgetSlotMap,\n\twithSlotNameAndSymbol,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\nimport { type UseDropZoneProps, useDropZone } from \"./use-drop-zone\";\n\ntype DropZoneProps = UseDropZoneProps & {\n\t/**\n\t * Controls whether to include internal elements (root and input) or not.\n\t */\n\twithInternalElements?: boolean;\n};\n\nexport function DropZoneRoot(props: DropZoneProps) {\n\tconst { withInternalElements = true, ...restOfProps } = props;\n\n\tconst api = useDropZone(restOfProps);\n\n\tconst RootComponent = withInternalElements ? \"div\" : ReactFragment;\n\tconst InputComponent = withInternalElements ? \"input\" : ReactFragment;\n\n\tconst rootComponentProps = RootComponent === \"div\" && api.getRootProps();\n\tconst inputComponentProps = InputComponent === \"input\" && api.getInputProps();\n\n\tconst resolvedChildren = api.getResolvedChildren();\n\n\t/**\n\t * Whether the children could contain slots.\n\t */\n\tconst couldChildrenContainSlots =\n\t\tisArray(resolvedChildren)\n\t\t|| (isValidElement(resolvedChildren) && resolvedChildren.type === ReactFragment);\n\n\tconst slots = getSlotMap<SlotComponentProps>(resolvedChildren, {\n\t\tcondition: withInternalElements && couldChildrenContainSlots,\n\t});\n\n\treturn (\n\t\t<>\n\t\t\t<RootComponent {...rootComponentProps}>\n\t\t\t\t<InputComponent {...inputComponentProps} />\n\n\t\t\t\t{slots.default}\n\t\t\t</RootComponent>\n\n\t\t\t{slots.preview}\n\t\t</>\n\t);\n}\n\ntype SlotComponentProps = GetSlotComponentProps<\"preview\">;\n\nexport const DropZoneImagePreview = withSlotNameAndSymbol<SlotComponentProps>(\"preview\");\n","export { DropZoneRoot as Root, DropZoneImagePreview as ImagePreview } from \"./drop-zone\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/drop-zone/utils.ts","../../../../src/components/ui/drop-zone/use-drop-zone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx","../../../../src/components/ui/drop-zone/drop-zone-parts.ts"],"names":["ReactFragment"],"mappings":";;;;;;;;;;AAIO,IAAM,gBAAA,GAAmB,CAAC,IAAkC,KAAA;AAClE,EAAI,IAAA,CAAC,MAAO,CAAA,IAAI,CAAG,EAAA;AAClB,IAAA,OAAO,IAAK,CAAA,EAAA;AAAA;AAGb,EAAA,OAAO,GAAG,IAAK,CAAA,IAAI,CAAK,EAAA,EAAA,IAAA,CAAK,MAAM,WAAY,CAAA,GAAA,EAAK,CAAC,KAAK,MAAO,CAAA,UAAA,GAAa,KAAM,CAAA,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;AAC1F,CAAA;AAEO,IAAM,eAAA,GAAkB,CAAC,IAAA,EAAY,+BAA6C,KAAA;AACxF,EAAA,IAAI,mCAAmC,CAAC,IAAA,CAAK,IAAK,CAAA,UAAA,CAAW,QAAQ,CAAG,EAAA;AAExE,EAAA,OAAO,mBAAmB,IAAI,CAAA;AAC/B,CAAA;AAEO,IAAM,cAAA,GAAiB,CAC7B,eAAA,EACA,+BACI,KAAA;AACJ,EAAA,IAAI,CAAC,MAAA,CAAO,eAAiB,EAAA,IAAI,CAAG,EAAA;AAEpC,EAAA,IAAI,mCAAmC,CAAC,eAAA,CAAgB,KAAK,IAAK,CAAA,UAAA,CAAW,QAAQ,CAAG,EAAA;AAExF,EAAI,IAAA,CAAC,gBAAgB,OAAS,EAAA;AAE9B,EAAI,G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e,EAAA,EAAA,GAAG,sCACjB,KAAA,CAAA,aAAA,CAAA,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAqB,CAExC,EAAA,KAAA,CAAM,OACR,CAAA,EAEC,MAAM,OACR,CAAA;AAEF;AAIa,IAAA,oBAAA,GAAuB,sBAA0C,SAAS;;;AC3DvF,IAAA,uBAAA,GAAA;AAAA,QAAA,CAAA,uBAAA,EAAA;AAAA,EAAA,YAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import { type FileMeta, createImagePreview } from \"@zayne-labs/toolkit-core\";\nimport { isFile } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { FileWithPreview } from \"./use-drop-zone\";\n\nexport const generateUniqueId = (file: File | FileMeta): string => {\n\tif (!isFile(file)) {\n\t\treturn file.id;\n\t}\n\n\treturn `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;\n};\n\nexport const createObjectURL = (file: File, disallowPreviewForNonImageFiles: boolean) => {\n\tif (disallowPreviewForNonImageFiles && !file.type.startsWith(\"image/\")) return;\n\n\treturn createImagePreview(file);\n};\n\nexport const clearObjectURL = (\n\tfileWithPreview: FileWithPreview | undefined,\n\tdisallowPreviewForNonImageFiles: boolean\n) => {\n\tif (!isFile(fileWithPreview?.file)) return;\n\n\tif (disallowPreviewForNonImageFiles && !fileWithPreview.file.type.startsWith(\"image/\")) return;\n\n\tif (!fileWithPreview.preview) return;\n\n\tURL.revokeObjectURL(fileWithPreview.preview);\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { dataAttr } from \"@/lib/utils/common\";\nimport {\n\ttype FileMeta,\n\ttype FileValidationErrorContext,\n\ttype FileValidationOptions,\n\thandleFileValidation,\n\ttoArray,\n} from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport {\n\ttype DiscriminatedRenderProps,\n\ttype InferProps,\n\tcomposeRefs,\n\tmergeTwoProps,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { type Prettify, isFunction, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { clearObjectURL, createObjectURL, generateUniqueId } from \"./utils\";\n\nexport type RootProps = InferProps<HTMLElement> & {\n\tclassNames?: {\n\t\tbase?: string;\n\t\tisDragging?: string;\n\t};\n};\n\nexport type InputProps = InferProps<\"input\">;\n\nexport type FileWithPreview = {\n\t/**\n\t * File object or file metadata\n\t */\n\tfile: File | FileMeta;\n\t/**\n\t * Unique ID for the file\n\t */\n\tid: string;\n\t/**\n\t * Preview URL for the file\n\t * - Will be undefined if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image\n\t * - Can also be undefined if `URL.createObjectURL` fails\n\t */\n\tpreview: string | undefined;\n};\n\nexport type DropZoneState = {\n\t/**\n\t * List of validation errors\n\t */\n\terrors: FileValidationErrorContext[];\n\t/**\n\t * List of files with their preview URLs and unique IDs\n\t */\n\tfilesWithPreview: FileWithPreview[];\n\t/**\n\t * Whether or not a file is currently being dragged over the drop zone\n\t */\n\tisDragging: boolean;\n};\n\ntype ChangeOrDragEvent = React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>;\n\ntype DropZoneActions = {\n\taddFiles: (fileList: File[] | FileList | null, event?: ChangeOrDragEvent) => void;\n\tclearErrors: () => void;\n\tclearFiles: () => void;\n\thandleDragEnter: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragLeave: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragOver: (event: React.DragEvent<HTMLElement>) => void;\n\thandleFileUpload: (event: ChangeOrDragEvent) => void;\n\topenFilePicker: () => void;\n\tremoveFile: (fileToRemoveOrId: string | FileWithPreview) => void;\n};\n\ntype RenderProps = {\n\tdropZoneActions: DropZoneActions;\n\tdropZoneState: DropZoneState;\n\tgetInputProps: (inputProps?: InputProps) => InputProps;\n\tgetRootProps: (rootProps?: RootProps) => RootProps;\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n};\n\ntype UseDropZoneResult = RenderProps & { getResolvedChildren: () => React.ReactNode };\n\ntype DropZoneRenderProps = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: RenderProps) => React.ReactNode)\n>;\n\nexport type UseDropZoneProps = DropZoneRenderProps & {\n\t/**\n\t * Allowed file types to be uploaded.\n\t */\n\tallowedFileTypes?: string[];\n\n\t/**\n\t * CSS classes to apply to the various parts of the drop zone\n\t */\n\tclassNames?: Prettify<RootProps[\"classNames\"] & { input?: string }>;\n\n\t/**\n\t * Whether to disallow duplicate files\n\t * @default true\n\t */\n\tdisallowDuplicates?: boolean;\n\n\t/**\n\t * Whether to disallow preview for non-image files\n\t * @default true\n\t */\n\tdisallowPreviewForNonImageFiles?: boolean;\n\n\t/**\n\t * Extra props to pass to the input element\n\t */\n\textraInputProps?: InputProps;\n\n\t/**\n\t * Extra props to pass to the root element\n\t */\n\textraRootProps?: RootProps;\n\n\t/**\n\t * Initial files to populate the drop zone\n\t */\n\tinitialFiles?: FileMeta | FileMeta[] | null;\n\n\t/**\n\t * Maximum number of files that can be uploaded.\n\t */\n\tmaxFileCount?: number;\n\n\t/**\n\t * Maximum file size in MB\n\t */\n\tmaxFileSize?: number;\n\n\t/**\n\t * Whether to allow multiple files to be uploaded\n\t */\n\tmultiple?: boolean;\n\n\t/**\n\t * Callback function to be called when internal files state changes\n\t */\n\tonFilesChange?: (context: { filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called when new files are uploaded\n\t */\n\tonUpload?: (context: { event: ChangeOrDragEvent; filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called on each file upload as they occur\n\t */\n\tonUploadError?: FileValidationOptions[\"onError\"];\n\n\t/**\n\t * Callback function to be called once after all file upload errors have occurred\n\t */\n\tonUploadErrors?: FileValidationOptions[\"onErrors\"];\n\n\t/**\n\t * Callback function to be called on file upload success\n\t */\n\tonUploadSuccess?: FileValidationOptions[\"onSuccess\"];\n\n\t/**\n\t * Custom validator function to handle file validation\n\t */\n\tvalidator?: FileValidationOptions[\"validator\"];\n};\n\nexport const useDropZone = (props?: UseDropZoneProps): UseDropZoneResult => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tchildren,\n\t\tclassNames,\n\t\tdisallowDuplicates = true,\n\t\tdisallowPreviewForNonImageFiles = true,\n\t\textraInputProps,\n\t\textraRootProps,\n\t\tinitialFiles,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrors,\n\t\tonUploadSuccess,\n\t\trender,\n\t\tvalidator,\n\t} = props ?? {};\n\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst initialFileArray = toArray(initialFiles).filter(Boolean);\n\n\tconst [dropZoneState, setDropZoneState] = useState<DropZoneState>({\n\t\terrors: [],\n\t\tfilesWithPreview: initialFileArray.map((fileMeta) => ({\n\t\t\tfile: fileMeta,\n\t\t\tid: fileMeta.id,\n\t\t\tpreview: fileMeta.url,\n\t\t})),\n\t\tisDragging: false,\n\t});\n\n\tconst toggleIsDragging = (value: boolean) => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, isDragging: value }));\n\t};\n\n\tconst addFiles: DropZoneActions[\"addFiles\"] = useCallbackRef((fileList, event) => {\n\t\tif (!fileList || fileList.length === 0) {\n\t\t\tconsole.warn(\"No file selected!\");\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear existing errors when new files are uploaded\n\t\tclearErrors();\n\n\t\t// In single file mode, clear existing files first\n\t\tif (!multiple) {\n\t\t\tclearFiles();\n\t\t}\n\n\t\tconst { errors, validFiles } = handleFileValidation({\n\t\t\texistingFiles: dropZoneState.filesWithPreview.map((fileWithPreview) => fileWithPreview.file),\n\t\t\tnewFiles: fileList,\n\t\t\tonError: onUploadError,\n\t\t\tonErrors: onUploadErrors,\n\t\t\tonSuccess: onUploadSuccess,\n\t\t\tvalidationSettings: { allowedFileTypes, disallowDuplicates, maxFileCount, maxFileSize },\n\t\t\tvalidator,\n\t\t});\n\n\t\tif (validFiles.length === 0) {\n\t\t\tsetDropZoneState((prevState) => ({ ...prevState, errors }));\n\t\t\treturn;\n\t\t}\n\n\t\tconst filesWithPreview: FileWithPreview[] = validFiles.map((file) => ({\n\t\t\tfile,\n\t\t\tid: generateUniqueId(file),\n\t\t\tpreview: createObjectURL(file, disallowPreviewForNonImageFiles),\n\t\t}));\n\n\t\t// == Only call onUpload callback if event is provided, which indicates that new files were uploaded from an event handler\n\n\t\tif (event) {\n\t\t\tonUpload?.({ event, filesWithPreview });\n\t\t}\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors,\n\t\t\t...(event?.type === \"drop\" && { isDragging: false }),\n\t\t\tfilesWithPreview: multiple\n\t\t\t\t? [...dropZoneState.filesWithPreview, ...filesWithPreview]\n\t\t\t\t: filesWithPreview,\n\t\t} satisfies DropZoneState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after adding files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst clearFiles: DropZoneActions[\"clearFiles\"] = useCallbackRef(() => {\n\t\t// == Clean up object URLs if any\n\t\tdropZoneState.filesWithPreview.forEach((fileWithPreview) =>\n\t\t\tclearObjectURL(fileWithPreview, disallowPreviewForNonImageFiles)\n\t\t);\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: [],\n\t\t} satisfies DropZoneState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after clearing files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst removeFile: DropZoneActions[\"removeFile\"] = useCallbackRef((fileToRemoveOrId) => {\n\t\tconst actualFileToRemove = isString(fileToRemoveOrId)\n\t\t\t? dropZoneState.filesWithPreview.find((file) => file.id === fileToRemoveOrId)\n\t\t\t: fileToRemoveOrId;\n\n\t\tif (!actualFileToRemove) return;\n\n\t\tclearObjectURL(actualFileToRemove, disallowPreviewForNonImageFiles);\n\n\t\tconst newFilesWithPreview = dropZoneState.filesWithPreview.filter(\n\t\t\t(file) => file.id !== actualFileToRemove.id\n\t\t);\n\n\t\tonFilesChange?.({ filesWithPreview: newFilesWithPreview });\n\n\t\tsetDropZoneState({\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: newFilesWithPreview,\n\t\t});\n\t});\n\n\tconst clearErrors: DropZoneActions[\"clearErrors\"] = useCallbackRef(() => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, errors: [] }));\n\t});\n\n\tconst handleFileUpload: DropZoneActions[\"handleFileUpload\"] = useCallbackRef((event) => {\n\t\tif (event.defaultPrevented) return;\n\n\t\tif (inputRef.current?.disabled) return;\n\n\t\tif (event.type === \"drop\") {\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t}\n\n\t\tconst fileList =\n\t\t\tevent.type === \"drop\"\n\t\t\t\t? (event as React.DragEvent).dataTransfer.files\n\t\t\t\t: (event as React.ChangeEvent<HTMLInputElement>).target.files;\n\n\t\t// == In single file mode, only use the first file\n\t\tif (!multiple) {\n\t\t\tconst firstFile = fileList?.[0];\n\n\t\t\tfirstFile && addFiles([firstFile], event);\n\n\t\t\treturn;\n\t\t}\n\n\t\taddFiles(fileList, event);\n\t});\n\n\tconst handleDragEnter: DropZoneActions[\"handleDragEnter\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragOver: DropZoneActions[\"handleDragOver\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragLeave: DropZoneActions[\"handleDragLeave\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(false);\n\t});\n\n\tconst openFilePicker: DropZoneActions[\"openFilePicker\"] = useCallbackRef(() => {\n\t\tinputRef.current?.click();\n\t});\n\n\tconst getRootProps: UseDropZoneResult[\"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\"relative isolate flex flex-col\",\n\t\t\t\t\tmergedRootProps.className,\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tdropZoneState.isDragging && [\n\t\t\t\t\t\t\"opacity-60\",\n\t\t\t\t\t\tclassNames?.isDragging,\n\t\t\t\t\t\trootProps?.classNames?.isDragging,\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"root\",\n\t\t\t\t\"data-slot\": \"dropzone-root\",\n\t\t\t\tonDragEnter: handleDragEnter,\n\t\t\t\tonDragLeave: handleDragLeave,\n\t\t\t\tonDragOver: handleDragOver,\n\t\t\t\tonDrop: handleFileUpload,\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclassNames?.base,\n\t\t\tclassNames?.isDragging,\n\t\t\textraRootProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleDragEnter,\n\t\t\thandleDragLeave,\n\t\t\thandleDragOver,\n\t\t\thandleFileUpload,\n\t\t]\n\t);\n\n\tconst getInputProps: UseDropZoneResult[\"getInputProps\"] = useCallback(\n\t\t(inputProps) => {\n\t\t\tconst mergedInputProps = mergeTwoProps(extraInputProps, inputProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedInputProps,\n\t\t\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : mergedInputProps.accept,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\t\t\tclassNames?.input,\n\t\t\t\t\tmergedInputProps.className\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"input\",\n\t\t\t\t\"data-slot\": \"dropzone-input\",\n\t\t\t\tmultiple: multiple ?? mergedInputProps.multiple,\n\t\t\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\t\t\tmergedInputProps.onChange?.(event);\n\t\t\t\t\thandleFileUpload(event);\n\t\t\t\t},\n\t\t\t\tref: composeRefs([inputRef, mergedInputProps.ref]),\n\t\t\t\ttype: \"file\",\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tallowedFileTypes,\n\t\t\tclassNames?.input,\n\t\t\textraInputProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleFileUpload,\n\t\t\tmultiple,\n\t\t]\n\t);\n\n\tconst renderProps = {\n\t\tdropZoneActions: {\n\t\t\taddFiles,\n\t\t\tclearErrors,\n\t\t\tclearFiles,\n\t\t\thandleDragEnter,\n\t\t\thandleDragLeave,\n\t\t\thandleDragOver,\n\t\t\thandleFileUpload,\n\t\t\topenFilePicker,\n\t\t\tremoveFile,\n\t\t},\n\t\tdropZoneState,\n\t\tgetInputProps,\n\t\tgetRootProps,\n\t\tinputRef,\n\t} satisfies RenderProps;\n\n\tconst selectedChildren = children ?? render;\n\n\tconst getResolvedChildren = () => {\n\t\treturn isFunction(selectedChildren) ? selectedChildren(renderProps) : selectedChildren;\n\t};\n\n\treturn {\n\t\t...renderProps,\n\t\tgetResolvedChildren,\n\t};\n};\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport {\n\ttype GetSlotComponentProps,\n\tgetSlotMap,\n\twithSlotNameAndSymbol,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\nimport { type UseDropZoneProps, useDropZone } from \"./use-drop-zone\";\n\ntype DropZoneProps = UseDropZoneProps & {\n\t/**\n\t * Controls whether to include internal elements (root and input) or not.\n\t */\n\twithInternalElements?: boolean;\n};\n\nexport function DropZoneRoot(props: DropZoneProps) {\n\tconst { withInternalElements = true, ...restOfProps } = props;\n\n\tconst api = useDropZone(restOfProps);\n\n\tconst RootComponent = withInternalElements ? \"div\" : ReactFragment;\n\tconst InputComponent = withInternalElements ? \"input\" : ReactFragment;\n\n\tconst rootComponentProps = RootComponent === \"div\" && api.getRootProps();\n\tconst inputComponentProps = InputComponent === \"input\" && api.getInputProps();\n\n\tconst resolvedChildren = api.getResolvedChildren();\n\n\t/**\n\t * Whether the children could contain slots.\n\t */\n\tconst couldChildrenContainSlots =\n\t\tisArray(resolvedChildren)\n\t\t|| (isValidElement(resolvedChildren) && resolvedChildren.type === ReactFragment);\n\n\tconst slots = getSlotMap<SlotComponentProps>(resolvedChildren, {\n\t\tcondition: withInternalElements && couldChildrenContainSlots,\n\t});\n\n\treturn (\n\t\t<>\n\t\t\t<RootComponent {...rootComponentProps}>\n\t\t\t\t<InputComponent {...inputComponentProps} />\n\n\t\t\t\t{slots.default}\n\t\t\t</RootComponent>\n\n\t\t\t{slots.preview}\n\t\t</>\n\t);\n}\n\ntype SlotComponentProps = GetSlotComponentProps<\"preview\">;\n\nexport const DropZoneImagePreview = withSlotNameAndSymbol<SlotComponentProps>(\"preview\");\n","export { DropZoneRoot as Root, DropZoneImagePreview as ImagePreview } from \"./drop-zone\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/ui-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.5",
|
|
5
5
|
"description": "A composable UI/UI-utilities components library. ",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@zayne-labs/toolkit-core": "0.9.
|
|
57
|
-
"@zayne-labs/toolkit-react": "0.9.
|
|
58
|
-
"@zayne-labs/toolkit-type-helpers": "0.9.
|
|
56
|
+
"@zayne-labs/toolkit-core": "0.9.24",
|
|
57
|
+
"@zayne-labs/toolkit-react": "0.9.24",
|
|
58
|
+
"@zayne-labs/toolkit-type-helpers": "0.9.24",
|
|
59
59
|
"tailwind-merge": "3.2.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|