@kareemelbalshe/any-table 1.0.3 â 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -8
- package/dist/components/AnyTable.d.ts +5 -2
- package/dist/components/TableBody.d.ts +5 -1
- package/dist/components/TableConfirmDialog.d.ts +1 -1
- package/dist/components/TableEmptyState.d.ts +1 -1
- package/dist/components/TableErrorState.d.ts +1 -1
- package/dist/components/TableHeader.d.ts +2 -1
- package/dist/components/TablePagination.d.ts +1 -1
- package/dist/components/TableSearch.d.ts +1 -1
- package/dist/components/TableSkeleton.d.ts +1 -1
- package/dist/components/TableToolbar.d.ts +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useAnyTableController.d.ts +2 -1
- package/dist/hooks/useAnyTableData.d.ts +2 -1
- package/dist/hooks/useAnyTableSelection.d.ts +1 -1
- package/dist/hooks/useAnyTableVirtualizer.d.ts +20 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1565 -1461
- package/dist/index.js.map +1 -1
- package/dist/renderers/ActionRenderer.d.ts +1 -1
- package/dist/renderers/CellRenderer.d.ts +1 -1
- package/dist/renderers/DefaultRenderers.d.ts +20 -59
- package/dist/style.css +1 -1
- package/dist/types/table.types.d.ts +26 -0
- package/package.json +13 -7
- package/dist/favicon.svg +0 -65
- package/dist/logo.svg +0 -65
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# đ AnyTable â Smart Data Table Library for React
|
|
2
2
|
|
|
3
|
-
> **A developer-facing, smart data table library for React (18
|
|
3
|
+
> **A developer-facing, smart data table library for React (16.8+, 17, 18, 19+) & TypeScript with 3-Tier API auto-detection, dynamic column extraction, autonomous server/client search, sorting & pagination, interactive row actions with instant PATCH switches, zero runtime dependencies, and zero business logic coupling.**
|
|
4
4
|
|
|
5
5
|
[](https://npmjs.org/package/@kareemelbalshe/any-table)
|
|
6
6
|
[](https://kareemelbalshe.github.io/anyTable/)
|
|
7
7
|
[](LICENSE)
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
|
-
[](https://react.dev/)
|
|
10
|
+
[-success)](package.json)
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
- [Destructive Actions with Confirmation Modal](#3-destructive-actions-with-confirmation-modal)
|
|
29
29
|
- [đ ī¸ Column Types & Smart Renderers](#ī¸-column-types--smart-renderers)
|
|
30
30
|
- [đšī¸ Imperative Controller API (`tableRef`)](#ī¸-imperative-controller-api-tableref)
|
|
31
|
+
- [⥠High-Performance DOM Virtualization (100,000+ Rows)](#-high-performance-dom-virtualization-100000-rows)
|
|
31
32
|
- [âī¸ Selection & Batch Operations](#ī¸-selection--batch-operations)
|
|
32
33
|
- [đ¨ Theming & Dark Mode](#-theming--dark-mode)
|
|
33
34
|
- [đ Integration Guides (Next.js & Vite)](#-integration-guides-nextjs--vite)
|
|
@@ -62,15 +63,17 @@ AnyTable is intentionally designed to **never lock you into specific backend con
|
|
|
62
63
|
|
|
63
64
|
### 1. Install via Package Manager
|
|
64
65
|
|
|
66
|
+
> **Zero Runtime Dependencies**: AnyTable has **0** external runtime dependencies and is fully compatible with **React 16.8+, React 17, React 18, React 19**, and Next.js / Vite.
|
|
67
|
+
|
|
65
68
|
```bash
|
|
66
69
|
# Using NPM
|
|
67
|
-
npm install @kareemelbalshe/any-table
|
|
70
|
+
npm install @kareemelbalshe/any-table
|
|
68
71
|
|
|
69
72
|
# Using Yarn
|
|
70
|
-
yarn add @kareemelbalshe/any-table
|
|
73
|
+
yarn add @kareemelbalshe/any-table
|
|
71
74
|
|
|
72
75
|
# Using PNPM
|
|
73
|
-
pnpm add @kareemelbalshe/any-table
|
|
76
|
+
pnpm add @kareemelbalshe/any-table
|
|
74
77
|
```
|
|
75
78
|
|
|
76
79
|
### 2. Import CSS Styles
|
|
@@ -643,8 +646,9 @@ export default function Dashboard() {
|
|
|
643
646
|
<button onClick={() => tableRef.current?.reset()}>⥠Reset Table</button>
|
|
644
647
|
</div>
|
|
645
648
|
|
|
649
|
+
{/* Both standard ref={tableRef} and tableRef={tableRef} are supported */}
|
|
646
650
|
<AnyTable<User>
|
|
647
|
-
|
|
651
|
+
ref={tableRef}
|
|
648
652
|
api={{ fetcher: fetchUsers }}
|
|
649
653
|
/>
|
|
650
654
|
</div>
|
|
@@ -654,6 +658,63 @@ export default function Dashboard() {
|
|
|
654
658
|
|
|
655
659
|
---
|
|
656
660
|
|
|
661
|
+
## ⥠High-Performance DOM Virtualization (100,000+ Rows)
|
|
662
|
+
|
|
663
|
+
Need to render 10,000, 50,000, or even **100,000+ rows** smoothly at **60 FPS**? AnyTable features a built-in, native DOM virtualization engine with **zero external runtime dependencies** (0 KB overhead) while maintaining **100% valid HTML `<table>` semantics**.
|
|
664
|
+
|
|
665
|
+
### Key Highlights
|
|
666
|
+
- đ **Smooth 60 FPS Scrolling**: Uses passive event listeners and `requestAnimationFrame` to batch scroll updates and completely eliminate layout thrashing.
|
|
667
|
+
- đ **Standard HTML `<table>`**: Never breaks your table into arbitrary nested `<div>` tags; uses dynamic top/bottom spacer rows inside `<tbody>`.
|
|
668
|
+
- đ **Programmatic Navigation**: Jump to any row instantly via `tableRef.current.scrollToIndex(index, "center")`.
|
|
669
|
+
- đ **Integrated Search & Sort**: Automatically recalculates windowing slices during live client search and column sorting.
|
|
670
|
+
- đī¸ **Sticky Header**: Automatically sticks `<thead>` to the top of the virtual scroll container.
|
|
671
|
+
|
|
672
|
+
### Usage Example
|
|
673
|
+
|
|
674
|
+
```tsx
|
|
675
|
+
import React, { useRef } from "react";
|
|
676
|
+
import { AnyTable, TableInstance } from "@kareemelbalshe/any-table";
|
|
677
|
+
|
|
678
|
+
interface Employee {
|
|
679
|
+
id: number;
|
|
680
|
+
name: string;
|
|
681
|
+
department: string;
|
|
682
|
+
salary: number;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
export function WorkforceDirectory({ employees }: { employees: Employee[] }) {
|
|
686
|
+
const tableRef = useRef<TableInstance<Employee>>(null);
|
|
687
|
+
|
|
688
|
+
return (
|
|
689
|
+
<div>
|
|
690
|
+
<div className="flex gap-2 mb-4">
|
|
691
|
+
<button onClick={() => tableRef.current?.scrollToIndex(0, "start")}>
|
|
692
|
+
âŽī¸ Top
|
|
693
|
+
</button>
|
|
694
|
+
<button onClick={() => tableRef.current?.scrollToIndex(50000, "center")}>
|
|
695
|
+
đ Jump to #50,000
|
|
696
|
+
</button>
|
|
697
|
+
</div>
|
|
698
|
+
|
|
699
|
+
<AnyTable<Employee>
|
|
700
|
+
ref={tableRef}
|
|
701
|
+
data={employees} // e.g. 100,000 rows
|
|
702
|
+
rowKey="id"
|
|
703
|
+
search={true}
|
|
704
|
+
sorting={true}
|
|
705
|
+
virtualized={{
|
|
706
|
+
rowHeight: 48, // Row height in pixels (default: 48)
|
|
707
|
+
maxHeight: 520, // Scroll container height in px (default: 520)
|
|
708
|
+
overscan: 10, // Buffer rows outside visible area (default: 10)
|
|
709
|
+
}}
|
|
710
|
+
/>
|
|
711
|
+
</div>
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
---
|
|
717
|
+
|
|
657
718
|
## âī¸ Selection & Batch Operations
|
|
658
719
|
|
|
659
720
|
Enable multi-row checkboxes to perform batch deletes or status updates:
|
|
@@ -1345,7 +1406,37 @@ export default function AdminPage() {
|
|
|
1345
1406
|
|
|
1346
1407
|
---
|
|
1347
1408
|
|
|
1348
|
-
### đĄ Ø§ŲØØ§ŲØŠ 8:
|
|
1409
|
+
### đĄ Ø§ŲØØ§ŲØŠ 8: Ø§ŲØŦدŲŲØŠ Ø§ŲØ§ŲØĒØąØ§ØļŲØŠ ŲØšØąØļ 100,000+ ØĩŲ Ø¨ØŗŲØ§ØŗØŠ 60fps دŲŲ ØŖŲ ØĒØŦŲ
ŲØ¯ ŲŲŲ DOM
|
|
1410
|
+
```tsx
|
|
1411
|
+
export default function MassiveDataPage() {
|
|
1412
|
+
const tableRef = useRef<TableInstance<any>>(null);
|
|
1413
|
+
|
|
1414
|
+
return (
|
|
1415
|
+
<div>
|
|
1416
|
+
<button onClick={() => tableRef.current?.scrollToIndex(50000, "center")}>
|
|
1417
|
+
đ Ø§ŲŲŲØ˛ Ų
Ø¨Ø§Ø´ØąØŠ ØĨŲŲ Ø§ŲØĩŲ ØąŲŲ
50,000
|
|
1418
|
+
</button>
|
|
1419
|
+
|
|
1420
|
+
<AnyTable
|
|
1421
|
+
ref={tableRef}
|
|
1422
|
+
data={hundredThousandItems} // Ų
ØĩŲŲŲØŠ ØļØŽŲ
ØŠ Ø¨ŲØ§ 100 ØŖŲŲ ØšŲØĩØą
|
|
1423
|
+
rowKey="id"
|
|
1424
|
+
search={true}
|
|
1425
|
+
sorting={true}
|
|
1426
|
+
virtualized={{
|
|
1427
|
+
rowHeight: 48, // Ø§ØąØĒŲØ§Øš Ø§ŲØĩŲ Ø¨Ø§ŲØ¨ŲØŗŲ
|
|
1428
|
+
maxHeight: 520, // Ø§ØąØĒŲØ§Øš ŲØ§Ųذ؊ Ø§ŲØŦدŲŲ Ø§ŲØĒŲ
ØąŲØąŲØŠ
|
|
1429
|
+
overscan: 10, // ؚدد Ø§ŲØĩŲŲŲ Ø§ŲØšØ§Ø˛ŲØŠ ØŲŲ Ø§ŲØ´Ø§Ø´ØŠ
|
|
1430
|
+
}}
|
|
1431
|
+
/>
|
|
1432
|
+
</div>
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
```
|
|
1436
|
+
|
|
1437
|
+
---
|
|
1438
|
+
|
|
1439
|
+
### đĄ Ø§ŲØØ§ŲØŠ 9: Ø§ŲØĒØØ¯ŲØ¯ اŲŲ
ØĒؚدد ŲØ§ŲØšŲ
ŲŲØ§ØĒ Ø§ŲØŦŲ
Ø§ØšŲØŠ (Batch Operations)
|
|
1349
1440
|
```tsx
|
|
1350
1441
|
export default function SelectionPage() {
|
|
1351
1442
|
const [selectedUsers, setSelectedUsers] = useState([]);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { AnyTableProps } from '../types/table.types';
|
|
2
|
+
import { AnyTableProps, TableInstance } from '../types/table.types';
|
|
3
3
|
export declare function AnyTableInner<TData = any>(props: AnyTableProps<TData>): React.JSX.Element;
|
|
4
4
|
/**
|
|
5
5
|
* AnyTable â The developer-facing, smart data table library for React.
|
|
6
|
+
* Supports both standard ref={tableRef} and tableRef={tableRef} seamlessly across React 16.8, 17, 18, and 19.
|
|
6
7
|
*/
|
|
7
|
-
export declare
|
|
8
|
+
export declare const AnyTable: <TData = any>(props: AnyTableProps<TData> & {
|
|
9
|
+
ref?: React.Ref<TableInstance<TData>>;
|
|
10
|
+
}) => React.ReactElement | null;
|
|
8
11
|
export default AnyTable;
|
|
@@ -14,5 +14,9 @@ export interface TableBodyProps<TData = any> {
|
|
|
14
14
|
striped?: boolean;
|
|
15
15
|
hoverable?: boolean;
|
|
16
16
|
rowClassName?: string | ((row: TData, index: number) => string);
|
|
17
|
+
isVirtualized?: boolean;
|
|
18
|
+
paddingTop?: number;
|
|
19
|
+
paddingBottom?: number;
|
|
20
|
+
startIndex?: number;
|
|
17
21
|
}
|
|
18
|
-
export declare
|
|
22
|
+
export declare function TableBody<TData = any>({ rows, columns, actions, actionContext, rowKeyResolver, selectable, selectedKeys, onToggleSelectRow, onRowClick, striped, hoverable, rowClassName, isVirtualized, paddingTop, paddingBottom, startIndex, }: TableBodyProps<TData>): React.JSX.Element;
|
|
@@ -10,4 +10,4 @@ export interface ConfirmModalProps {
|
|
|
10
10
|
onConfirm: () => void | Promise<void>;
|
|
11
11
|
isLoading?: boolean;
|
|
12
12
|
}
|
|
13
|
-
export declare
|
|
13
|
+
export declare function ConfirmModal({ isOpen, title, message, confirmText, cancelText, type, onClose, onConfirm, isLoading, }: ConfirmModalProps): React.JSX.Element | null;
|
|
@@ -6,4 +6,4 @@ export interface TableEmptyStateProps {
|
|
|
6
6
|
onClearSearch?: () => void;
|
|
7
7
|
colSpan?: number;
|
|
8
8
|
}
|
|
9
|
-
export declare
|
|
9
|
+
export declare function TableEmptyState({ title, description, isSearchActive, onClearSearch, colSpan, }: TableEmptyStateProps): React.JSX.Element;
|
|
@@ -13,5 +13,6 @@ export interface TableHeaderProps<TData = any> {
|
|
|
13
13
|
isIndeterminate?: boolean;
|
|
14
14
|
onToggleSelectAll?: () => void;
|
|
15
15
|
headerClassName?: string;
|
|
16
|
+
sticky?: boolean;
|
|
16
17
|
}
|
|
17
|
-
export declare
|
|
18
|
+
export declare function TableHeader<TData = any>({ columns, hasActions, actionsTitle, actionsWidth, sortBy, sortOrder, onSort, selectable, allSelected, isIndeterminate, onToggleSelectAll, headerClassName, sticky, }: TableHeaderProps<TData>): React.JSX.Element;
|
|
@@ -11,4 +11,4 @@ export interface TablePaginationProps {
|
|
|
11
11
|
showTotalCount?: boolean;
|
|
12
12
|
pageWindow: number[];
|
|
13
13
|
}
|
|
14
|
-
export declare
|
|
14
|
+
export declare function TablePagination({ page, pageSize, totalRecords, totalPages, pageSizeOptions, onPageChange, onPageSizeChange, showPageSizeSelector, showTotalCount, pageWindow, }: TablePaginationProps): React.JSX.Element;
|
|
@@ -6,4 +6,4 @@ export interface TableSearchProps {
|
|
|
6
6
|
isDebouncing?: boolean;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
}
|
|
9
|
-
export declare
|
|
9
|
+
export declare function TableSearch({ value, onChange, onClear, isDebouncing, placeholder, }: TableSearchProps): React.JSX.Element;
|
|
@@ -4,4 +4,4 @@ export interface TableSkeletonProps {
|
|
|
4
4
|
rowsCount?: number;
|
|
5
5
|
hasActions?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare
|
|
7
|
+
export declare function TableSkeleton({ columnsCount, rowsCount, hasActions, }: TableSkeletonProps): React.JSX.Element;
|
|
@@ -13,4 +13,4 @@ export interface TableToolbarProps {
|
|
|
13
13
|
linkAdd?: string;
|
|
14
14
|
addHandler?: () => void;
|
|
15
15
|
}
|
|
16
|
-
export declare
|
|
16
|
+
export declare function TableToolbar({ displayTitle, subtitle, isSearchEnabled, searchQuery, setSearch, clearSearch, isDebouncing, searchPlaceholder, headerActions, add, linkAdd, addHandler, }: TableToolbarProps): React.JSX.Element | null;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ export interface UseAnyTableControllerParams<TData = any> {
|
|
|
14
14
|
selectedRows: TData[];
|
|
15
15
|
clearSelection: () => void;
|
|
16
16
|
getState: () => TableState<TData>;
|
|
17
|
+
scrollToIndex?: (index: number, align?: "start" | "center" | "end" | "auto") => void;
|
|
17
18
|
}
|
|
18
|
-
export declare function useAnyTableController<TData = any>({ tableRef, refresh, resetPagination, resetSearch, resetSorting, setPage, setPageSize, setSearch, setSorting, selectedRows, clearSelection, getState, }: UseAnyTableControllerParams<TData>): void;
|
|
19
|
+
export declare function useAnyTableController<TData = any>({ tableRef, refresh, resetPagination, resetSearch, resetSorting, setPage, setPageSize, setSearch, setSorting, selectedRows, clearSelection, getState, scrollToIndex, }: UseAnyTableControllerParams<TData>): void;
|
|
@@ -9,9 +9,10 @@ export interface UseAnyTableDataParams<TData = any> {
|
|
|
9
9
|
sortOrder: SortDirection;
|
|
10
10
|
page: number;
|
|
11
11
|
pageSize: number;
|
|
12
|
+
paginationEnabled?: boolean;
|
|
12
13
|
manualLoading?: boolean;
|
|
13
14
|
}
|
|
14
|
-
export declare function useAnyTableData<TData = any>({ data: directData, api, columns, searchQuery, sortBy, sortOrder, page, pageSize, manualLoading, }: UseAnyTableDataParams<TData>): {
|
|
15
|
+
export declare function useAnyTableData<TData = any>({ data: directData, api, columns, searchQuery, sortBy, sortOrder, page, pageSize, paginationEnabled, manualLoading, }: UseAnyTableDataParams<TData>): {
|
|
15
16
|
rows: TData[];
|
|
16
17
|
totalRecords: number;
|
|
17
18
|
loading: boolean;
|
|
@@ -6,7 +6,7 @@ export interface UseAnyTableSelectionOptions<TData = any> {
|
|
|
6
6
|
export declare function useAnyTableSelection<TData = any>({ rows, rowKeyResolver, onSelectionChange, }: UseAnyTableSelectionOptions<TData>): {
|
|
7
7
|
selectedKeys: Set<string | number>;
|
|
8
8
|
setSelectedKeys: import('react').Dispatch<import('react').SetStateAction<Set<string | number>>>;
|
|
9
|
-
selectedRows: TData[];
|
|
9
|
+
selectedRows: NonNullable<TData>[];
|
|
10
10
|
onToggleSelectRow: (key: string | number, row: TData) => void;
|
|
11
11
|
handleToggleSelectAll: () => void;
|
|
12
12
|
clearSelection: () => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { VirtualizedConfig } from '../types/table.types';
|
|
3
|
+
export interface UseAnyTableVirtualizerParams {
|
|
4
|
+
config?: boolean | VirtualizedConfig;
|
|
5
|
+
totalCount: number;
|
|
6
|
+
scrollContainerRef: React.RefObject<HTMLDivElement | null>;
|
|
7
|
+
}
|
|
8
|
+
export interface UseAnyTableVirtualizerReturn {
|
|
9
|
+
isVirtualized: boolean;
|
|
10
|
+
totalHeight: number;
|
|
11
|
+
paddingTop: number;
|
|
12
|
+
paddingBottom: number;
|
|
13
|
+
startIndex: number;
|
|
14
|
+
endIndex: number;
|
|
15
|
+
rowHeight: number;
|
|
16
|
+
maxHeight: number | string;
|
|
17
|
+
scrollToIndex: (index: number, align?: "start" | "center" | "end" | "auto") => void;
|
|
18
|
+
sliceRows: <T>(rows: T[]) => T[];
|
|
19
|
+
}
|
|
20
|
+
export declare function useAnyTableVirtualizer({ config, totalCount, scrollContainerRef, }: UseAnyTableVirtualizerParams): UseAnyTableVirtualizerReturn;
|