nucleus-core-ts 0.8.7 → 0.8.9
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/client.js +1 -1
- package/dist/fe/components/AbstractAnimatedBackground/index.js +437 -0
- package/dist/fe/components/AuthorizationPage/components/AuthorizationPage.js +841 -0
- package/dist/fe/components/AuthorizationPage/components/ClaimList.js +100 -0
- package/dist/fe/components/AuthorizationPage/components/RoleClaimEditor.js +232 -0
- package/dist/fe/components/AuthorizationPage/components/RoleList.js +115 -0
- package/dist/fe/components/AuthorizationPage/index.js +6 -0
- package/dist/fe/components/AuthorizationPage/store/index.js +117 -0
- package/dist/fe/components/AuthorizationPage/theme/index.js +137 -0
- package/dist/fe/components/AuthorizationPage/types/index.js +1 -0
- package/dist/fe/components/Button/components/Button.js +158 -0
- package/dist/fe/components/Button/components/ButtonSpinner.js +52 -0
- package/dist/fe/components/Button/index.js +3 -0
- package/dist/fe/components/Button/theme/index.js +186 -0
- package/dist/fe/components/Button/types/index.js +1 -0
- package/dist/fe/components/Button/utils/cn.js +5 -0
- package/dist/fe/components/Captcha/components/Captcha.js +311 -0
- package/dist/fe/components/Captcha/index.js +2 -0
- package/dist/fe/components/Captcha/theme.js +52 -0
- package/dist/fe/components/Captcha/types.js +1 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordForm.js +242 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordHeader.js +39 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordPage.js +60 -0
- package/dist/fe/components/ChangePasswordPage/index.js +5 -0
- package/dist/fe/components/ChangePasswordPage/store/index.js +44 -0
- package/dist/fe/components/ChangePasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ChangePasswordPage/types/index.js +1 -0
- package/dist/fe/components/Checkbox/components/Checkbox.js +115 -0
- package/dist/fe/components/Checkbox/components/CheckboxIcon.js +119 -0
- package/dist/fe/components/Checkbox/components/SwitchTrack.js +178 -0
- package/dist/fe/components/Checkbox/index.js +4 -0
- package/dist/fe/components/Checkbox/theme/index.js +221 -0
- package/dist/fe/components/Checkbox/types/index.js +1 -0
- package/dist/fe/components/Checkbox/utils/cn.js +5 -0
- package/dist/fe/components/DataTable/DataTable.js +225 -0
- package/dist/fe/components/DataTable/components/ActionCell.js +26 -0
- package/dist/fe/components/DataTable/components/DataCell.js +76 -0
- package/dist/fe/components/DataTable/components/EditableCell.js +221 -0
- package/dist/fe/components/DataTable/components/EmptyState.js +29 -0
- package/dist/fe/components/DataTable/components/HeaderCell.js +64 -0
- package/dist/fe/components/DataTable/components/InfiniteScrollTrigger.js +66 -0
- package/dist/fe/components/DataTable/components/LoadingSpinner.js +19 -0
- package/dist/fe/components/DataTable/components/ResizeHandle.js +41 -0
- package/dist/fe/components/DataTable/components/SelectionCell.js +105 -0
- package/dist/fe/components/DataTable/components/SkeletonRow.js +56 -0
- package/dist/fe/components/DataTable/components/SkeletonTable.js +83 -0
- package/dist/fe/components/DataTable/components/SortIcon.js +39 -0
- package/dist/fe/components/DataTable/components/TableHeader.js +49 -0
- package/dist/fe/components/DataTable/components/TableRow.js +118 -0
- package/dist/fe/components/DataTable/components/index.js +14 -0
- package/dist/fe/components/DataTable/hooks/index.js +2 -0
- package/dist/fe/components/DataTable/hooks/useAutoFitColumn.js +23 -0
- package/dist/fe/components/DataTable/hooks/useResizeColumn.js +122 -0
- package/dist/fe/components/DataTable/index.js +3 -0
- package/dist/fe/components/DataTable/store/index.js +97 -0
- package/dist/fe/components/DataTable/theme/index.js +144 -0
- package/dist/fe/components/DataTable/types/index.js +1 -0
- package/dist/fe/components/DataTable/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/components/CalendarGrid.js +95 -0
- package/dist/fe/components/DatePicker/components/CalendarHeader.js +152 -0
- package/dist/fe/components/DatePicker/components/DatePicker.js +381 -0
- package/dist/fe/components/DatePicker/components/MonthYearSelector.js +93 -0
- package/dist/fe/components/DatePicker/index.js +7 -0
- package/dist/fe/components/DatePicker/locales/index.js +1113 -0
- package/dist/fe/components/DatePicker/theme/index.js +315 -0
- package/dist/fe/components/DatePicker/types/index.js +1 -0
- package/dist/fe/components/DatePicker/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/utils/date.js +132 -0
- package/dist/fe/components/DevicesPage/components/DeviceCard.js +251 -0
- package/dist/fe/components/DevicesPage/components/DevicesHeader.js +42 -0
- package/dist/fe/components/DevicesPage/components/DevicesPage.js +450 -0
- package/dist/fe/components/DevicesPage/index.js +5 -0
- package/dist/fe/components/DevicesPage/store/index.js +55 -0
- package/dist/fe/components/DevicesPage/theme/index.js +131 -0
- package/dist/fe/components/DevicesPage/types/index.js +1 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordForm.js +214 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordHeader.js +42 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordPage.js +59 -0
- package/dist/fe/components/ForgotPasswordPage/index.js +5 -0
- package/dist/fe/components/ForgotPasswordPage/store/index.js +28 -0
- package/dist/fe/components/ForgotPasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ForgotPasswordPage/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/components/FormBuilder.js +156 -0
- package/dist/fe/components/FormBuilder/components/FormField.js +218 -0
- package/dist/fe/components/FormBuilder/hooks/useFormBuilder.js +152 -0
- package/dist/fe/components/FormBuilder/index.js +4 -0
- package/dist/fe/components/FormBuilder/theme/index.js +134 -0
- package/dist/fe/components/FormBuilder/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/utils/cn.js +5 -0
- package/dist/fe/components/FormBuilder/utils/fieldMapping.js +216 -0
- package/dist/fe/components/FormBuilder/utils/validation.js +78 -0
- package/dist/fe/components/LoginPage/components/LoginForm.js +214 -0
- package/dist/fe/components/LoginPage/components/LoginHeader.js +24 -0
- package/dist/fe/components/LoginPage/components/LoginPage.js +138 -0
- package/dist/fe/components/LoginPage/index.js +5 -0
- package/dist/fe/components/LoginPage/store/index.js +59 -0
- package/dist/fe/components/LoginPage/theme/index.js +98 -0
- package/dist/fe/components/LoginPage/types/index.js +1 -0
- package/dist/fe/components/MagicLinkVerifyPage/components/MagicLinkVerifyPage.js +200 -0
- package/dist/fe/components/MagicLinkVerifyPage/index.js +3 -0
- package/dist/fe/components/MagicLinkVerifyPage/store.js +20 -0
- package/dist/fe/components/MagicLinkVerifyPage/theme.js +36 -0
- package/dist/fe/components/MagicLinkVerifyPage/types.js +1 -0
- package/dist/fe/components/NucleusEntityShowcase.js +1409 -0
- package/dist/fe/components/NucleusTextInput/components/FloatingLabel.js +56 -0
- package/dist/fe/components/NucleusTextInput/components/InputIcons.js +258 -0
- package/dist/fe/components/NucleusTextInput/components/NucleusTextInput.js +321 -0
- package/dist/fe/components/NucleusTextInput/components/PasswordStrengthIndicator.js +104 -0
- package/dist/fe/components/NucleusTextInput/components/TypewriterText.js +56 -0
- package/dist/fe/components/NucleusTextInput/index.js +7 -0
- package/dist/fe/components/NucleusTextInput/theme/index.js +121 -0
- package/dist/fe/components/NucleusTextInput/types/index.js +1 -0
- package/dist/fe/components/NucleusTextInput/utils/cn.js +5 -0
- package/dist/fe/components/NucleusTextInput/utils/format.js +62 -0
- package/dist/fe/components/NucleusTextInput/utils/validation.js +191 -0
- package/dist/fe/components/ProfilePage/components/AddressCard.js +196 -0
- package/dist/fe/components/ProfilePage/components/PhoneCard.js +206 -0
- package/dist/fe/components/ProfilePage/components/ProfileHeader.js +150 -0
- package/dist/fe/components/ProfilePage/components/ProfilePage.js +1336 -0
- package/dist/fe/components/ProfilePage/index.js +6 -0
- package/dist/fe/components/ProfilePage/store/index.js +115 -0
- package/dist/fe/components/ProfilePage/theme/index.js +168 -0
- package/dist/fe/components/ProfilePage/types/index.js +1 -0
- package/dist/fe/components/RangePicker/components/RangePicker.js +338 -0
- package/dist/fe/components/RangePicker/components/RangeThumb.js +68 -0
- package/dist/fe/components/RangePicker/components/RangeTooltip.js +45 -0
- package/dist/fe/components/RangePicker/components/RangeTrack.js +32 -0
- package/dist/fe/components/RangePicker/index.js +5 -0
- package/dist/fe/components/RangePicker/theme/index.js +88 -0
- package/dist/fe/components/RangePicker/types/index.js +1 -0
- package/dist/fe/components/RangePicker/utils/cn.js +3 -0
- package/dist/fe/components/RegisterPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/RegisterPage/components/RegisterForm.js +322 -0
- package/dist/fe/components/RegisterPage/components/RegisterHeader.js +23 -0
- package/dist/fe/components/RegisterPage/components/RegisterPage.js +85 -0
- package/dist/fe/components/RegisterPage/index.js +6 -0
- package/dist/fe/components/RegisterPage/store/index.js +106 -0
- package/dist/fe/components/RegisterPage/theme/index.js +128 -0
- package/dist/fe/components/RegisterPage/types/index.js +1 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordForm.js +347 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordHeader.js +42 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordPage.js +61 -0
- package/dist/fe/components/ResetPasswordPage/index.js +5 -0
- package/dist/fe/components/ResetPasswordPage/store/index.js +36 -0
- package/dist/fe/components/ResetPasswordPage/theme/index.js +99 -0
- package/dist/fe/components/ResetPasswordPage/types/index.js +1 -0
- package/dist/fe/components/SearchBox/components/SearchBox.js +271 -0
- package/dist/fe/components/SearchBox/components/SearchBoxDropdown.js +87 -0
- package/dist/fe/components/SearchBox/index.js +5 -0
- package/dist/fe/components/SearchBox/theme/index.js +184 -0
- package/dist/fe/components/SearchBox/types/index.js +1 -0
- package/dist/fe/components/SearchBox/utils/cn.js +5 -0
- package/dist/fe/components/SearchBox/utils/debounce.js +22 -0
- package/dist/fe/components/SearchBox/utils/sanitize.js +48 -0
- package/dist/fe/components/SelectBox/components/SelectBox.js +364 -0
- package/dist/fe/components/SelectBox/components/SelectDropdown.js +92 -0
- package/dist/fe/components/SelectBox/components/SelectOptionItem.js +43 -0
- package/dist/fe/components/SelectBox/components/SelectTrigger.js +22 -0
- package/dist/fe/components/SelectBox/index.js +5 -0
- package/dist/fe/components/SelectBox/theme/index.js +98 -0
- package/dist/fe/components/SelectBox/types/index.js +1 -0
- package/dist/fe/components/SelectBox/utils/cn.js +3 -0
- package/dist/fe/components/SetPasswordPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordForm.js +142 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordHeader.js +23 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordPage.js +263 -0
- package/dist/fe/components/SetPasswordPage/index.js +7 -0
- package/dist/fe/components/SetPasswordPage/store/index.js +79 -0
- package/dist/fe/components/SetPasswordPage/theme/index.js +98 -0
- package/dist/fe/components/SetPasswordPage/types/index.js +12 -0
- package/dist/fe/components/UsersPage/components/InviteUserModal.js +262 -0
- package/dist/fe/components/UsersPage/components/Pagination.js +147 -0
- package/dist/fe/components/UsersPage/components/RoleAssignmentModal.js +186 -0
- package/dist/fe/components/UsersPage/components/StatsCards.js +124 -0
- package/dist/fe/components/UsersPage/components/UserDetailDrawer.js +444 -0
- package/dist/fe/components/UsersPage/components/UserFilters.js +142 -0
- package/dist/fe/components/UsersPage/components/UserListItem.js +125 -0
- package/dist/fe/components/UsersPage/components/UserListSkeleton.js +40 -0
- package/dist/fe/components/UsersPage/components/UsersPage.js +556 -0
- package/dist/fe/components/UsersPage/index.js +10 -0
- package/dist/fe/components/UsersPage/store/index.js +151 -0
- package/dist/fe/components/UsersPage/theme/index.js +231 -0
- package/dist/fe/components/UsersPage/types/index.js +1 -0
- package/dist/fe/components/VerifyEmailPage/components/VerifyEmailPage.js +290 -0
- package/dist/fe/components/VerifyEmailPage/index.js +3 -0
- package/dist/fe/components/VerifyEmailPage/store/index.js +45 -0
- package/dist/fe/components/VerifyEmailPage/theme/index.js +52 -0
- package/dist/fe/components/VerifyEmailPage/types/index.js +1 -0
- package/dist/fe/hooks/useNucleusEntity.js +247 -0
- package/dist/fe/index.js +28 -157
- package/dist/fe/types/index.js +1 -0
- package/dist/fe/utils/cn.js +5 -0
- package/dist/fe/utils/columnUtils.js +189 -0
- package/dist/fe/utils/endpointKeys.js +44 -0
- package/dist/index.js +1 -1
- package/dist/nucleus.config.d.ts +2 -0
- package/dist/src/Client/ApiCaller/client.js +1 -0
- package/dist/src/Client/ApiCaller/examples/usage.example.js +1 -0
- package/dist/src/Client/ApiCaller/generator.js +1 -0
- package/dist/src/Client/ApiCaller/index.js +1 -0
- package/dist/src/Client/ApiCaller/server.js +1 -0
- package/dist/src/Client/ApiCaller/system-tables.js +1 -0
- package/dist/src/Client/ApiCaller/types.js +1 -0
- package/dist/src/Client/Proxy/httpProxy.js +1 -0
- package/dist/src/Client/Proxy/index.js +1 -1
- package/dist/src/Client/Proxy/server.js +1 -0
- package/dist/src/Client/Proxy/types.js +1 -0
- package/dist/src/Client/Proxy/utils.js +1 -0
- package/dist/src/Client/Proxy/wsProxy.js +1 -0
- package/dist/src/Client/ServerFetch/index.js +1 -0
- package/dist/src/Client/ServerFetch/types.js +1 -0
- package/dist/src/Client/index.js +1 -0
- package/package.json +1 -1
- package/scripts/build.ts +41 -16
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { dataTableTheme } from "../theme";
|
|
7
|
+
import { cn } from "../utils/cn";
|
|
8
|
+
import { SkeletonRow } from "./SkeletonRow";
|
|
9
|
+
export function SkeletonTable({ columns, actionColumns, rowCount = 5, defaultColumnWidth = 150 }) {
|
|
10
|
+
const tableRef = useRef(null);
|
|
11
|
+
const theme = dataTableTheme;
|
|
12
|
+
useGSAP(()=>{
|
|
13
|
+
if (!tableRef.current) return;
|
|
14
|
+
gsap.fromTo(tableRef.current, {
|
|
15
|
+
opacity: 0
|
|
16
|
+
}, {
|
|
17
|
+
opacity: 1,
|
|
18
|
+
duration: 0.3,
|
|
19
|
+
ease: "power2.out"
|
|
20
|
+
});
|
|
21
|
+
}, []);
|
|
22
|
+
const columnWidths = columns.map((col)=>col.width ?? defaultColumnWidth);
|
|
23
|
+
if (actionColumns?.length) {
|
|
24
|
+
actionColumns.forEach((col)=>{
|
|
25
|
+
columnWidths.push(col.width ?? defaultColumnWidth);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return /*#__PURE__*/ _jsxs("table", {
|
|
29
|
+
ref: tableRef,
|
|
30
|
+
className: cn(theme.table.base, theme.table.layout),
|
|
31
|
+
children: [
|
|
32
|
+
/*#__PURE__*/ _jsx("thead", {
|
|
33
|
+
className: theme.header.wrapper.base,
|
|
34
|
+
children: /*#__PURE__*/ _jsxs("tr", {
|
|
35
|
+
className: theme.header.row.base,
|
|
36
|
+
children: [
|
|
37
|
+
columns.map((column, colIndex)=>/*#__PURE__*/ _jsx("th", {
|
|
38
|
+
style: {
|
|
39
|
+
width: columnWidths[colIndex]
|
|
40
|
+
},
|
|
41
|
+
className: cn(theme.header.cell.base, theme.header.cell.padding, theme.header.cell.text, theme.header.cell.color),
|
|
42
|
+
children: /*#__PURE__*/ _jsx(SkeletonHeaderCell, {})
|
|
43
|
+
}, String(column.key))),
|
|
44
|
+
actionColumns?.map((column)=>/*#__PURE__*/ _jsx("th", {
|
|
45
|
+
style: {
|
|
46
|
+
width: column.width ?? defaultColumnWidth
|
|
47
|
+
},
|
|
48
|
+
className: cn(theme.header.cell.base, theme.header.cell.padding, theme.header.cell.text, theme.header.cell.color),
|
|
49
|
+
children: /*#__PURE__*/ _jsx(SkeletonHeaderCell, {})
|
|
50
|
+
}, column.key))
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ _jsx("tbody", {
|
|
55
|
+
className: theme.body.wrapper.base,
|
|
56
|
+
children: Array.from({
|
|
57
|
+
length: rowCount
|
|
58
|
+
}).map((_, rowIndex)=>/*#__PURE__*/ _jsx(SkeletonRow, {
|
|
59
|
+
columnCount: columns.length,
|
|
60
|
+
rowIndex: rowIndex,
|
|
61
|
+
columnWidths: columnWidths,
|
|
62
|
+
hasActionColumn: Boolean(actionColumns?.length)
|
|
63
|
+
}, rowIndex))
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function SkeletonHeaderCell() {
|
|
69
|
+
const cellRef = useRef(null);
|
|
70
|
+
useGSAP(()=>{
|
|
71
|
+
if (!cellRef.current) return;
|
|
72
|
+
gsap.to(cellRef.current, {
|
|
73
|
+
backgroundPosition: "200% 0",
|
|
74
|
+
duration: 1.5,
|
|
75
|
+
repeat: -1,
|
|
76
|
+
ease: "none"
|
|
77
|
+
});
|
|
78
|
+
}, []);
|
|
79
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
80
|
+
ref: cellRef,
|
|
81
|
+
className: "h-4 w-1/2 rounded bg-gradient-to-r from-gray-300 via-gray-400 to-gray-300 bg-[length:200%_100%] dark:from-zinc-600 dark:via-zinc-500 dark:to-zinc-600"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { dataTableTheme } from "../theme";
|
|
7
|
+
import { cn } from "../utils/cn";
|
|
8
|
+
gsap.registerPlugin(useGSAP);
|
|
9
|
+
export function SortIcon({ direction, isActive, className }) {
|
|
10
|
+
const iconRef = useRef(null);
|
|
11
|
+
useGSAP(()=>{
|
|
12
|
+
if (!iconRef.current) return;
|
|
13
|
+
const rotation = isActive && direction === "desc" ? 180 : 0;
|
|
14
|
+
gsap.to(iconRef.current, {
|
|
15
|
+
rotation,
|
|
16
|
+
opacity: isActive ? 1 : 0.4,
|
|
17
|
+
duration: dataTableTheme.animation.sort.duration,
|
|
18
|
+
ease: dataTableTheme.animation.sort.ease
|
|
19
|
+
});
|
|
20
|
+
}, [
|
|
21
|
+
direction,
|
|
22
|
+
isActive
|
|
23
|
+
]);
|
|
24
|
+
const theme = dataTableTheme.header.sortIcon;
|
|
25
|
+
return /*#__PURE__*/ _jsx("svg", {
|
|
26
|
+
ref: iconRef,
|
|
27
|
+
className: cn(theme.base, isActive ? theme.active : theme.inactive, className),
|
|
28
|
+
width: "12",
|
|
29
|
+
height: "12",
|
|
30
|
+
viewBox: "0 0 12 12",
|
|
31
|
+
fill: "none",
|
|
32
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
children: /*#__PURE__*/ _jsx("path", {
|
|
35
|
+
d: "M6 2L10 7H2L6 2Z",
|
|
36
|
+
fill: "currentColor"
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { dataTableTheme } from "../theme";
|
|
4
|
+
import { cn } from "../utils/cn";
|
|
5
|
+
import { HeaderCell } from "./HeaderCell";
|
|
6
|
+
import { SelectionCell } from "./SelectionCell";
|
|
7
|
+
export function TableHeader({ columns, actionColumns, columnWidths, sortColumnKey, sortDirection, resizingColumn, defaultColumnWidth, onSort, onResizeStart, onColumnDoubleClick, headerMiddleware, enableSelection, totalRows = 0 }) {
|
|
8
|
+
const theme = dataTableTheme.header;
|
|
9
|
+
const getColumnWidth = (key, defaultWidth)=>{
|
|
10
|
+
return columnWidths[key] ?? defaultWidth ?? defaultColumnWidth;
|
|
11
|
+
};
|
|
12
|
+
return /*#__PURE__*/ _jsx("thead", {
|
|
13
|
+
className: cn(theme.wrapper.base, theme.wrapper.background),
|
|
14
|
+
children: /*#__PURE__*/ _jsxs("tr", {
|
|
15
|
+
className: cn(theme.row.base, theme.row.border),
|
|
16
|
+
children: [
|
|
17
|
+
enableSelection && /*#__PURE__*/ _jsx(SelectionCell, {
|
|
18
|
+
rowIndex: -1,
|
|
19
|
+
isHovered: false,
|
|
20
|
+
isHeader: true,
|
|
21
|
+
totalRows: totalRows
|
|
22
|
+
}),
|
|
23
|
+
columns.map((column)=>{
|
|
24
|
+
const columnKey = String(column.key);
|
|
25
|
+
return /*#__PURE__*/ _jsx(HeaderCell, {
|
|
26
|
+
column: column,
|
|
27
|
+
width: getColumnWidth(columnKey, column.width),
|
|
28
|
+
sortDirection: sortColumnKey === column.key ? sortDirection : null,
|
|
29
|
+
isResizing: resizingColumn === columnKey,
|
|
30
|
+
isSorted: sortColumnKey === column.key,
|
|
31
|
+
onSort: ()=>onSort(column.key),
|
|
32
|
+
onResizeStart: (e)=>onResizeStart(columnKey, e),
|
|
33
|
+
onDoubleClick: ()=>onColumnDoubleClick(columnKey),
|
|
34
|
+
headerMiddleware: headerMiddleware
|
|
35
|
+
}, columnKey);
|
|
36
|
+
}),
|
|
37
|
+
actionColumns?.map((column)=>/*#__PURE__*/ _jsx("th", {
|
|
38
|
+
scope: "col",
|
|
39
|
+
style: {
|
|
40
|
+
width: `${getColumnWidth(column.key, column.width)}px`,
|
|
41
|
+
minWidth: column.minWidth
|
|
42
|
+
},
|
|
43
|
+
className: cn(theme.cell.base, theme.cell.padding, theme.cell.text, theme.cell.color, column.headerClassName),
|
|
44
|
+
children: column.header
|
|
45
|
+
}, column.key))
|
|
46
|
+
]
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { useDataTableStore } from "../store";
|
|
7
|
+
import { dataTableTheme } from "../theme";
|
|
8
|
+
import { cn } from "../utils/cn";
|
|
9
|
+
import { ActionCell } from "./ActionCell";
|
|
10
|
+
import { DataCell } from "./DataCell";
|
|
11
|
+
import { EditableCell } from "./EditableCell";
|
|
12
|
+
import { SelectionCell } from "./SelectionCell";
|
|
13
|
+
gsap.registerPlugin(useGSAP);
|
|
14
|
+
export function TableRow({ row, rowIndex, columns, actionColumns, defaultColumnWidth, hasClickAction, hasDoubleClickAction, onCellClick, onCellDoubleClick, onCellEdit, cellMiddleware, animationDelay = 0, enableSelection }) {
|
|
15
|
+
const rowRef = useRef(null);
|
|
16
|
+
const store = useDataTableStore();
|
|
17
|
+
const theme = dataTableTheme.body.row;
|
|
18
|
+
const animConfig = dataTableTheme.animation.row;
|
|
19
|
+
const isHovered = store.hoveredRow === rowIndex;
|
|
20
|
+
const columnWidths = store.columnWidths;
|
|
21
|
+
const hasAnimated = useRef(false);
|
|
22
|
+
useGSAP(()=>{
|
|
23
|
+
if (!rowRef.current || hasAnimated.current) return;
|
|
24
|
+
gsap.fromTo(rowRef.current, {
|
|
25
|
+
opacity: animConfig.enter.opacity,
|
|
26
|
+
y: animConfig.enter.y
|
|
27
|
+
}, {
|
|
28
|
+
opacity: animConfig.visible.opacity,
|
|
29
|
+
y: animConfig.visible.y,
|
|
30
|
+
duration: animConfig.duration,
|
|
31
|
+
delay: animationDelay,
|
|
32
|
+
ease: "power2.out"
|
|
33
|
+
});
|
|
34
|
+
hasAnimated.current = true;
|
|
35
|
+
}, []);
|
|
36
|
+
const getColumnWidth = (key, defaultWidth)=>{
|
|
37
|
+
return columnWidths[key] ?? defaultWidth ?? defaultColumnWidth;
|
|
38
|
+
};
|
|
39
|
+
const isEven = rowIndex % 2 === 0;
|
|
40
|
+
const handleCellClick = (columnKey, isActionColumn)=>{
|
|
41
|
+
if (!onCellClick) return;
|
|
42
|
+
const value = isActionColumn ? null : row[columnKey];
|
|
43
|
+
onCellClick({
|
|
44
|
+
value,
|
|
45
|
+
row,
|
|
46
|
+
rowIndex,
|
|
47
|
+
columnKey,
|
|
48
|
+
isActionColumn
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const handleCellDoubleClick = (columnKey, isActionColumn)=>{
|
|
52
|
+
if (!onCellDoubleClick) return;
|
|
53
|
+
const value = isActionColumn ? null : row[columnKey];
|
|
54
|
+
onCellDoubleClick({
|
|
55
|
+
value,
|
|
56
|
+
row,
|
|
57
|
+
rowIndex,
|
|
58
|
+
columnKey,
|
|
59
|
+
isActionColumn
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return /*#__PURE__*/ _jsxs("tr", {
|
|
63
|
+
ref: rowRef,
|
|
64
|
+
className: cn(theme.base, theme.border, theme.transition, theme.hover, isEven ? theme.zebra.even : theme.zebra.odd),
|
|
65
|
+
onMouseEnter: ()=>store.setHoveredRow(rowIndex),
|
|
66
|
+
onMouseLeave: ()=>store.setHoveredRow(null),
|
|
67
|
+
children: [
|
|
68
|
+
enableSelection && /*#__PURE__*/ _jsx(SelectionCell, {
|
|
69
|
+
rowIndex: rowIndex,
|
|
70
|
+
isHovered: isHovered
|
|
71
|
+
}),
|
|
72
|
+
columns.map((column)=>{
|
|
73
|
+
const columnKey = String(column.key);
|
|
74
|
+
const columnWidth = getColumnWidth(columnKey, column.width);
|
|
75
|
+
if (column.editable) {
|
|
76
|
+
return /*#__PURE__*/ _jsx(EditableCell, {
|
|
77
|
+
column: column,
|
|
78
|
+
row: row,
|
|
79
|
+
rowIndex: rowIndex,
|
|
80
|
+
width: columnWidth,
|
|
81
|
+
isHovered: isHovered,
|
|
82
|
+
onSave: (newValue)=>{
|
|
83
|
+
if (onCellEdit) {
|
|
84
|
+
const oldValue = row[column.key];
|
|
85
|
+
onCellEdit({
|
|
86
|
+
row,
|
|
87
|
+
rowIndex,
|
|
88
|
+
columnKey: column.key,
|
|
89
|
+
oldValue,
|
|
90
|
+
newValue
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
cellMiddleware: cellMiddleware
|
|
95
|
+
}, columnKey);
|
|
96
|
+
}
|
|
97
|
+
return /*#__PURE__*/ _jsx(DataCell, {
|
|
98
|
+
column: column,
|
|
99
|
+
row: row,
|
|
100
|
+
rowIndex: rowIndex,
|
|
101
|
+
width: columnWidth,
|
|
102
|
+
isHovered: isHovered,
|
|
103
|
+
hasClickAction: hasClickAction,
|
|
104
|
+
hasDoubleClickAction: hasDoubleClickAction,
|
|
105
|
+
onClick: ()=>handleCellClick(column.key, false),
|
|
106
|
+
onDoubleClick: ()=>handleCellDoubleClick(column.key, false),
|
|
107
|
+
cellMiddleware: cellMiddleware
|
|
108
|
+
}, columnKey);
|
|
109
|
+
}),
|
|
110
|
+
actionColumns?.map((column)=>/*#__PURE__*/ _jsx(ActionCell, {
|
|
111
|
+
column: column,
|
|
112
|
+
row: row,
|
|
113
|
+
rowIndex: rowIndex,
|
|
114
|
+
width: getColumnWidth(column.key, column.width)
|
|
115
|
+
}, column.key))
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { ActionCell } from "./ActionCell";
|
|
2
|
+
export { DataCell } from "./DataCell";
|
|
3
|
+
export { EditableCell } from "./EditableCell";
|
|
4
|
+
export { EmptyState } from "./EmptyState";
|
|
5
|
+
export { HeaderCell } from "./HeaderCell";
|
|
6
|
+
export { InfiniteScrollTrigger } from "./InfiniteScrollTrigger";
|
|
7
|
+
export { LoadingSpinner } from "./LoadingSpinner";
|
|
8
|
+
export { ResizeHandle } from "./ResizeHandle";
|
|
9
|
+
export { SelectionCell } from "./SelectionCell";
|
|
10
|
+
export { SkeletonRow } from "./SkeletonRow";
|
|
11
|
+
export { SkeletonTable } from "./SkeletonTable";
|
|
12
|
+
export { SortIcon } from "./SortIcon";
|
|
13
|
+
export { TableHeader } from "./TableHeader";
|
|
14
|
+
export { TableRow } from "./TableRow";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export function useAutoFitColumn({ onAutoFit }) {
|
|
3
|
+
const autoFit = (columnKey, tableRef)=>{
|
|
4
|
+
if (!tableRef) return;
|
|
5
|
+
const cells = tableRef.querySelectorAll(`td[data-column="${columnKey}"], th[data-column="${columnKey}"]`);
|
|
6
|
+
let maxWidth = 0;
|
|
7
|
+
cells.forEach((cell)=>{
|
|
8
|
+
const content = cell.firstElementChild;
|
|
9
|
+
if (content) {
|
|
10
|
+
const contentWidth = content.scrollWidth;
|
|
11
|
+
maxWidth = Math.max(maxWidth, contentWidth);
|
|
12
|
+
} else {
|
|
13
|
+
maxWidth = Math.max(maxWidth, cell.scrollWidth);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (maxWidth > 0) {
|
|
17
|
+
onAutoFit(columnKey, maxWidth);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
autoFit
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
export function useResizeColumn({ minWidth, tableRef, onResizeStart, onResizeEnd }) {
|
|
4
|
+
const startXRef = useRef(0);
|
|
5
|
+
const startWidthRef = useRef(0);
|
|
6
|
+
const columnKeyRef = useRef("");
|
|
7
|
+
const currentWidthRef = useRef(0);
|
|
8
|
+
const justResizedRef = useRef(false);
|
|
9
|
+
const getHeaderCell = (columnKey)=>{
|
|
10
|
+
if (!tableRef.current) return null;
|
|
11
|
+
return tableRef.current.querySelector(`th[data-column-key="${columnKey}"]`);
|
|
12
|
+
};
|
|
13
|
+
const getColumnElements = (columnKey)=>{
|
|
14
|
+
if (!tableRef.current) return [];
|
|
15
|
+
const headerCell = getHeaderCell(columnKey);
|
|
16
|
+
const dataCells = tableRef.current.querySelectorAll(`td[data-column-key="${columnKey}"]`);
|
|
17
|
+
const elements = [];
|
|
18
|
+
if (headerCell) elements.push(headerCell);
|
|
19
|
+
for (const cell of Array.from(dataCells)){
|
|
20
|
+
elements.push(cell);
|
|
21
|
+
}
|
|
22
|
+
return elements;
|
|
23
|
+
};
|
|
24
|
+
const freezeAllColumnWidths = (excludeLastColumn)=>{
|
|
25
|
+
if (!tableRef.current) return;
|
|
26
|
+
const allHeaders = Array.from(tableRef.current.querySelectorAll("th[data-column-key]"));
|
|
27
|
+
const lastIndex = allHeaders.length - 1;
|
|
28
|
+
for(let i = 0; i < allHeaders.length; i++){
|
|
29
|
+
const header = allHeaders[i];
|
|
30
|
+
if (!header) continue;
|
|
31
|
+
const columnKey = header.getAttribute("data-column-key");
|
|
32
|
+
if (!columnKey) continue;
|
|
33
|
+
const isLast = i === lastIndex;
|
|
34
|
+
const width = header.offsetWidth;
|
|
35
|
+
const elements = getColumnElements(columnKey);
|
|
36
|
+
for (const el of elements){
|
|
37
|
+
if (excludeLastColumn && isLast) {
|
|
38
|
+
el.style.width = "";
|
|
39
|
+
} else {
|
|
40
|
+
el.style.width = `${width}px`;
|
|
41
|
+
el.style.minWidth = `${width}px`;
|
|
42
|
+
el.style.maxWidth = `${width}px`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const updateColumnWidth = (width)=>{
|
|
48
|
+
const elements = getColumnElements(columnKeyRef.current);
|
|
49
|
+
for (const el of elements){
|
|
50
|
+
el.style.width = `${width}px`;
|
|
51
|
+
el.style.minWidth = `${width}px`;
|
|
52
|
+
el.style.maxWidth = `${width}px`;
|
|
53
|
+
}
|
|
54
|
+
currentWidthRef.current = width;
|
|
55
|
+
};
|
|
56
|
+
const handleMouseMove = (e)=>{
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
const diff = e.clientX - startXRef.current;
|
|
59
|
+
const newWidth = Math.max(minWidth, startWidthRef.current + diff);
|
|
60
|
+
updateColumnWidth(newWidth);
|
|
61
|
+
};
|
|
62
|
+
const handleTouchMove = (e)=>{
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
const touch = e.touches[0];
|
|
65
|
+
if (!touch) return;
|
|
66
|
+
const diff = touch.clientX - startXRef.current;
|
|
67
|
+
const newWidth = Math.max(minWidth, startWidthRef.current + diff);
|
|
68
|
+
updateColumnWidth(newWidth);
|
|
69
|
+
};
|
|
70
|
+
const cleanup = ()=>{
|
|
71
|
+
document.body.style.cursor = "";
|
|
72
|
+
document.body.style.userSelect = "";
|
|
73
|
+
justResizedRef.current = true;
|
|
74
|
+
setTimeout(()=>{
|
|
75
|
+
justResizedRef.current = false;
|
|
76
|
+
}, 100);
|
|
77
|
+
};
|
|
78
|
+
const isJustResized = ()=>justResizedRef.current;
|
|
79
|
+
const handleMouseUp = ()=>{
|
|
80
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
81
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
82
|
+
cleanup();
|
|
83
|
+
onResizeEnd(columnKeyRef.current, currentWidthRef.current);
|
|
84
|
+
};
|
|
85
|
+
const handleTouchEnd = ()=>{
|
|
86
|
+
document.removeEventListener("touchmove", handleTouchMove);
|
|
87
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
88
|
+
cleanup();
|
|
89
|
+
onResizeEnd(columnKeyRef.current, currentWidthRef.current);
|
|
90
|
+
};
|
|
91
|
+
const startResize = (columnKey, e)=>{
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
const headerCell = getHeaderCell(columnKey);
|
|
95
|
+
if (!headerCell) return;
|
|
96
|
+
const actualWidth = headerCell.offsetWidth;
|
|
97
|
+
columnKeyRef.current = columnKey;
|
|
98
|
+
startWidthRef.current = actualWidth;
|
|
99
|
+
currentWidthRef.current = actualWidth;
|
|
100
|
+
freezeAllColumnWidths(true);
|
|
101
|
+
onResizeStart(columnKey);
|
|
102
|
+
document.body.style.cursor = "col-resize";
|
|
103
|
+
document.body.style.userSelect = "none";
|
|
104
|
+
if ("touches" in e) {
|
|
105
|
+
const touch = e.touches[0];
|
|
106
|
+
if (!touch) return;
|
|
107
|
+
startXRef.current = touch.clientX;
|
|
108
|
+
document.addEventListener("touchmove", handleTouchMove, {
|
|
109
|
+
passive: false
|
|
110
|
+
});
|
|
111
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
112
|
+
} else {
|
|
113
|
+
startXRef.current = e.clientX;
|
|
114
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
115
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
startResize,
|
|
120
|
+
isJustResized
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { batch, createStore } from "h-state";
|
|
2
|
+
const initialState = {
|
|
3
|
+
sortColumnKey: null,
|
|
4
|
+
sortDirection: null,
|
|
5
|
+
columnWidths: {},
|
|
6
|
+
rowHeights: {},
|
|
7
|
+
resizingColumn: null,
|
|
8
|
+
resizingRow: null,
|
|
9
|
+
hoveredRow: null,
|
|
10
|
+
hoveredCell: null,
|
|
11
|
+
editingCell: null,
|
|
12
|
+
editValue: "",
|
|
13
|
+
isLoadingMore: false,
|
|
14
|
+
selectedRows: []
|
|
15
|
+
};
|
|
16
|
+
const { useStore } = createStore(initialState, {
|
|
17
|
+
setSortState: (store)=>(columnKey, direction)=>{
|
|
18
|
+
batch(()=>{
|
|
19
|
+
store.sortColumnKey = columnKey;
|
|
20
|
+
store.sortDirection = direction;
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
setColumnWidth: (store)=>(columnKey, width)=>{
|
|
24
|
+
store.columnWidths[columnKey] = width;
|
|
25
|
+
},
|
|
26
|
+
setRowHeight: (store)=>(rowIndex, height)=>{
|
|
27
|
+
store.rowHeights[rowIndex] = height;
|
|
28
|
+
},
|
|
29
|
+
setResizingColumn: (store)=>(columnKey)=>{
|
|
30
|
+
store.resizingColumn = columnKey;
|
|
31
|
+
},
|
|
32
|
+
setResizingRow: (store)=>(rowIndex)=>{
|
|
33
|
+
store.resizingRow = rowIndex;
|
|
34
|
+
},
|
|
35
|
+
setHoveredRow: (store)=>(rowIndex)=>{
|
|
36
|
+
store.hoveredRow = rowIndex;
|
|
37
|
+
},
|
|
38
|
+
setHoveredCell: (store)=>(cell)=>{
|
|
39
|
+
store.hoveredCell = cell;
|
|
40
|
+
},
|
|
41
|
+
setEditingCell: (store)=>(cell)=>{
|
|
42
|
+
store.editingCell = cell;
|
|
43
|
+
},
|
|
44
|
+
setEditValue: (store)=>(value)=>{
|
|
45
|
+
store.editValue = value;
|
|
46
|
+
},
|
|
47
|
+
startEditing: (store)=>(row, column, initialValue)=>{
|
|
48
|
+
batch(()=>{
|
|
49
|
+
store.editingCell = {
|
|
50
|
+
row,
|
|
51
|
+
column
|
|
52
|
+
};
|
|
53
|
+
store.editValue = initialValue;
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
cancelEditing: (store)=>()=>{
|
|
57
|
+
batch(()=>{
|
|
58
|
+
store.editingCell = null;
|
|
59
|
+
store.editValue = "";
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
setIsLoadingMore: (store)=>(isLoading)=>{
|
|
63
|
+
store.isLoadingMore = isLoading;
|
|
64
|
+
},
|
|
65
|
+
resetWidths: (store)=>()=>{
|
|
66
|
+
batch(()=>{
|
|
67
|
+
store.columnWidths = {};
|
|
68
|
+
store.rowHeights = {};
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
autoFitColumn: (store)=>(columnKey, contentWidth)=>{
|
|
72
|
+
store.columnWidths[columnKey] = Math.max(contentWidth + 32, 60);
|
|
73
|
+
},
|
|
74
|
+
toggleRowSelection: (store)=>(rowIndex)=>{
|
|
75
|
+
const index = store.selectedRows.indexOf(rowIndex);
|
|
76
|
+
if (index === -1) {
|
|
77
|
+
store.selectedRows = [
|
|
78
|
+
...store.selectedRows,
|
|
79
|
+
rowIndex
|
|
80
|
+
];
|
|
81
|
+
} else {
|
|
82
|
+
store.selectedRows = store.selectedRows.filter((i)=>i !== rowIndex);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
selectAllRows: (store)=>(rowCount)=>{
|
|
86
|
+
store.selectedRows = Array.from({
|
|
87
|
+
length: rowCount
|
|
88
|
+
}, (_, i)=>i);
|
|
89
|
+
},
|
|
90
|
+
clearSelection: (store)=>()=>{
|
|
91
|
+
store.selectedRows = [];
|
|
92
|
+
},
|
|
93
|
+
isRowSelected: (store)=>(rowIndex)=>{
|
|
94
|
+
return store.selectedRows.includes(rowIndex);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
export { useStore as useDataTableStore };
|