@react-fabric/data 1.0.0-beta.6 → 1.0.0-beta.61

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.
Files changed (104) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/{dist/esm/tree/types.js → css/styles.css} +2 -7
  3. package/dist/cjs/checklist/CheckList.js +27 -4
  4. package/dist/cjs/histogram/Histogram.js +39 -9
  5. package/dist/cjs/hooks/useFilteredList.js +88 -10
  6. package/dist/cjs/hooks/usePagination.js +27 -4
  7. package/dist/cjs/hooks/useSelectableList.js +29 -0
  8. package/dist/cjs/i18n/ar.json.js +8 -1
  9. package/dist/cjs/i18n/en.json.js +8 -1
  10. package/dist/cjs/json/JsonViewer.js +68 -28
  11. package/dist/cjs/pagination/Pagination.js +14 -4
  12. package/dist/cjs/table/AddColumn.js +3 -3
  13. package/dist/cjs/table/BodyCell.js +14 -6
  14. package/dist/cjs/table/BodyRow.js +4 -4
  15. package/dist/cjs/table/CheckboxCell.js +2 -2
  16. package/dist/cjs/table/ColumnFilters.js +97 -0
  17. package/dist/cjs/table/HeaderCell.js +71 -43
  18. package/dist/cjs/table/Table.js +62 -13
  19. package/dist/cjs/table/types.js +29 -0
  20. package/dist/cjs/table/useResizer.js +4 -4
  21. package/dist/cjs/table/useVirtualTable.js +127 -19
  22. package/dist/cjs/tree/TreeNode.js +50 -32
  23. package/dist/cjs/tree/TreePanel.js +52 -19
  24. package/dist/cjs/tree/useTree.js +199 -38
  25. package/dist/cjs/tree/utils.js +39 -12
  26. package/dist/cjs/virtual/Gallery.js +97 -45
  27. package/dist/cjs/virtual/List.js +93 -39
  28. package/dist/cjs/virtual/Scroller.js +16 -8
  29. package/dist/esm/checklist/CheckList.js +28 -5
  30. package/dist/esm/histogram/Histogram.js +41 -11
  31. package/dist/esm/hooks/useFilteredList.js +89 -11
  32. package/dist/esm/hooks/usePagination.js +27 -4
  33. package/dist/esm/hooks/useSelectableList.js +29 -0
  34. package/dist/esm/i18n/ar.json.js +8 -2
  35. package/dist/esm/i18n/en.json.js +8 -2
  36. package/dist/esm/json/JsonViewer.js +69 -29
  37. package/dist/esm/pagination/Pagination.js +15 -5
  38. package/dist/esm/table/AddColumn.js +4 -4
  39. package/dist/esm/table/BodyCell.js +15 -7
  40. package/dist/esm/table/BodyRow.js +4 -4
  41. package/dist/esm/table/CheckboxCell.js +3 -3
  42. package/dist/esm/table/ColumnFilters.js +97 -0
  43. package/dist/esm/table/HeaderCell.js +72 -44
  44. package/dist/esm/table/Table.js +63 -14
  45. package/dist/esm/table/types.js +29 -0
  46. package/dist/esm/table/useResizer.js +4 -4
  47. package/dist/esm/table/useVirtualTable.js +129 -21
  48. package/dist/esm/tree/TreeNode.js +53 -35
  49. package/dist/esm/tree/TreePanel.js +54 -21
  50. package/dist/esm/tree/useTree.js +202 -41
  51. package/dist/esm/tree/utils.js +40 -13
  52. package/dist/esm/virtual/Gallery.js +97 -45
  53. package/dist/esm/virtual/List.js +93 -39
  54. package/dist/esm/virtual/Scroller.js +17 -9
  55. package/dist/types/checklist/CheckList.d.ts +22 -0
  56. package/dist/types/histogram/Histogram.d.ts +28 -1
  57. package/dist/types/hooks/useFilteredList.d.ts +66 -5
  58. package/dist/types/hooks/usePagination.d.ts +19 -0
  59. package/dist/types/hooks/useSelectableList.d.ts +29 -0
  60. package/dist/types/json/JsonViewer.d.ts +27 -2
  61. package/dist/types/pagination/Pagination.d.ts +10 -1
  62. package/dist/types/table/ColumnFilters.d.ts +9 -0
  63. package/dist/types/table/HeaderCell.d.ts +1 -1
  64. package/dist/types/table/Table.d.ts +14 -1
  65. package/dist/types/table/types.d.ts +46 -7
  66. package/dist/types/table/useVirtualTable.d.ts +23 -9
  67. package/dist/types/tree/TreeNode.d.ts +1 -1
  68. package/dist/types/tree/TreePanel.d.ts +42 -1
  69. package/dist/types/tree/types.d.ts +65 -21
  70. package/dist/types/tree/useTree.d.ts +9 -10
  71. package/dist/types/tree/utils.d.ts +10 -3
  72. package/dist/types/virtual/Gallery.d.ts +42 -3
  73. package/dist/types/virtual/List.d.ts +42 -3
  74. package/package.json +16 -14
  75. package/src/checklist/CheckList.tsx +39 -7
  76. package/src/histogram/Histogram.tsx +43 -19
  77. package/src/hooks/useFilteredList.tsx +109 -9
  78. package/src/hooks/usePagination.tsx +32 -7
  79. package/src/hooks/useSelectableList.ts +29 -0
  80. package/src/i18n/ar.json +5 -0
  81. package/src/i18n/en.json +5 -0
  82. package/src/json/JsonViewer.tsx +76 -37
  83. package/src/pagination/Pagination.tsx +15 -5
  84. package/src/table/AddColumn.tsx +4 -4
  85. package/src/table/BodyCell.tsx +24 -7
  86. package/src/table/BodyRow.tsx +7 -4
  87. package/src/table/CheckboxCell.tsx +5 -5
  88. package/src/table/ColumnFilters.tsx +105 -0
  89. package/src/table/HeaderCell.tsx +74 -21
  90. package/src/table/Table.tsx +107 -12
  91. package/src/table/types.ts +49 -10
  92. package/src/table/useResizer.ts +5 -3
  93. package/src/table/useVirtualTable.ts +158 -27
  94. package/src/tree/TreeNode.tsx +96 -62
  95. package/src/tree/TreePanel.tsx +88 -22
  96. package/src/tree/types.ts +73 -23
  97. package/src/tree/useTree.ts +220 -44
  98. package/src/tree/utils.ts +58 -20
  99. package/src/virtual/Gallery.tsx +118 -54
  100. package/src/virtual/List.tsx +99 -39
  101. package/src/virtual/Scroller.tsx +25 -9
  102. package/dist/cjs/histogram/Histogram.module.css +0 -1
  103. package/dist/cjs/tree/types.js +0 -30
  104. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -1,7 +1,68 @@
