@zayne-labs/ui-react 0.10.52 → 0.11.0
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-DCY8KkO1.js → presence-CWOGx-be.js} +9 -11
- package/dist/esm/{presence-DCY8KkO1.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-CAyHw8R-.js → slot-DuwoiC2C.js} +6 -7
- package/dist/esm/slot-DuwoiC2C.js.map +1 -0
- package/dist/esm/ui/card/index.js +4 -6
- 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 +97 -63
- package/dist/esm/ui/drag-scroll/index.js +122 -41
- package/dist/esm/ui/drag-scroll/index.js.map +1 -1
- package/dist/esm/ui/drop-zone/index.d.ts +47 -40
- package/dist/esm/ui/drop-zone/index.js +23 -24
- 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 +20 -21
- 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-CAyHw8R-.js.map +0 -1
- package/dist/esm/useErrorBoundary-CIUZVY-G.js.map +0 -1
|
@@ -1,115 +1,125 @@
|
|
|
1
|
-
import { InferProps } from "@zayne-labs/toolkit-react/utils";
|
|
1
|
+
import { InferProps, PolymorphicPropsStrict } from "@zayne-labs/toolkit-react/utils";
|
|
2
2
|
import * as _zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
+
import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
3
4
|
import * as react from "react";
|
|
4
|
-
import "
|
|
5
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
6
|
import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
6
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;
|
|
10
11
|
store: {
|
|
11
|
-
getInitialState: () => DragScrollStore
|
|
12
|
-
getListeners: () => Set<(state: DragScrollStore
|
|
13
|
-
getState: () => DragScrollStore
|
|
12
|
+
getInitialState: () => DragScrollStore;
|
|
13
|
+
getListeners: () => Set<(state: DragScrollStore, prevState: DragScrollStore) => void>;
|
|
14
|
+
getState: () => DragScrollStore;
|
|
14
15
|
resetState: () => void;
|
|
15
16
|
setState: {
|
|
16
|
-
(stateUpdate: Partial<DragScrollStore
|
|
17
|
-
onNotifySync?: ((previousState: DragScrollStore
|
|
18
|
-
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore
|
|
17
|
+
(stateUpdate: Partial<DragScrollStore> | ((prevState: DragScrollStore) => Partial<DragScrollStore>), options?: ({
|
|
18
|
+
onNotifySync?: ((previousState: DragScrollStore) => void) | undefined;
|
|
19
|
+
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore) => void) | undefined;
|
|
19
20
|
shouldNotifySync?: boolean | undefined;
|
|
20
21
|
} & {
|
|
21
22
|
shouldReplace?: false;
|
|
22
23
|
}) | undefined): void;
|
|
23
|
-
(stateUpdate: DragScrollStore
|
|
24
|
-
onNotifySync?: ((previousState: DragScrollStore
|
|
25
|
-
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore
|
|
24
|
+
(stateUpdate: DragScrollStore | ((prevState: DragScrollStore) => DragScrollStore), options?: ({
|
|
25
|
+
onNotifySync?: ((previousState: DragScrollStore) => void) | undefined;
|
|
26
|
+
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore) => void) | undefined;
|
|
26
27
|
shouldNotifySync?: boolean | undefined;
|
|
27
28
|
} & {
|
|
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
34
|
}) => react.FunctionComponentElement<react.ProviderProps<{
|
|
34
|
-
getInitialState: () => DragScrollStore
|
|
35
|
-
getListeners: () => Set<(state: DragScrollStore
|
|
36
|
-
getState: () => DragScrollStore
|
|
35
|
+
getInitialState: () => DragScrollStore;
|
|
36
|
+
getListeners: () => Set<(state: DragScrollStore, prevState: DragScrollStore) => void>;
|
|
37
|
+
getState: () => DragScrollStore;
|
|
37
38
|
resetState: () => void;
|
|
38
39
|
setState: {
|
|
39
|
-
(stateUpdate: Partial<DragScrollStore
|
|
40
|
-
onNotifySync?: ((previousState: DragScrollStore
|
|
41
|
-
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore
|
|
40
|
+
(stateUpdate: Partial<DragScrollStore> | ((prevState: DragScrollStore) => Partial<DragScrollStore>), options?: ({
|
|
41
|
+
onNotifySync?: ((previousState: DragScrollStore) => void) | undefined;
|
|
42
|
+
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore) => void) | undefined;
|
|
42
43
|
shouldNotifySync?: boolean | undefined;
|
|
43
44
|
} & {
|
|
44
45
|
shouldReplace?: false;
|
|
45
46
|
}) | undefined): void;
|
|
46
|
-
(stateUpdate: DragScrollStore
|
|
47
|
-
onNotifySync?: ((previousState: DragScrollStore
|
|
48
|
-
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore
|
|
47
|
+
(stateUpdate: DragScrollStore | ((prevState: DragScrollStore) => DragScrollStore), options?: ({
|
|
48
|
+
onNotifySync?: ((previousState: DragScrollStore) => void) | undefined;
|
|
49
|
+
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore) => void) | undefined;
|
|
49
50
|
shouldNotifySync?: boolean | undefined;
|
|
50
51
|
} & {
|
|
51
52
|
shouldReplace: true;
|
|
52
53
|
}) | undefined): void;
|
|
53
54
|
};
|
|
54
|
-
subscribe: _zayne_labs_toolkit_core0.SubscribeFn<DragScrollStore
|
|
55
|
-
}>>, useDragScrollStoreContext: <TResult = DragScrollStore
|
|
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 };
|
|
59
60
|
type InitStoreValues = Pick<RequiredUseDragScrollProps, "orientation" | "scrollAmount" | "usage">;
|
|
60
|
-
declare const createDragScrollStore:
|
|
61
|
-
getInitialState: () => DragScrollStore
|
|
62
|
-
getListeners: () => Set<(state: DragScrollStore
|
|
63
|
-
getState: () => DragScrollStore
|
|
61
|
+
declare const createDragScrollStore: (initStoreValues: InitStoreValues) => {
|
|
62
|
+
getInitialState: () => DragScrollStore;
|
|
63
|
+
getListeners: () => Set<(state: DragScrollStore, prevState: DragScrollStore) => void>;
|
|
64
|
+
getState: () => DragScrollStore;
|
|
64
65
|
resetState: () => void;
|
|
65
66
|
setState: {
|
|
66
|
-
(stateUpdate: Partial<DragScrollStore
|
|
67
|
-
onNotifySync?: ((previousState: DragScrollStore
|
|
68
|
-
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore
|
|
67
|
+
(stateUpdate: Partial<DragScrollStore> | ((prevState: DragScrollStore) => Partial<DragScrollStore>), options?: ({
|
|
68
|
+
onNotifySync?: ((previousState: DragScrollStore) => void) | undefined;
|
|
69
|
+
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore) => void) | undefined;
|
|
69
70
|
shouldNotifySync?: boolean | undefined;
|
|
70
71
|
} & {
|
|
71
72
|
shouldReplace?: false;
|
|
72
73
|
}) | undefined): void;
|
|
73
|
-
(stateUpdate: DragScrollStore
|
|
74
|
-
onNotifySync?: ((previousState: DragScrollStore
|
|
75
|
-
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore
|
|
74
|
+
(stateUpdate: DragScrollStore | ((prevState: DragScrollStore) => DragScrollStore), options?: ({
|
|
75
|
+
onNotifySync?: ((previousState: DragScrollStore) => void) | undefined;
|
|
76
|
+
onNotifyViaBatch?: ((previousStateSnapshot: DragScrollStore) => void) | undefined;
|
|
76
77
|
shouldNotifySync?: boolean | undefined;
|
|
77
78
|
} & {
|
|
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
|
|
85
86
|
type RecordForDataAttr = Record<`data-${string}`, unknown>;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
type SharedInputProps = {
|
|
88
|
+
/**
|
|
89
|
+
* Set to `true` to disable the default styling
|
|
90
|
+
*/
|
|
91
|
+
unstyled?: boolean;
|
|
92
|
+
};
|
|
93
|
+
type PartProps<TContainerElement extends HTMLElement = HTMLElement> = {
|
|
94
|
+
container: {
|
|
95
|
+
input: PartProps<TContainerElement>["container"]["output"] & SharedInputProps;
|
|
96
|
+
output: RecordForDataAttr & InferProps<TContainerElement>;
|
|
90
97
|
};
|
|
91
98
|
item: {
|
|
92
|
-
input: PartProps<
|
|
99
|
+
input: PartProps<TContainerElement>["item"]["output"] & SharedInputProps;
|
|
93
100
|
output: InferProps<HTMLElement> & RecordForDataAttr;
|
|
94
101
|
};
|
|
95
102
|
nextButton: {
|
|
96
|
-
input: PartProps<
|
|
97
|
-
output: InferProps<"button"
|
|
103
|
+
input: PartProps<TContainerElement>["nextButton"]["output"] & SharedInputProps;
|
|
104
|
+
output: RecordForDataAttr & InferProps<"button">;
|
|
105
|
+
};
|
|
106
|
+
prevButton: {
|
|
107
|
+
input: PartProps<TContainerElement>["prevButton"]["output"] & SharedInputProps;
|
|
108
|
+
output: RecordForDataAttr & InferProps<"button">;
|
|
98
109
|
};
|
|
99
110
|
root: {
|
|
100
|
-
input: PartProps<
|
|
101
|
-
output:
|
|
102
|
-
ref?: React.Ref<TElement>;
|
|
103
|
-
};
|
|
111
|
+
input: PartProps<TContainerElement>["root"]["output"] & SharedInputProps;
|
|
112
|
+
output: RecordForDataAttr & InferProps<"div">;
|
|
104
113
|
};
|
|
105
|
-
}
|
|
106
|
-
type DragScrollPropGetters<
|
|
114
|
+
};
|
|
115
|
+
type DragScrollPropGetters<TContainerElement extends HTMLElement = HTMLElement> = { [Key in keyof PartProps<TContainerElement> as `get${Capitalize<Key>}Props`]: (props?: PartProps<TContainerElement>[Key]["input"]) => PartProps<TContainerElement>[Key]["output"] };
|
|
116
|
+
type PartInputProps<TContainerElement extends HTMLElement = HTMLElement> = { [Key in keyof PartProps<TContainerElement>]: PartProps<TContainerElement>[Key]["input"] };
|
|
107
117
|
type DragScrollState = {
|
|
108
118
|
/** Whether the container can scroll forward (right/down) */canGoToNext: boolean; /** Whether the container can scroll backward (left/up) */
|
|
109
119
|
canGoToPrev: boolean; /** Whether the user is currently dragging */
|
|
110
120
|
isDragging: boolean;
|
|
111
121
|
};
|
|
112
|
-
type DragScrollActions
|
|
122
|
+
type DragScrollActions = {
|
|
113
123
|
actions: {
|
|
114
124
|
cleanupDragListeners: () => void;
|
|
115
125
|
goToNext: () => void;
|
|
@@ -119,19 +129,12 @@ type DragScrollActions<TElement extends HTMLElement> = {
|
|
|
119
129
|
handleMouseUpOrLeave: () => void;
|
|
120
130
|
handleScroll: () => void;
|
|
121
131
|
initializeResizeObserver: () => (() => void) | undefined;
|
|
122
|
-
setContainerRef: (element:
|
|
132
|
+
setContainerRef: (element: HTMLElement | null) => void;
|
|
123
133
|
updateScrollState: () => void;
|
|
124
134
|
};
|
|
125
135
|
};
|
|
126
|
-
type DragScrollStore
|
|
136
|
+
type DragScrollStore = DragScrollActions & DragScrollState;
|
|
127
137
|
type UseDragScrollProps = {
|
|
128
|
-
/**
|
|
129
|
-
* Custom class names for the root container and items
|
|
130
|
-
*/
|
|
131
|
-
classNames?: {
|
|
132
|
-
base?: string;
|
|
133
|
-
item?: string;
|
|
134
|
-
};
|
|
135
138
|
/**
|
|
136
139
|
* Whether to disable the internal state subscription for setting things like data attributes
|
|
137
140
|
* - This is useful if you want to subscribe to the state yourself
|
|
@@ -162,15 +165,46 @@ type UseDragScrollProps = {
|
|
|
162
165
|
*/
|
|
163
166
|
usage?: "allScreens" | "desktopOnly" | "mobileAndTabletOnly";
|
|
164
167
|
};
|
|
165
|
-
type UseDragScrollResult<
|
|
166
|
-
containerRef: React.RefObject<
|
|
167
|
-
propGetters: DragScrollPropGetters<
|
|
168
|
-
storeApi: ReturnType<typeof createDragScrollStore
|
|
168
|
+
type UseDragScrollResult<TContainerElement extends HTMLElement> = Pick<UseDragScrollProps, "disableInternalStateSubscription"> & {
|
|
169
|
+
containerRef: React.RefObject<TContainerElement | null>;
|
|
170
|
+
propGetters: DragScrollPropGetters<TContainerElement>;
|
|
171
|
+
storeApi: ReturnType<typeof createDragScrollStore>;
|
|
169
172
|
useDragScrollStore: typeof useDragScrollStoreContext;
|
|
170
173
|
};
|
|
171
174
|
//#endregion
|
|
172
175
|
//#region src/components/ui/drag-scroll/use-drag-scroll.d.ts
|
|
173
|
-
declare const useDragScroll: <
|
|
176
|
+
declare const useDragScroll: <TContainerElement extends HTMLElement = HTMLElement>(props?: UseDragScrollProps) => UseDragScrollResult<TContainerElement>;
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/components/ui/drag-scroll/drag-scroll.d.ts
|
|
179
|
+
type DragScrollRootProps = UseDragScrollProps & {
|
|
180
|
+
asChild?: boolean;
|
|
181
|
+
children: React.ReactNode;
|
|
182
|
+
} & PartInputProps["root"];
|
|
183
|
+
declare function DragScrollRoot<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, DragScrollRootProps>): react_jsx_runtime0.JSX.Element;
|
|
184
|
+
type DragScrollContextProps<TSlice> = {
|
|
185
|
+
children: React.ReactNode | ((context: TSlice) => React.ReactNode);
|
|
186
|
+
selector?: SelectorFn<DragScrollStore, TSlice>;
|
|
187
|
+
};
|
|
188
|
+
declare function DragScrollContext<TSlice = DragScrollStore>(props: DragScrollContextProps<TSlice>): react.ReactNode;
|
|
189
|
+
type DragScrollContainerProps = {
|
|
190
|
+
asChild?: boolean;
|
|
191
|
+
} & PartInputProps["container"];
|
|
192
|
+
declare function DragScrollContainer<TElement extends React.ElementType = "ul">(props: PolymorphicPropsStrict<TElement, DragScrollContainerProps>): react_jsx_runtime0.JSX.Element;
|
|
193
|
+
type DragScrollItemProps = {
|
|
194
|
+
asChild?: boolean;
|
|
195
|
+
} & PartInputProps["item"];
|
|
196
|
+
declare function DragScrollItem<TElement extends React.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DragScrollItemProps>): react_jsx_runtime0.JSX.Element;
|
|
197
|
+
type DragScrollPrevProps = {
|
|
198
|
+
asChild?: boolean;
|
|
199
|
+
} & PartInputProps["prevButton"];
|
|
200
|
+
declare function DragScrollPrev(props: DragScrollPrevProps): react_jsx_runtime0.JSX.Element;
|
|
201
|
+
type DragScrollNextProps = {
|
|
202
|
+
asChild?: boolean;
|
|
203
|
+
} & PartInputProps["nextButton"];
|
|
204
|
+
declare function DragScrollNext(props: DragScrollNextProps): react_jsx_runtime0.JSX.Element;
|
|
205
|
+
declare namespace drag_scroll_parts_d_exports {
|
|
206
|
+
export { DragScrollContainer as Container, DragScrollContext as Context, DragScrollItem as Item, DragScrollNext as Next, DragScrollPrev as Prev, DragScrollRoot as Root };
|
|
207
|
+
}
|
|
174
208
|
//#endregion
|
|
175
|
-
export { type DragScrollStore, type UseDragScrollProps, type UseDragScrollResult, useDragScroll };
|
|
209
|
+
export { drag_scroll_parts_d_exports as DragScroll, DragScrollContainer, DragScrollContainerProps, DragScrollContext, DragScrollContextProps, DragScrollItem, DragScrollItemProps, DragScrollNext, DragScrollNextProps, DragScrollPrev, DragScrollPrevProps, DragScrollRoot, DragScrollRootProps, type DragScrollStore, type UseDragScrollProps, type UseDragScrollResult, useDragScroll, useDragScrollStoreContext };
|
|
176
210
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as __exportAll } from "../../chunk-pbuEa-1d.js";
|
|
3
|
+
import { n as SlotRoot } from "../../slot-DuwoiC2C.js";
|
|
4
|
+
import { t as cnMerge } from "../../cn-Bbh2G587.js";
|
|
2
5
|
import { composeRefs, composeTwoEventHandlers } from "@zayne-labs/toolkit-react/utils";
|
|
3
|
-
import { isNumber } from "@zayne-labs/toolkit-type-helpers";
|
|
6
|
+
import { isFunction, isNumber } from "@zayne-labs/toolkit-type-helpers";
|
|
4
7
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
5
|
-
import { useCallbackRef, useStore } from "@zayne-labs/toolkit-react";
|
|
8
|
+
import { createCustomContext, useCallbackRef, useCompareSelector, useStore } from "@zayne-labs/toolkit-react";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
10
|
import { checkIsDeviceMobile, createStore, dataAttr, on, throttleByFrame } from "@zayne-labs/toolkit-core";
|
|
7
|
-
|
|
11
|
+
import { createReactStoreContext } from "@zayne-labs/toolkit-react/zustand";
|
|
8
12
|
//#region src/components/ui/drag-scroll/utils.ts
|
|
9
13
|
const updateCursor = (element) => {
|
|
10
14
|
element.style.cursor = "grabbing";
|
|
@@ -25,19 +29,18 @@ const handleScrollSnap = (dragContainer) => {
|
|
|
25
29
|
if (!checkIsDeviceMobile()) onScrollSnap("remove", dragContainer);
|
|
26
30
|
else onScrollSnap("reset", dragContainer);
|
|
27
31
|
};
|
|
28
|
-
|
|
29
32
|
//#endregion
|
|
30
33
|
//#region src/components/ui/drag-scroll/drag-scroll-store.ts
|
|
31
34
|
const createDragScrollStore = (initStoreValues) => {
|
|
32
35
|
const { orientation = "horizontal", scrollAmount = "item", usage = "allScreens" } = initStoreValues;
|
|
33
36
|
const containerRef = { current: null };
|
|
34
|
-
const positionRef = {
|
|
37
|
+
const positionRef = { current: {
|
|
35
38
|
left: 0,
|
|
36
39
|
top: 0,
|
|
37
40
|
x: 0,
|
|
38
41
|
y: 0
|
|
39
|
-
};
|
|
40
|
-
const
|
|
42
|
+
} };
|
|
43
|
+
const abortControllerRef = { current: {
|
|
41
44
|
mouseLeave: new AbortController(),
|
|
42
45
|
mouseMove: new AbortController(),
|
|
43
46
|
mouseUp: new AbortController()
|
|
@@ -54,9 +57,9 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
54
57
|
isDragging: false,
|
|
55
58
|
actions: {
|
|
56
59
|
cleanupDragListeners: () => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
abortControllerRef.current.mouseMove.abort();
|
|
61
|
+
abortControllerRef.current.mouseUp.abort();
|
|
62
|
+
abortControllerRef.current.mouseLeave.abort();
|
|
60
63
|
},
|
|
61
64
|
goToNext: () => {
|
|
62
65
|
if (!containerRef.current) return;
|
|
@@ -84,39 +87,39 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
84
87
|
if (usage === "mobileAndTabletOnly" && window.innerWidth >= 768) return;
|
|
85
88
|
if (usage === "desktopOnly" && window.innerWidth < 768) return;
|
|
86
89
|
if (!containerRef.current) return;
|
|
87
|
-
|
|
90
|
+
abortControllerRef.current = {
|
|
88
91
|
mouseLeave: new AbortController(),
|
|
89
92
|
mouseMove: new AbortController(),
|
|
90
93
|
mouseUp: new AbortController()
|
|
91
94
|
};
|
|
92
95
|
if (orientation === "horizontal" || orientation === "both") {
|
|
93
|
-
positionRef.x = event.clientX;
|
|
94
|
-
positionRef.left = containerRef.current.scrollLeft;
|
|
96
|
+
positionRef.current.x = event.clientX;
|
|
97
|
+
positionRef.current.left = containerRef.current.scrollLeft;
|
|
95
98
|
}
|
|
96
99
|
if (orientation === "vertical" || orientation === "both") {
|
|
97
|
-
positionRef.y = event.clientY;
|
|
98
|
-
positionRef.top = containerRef.current.scrollTop;
|
|
100
|
+
positionRef.current.y = event.clientY;
|
|
101
|
+
positionRef.current.top = containerRef.current.scrollTop;
|
|
99
102
|
}
|
|
100
103
|
updateCursor(containerRef.current);
|
|
101
104
|
set({ isDragging: true });
|
|
102
105
|
const { actions } = get();
|
|
103
|
-
on("mousemove",
|
|
104
|
-
on("mouseup",
|
|
105
|
-
on("mouseleave",
|
|
106
|
-
on("mouseup",
|
|
106
|
+
on(containerRef.current, "mousemove", actions.handleMouseMove, { signal: abortControllerRef.current.mouseMove.signal });
|
|
107
|
+
on(containerRef.current, "mouseup", actions.handleMouseUpOrLeave, { signal: abortControllerRef.current.mouseUp.signal });
|
|
108
|
+
on(containerRef.current, "mouseleave", actions.handleMouseUpOrLeave, { signal: abortControllerRef.current.mouseLeave.signal });
|
|
109
|
+
on(document, "mouseup", actions.handleMouseUpOrLeave, {
|
|
107
110
|
once: true,
|
|
108
|
-
signal:
|
|
111
|
+
signal: abortControllerRef.current.mouseUp.signal
|
|
109
112
|
});
|
|
110
113
|
},
|
|
111
114
|
handleMouseMove: (event) => {
|
|
112
115
|
if (!containerRef.current) return;
|
|
113
116
|
if (orientation === "horizontal" || orientation === "both") {
|
|
114
|
-
const dx = event.clientX - positionRef.x;
|
|
115
|
-
containerRef.current.scrollLeft = positionRef.left - dx;
|
|
117
|
+
const dx = event.clientX - positionRef.current.x;
|
|
118
|
+
containerRef.current.scrollLeft = positionRef.current.left - dx;
|
|
116
119
|
}
|
|
117
120
|
if (orientation === "vertical" || orientation === "both") {
|
|
118
|
-
const dy = event.clientY - positionRef.y;
|
|
119
|
-
containerRef.current.scrollTop = positionRef.top - dy;
|
|
121
|
+
const dy = event.clientY - positionRef.current.y;
|
|
122
|
+
containerRef.current.scrollTop = positionRef.current.top - dy;
|
|
120
123
|
}
|
|
121
124
|
},
|
|
122
125
|
handleMouseUpOrLeave: () => {
|
|
@@ -168,7 +171,6 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
168
171
|
}
|
|
169
172
|
}));
|
|
170
173
|
};
|
|
171
|
-
|
|
172
174
|
//#endregion
|
|
173
175
|
//#region src/components/ui/drag-scroll/use-drag-scroll.ts
|
|
174
176
|
const getScopeAttrs = (part) => ({
|
|
@@ -177,7 +179,7 @@ const getScopeAttrs = (part) => ({
|
|
|
177
179
|
"data-slot": `drag-scroll-${part}`
|
|
178
180
|
});
|
|
179
181
|
const useDragScroll = (props) => {
|
|
180
|
-
const {
|
|
182
|
+
const { disableInternalStateSubscription = false, orientation = "horizontal", scrollAmount = "item", usage = "allScreens" } = props ?? {};
|
|
181
183
|
const containerRef = useRef(null);
|
|
182
184
|
const storeApi = useMemo(() => {
|
|
183
185
|
return createDragScrollStore({
|
|
@@ -201,8 +203,8 @@ const useDragScroll = (props) => {
|
|
|
201
203
|
containerRef.current = node;
|
|
202
204
|
actions.setContainerRef(node);
|
|
203
205
|
if (!node) return;
|
|
204
|
-
const cleanupMouseDown = on("mousedown",
|
|
205
|
-
const cleanupScroll = on("scroll",
|
|
206
|
+
const cleanupMouseDown = on(node, "mousedown", actions.handleMouseDown);
|
|
207
|
+
const cleanupScroll = on(node, "scroll", actions.handleScroll, { passive: true });
|
|
206
208
|
return () => {
|
|
207
209
|
cleanupMouseDown();
|
|
208
210
|
cleanupScroll();
|
|
@@ -211,33 +213,39 @@ const useDragScroll = (props) => {
|
|
|
211
213
|
useEffect(() => {
|
|
212
214
|
return actions.initializeResizeObserver();
|
|
213
215
|
}, [actions]);
|
|
214
|
-
const getRootProps =
|
|
216
|
+
const getRootProps = useCallbackRef((innerProps) => {
|
|
215
217
|
return {
|
|
216
218
|
...getScopeAttrs("root"),
|
|
219
|
+
...innerProps,
|
|
220
|
+
className: cnMerge("relative", innerProps?.className)
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
const getContainerProps = useCallback((innerProps) => {
|
|
224
|
+
return {
|
|
225
|
+
...getScopeAttrs("container"),
|
|
217
226
|
...!disableInternalStateSubscription && { "data-dragging": dataAttr(isDragging) },
|
|
218
227
|
...innerProps,
|
|
219
|
-
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",
|
|
228
|
+
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),
|
|
220
229
|
ref: composeRefs(refCallback, innerProps?.ref)
|
|
221
230
|
};
|
|
222
231
|
}, [
|
|
223
|
-
classNames?.base,
|
|
224
232
|
disableInternalStateSubscription,
|
|
225
233
|
isDragging,
|
|
226
234
|
orientation,
|
|
227
235
|
refCallback,
|
|
228
236
|
usage
|
|
229
237
|
]);
|
|
230
|
-
const getItemProps =
|
|
238
|
+
const getItemProps = useCallbackRef((innerProps) => {
|
|
231
239
|
return {
|
|
232
240
|
...getScopeAttrs("item"),
|
|
233
241
|
...innerProps,
|
|
234
|
-
className: cnMerge("snap-center snap-always",
|
|
242
|
+
className: cnMerge("snap-center snap-always", innerProps?.className)
|
|
235
243
|
};
|
|
236
|
-
}
|
|
237
|
-
const
|
|
244
|
+
});
|
|
245
|
+
const getPrevButtonProps = useCallback((innerProps) => {
|
|
238
246
|
const isDisabled = innerProps?.disabled ?? !canGoToPrev;
|
|
239
247
|
return {
|
|
240
|
-
...getScopeAttrs("
|
|
248
|
+
...getScopeAttrs("prev-button"),
|
|
241
249
|
type: "button",
|
|
242
250
|
...innerProps,
|
|
243
251
|
"aria-disabled": dataAttr(isDisabled),
|
|
@@ -261,12 +269,14 @@ const useDragScroll = (props) => {
|
|
|
261
269
|
};
|
|
262
270
|
}, [actions.goToNext, canGoToNext]);
|
|
263
271
|
const propGetters = useMemo(() => ({
|
|
264
|
-
|
|
272
|
+
getContainerProps,
|
|
265
273
|
getItemProps,
|
|
266
274
|
getNextButtonProps,
|
|
275
|
+
getPrevButtonProps,
|
|
267
276
|
getRootProps
|
|
268
277
|
}), [
|
|
269
|
-
|
|
278
|
+
getPrevButtonProps,
|
|
279
|
+
getContainerProps,
|
|
270
280
|
getItemProps,
|
|
271
281
|
getNextButtonProps,
|
|
272
282
|
getRootProps
|
|
@@ -285,7 +295,78 @@ const useDragScroll = (props) => {
|
|
|
285
295
|
stableUseDragScrollStore
|
|
286
296
|
]);
|
|
287
297
|
};
|
|
288
|
-
|
|
289
298
|
//#endregion
|
|
290
|
-
|
|
299
|
+
//#region src/components/ui/drag-scroll/drag-scroll-context.ts
|
|
300
|
+
const [DragScrollStoreContextProvider, useDragScrollStoreContext] = createReactStoreContext({
|
|
301
|
+
hookName: "useDragScrollStoreContext",
|
|
302
|
+
name: "DragScrollStoreContext",
|
|
303
|
+
providerName: "DragScrollRoot"
|
|
304
|
+
});
|
|
305
|
+
const [DragScrollRootContextProvider, useDragScrollRootContext] = createCustomContext({
|
|
306
|
+
hookName: "useDragScrollRootContext",
|
|
307
|
+
name: "DragScrollRootContext",
|
|
308
|
+
providerName: "DragScrollRoot"
|
|
309
|
+
});
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/components/ui/drag-scroll/drag-scroll.tsx
|
|
312
|
+
function DragScrollRoot(props) {
|
|
313
|
+
const { as: Element = "div", asChild, children, ...restOfProps } = props;
|
|
314
|
+
const { containerRef, disableInternalStateSubscription, propGetters, storeApi } = useDragScroll(restOfProps);
|
|
315
|
+
return /* @__PURE__ */ jsx(DragScrollStoreContextProvider, {
|
|
316
|
+
store: storeApi,
|
|
317
|
+
children: /* @__PURE__ */ jsx(DragScrollRootContextProvider, {
|
|
318
|
+
value: useMemo(() => ({
|
|
319
|
+
containerRef,
|
|
320
|
+
disableInternalStateSubscription,
|
|
321
|
+
propGetters
|
|
322
|
+
}), [
|
|
323
|
+
containerRef,
|
|
324
|
+
disableInternalStateSubscription,
|
|
325
|
+
propGetters
|
|
326
|
+
]),
|
|
327
|
+
children: /* @__PURE__ */ jsx(asChild ? SlotRoot : Element, {
|
|
328
|
+
...propGetters.getRootProps(restOfProps),
|
|
329
|
+
children
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
function DragScrollContext(props) {
|
|
335
|
+
const { children, selector } = props;
|
|
336
|
+
const dragScrollCtx = useDragScrollStoreContext(useCompareSelector(selector));
|
|
337
|
+
return isFunction(children) ? children(dragScrollCtx) : children;
|
|
338
|
+
}
|
|
339
|
+
function DragScrollContainer(props) {
|
|
340
|
+
const { as: Element = "ul", asChild, ...restOfProps } = props;
|
|
341
|
+
const { propGetters } = useDragScrollRootContext();
|
|
342
|
+
return /* @__PURE__ */ jsx(asChild ? SlotRoot : Element, { ...propGetters.getContainerProps(restOfProps) });
|
|
343
|
+
}
|
|
344
|
+
function DragScrollItem(props) {
|
|
345
|
+
const { as: Element = "li", asChild, ...restOfProps } = props;
|
|
346
|
+
const { propGetters } = useDragScrollRootContext();
|
|
347
|
+
return /* @__PURE__ */ jsx(asChild ? SlotRoot : Element, { ...propGetters.getItemProps(restOfProps) });
|
|
348
|
+
}
|
|
349
|
+
function DragScrollPrev(props) {
|
|
350
|
+
const { asChild, ...restOfProps } = props;
|
|
351
|
+
const { propGetters } = useDragScrollRootContext();
|
|
352
|
+
return /* @__PURE__ */ jsx(asChild ? SlotRoot : "button", { ...propGetters.getPrevButtonProps(restOfProps) });
|
|
353
|
+
}
|
|
354
|
+
function DragScrollNext(props) {
|
|
355
|
+
const { asChild, ...restOfProps } = props;
|
|
356
|
+
const { propGetters } = useDragScrollRootContext();
|
|
357
|
+
return /* @__PURE__ */ jsx(asChild ? SlotRoot : "button", { ...propGetters.getNextButtonProps(restOfProps) });
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/components/ui/drag-scroll/drag-scroll-parts.ts
|
|
361
|
+
var drag_scroll_parts_exports = /* @__PURE__ */ __exportAll({
|
|
362
|
+
Container: () => DragScrollContainer,
|
|
363
|
+
Context: () => DragScrollContext,
|
|
364
|
+
Item: () => DragScrollItem,
|
|
365
|
+
Next: () => DragScrollNext,
|
|
366
|
+
Prev: () => DragScrollPrev,
|
|
367
|
+
Root: () => DragScrollRoot
|
|
368
|
+
});
|
|
369
|
+
//#endregion
|
|
370
|
+
export { drag_scroll_parts_exports as DragScroll, DragScrollContainer, DragScrollContext, DragScrollItem, DragScrollNext, DragScrollPrev, DragScrollRoot, useDragScroll, useDragScrollStoreContext };
|
|
371
|
+
|
|
291
372
|
//# sourceMappingURL=index.js.map
|