@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 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 & 19) & TypeScript with 3-Tier API auto-detection, dynamic column extraction, autonomous server/client search, sorting & pagination, interactive row actions with instant PATCH switches, and zero business logic coupling.**
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
  [![npm version](https://img.shields.io/npm/v/@kareemelbalshe/any-table.svg)](https://npmjs.org/package/@kareemelbalshe/any-table)
6
6
  [![Live Demo](https://img.shields.io/badge/Live%20Demo-Online-brightgreen?logo=react)](https://kareemelbalshe.github.io/anyTable/)
7
7
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-Strict%205.0%2B-blue)](https://www.typescriptlang.org/)
9
- [![React](https://img.shields.io/badge/React-18%20%7C%2019-61dafb)](https://react.dev/)
10
- [![Tests](https://img.shields.io/badge/Tests-46%20Passed-success)](https://vitest.dev/)
9
+ [![React](https://img.shields.io/badge/React-16.8%2B%20%7C%2017%20%7C%2018%20%7C%2019-61dafb)](https://react.dev/)
10
+ [![Dependencies](https://img.shields.io/badge/Dependencies-0%20(Zero)-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 react-icons
70
+ npm install @kareemelbalshe/any-table
68
71
 
69
72
  # Using Yarn
70
- yarn add @kareemelbalshe/any-table react-icons
73
+ yarn add @kareemelbalshe/any-table
71
74
 
72
75
  # Using PNPM
73
- pnpm add @kareemelbalshe/any-table react-icons
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
- tableRef={tableRef}
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: Ø§Ų„ØĒØ­Ø¯ŲŠØ¯ Ø§Ų„Ų…ØĒؚدد ŲˆØ§Ų„ØšŲ…Ų„ŲŠØ§ØĒ Ø§Ų„ØŦŲ…Ø§ØšŲŠØŠ (Batch Operations)
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 function AnyTable<TData = any>(props: AnyTableProps<TData>): React.JSX.Element;
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 const TableBody: React.FC<TableBodyProps>;
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 const ConfirmModal: React.FC<ConfirmModalProps>;
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 const TableEmptyState: React.FC<TableEmptyStateProps>;
9
+ export declare function TableEmptyState({ title, description, isSearchActive, onClearSearch, colSpan, }: TableEmptyStateProps): React.JSX.Element;
@@ -3,4 +3,4 @@ export interface TableErrorStateProps {
3
3
  error: any;
4
4
  onRetry?: () => void;
5
5
  }
6
- export declare const TableErrorState: React.FC<TableErrorStateProps>;
6
+ export declare function TableErrorState({ error, onRetry }: TableErrorStateProps): 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 const TableHeader: React.FC<TableHeaderProps>;
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 const TablePagination: React.FC<TablePaginationProps>;
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 const TableSearch: React.FC<TableSearchProps>;
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 const TableSkeleton: React.FC<TableSkeletonProps>;
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 const TableToolbar: React.FC<TableToolbarProps>;
16
+ export declare function TableToolbar({ displayTitle, subtitle, isSearchEnabled, searchQuery, setSearch, clearSearch, isDebouncing, searchPlaceholder, headerActions, add, linkAdd, addHandler, }: TableToolbarProps): React.JSX.Element | null;
@@ -4,3 +4,4 @@ export * from './useAnyTablePagination';
4
4
  export * from './useAnyTableData';
5
5
  export * from './useAnyTableController';
6
6
  export * from './useAnyTableSelection';
7
+ export * from './useAnyTableVirtualizer';
@@ -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;