1
- /// <reference types="react" />
2
- export declare const useFilteredList: <T extends unknown = KeyValue<any>, Q extends unknown = string>(items: T[], matcher?: (item: T, query: Q) => boolean) => {
3
- onSearch: import("react").Dispatch<import("react").SetStateAction<Q | undefined>>;
4
- query: Q | undefined;
1
+ interface RetType<T, Q> {
2
+ onSearch: (query?: Q) => void;
3
+ query: Q;
5
4
  filteredList: T[];
6
5
  isSearching: boolean;
7
- };
6
+ }
7
+ /**
8
+ * Custom hook to filter a list of items based on a query.
9
+ * It provides a way to search through the items and returns the filtered list.
10
+ * The hook uses a deferred value to optimize performance during transitions.
11
+ * It also allows for a custom matcher function to define how items should be matched against the query.
12
+ *
13
+ * @param items - The list of items to filter.
14
+ * @param matchAll - Match all phrases in the query list against the items.
15
+ * @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
16
+ *
17
+ * @example
18
+ * ```jsx
19
+ * useFilteredList(items, (item, query) => {
20
+ * return item.name.includes(query);
21
+ * });
22
+ * ```
23
+ *
24
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
25
+ */
26
+ export declare function useFilteredList<T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matchAll?: boolean): RetType<T, Q>;
27
+ /**
28
+ * Custom hook to filter a list of items based on a query.
29
+ * It provides a way to search through the items and returns the filtered list.
30
+ * The hook uses a deferred value to optimize performance during transitions.
31
+ * It also allows for a custom matcher function to define how items should be matched against the query.
32
+ *
33
+ * @param items - The list of items to filter.
34
+ * @param matcher - An optional function to match items against the query.
35
+ * @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
36
+ *
37
+ * @example
38
+ * ```jsx
39
+ * useFilteredList(items, (item, query) => {
40
+ * return item.name.includes(query);
41
+ * });
42
+ * ```
43
+ *
44
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
45
+ */
46
+ export declare function useFilteredList<T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matcher?: (item: T, query: Q) => boolean): RetType<T, Q>;
47
+ /**
48
+ * Custom hook to filter a list of items based on a query.
49
+ * It provides a way to search through the items and returns the filtered list.
50
+ * The hook uses a deferred value to optimize performance during transitions.
51
+ * It also allows for a custom matcher function to define how items should be matched against the query.
52
+ *
53
+ * @param items - The list of items to filter.
54
+ * @param matchAll - Match all phrases in the query list against the items.
55
+ * @param matcher - An optional function to match items against the query.
56
+ * @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
57
+ *
58
+ * @example
59
+ * ```jsx
60
+ * useFilteredList(items, (item, query) => {
61
+ * return item.name.includes(query);
62
+ * });
63
+ * ```
64
+ *
65
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
66
+ */
67
+ export declare function useFilteredList<T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matchAll?: boolean, matcher?: (item: T, query: Q) => boolean): RetType<T, Q>;
68
+ export {};
@@ -16,6 +16,25 @@ export interface PaginationOptions {
16
16
  */
17
17
  onChange?: (page: number) => void;
18
18
  }
