@opencosmos/ui 1.3.1
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/.claude/CLAUDE.md +239 -0
- package/README.md +161 -0
- package/dist/cli.mjs +151 -0
- package/dist/dates.d.mts +20 -0
- package/dist/dates.d.ts +20 -0
- package/dist/dates.js +240 -0
- package/dist/dates.js.map +1 -0
- package/dist/dates.mjs +203 -0
- package/dist/dates.mjs.map +1 -0
- package/dist/dnd.d.mts +126 -0
- package/dist/dnd.d.ts +126 -0
- package/dist/dnd.js +274 -0
- package/dist/dnd.js.map +1 -0
- package/dist/dnd.mjs +250 -0
- package/dist/dnd.mjs.map +1 -0
- package/dist/fontThemes-Dh8mtXES.d.mts +868 -0
- package/dist/fontThemes-Dh8mtXES.d.ts +868 -0
- package/dist/forms.d.mts +38 -0
- package/dist/forms.d.ts +38 -0
- package/dist/forms.js +198 -0
- package/dist/forms.js.map +1 -0
- package/dist/forms.mjs +159 -0
- package/dist/forms.mjs.map +1 -0
- package/dist/hooks-1b8WaQf1.d.mts +225 -0
- package/dist/hooks-CKW8vE9H.d.ts +225 -0
- package/dist/hooks.d.mts +3 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +971 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hooks.mjs +943 -0
- package/dist/hooks.mjs.map +1 -0
- package/dist/index-DscTIrZ2.d.mts +29 -0
- package/dist/index-DscTIrZ2.d.ts +29 -0
- package/dist/index.d.mts +3382 -0
- package/dist/index.d.ts +3382 -0
- package/dist/index.js +15146 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14802 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers-CXPDMsl7.d.mts +30 -0
- package/dist/providers-Dn_Msjvz.d.ts +30 -0
- package/dist/providers.d.mts +3 -0
- package/dist/providers.d.ts +3 -0
- package/dist/providers.js +1885 -0
- package/dist/providers.js.map +1 -0
- package/dist/providers.mjs +1859 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/tables.d.mts +10 -0
- package/dist/tables.d.ts +10 -0
- package/dist/tables.js +248 -0
- package/dist/tables.js.map +1 -0
- package/dist/tables.mjs +218 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tokens.d.mts +1065 -0
- package/dist/tokens.d.ts +1065 -0
- package/dist/tokens.js +2637 -0
- package/dist/tokens.js.map +1 -0
- package/dist/tokens.mjs +2555 -0
- package/dist/tokens.mjs.map +1 -0
- package/dist/utils-CIIM7dAC.d.ts +986 -0
- package/dist/utils-Cs04sxth.d.mts +986 -0
- package/dist/utils.d.mts +4 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +874 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +806 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/validation-Bj1ye-v_.d.mts +114 -0
- package/dist/validation-Bj1ye-v_.d.ts +114 -0
- package/dist/webgl.d.mts +104 -0
- package/dist/webgl.d.ts +104 -0
- package/dist/webgl.js +226 -0
- package/dist/webgl.js.map +1 -0
- package/dist/webgl.mjs +195 -0
- package/dist/webgl.mjs.map +1 -0
- package/package.json +267 -0
- package/src/cli.ts +206 -0
- package/src/component-registry.ts +183 -0
- package/src/components/actions/Button.test.tsx +61 -0
- package/src/components/actions/Button.tsx +70 -0
- package/src/components/actions/Link.tsx +78 -0
- package/src/components/actions/Magnetic.tsx +68 -0
- package/src/components/actions/Toggle.test.tsx +40 -0
- package/src/components/actions/Toggle.tsx +47 -0
- package/src/components/actions/ToggleGroup.tsx +70 -0
- package/src/components/actions/index.ts +5 -0
- package/src/components/backgrounds/FaultyTerminal.tsx +426 -0
- package/src/components/backgrounds/OrbBackground.tsx +424 -0
- package/src/components/backgrounds/WarpBackground.tsx +358 -0
- package/src/components/backgrounds/index.ts +3 -0
- package/src/components/blocks/Hero.tsx +142 -0
- package/src/components/blocks/social/OpenGraphCard.tsx +243 -0
- package/src/components/cursor/SplashCursor.tsx +1315 -0
- package/src/components/cursor/TargetCursor.tsx +187 -0
- package/src/components/cursor/index.ts +2 -0
- package/src/components/data-display/AspectImage.tsx +73 -0
- package/src/components/data-display/Avatar.test.tsx +35 -0
- package/src/components/data-display/Avatar.tsx +55 -0
- package/src/components/data-display/Badge.test.tsx +43 -0
- package/src/components/data-display/Badge.tsx +84 -0
- package/src/components/data-display/Brand.tsx +123 -0
- package/src/components/data-display/Calendar.tsx +70 -0
- package/src/components/data-display/Card.test.tsx +92 -0
- package/src/components/data-display/Card.tsx +115 -0
- package/src/components/data-display/Code.tsx +210 -0
- package/src/components/data-display/CollapsibleCodeBlock.tsx +238 -0
- package/src/components/data-display/DataTable.tsx +119 -0
- package/src/components/data-display/DescriptionList.tsx +41 -0
- package/src/components/data-display/GitHubIcon.tsx +44 -0
- package/src/components/data-display/Heading.test.tsx +36 -0
- package/src/components/data-display/Heading.tsx +83 -0
- package/src/components/data-display/StatCard.tsx +195 -0
- package/src/components/data-display/Table.tsx +133 -0
- package/src/components/data-display/Text.test.tsx +48 -0
- package/src/components/data-display/Text.tsx +144 -0
- package/src/components/data-display/Timeline.tsx +194 -0
- package/src/components/data-display/TreeView.tsx +226 -0
- package/src/components/data-display/Typewriter.tsx +119 -0
- package/src/components/data-display/VariableWeightText.tsx +130 -0
- package/src/components/data-display/index.ts +19 -0
- package/src/components/feedback/Alert.test.tsx +44 -0
- package/src/components/feedback/Alert.tsx +65 -0
- package/src/components/feedback/EmptyState.tsx +113 -0
- package/src/components/feedback/Progress.test.tsx +60 -0
- package/src/components/feedback/Progress.tsx +30 -0
- package/src/components/feedback/ProgressBar.tsx +158 -0
- package/src/components/feedback/Skeleton.test.tsx +39 -0
- package/src/components/feedback/Skeleton.tsx +45 -0
- package/src/components/feedback/Sonner.tsx +28 -0
- package/src/components/feedback/Spinner.test.tsx +33 -0
- package/src/components/feedback/Spinner.tsx +99 -0
- package/src/components/feedback/Stepper.tsx +307 -0
- package/src/components/feedback/Toast/Toast.tsx +243 -0
- package/src/components/feedback/Toast/index.ts +2 -0
- package/src/components/feedback/index.ts +9 -0
- package/src/components/forms/Checkbox.test.tsx +40 -0
- package/src/components/forms/Checkbox.tsx +31 -0
- package/src/components/forms/ColorPicker.tsx +118 -0
- package/src/components/forms/Combobox.tsx +96 -0
- package/src/components/forms/DragDrop.tsx +440 -0
- package/src/components/forms/FileUpload.tsx +252 -0
- package/src/components/forms/FilterButton.tsx +65 -0
- package/src/components/forms/Form.tsx +197 -0
- package/src/components/forms/Input.test.tsx +46 -0
- package/src/components/forms/Input.tsx +43 -0
- package/src/components/forms/InputOTP.tsx +81 -0
- package/src/components/forms/Label.test.tsx +20 -0
- package/src/components/forms/Label.tsx +25 -0
- package/src/components/forms/RadioGroup.tsx +51 -0
- package/src/components/forms/SearchBar.tsx +215 -0
- package/src/components/forms/Select.test.tsx +118 -0
- package/src/components/forms/Select.tsx +274 -0
- package/src/components/forms/Slider.tsx +29 -0
- package/src/components/forms/Switch.test.tsx +76 -0
- package/src/components/forms/Switch.tsx +30 -0
- package/src/components/forms/TextField.tsx +152 -0
- package/src/components/forms/Textarea.test.tsx +41 -0
- package/src/components/forms/Textarea.tsx +29 -0
- package/src/components/forms/ThemeSwitcher.tsx +290 -0
- package/src/components/forms/ThemeToggle.tsx +151 -0
- package/src/components/forms/index.ts +19 -0
- package/src/components/layout/Accordion.test.tsx +66 -0
- package/src/components/layout/Accordion.tsx +64 -0
- package/src/components/layout/AspectRatio.tsx +7 -0
- package/src/components/layout/Carousel.tsx +277 -0
- package/src/components/layout/Collapsible.test.tsx +40 -0
- package/src/components/layout/Collapsible.tsx +31 -0
- package/src/components/layout/Container.test.tsx +45 -0
- package/src/components/layout/Container.tsx +99 -0
- package/src/components/layout/CustomizerPanel.tsx +400 -0
- package/src/components/layout/DatePicker.tsx +57 -0
- package/src/components/layout/Footer/Footer.tsx +175 -0
- package/src/components/layout/Footer/index.ts +2 -0
- package/src/components/layout/GlassSurface.tsx +82 -0
- package/src/components/layout/Grid.test.tsx +31 -0
- package/src/components/layout/Grid.tsx +130 -0
- package/src/components/layout/Header/Header.tsx +450 -0
- package/src/components/layout/Header/index.ts +2 -0
- package/src/components/layout/PageLayout.tsx +180 -0
- package/src/components/layout/PageTemplate.tsx +158 -0
- package/src/components/layout/Resizable.tsx +48 -0
- package/src/components/layout/ScrollArea.tsx +53 -0
- package/src/components/layout/Separator.test.tsx +28 -0
- package/src/components/layout/Separator.tsx +29 -0
- package/src/components/layout/Sidebar.tsx +171 -0
- package/src/components/layout/Stack.test.tsx +41 -0
- package/src/components/layout/Stack.tsx +89 -0
- package/src/components/layout/glass-surface.css +60 -0
- package/src/components/layout/index.ts +18 -0
- package/src/components/motion/AnimatedBeam.tsx +159 -0
- package/src/components/navigation/Breadcrumb.test.tsx +57 -0
- package/src/components/navigation/Breadcrumb.tsx +119 -0
- package/src/components/navigation/Breadcrumbs.tsx +221 -0
- package/src/components/navigation/Command.tsx +159 -0
- package/src/components/navigation/Menubar.tsx +115 -0
- package/src/components/navigation/NavLink.tsx +55 -0
- package/src/components/navigation/NavigationMenu.tsx +125 -0
- package/src/components/navigation/Pagination.tsx +121 -0
- package/src/components/navigation/SecondaryNav.tsx +100 -0
- package/src/components/navigation/Tabs.test.tsx +47 -0
- package/src/components/navigation/Tabs.tsx +60 -0
- package/src/components/navigation/TertiaryNav.tsx +90 -0
- package/src/components/navigation/index.ts +10 -0
- package/src/components/overlays/AlertDialog.test.tsx +69 -0
- package/src/components/overlays/AlertDialog.tsx +166 -0
- package/src/components/overlays/ContextMenu.tsx +243 -0
- package/src/components/overlays/Dialog.test.tsx +79 -0
- package/src/components/overlays/Dialog.tsx +158 -0
- package/src/components/overlays/Drawer.tsx +128 -0
- package/src/components/overlays/Dropdown.tsx +253 -0
- package/src/components/overlays/DropdownMenu.tsx +242 -0
- package/src/components/overlays/HoverCard.tsx +32 -0
- package/src/components/overlays/Modal.tsx +250 -0
- package/src/components/overlays/NotificationCenter.tsx +364 -0
- package/src/components/overlays/Popover.test.tsx +40 -0
- package/src/components/overlays/Popover.tsx +46 -0
- package/src/components/overlays/Sheet.tsx +163 -0
- package/src/components/overlays/Tooltip.test.tsx +33 -0
- package/src/components/overlays/Tooltip.tsx +32 -0
- package/src/components/overlays/index.ts +12 -0
- package/src/dates.ts +2 -0
- package/src/dnd.ts +1 -0
- package/src/forms.ts +1 -0
- package/src/globals.css +187 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useForm.ts +247 -0
- package/src/hooks/useMotionPreference.test.ts +102 -0
- package/src/hooks/useMotionPreference.ts +78 -0
- package/src/hooks/useTheme.ts +58 -0
- package/src/hooks.ts +9 -0
- package/src/index.ts +168 -0
- package/src/lib/animations.ts +356 -0
- package/src/lib/breadcrumbs.ts +94 -0
- package/src/lib/colors.ts +493 -0
- package/src/lib/store/customizer.ts +482 -0
- package/src/lib/store/index.ts +3 -0
- package/src/lib/store/theme.ts +55 -0
- package/src/lib/syntax-parser/index.ts +50 -0
- package/src/lib/syntax-parser/patterns.ts +64 -0
- package/src/lib/syntax-parser/tokenizer.ts +117 -0
- package/src/lib/syntax-parser/types.ts +27 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validation.ts +204 -0
- package/src/lib/webgl/Color.ts +11 -0
- package/src/lib/webgl/Mesh.ts +41 -0
- package/src/lib/webgl/Program.ts +118 -0
- package/src/lib/webgl/Renderer.ts +51 -0
- package/src/lib/webgl/Triangle.ts +27 -0
- package/src/lib/webgl/Vec3.ts +18 -0
- package/src/lib/webgl/index.ts +13 -0
- package/src/nativewind-env.d.ts +1 -0
- package/src/providers/ThemeProvider.tsx +461 -0
- package/src/providers/index.ts +1 -0
- package/src/providers.ts +7 -0
- package/src/tables.ts +1 -0
- package/src/test/setup.ts +39 -0
- package/src/theme.css +158 -0
- package/src/tokens.ts +7 -0
- package/src/utils.ts +12 -0
- package/src/webgl.ts +1 -0
package/dist/dnd.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { SortingStrategy } from '@dnd-kit/sortable';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Item interface for drag and drop lists
|
|
7
|
+
*/
|
|
8
|
+
interface DragDropItem {
|
|
9
|
+
id: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Props for DragDropList component
|
|
14
|
+
*/
|
|
15
|
+
interface DragDropListProps<T extends DragDropItem> {
|
|
16
|
+
/**
|
|
17
|
+
* Array of items to display
|
|
18
|
+
*/
|
|
19
|
+
items: T[];
|
|
20
|
+
/**
|
|
21
|
+
* Callback fired when items are reordered
|
|
22
|
+
*/
|
|
23
|
+
onReorder: (items: T[]) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Render function for each item
|
|
26
|
+
*/
|
|
27
|
+
renderItem: (item: T, isDragging: boolean) => React__default.ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* Enable drag handle mode (only drag from handle)
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
withHandle?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Custom class name for the list container
|
|
35
|
+
*/
|
|
36
|
+
className?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Custom class name for list items
|
|
39
|
+
*/
|
|
40
|
+
itemClassName?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Sorting strategy for the drag & drop behavior
|
|
43
|
+
* - verticalListSortingStrategy: For vertical lists (default)
|
|
44
|
+
* - rectSortingStrategy: For grid layouts
|
|
45
|
+
* @default verticalListSortingStrategy
|
|
46
|
+
*/
|
|
47
|
+
strategy?: SortingStrategy;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Drag handle component for manual drag control
|
|
51
|
+
* Must be used within a DragDropList with withHandle={true}
|
|
52
|
+
*/
|
|
53
|
+
interface DragDropHandleProps {
|
|
54
|
+
/**
|
|
55
|
+
* Custom class name
|
|
56
|
+
*/
|
|
57
|
+
className?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Handle icon
|
|
60
|
+
*/
|
|
61
|
+
icon?: React__default.ReactNode;
|
|
62
|
+
}
|
|
63
|
+
declare function DragDropHandle({ className, icon }: DragDropHandleProps): react_jsx_runtime.JSX.Element | null;
|
|
64
|
+
/**
|
|
65
|
+
* DragDropList - Sortable list component with drag and drop functionality
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const [items, setItems] = useState([
|
|
70
|
+
* { id: '1', name: 'Item 1' },
|
|
71
|
+
* { id: '2', name: 'Item 2' },
|
|
72
|
+
* ]);
|
|
73
|
+
*
|
|
74
|
+
* <DragDropList
|
|
75
|
+
* items={items}
|
|
76
|
+
* onReorder={setItems}
|
|
77
|
+
* renderItem={(item) => (
|
|
78
|
+
* <div className="p-4 bg-surface rounded">{item.name}</div>
|
|
79
|
+
* )}
|
|
80
|
+
* />
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function DragDropList<T extends DragDropItem>({ items, onReorder, renderItem, withHandle, className, itemClassName, strategy, }: DragDropListProps<T>): react_jsx_runtime.JSX.Element;
|
|
84
|
+
/**
|
|
85
|
+
* Props for DragDropTable component
|
|
86
|
+
*/
|
|
87
|
+
interface DragDropTableProps<T extends DragDropItem> {
|
|
88
|
+
/**
|
|
89
|
+
* Array of items to display
|
|
90
|
+
*/
|
|
91
|
+
items: T[];
|
|
92
|
+
/**
|
|
93
|
+
* Callback fired when items are reordered
|
|
94
|
+
*/
|
|
95
|
+
onReorder: (items: T[]) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Table columns configuration
|
|
98
|
+
*/
|
|
99
|
+
columns: {
|
|
100
|
+
key: string;
|
|
101
|
+
header: string;
|
|
102
|
+
render?: (item: T) => React__default.ReactNode;
|
|
103
|
+
}[];
|
|
104
|
+
/**
|
|
105
|
+
* Custom class name for the table
|
|
106
|
+
*/
|
|
107
|
+
className?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* DragDropTable - Sortable table with draggable rows
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```tsx
|
|
114
|
+
* <DragDropTable
|
|
115
|
+
* items={data}
|
|
116
|
+
* onReorder={setData}
|
|
117
|
+
* columns={[
|
|
118
|
+
* { key: 'name', header: 'Name' },
|
|
119
|
+
* { key: 'email', header: 'Email' },
|
|
120
|
+
* ]}
|
|
121
|
+
* />
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function DragDropTable<T extends DragDropItem>({ items, onReorder, columns, className, }: DragDropTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
125
|
+
|
|
126
|
+
export { DragDropHandle, type DragDropHandleProps, type DragDropItem, DragDropList, type DragDropListProps, DragDropTable, type DragDropTableProps };
|
package/dist/dnd.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/dnd.ts
|
|
32
|
+
var dnd_exports = {};
|
|
33
|
+
__export(dnd_exports, {
|
|
34
|
+
DragDropHandle: () => DragDropHandle,
|
|
35
|
+
DragDropList: () => DragDropList,
|
|
36
|
+
DragDropTable: () => DragDropTable
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(dnd_exports);
|
|
39
|
+
|
|
40
|
+
// src/components/forms/DragDrop.tsx
|
|
41
|
+
var import_react = __toESM(require("react"));
|
|
42
|
+
var import_core = require("@dnd-kit/core");
|
|
43
|
+
var import_sortable = require("@dnd-kit/sortable");
|
|
44
|
+
var import_utilities = require("@dnd-kit/utilities");
|
|
45
|
+
var import_lucide_react = require("lucide-react");
|
|
46
|
+
|
|
47
|
+
// src/lib/utils.ts
|
|
48
|
+
var import_clsx = require("clsx");
|
|
49
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
50
|
+
function cn(...inputs) {
|
|
51
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/components/forms/DragDrop.tsx
|
|
55
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
56
|
+
var DragHandleContext = (0, import_react.createContext)(null);
|
|
57
|
+
function SortableItem({ id, children, withHandle, className }) {
|
|
58
|
+
const {
|
|
59
|
+
attributes,
|
|
60
|
+
listeners,
|
|
61
|
+
setNodeRef,
|
|
62
|
+
setActivatorNodeRef,
|
|
63
|
+
transform,
|
|
64
|
+
transition,
|
|
65
|
+
isDragging
|
|
66
|
+
} = (0, import_sortable.useSortable)({ id });
|
|
67
|
+
const style = {
|
|
68
|
+
transform: import_utilities.CSS.Transform.toString(transform),
|
|
69
|
+
transition,
|
|
70
|
+
opacity: isDragging ? 0.5 : 1
|
|
71
|
+
};
|
|
72
|
+
const itemProps = withHandle ? {} : { ...listeners, ...attributes };
|
|
73
|
+
const content = withHandle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DragHandleContext.Provider, { value: { attributes, listeners, setActivatorNodeRef }, children }) : children;
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
75
|
+
"div",
|
|
76
|
+
{
|
|
77
|
+
ref: setNodeRef,
|
|
78
|
+
style,
|
|
79
|
+
className: cn(
|
|
80
|
+
"relative transition-opacity",
|
|
81
|
+
isDragging && "z-50",
|
|
82
|
+
className
|
|
83
|
+
),
|
|
84
|
+
...itemProps,
|
|
85
|
+
children: content
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function DragDropHandle({ className, icon }) {
|
|
90
|
+
const context = (0, import_react.useContext)(DragHandleContext);
|
|
91
|
+
if (!context) {
|
|
92
|
+
console.warn("DragDropHandle must be used within a DragDropList with withHandle={true}");
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const { attributes, listeners, setActivatorNodeRef } = context;
|
|
96
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
ref: setActivatorNodeRef,
|
|
100
|
+
...attributes,
|
|
101
|
+
...listeners,
|
|
102
|
+
className: cn(
|
|
103
|
+
"flex items-center justify-center cursor-grab active:cursor-grabbing",
|
|
104
|
+
"text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)]",
|
|
105
|
+
"transition-colors",
|
|
106
|
+
className
|
|
107
|
+
),
|
|
108
|
+
children: icon || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.GripVertical, { className: "w-4 h-4" })
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
function DragDropList({
|
|
113
|
+
items,
|
|
114
|
+
onReorder,
|
|
115
|
+
renderItem,
|
|
116
|
+
withHandle = false,
|
|
117
|
+
className,
|
|
118
|
+
itemClassName,
|
|
119
|
+
strategy = import_sortable.verticalListSortingStrategy
|
|
120
|
+
}) {
|
|
121
|
+
const [activeId, setActiveId] = import_react.default.useState(null);
|
|
122
|
+
const sensors = (0, import_core.useSensors)(
|
|
123
|
+
(0, import_core.useSensor)(import_core.PointerSensor, {
|
|
124
|
+
activationConstraint: {
|
|
125
|
+
distance: 5
|
|
126
|
+
// Prevents accidental drags on mobile
|
|
127
|
+
}
|
|
128
|
+
}),
|
|
129
|
+
(0, import_core.useSensor)(import_core.KeyboardSensor, {
|
|
130
|
+
coordinateGetter: import_sortable.sortableKeyboardCoordinates
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
const handleDragStart = (event) => {
|
|
134
|
+
setActiveId(event.active.id);
|
|
135
|
+
};
|
|
136
|
+
const handleDragEnd = (event) => {
|
|
137
|
+
const { active, over } = event;
|
|
138
|
+
if (over && active.id !== over.id) {
|
|
139
|
+
const oldIndex = items.findIndex((item) => item.id === active.id);
|
|
140
|
+
const newIndex = items.findIndex((item) => item.id === over.id);
|
|
141
|
+
onReorder((0, import_sortable.arrayMove)(items, oldIndex, newIndex));
|
|
142
|
+
}
|
|
143
|
+
setActiveId(null);
|
|
144
|
+
};
|
|
145
|
+
const activeItem = items.find((item) => item.id === activeId);
|
|
146
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
147
|
+
import_core.DndContext,
|
|
148
|
+
{
|
|
149
|
+
sensors,
|
|
150
|
+
collisionDetection: import_core.closestCenter,
|
|
151
|
+
onDragStart: handleDragStart,
|
|
152
|
+
onDragEnd: handleDragEnd,
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sortable.SortableContext, { items, strategy, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: cn(strategy === import_sortable.verticalListSortingStrategy && "space-y-2", className), children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
155
|
+
SortableItem,
|
|
156
|
+
{
|
|
157
|
+
id: item.id,
|
|
158
|
+
withHandle,
|
|
159
|
+
className: itemClassName,
|
|
160
|
+
children: renderItem(item, item.id === activeId)
|
|
161
|
+
},
|
|
162
|
+
item.id
|
|
163
|
+
)) }) }),
|
|
164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.DragOverlay, { children: activeId && activeItem ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "opacity-80 shadow-lg", children: renderItem(activeItem, true) }) : null })
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
function DragDropTable({
|
|
170
|
+
items,
|
|
171
|
+
onReorder,
|
|
172
|
+
columns,
|
|
173
|
+
className
|
|
174
|
+
}) {
|
|
175
|
+
const [activeId, setActiveId] = import_react.default.useState(null);
|
|
176
|
+
const sensors = (0, import_core.useSensors)(
|
|
177
|
+
(0, import_core.useSensor)(import_core.PointerSensor, {
|
|
178
|
+
activationConstraint: {
|
|
179
|
+
distance: 5
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
(0, import_core.useSensor)(import_core.KeyboardSensor, {
|
|
183
|
+
coordinateGetter: import_sortable.sortableKeyboardCoordinates
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
const handleDragStart = (event) => {
|
|
187
|
+
setActiveId(event.active.id);
|
|
188
|
+
};
|
|
189
|
+
const handleDragEnd = (event) => {
|
|
190
|
+
const { active, over } = event;
|
|
191
|
+
if (over && active.id !== over.id) {
|
|
192
|
+
const oldIndex = items.findIndex((item) => item.id === active.id);
|
|
193
|
+
const newIndex = items.findIndex((item) => item.id === over.id);
|
|
194
|
+
onReorder((0, import_sortable.arrayMove)(items, oldIndex, newIndex));
|
|
195
|
+
}
|
|
196
|
+
setActiveId(null);
|
|
197
|
+
};
|
|
198
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
199
|
+
import_core.DndContext,
|
|
200
|
+
{
|
|
201
|
+
sensors,
|
|
202
|
+
collisionDetection: import_core.closestCenter,
|
|
203
|
+
onDragStart: handleDragStart,
|
|
204
|
+
onDragEnd: handleDragEnd,
|
|
205
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: cn("overflow-x-auto", className), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { className: "w-full border-collapse", children: [
|
|
206
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { className: "border-b border-[var(--color-border)]", children: [
|
|
207
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { className: "w-12" }),
|
|
208
|
+
columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
209
|
+
"th",
|
|
210
|
+
{
|
|
211
|
+
className: "text-left p-3 text-sm font-medium text-[var(--color-text-secondary)]",
|
|
212
|
+
children: column.header
|
|
213
|
+
},
|
|
214
|
+
column.key
|
|
215
|
+
))
|
|
216
|
+
] }) }),
|
|
217
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sortable.SortableContext, { items, strategy: import_sortable.verticalListSortingStrategy, children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
218
|
+
TableRow,
|
|
219
|
+
{
|
|
220
|
+
item,
|
|
221
|
+
columns,
|
|
222
|
+
isDragging: item.id === activeId
|
|
223
|
+
},
|
|
224
|
+
item.id
|
|
225
|
+
)) }) })
|
|
226
|
+
] }) })
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function TableRow({ item, columns, isDragging }) {
|
|
231
|
+
const {
|
|
232
|
+
attributes,
|
|
233
|
+
listeners,
|
|
234
|
+
setNodeRef,
|
|
235
|
+
transform,
|
|
236
|
+
transition
|
|
237
|
+
} = (0, import_sortable.useSortable)({ id: item.id });
|
|
238
|
+
const style = {
|
|
239
|
+
transform: import_utilities.CSS.Transform.toString(transform),
|
|
240
|
+
transition,
|
|
241
|
+
opacity: isDragging ? 0.5 : 1
|
|
242
|
+
};
|
|
243
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
244
|
+
"tr",
|
|
245
|
+
{
|
|
246
|
+
ref: setNodeRef,
|
|
247
|
+
style,
|
|
248
|
+
className: cn(
|
|
249
|
+
"border-b border-[var(--color-border)] hover:bg-[var(--color-hover)]",
|
|
250
|
+
"transition-colors",
|
|
251
|
+
isDragging && "bg-[var(--color-active)]"
|
|
252
|
+
),
|
|
253
|
+
children: [
|
|
254
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className: "p-3", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
255
|
+
"div",
|
|
256
|
+
{
|
|
257
|
+
...attributes,
|
|
258
|
+
...listeners,
|
|
259
|
+
className: "cursor-grab active:cursor-grabbing text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)] transition-colors",
|
|
260
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.GripVertical, { className: "w-4 h-4" })
|
|
261
|
+
}
|
|
262
|
+
) }),
|
|
263
|
+
columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className: "p-3 text-sm", children: column.render ? column.render(item) : item[column.key] }, column.key))
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
270
|
+
DragDropHandle,
|
|
271
|
+
DragDropList,
|
|
272
|
+
DragDropTable
|
|
273
|
+
});
|
|
274
|
+
//# sourceMappingURL=dnd.js.map
|
package/dist/dnd.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dnd.ts","../src/components/forms/DragDrop.tsx","../src/lib/utils.ts"],"sourcesContent":["export * from './components/forms/DragDrop';\n","'use client';\n\nimport React, { createContext, useContext } from 'react';\nimport {\n DndContext,\n closestCenter,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors,\n DragEndEvent,\n DragOverlay,\n DragStartEvent,\n} from '@dnd-kit/core';\nimport {\n arrayMove,\n SortableContext,\n sortableKeyboardCoordinates,\n useSortable,\n verticalListSortingStrategy,\n rectSortingStrategy,\n SortingStrategy,\n} from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { GripVertical } from 'lucide-react';\nimport { cn } from '../../lib/utils';\n\n/**\n * Item interface for drag and drop lists\n */\nexport interface DragDropItem {\n id: string;\n [key: string]: any;\n}\n\n/**\n * Context for sharing drag handle listeners\n */\ninterface DragHandleContextValue {\n attributes: any;\n listeners: any;\n setActivatorNodeRef?: (element: HTMLElement | null) => void;\n}\n\nconst DragHandleContext = createContext<DragHandleContextValue | null>(null);\n\n/**\n * Props for DragDropList component\n */\nexport interface DragDropListProps<T extends DragDropItem> {\n /**\n * Array of items to display\n */\n items: T[];\n /**\n * Callback fired when items are reordered\n */\n onReorder: (items: T[]) => void;\n /**\n * Render function for each item\n */\n renderItem: (item: T, isDragging: boolean) => React.ReactNode;\n /**\n * Enable drag handle mode (only drag from handle)\n * @default false\n */\n withHandle?: boolean;\n /**\n * Custom class name for the list container\n */\n className?: string;\n /**\n * Custom class name for list items\n */\n itemClassName?: string;\n /**\n * Sorting strategy for the drag & drop behavior\n * - verticalListSortingStrategy: For vertical lists (default)\n * - rectSortingStrategy: For grid layouts\n * @default verticalListSortingStrategy\n */\n strategy?: SortingStrategy;\n}\n\n/**\n * Props for sortable item\n */\ninterface SortableItemProps {\n id: string;\n children: React.ReactNode;\n withHandle?: boolean;\n className?: string;\n}\n\n/**\n * Internal sortable item component\n */\nfunction SortableItem({ id, children, withHandle, className }: SortableItemProps) {\n const {\n attributes,\n listeners,\n setNodeRef,\n setActivatorNodeRef,\n transform,\n transition,\n isDragging,\n } = useSortable({ id });\n\n const style = {\n transform: CSS.Transform.toString(transform),\n transition,\n opacity: isDragging ? 0.5 : 1,\n };\n\n // If using handle, don't attach listeners to the item\n const itemProps = withHandle ? {} : { ...listeners, ...attributes };\n\n const content = withHandle ? (\n <DragHandleContext.Provider value={{ attributes, listeners, setActivatorNodeRef }}>\n {children}\n </DragHandleContext.Provider>\n ) : (\n children\n );\n\n return (\n <div\n ref={setNodeRef}\n style={style}\n className={cn(\n 'relative transition-opacity',\n isDragging && 'z-50',\n className\n )}\n {...itemProps}\n >\n {content}\n </div>\n );\n}\n\n/**\n * Drag handle component for manual drag control\n * Must be used within a DragDropList with withHandle={true}\n */\nexport interface DragDropHandleProps {\n /**\n * Custom class name\n */\n className?: string;\n /**\n * Handle icon\n */\n icon?: React.ReactNode;\n}\n\nexport function DragDropHandle({ className, icon }: DragDropHandleProps) {\n const context = useContext(DragHandleContext);\n\n if (!context) {\n console.warn('DragDropHandle must be used within a DragDropList with withHandle={true}');\n return null;\n }\n\n const { attributes, listeners, setActivatorNodeRef } = context;\n\n return (\n <div\n ref={setActivatorNodeRef}\n {...attributes}\n {...listeners}\n className={cn(\n 'flex items-center justify-center cursor-grab active:cursor-grabbing',\n 'text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)]',\n 'transition-colors',\n className\n )}\n >\n {icon || <GripVertical className=\"w-4 h-4\" />}\n </div>\n );\n}\n\n/**\n * DragDropList - Sortable list component with drag and drop functionality\n *\n * @example\n * ```tsx\n * const [items, setItems] = useState([\n * { id: '1', name: 'Item 1' },\n * { id: '2', name: 'Item 2' },\n * ]);\n *\n * <DragDropList\n * items={items}\n * onReorder={setItems}\n * renderItem={(item) => (\n * <div className=\"p-4 bg-surface rounded\">{item.name}</div>\n * )}\n * />\n * ```\n */\nexport function DragDropList<T extends DragDropItem>({\n items,\n onReorder,\n renderItem,\n withHandle = false,\n className,\n itemClassName,\n strategy = verticalListSortingStrategy,\n}: DragDropListProps<T>) {\n const [activeId, setActiveId] = React.useState<string | null>(null);\n\n // Configure sensors for touch/mouse/keyboard support\n const sensors = useSensors(\n useSensor(PointerSensor, {\n activationConstraint: {\n distance: 5, // Prevents accidental drags on mobile\n },\n }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n })\n );\n\n const handleDragStart = (event: DragStartEvent) => {\n setActiveId(event.active.id as string);\n };\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (over && active.id !== over.id) {\n const oldIndex = items.findIndex((item) => item.id === active.id);\n const newIndex = items.findIndex((item) => item.id === over.id);\n onReorder(arrayMove(items, oldIndex, newIndex));\n }\n\n setActiveId(null);\n };\n\n const activeItem = items.find((item) => item.id === activeId);\n\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n >\n <SortableContext items={items} strategy={strategy}>\n <div className={cn(strategy === verticalListSortingStrategy && 'space-y-2', className)}>\n {items.map((item) => (\n <SortableItem\n key={item.id}\n id={item.id}\n withHandle={withHandle}\n className={itemClassName}\n >\n {renderItem(item, item.id === activeId)}\n </SortableItem>\n ))}\n </div>\n </SortableContext>\n\n <DragOverlay>\n {activeId && activeItem ? (\n <div className=\"opacity-80 shadow-lg\">\n {renderItem(activeItem, true)}\n </div>\n ) : null}\n </DragOverlay>\n </DndContext>\n );\n}\n\n/**\n * Props for DragDropTable component\n */\nexport interface DragDropTableProps<T extends DragDropItem> {\n /**\n * Array of items to display\n */\n items: T[];\n /**\n * Callback fired when items are reordered\n */\n onReorder: (items: T[]) => void;\n /**\n * Table columns configuration\n */\n columns: {\n key: string;\n header: string;\n render?: (item: T) => React.ReactNode;\n }[];\n /**\n * Custom class name for the table\n */\n className?: string;\n}\n\n/**\n * DragDropTable - Sortable table with draggable rows\n *\n * @example\n * ```tsx\n * <DragDropTable\n * items={data}\n * onReorder={setData}\n * columns={[\n * { key: 'name', header: 'Name' },\n * { key: 'email', header: 'Email' },\n * ]}\n * />\n * ```\n */\nexport function DragDropTable<T extends DragDropItem>({\n items,\n onReorder,\n columns,\n className,\n}: DragDropTableProps<T>) {\n const [activeId, setActiveId] = React.useState<string | null>(null);\n\n const sensors = useSensors(\n useSensor(PointerSensor, {\n activationConstraint: {\n distance: 5,\n },\n }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n })\n );\n\n const handleDragStart = (event: DragStartEvent) => {\n setActiveId(event.active.id as string);\n };\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (over && active.id !== over.id) {\n const oldIndex = items.findIndex((item) => item.id === active.id);\n const newIndex = items.findIndex((item) => item.id === over.id);\n onReorder(arrayMove(items, oldIndex, newIndex));\n }\n\n setActiveId(null);\n };\n\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n >\n <div className={cn('overflow-x-auto', className)}>\n <table className=\"w-full border-collapse\">\n <thead>\n <tr className=\"border-b border-[var(--color-border)]\">\n <th className=\"w-12\"></th>\n {columns.map((column) => (\n <th\n key={column.key}\n className=\"text-left p-3 text-sm font-medium text-[var(--color-text-secondary)]\"\n >\n {column.header}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n <SortableContext items={items} strategy={verticalListSortingStrategy}>\n {items.map((item) => (\n <TableRow\n key={item.id}\n item={item}\n columns={columns}\n isDragging={item.id === activeId}\n />\n ))}\n </SortableContext>\n </tbody>\n </table>\n </div>\n </DndContext>\n );\n}\n\ninterface TableRowProps<T extends DragDropItem> {\n item: T;\n columns: { key: string; header: string; render?: (item: T) => React.ReactNode }[];\n isDragging: boolean;\n}\n\nfunction TableRow<T extends DragDropItem>({ item, columns, isDragging }: TableRowProps<T>) {\n const {\n attributes,\n listeners,\n setNodeRef,\n transform,\n transition,\n } = useSortable({ id: item.id });\n\n const style = {\n transform: CSS.Transform.toString(transform),\n transition,\n opacity: isDragging ? 0.5 : 1,\n };\n\n return (\n <tr\n ref={setNodeRef}\n style={style}\n className={cn(\n 'border-b border-[var(--color-border)] hover:bg-[var(--color-hover)]',\n 'transition-colors',\n isDragging && 'bg-[var(--color-active)]'\n )}\n >\n <td className=\"p-3\">\n <div\n {...attributes}\n {...listeners}\n className=\"cursor-grab active:cursor-grabbing text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)] transition-colors\"\n >\n <GripVertical className=\"w-4 h-4\" />\n </div>\n </td>\n {columns.map((column) => (\n <td key={column.key} className=\"p-3 text-sm\">\n {column.render ? column.render(item) : (item as any)[column.key]}\n </td>\n ))}\n </tr>\n );\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAAiD;AACjD,kBAUO;AACP,sBAQO;AACP,uBAAoB;AACpB,0BAA6B;;;ACxB7B,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AACxC,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC/B;;;ADiHI;AA1EJ,IAAM,wBAAoB,4BAA6C,IAAI;AAqD3E,SAAS,aAAa,EAAE,IAAI,UAAU,YAAY,UAAU,GAAsB;AAChF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAA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AAA,EACF;AAEJ;AAQA,SAAS,SAAiC,EAAE,MAAM,SAAS,WAAW,GAAqB;AACzF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,6BAAY,EAAE,IAAI,KAAK,GAAG,CAAC;AAE/B,QAAM,QAAQ;AAAA,IACZ,WAAW,qBAAI,UAAU,SAAS,SAAS;AAAA,IAC3C;AAAA,IACA,SAAS,aAAa,MAAM;AAAA,EAC9B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA,cAAc;AAAA,MAChB;AAAA,MAEA;AAAA,oDAAC,QAAG,WAAU,OACZ;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,YACH,GAAG;AAAA,YACJ,WAAU;AAAA,YAEV,sDAAC,oCAAa,WAAU,WAAU;AAAA;AAAA,QACpC,GACF;AAAA,QACC,QAAQ,IAAI,CAAC,WACZ,4CAAC,QAAoB,WAAU,eAC5B,iBAAO,SAAS,OAAO,OAAO,IAAI,IAAK,KAAa,OAAO,GAAG,KADxD,OAAO,GAEhB,CACD;AAAA;AAAA;AAAA,EACH;AAEJ;","names":["React"]}
|
package/dist/dnd.mjs
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/forms/DragDrop.tsx
|
|
4
|
+
import React, { createContext, useContext } from "react";
|
|
5
|
+
import {
|
|
6
|
+
DndContext,
|
|
7
|
+
closestCenter,
|
|
8
|
+
KeyboardSensor,
|
|
9
|
+
PointerSensor,
|
|
10
|
+
useSensor,
|
|
11
|
+
useSensors,
|
|
12
|
+
DragOverlay
|
|
13
|
+
} from "@dnd-kit/core";
|
|
14
|
+
import {
|
|
15
|
+
arrayMove,
|
|
16
|
+
SortableContext,
|
|
17
|
+
sortableKeyboardCoordinates,
|
|
18
|
+
useSortable,
|
|
19
|
+
verticalListSortingStrategy
|
|
20
|
+
} from "@dnd-kit/sortable";
|
|
21
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
22
|
+
import { GripVertical } from "lucide-react";
|
|
23
|
+
|
|
24
|
+
// src/lib/utils.ts
|
|
25
|
+
import { clsx } from "clsx";
|
|
26
|
+
import { twMerge } from "tailwind-merge";
|
|
27
|
+
function cn(...inputs) {
|
|
28
|
+
return twMerge(clsx(inputs));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/components/forms/DragDrop.tsx
|
|
32
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
+
var DragHandleContext = createContext(null);
|
|
34
|
+
function SortableItem({ id, children, withHandle, className }) {
|
|
35
|
+
const {
|
|
36
|
+
attributes,
|
|
37
|
+
listeners,
|
|
38
|
+
setNodeRef,
|
|
39
|
+
setActivatorNodeRef,
|
|
40
|
+
transform,
|
|
41
|
+
transition,
|
|
42
|
+
isDragging
|
|
43
|
+
} = useSortable({ id });
|
|
44
|
+
const style = {
|
|
45
|
+
transform: CSS.Transform.toString(transform),
|
|
46
|
+
transition,
|
|
47
|
+
opacity: isDragging ? 0.5 : 1
|
|
48
|
+
};
|
|
49
|
+
const itemProps = withHandle ? {} : { ...listeners, ...attributes };
|
|
50
|
+
const content = withHandle ? /* @__PURE__ */ jsx(DragHandleContext.Provider, { value: { attributes, listeners, setActivatorNodeRef }, children }) : children;
|
|
51
|
+
return /* @__PURE__ */ jsx(
|
|
52
|
+
"div",
|
|
53
|
+
{
|
|
54
|
+
ref: setNodeRef,
|
|
55
|
+
style,
|
|
56
|
+
className: cn(
|
|
57
|
+
"relative transition-opacity",
|
|
58
|
+
isDragging && "z-50",
|
|
59
|
+
className
|
|
60
|
+
),
|
|
61
|
+
...itemProps,
|
|
62
|
+
children: content
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
function DragDropHandle({ className, icon }) {
|
|
67
|
+
const context = useContext(DragHandleContext);
|
|
68
|
+
if (!context) {
|
|
69
|
+
console.warn("DragDropHandle must be used within a DragDropList with withHandle={true}");
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const { attributes, listeners, setActivatorNodeRef } = context;
|
|
73
|
+
return /* @__PURE__ */ jsx(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
ref: setActivatorNodeRef,
|
|
77
|
+
...attributes,
|
|
78
|
+
...listeners,
|
|
79
|
+
className: cn(
|
|
80
|
+
"flex items-center justify-center cursor-grab active:cursor-grabbing",
|
|
81
|
+
"text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)]",
|
|
82
|
+
"transition-colors",
|
|
83
|
+
className
|
|
84
|
+
),
|
|
85
|
+
children: icon || /* @__PURE__ */ jsx(GripVertical, { className: "w-4 h-4" })
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function DragDropList({
|
|
90
|
+
items,
|
|
91
|
+
onReorder,
|
|
92
|
+
renderItem,
|
|
93
|
+
withHandle = false,
|
|
94
|
+
className,
|
|
95
|
+
itemClassName,
|
|
96
|
+
strategy = verticalListSortingStrategy
|
|
97
|
+
}) {
|
|
98
|
+
const [activeId, setActiveId] = React.useState(null);
|
|
99
|
+
const sensors = useSensors(
|
|
100
|
+
useSensor(PointerSensor, {
|
|
101
|
+
activationConstraint: {
|
|
102
|
+
distance: 5
|
|
103
|
+
// Prevents accidental drags on mobile
|
|
104
|
+
}
|
|
105
|
+
}),
|
|
106
|
+
useSensor(KeyboardSensor, {
|
|
107
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
const handleDragStart = (event) => {
|
|
111
|
+
setActiveId(event.active.id);
|
|
112
|
+
};
|
|
113
|
+
const handleDragEnd = (event) => {
|
|
114
|
+
const { active, over } = event;
|
|
115
|
+
if (over && active.id !== over.id) {
|
|
116
|
+
const oldIndex = items.findIndex((item) => item.id === active.id);
|
|
117
|
+
const newIndex = items.findIndex((item) => item.id === over.id);
|
|
118
|
+
onReorder(arrayMove(items, oldIndex, newIndex));
|
|
119
|
+
}
|
|
120
|
+
setActiveId(null);
|
|
121
|
+
};
|
|
122
|
+
const activeItem = items.find((item) => item.id === activeId);
|
|
123
|
+
return /* @__PURE__ */ jsxs(
|
|
124
|
+
DndContext,
|
|
125
|
+
{
|
|
126
|
+
sensors,
|
|
127
|
+
collisionDetection: closestCenter,
|
|
128
|
+
onDragStart: handleDragStart,
|
|
129
|
+
onDragEnd: handleDragEnd,
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx(SortableContext, { items, strategy, children: /* @__PURE__ */ jsx("div", { className: cn(strategy === verticalListSortingStrategy && "space-y-2", className), children: items.map((item) => /* @__PURE__ */ jsx(
|
|
132
|
+
SortableItem,
|
|
133
|
+
{
|
|
134
|
+
id: item.id,
|
|
135
|
+
withHandle,
|
|
136
|
+
className: itemClassName,
|
|
137
|
+
children: renderItem(item, item.id === activeId)
|
|
138
|
+
},
|
|
139
|
+
item.id
|
|
140
|
+
)) }) }),
|
|
141
|
+
/* @__PURE__ */ jsx(DragOverlay, { children: activeId && activeItem ? /* @__PURE__ */ jsx("div", { className: "opacity-80 shadow-lg", children: renderItem(activeItem, true) }) : null })
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
function DragDropTable({
|
|
147
|
+
items,
|
|
148
|
+
onReorder,
|
|
149
|
+
columns,
|
|
150
|
+
className
|
|
151
|
+
}) {
|
|
152
|
+
const [activeId, setActiveId] = React.useState(null);
|
|
153
|
+
const sensors = useSensors(
|
|
154
|
+
useSensor(PointerSensor, {
|
|
155
|
+
activationConstraint: {
|
|
156
|
+
distance: 5
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
useSensor(KeyboardSensor, {
|
|
160
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
const handleDragStart = (event) => {
|
|
164
|
+
setActiveId(event.active.id);
|
|
165
|
+
};
|
|
166
|
+
const handleDragEnd = (event) => {
|
|
167
|
+
const { active, over } = event;
|
|
168
|
+
if (over && active.id !== over.id) {
|
|
169
|
+
const oldIndex = items.findIndex((item) => item.id === active.id);
|
|
170
|
+
const newIndex = items.findIndex((item) => item.id === over.id);
|
|
171
|
+
onReorder(arrayMove(items, oldIndex, newIndex));
|
|
172
|
+
}
|
|
173
|
+
setActiveId(null);
|
|
174
|
+
};
|
|
175
|
+
return /* @__PURE__ */ jsx(
|
|
176
|
+
DndContext,
|
|
177
|
+
{
|
|
178
|
+
sensors,
|
|
179
|
+
collisionDetection: closestCenter,
|
|
180
|
+
onDragStart: handleDragStart,
|
|
181
|
+
onDragEnd: handleDragEnd,
|
|
182
|
+
children: /* @__PURE__ */ jsx("div", { className: cn("overflow-x-auto", className), children: /* @__PURE__ */ jsxs("table", { className: "w-full border-collapse", children: [
|
|
183
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-[var(--color-border)]", children: [
|
|
184
|
+
/* @__PURE__ */ jsx("th", { className: "w-12" }),
|
|
185
|
+
columns.map((column) => /* @__PURE__ */ jsx(
|
|
186
|
+
"th",
|
|
187
|
+
{
|
|
188
|
+
className: "text-left p-3 text-sm font-medium text-[var(--color-text-secondary)]",
|
|
189
|
+
children: column.header
|
|
190
|
+
},
|
|
191
|
+
column.key
|
|
192
|
+
))
|
|
193
|
+
] }) }),
|
|
194
|
+
/* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx(SortableContext, { items, strategy: verticalListSortingStrategy, children: items.map((item) => /* @__PURE__ */ jsx(
|
|
195
|
+
TableRow,
|
|
196
|
+
{
|
|
197
|
+
item,
|
|
198
|
+
columns,
|
|
199
|
+
isDragging: item.id === activeId
|
|
200
|
+
},
|
|
201
|
+
item.id
|
|
202
|
+
)) }) })
|
|
203
|
+
] }) })
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function TableRow({ item, columns, isDragging }) {
|
|
208
|
+
const {
|
|
209
|
+
attributes,
|
|
210
|
+
listeners,
|
|
211
|
+
setNodeRef,
|
|
212
|
+
transform,
|
|
213
|
+
transition
|
|
214
|
+
} = useSortable({ id: item.id });
|
|
215
|
+
const style = {
|
|
216
|
+
transform: CSS.Transform.toString(transform),
|
|
217
|
+
transition,
|
|
218
|
+
opacity: isDragging ? 0.5 : 1
|
|
219
|
+
};
|
|
220
|
+
return /* @__PURE__ */ jsxs(
|
|
221
|
+
"tr",
|
|
222
|
+
{
|
|
223
|
+
ref: setNodeRef,
|
|
224
|
+
style,
|
|
225
|
+
className: cn(
|
|
226
|
+
"border-b border-[var(--color-border)] hover:bg-[var(--color-hover)]",
|
|
227
|
+
"transition-colors",
|
|
228
|
+
isDragging && "bg-[var(--color-active)]"
|
|
229
|
+
),
|
|
230
|
+
children: [
|
|
231
|
+
/* @__PURE__ */ jsx("td", { className: "p-3", children: /* @__PURE__ */ jsx(
|
|
232
|
+
"div",
|
|
233
|
+
{
|
|
234
|
+
...attributes,
|
|
235
|
+
...listeners,
|
|
236
|
+
className: "cursor-grab active:cursor-grabbing text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)] transition-colors",
|
|
237
|
+
children: /* @__PURE__ */ jsx(GripVertical, { className: "w-4 h-4" })
|
|
238
|
+
}
|
|
239
|
+
) }),
|
|
240
|
+
columns.map((column) => /* @__PURE__ */ jsx("td", { className: "p-3 text-sm", children: column.render ? column.render(item) : item[column.key] }, column.key))
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
export {
|
|
246
|
+
DragDropHandle,
|
|
247
|
+
DragDropList,
|
|
248
|
+
DragDropTable
|
|
249
|
+
};
|
|
250
|
+
//# sourceMappingURL=dnd.mjs.map
|