@zayne-labs/ui-react 0.10.51 → 0.10.53
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/chunk-pbuEa-1d.js +13 -0
- package/dist/esm/{cn-2hIN1AQ7.js → cn-Bbh2G587.js} +2 -3
- package/dist/esm/cn-Bbh2G587.js.map +1 -0
- package/dist/esm/common/await/index.d.ts +3 -5
- package/dist/esm/common/await/index.js +4 -8
- package/dist/esm/common/await/index.js.map +1 -1
- package/dist/esm/common/client-gate/index.d.ts +1 -1
- package/dist/esm/common/client-gate/index.js +29 -3
- package/dist/esm/common/client-gate/index.js.map +1 -0
- package/dist/esm/common/error-boundary/index.d.ts +2 -2
- package/dist/esm/common/error-boundary/index.js +2 -4
- package/dist/esm/common/for/index.d.ts +4 -3
- package/dist/esm/common/for/index.js +2 -3
- package/dist/esm/common/presence/index.d.ts +1 -1
- package/dist/esm/common/presence/index.js +2 -4
- package/dist/esm/common/show/index.d.ts +4 -4
- package/dist/esm/common/show/index.js +2 -4
- package/dist/esm/common/slot/index.js +2 -3
- package/dist/esm/common/suspense-with-boundary/index.d.ts +1 -2
- package/dist/esm/common/suspense-with-boundary/index.js +2 -3
- package/dist/esm/common/suspense-with-boundary/index.js.map +1 -1
- package/dist/esm/common/switch/index.d.ts +3 -3
- package/dist/esm/common/switch/index.js +2 -5
- package/dist/esm/common/switch/index.js.map +1 -1
- package/dist/esm/common/teleport/index.d.ts +3 -3
- package/dist/esm/common/teleport/index.js +2 -3
- package/dist/esm/common/teleport/index.js.map +1 -1
- package/dist/esm/{useErrorBoundary-CIUZVY-G.js → error-boundary-C4btQhu_.js} +2 -5
- package/dist/esm/error-boundary-C4btQhu_.js.map +1 -0
- package/dist/esm/{getElementList-CtQvQXjS.js → for-DGTMIS0w.js} +2 -4
- package/dist/esm/for-DGTMIS0w.js.map +1 -0
- package/dist/esm/{useErrorBoundary-DhOgXZDB.d.ts → index-BUIvQ2wP.d.ts} +6 -2
- package/dist/esm/{suspense-with-boundary-CAT0Jm5m.d.ts → index-ClV6w6nv.d.ts} +2 -2
- package/dist/esm/{presence-BjbQUjhT.js → presence-CWOGx-be.js} +9 -11
- package/dist/esm/{presence-BjbQUjhT.js.map → presence-CWOGx-be.js.map} +1 -1
- package/dist/esm/{show-parts-BsJLZhNL.js → show-BzfAw7y3.js} +3 -5
- package/dist/esm/show-BzfAw7y3.js.map +1 -0
- package/dist/esm/{slot-parts-Da1BsS7u.js → slot-DuwoiC2C.js} +19 -14
- package/dist/esm/slot-DuwoiC2C.js.map +1 -0
- package/dist/esm/ui/card/index.js +5 -7
- package/dist/esm/ui/card/index.js.map +1 -1
- package/dist/esm/ui/carousel/index.js +5 -11
- package/dist/esm/ui/carousel/index.js.map +1 -1
- package/dist/esm/ui/drag-scroll/index.d.ts +0 -1
- package/dist/esm/ui/drag-scroll/index.js +24 -27
- package/dist/esm/ui/drag-scroll/index.js.map +1 -1
- package/dist/esm/ui/drop-zone/index.d.ts +39 -40
- package/dist/esm/ui/drop-zone/index.js +7 -15
- package/dist/esm/ui/drop-zone/index.js.map +1 -1
- package/dist/esm/ui/form/index.d.ts +35 -43
- package/dist/esm/ui/form/index.js +13 -19
- package/dist/esm/ui/form/index.js.map +1 -1
- package/dist/style.css +9 -9
- package/package.json +18 -19
- package/dist/esm/chunk-BYypO7fO.js +0 -18
- package/dist/esm/client-gate-BhR-cK58.js +0 -31
- package/dist/esm/client-gate-BhR-cK58.js.map +0 -1
- package/dist/esm/cn-2hIN1AQ7.js.map +0 -1
- package/dist/esm/getElementList-CtQvQXjS.js.map +0 -1
- package/dist/esm/show-parts-BsJLZhNL.js.map +0 -1
- package/dist/esm/slot-parts-Da1BsS7u.js.map +0 -1
- package/dist/esm/useErrorBoundary-CIUZVY-G.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"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"],"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\" | \"usage\">;\n\nexport const createDragScrollStore = <TElement extends HTMLElement = HTMLElement>(\n\tinitStoreValues: InitStoreValues\n) => {\n\tconst { orientation = \"horizontal\", scrollAmount = \"item\", usage = \"allScreens\" } = initStoreValues;\n\n\tconst containerRef: React.RefObject<TElement | null> = { current: null };\n\tconst positionRef = { left: 0, top: 0, x: 0, y: 0 };\n\n\tconst abortControllers = {\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: TElement): 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<TElement>>((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\tabortControllers.current.mouseMove.abort();\n\t\t\t\tabortControllers.current.mouseUp.abort();\n\t\t\t\tabortControllers.current.mouseLeave.abort();\n\t\t\t},\n\n\t\t\tgoToNext: () => {\n\t\t\t\tif (!containerRef.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(containerRef.current);\n\n\t\t\t\tcontainerRef.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 (!containerRef.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(containerRef.current);\n\n\t\t\t\tcontainerRef.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 (usage === \"mobileAndTabletOnly\" && window.innerWidth >= 768) return;\n\t\t\t\tif (usage === \"desktopOnly\" && window.innerWidth < 768) return;\n\n\t\t\t\tif (!containerRef.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\tabortControllers.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.x = event.clientX;\n\t\t\t\t\tpositionRef.left = containerRef.current.scrollLeft;\n\t\t\t\t}\n\n\t\t\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t\t\tpositionRef.y = event.clientY;\n\t\t\t\t\tpositionRef.top = containerRef.current.scrollTop;\n\t\t\t\t}\n\n\t\t\t\tupdateCursor(containerRef.current);\n\t\t\t\tset({ isDragging: true });\n\n\t\t\t\tconst { actions } = get();\n\n\t\t\t\ton(\"mousemove\", containerRef.current, actions.handleMouseMove, {\n\t\t\t\t\tsignal: abortControllers.current.mouseMove.signal,\n\t\t\t\t});\n\t\t\t\ton(\"mouseup\", containerRef.current, actions.handleMouseUpOrLeave, {\n\t\t\t\t\tsignal: abortControllers.current.mouseUp.signal,\n\t\t\t\t});\n\t\t\t\ton(\"mouseleave\", containerRef.current, actions.handleMouseUpOrLeave, {\n\t\t\t\t\tsignal: abortControllers.current.mouseLeave.signal,\n\t\t\t\t});\n\n\t\t\t\t// == Document-level mouseup fallback for when user releases outside the container\n\t\t\t\ton(\"mouseup\", document, actions.handleMouseUpOrLeave, {\n\t\t\t\t\tonce: true,\n\t\t\t\t\tsignal: abortControllers.current.mouseUp.signal,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\thandleMouseMove: (event) => {\n\t\t\t\tif (!containerRef.current) return;\n\n\t\t\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t\t\tconst dx = event.clientX - positionRef.x;\n\t\t\t\t\tcontainerRef.current.scrollLeft = positionRef.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.y;\n\t\t\t\t\tcontainerRef.current.scrollTop = positionRef.top - dy;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\thandleMouseUpOrLeave: () => {\n\t\t\t\tif (!containerRef.current) return;\n\n\t\t\t\tresetCursor(containerRef.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 (!containerRef.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(containerRef.current);\n\n\t\t\t\t// == Also observe children for size changes\n\t\t\t\tfor (const child of containerRef.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\tsetContainerRef: (element) => {\n\t\t\t\tcontainerRef.current = element;\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 (!containerRef.current) return;\n\n\t\t\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t\t\tconst { clientWidth, scrollLeft, scrollWidth } = containerRef.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 } = containerRef.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 { createDragScrollStore } from \"./drag-scroll-store\";\nimport type { DragScrollPropGetters, UseDragScrollProps, UseDragScrollResult } from \"./types\";\n\nconst getScopeAttrs = (part: string) =>\n\t({\n\t\t\"data-part\": part,\n\t\t\"data-scope\": \"drag-scroll\",\n\t\t\"data-slot\": `drag-scroll-${part}`,\n\t}) as const;\n\nexport const useDragScroll = <TElement extends HTMLElement>(\n\tprops?: UseDragScrollProps\n): UseDragScrollResult<TElement> => {\n\tconst {\n\t\tclassNames,\n\t\tdisableInternalStateSubscription = false,\n\t\torientation = \"horizontal\",\n\t\tscrollAmount = \"item\",\n\t\tusage = \"allScreens\",\n\t} = props ?? {};\n\n\tconst containerRef = useRef<TElement>(null);\n\n\tconst storeApi = useMemo(() => {\n\t\treturn createDragScrollStore<TElement>({ orientation, scrollAmount, usage });\n\t}, [orientation, scrollAmount, usage]);\n\n\tconst actions = storeApi.getState().actions;\n\n\t/* eslint-disable react-hooks/hooks -- ignore */\n\tconst useDragScrollStore: UseDragScrollResult<TElement>[\"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<TElement> = useCallbackRef((node) => {\n\t\tcontainerRef.current = node;\n\t\tactions.setContainerRef(node);\n\n\t\tif (!node) return;\n\n\t\tconst cleanupMouseDown = on(\"mousedown\", node, actions.handleMouseDown);\n\t\tconst cleanupScroll = on(\"scroll\", node as never, actions.handleScroll as never, {\n\t\t\tpassive: true,\n\t\t});\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<TElement>[\"getRootProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"root\"),\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\t...innerProps,\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\tusage === \"mobileAndTabletOnly\" && \"md:cursor-default md:flex-col\",\n\t\t\t\t\tusage === \"desktopOnly\" && \"max-md:cursor-default max-md:flex-col\",\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tinnerProps?.className\n\t\t\t\t),\n\t\t\t\tref: composeRefs(refCallback, innerProps?.ref),\n\t\t\t} as never;\n\t\t},\n\t\t[classNames?.base, disableInternalStateSubscription, isDragging, orientation, refCallback, usage]\n\t);\n\n\tconst getItemProps: DragScrollPropGetters<TElement>[\"getItemProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"item\"),\n\t\t\t\t...innerProps,\n\t\t\t\tclassName: cnMerge(\"snap-center snap-always\", classNames?.item, innerProps?.className),\n\t\t\t};\n\t\t},\n\t\t[classNames?.item]\n\t);\n\n\tconst getBackButtonProps: DragScrollPropGetters<TElement>[\"getBackButtonProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst isDisabled = innerProps?.disabled ?? !canGoToPrev;\n\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"back-button\"),\n\t\t\t\ttype: \"button\",\n\t\t\t\t...innerProps,\n\t\t\t\t\"aria-disabled\": dataAttr(isDisabled),\n\t\t\t\t\"aria-label\": innerProps?.[\"aria-label\"] ?? \"Scroll back\",\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};\n\t\t},\n\t\t[actions.goToPrev, canGoToPrev]\n\t);\n\n\tconst getNextButtonProps: DragScrollPropGetters<TElement>[\"getNextButtonProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst isDisabled = innerProps?.disabled ?? !canGoToNext;\n\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"next-button\"),\n\t\t\t\ttype: \"button\",\n\t\t\t\t...innerProps,\n\t\t\t\t\"aria-disabled\": dataAttr(isDisabled),\n\t\t\t\t\"aria-label\": innerProps?.[\"aria-label\"] ?? \"Scroll forward\",\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};\n\t\t},\n\t\t[actions.goToNext, canGoToNext]\n\t);\n\n\tconst propGetters = useMemo<DragScrollPropGetters<TElement>>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tgetBackButtonProps,\n\t\t\t\tgetItemProps,\n\t\t\t\tgetNextButtonProps,\n\t\t\t\tgetRootProps,\n\t\t\t}) satisfies DragScrollPropGetters<TElement>,\n\t\t[getBackButtonProps, getItemProps, getNextButtonProps, getRootProps]\n\t);\n\n\tconst stableUseDragScrollStore = useCallbackRef(useDragScrollStore);\n\n\tconst result = useMemo<UseDragScrollResult<TElement>>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tcontainerRef,\n\t\t\t\tdisableInternalStateSubscription,\n\t\t\t\tpropGetters,\n\t\t\t\tstoreApi,\n\t\t\t\tuseDragScrollStore: stableUseDragScrollStore,\n\t\t\t}) satisfies UseDragScrollResult<TElement>,\n\t\t[propGetters, disableInternalStateSubscription, storeApi, stableUseDragScrollStore]\n\t);\n\n\treturn result;\n};\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;;AAI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B,yCAC3B,YAAY,MACZ,YAAY,UACZ;GACD,KAAK,YAAY,aAAa,YAAY,IAAI;GAC9C;IAEF;EAAC,YAAY;EAAM;EAAkC;EAAY;EAAa;EAAa;EAAM,CACjG;CAED,MAAM,eAAgE,aACpE,eAAe;AACf,SAAO;GACN,GAAG,cAAc,OAAO;GACxB,GAAG;GACH,WAAW,QAAQ,2BAA2B,YAAY,MAAM,YAAY,UAAU;GACtF;IAEF,CAAC,YAAY,KAAK,CAClB;CAED,MAAM,qBAA4E,aAChF,eAAe;EACf,MAAM,aAAa,YAAY,YAAY,CAAC;AAE5C,SAAO;GACN,GAAG,cAAc,cAAc;GAC/B,MAAM;GACN,GAAG;GACH,iBAAiB,SAAS,WAAW;GACrC,cAAc,aAAa,iBAAiB;GAC5C,iBAAiB,SAAS,WAAW;GACrC,UAAU;GACV,SAAS,wBAAwB,QAAQ,UAAU,YAAY,QAAQ;GACvE;IAEF,CAAC,QAAQ,UAAU,YAAY,CAC/B;CAED,MAAM,qBAA4E,aAChF,eAAe;EACf,MAAM,aAAa,YAAY,YAAY,CAAC;AAE5C,SAAO;GACN,GAAG,cAAc,cAAc;GAC/B,MAAM;GACN,GAAG;GACH,iBAAiB,SAAS,WAAW;GACrC,cAAc,aAAa,iBAAiB;GAC5C,iBAAiB,SAAS,WAAW;GACrC,UAAU;GACV,SAAS,wBAAwB,QAAQ,UAAU,YAAY,QAAQ;GACvE;IAEF,CAAC,QAAQ,UAAU,YAAY,CAC/B;CAED,MAAM,cAAc,eAEjB;EACA;EACA;EACA;EACA;EACA,GACF;EAAC;EAAoB;EAAc;EAAoB;EAAa,CACpE;CAED,MAAM,2BAA2B,eAAe,mBAAmB;AAcnE,QAZe,eAEZ;EACA;EACA;EACA;EACA;EACA,oBAAoB;EACpB,GACF;EAAC;EAAa;EAAkC;EAAU;EAAyB,CACnF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"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"],"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\" | \"usage\">;\n\nexport const createDragScrollStore = <TElement extends HTMLElement = HTMLElement>(\n\tinitStoreValues: InitStoreValues\n) => {\n\tconst { orientation = \"horizontal\", scrollAmount = \"item\", usage = \"allScreens\" } = initStoreValues;\n\n\tconst containerRef: React.RefObject<TElement | 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: TElement): 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<TElement>>((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 (!containerRef.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(containerRef.current);\n\n\t\t\t\tcontainerRef.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 (!containerRef.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(containerRef.current);\n\n\t\t\t\tcontainerRef.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 (usage === \"mobileAndTabletOnly\" && window.innerWidth >= 768) return;\n\t\t\t\tif (usage === \"desktopOnly\" && window.innerWidth < 768) return;\n\n\t\t\t\tif (!containerRef.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 = containerRef.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 = containerRef.current.scrollTop;\n\t\t\t\t}\n\n\t\t\t\tupdateCursor(containerRef.current);\n\t\t\t\tset({ isDragging: true });\n\n\t\t\t\tconst { actions } = get();\n\n\t\t\t\ton(containerRef.current, \"mousemove\", actions.handleMouseMove, {\n\t\t\t\t\tsignal: abortControllerRef.current.mouseMove.signal,\n\t\t\t\t});\n\t\t\t\ton(containerRef.current, \"mouseup\", actions.handleMouseUpOrLeave, {\n\t\t\t\t\tsignal: abortControllerRef.current.mouseUp.signal,\n\t\t\t\t});\n\t\t\t\ton(containerRef.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 (!containerRef.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\tcontainerRef.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\tcontainerRef.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 (!containerRef.current) return;\n\n\t\t\t\tresetCursor(containerRef.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 (!containerRef.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(containerRef.current);\n\n\t\t\t\t// == Also observe children for size changes\n\t\t\t\tfor (const child of containerRef.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\tsetContainerRef: (element) => {\n\t\t\t\tcontainerRef.current = element;\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 (!containerRef.current) return;\n\n\t\t\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t\t\tconst { clientWidth, scrollLeft, scrollWidth } = containerRef.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 } = containerRef.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 { createDragScrollStore } from \"./drag-scroll-store\";\nimport type { DragScrollPropGetters, UseDragScrollProps, UseDragScrollResult } from \"./types\";\n\nconst getScopeAttrs = (part: string) =>\n\t({\n\t\t\"data-part\": part,\n\t\t\"data-scope\": \"drag-scroll\",\n\t\t\"data-slot\": `drag-scroll-${part}`,\n\t}) as const;\n\nexport const useDragScroll = <TElement extends HTMLElement>(\n\tprops?: UseDragScrollProps\n): UseDragScrollResult<TElement> => {\n\tconst {\n\t\tclassNames,\n\t\tdisableInternalStateSubscription = false,\n\t\torientation = \"horizontal\",\n\t\tscrollAmount = \"item\",\n\t\tusage = \"allScreens\",\n\t} = props ?? {};\n\n\tconst containerRef = useRef<TElement>(null);\n\n\tconst storeApi = useMemo(() => {\n\t\treturn createDragScrollStore<TElement>({ orientation, scrollAmount, usage });\n\t}, [orientation, scrollAmount, usage]);\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<TElement>[\"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<TElement> = useCallbackRef((node) => {\n\t\tcontainerRef.current = node;\n\t\tactions.setContainerRef(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, {\n\t\t\tpassive: true,\n\t\t});\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<TElement>[\"getRootProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"root\"),\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\t...innerProps,\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\tusage === \"mobileAndTabletOnly\" && \"md:cursor-default md:flex-col\",\n\t\t\t\t\tusage === \"desktopOnly\" && \"max-md:cursor-default max-md:flex-col\",\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tinnerProps?.className\n\t\t\t\t),\n\t\t\t\tref: composeRefs(refCallback, innerProps?.ref),\n\t\t\t} as never;\n\t\t},\n\t\t[classNames?.base, disableInternalStateSubscription, isDragging, orientation, refCallback, usage]\n\t);\n\n\tconst getItemProps: DragScrollPropGetters<TElement>[\"getItemProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"item\"),\n\t\t\t\t...innerProps,\n\t\t\t\tclassName: cnMerge(\"snap-center snap-always\", classNames?.item, innerProps?.className),\n\t\t\t};\n\t\t},\n\t\t[classNames?.item]\n\t);\n\n\tconst getBackButtonProps: DragScrollPropGetters<TElement>[\"getBackButtonProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst isDisabled = innerProps?.disabled ?? !canGoToPrev;\n\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"back-button\"),\n\t\t\t\ttype: \"button\",\n\t\t\t\t...innerProps,\n\t\t\t\t\"aria-disabled\": dataAttr(isDisabled),\n\t\t\t\t\"aria-label\": innerProps?.[\"aria-label\"] ?? \"Scroll back\",\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};\n\t\t},\n\t\t[actions.goToPrev, canGoToPrev]\n\t);\n\n\tconst getNextButtonProps: DragScrollPropGetters<TElement>[\"getNextButtonProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst isDisabled = innerProps?.disabled ?? !canGoToNext;\n\n\t\t\treturn {\n\t\t\t\t...getScopeAttrs(\"next-button\"),\n\t\t\t\ttype: \"button\",\n\t\t\t\t...innerProps,\n\t\t\t\t\"aria-disabled\": dataAttr(isDisabled),\n\t\t\t\t\"aria-label\": innerProps?.[\"aria-label\"] ?? \"Scroll forward\",\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};\n\t\t},\n\t\t[actions.goToNext, canGoToNext]\n\t);\n\n\tconst propGetters = useMemo<DragScrollPropGetters<TElement>>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tgetBackButtonProps,\n\t\t\t\tgetItemProps,\n\t\t\t\tgetNextButtonProps,\n\t\t\t\tgetRootProps,\n\t\t\t}) satisfies DragScrollPropGetters<TElement>,\n\t\t[getBackButtonProps, getItemProps, getNextButtonProps, getRootProps]\n\t);\n\n\tconst stableUseDragScrollStore = useCallbackRef(useDragScrollStore);\n\n\tconst result = useMemo<UseDragScrollResult<TElement>>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tcontainerRef,\n\t\t\t\tdisableInternalStateSubscription,\n\t\t\t\tpropGetters,\n\t\t\t\tstoreApi,\n\t\t\t\tuseDragScrollStore: stableUseDragScrollStore,\n\t\t\t}) satisfies UseDragScrollResult<TElement>,\n\t\t[propGetters, disableInternalStateSubscription, storeApi, stableUseDragScrollStore]\n\t);\n\n\treturn result;\n};\n"],"mappings":";;;;;;;AAGA,MAAa,gBAA8C,YAAsB;AAChF,SAAQ,MAAM,SAAS;AACvB,SAAQ,MAAM,aAAa;;AAG5B,MAAa,gBACZ,QACA,YACI;AACJ,KA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EAAa,CACpE;CAED,MAAM,2BAA2B,eAAe,mBAAmB;AAcnE,QAZe,eAEZ;EACA;EACA;EACA;EACA;EACA,oBAAoB;EACpB,GACF;EAAC;EAAa;EAAkC;EAAU;EAAyB,CACnF"}
|
|
@@ -2,7 +2,6 @@ import { InferProps, PolymorphicPropsStrict } from "@zayne-labs/toolkit-react/ut
|
|
|
2
2
|
import * as _zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
|
|
3
3
|
import { Awaitable, SelectorFn, UnionDiscriminator } from "@zayne-labs/toolkit-type-helpers";
|
|
4
4
|
import * as react from "react";
|
|
5
|
-
import "@zayne-labs/toolkit-react";
|
|
6
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
7
6
|
import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
8
7
|
import { FileMeta, FileOrFileMeta, FileValidationErrorContextEach, FileValidationHooksAsync, FileValidationSettingsAsync } from "@zayne-labs/toolkit-core";
|
|
@@ -91,47 +90,47 @@ type SharedInputProps = {
|
|
|
91
90
|
interface PartProps {
|
|
92
91
|
container: {
|
|
93
92
|
input: PartProps["container"]["output"] & SharedInputProps;
|
|
94
|
-
output: InferProps<HTMLElement
|
|
93
|
+
output: RecordForDataAttr & InferProps<HTMLElement>;
|
|
95
94
|
};
|
|
96
95
|
fileItem: {
|
|
97
96
|
input: PartProps["fileItem"]["output"] & SharedInputProps;
|
|
98
|
-
output: InferProps<"li"
|
|
97
|
+
output: RecordForDataAttr & InferProps<"li">;
|
|
99
98
|
};
|
|
100
99
|
fileItemClear: {
|
|
101
100
|
input: PartProps["fileItemClear"]["output"];
|
|
102
|
-
output: InferProps<"button"
|
|
101
|
+
output: RecordForDataAttr & InferProps<"button">;
|
|
103
102
|
};
|
|
104
103
|
fileItemDelete: {
|
|
105
104
|
input: Partial<FileStateOrIDProp> & PartProps["fileItemDelete"]["output"];
|
|
106
|
-
output: InferProps<"button"
|
|
105
|
+
output: RecordForDataAttr & InferProps<"button">;
|
|
107
106
|
};
|
|
108
107
|
fileItemMetadata: {
|
|
109
|
-
input: PartProps["fileItemMetadata"]["output"]
|
|
110
|
-
output: InferProps<"div"
|
|
108
|
+
input: SharedInputProps & PartProps["fileItemMetadata"]["output"];
|
|
109
|
+
output: RecordForDataAttr & InferProps<"div">;
|
|
111
110
|
};
|
|
112
111
|
fileItemPreview: {
|
|
113
|
-
input: PartProps["fileItemPreview"]["output"]
|
|
114
|
-
output: InferProps<"span"
|
|
112
|
+
input: SharedInputProps & PartProps["fileItemPreview"]["output"];
|
|
113
|
+
output: RecordForDataAttr & InferProps<"span">;
|
|
115
114
|
};
|
|
116
115
|
fileItemProgress: {
|
|
117
|
-
input:
|
|
116
|
+
input: SharedInputProps & {
|
|
118
117
|
variant?: "circular" | "fill" | "linear";
|
|
119
|
-
};
|
|
120
|
-
output: InferProps<"span"
|
|
118
|
+
} & PartProps["fileItemProgress"]["output"];
|
|
119
|
+
output: RecordForDataAttr & InferProps<"span">;
|
|
121
120
|
};
|
|
122
121
|
fileList: {
|
|
123
|
-
input:
|
|
122
|
+
input: SharedInputProps & {
|
|
124
123
|
orientation?: "horizontal" | "vertical";
|
|
125
|
-
};
|
|
126
|
-
output: InferProps<"ul"
|
|
124
|
+
} & PartProps["fileList"]["output"];
|
|
125
|
+
output: RecordForDataAttr & InferProps<"ul">;
|
|
127
126
|
};
|
|
128
127
|
input: {
|
|
129
128
|
input: PartProps["input"]["output"];
|
|
130
|
-
output: InferProps<"input"
|
|
129
|
+
output: RecordForDataAttr & InferProps<"input">;
|
|
131
130
|
};
|
|
132
131
|
trigger: {
|
|
133
132
|
input: PartProps["trigger"]["output"];
|
|
134
|
-
output: InferProps<"button"
|
|
133
|
+
output: RecordForDataAttr & InferProps<"button">;
|
|
135
134
|
};
|
|
136
135
|
}
|
|
137
136
|
type DropZonePropGetters = { [Key in keyof PartProps as `get${Capitalize<Key>}Props`]: (props: PartProps[Key]["input"]) => PartProps[Key]["output"] };
|
|
@@ -309,22 +308,22 @@ type DropZoneContextProps<TSlice> = {
|
|
|
309
308
|
selector?: SelectorFn<DropZoneStore, TSlice>;
|
|
310
309
|
};
|
|
311
310
|
declare function DropZoneContext<TSlice = DropZoneStore>(props: DropZoneContextProps<TSlice>): react.ReactNode;
|
|
312
|
-
type DropZoneContainerProps =
|
|
311
|
+
type DropZoneContainerProps = {
|
|
313
312
|
asChild?: boolean;
|
|
314
|
-
};
|
|
313
|
+
} & PartInputProps["container"];
|
|
315
314
|
declare function DropZoneContainer<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, DropZoneContainerProps>): react_jsx_runtime0.JSX.Element;
|
|
316
|
-
type DropZoneInputProps =
|
|
315
|
+
type DropZoneInputProps = {
|
|
317
316
|
asChild?: boolean;
|
|
318
|
-
};
|
|
317
|
+
} & PartInputProps["input"];
|
|
319
318
|
declare function DropZoneInput(props: DropZoneInputProps): react_jsx_runtime0.JSX.Element;
|
|
320
|
-
type DropZoneAreaProps<TSlice> = DropZoneContextProps<TSlice> &
|
|
319
|
+
type DropZoneAreaProps<TSlice = DropZoneStore> = DropZoneContextProps<TSlice> & {
|
|
321
320
|
classNames?: Partial<Record<Extract<keyof PartInputProps, "container" | "input">, string>>;
|
|
322
321
|
extraProps?: Partial<Pick<PartInputProps, "container" | "input">>;
|
|
323
|
-
};
|
|
322
|
+
} & PartInputProps["container"];
|
|
324
323
|
declare function DropZoneArea<TSlice = DropZoneStore>(props: DropZoneAreaProps<TSlice>): react_jsx_runtime0.JSX.Element;
|
|
325
|
-
type DropZoneTriggerProps =
|
|
324
|
+
type DropZoneTriggerProps = {
|
|
326
325
|
asChild?: boolean;
|
|
327
|
-
};
|
|
326
|
+
} & PartInputProps["trigger"];
|
|
328
327
|
declare function DropZoneTrigger(props: DropZoneTriggerProps): react_jsx_runtime0.JSX.Element;
|
|
329
328
|
type ListPerItemContext = Pick<DropZoneStore, "actions"> & {
|
|
330
329
|
array: DropZoneStore["fileStateArray"];
|
|
@@ -340,24 +339,24 @@ type FileListManualListVariant = {
|
|
|
340
339
|
children: React.ReactNode | ((context: ListManualListContext) => React.ReactNode);
|
|
341
340
|
renderMode: "manual-list";
|
|
342
341
|
};
|
|
343
|
-
type DropZoneFileListProps =
|
|
342
|
+
type DropZoneFileListProps = {
|
|
344
343
|
asChild?: boolean;
|
|
345
344
|
forceMount?: boolean;
|
|
346
|
-
} & (FileListManualListVariant | FileListPerItemVariant)
|
|
345
|
+
} & (FileListManualListVariant | FileListPerItemVariant) & Omit<PartInputProps["fileList"], "children">;
|
|
347
346
|
declare function DropZoneFileList<TElement extends React.ElementType = "ul">(props: PolymorphicPropsStrict<TElement, DropZoneFileListProps>): react_jsx_runtime0.JSX.Element;
|
|
348
|
-
type DropZoneFileItemProps = FileItemContextType &
|
|
347
|
+
type DropZoneFileItemProps = FileItemContextType & {
|
|
349
348
|
asChild?: boolean;
|
|
350
|
-
};
|
|
349
|
+
} & PartInputProps["fileItem"];
|
|
351
350
|
declare function DropZoneFileItem<TElement extends React.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProps>): react_jsx_runtime0.JSX.Element;
|
|
352
|
-
type DropZoneFileItemDeleteProps =
|
|
351
|
+
type DropZoneFileItemDeleteProps = {
|
|
353
352
|
asChild?: boolean;
|
|
354
|
-
};
|
|
353
|
+
} & PartInputProps["fileItemDelete"];
|
|
355
354
|
declare function DropZoneFileItemDelete(props: DropZoneFileItemDeleteProps): react_jsx_runtime0.JSX.Element;
|
|
356
|
-
type DropZoneFileItemProgressProps =
|
|
355
|
+
type DropZoneFileItemProgressProps = {
|
|
357
356
|
asChild?: boolean;
|
|
358
357
|
forceMount?: boolean;
|
|
359
358
|
size?: number;
|
|
360
|
-
};
|
|
359
|
+
} & PartInputProps["fileItemProgress"];
|
|
361
360
|
declare function DropZoneFileItemProgress<TElement extends React.ElementType = "span">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProgressProps>): react_jsx_runtime0.JSX.Element | null;
|
|
362
361
|
type NodeCtx<TElement extends React.ElementType> = {
|
|
363
362
|
getProps: (innerProps: Partial<InferProps<TElement>>) => InferProps<TElement>;
|
|
@@ -383,15 +382,15 @@ type RenderPreviewObject = {
|
|
|
383
382
|
};
|
|
384
383
|
type RenderPreviewFn = (context: RenderPropContext) => RenderPreviewObject;
|
|
385
384
|
type RenderPreview = RenderPreviewFn | RenderPreviewObject;
|
|
386
|
-
type DropZoneFileItemPreviewProps =
|
|
385
|
+
type DropZoneFileItemPreviewProps = Partial<Pick<FileItemContextType, "fileState">> & {
|
|
387
386
|
asChild?: boolean;
|
|
388
387
|
children?: React.ReactNode | ((context: RenderPropContext & {
|
|
389
388
|
fallbackPreview: () => React.ReactNode;
|
|
390
389
|
}) => React.ReactNode);
|
|
391
390
|
renderPreview?: boolean | RenderPreview;
|
|
392
|
-
}
|
|
391
|
+
} & Omit<PartInputProps["fileItemPreview"], "children">;
|
|
393
392
|
declare function DropZoneFileItemPreview<TElement extends React.ElementType>(props: PolymorphicPropsStrict<TElement, DropZoneFileItemPreviewProps>): react_jsx_runtime0.JSX.Element | null;
|
|
394
|
-
type DropZoneFileItemMetadataProps =
|
|
393
|
+
type DropZoneFileItemMetadataProps = Partial<Pick<FileItemContextType, "fileState">> & {
|
|
395
394
|
asChild?: boolean;
|
|
396
395
|
children?: React.ReactNode | ((context: Pick<FileItemContextType, "fileState">) => React.ReactNode);
|
|
397
396
|
classNames?: {
|
|
@@ -399,12 +398,12 @@ type DropZoneFileItemMetadataProps = Omit<PartInputProps["fileItemMetadata"], "c
|
|
|
399
398
|
size?: string;
|
|
400
399
|
};
|
|
401
400
|
size?: "default" | "sm";
|
|
402
|
-
}
|
|
401
|
+
} & Omit<PartInputProps["fileItemMetadata"], "children">;
|
|
403
402
|
declare function DropZoneFileItemMetadata(props: DropZoneFileItemMetadataProps): react_jsx_runtime0.JSX.Element | null;
|
|
404
|
-
type DropZoneFileClearProps =
|
|
403
|
+
type DropZoneFileClearProps = {
|
|
405
404
|
asChild?: boolean;
|
|
406
405
|
forceMount?: boolean;
|
|
407
|
-
};
|
|
406
|
+
} & PartInputProps["fileItemClear"];
|
|
408
407
|
declare function DropZoneFileClear(props: DropZoneFileClearProps): react_jsx_runtime0.JSX.Element | null;
|
|
409
408
|
declare namespace drop_zone_parts_d_exports {
|
|
410
409
|
export { DropZoneArea as Area, DropZoneContainer as Container, DropZoneContext as Context, DropZoneFileClear as FileClear, DropZoneFileItem as FileItem, DropZoneFileItemDelete as FileItemDelete, DropZoneFileItemMetadata as FileItemMetadata, DropZoneFileItemPreview as FileItemPreview, DropZoneFileItemProgress as FileItemProgress, DropZoneFileList as FileList, DropZoneInput as Input, DropZoneRoot as Root, DropZoneTrigger as Trigger };
|
|
@@ -413,5 +412,5 @@ declare namespace drop_zone_parts_d_exports {
|
|
|
413
412
|
//#region src/components/ui/drop-zone/use-drop-zone.d.ts
|
|
414
413
|
declare const useDropZone: (props?: UseDropZoneProps) => UseDropZoneResult;
|
|
415
414
|
//#endregion
|
|
416
|
-
export { drop_zone_parts_d_exports as DropZone, type DropZoneActions, DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneError, DropZoneFileClear, DropZoneFileItem, DropZoneFileItemDelete, DropZoneFileItemMetadata, DropZoneFileItemPreview, DropZoneFileItemProgress, DropZoneFileList, DropZoneInput, DropZoneRoot, type DropZoneState, type DropZoneStore, DropZoneTrigger, type FileState, type UseDropZoneProps, type UseDropZoneResult, useDropZone, useDropZoneStoreContext };
|
|
415
|
+
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 };
|
|
417
416
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import { t as cnMerge } from "../../cn-2hIN1AQ7.js";
|
|
2
|
+
import { t as __exportAll } from "../../chunk-pbuEa-1d.js";
|
|
3
|
+
import { n as SlotRoot } from "../../slot-DuwoiC2C.js";
|
|
4
|
+
import { n as For } from "../../for-DGTMIS0w.js";
|
|
5
|
+
import { t as Presence } from "../../presence-CWOGx-be.js";
|
|
6
|
+
import { t as cnMerge } from "../../cn-Bbh2G587.js";
|
|
8
7
|
import { composeRefs, composeTwoEventHandlers } from "@zayne-labs/toolkit-react/utils";
|
|
9
8
|
import { isBoolean, isFile, isFunction, isNumber, isObject, isString } from "@zayne-labs/toolkit-type-helpers";
|
|
10
9
|
import { useCallback, useMemo, useRef } from "react";
|
|
@@ -12,7 +11,6 @@ import { createCustomContext, useCallbackRef, useCompareSelector, useCompareValu
|
|
|
12
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
12
|
import { createFileURL, createStore, dataAttr, formatBytes, generateFileID, handleFileValidationAsync, toArray } from "@zayne-labs/toolkit-core";
|
|
14
13
|
import { createReactStoreContext } from "@zayne-labs/toolkit-react/zustand";
|
|
15
|
-
|
|
16
14
|
//#region src/components/ui/drop-zone/drop-zone-context.ts
|
|
17
15
|
const [DropZoneStoreContextProvider, useDropZoneStoreContext] = createReactStoreContext({
|
|
18
16
|
hookName: "useDropZoneStoreContext",
|
|
@@ -31,7 +29,6 @@ const [FileItemContextProvider, useFileItemContext] = createCustomContext({
|
|
|
31
29
|
providerName: "FileItem",
|
|
32
30
|
strict: false
|
|
33
31
|
});
|
|
34
|
-
|
|
35
32
|
//#endregion
|
|
36
33
|
//#region src/components/ui/drop-zone/icons.tsx
|
|
37
34
|
const FileVideoIcon = (props) => /* @__PURE__ */ jsx("svg", {
|
|
@@ -155,7 +152,6 @@ const FileIcon = (props) => /* @__PURE__ */ jsx("svg", {
|
|
|
155
152
|
children: [/* @__PURE__ */ jsx("path", { d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z" }), /* @__PURE__ */ jsx("path", { d: "M14 2v4a2 2 0 0 0 2 2h4" })]
|
|
156
153
|
})
|
|
157
154
|
});
|
|
158
|
-
|
|
159
155
|
//#endregion
|
|
160
156
|
//#region src/components/ui/drop-zone/utils.ts
|
|
161
157
|
const generateFileID$1 = generateFileID;
|
|
@@ -217,7 +213,6 @@ const getErrorContext = (error) => {
|
|
|
217
213
|
originalError: actualError
|
|
218
214
|
};
|
|
219
215
|
};
|
|
220
|
-
|
|
221
216
|
//#endregion
|
|
222
217
|
//#region src/components/ui/drop-zone/drop-zone-store.ts
|
|
223
218
|
const createDropZoneStore = (storeContext) => {
|
|
@@ -441,7 +436,6 @@ const createDropZoneStore = (storeContext) => {
|
|
|
441
436
|
});
|
|
442
437
|
return store;
|
|
443
438
|
};
|
|
444
|
-
|
|
445
439
|
//#endregion
|
|
446
440
|
//#region src/components/ui/drop-zone/use-drop-zone.ts
|
|
447
441
|
const useDropZone = (props) => {
|
|
@@ -598,7 +592,7 @@ const useDropZone = (props) => {
|
|
|
598
592
|
...getDropZoneScopeAttrs("file-item-progress"),
|
|
599
593
|
role: "progressbar",
|
|
600
594
|
...restOfInnerProps,
|
|
601
|
-
...!unstyled && { className: cnMerge("inline-flex", variant === "circular" && "absolute top-1/2 left-1/2 -translate-
|
|
595
|
+
...!unstyled && { className: cnMerge("inline-flex", variant === "circular" && "absolute top-1/2 left-1/2 -translate-1/2", variant === "fill" && `absolute inset-0 bg-zu-primary/50 transition-[clip-path] duration-300 ease-linear [clip-path:var(--clip-path)]`, variant === "linear" && "relative h-1.5 w-full overflow-hidden rounded-full bg-zu-primary/20", restOfInnerProps.className) }
|
|
602
596
|
};
|
|
603
597
|
}, [globalUnstyled]);
|
|
604
598
|
const getFileItemDeleteProps = useCallback((innerProps) => {
|
|
@@ -680,7 +674,6 @@ const useDropZone = (props) => {
|
|
|
680
674
|
stableUseDropZoneStore
|
|
681
675
|
]);
|
|
682
676
|
};
|
|
683
|
-
|
|
684
677
|
//#endregion
|
|
685
678
|
//#region src/components/ui/drop-zone/drop-zone.tsx
|
|
686
679
|
function DropZoneRoot(props) {
|
|
@@ -1011,7 +1004,6 @@ function DropZoneFileClear(props) {
|
|
|
1011
1004
|
if (!(forceMount || fileCount > 0)) return null;
|
|
1012
1005
|
return /* @__PURE__ */ jsx(asChild ? SlotRoot : "button", { ...propGetters.getFileItemClearProps(restOfProps) });
|
|
1013
1006
|
}
|
|
1014
|
-
|
|
1015
1007
|
//#endregion
|
|
1016
1008
|
//#region src/components/ui/drop-zone/drop-zone-parts.ts
|
|
1017
1009
|
var drop_zone_parts_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1029,7 +1021,7 @@ var drop_zone_parts_exports = /* @__PURE__ */ __exportAll({
|
|
|
1029
1021
|
Root: () => DropZoneRoot,
|
|
1030
1022
|
Trigger: () => DropZoneTrigger
|
|
1031
1023
|
});
|
|
1032
|
-
|
|
1033
1024
|
//#endregion
|
|
1034
1025
|
export { drop_zone_parts_exports as DropZone, DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneError, DropZoneFileClear, DropZoneFileItem, DropZoneFileItemDelete, DropZoneFileItemMetadata, DropZoneFileItemPreview, DropZoneFileItemProgress, DropZoneFileList, DropZoneInput, DropZoneRoot, DropZoneTrigger, useDropZone, useDropZoneStoreContext };
|
|
1026
|
+
|
|
1035
1027
|
//# sourceMappingURL=index.js.map
|