19
+ /**
20
+ * Custom hook to manage pagination state and logic.
21
+ * It calculates the total number of pages, generates page ranges,
22
+ * and provides a way to change the current page.
23
+ * It also handles the transition of page changes to optimize performance.
24
+ *
25
+ * @param options - The pagination options including total records, current page, records per page, and change handler.
26
+ * @returns An object containing the current page, total pages, head label, ranges for pagination pills, and a function to change the page.
27
+ *
28
+ * @example
29
+ * ```jsx
30
+ * const { page, totalPages, headLabel, ranges, onPageChange } = usePagination({
31
+ * totalRecords: 100,
32
+ * currentPage: 0,
33
+ * perPage: 10,
34
+ * onChange: (newPage) => console.log("Page changed to:", newPage),
35
+ * });
36
+ * ```
37
+ */
19
38
  export declare const usePagination: ({ totalRecords, currentPage, perPage, onChange, }: PaginationOptions) => {
20
39
  page: number;
21
40
  totalPages: number;
@@ -22,6 +22,35 @@ export interface SelectableProps {
22
22
  */
23
23
  onClick?: (id: string, isNegative: boolean) => void;
24
24
  }
25
+ /**
26
+ * Custom hook to manage selection of items in a list.
27
+ * It allows toggling selection state of items, handling both selected and non-selected states.
28
+ * The hook maintains a selection state and provides a function to toggle the selection of items.
29
+ * It also supports callbacks for when the selection changes or when an item is clicked.
30
+ *
31
+ * @param items - The list of items to manage selection for.
32
+ * @param selected - An array of item IDs that are currently selected.
33
+ * @param nonselected - An array of item IDs that are currently non-selected.
34
+ * @param onChange - Callback function that is called when the selection changes.
35
+ * @param onClick - Callback function that is called when an item is clicked.
36
+ * @returns An object containing the current selection state and a function to toggle selection of items.
37
+ *
38
+ * @example
39
+ * ```jsx
40
+ * const { selection, toggleSelection } = useSelectableList({
41
+ * items: [{ id: '1', label: 'Item 1' }, { id: '2', label: 'Item 2' }],
42
+ * selected: ['1'],
43
+ * nonselected: ['2'],
44
+ * onChange: (selectedIds, nonSelectedIds) => {
45
+ * console.log('Selected:', selectedIds);
46
+ * console.log('Non-selected:', nonSelectedIds);
47
+ * },
48
+ * onClick: (id, isNegative) => {
49
+ * console.log(`Item ${id} clicked, isNegative: ${isNegative}`);
50
+ * },
51
+ * });
52
+ * ```
53
+ */
25
54
  export declare const useSelectableList: ({ items, selected, nonselected, onChange, onClick, }: SelectableProps) => {
26
55
  selection: KeyValue<number>;
27
56
  toggleSelection: (id: string, isNegative?: boolean) => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type CssProp } from "@react-fabric/core/dist/types/types";
3
2
  export interface JsonViewProps<T> extends CssProp {
4
3
  /**
@@ -56,4 +55,30 @@ export interface JsonViewProps<T> extends CssProp {
56
55
  */
57
56
  formatter?: (path?: string, value?: AnyObject) => string | JSX.Element | undefined;
58
57
  }
59
- export declare const JsonViewer: <T extends KeyValue<any> = KeyValue<any>>({ className, json, copy, propertyScheme, filters, inline, labelWidth, formatter, labeler, onFilter, emptyMessage, showPropertyTree, ...rest }: JsonViewProps<T>) => import("react/jsx-runtime").JSX.Element;
58
+ /**
59
+ * JsonViewer component to display JSON data in a structured format.
60
+ * It supports inline display, property filtering, and custom formatting.
61
+ * The component can handle nested objects and arrays, displaying them in a tree-like structure.
62
+ * It also provides options for copying values and filtering properties.
63
+ *
64
+ * @param {JsonViewProps<T>} props - The properties for the JsonViewer component.
65
+ * @returns {JSX.Element} The rendered JsonViewer component.
66
+ *
67
+ * @example
68
+ * ```jsx
69
+ * <JsonViewer
70
+ * json={{ name: "John", age: 30, address: { city: "New York", zip: "10001" } }}
71
+ * copy={true}
72
+ * filters={true}
73
+ * propertyScheme={{ date: ["createdAt"], phone: ["contact"] }}
74
+ * inline={true}
75
+ * labelWidth="25%"
76
+ * formatter={(path, value) => (path === "age" ? `${value} years` : value)}
77
+ * labeler={(path) => path.replace(/_/g, " ").toUpperCase()}
78
+ * onFilter={(path, value, negate) => console.log(`Filter ${negate ? "negate" : ""} on ${path}:`, value)}
79
+ * />
80
+ * ```
81
+ *
82
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-jsonviewer--docs}
83
+ */
84
+ export declare const JsonViewer: <T extends KeyValue = KeyValue>({ className, json, copy, propertyScheme, filters, inline, labelWidth, formatter, labeler, onFilter, emptyMessage, showPropertyTree, ...rest }: JsonViewProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export interface PaginationProps {
3
2
  /**
4
3
  * currrent page number
@@ -21,4 +20,14 @@ export interface PaginationProps {
21
20
  */
22
21
  onPageChange: (page: number) => void;
23
22
  }
23
+ /**
24
+ * Pagination component to navigate through pages of data.
25
+ * It displays buttons for navigating to the first, previous, next, and last pages,
26
+ * as well as buttons for specific page numbers based on the provided ranges.
27
+ * The component supports a minimal view that shows the current page and total pages.
28
+ * It uses memoization to optimize rendering performance.
29
+ *
30
+ * @param {PaginationProps} props - The properties for the Pagination component.
31
+ * @returns {JSX.Element} The rendered Pagination component.
32
+ */
24
33
  export declare const Pagination: import("react").MemoExoticComponent<({ page, ranges, totalPages, minimal, onPageChange }: PaginationProps) => import("react/jsx-runtime").JSX.Element>;
@@ -0,0 +1,9 @@
1
+ import { type TableColumn } from "./types";
2
+ interface FilterProps {
3
+ type: TableColumn["dataType"];
4
+ onFilter: (value: AnyObject) => void;
5
+ list?: AnyObject[];
6
+ filter: AnyObject;
7
+ }
8
+ export declare const ColumnFilters: ({ type, list, filter, onFilter, }: FilterProps) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -1,2 +1,2 @@
1
1
  import { type TableColumn, type TableProps } from "./types";
2
- export declare const HeaderCell: ({ id, label, icon, iconBg, iconColor, rtlFlip, actions, locked, tooltip, sortable, resizable, width: _width, maxWidth, minWidth, sort, onSort, }: TableColumn & Pick<TableProps, "sort" | "onSort">) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const HeaderCell: ({ id, field, dataType, label, icon, actions, locked, filter, filterable, filterOptions, tooltip, sortable, resizable, width: _width, maxWidth, minWidth, sort, onSort, onFilter, }: TableColumn & Pick<TableProps, "sort" | "onSort" | "onFilter">) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,15 @@
1
1
  import { type TableProps } from "./types";
2
- export declare const Table: <T extends KeyValue<any> = KeyValue<any>>({ ref, data, columns, keyProperty, checkableRows, initialScroll, hideableColumns, sort, loading, emptyDisplay, canExpand, children, onSort, onScroll, onRowClick, onCheckedChanged, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ /**
3
+ * Table component for displaying data in a tabular format with features like sorting, filtering, and virtual scrolling.
4
+ * It supports expandable rows, checkable rows, and customizable columns.
5
+ * The component is designed to handle large datasets efficiently by rendering only the visible rows.
6
+ * It also provides a way to manage column visibility and allows for custom rendering of group headers.
7
+ * Uses TanStack's `useVirtual` for virtualization and React's `useMemo` for performance optimization.
8
+ *
9
+ * @param {TableProps<T>} props - The properties for the Table component.
10
+ * @returns {JSX.Element} The rendered Table component.
11
+ *
12
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/data-table--table}
13
+ * @see {@link https://tanstack.com/table/v8/docs/api/virtual}
14
+ */
15
+ export declare const Table: <T extends KeyValue = KeyValue>({ ref, data, columns, keyProperty, groupProperty, checkableRows, initialScroll, hideableColumns, sort, loading, checked, emptyDisplay, groupRenderer, canExpand, children, onSort, onFilter, onScroll, onRowClick, onCheckedChanged, total, onLoadMore, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,21 +1,54 @@
1
- import { type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
1
+ import { type IconProps } from "@react-fabric/core/dist/types/components/icon/Icon";
2
+ import { type CssProp, type Elements, type NestedKeys, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
2
3
  import { type ReactElement } from "react";
3
4
  export declare const COL_MIN_WIDTH = "3rem";
4
5
  export declare const COL_MAX_WIDTH = "64rem";
5
6
  export declare const COL_DEFAULT_WIDTH = "12rem";
6
- export interface TableColumn<T = KeyValue> extends CssProp, IconProps, TestProps {
7
- id: keyof T | string;
7
+ /**
8
+ * TableColumn interface defines the structure of a column in a table.
9
+ * It includes properties for column identification, display options, alignment,
10
+ * visibility, resizing, sorting, filtering, and rendering.
11
+ *
12
+ * @template T - The type of data the column will represent, defaulting to KeyValue.
13
+ * @property {keyof T | string} id - Unique identifier for the column.
14
+ * @property {"string" | "number" | "boolean" | "datetime" | "date" | "time" | "unknown"} [dataType] - Data type of the column values.
15
+ * @property {string} [label] - Display label for the column header.
16
+ * @property {string} [tooltip] - Tooltip text for the column header.
17
+ * @property {string} [format] - Format string for displaying the column values.
18
+ * @property {"start" | "center" | "end"} [align] - Text alignment within the column.
19
+ * @property {"start" | "end"} [locked] - Indicates if the column is locked at the start or end.
20
+ * @property {boolean} [hidden] - Whether the column is hidden.
21
+ * @property {boolean} [truncate] - Whether to truncate the text in the column.
22
+ * @property {boolean} [hideable] - Whether the column can be hidden by the user.
23
+ * @property {boolean} [resizable] - Whether the column can be resized by the user.
24
+ * @property {boolean} [sortable] - Whether the column can be sorted.
25
+ * @property {boolean} [filterable] - Whether the column can be filtered.
26
+ * @property {AnyObject} [filter] - Filter criteria for the column.
27
+ * @property {ReactElement[]} [actions] - Array of action elements to be displayed in the column.
28
+ * @property {AnyObject[]} [filterOptions] - Options for filtering the column.
29
+ * @property {string | number} [width] - Width of the column.
30
+ * @property {string | number} [minWidth] - Minimum width of the column.
31
+ * @property {string | number} [maxWidth] - Maximum width of the column.
32
+ * @property {KeyValue} [valueMap] - Mapping of values for the column.
33
+ * @property {(value: AnyObject, data: T, index: number) => Elements<AnyObject>} [renderer] - Custom renderer function for the column values.
34
+ */
35
+ export interface TableColumn<T = KeyValue> extends CssProp, TestProps {
36
+ id: NestedKeys<T>;
37
+ field?: string;
8
38
  label?: string;
9
39
  tooltip?: string;
10
- actions?: ReactElement;
40
+ icon?: IconProps;
41
+ actions?: ReactElement[];
11
42
  align?: "start" | "center" | "end";
12
43
  locked?: "start" | "end";
13
44
  hidden?: boolean;
45
+ truncate?: boolean;
14
46
  hideable?: boolean;
15
47
  resizable?: boolean;
16
48
  sortable?: boolean;
17
49
  filterable?: boolean;
18
- filterList?: AnyObject[];
50
+ filter?: AnyObject;
51
+ filterOptions?: AnyObject[];
19
52
  width?: string | number;
20
53
  minWidth?: string | number;
21
54
  maxWidth?: string | number;
@@ -32,13 +65,16 @@ export interface TableRef {
32
65
  export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
33
66
  columns: Array<TableColumn<T>>;
34
67
  data: T[];
35
- keyProperty?: keyof T;
68
+ keyProperty?: NestedKeys<T>;
69
+ groupProperty?: NestedKeys<T>;
70
+ groupRenderer?: (key: AnyObject) => ReactElement;
36
71
  emptyDisplay?: ReactElement;
37
72
  /**
38
73
  * checkable rows
39
74
  */
75
+ checked?: AnyObject[];
40
76
  checkableRows?: boolean;
41
- onCheckedChanged?: (rows: Array<keyof T>) => void;
77
+ onCheckedChanged?: (rows: AnyObject[]) => void;
42
78
  /**
43
79
  * sorting
44
80
  */
@@ -57,4 +93,7 @@ export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
57
93
  onScroll?: (firstItem: number) => void;
58
94
  canExpand?: (record: T) => boolean;
59
95
  children?: (record: T) => Elements<AnyObject>;
96
+ onFilter?: (id: NestedKeys<T> | string, value?: AnyObject) => void;
97
+ total?: number;
98
+ onLoadMore?: (lastIndex?: number) => void;
60
99
  }
@@ -1,18 +1,32 @@
1
- /// <reference types="react" />
2
- interface DataState {
3
- expanded: Key[];
4
- checked: Key[];
1
+ interface DataState<T = KeyValue> {
2
+ data: T[];
3
+ items: T[];
4
+ grouped: KeyValue<T[]>;
5
+ groups: AnyObject[];
6
+ expanded: AnyObject[];
7
+ checked: AnyObject[];
5
8
  allChecked: 0 | 1 | 2;
6
9
  }
7
- export declare const useVirtualTable: (data: KeyValue[], keyProperty?: Key, onCheckChanged?: (checked: Key[]) => void) => {
8
- scrollerRef: import("react").RefObject<HTMLDivElement>;
9
- items: import("@tanstack/virtual-core").VirtualItem<Element>[];
10
- checkState: DataState;
11
- getData: (index: number) => KeyValue<any>;
10
+ export declare const useVirtualTable: <T extends KeyValue = KeyValue>(data: T[], options: {
11
+ checked?: AnyObject[];
12
+ keyProperty: keyof T;
13
+ groupProperty?: keyof T;
14
+ loading?: boolean;
15
+ total: number;
16
+ onLoadMore?: (startIndex: number) => void;
17
+ onCheckChanged?: (checked: AnyObject[]) => void;
18
+ }) => {
19
+ scrollerRef: import("react").RefObject<HTMLDivElement | null>;
20
+ items: import("@tanstack/virtual-core").VirtualItem[];
21
+ checkState: DataState<T>;
22
+ getData: (index: number) => T;
12
23
  virtualizer: import("@tanstack/virtual-core").Virtualizer<HTMLDivElement, Element>;
24
+ hasActiveSticky: boolean;
25
+ isActiveSticky: (index: number) => boolean;
13
26
  top: number | undefined;
14
27
  totalSize: () => number;
15
28
  measureElement: (node: Element | null | undefined) => void;
29
+ toggleGroupExpand: (key: Key) => void;
16
30
  toggleExpand: (key: Key) => void;
17
31
  toggleChecked: (key: Key) => void;
18
32
  toggleAllChecked: () => void;
@@ -1,2 +1,2 @@
1
1
  import { type TreeNodeProps } from "./types";
2
- export declare const TreeNode: ({ node, noLines, expanders, checkable, selectable, defaultLeafIcon, defaultNodeIcon, onToggle, onSelect, onChecked, children, }: TreeNodeProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const TreeNode: ({ node, noLines, expanders, checkable, selectable, defaultLeafIcon, defaultNodeIcon, onToggle, onClick, onSelect, onChecked, children, leafClassName, nodeClassName, }: TreeNodeProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,43 @@
1
1
  import { type TreePanelProps } from "./types";
2
- export declare const TreePanel: <T extends KeyValue<any>>({ ref, items, selected, checked, checkable, noLines, renderer, searchable, selectable, matcher, filterPlaceholder, defaultLeafIcon, defaultNodeIcon, expander, onChecked, onLoad, onSelect, ...aria }: TreePanelProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ /**
3
+ * TreePanel component renders a virtualized tree structure with support for
4
+ * selection, expansion, and filtering. It allows for custom rendering of tree
5
+ * nodes and supports checkable nodes.
6
+ *
7
+ * @param {TreePanelProps<T>} props - The properties for the TreePanel component.
8
+ * @returns {JSX.Element} The rendered TreePanel component.
9
+ * @template T - The type of items in the tree, extending KeyValue.
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * <TreePanel
14
+ * items={items}
15
+ * selected={selectedItem}
16
+ * checked={checkedItems}
17
+ * checkable={true}
18
+ * renderer={(item) => <span>{item.name}</span>}
19
+ * searchable={true}
20
+ * selectable={true}
21
+ * matcher={(item, query) => item.name.toLowerCase().includes(query.toLowerCase())}
22
+ * filterPlaceholder="Search..."
23
+ * defaultLeafIcon={<Icon icon="icon-[mdi--file]" />}
24
+ * defaultNodeIcon={<Icon icon="icon-[mdi--folder]" />}
25
+ * expander="caret"
26
+ * onChecked={(checkedItems) => console.log(checkedItems)}
27
+ * onLoad={(id) => console.log(`Load children for ${id}`)}
28
+ * onQuery={(query) => console.log(`Query: ${query}`)}
29
+ * onSelect={(selectedItem) => console.log(selectedItem)}
30
+ * onClick={(item) => console.log(`Clicked on ${item.id}`)}
31
+ * sorter={(a, b) => a.label.localeCompare(b.label)}
32
+ * makeLabel={(item) => item.name}
33
+ * makeIcon={(item) => item.icon ? <Icon icon={item.icon} /> : null}
34
+ * defaultExpanded={["root"]}
35
+ * onExpandToggle={(id, expanded) => console.log(`Toggle expand for ${id}: ${expanded}`)}
36
+ * leafClassName="leaf-node"
37
+ * nodeClassName="tree-node"
38
+ * />
39
+ * ```
40
+ *
41
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-treepanel--docs}
42
+ */
43
+ export declare const TreePanel: <T extends KeyValue>({ ref, items, selected, checked, checkable, noLines, searchable, selectable, multiple, matcher, filterPlaceholder, defaultLeafIcon, defaultNodeIcon, expander, onChecked, onLoad, onQuery, onSelect, onClick, sorter, makeLabel, makeIcon, defaultExpanded, onExpandToggle, leafClassName, nodeClassName, ...aria }: TreePanelProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,15 @@
1
- /// <reference types="react" />
2
- import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
3
- interface TreeBaseNode<T> extends IconProps, CssProp, TestProps {
1
+ import { type IconProps } from "@react-fabric/core/dist/types/components/icon/Icon";
2
+ import { type BadgeType, type ChildProp, type CssProp, type Elements, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
3
+ interface TreeBaseNode<T> extends CssProp, TestProps {
4
4
  id: string;
5
5
  /**
6
6
  * display label
7
7
  */
8
8
  label: Elements<JSX.Element>;
9
+ /**
10
+ * icon path or props
11
+ */
12
+ icon?: IconProps;
9
13
  /**
10
14
  * full text to be used for querying purposes
11
15
  */
@@ -28,12 +32,12 @@ export type TreeNodeType<T extends KeyValue = KeyValue> = TreeBaseNode<T> & ({
28
32
  leaf: true;
29
33
  children?: never;
30
34
  } | {
31
- leaf?: false;
35
+ leaf?: boolean;
32
36
  children?: Array<TreeNodeType<T>>;
33
37
  open?: boolean;
34
38
  iconOpen?: string;
35
39
  });
36
- export interface InternalNode extends IconProps, CssProp, TestProps {
40
+ export interface InternalNode extends CssProp, TestProps {
37
41
  id: string;
38
42
  label: Elements<JSX.Element>;
39
43
  queryable?: string;
@@ -50,6 +54,7 @@ export interface InternalNode extends IconProps, CssProp, TestProps {
50
54
  loaded: boolean;
51
55
  parent?: string;
52
56
  empty?: boolean;
57
+ icon?: IconProps;
53
58
  errored?: string;
54
59
  selected?: true;
55
60
  childSelected?: true;
@@ -61,20 +66,51 @@ export interface InternalNode extends IconProps, CssProp, TestProps {
61
66
  export interface TreeNodeProps extends ChildProp {
62
67
  node: InternalNode;
63
68
  expanders: [string, string];
64
- defaultNodeIcon?: string;
65
- defaultLeafIcon?: string;
69
+ defaultNodeIcon?: Elements<JSX.Element>;
70
+ defaultLeafIcon?: Elements<JSX.Element>;
66
71
  noLines?: boolean;
67
72
  selectable?: true | "leafOnly";
68
73
  checkable?: true | "leafOnly";
74
+ leafClassName?: string;
75
+ nodeClassName?: string;
69
76
  onToggle: (id: string) => void;
70
- onSelect: (id: string) => void;
77
+ onSelect: (id: string, shiftKey?: boolean) => void;
71
78
  onChecked: (id: string) => void;
79
+ onClick?: (id: string, node: any) => void;
72
80
  }
73
81
  export interface TreeRef {
74
82
  select: (id: string) => void;
75
83
  open: (id: string) => void;
84
+ openAndLoad: (list: string[]) => void;
76
85
  }
77
- export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps, RefProp<TreeRef> {
86
+ export type TreePanelProps<T extends KeyValue = KeyValue> = BaseTreePanelProps<T> & ({
87
+ /**
88
+ * enable multi select
89
+ */
90
+ multiple?: never | false;
91
+ /**
92
+ * selected item id
93
+ */
94
+ selected?: string;
95
+ /**
96
+ * callback on selection of tree node
97
+ */
98
+ onSelect?: (id: string, data: T) => void;
99
+ } | {
100
+ /**
101
+ * enable multi select
102
+ */
103
+ multiple: true;
104
+ /**
105
+ * selected item id
106
+ */
107
+ selected?: string[];
108
+ /**
109
+ * callback on selection of tree node
110
+ */
111
+ onSelect?: (id: string[], data: T) => void;
112
+ });
113
+ interface BaseTreePanelProps<T extends KeyValue = KeyValue> extends TestProps, RefProp<TreeRef> {
78
114
  items?: Array<TreeNodeType<T>>;
79
115
  /**
80
116
  * make tree searchable
@@ -89,13 +125,13 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
89
125
  */
90
126
  selectable?: true | "leafOnly";
91
127
  /**
92
- * enable checkable
128
+ * enable multi select
93
129
  */
94
- checkable?: true | "leafOnly";
130
+ multiple?: boolean;
95
131
  /**
96
- * selected item id
132
+ * enable checkable
97
133
  */
98
- selected?: string;
134
+ checkable?: true | "leafOnly";
99
135
  /**
100
136
  * checked items
101
137
  */
@@ -121,22 +157,30 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
121
157
  */
122
158
  onLoad?: (id: string) => Promise<Array<TreeNodeType<T>> | undefined> | Array<TreeNodeType<T>> | undefined;
123
159
  /**
124
- * callback on selection of tree node
160
+ * callback to load tree using search query
125
161
  */
126
- onSelect?: (id: string) => void;
162
+ onQuery?: (query: string) => void;
127
163
  /**
128
- * callback on change of checked list
164
+ * callback on click of tree node
129
165
  */
130
- onChecked?: (leafs: string[], nodes: string[]) => void;
166
+ onClick?: (id: string, data: T) => void;
131
167
  /**
132
- * item label renderer
168
+ * callback on change of checked list
169
+ * @param leafs - list of checked leaf nodes
170
+ * @param nodes - list of checked nodes
171
+ * @param partials - list of partially checked nodes
133
172
  */
134
- renderer?: (data: T) => JSX.Element;
173
+ onChecked?: (leafs: string[], nodes: string[], partials: string[]) => void;
135
174
  /**
136
175
  * item filter matcher
137
176
  */
138
177
  matcher?: (data: T, query: string) => boolean;
178
+ sorter?: false | ((a: T, b: T) => number);
179
+ makeLabel?: (node: T) => Elements<JSX.Element>;
180
+ makeIcon?: (node: T) => Elements<JSX.Element>;
181
+ defaultExpanded?: string[];
182
+ onExpandToggle?: (id: string[]) => void;
183
+ leafClassName?: string;
184
+ nodeClassName?: string;
139
185
  }
140
- export declare const iconExpandAll = "M12.984 9v6h3l-3.984 3.984-3.984-3.984h3v-6h-3l3.984-3.984 3.984 3.984h-3zM3.984 2.016h16.031v1.969h-16.031v-1.969zM3.984 20.016h16.031v1.969h-16.031v-1.969z";
141
- export declare const iconCollapseAll = "M3.984 11.016h16.031v1.969h-16.031v-1.969zM15.984 5.016l-3.984 3.984-3.984-3.984h3v-4.031h1.969v4.031h3zM8.016 18.984l3.984-3.984 3.984 3.984h-3v4.031h-1.969v-4.031h-3z";
142
186
  export {};
@@ -1,21 +1,20 @@
1
- import { type InternalNode, type TreeNodeType } from "./types";
2
- export declare const useTree: <T extends KeyValue<any>>({ items, checked, selected, matcher, onSelect, onChecked, }: {
3
- items?: Array<TreeNodeType<T>>;
4
- selected?: string;
5
- checked?: string[];
6
- onSelect?: (id: string) => void;
7
- onChecked?: (leafs: string[], nodes: string[]) => void;
8
- matcher?: (data: T, query: string) => boolean;
1
+ import { type InternalNode, type TreePanelProps } from "./types";
2
+ export declare const useTree: <T extends KeyValue>({ items, checked, selected, multiple, sorter, matcher, onLoad, onQuery, onSelect, onChecked, defaultExpanded, onExpandToggle, }: Partial<TreePanelProps<T>> & {
3
+ selected?: AnyObject;
4
+ multiple?: boolean;
9
5
  }) => {
10
6
  tree: InternalNode[];
7
+ query: string | undefined;
8
+ selected: any;
11
9
  toggleExpand: (id: string) => void;
12
10
  expandAll: () => void;
13
11
  collapseAll: () => void;
14
12
  toggleCheck: (id: string) => void;
15
- select: (id: string) => void;
13
+ expandAndLoad: (expandList: string[]) => void;
14
+ select: (id: string, shiftKey?: boolean) => void;
16
15
  expand: (id: string) => void;
17
16
  onFilter: {
18
- (...args: any): void;
17
+ (...args: AnyObject): void;
19
18
  cancel(): void;
20
19
  };
21
20
  };
@@ -1,10 +1,17 @@
1
1
  import { type InternalNode, type TreeNodeType } from "./types";
2
- export declare const refactorTree: (nodes: TreeNodeType[], options?: {
2
+ export declare const refactorTree: (nodes: TreeNodeType[], { sorter, defaultExpanded, }: {
3
+ sorter?: any;
4
+ defaultExpanded?: string[];
5
+ }, options?: {
3
6
  level: number;
4
7
  parent?: string;
5
8
  }) => InternalNode[];
6
9
  export declare const makeTreeMap: (nodes: InternalNode[], map?: Map<any, any>) => Map<any, any>;
7
10
  export declare const flattenTree: (nodes: InternalNode[], lines?: Array<0 | 1 | 2 | 3>) => InternalNode[];
8
- export declare const updateSelection: (nodes: Map<string, InternalNode>, id: string, selected?: true) => void;
9
- export declare const updateChecked: (list: Map<string, AnyObject>, id: string) => void;
11
+ export declare const updateSelection: ({ nodes, multiple, selected, }: {
12
+ nodes: Map<string, InternalNode>;
13
+ multiple?: boolean;
14
+ selected?: string | string[];
15
+ }) => void;
16
+ export declare const updateChecked: (list: Map<string, AnyObject>, id: string, checked?: 0 | 1 | 2) => void;
10
17
  export declare const filterTree: (nodes: Map<string, InternalNode>, query?: string, matcher?: AnyObject) => void;