simple-table-core 1.2.4 → 1.2.6

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.
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, MutableRefObject } from "react";
2
- import HeaderObject from "../../types/HeaderObject";
2
+ import HeaderObject, { Accessor } from "../../types/HeaderObject";
3
3
  import CellChangeProps from "../../types/CellChangeProps";
4
4
  import Theme from "../../types/Theme";
5
5
  import Row from "../../types/Row";
@@ -8,7 +8,7 @@ import TableRefType from "../../types/TableRefType";
8
8
  import OnNextPage from "../../types/OnNextPage";
9
9
  import "../../styles/simple-table.css";
10
10
  import { TableFilterState } from "../../types/FilterTypes";
11
- import { SortColumn } from "../../types/SortConfig";
11
+ import SortColumn from "../../types/SortColumn";
12
12
  interface SimpleTableProps {
13
13
  allowAnimations?: boolean;
14
14
  cellUpdateFlash?: boolean;
@@ -34,9 +34,9 @@ interface SimpleTableProps {
34
34
  onNextPage?: OnNextPage;
35
35
  onSortChange?: (sort: SortColumn | null) => void;
36
36
  prevIcon?: ReactNode;
37
- rowGrouping?: string[];
37
+ rowGrouping?: Accessor[];
38
38
  rowHeight?: number;
39
- rowIdAccessor: string;
39
+ rowIdAccessor: Accessor;
40
40
  rows: Row[];
41
41
  rowsPerPage?: number;
42
42
  selectableCells?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from "react";
2
- import { SortColumn } from "../../types/SortConfig";
2
+ import SortColumn from "../../types/SortColumn";
3
3
  import TableRow from "../../types/TableRow";
4
4
  interface TableContentLocalProps {
5
5
  pinnedLeftWidth: number;
@@ -1,5 +1,5 @@
1
1
  import HeaderObject from "../../types/HeaderObject";
2
- import { SortColumn } from "../../types/SortConfig";
2
+ import SortColumn from "../../types/SortColumn";
3
3
  interface HeaderCellProps {
4
4
  colIndex: number;
5
5
  gridColumnEnd: number;
@@ -1,4 +1,4 @@
1
- import HeaderObject from "../../../types/HeaderObject";
2
- export declare const findAndMarkParentsVisible: (headers: HeaderObject[], childAccessor: string, visited?: Set<string>) => void;
1
+ import HeaderObject, { Accessor } from "../../../types/HeaderObject";
2
+ export declare const findAndMarkParentsVisible: (headers: HeaderObject[], childAccessor: Accessor, visited?: Set<string>) => void;
3
3
  export declare const areAllChildrenHidden: (children: HeaderObject[]) => boolean;
4
4
  export declare const updateParentHeaders: (headers: HeaderObject[]) => void;
@@ -2,7 +2,7 @@ import { ReactNode, RefObject, MutableRefObject, Dispatch, SetStateAction } from
2
2
  import { TableFilterState, FilterCondition } from "../types/FilterTypes";
3
3
  import TableRow from "../types/TableRow";
4
4
  import Cell from "../types/Cell";
5
- import HeaderObject from "../types/HeaderObject";
5
+ import HeaderObject, { Accessor } from "../types/HeaderObject";
6
6
  import OnSortProps from "../types/OnSortProps";
7
7
  import Theme from "../types/Theme";
8
8
  import CellValue from "../types/CellValue";
@@ -23,7 +23,7 @@ interface TableContextType {
23
23
  getBorderClass: (cell: Cell) => string;
24
24
  handleApplyFilter: (filter: FilterCondition) => void;
25
25
  handleClearAllFilters: () => void;
26
- handleClearFilter: (accessor: string) => void;
26
+ handleClearFilter: (accessor: Accessor) => void;
27
27
  handleMouseDown: (cell: Cell) => void;
28
28
  handleMouseOver: (cell: Cell) => void;
29
29
  headerContainerRef: RefObject<HTMLDivElement>;
@@ -46,9 +46,9 @@ interface TableContextType {
46
46
  pinnedLeftRef: RefObject<HTMLDivElement>;
47
47
  pinnedRightRef: RefObject<HTMLDivElement>;
48
48
  prevIcon: ReactNode;
49
- rowGrouping?: string[];
49
+ rowGrouping?: Accessor[];
50
50
  rowHeight: number;
51
- rowIdAccessor: string;
51
+ rowIdAccessor: Accessor;
52
52
  scrollbarWidth: number;
53
53
  selectColumns?: (columnIndices: number[], isShiftKey?: boolean) => void;
54
54
  selectableColumns: boolean;
@@ -1,4 +1,4 @@
1
- import { SortColumn } from "../types/SortConfig";
1
+ import SortColumn from "../types/SortColumn";
2
2
  declare const useExternalSort: ({ sort, onSortChange, }: {
3
3
  sort: SortColumn | null;
4
4
  onSortChange?: ((sort: SortColumn | null) => void) | undefined;
@@ -1,5 +1,6 @@
1
1
  import { TableFilterState, FilterCondition } from "../types/FilterTypes";
2
2
  import Row from "../types/Row";
3
+ import { Accessor } from "../types/HeaderObject";
3
4
  interface UseFilterableDataProps {
4
5
  rows: Row[];
5
6
  externalFilterHandling: boolean;
@@ -8,7 +9,7 @@ interface UseFilterableDataProps {
8
9
  interface UseFilterableDataReturn {
9
10
  filteredRows: Row[];
10
11
  updateFilter: (filter: FilterCondition) => void;
11
- clearFilter: (accessor: string) => void;
12
+ clearFilter: (accessor: Accessor) => void;
12
13
  clearAllFilters: () => void;
13
14
  filters: TableFilterState;
14
15
  computeFilteredRowsPreview: (filter: FilterCondition) => Row[];
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import HeaderObject from "../types/HeaderObject";
2
+ import HeaderObject, { Accessor } from "../types/HeaderObject";
3
3
  import type TableRowType from "../types/TableRow";
4
4
  import Cell from "../types/Cell";
5
5
  export declare const createSetString: ({ rowIndex, colIndex, rowId }: Cell) => string;
@@ -7,7 +7,7 @@ interface UseSelectionProps {
7
7
  selectableCells: boolean;
8
8
  headers: HeaderObject[];
9
9
  tableRows: TableRowType[];
10
- rowIdAccessor: string;
10
+ rowIdAccessor: Accessor;
11
11
  onCellEdit?: (props: any) => void;
12
12
  cellRegistry?: Map<string, any>;
13
13
  }
@@ -1,6 +1,6 @@
1
- import HeaderObject from "../types/HeaderObject";
1
+ import HeaderObject, { Accessor } from "../types/HeaderObject";
2
2
  import Row from "../types/Row";
3
- import { SortColumn } from "../types/SortConfig";
3
+ import SortColumn from "../types/SortColumn";
4
4
  declare const useSortableData: ({ headers, tableRows, externalSortHandling, onSortChange, rowGrouping, }: {
5
5
  headers: HeaderObject[];
6
6
  tableRows: Row[];
@@ -10,7 +10,7 @@ declare const useSortableData: ({ headers, tableRows, externalSortHandling, onSo
10
10
  }) => {
11
11
  sort: SortColumn | null;
12
12
  sortedRows: Row[];
13
- updateSort: (accessor: string) => void;
14
- computeSortedRowsPreview: (accessor: string) => Row[];
13
+ updateSort: (accessor: Accessor) => void;
14
+ computeSortedRowsPreview: (accessor: Accessor) => Row[];
15
15
  };
16
16
  export default useSortableData;
@@ -1,10 +1,11 @@
1
1
  import { MutableRefObject } from "react";
2
2
  import { Row, TableRefType } from "..";
3
3
  import { CellRegistryEntry } from "../context/TableContext";
4
+ import { Accessor } from "../types/HeaderObject";
4
5
  declare const useTableAPI: ({ tableRef, rows, rowIdAccessor, cellRegistryRef, }: {
5
6
  tableRef?: MutableRefObject<TableRefType | null> | undefined;
6
7
  rows: Row[];
7
- rowIdAccessor: string;
8
+ rowIdAccessor: Accessor;
8
9
  cellRegistryRef: MutableRefObject<Map<string, CellRegistryEntry>>;
9
10
  }) => void;
10
11
  export default useTableAPI;
@@ -1,4 +1,6 @@
1
1
  import Row from "../types/Row";
2
+ import { Accessor } from "../types/HeaderObject";
3
+ import { FilterCondition } from "../types/FilterTypes";
2
4
  interface UseTableRowProcessingProps {
3
5
  allowAnimations: boolean;
4
6
  sortedRows: Row[];
@@ -6,22 +8,22 @@ interface UseTableRowProcessingProps {
6
8
  currentPage: number;
7
9
  rowsPerPage: number;
8
10
  shouldPaginate: boolean;
9
- rowGrouping?: string[];
10
- rowIdAccessor: string;
11
+ rowGrouping?: Accessor[];
12
+ rowIdAccessor: Accessor;
11
13
  unexpandedRows: Set<string>;
12
14
  expandAll: boolean;
13
15
  contentHeight: number;
14
16
  rowHeight: number;
15
17
  scrollTop: number;
16
- computeFilteredRowsPreview: (filter: any) => Row[];
17
- computeSortedRowsPreview: (accessor: string) => Row[];
18
+ computeFilteredRowsPreview: (filter: FilterCondition) => Row[];
19
+ computeSortedRowsPreview: (accessor: Accessor) => Row[];
18
20
  }
19
21
  declare const useTableRowProcessing: ({ allowAnimations, sortedRows, originalRows, currentPage, rowsPerPage, shouldPaginate, rowGrouping, rowIdAccessor, unexpandedRows, expandAll, contentHeight, rowHeight, scrollTop, computeFilteredRowsPreview, computeSortedRowsPreview, }: UseTableRowProcessingProps) => {
20
22
  currentTableRows: import("../types/TableRow").default[];
21
23
  currentVisibleRows: import("../types/TableRow").default[];
22
24
  isAnimating: boolean;
23
25
  prepareForFilterChange: (filter: any) => void;
24
- prepareForSortChange: (accessor: string) => void;
26
+ prepareForSortChange: (accessor: Accessor) => void;
25
27
  rowsToRender: any[];
26
28
  };
27
29
  export default useTableRowProcessing;
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import type { AggregationConfig, AggregationType } from "./types/AggregationType
11
11
  import type OnSortProps from "./types/OnSortProps";
12
12
  import type Row from "./types/Row";
13
13
  import type SharedTableProps from "./types/SharedTableProps";
14
- import type SortConfig from "./types/SortConfig";
14
+ import type SortColumn from "./types/SortColumn";
15
15
  import type TableCellProps from "./types/TableCellProps";
16
16
  import type TableHeaderProps from "./types/TableHeaderProps";
17
17
  import TableRefType from "./types/TableRefType";
@@ -20,4 +20,4 @@ import type Theme from "./types/Theme";
20
20
  import type UpdateDataProps from "./types/UpdateCellProps";
21
21
  import { FilterCondition, TableFilterState } from "./types/FilterTypes";
22
22
  export { SimpleTable };
23
- export type { AggregationConfig, AggregationType, BoundingBox, Cell, CellChangeProps, CellValue, ColumnEditorPosition, DragHandlerProps, EnumOption, FilterCondition, HeaderObject, OnSortProps, Row, SharedTableProps, SortConfig, TableCellProps, TableFilterState, TableHeaderProps, TableRefType, TableRowProps, Theme, UpdateDataProps, };
23
+ export type { AggregationConfig, AggregationType, BoundingBox, Cell, CellChangeProps, CellValue, ColumnEditorPosition, DragHandlerProps, EnumOption, FilterCondition, HeaderObject, OnSortProps, Row, SharedTableProps, SortColumn, TableCellProps, TableFilterState, TableHeaderProps, TableRefType, TableRowProps, Theme, UpdateDataProps, };
@@ -1,7 +1,8 @@
1
1
  import CellValue from "./CellValue";
2
+ import { Accessor } from "./HeaderObject";
2
3
  import Row from "./Row";
3
4
  type CellChangeProps = {
4
- accessor: string;
5
+ accessor: Accessor;
5
6
  newValue: CellValue;
6
7
  row: Row;
7
8
  };
@@ -1,4 +1,5 @@
1
1
  import CellValue from "./CellValue";
2
+ import { Accessor } from "./HeaderObject";
2
3
  export type StringFilterOperator = "equals" | "notEquals" | "contains" | "notContains" | "startsWith" | "endsWith" | "isEmpty" | "isNotEmpty";
3
4
  export type NumberFilterOperator = "equals" | "notEquals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "between" | "notBetween" | "isEmpty" | "isNotEmpty";
4
5
  export type BooleanFilterOperator = "equals" | "isEmpty" | "isNotEmpty";
@@ -6,13 +7,13 @@ export type DateFilterOperator = "equals" | "notEquals" | "before" | "after" | "
6
7
  export type EnumFilterOperator = "in" | "notIn" | "isEmpty" | "isNotEmpty";
7
8
  export type FilterOperator = StringFilterOperator | NumberFilterOperator | BooleanFilterOperator | DateFilterOperator | EnumFilterOperator;
8
9
  export interface FilterCondition {
9
- accessor: string;
10
+ accessor: Accessor;
10
11
  operator: FilterOperator;
11
12
  value?: CellValue;
12
13
  values?: CellValue[];
13
14
  }
14
15
  export interface TableFilterState {
15
- [accessor: string]: FilterCondition;
16
+ [accessor: Accessor]: FilterCondition;
16
17
  }
17
18
  export declare const FILTER_OPERATOR_LABELS: Record<FilterOperator, string>;
18
19
  export declare const getAvailableOperators: (columnType: "string" | "number" | "boolean" | "date" | "enum") => FilterOperator[];
@@ -4,12 +4,13 @@ import { Pinned } from "./Pinned";
4
4
  import Theme from "./Theme";
5
5
  import EnumOption from "./EnumOption";
6
6
  import { AggregationConfig } from "./AggregationTypes";
7
+ export type Accessor = keyof Row;
7
8
  type HeaderObject = {
8
- accessor: string;
9
+ accessor: Accessor;
9
10
  aggregation?: AggregationConfig;
10
11
  align?: "left" | "center" | "right";
11
12
  cellRenderer?: ({ accessor, colIndex, row, }: {
12
- accessor: string;
13
+ accessor: Accessor;
13
14
  colIndex: number;
14
15
  row: Row;
15
16
  theme: Theme;
@@ -20,7 +21,7 @@ type HeaderObject = {
20
21
  expandable?: boolean;
21
22
  filterable?: boolean;
22
23
  headerRenderer?: ({ accessor, colIndex, header, }: {
23
- accessor: string;
24
+ accessor: Accessor;
24
25
  colIndex: number;
25
26
  header: HeaderObject;
26
27
  }) => ReactNode | string;
@@ -1,2 +1,3 @@
1
- type OnSortProps = (accessor: string) => void;
1
+ import { Accessor } from "./HeaderObject";
2
+ type OnSortProps = (accessor: Accessor) => void;
2
3
  export default OnSortProps;
@@ -0,0 +1,6 @@
1
+ import HeaderObject from "./HeaderObject";
2
+ type SortColumn = {
3
+ key: HeaderObject;
4
+ direction: "ascending" | "descending";
5
+ };
6
+ export default SortColumn;
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from "react";
2
- import { SortColumn } from "./SortConfig";
2
+ import SortColumn from "./SortColumn";
3
3
  import HeaderObject from "./HeaderObject";
4
4
  type TableHeaderProps = {
5
5
  centerHeaderRef: RefObject<HTMLDivElement>;
@@ -1,6 +1,6 @@
1
1
  import { UIEventHandler } from "react";
2
2
  import { Pinned } from "./Pinned";
3
- import { SortColumn } from "./SortConfig";
3
+ import SortColumn from "./SortColumn";
4
4
  import { HeaderObject } from "..";
5
5
  import { RefObject } from "react";
6
6
  import { ColumnIndices } from "../utils/columnIndicesUtils";
@@ -1,6 +1,7 @@
1
1
  import { CellValue } from "..";
2
+ import { Accessor } from "./HeaderObject";
2
3
  type UpdateDataProps = {
3
- accessor: string;
4
+ accessor: Accessor;
4
5
  rowIndex: number;
5
6
  newValue: CellValue;
6
7
  };
@@ -1,8 +1,8 @@
1
- import HeaderObject from "../types/HeaderObject";
1
+ import HeaderObject, { Accessor } from "../types/HeaderObject";
2
2
  import { Pinned } from "../types/Pinned";
3
3
  import { RowId } from "../types/RowId";
4
4
  export declare const getCellId: ({ accessor, rowId }: {
5
- accessor: string;
5
+ accessor: Accessor;
6
6
  rowId: RowId;
7
7
  }) => string;
8
8
  export declare const displayCell: ({ header, pinned }: {
@@ -11,5 +11,5 @@ export declare const displayCell: ({ header, pinned }: {
11
11
  }) => true | null;
12
12
  export declare const getCellKey: ({ rowId, accessor }: {
13
13
  rowId: RowId;
14
- accessor: string;
14
+ accessor: Accessor;
15
15
  }) => string;
@@ -1,6 +1,7 @@
1
1
  import TableRow from "../types/TableRow";
2
2
  import Row from "../types/Row";
3
3
  import { RowId } from "../types/RowId";
4
+ import { Accessor } from "../types/HeaderObject";
4
5
  /**
5
6
  * Check if an array contains Row objects (vs primitive arrays like string[] or number[])
6
7
  */
@@ -10,7 +11,7 @@ export declare const isRowArray: (data: any) => data is Row[];
10
11
  */
11
12
  export declare const getRowId: ({ row, rowIdAccessor }: {
12
13
  row: Row;
13
- rowIdAccessor: string;
14
+ rowIdAccessor: Accessor;
14
15
  }) => RowId;
15
16
  /**
16
17
  * Get nested rows from a row based on the grouping path
@@ -29,6 +30,6 @@ export declare const flattenRowsWithGrouping: ({ depth, expandAll, unexpandedRow
29
30
  expandAll?: boolean | undefined;
30
31
  unexpandedRows: Set<string>;
31
32
  rowGrouping?: string[] | undefined;
32
- rowIdAccessor: string;
33
+ rowIdAccessor: Accessor;
33
34
  rows: Row[];
34
35
  }) => TableRow[];
@@ -1,6 +1,6 @@
1
1
  import HeaderObject from "../types/HeaderObject";
2
- import { SortColumn } from "../types/SortConfig";
3
2
  import Row from "../types/Row";
3
+ import SortColumn from "../types/SortColumn";
4
4
  export declare const handleSort: ({ headers, rows, sortColumn, }: {
5
5
  headers: HeaderObject[];
6
6
  rows: Row[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.4",
2
+ "version": "1.2.6",
3
3
  "main": "dist/index.js",
4
4
  "module": "dist/index.es.js",
5
5
  "types": "dist/index.d.ts",
@@ -1,11 +0,0 @@
1
- import HeaderObject from "./HeaderObject";
2
- export type SortColumn = {
3
- key: HeaderObject;
4
- direction: "ascending" | "descending";
5
- };
6
- type SortConfig = {
7
- previous: SortColumn | null;
8
- current: SortColumn | null;
9
- next: SortColumn | null;
10
- };
11
- export default SortConfig;