@cmdniels/uikit 1.0.5 → 1.0.7
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/out/components/button/Button.d.ts +3 -1
- package/out/components/button/Button.js +4 -3
- package/out/components/button-group/buttonGroupVariants.js +1 -1
- package/out/components/sortable/Sortable.d.ts +37 -33
- package/out/components/sortable/Sortable.js +6 -123
- package/out/components/sortable/SortableContent.d.ts +8 -0
- package/out/components/sortable/SortableContent.js +23 -0
- package/out/components/sortable/SortableContentContext.d.ts +2 -0
- package/out/components/sortable/SortableContentContext.js +3 -0
- package/out/components/sortable/SortableItem.d.ts +17 -0
- package/out/components/sortable/SortableItem.js +67 -0
- package/out/components/sortable/SortableItemHandle.d.ts +4 -0
- package/out/components/sortable/SortableItemHandle.js +32 -0
- package/out/components/sortable/SortableOverlay.d.ts +8 -0
- package/out/components/sortable/SortableOverlay.js +44 -0
- package/out/components/sortable/SortableOverlayContext.d.ts +2 -0
- package/out/components/sortable/SortableOverlayContext.js +4 -0
- package/out/components/sortable/SortableRootContext.d.ts +3 -0
- package/out/components/sortable/SortableRootContext.js +3 -0
- package/out/components/sortable/useSortableContext.d.ts +1 -0
- package/out/components/sortable/useSortableContext.js +9 -0
- package/out/components/sortable/useSortableItemContext.d.ts +1 -0
- package/out/components/sortable/useSortableItemContext.js +9 -0
- package/out/components/spinner/Spinner.d.ts +2 -0
- package/out/components/spinner/Spinner.js +18 -0
- package/out/components/typography/TypographyImg.d.ts +1 -1
- package/out/index.d.ts +6 -1
- package/out/index.js +7 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
2
2
|
import { buttonVariants } from "./buttonVariants";
|
|
3
3
|
import type { VariantProps } from "class-variance-authority";
|
|
4
|
-
export default function Button({ className, variant, size, ...props }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>
|
|
4
|
+
export default function Button({ className, children, variant, size, loading, disabled, ...props }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants> & {
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,11 +9,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
14
14
|
import cn from "../../cn";
|
|
15
|
+
import Spinner from "../../components/spinner/Spinner";
|
|
15
16
|
import { buttonVariants } from "./buttonVariants";
|
|
16
17
|
export default function Button(_a) {
|
|
17
|
-
var { className, variant = "default", size = "default" } = _a, props = __rest(_a, ["className", "variant", "size"]);
|
|
18
|
-
return (
|
|
18
|
+
var { className, children, variant = "default", size = "default", loading = false, disabled } = _a, props = __rest(_a, ["className", "children", "variant", "size", "loading", "disabled"]);
|
|
19
|
+
return (_jsxs(ButtonPrimitive, Object.assign({ "data-slot": "button", className: cn(buttonVariants({ variant, size, className }), "relative"), disabled: disabled !== null && disabled !== void 0 ? disabled : loading }, props, { children: [loading && _jsx(Spinner, { className: "absolute inset-0 m-auto" }), _jsx("span", { className: cn(loading ? "invisible relative" : ""), children: children })] })));
|
|
19
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cva } from "class-variance-authority";
|
|
2
|
-
const buttonGroupVariants = cva("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1", {
|
|
2
|
+
const buttonGroupVariants = cva("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 [&>[data-slot=button]]:border-border has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1", {
|
|
3
3
|
variants: {
|
|
4
4
|
orientation: {
|
|
5
5
|
horizontal: "[&>[data-slot]]:rounded-r-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-r-md! [&>[data-slot]~[data-slot]]:rounded-l-none [&>[data-slot]~[data-slot]]:border-l-0",
|
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
import { type DndContextProps, type DragEndEvent,
|
|
1
|
+
import { type DndContextProps, type DragEndEvent, type UniqueIdentifier } from "@dnd-kit/core";
|
|
2
2
|
import { type SortableContextProps } from "@dnd-kit/sortable";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export declare const orientationConfig: {
|
|
4
|
+
vertical: {
|
|
5
|
+
modifiers: import("@dnd-kit/core").Modifier[];
|
|
6
|
+
strategy: import("@dnd-kit/sortable").SortingStrategy;
|
|
7
|
+
collisionDetection: import("@dnd-kit/core").CollisionDetection;
|
|
8
|
+
};
|
|
9
|
+
horizontal: {
|
|
10
|
+
modifiers: import("@dnd-kit/core").Modifier[];
|
|
11
|
+
strategy: import("@dnd-kit/sortable").SortingStrategy;
|
|
12
|
+
collisionDetection: import("@dnd-kit/core").CollisionDetection;
|
|
13
|
+
};
|
|
14
|
+
mixed: {
|
|
15
|
+
modifiers: import("@dnd-kit/core").Modifier[];
|
|
16
|
+
strategy: undefined;
|
|
17
|
+
collisionDetection: import("@dnd-kit/core").CollisionDetection;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export interface SortableRootContextValue<T> {
|
|
21
|
+
id: string;
|
|
22
|
+
items: UniqueIdentifier[];
|
|
23
|
+
modifiers: DndContextProps["modifiers"];
|
|
24
|
+
strategy: SortableContextProps["strategy"];
|
|
25
|
+
activeId: UniqueIdentifier | null;
|
|
26
|
+
setActiveId: (id: UniqueIdentifier | null) => void;
|
|
27
|
+
getItemValue: (item: T) => UniqueIdentifier;
|
|
28
|
+
flatCursor: boolean;
|
|
29
|
+
}
|
|
30
|
+
export default function Sortable<T>(props: DndContextProps & (T extends object ? {
|
|
5
31
|
/**
|
|
6
32
|
* Callback that returns a unique identifier for each sortable item. Required for array of objects.
|
|
7
33
|
* @example getItemValue={(item) => item.id}
|
|
8
34
|
*/
|
|
9
35
|
getItemValue: (item: T) => UniqueIdentifier;
|
|
10
|
-
}
|
|
11
|
-
|
|
36
|
+
} : {
|
|
37
|
+
/**
|
|
38
|
+
* Callback that returns a unique identifier for each sortable item. Required for array of objects.
|
|
39
|
+
* @example getItemValue={(item) => item.id}
|
|
40
|
+
*/
|
|
41
|
+
getItemValue?: (item: T) => UniqueIdentifier;
|
|
42
|
+
}) & {
|
|
12
43
|
value: T[];
|
|
13
44
|
onValueChange?: (items: T[]) => void;
|
|
14
45
|
onMove?: (event: DragEndEvent & {
|
|
@@ -18,31 +49,4 @@ type SortableProps<T> = DndContextProps & (T extends object ? GetItemValue<T> :
|
|
|
18
49
|
strategy?: SortableContextProps["strategy"];
|
|
19
50
|
orientation?: "vertical" | "horizontal" | "mixed";
|
|
20
51
|
flatCursor?: boolean;
|
|
21
|
-
};
|
|
22
|
-
declare function Sortable<T>(props: SortableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
interface SortableContentProps<T extends ElementType = "div"> {
|
|
24
|
-
strategy?: SortableContextProps["strategy"];
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
render?: ReactElement<T>;
|
|
27
|
-
withoutSlot?: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare function SortableContent<T extends ElementType = "div">(props: SortableContentProps<T> & ComponentPropsWithRef<T>): import("react/jsx-runtime").JSX.Element;
|
|
30
|
-
interface SortableItemProps<T extends ElementType = "div"> {
|
|
31
|
-
value: UniqueIdentifier;
|
|
32
|
-
asHandle?: boolean;
|
|
33
|
-
render?: ReactElement<T>;
|
|
34
|
-
disabled?: boolean;
|
|
35
|
-
}
|
|
36
|
-
declare function SortableItem<T extends ElementType = "div">(props: SortableItemProps<T> & ComponentPropsWithRef<T>): import("react/jsx-runtime").JSX.Element;
|
|
37
|
-
interface SortableItemHandleProps<T extends ElementType = "button"> {
|
|
38
|
-
render?: ReactElement<T>;
|
|
39
|
-
}
|
|
40
|
-
declare function SortableItemHandle<T extends ElementType = "button">(props: SortableItemHandleProps<T> & ComponentPropsWithRef<T>): import("react/jsx-runtime").JSX.Element;
|
|
41
|
-
interface SortableOverlayProps extends Omit<ComponentProps<typeof DragOverlay>, "children"> {
|
|
42
|
-
container?: Element | DocumentFragment | null;
|
|
43
|
-
children?: ((params: {
|
|
44
|
-
value: UniqueIdentifier;
|
|
45
|
-
}) => ReactNode) | ReactNode;
|
|
46
|
-
}
|
|
47
|
-
declare function SortableOverlay(props: SortableOverlayProps): import("react").ReactPortal | null;
|
|
48
|
-
export { Sortable, SortableContent, SortableItem, SortableItemHandle, SortableOverlay, type SortableProps, };
|
|
52
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,15 +11,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { closestCenter, closestCorners,
|
|
14
|
+
import { closestCenter, closestCorners, DndContext, KeyboardSensor, MouseSensor, TouchSensor, useSensor, useSensors, } from "@dnd-kit/core";
|
|
15
15
|
import { restrictToHorizontalAxis, restrictToParentElement, restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
16
|
-
import { arrayMove, horizontalListSortingStrategy,
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
import * as ReactDOM from "react-dom";
|
|
21
|
-
import cn from "../../cn";
|
|
22
|
-
const orientationConfig = {
|
|
16
|
+
import { arrayMove, horizontalListSortingStrategy, sortableKeyboardCoordinates, verticalListSortingStrategy, } from "@dnd-kit/sortable";
|
|
17
|
+
import { useCallback, useId, useMemo, useState } from "react";
|
|
18
|
+
import SortableRootContext from "./SortableRootContext";
|
|
19
|
+
export const orientationConfig = {
|
|
23
20
|
vertical: {
|
|
24
21
|
modifiers: [restrictToVerticalAxis, restrictToParentElement],
|
|
25
22
|
strategy: verticalListSortingStrategy,
|
|
@@ -36,20 +33,7 @@ const orientationConfig = {
|
|
|
36
33
|
collisionDetection: closestCorners,
|
|
37
34
|
},
|
|
38
35
|
};
|
|
39
|
-
|
|
40
|
-
const CONTENT_NAME = "SortableContent";
|
|
41
|
-
const ITEM_NAME = "SortableItem";
|
|
42
|
-
const ITEM_HANDLE_NAME = "SortableItemHandle";
|
|
43
|
-
const OVERLAY_NAME = "SortableOverlay";
|
|
44
|
-
const SortableRootContext = createContext(null);
|
|
45
|
-
function useSortableContext(consumerName) {
|
|
46
|
-
const context = useContext(SortableRootContext);
|
|
47
|
-
if (!context) {
|
|
48
|
-
throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);
|
|
49
|
-
}
|
|
50
|
-
return context;
|
|
51
|
-
}
|
|
52
|
-
function Sortable(props) {
|
|
36
|
+
export default function Sortable(props) {
|
|
53
37
|
const { value, onValueChange, collisionDetection, modifiers, strategy, onMove, orientation = "vertical", flatCursor = false, getItemValue: getItemValueProp, accessibility, onDragStart: onDragStartProp, onDragEnd: onDragEndProp, onDragCancel: onDragCancelProp } = props, sortableProps = __rest(props, ["value", "onValueChange", "collisionDetection", "modifiers", "strategy", "onMove", "orientation", "flatCursor", "getItemValue", "accessibility", "onDragStart", "onDragEnd", "onDragCancel"]);
|
|
54
38
|
const id = useId();
|
|
55
39
|
const [activeId, setActiveId] = useState(null);
|
|
@@ -160,104 +144,3 @@ function Sortable(props) {
|
|
|
160
144
|
return (_jsx(SortableRootContext.Provider, { value: contextValue, children: _jsx(DndContext, Object.assign({ collisionDetection: collisionDetection !== null && collisionDetection !== void 0 ? collisionDetection : config.collisionDetection, modifiers: modifiers !== null && modifiers !== void 0 ? modifiers : config.modifiers, sensors: sensors }, sortableProps, { id: id, onDragStart: onDragStart, onDragEnd: onDragEnd, onDragCancel: onDragCancel, accessibility: Object.assign({ announcements,
|
|
161
145
|
screenReaderInstructions }, accessibility) })) }));
|
|
162
146
|
}
|
|
163
|
-
const SortableContentContext = createContext(false);
|
|
164
|
-
function SortableContent(props) {
|
|
165
|
-
const { strategy: strategyProp, render, withoutSlot, children } = props, contentProps = __rest(props, ["strategy", "render", "withoutSlot", "children"]);
|
|
166
|
-
const context = useSortableContext(CONTENT_NAME);
|
|
167
|
-
const element = render ? (cloneElement(render, Object.assign(Object.assign(Object.assign({}, contentProps), render.props), { children, "data-slot": "sortable-content" }))) : (_jsx("div", Object.assign({ "data-slot": "sortable-content" }, contentProps, { children: children })));
|
|
168
|
-
return (_jsx(SortableContentContext.Provider, { value: true, children: _jsx(SortableContext, { items: context.items, strategy: strategyProp !== null && strategyProp !== void 0 ? strategyProp : context.strategy, children: withoutSlot ? children : element }) }));
|
|
169
|
-
}
|
|
170
|
-
const SortableItemContext = createContext(null);
|
|
171
|
-
function useSortableItemContext(consumerName) {
|
|
172
|
-
const context = useContext(SortableItemContext);
|
|
173
|
-
if (!context) {
|
|
174
|
-
throw new Error(`\`${consumerName}\` must be used within \`${ITEM_NAME}\``);
|
|
175
|
-
}
|
|
176
|
-
return context;
|
|
177
|
-
}
|
|
178
|
-
function SortableItem(props) {
|
|
179
|
-
const { value, style, asHandle, render, disabled, className, ref } = props, itemProps = __rest(props, ["value", "style", "asHandle", "render", "disabled", "className", "ref"]);
|
|
180
|
-
const inSortableContent = useContext(SortableContentContext);
|
|
181
|
-
const inSortableOverlay = useContext(SortableOverlayContext);
|
|
182
|
-
if (!inSortableContent && !inSortableOverlay) {
|
|
183
|
-
throw new Error(`\`${ITEM_NAME}\` must be used within \`${CONTENT_NAME}\` or \`${OVERLAY_NAME}\``);
|
|
184
|
-
}
|
|
185
|
-
if (value === "") {
|
|
186
|
-
throw new Error(`\`${ITEM_NAME}\` value cannot be an empty string`);
|
|
187
|
-
}
|
|
188
|
-
const context = useSortableContext(ITEM_NAME);
|
|
189
|
-
const id = useId();
|
|
190
|
-
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
|
|
191
|
-
id: value,
|
|
192
|
-
disabled,
|
|
193
|
-
});
|
|
194
|
-
const composedRef = useComposedRefs(ref, (node) => {
|
|
195
|
-
if (disabled) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
setNodeRef(node);
|
|
199
|
-
if (asHandle) {
|
|
200
|
-
setActivatorNodeRef(node);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
const composedStyle = useMemo(() => (Object.assign({ transform: CSS.Translate.toString(transform), transition }, style)), [transform, transition, style]);
|
|
204
|
-
const itemContext = useMemo(() => ({
|
|
205
|
-
id,
|
|
206
|
-
attributes,
|
|
207
|
-
listeners,
|
|
208
|
-
setActivatorNodeRef,
|
|
209
|
-
isDragging,
|
|
210
|
-
disabled,
|
|
211
|
-
}), [id, attributes, listeners, setActivatorNodeRef, isDragging, disabled]);
|
|
212
|
-
const mergedProps = Object.assign(Object.assign(Object.assign(Object.assign({ id, "data-disabled": disabled, "data-dragging": isDragging ? "" : undefined, "data-slot": "sortable-item" }, itemProps), (asHandle && !disabled ? attributes : {})), (asHandle && !disabled ? listeners : {})), { ref: composedRef, style: composedStyle, className: cn("focus-visible:ring-1 focus-visible:ring-neutral-950 focus-visible:ring-offset-1 focus-visible:outline-hidden dark:focus-visible:ring-neutral-300", {
|
|
213
|
-
"touch-none select-none": asHandle,
|
|
214
|
-
"cursor-default": context.flatCursor,
|
|
215
|
-
"data-dragging:cursor-grabbing": !context.flatCursor,
|
|
216
|
-
"cursor-grab": !isDragging && asHandle && !context.flatCursor,
|
|
217
|
-
"opacity-50": isDragging,
|
|
218
|
-
"pointer-events-none opacity-50": disabled,
|
|
219
|
-
}, className) });
|
|
220
|
-
const element = render ? cloneElement(render, mergedProps) : _jsx("div", Object.assign({}, mergedProps));
|
|
221
|
-
return _jsx(SortableItemContext.Provider, { value: itemContext, children: element });
|
|
222
|
-
}
|
|
223
|
-
function SortableItemHandle(props) {
|
|
224
|
-
const { render, disabled, className } = props, itemHandleProps = __rest(props, ["render", "disabled", "className"]);
|
|
225
|
-
const context = useSortableContext(ITEM_HANDLE_NAME);
|
|
226
|
-
const itemContext = useSortableItemContext(ITEM_HANDLE_NAME);
|
|
227
|
-
const isDisabled = disabled !== null && disabled !== void 0 ? disabled : itemContext.disabled;
|
|
228
|
-
const composedRef = useComposedRefs(itemHandleProps.ref, (node) => {
|
|
229
|
-
if (!isDisabled) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
itemContext.setActivatorNodeRef(node);
|
|
233
|
-
});
|
|
234
|
-
const mergedProps = Object.assign(Object.assign(Object.assign(Object.assign({ type: "button", "aria-controls": itemContext.id, "data-disabled": isDisabled, "data-dragging": itemContext.isDragging ? "" : undefined, "data-slot": "sortable-item-handle" }, itemHandleProps), (isDisabled ? {} : itemContext.attributes)), (isDisabled ? {} : itemContext.listeners)), { ref: composedRef, className: cn("select-none disabled:pointer-events-none disabled:opacity-50", context.flatCursor ? "cursor-default" : "cursor-grab data-dragging:cursor-grabbing", className), disabled: isDisabled });
|
|
235
|
-
return render ? cloneElement(render, mergedProps) : _jsx("button", Object.assign({}, mergedProps));
|
|
236
|
-
}
|
|
237
|
-
const SortableOverlayContext = createContext(false);
|
|
238
|
-
const dropAnimation = {
|
|
239
|
-
sideEffects: defaultDropAnimationSideEffects({
|
|
240
|
-
styles: {
|
|
241
|
-
active: {
|
|
242
|
-
opacity: "0.4",
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
}),
|
|
246
|
-
};
|
|
247
|
-
function SortableOverlay(props) {
|
|
248
|
-
var _a;
|
|
249
|
-
const { container: containerProp, children } = props, overlayProps = __rest(props, ["container", "children"]);
|
|
250
|
-
const context = useSortableContext(OVERLAY_NAME);
|
|
251
|
-
const [mounted, setMounted] = useState(false);
|
|
252
|
-
useLayoutEffect(() => setMounted(true), []);
|
|
253
|
-
const container = containerProp !== null && containerProp !== void 0 ? containerProp : (mounted ? (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.body : null);
|
|
254
|
-
if (!container) {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
return ReactDOM.createPortal(_jsx(DragOverlay, Object.assign({ dropAnimation: dropAnimation, modifiers: context.modifiers, className: cn(!context.flatCursor && "cursor-grabbing") }, overlayProps, { children: _jsx(SortableOverlayContext.Provider, { value: true, children: context.activeId
|
|
258
|
-
? typeof children === "function"
|
|
259
|
-
? children({ value: context.activeId })
|
|
260
|
-
: children
|
|
261
|
-
: null }) })), container);
|
|
262
|
-
}
|
|
263
|
-
export { Sortable, SortableContent, SortableItem, SortableItemHandle, SortableOverlay, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SortableContextProps } from "@dnd-kit/sortable";
|
|
2
|
+
import { type ComponentPropsWithRef, type ElementType, type ReactElement, type ReactNode } from "react";
|
|
3
|
+
export default function SortableContent<T extends ElementType = "div">(props: {
|
|
4
|
+
strategy?: SortableContextProps["strategy"];
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
render?: ReactElement<T>;
|
|
7
|
+
withoutSlot?: boolean;
|
|
8
|
+
} & ComponentPropsWithRef<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { SortableContext } from "@dnd-kit/sortable";
|
|
15
|
+
import { cloneElement } from "react";
|
|
16
|
+
import SortableContentContext from "./SortableContentContext";
|
|
17
|
+
import useSortableContext from "./useSortableContext";
|
|
18
|
+
export default function SortableContent(props) {
|
|
19
|
+
const { strategy: strategyProp, render, withoutSlot, children } = props, contentProps = __rest(props, ["strategy", "render", "withoutSlot", "children"]);
|
|
20
|
+
const context = useSortableContext();
|
|
21
|
+
const element = render ? (cloneElement(render, Object.assign(Object.assign(Object.assign({}, contentProps), render.props), { children, "data-slot": "sortable-content" }))) : (_jsx("div", Object.assign({ "data-slot": "sortable-content" }, contentProps, { children: children })));
|
|
22
|
+
return (_jsx(SortableContentContext.Provider, { value: true, children: _jsx(SortableContext, { items: context.items, strategy: strategyProp !== null && strategyProp !== void 0 ? strategyProp : context.strategy, children: withoutSlot ? children : element }) }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type UniqueIdentifier, type DraggableAttributes, type DraggableSyntheticListeners } from "@dnd-kit/core";
|
|
2
|
+
import { type ComponentPropsWithRef, type ElementType, type ReactElement } from "react";
|
|
3
|
+
export interface SortableItemContextValue {
|
|
4
|
+
id: string;
|
|
5
|
+
attributes: DraggableAttributes;
|
|
6
|
+
listeners: DraggableSyntheticListeners | undefined;
|
|
7
|
+
setActivatorNodeRef: (node: HTMLElement | null) => void;
|
|
8
|
+
isDragging?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const SortableItemContext: import("react").Context<SortableItemContextValue | null>;
|
|
12
|
+
export default function SortableItem<T extends ElementType = "div">(props: {
|
|
13
|
+
value: UniqueIdentifier;
|
|
14
|
+
asHandle?: boolean;
|
|
15
|
+
render?: ReactElement<T>;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
} & ComponentPropsWithRef<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
15
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
16
|
+
import { useComposedRefs } from "motion/react";
|
|
17
|
+
import { cloneElement, createContext, useContext, useId, useMemo, } from "react";
|
|
18
|
+
import cn from "../../cn";
|
|
19
|
+
import SortableContentContext from "./SortableContentContext";
|
|
20
|
+
import SortableOverlayContext from "./SortableOverlayContext";
|
|
21
|
+
import useSortableContext from "./useSortableContext";
|
|
22
|
+
export const SortableItemContext = createContext(null);
|
|
23
|
+
export default function SortableItem(props) {
|
|
24
|
+
const { value, style, asHandle, render, disabled, className, ref } = props, itemProps = __rest(props, ["value", "style", "asHandle", "render", "disabled", "className", "ref"]);
|
|
25
|
+
const inSortableContent = useContext(SortableContentContext);
|
|
26
|
+
const inSortableOverlay = useContext(SortableOverlayContext);
|
|
27
|
+
if (!inSortableContent && !inSortableOverlay) {
|
|
28
|
+
throw new Error("`SortableItem` must be used within `SortableContent` or `SortableOverlay`");
|
|
29
|
+
}
|
|
30
|
+
if (value === "") {
|
|
31
|
+
throw new Error("`SortableItem` value cannot be an empty string");
|
|
32
|
+
}
|
|
33
|
+
const context = useSortableContext();
|
|
34
|
+
const id = useId();
|
|
35
|
+
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
|
|
36
|
+
id: value,
|
|
37
|
+
disabled,
|
|
38
|
+
});
|
|
39
|
+
const composedRef = useComposedRefs(ref, (node) => {
|
|
40
|
+
if (disabled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
setNodeRef(node);
|
|
44
|
+
if (asHandle) {
|
|
45
|
+
setActivatorNodeRef(node);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const composedStyle = useMemo(() => (Object.assign({ transform: CSS.Translate.toString(transform), transition }, style)), [transform, transition, style]);
|
|
49
|
+
const itemContext = useMemo(() => ({
|
|
50
|
+
id,
|
|
51
|
+
attributes,
|
|
52
|
+
listeners,
|
|
53
|
+
setActivatorNodeRef,
|
|
54
|
+
isDragging,
|
|
55
|
+
disabled,
|
|
56
|
+
}), [id, attributes, listeners, setActivatorNodeRef, isDragging, disabled]);
|
|
57
|
+
const mergedProps = Object.assign(Object.assign(Object.assign(Object.assign({ id, "data-disabled": disabled, "data-dragging": isDragging ? "" : undefined, "data-slot": "sortable-item" }, itemProps), (asHandle && !disabled ? attributes : {})), (asHandle && !disabled ? listeners : {})), { ref: composedRef, style: composedStyle, className: cn("focus-visible:ring-1 focus-visible:ring-neutral-950 focus-visible:ring-offset-1 focus-visible:outline-hidden dark:focus-visible:ring-neutral-300", {
|
|
58
|
+
"touch-none select-none": asHandle,
|
|
59
|
+
"cursor-default": context.flatCursor,
|
|
60
|
+
"data-dragging:cursor-grabbing": !context.flatCursor,
|
|
61
|
+
"cursor-grab": !isDragging && asHandle && !context.flatCursor,
|
|
62
|
+
"opacity-50": isDragging,
|
|
63
|
+
"pointer-events-none opacity-50": disabled,
|
|
64
|
+
}, className) });
|
|
65
|
+
const element = render ? cloneElement(render, mergedProps) : _jsx("div", Object.assign({}, mergedProps));
|
|
66
|
+
return _jsx(SortableItemContext.Provider, { value: itemContext, children: element });
|
|
67
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ElementType, type ReactElement } from "react";
|
|
2
|
+
export default function SortableItemHandle<T extends ElementType = "button">(props: {
|
|
3
|
+
render?: ReactElement<T>;
|
|
4
|
+
} & ComponentPropsWithRef<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { useComposedRefs } from "motion/react";
|
|
15
|
+
import { cloneElement } from "react";
|
|
16
|
+
import cn from "../../cn";
|
|
17
|
+
import useSortableContext from "./useSortableContext";
|
|
18
|
+
import useSortableItemContext from "./useSortableItemContext";
|
|
19
|
+
export default function SortableItemHandle(props) {
|
|
20
|
+
const { render, disabled, className } = props, itemHandleProps = __rest(props, ["render", "disabled", "className"]);
|
|
21
|
+
const context = useSortableContext();
|
|
22
|
+
const itemContext = useSortableItemContext();
|
|
23
|
+
const isDisabled = disabled !== null && disabled !== void 0 ? disabled : itemContext.disabled;
|
|
24
|
+
const composedRef = useComposedRefs(itemHandleProps.ref, (node) => {
|
|
25
|
+
if (!isDisabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
itemContext.setActivatorNodeRef(node);
|
|
29
|
+
});
|
|
30
|
+
const mergedProps = Object.assign(Object.assign(Object.assign(Object.assign({ type: "button", "aria-controls": itemContext.id, "data-disabled": isDisabled, "data-dragging": itemContext.isDragging ? "" : undefined, "data-slot": "sortable-item-handle" }, itemHandleProps), (isDisabled ? {} : itemContext.attributes)), (isDisabled ? {} : itemContext.listeners)), { ref: composedRef, className: cn("select-none disabled:pointer-events-none disabled:opacity-50", context.flatCursor ? "cursor-default" : "cursor-grab data-dragging:cursor-grabbing", className), disabled: isDisabled });
|
|
31
|
+
return render ? cloneElement(render, mergedProps) : _jsx("button", Object.assign({}, mergedProps));
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type UniqueIdentifier, DragOverlay } from "@dnd-kit/core";
|
|
2
|
+
import { type ComponentProps, type ReactNode } from "react";
|
|
3
|
+
export default function SortableOverlay(props: {
|
|
4
|
+
container?: Element | DocumentFragment | null;
|
|
5
|
+
children?: ((params: {
|
|
6
|
+
value: UniqueIdentifier;
|
|
7
|
+
}) => ReactNode) | ReactNode;
|
|
8
|
+
} & Omit<ComponentProps<typeof DragOverlay>, "children">): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { DragOverlay, defaultDropAnimationSideEffects } from "@dnd-kit/core";
|
|
15
|
+
import { useLayoutEffect, useState } from "react";
|
|
16
|
+
import * as ReactDOM from "react-dom";
|
|
17
|
+
import cn from "../../cn";
|
|
18
|
+
import SortableOverlayContext from "./SortableOverlayContext";
|
|
19
|
+
import useSortableContext from "./useSortableContext";
|
|
20
|
+
const dropAnimation = {
|
|
21
|
+
sideEffects: defaultDropAnimationSideEffects({
|
|
22
|
+
styles: {
|
|
23
|
+
active: {
|
|
24
|
+
opacity: "0.4",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
export default function SortableOverlay(props) {
|
|
30
|
+
var _a;
|
|
31
|
+
const { container: containerProp, children } = props, overlayProps = __rest(props, ["container", "children"]);
|
|
32
|
+
const context = useSortableContext();
|
|
33
|
+
const [mounted, setMounted] = useState(false);
|
|
34
|
+
useLayoutEffect(() => setMounted(true), []);
|
|
35
|
+
const container = containerProp !== null && containerProp !== void 0 ? containerProp : (mounted ? (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.body : null);
|
|
36
|
+
if (!container) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return ReactDOM.createPortal(_jsx(DragOverlay, Object.assign({ dropAnimation: dropAnimation, modifiers: context.modifiers, className: cn(!context.flatCursor && "cursor-grabbing") }, overlayProps, { children: _jsx(SortableOverlayContext.Provider, { value: true, children: context.activeId
|
|
40
|
+
? typeof children === "function"
|
|
41
|
+
? children({ value: context.activeId })
|
|
42
|
+
: children
|
|
43
|
+
: null }) })), container);
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useSortableContext(): import("./Sortable").SortableRootContextValue<unknown>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import SortableRootContext from "./SortableRootContext";
|
|
3
|
+
export default function useSortableContext() {
|
|
4
|
+
const context = useContext(SortableRootContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("`useSortableContext` must be used within `Sortable`");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useSortableItemContext(): import("./SortableItem").SortableItemContextValue;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { SortableItemContext } from "./SortableItem";
|
|
3
|
+
export default function useSortableItemContext() {
|
|
4
|
+
const context = useContext(SortableItemContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("`useSortableItemContext` must be used within `SortableItem`");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { IconLoader } from "@tabler/icons-react";
|
|
14
|
+
import cn from "../../cn";
|
|
15
|
+
export default function Spinner(_a) {
|
|
16
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
17
|
+
return (_jsx(IconLoader, Object.assign({ role: "status", "aria-label": "Loading", className: cn("size-4 animate-spin", className) }, props)));
|
|
18
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const TypographyImg: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref" | "height" | "width" | "
|
|
1
|
+
declare const TypographyImg: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref" | "height" | "width" | "loading" | "alt" | "src" | "srcSet"> & {
|
|
2
2
|
src: string | import("next/dist/shared/lib/get-img-props").StaticImport;
|
|
3
3
|
alt: string;
|
|
4
4
|
width?: number | `${number}`;
|
package/out/index.d.ts
CHANGED
|
@@ -135,7 +135,12 @@ export { default as SelectValue } from "./components/select/SelectValue";
|
|
|
135
135
|
export { default as Separator } from "./components/separator/Separator";
|
|
136
136
|
export { default as Skeleton } from "./components/skeleton/Skeleton";
|
|
137
137
|
export { default as Toaster } from "./components/sonner/Toaster";
|
|
138
|
-
export
|
|
138
|
+
export { default as Sortable } from "./components/sortable/Sortable";
|
|
139
|
+
export { default as SortableContent } from "./components/sortable/SortableContent";
|
|
140
|
+
export { default as SortableItem } from "./components/sortable/SortableItem";
|
|
141
|
+
export { default as SortableItemHandle } from "./components/sortable/SortableItemHandle";
|
|
142
|
+
export { default as SortableOverlay } from "./components/sortable/SortableOverlay";
|
|
143
|
+
export { default as Spinner } from "./components/spinner/Spinner";
|
|
139
144
|
export { default as Switch } from "./components/switch/Switch";
|
|
140
145
|
export { default as Table } from "./components/table/Table";
|
|
141
146
|
export { default as TableBody } from "./components/table/TableBody";
|
package/out/index.js
CHANGED
|
@@ -165,7 +165,13 @@ export { default as Skeleton } from "./components/skeleton/Skeleton";
|
|
|
165
165
|
// Sonner
|
|
166
166
|
export { default as Toaster } from "./components/sonner/Toaster";
|
|
167
167
|
// Sortable
|
|
168
|
-
export
|
|
168
|
+
export { default as Sortable } from "./components/sortable/Sortable";
|
|
169
|
+
export { default as SortableContent } from "./components/sortable/SortableContent";
|
|
170
|
+
export { default as SortableItem } from "./components/sortable/SortableItem";
|
|
171
|
+
export { default as SortableItemHandle } from "./components/sortable/SortableItemHandle";
|
|
172
|
+
export { default as SortableOverlay } from "./components/sortable/SortableOverlay";
|
|
173
|
+
// Spinner
|
|
174
|
+
export { default as Spinner } from "./components/spinner/Spinner";
|
|
169
175
|
// Switch
|
|
170
176
|
export { default as Switch } from "./components/switch/Switch";
|
|
171
177
|
// Table
|