@zayne-labs/ui-react 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/{cn-CIbU5eI0.js → cn-jNZfGhrk.js} +1 -1
- package/dist/esm/{cn-CIbU5eI0.js.map → cn-jNZfGhrk.js.map} +1 -1
- package/dist/esm/common/await/index.d.ts +6 -6
- package/dist/esm/common/await/index.js +3 -3
- package/dist/esm/common/client-gate/index.d.ts +2 -2
- package/dist/esm/common/error-boundary/index.d.ts +1 -1
- package/dist/esm/common/error-boundary/index.js +1 -1
- package/dist/esm/common/for/index.d.ts +4 -4
- package/dist/esm/common/presence/index.d.ts +2 -2
- package/dist/esm/common/presence/index.js +1 -1
- package/dist/esm/common/show/index.d.ts +4 -4
- package/dist/esm/common/show/index.js +1 -1
- package/dist/esm/common/slot/index.d.ts +4 -4
- package/dist/esm/common/slot/index.js +1 -1
- package/dist/esm/common/suspense-with-boundary/index.d.ts +1 -1
- package/dist/esm/common/suspense-with-boundary/index.js +1 -1
- package/dist/esm/common/switch/index.d.ts +4 -4
- package/dist/esm/common/teleport/index.d.ts +2 -2
- package/dist/esm/common/teleport/index.js +1 -1
- package/dist/esm/{error-boundary-C9o5EzC9.js → error-boundary-C4btQhu_.js} +2 -2
- package/dist/esm/{error-boundary-C9o5EzC9.js.map → error-boundary-C4btQhu_.js.map} +1 -1
- package/dist/esm/{index-DpVwG1sA.d.ts → index-DC9fblW0.d.ts} +6 -6
- package/dist/esm/{index-CaUmIQiv.d.ts → index-D_Ntazyt.d.ts} +4 -4
- package/dist/esm/{presence-DgJvW30C.js → presence-CHd9s3IS.js} +3 -3
- package/dist/esm/{presence-DgJvW30C.js.map → presence-CHd9s3IS.js.map} +1 -1
- package/dist/esm/{show-mvRnLPj8.js → show-BzfAw7y3.js} +1 -1
- package/dist/esm/{show-mvRnLPj8.js.map → show-BzfAw7y3.js.map} +1 -1
- package/dist/esm/{slot-CHR5Li4r.js → slot-DuwoiC2C.js} +1 -1
- package/dist/esm/{slot-CHR5Li4r.js.map → slot-DuwoiC2C.js.map} +1 -1
- package/dist/esm/ui/card/index.d.ts +8 -8
- package/dist/esm/ui/card/index.js +2 -2
- package/dist/esm/ui/carousel/index.d.ts +9 -9
- package/dist/esm/ui/carousel/index.js +3 -3
- package/dist/esm/ui/drag-scroll/index.d.ts +34 -25
- package/dist/esm/ui/drag-scroll/index.js +58 -56
- package/dist/esm/ui/drag-scroll/index.js.map +1 -1
- package/dist/esm/ui/drop-zone/index.d.ts +23 -22
- package/dist/esm/ui/drop-zone/index.js +4 -4
- package/dist/esm/ui/form/index.d.ts +22 -22
- package/dist/esm/ui/form/index.js +3 -3
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PolymorphicPropsStrict } from "@zayne-labs/toolkit-react/utils";
|
|
2
2
|
import { UnionDiscriminator } from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
4
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
|
5
5
|
|
|
6
6
|
//#region src/components/ui/carousel/types.d.ts
|
|
@@ -78,14 +78,14 @@ type OtherCarouselProps = {
|
|
|
78
78
|
};
|
|
79
79
|
//#endregion
|
|
80
80
|
//#region src/components/ui/carousel/carousel.d.ts
|
|
81
|
-
declare function CarouselRoot<TImages extends ImagesType, TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, CarouselRootProps<TImages>>): react_jsx_runtime0.JSX.Element;
|
|
82
|
-
declare function CarouselButton(props: CarouselButtonsProps): react_jsx_runtime0.JSX.Element;
|
|
83
|
-
declare function CarouselControls(props: CarouselControlProps): react_jsx_runtime0.JSX.Element;
|
|
84
|
-
declare function CarouselItemList<TArray extends unknown[]>(props: CarouselWrapperProps<TArray[number]>): react_jsx_runtime0.JSX.Element;
|
|
85
|
-
declare function CarouselItem(props: OtherCarouselProps): react_jsx_runtime0.JSX.Element;
|
|
86
|
-
declare function CarouselCaption<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, OtherCarouselProps>): react_jsx_runtime0.JSX.Element;
|
|
87
|
-
declare function CarouselIndicatorList<TArray extends unknown[]>(props: CarouselWrapperProps<TArray[number]>): react_jsx_runtime0.JSX.Element;
|
|
88
|
-
declare function CarouselIndicator(props: CarouselIndicatorProps): react_jsx_runtime0.JSX.Element;
|
|
81
|
+
declare function CarouselRoot<TImages extends ImagesType, TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, CarouselRootProps<TImages>>): _$react_jsx_runtime0.JSX.Element;
|
|
82
|
+
declare function CarouselButton(props: CarouselButtonsProps): _$react_jsx_runtime0.JSX.Element;
|
|
83
|
+
declare function CarouselControls(props: CarouselControlProps): _$react_jsx_runtime0.JSX.Element;
|
|
84
|
+
declare function CarouselItemList<TArray extends unknown[]>(props: CarouselWrapperProps<TArray[number]>): _$react_jsx_runtime0.JSX.Element;
|
|
85
|
+
declare function CarouselItem(props: OtherCarouselProps): _$react_jsx_runtime0.JSX.Element;
|
|
86
|
+
declare function CarouselCaption<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, OtherCarouselProps>): _$react_jsx_runtime0.JSX.Element;
|
|
87
|
+
declare function CarouselIndicatorList<TArray extends unknown[]>(props: CarouselWrapperProps<TArray[number]>): _$react_jsx_runtime0.JSX.Element;
|
|
88
|
+
declare function CarouselIndicator(props: CarouselIndicatorProps): _$react_jsx_runtime0.JSX.Element;
|
|
89
89
|
declare namespace carousel_parts_d_exports {
|
|
90
90
|
export { CarouselButton as Button, CarouselCaption as Caption, CarouselControls as Controls, CarouselIndicator as Indicator, CarouselIndicatorList as IndicatorList, CarouselItem as Item, CarouselItemList as ItemList, CarouselRoot as Root };
|
|
91
91
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { t as __exportAll } from "../../chunk-pbuEa-1d.js";
|
|
3
|
-
import { t as cnMerge } from "../../cn-CIbU5eI0.js";
|
|
4
3
|
import { n as For } from "../../for-DGTMIS0w.js";
|
|
5
|
-
import { i as ShowRoot, n as ShowContent, r as ShowFallback } from "../../show-
|
|
4
|
+
import { i as ShowRoot, n as ShowContent, r as ShowFallback } from "../../show-BzfAw7y3.js";
|
|
5
|
+
import { t as cnMerge } from "../../cn-jNZfGhrk.js";
|
|
6
6
|
import { isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
7
7
|
import { useMemo, useState } from "react";
|
|
8
|
+
import { useAnimationInterval, useCallbackRef, useStore } from "@zayne-labs/toolkit-react";
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import { createStore } from "@zayne-labs/toolkit-core";
|
|
10
|
-
import { useAnimationInterval, useCallbackRef, useStore } from "@zayne-labs/toolkit-react";
|
|
11
11
|
import { createReactStoreContext } from "@zayne-labs/toolkit-react/zustand";
|
|
12
12
|
//#region src/components/ui/carousel/carousel-store-context.ts
|
|
13
13
|
const [CarouselStoreContextProvider, useCarouselStoreContext] = createReactStoreContext({
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { InferProps, PolymorphicPropsStrict } from "@zayne-labs/toolkit-react/utils";
|
|
2
|
-
import * as _zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
+
import * as _$_zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
|
|
3
3
|
import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
4
|
-
import * as react from "react";
|
|
5
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
|
-
import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
4
|
+
import * as _$react from "react";
|
|
5
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
|
+
import * as _$_zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
7
|
+
|
|
7
8
|
//#region src/components/ui/drag-scroll/drag-scroll-context.d.ts
|
|
8
9
|
declare const DragScrollStoreContextProvider: (props: {
|
|
9
10
|
children: React.ReactNode;
|
|
@@ -28,9 +29,9 @@ declare const DragScrollStoreContextProvider: (props: {
|
|
|
28
29
|
shouldReplace: true;
|
|
29
30
|
}) | undefined): void;
|
|
30
31
|
};
|
|
31
|
-
subscribe: _zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore>;
|
|
32
|
+
subscribe: _$_zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore>;
|
|
32
33
|
};
|
|
33
|
-
}) => react.FunctionComponentElement<react.ProviderProps<{
|
|
34
|
+
}) => _$react.FunctionComponentElement<_$react.ProviderProps<{
|
|
34
35
|
getInitialState: () => DragScrollStore;
|
|
35
36
|
getListeners: () => Set<(state: DragScrollStore, prevState: DragScrollStore) => void>;
|
|
36
37
|
getState: () => DragScrollStore;
|
|
@@ -51,8 +52,8 @@ declare const DragScrollStoreContextProvider: (props: {
|
|
|
51
52
|
shouldReplace: true;
|
|
52
53
|
}) | undefined): void;
|
|
53
54
|
};
|
|
54
|
-
subscribe: _zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore>;
|
|
55
|
-
}>>, useDragScrollStoreContext: <TResult = DragScrollStore>(selector?: _zayne_labs_toolkit_type_helpers0.SelectorFn<DragScrollStore, TResult> | undefined) => TResult;
|
|
55
|
+
subscribe: _$_zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore>;
|
|
56
|
+
}>>, useDragScrollStoreContext: <TResult = DragScrollStore>(selector?: _$_zayne_labs_toolkit_type_helpers0.SelectorFn<DragScrollStore, TResult> | undefined) => TResult;
|
|
56
57
|
//#endregion
|
|
57
58
|
//#region src/components/ui/drag-scroll/drag-scroll-store.d.ts
|
|
58
59
|
type RequiredUseDragScrollProps = { [Key in keyof Required<UseDragScrollProps>]: UseDragScrollProps[Key] | undefined };
|
|
@@ -78,7 +79,7 @@ declare const createDragScrollStore: (initStoreValues: InitStoreValues) => {
|
|
|
78
79
|
shouldReplace: true;
|
|
79
80
|
}) | undefined): void;
|
|
80
81
|
};
|
|
81
|
-
subscribe: _zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore>;
|
|
82
|
+
subscribe: _$_zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore>;
|
|
82
83
|
};
|
|
83
84
|
//#endregion
|
|
84
85
|
//#region src/components/ui/drag-scroll/types.d.ts
|
|
@@ -90,14 +91,14 @@ type SharedInputProps = {
|
|
|
90
91
|
unstyled?: boolean;
|
|
91
92
|
};
|
|
92
93
|
type PartProps<TContainerElement extends HTMLElement = HTMLElement> = {
|
|
93
|
-
container: {
|
|
94
|
-
input: PartProps<TContainerElement>["container"]["output"] & SharedInputProps;
|
|
95
|
-
output: RecordForDataAttr & InferProps<TContainerElement>;
|
|
96
|
-
};
|
|
97
94
|
item: {
|
|
98
95
|
input: PartProps<TContainerElement>["item"]["output"] & SharedInputProps;
|
|
99
96
|
output: InferProps<HTMLElement> & RecordForDataAttr;
|
|
100
97
|
};
|
|
98
|
+
list: {
|
|
99
|
+
input: PartProps<TContainerElement>["list"]["output"] & SharedInputProps;
|
|
100
|
+
output: RecordForDataAttr & InferProps<TContainerElement>;
|
|
101
|
+
};
|
|
101
102
|
nextButton: {
|
|
102
103
|
input: PartProps<TContainerElement>["nextButton"]["output"] & SharedInputProps;
|
|
103
104
|
output: RecordForDataAttr & InferProps<"button">;
|
|
@@ -128,7 +129,7 @@ type DragScrollActions = {
|
|
|
128
129
|
handleMouseUpOrLeave: () => void;
|
|
129
130
|
handleScroll: () => void;
|
|
130
131
|
initializeResizeObserver: () => (() => void) | undefined;
|
|
131
|
-
|
|
132
|
+
setListRef: (element: HTMLElement | null) => void;
|
|
132
133
|
updateScrollState: () => void;
|
|
133
134
|
};
|
|
134
135
|
};
|
|
@@ -165,13 +166,21 @@ type UseDragScrollProps = {
|
|
|
165
166
|
usage?: "allScreens" | "desktopOnly" | "mobileAndTabletOnly";
|
|
166
167
|
};
|
|
167
168
|
type UseDragScrollResult<TContainerElement extends HTMLElement> = Pick<UseDragScrollProps, "disableInternalStateSubscription"> & {
|
|
168
|
-
|
|
169
|
+
listRef: React.RefObject<TContainerElement | null>;
|
|
169
170
|
propGetters: DragScrollPropGetters<TContainerElement>;
|
|
170
171
|
storeApi: ReturnType<typeof createDragScrollStore>;
|
|
171
172
|
useDragScrollStore: typeof useDragScrollStoreContext;
|
|
172
173
|
};
|
|
173
174
|
//#endregion
|
|
175
|
+
//#region src/lib/utils/type-helpers.d.ts
|
|
176
|
+
type FromCamelToKebabCase<TString extends string> = TString extends `${infer First}${infer Rest}` ? First extends Uppercase<First> ? `-${Lowercase<First>}${FromCamelToKebabCase<Rest>}` : `${First}${FromCamelToKebabCase<Rest>}` : "";
|
|
177
|
+
//#endregion
|
|
174
178
|
//#region src/components/ui/drag-scroll/use-drag-scroll.d.ts
|
|
179
|
+
declare const getDragScrollScopeAttrs: (part: FromCamelToKebabCase<keyof PartProps>) => {
|
|
180
|
+
readonly "data-slot": "drag-scroll-item" | "drag-scroll-list" | "drag-scroll-root" | "drag-scroll-next-button" | "drag-scroll-prev-button";
|
|
181
|
+
readonly "data-scope": "drag-scroll";
|
|
182
|
+
readonly "data-part": FromCamelToKebabCase<keyof PartProps>;
|
|
183
|
+
};
|
|
175
184
|
declare const useDragScroll: <TContainerElement extends HTMLElement = HTMLElement>(props?: UseDragScrollProps) => UseDragScrollResult<TContainerElement>;
|
|
176
185
|
//#endregion
|
|
177
186
|
//#region src/components/ui/drag-scroll/drag-scroll.d.ts
|
|
@@ -179,31 +188,31 @@ type DragScrollRootProps = UseDragScrollProps & {
|
|
|
179
188
|
asChild?: boolean;
|
|
180
189
|
children: React.ReactNode;
|
|
181
190
|
} & PartInputProps["root"];
|
|
182
|
-
declare function DragScrollRoot
|
|
191
|
+
declare function DragScrollRoot(props: DragScrollRootProps): _$react_jsx_runtime0.JSX.Element;
|
|
183
192
|
type DragScrollContextProps<TSlice> = {
|
|
184
193
|
children: React.ReactNode | ((context: TSlice) => React.ReactNode);
|
|
185
194
|
selector?: SelectorFn<DragScrollStore, TSlice>;
|
|
186
195
|
};
|
|
187
|
-
declare function DragScrollContext<TSlice = DragScrollStore>(props: DragScrollContextProps<TSlice>): react.ReactNode;
|
|
188
|
-
type
|
|
196
|
+
declare function DragScrollContext<TSlice = DragScrollStore>(props: DragScrollContextProps<TSlice>): _$react.ReactNode;
|
|
197
|
+
type DragScrollListProps = {
|
|
189
198
|
asChild?: boolean;
|
|
190
|
-
} & PartInputProps["
|
|
191
|
-
declare function
|
|
199
|
+
} & PartInputProps["list"];
|
|
200
|
+
declare function DragScrollList<TElement extends React.ElementType = "ul">(props: PolymorphicPropsStrict<TElement, DragScrollListProps>): _$react_jsx_runtime0.JSX.Element;
|
|
192
201
|
type DragScrollItemProps = {
|
|
193
202
|
asChild?: boolean;
|
|
194
203
|
} & PartInputProps["item"];
|
|
195
|
-
declare function DragScrollItem<TElement extends React.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DragScrollItemProps>): react_jsx_runtime0.JSX.Element;
|
|
204
|
+
declare function DragScrollItem<TElement extends React.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DragScrollItemProps>): _$react_jsx_runtime0.JSX.Element;
|
|
196
205
|
type DragScrollPrevProps = {
|
|
197
206
|
asChild?: boolean;
|
|
198
207
|
} & PartInputProps["prevButton"];
|
|
199
|
-
declare function DragScrollPrev(props: DragScrollPrevProps): react_jsx_runtime0.JSX.Element;
|
|
208
|
+
declare function DragScrollPrev(props: DragScrollPrevProps): _$react_jsx_runtime0.JSX.Element;
|
|
200
209
|
type DragScrollNextProps = {
|
|
201
210
|
asChild?: boolean;
|
|
202
211
|
} & PartInputProps["nextButton"];
|
|
203
|
-
declare function DragScrollNext(props: DragScrollNextProps): react_jsx_runtime0.JSX.Element;
|
|
212
|
+
declare function DragScrollNext(props: DragScrollNextProps): _$react_jsx_runtime0.JSX.Element;
|
|
204
213
|
declare namespace drag_scroll_parts_d_exports {
|
|
205
|
-
export {
|
|
214
|
+
export { DragScrollContext as Context, DragScrollItem as Item, DragScrollList as List, DragScrollNext as Next, DragScrollPrev as Prev, DragScrollRoot as Root };
|
|
206
215
|
}
|
|
207
216
|
//#endregion
|
|
208
|
-
export { drag_scroll_parts_d_exports as DragScroll,
|
|
217
|
+
export { drag_scroll_parts_d_exports as DragScroll, DragScrollContext, DragScrollContextProps, DragScrollItem, DragScrollItemProps, DragScrollList, DragScrollListProps, DragScrollNext, DragScrollNextProps, DragScrollPrev, DragScrollPrevProps, DragScrollRoot, DragScrollRootProps, type DragScrollStore, type UseDragScrollProps, type UseDragScrollResult, getDragScrollScopeAttrs, useDragScroll, useDragScrollStoreContext };
|
|
209
218
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { t as __exportAll } from "../../chunk-pbuEa-1d.js";
|
|
3
|
-
import { n as SlotRoot } from "../../slot-
|
|
4
|
-
import { t as cnMerge } from "../../cn-
|
|
3
|
+
import { n as SlotRoot } from "../../slot-DuwoiC2C.js";
|
|
4
|
+
import { t as cnMerge } from "../../cn-jNZfGhrk.js";
|
|
5
5
|
import { composeRefs, composeTwoEventHandlers } from "@zayne-labs/toolkit-react/utils";
|
|
6
6
|
import { isFunction, isNumber } from "@zayne-labs/toolkit-type-helpers";
|
|
7
7
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
8
|
+
import { createCustomContext, useCallbackRef, useCompareSelector, useStore } from "@zayne-labs/toolkit-react";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
import { checkIsDeviceMobile, createStore, dataAttr, on, throttleByFrame } from "@zayne-labs/toolkit-core";
|
|
10
|
-
import { createCustomContext, useCallbackRef, useCompareSelector, useStore } from "@zayne-labs/toolkit-react";
|
|
11
11
|
import { createReactStoreContext } from "@zayne-labs/toolkit-react/zustand";
|
|
12
12
|
//#region src/components/ui/drag-scroll/utils.ts
|
|
13
13
|
const updateCursor = (element) => {
|
|
@@ -33,7 +33,7 @@ const handleScrollSnap = (dragContainer) => {
|
|
|
33
33
|
//#region src/components/ui/drag-scroll/drag-scroll-store.ts
|
|
34
34
|
const createDragScrollStore = (initStoreValues) => {
|
|
35
35
|
const { orientation = "horizontal", scrollAmount = "item", usage = "allScreens" } = initStoreValues;
|
|
36
|
-
const
|
|
36
|
+
const listRef = { current: null };
|
|
37
37
|
const positionRef = { current: {
|
|
38
38
|
left: 0,
|
|
39
39
|
top: 0,
|
|
@@ -62,22 +62,22 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
62
62
|
abortControllerRef.current.mouseLeave.abort();
|
|
63
63
|
},
|
|
64
64
|
goToNext: () => {
|
|
65
|
-
if (!
|
|
65
|
+
if (!listRef.current) return;
|
|
66
66
|
const { canGoToNext } = get();
|
|
67
67
|
if (!canGoToNext) return;
|
|
68
|
-
const amount = getScrollAmount(
|
|
69
|
-
|
|
68
|
+
const amount = getScrollAmount(listRef.current);
|
|
69
|
+
listRef.current.scrollBy({
|
|
70
70
|
behavior: "smooth",
|
|
71
71
|
left: orientation === "vertical" ? 0 : amount,
|
|
72
72
|
top: orientation === "vertical" || orientation === "both" ? amount : 0
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
75
|
goToPrev: () => {
|
|
76
|
-
if (!
|
|
76
|
+
if (!listRef.current) return;
|
|
77
77
|
const { canGoToPrev } = get();
|
|
78
78
|
if (!canGoToPrev) return;
|
|
79
|
-
const amount = getScrollAmount(
|
|
80
|
-
|
|
79
|
+
const amount = getScrollAmount(listRef.current);
|
|
80
|
+
listRef.current.scrollBy({
|
|
81
81
|
behavior: "smooth",
|
|
82
82
|
left: orientation === "vertical" ? 0 : -amount,
|
|
83
83
|
top: orientation === "vertical" || orientation === "both" ? -amount : 0
|
|
@@ -86,7 +86,7 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
86
86
|
handleMouseDown: (event) => {
|
|
87
87
|
if (usage === "mobileAndTabletOnly" && window.innerWidth >= 768) return;
|
|
88
88
|
if (usage === "desktopOnly" && window.innerWidth < 768) return;
|
|
89
|
-
if (!
|
|
89
|
+
if (!listRef.current) return;
|
|
90
90
|
abortControllerRef.current = {
|
|
91
91
|
mouseLeave: new AbortController(),
|
|
92
92
|
mouseMove: new AbortController(),
|
|
@@ -94,37 +94,37 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
94
94
|
};
|
|
95
95
|
if (orientation === "horizontal" || orientation === "both") {
|
|
96
96
|
positionRef.current.x = event.clientX;
|
|
97
|
-
positionRef.current.left =
|
|
97
|
+
positionRef.current.left = listRef.current.scrollLeft;
|
|
98
98
|
}
|
|
99
99
|
if (orientation === "vertical" || orientation === "both") {
|
|
100
100
|
positionRef.current.y = event.clientY;
|
|
101
|
-
positionRef.current.top =
|
|
101
|
+
positionRef.current.top = listRef.current.scrollTop;
|
|
102
102
|
}
|
|
103
|
-
updateCursor(
|
|
103
|
+
updateCursor(listRef.current);
|
|
104
104
|
set({ isDragging: true });
|
|
105
105
|
const { actions } = get();
|
|
106
|
-
on(
|
|
107
|
-
on(
|
|
108
|
-
on(
|
|
106
|
+
on(listRef.current, "mousemove", actions.handleMouseMove, { signal: abortControllerRef.current.mouseMove.signal });
|
|
107
|
+
on(listRef.current, "mouseup", actions.handleMouseUpOrLeave, { signal: abortControllerRef.current.mouseUp.signal });
|
|
108
|
+
on(listRef.current, "mouseleave", actions.handleMouseUpOrLeave, { signal: abortControllerRef.current.mouseLeave.signal });
|
|
109
109
|
on(document, "mouseup", actions.handleMouseUpOrLeave, {
|
|
110
110
|
once: true,
|
|
111
111
|
signal: abortControllerRef.current.mouseUp.signal
|
|
112
112
|
});
|
|
113
113
|
},
|
|
114
114
|
handleMouseMove: (event) => {
|
|
115
|
-
if (!
|
|
115
|
+
if (!listRef.current) return;
|
|
116
116
|
if (orientation === "horizontal" || orientation === "both") {
|
|
117
117
|
const dx = event.clientX - positionRef.current.x;
|
|
118
|
-
|
|
118
|
+
listRef.current.scrollLeft = positionRef.current.left - dx;
|
|
119
119
|
}
|
|
120
120
|
if (orientation === "vertical" || orientation === "both") {
|
|
121
121
|
const dy = event.clientY - positionRef.current.y;
|
|
122
|
-
|
|
122
|
+
listRef.current.scrollTop = positionRef.current.top - dy;
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
handleMouseUpOrLeave: () => {
|
|
126
|
-
if (!
|
|
127
|
-
resetCursor(
|
|
126
|
+
if (!listRef.current) return;
|
|
127
|
+
resetCursor(listRef.current);
|
|
128
128
|
set({ isDragging: false });
|
|
129
129
|
const { actions } = get();
|
|
130
130
|
actions.cleanupDragListeners();
|
|
@@ -134,34 +134,34 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
134
134
|
actions.updateScrollState();
|
|
135
135
|
}),
|
|
136
136
|
initializeResizeObserver: () => {
|
|
137
|
-
if (!
|
|
137
|
+
if (!listRef.current) return;
|
|
138
138
|
const { actions } = get();
|
|
139
139
|
const resizeObserver = new ResizeObserver(() => actions.updateScrollState());
|
|
140
|
-
resizeObserver.observe(
|
|
141
|
-
for (const child of
|
|
140
|
+
resizeObserver.observe(listRef.current);
|
|
141
|
+
for (const child of listRef.current.children) resizeObserver.observe(child);
|
|
142
142
|
const cleanup = () => {
|
|
143
143
|
resizeObserver.disconnect();
|
|
144
144
|
};
|
|
145
145
|
return cleanup;
|
|
146
146
|
},
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
setListRef: (element) => {
|
|
148
|
+
listRef.current = element;
|
|
149
149
|
if (!element) return;
|
|
150
150
|
handleScrollSnap(element);
|
|
151
151
|
const { actions } = get();
|
|
152
152
|
actions.updateScrollState();
|
|
153
153
|
},
|
|
154
154
|
updateScrollState: () => {
|
|
155
|
-
if (!
|
|
155
|
+
if (!listRef.current) return;
|
|
156
156
|
if (orientation === "horizontal" || orientation === "both") {
|
|
157
|
-
const { clientWidth, scrollLeft, scrollWidth } =
|
|
157
|
+
const { clientWidth, scrollLeft, scrollWidth } = listRef.current;
|
|
158
158
|
set({
|
|
159
159
|
canGoToNext: Math.ceil(scrollLeft + clientWidth) < scrollWidth,
|
|
160
160
|
canGoToPrev: Math.floor(scrollLeft) > 0
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
if (orientation === "vertical") {
|
|
164
|
-
const { clientHeight, scrollHeight, scrollTop } =
|
|
164
|
+
const { clientHeight, scrollHeight, scrollTop } = listRef.current;
|
|
165
165
|
set({
|
|
166
166
|
canGoToNext: Math.ceil(scrollTop + clientHeight) < scrollHeight,
|
|
167
167
|
canGoToPrev: Math.floor(scrollTop) > 0
|
|
@@ -173,14 +173,16 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
173
173
|
};
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/components/ui/drag-scroll/use-drag-scroll.ts
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
const getDragScrollScopeAttrs = (part) => {
|
|
177
|
+
return {
|
|
178
|
+
"data-slot": `drag-scroll-${part}`,
|
|
179
|
+
"data-scope": "drag-scroll",
|
|
180
|
+
"data-part": part
|
|
181
|
+
};
|
|
182
|
+
};
|
|
181
183
|
const useDragScroll = (props) => {
|
|
182
184
|
const { disableInternalStateSubscription = false, orientation = "horizontal", scrollAmount = "item", usage = "allScreens" } = props ?? {};
|
|
183
|
-
const
|
|
185
|
+
const listRef = useRef(null);
|
|
184
186
|
const storeApi = useMemo(() => {
|
|
185
187
|
return createDragScrollStore({
|
|
186
188
|
orientation,
|
|
@@ -200,8 +202,8 @@ const useDragScroll = (props) => {
|
|
|
200
202
|
const canGoToNext = useDragScrollStore((state) => !disableInternalStateSubscription ? state.canGoToNext : null);
|
|
201
203
|
const isDragging = useDragScrollStore((state) => !disableInternalStateSubscription ? state.isDragging : null);
|
|
202
204
|
const refCallback = useCallbackRef((node) => {
|
|
203
|
-
|
|
204
|
-
actions.
|
|
205
|
+
listRef.current = node;
|
|
206
|
+
actions.setListRef(node);
|
|
205
207
|
if (!node) return;
|
|
206
208
|
const cleanupMouseDown = on(node, "mousedown", actions.handleMouseDown);
|
|
207
209
|
const cleanupScroll = on(node, "scroll", actions.handleScroll, { passive: true });
|
|
@@ -215,14 +217,14 @@ const useDragScroll = (props) => {
|
|
|
215
217
|
}, [actions]);
|
|
216
218
|
const getRootProps = useCallbackRef((innerProps) => {
|
|
217
219
|
return {
|
|
218
|
-
...
|
|
220
|
+
...getDragScrollScopeAttrs("root"),
|
|
219
221
|
...innerProps,
|
|
220
222
|
className: cnMerge("relative", innerProps?.className)
|
|
221
223
|
};
|
|
222
224
|
});
|
|
223
|
-
const
|
|
225
|
+
const getListProps = useCallback((innerProps) => {
|
|
224
226
|
return {
|
|
225
|
-
...
|
|
227
|
+
...getDragScrollScopeAttrs("list"),
|
|
226
228
|
...!disableInternalStateSubscription && { "data-dragging": dataAttr(isDragging) },
|
|
227
229
|
...innerProps,
|
|
228
230
|
className: cnMerge(`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-x-scroll overflow-y-hidden`, orientation === "horizontal" && "flex-row", orientation === "vertical" && "flex-col", usage === "mobileAndTabletOnly" && "md:cursor-default md:flex-col", usage === "desktopOnly" && "max-md:cursor-default max-md:flex-col", innerProps?.className),
|
|
@@ -237,7 +239,7 @@ const useDragScroll = (props) => {
|
|
|
237
239
|
]);
|
|
238
240
|
const getItemProps = useCallbackRef((innerProps) => {
|
|
239
241
|
return {
|
|
240
|
-
...
|
|
242
|
+
...getDragScrollScopeAttrs("item"),
|
|
241
243
|
...innerProps,
|
|
242
244
|
className: cnMerge("snap-center snap-always", innerProps?.className)
|
|
243
245
|
};
|
|
@@ -245,7 +247,7 @@ const useDragScroll = (props) => {
|
|
|
245
247
|
const getPrevButtonProps = useCallback((innerProps) => {
|
|
246
248
|
const isDisabled = innerProps?.disabled ?? !canGoToPrev;
|
|
247
249
|
return {
|
|
248
|
-
...
|
|
250
|
+
...getDragScrollScopeAttrs("prev-button"),
|
|
249
251
|
type: "button",
|
|
250
252
|
...innerProps,
|
|
251
253
|
"aria-disabled": dataAttr(isDisabled),
|
|
@@ -258,7 +260,7 @@ const useDragScroll = (props) => {
|
|
|
258
260
|
const getNextButtonProps = useCallback((innerProps) => {
|
|
259
261
|
const isDisabled = innerProps?.disabled ?? !canGoToNext;
|
|
260
262
|
return {
|
|
261
|
-
...
|
|
263
|
+
...getDragScrollScopeAttrs("next-button"),
|
|
262
264
|
type: "button",
|
|
263
265
|
...innerProps,
|
|
264
266
|
"aria-disabled": dataAttr(isDisabled),
|
|
@@ -269,22 +271,22 @@ const useDragScroll = (props) => {
|
|
|
269
271
|
};
|
|
270
272
|
}, [actions.goToNext, canGoToNext]);
|
|
271
273
|
const propGetters = useMemo(() => ({
|
|
272
|
-
getContainerProps,
|
|
273
274
|
getItemProps,
|
|
275
|
+
getListProps,
|
|
274
276
|
getNextButtonProps,
|
|
275
277
|
getPrevButtonProps,
|
|
276
278
|
getRootProps
|
|
277
279
|
}), [
|
|
278
280
|
getPrevButtonProps,
|
|
279
|
-
|
|
281
|
+
getListProps,
|
|
280
282
|
getItemProps,
|
|
281
283
|
getNextButtonProps,
|
|
282
284
|
getRootProps
|
|
283
285
|
]);
|
|
284
286
|
const stableUseDragScrollStore = useCallbackRef(useDragScrollStore);
|
|
285
287
|
return useMemo(() => ({
|
|
286
|
-
containerRef,
|
|
287
288
|
disableInternalStateSubscription,
|
|
289
|
+
listRef,
|
|
288
290
|
propGetters,
|
|
289
291
|
storeApi,
|
|
290
292
|
useDragScrollStore: stableUseDragScrollStore
|
|
@@ -310,21 +312,21 @@ const [DragScrollRootContextProvider, useDragScrollRootContext] = createCustomCo
|
|
|
310
312
|
//#endregion
|
|
311
313
|
//#region src/components/ui/drag-scroll/drag-scroll.tsx
|
|
312
314
|
function DragScrollRoot(props) {
|
|
313
|
-
const {
|
|
314
|
-
const {
|
|
315
|
+
const { asChild, children, ...restOfProps } = props;
|
|
316
|
+
const { disableInternalStateSubscription, listRef, propGetters, storeApi } = useDragScroll(restOfProps);
|
|
315
317
|
return /* @__PURE__ */ jsx(DragScrollStoreContextProvider, {
|
|
316
318
|
store: storeApi,
|
|
317
319
|
children: /* @__PURE__ */ jsx(DragScrollRootContextProvider, {
|
|
318
320
|
value: useMemo(() => ({
|
|
319
|
-
containerRef,
|
|
320
321
|
disableInternalStateSubscription,
|
|
322
|
+
listRef,
|
|
321
323
|
propGetters
|
|
322
324
|
}), [
|
|
323
|
-
|
|
325
|
+
listRef,
|
|
324
326
|
disableInternalStateSubscription,
|
|
325
327
|
propGetters
|
|
326
328
|
]),
|
|
327
|
-
children: /* @__PURE__ */ jsx(asChild ? SlotRoot :
|
|
329
|
+
children: /* @__PURE__ */ jsx(asChild ? SlotRoot : "div", {
|
|
328
330
|
...propGetters.getRootProps(restOfProps),
|
|
329
331
|
children
|
|
330
332
|
})
|
|
@@ -336,10 +338,10 @@ function DragScrollContext(props) {
|
|
|
336
338
|
const dragScrollCtx = useDragScrollStoreContext(useCompareSelector(selector));
|
|
337
339
|
return isFunction(children) ? children(dragScrollCtx) : children;
|
|
338
340
|
}
|
|
339
|
-
function
|
|
341
|
+
function DragScrollList(props) {
|
|
340
342
|
const { as: Element = "ul", asChild, ...restOfProps } = props;
|
|
341
343
|
const { propGetters } = useDragScrollRootContext();
|
|
342
|
-
return /* @__PURE__ */ jsx(asChild ? SlotRoot : Element, { ...propGetters.
|
|
344
|
+
return /* @__PURE__ */ jsx(asChild ? SlotRoot : Element, { ...propGetters.getListProps(restOfProps) });
|
|
343
345
|
}
|
|
344
346
|
function DragScrollItem(props) {
|
|
345
347
|
const { as: Element = "li", asChild, ...restOfProps } = props;
|
|
@@ -359,14 +361,14 @@ function DragScrollNext(props) {
|
|
|
359
361
|
//#endregion
|
|
360
362
|
//#region src/components/ui/drag-scroll/drag-scroll-parts.ts
|
|
361
363
|
var drag_scroll_parts_exports = /* @__PURE__ */ __exportAll({
|
|
362
|
-
Container: () => DragScrollContainer,
|
|
363
364
|
Context: () => DragScrollContext,
|
|
364
365
|
Item: () => DragScrollItem,
|
|
366
|
+
List: () => DragScrollList,
|
|
365
367
|
Next: () => DragScrollNext,
|
|
366
368
|
Prev: () => DragScrollPrev,
|
|
367
369
|
Root: () => DragScrollRoot
|
|
368
370
|
});
|
|
369
371
|
//#endregion
|
|
370
|
-
export { drag_scroll_parts_exports as DragScroll,
|
|
372
|
+
export { drag_scroll_parts_exports as DragScroll, DragScrollContext, DragScrollItem, DragScrollList, DragScrollNext, DragScrollPrev, DragScrollRoot, getDragScrollScopeAttrs, useDragScroll, useDragScrollStoreContext };
|
|
371
373
|
|
|
372
374
|
//# sourceMappingURL=index.js.map
|