@react-fabric/data 1.0.0-beta.8 → 1.0.1

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 (141) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/checklist/CheckList.js +59 -33
  4. package/dist/cjs/histogram/Histogram.js +41 -26
  5. package/dist/cjs/hooks/useFilteredList.js +100 -17
  6. package/dist/cjs/hooks/usePagination.js +29 -8
  7. package/dist/cjs/hooks/useSelectableList.js +30 -5
  8. package/dist/cjs/i18n/{ar.json.js → ar/data.json.js} +8 -1
  9. package/dist/cjs/i18n/{en.json.js → en/data.json.js} +8 -1
  10. package/dist/cjs/i18n/index.js +4 -4
  11. package/dist/cjs/index.js +30 -0
  12. package/dist/cjs/json/JsonViewer.js +80 -43
  13. package/dist/cjs/pagination/Pagination.js +24 -15
  14. package/dist/cjs/table/AddColumn.js +5 -5
  15. package/dist/cjs/table/BodyCell.js +20 -13
  16. package/dist/cjs/table/BodyRow.js +41 -28
  17. package/dist/cjs/table/CheckboxCell.js +10 -9
  18. package/dist/cjs/table/ColumnFilters.js +100 -0
  19. package/dist/cjs/table/EmptyCell.js +4 -4
  20. package/dist/cjs/table/HeaderCell.js +79 -53
  21. package/dist/cjs/table/HtmlTable.js +84 -0
  22. package/dist/cjs/table/{Context.js → Provider.js} +8 -10
  23. package/dist/cjs/table/Table.js +99 -33
  24. package/dist/cjs/{tree/types.js → table/context.js} +9 -5
  25. package/dist/cjs/table/types.js +29 -0
  26. package/dist/cjs/table/useResizer.js +10 -10
  27. package/dist/cjs/table/useTableColumns.js +4 -4
  28. package/dist/cjs/table/useVirtualTable.js +129 -22
  29. package/dist/cjs/tree/TreeNode.js +66 -46
  30. package/dist/cjs/tree/TreePanel.js +60 -24
  31. package/dist/cjs/tree/useTree.js +212 -47
  32. package/dist/cjs/tree/utils.js +63 -34
  33. package/dist/cjs/utils/getColor.js +58 -0
  34. package/dist/cjs/virtual/Gallery.js +119 -61
  35. package/dist/cjs/virtual/List.js +116 -55
  36. package/dist/cjs/virtual/Scroller.js +16 -8
  37. package/dist/esm/checklist/CheckList.js +61 -35
  38. package/dist/esm/histogram/Histogram.js +43 -28
  39. package/dist/esm/hooks/useFilteredList.js +101 -18
  40. package/dist/esm/hooks/usePagination.js +29 -8
  41. package/dist/esm/hooks/useSelectableList.js +30 -5
  42. package/dist/esm/i18n/{ar.json.js → ar/data.json.js} +8 -2
  43. package/dist/esm/i18n/{en.json.js → en/data.json.js} +8 -2
  44. package/dist/esm/i18n/index.js +2 -2
  45. package/dist/esm/index.js +31 -0
  46. package/dist/esm/json/JsonViewer.js +82 -45
  47. package/dist/esm/pagination/Pagination.js +25 -16
  48. package/dist/esm/table/AddColumn.js +6 -6
  49. package/dist/esm/table/BodyCell.js +21 -14
  50. package/dist/esm/table/BodyRow.js +41 -28
  51. package/dist/esm/table/CheckboxCell.js +11 -10
  52. package/dist/esm/table/ColumnFilters.js +100 -0
  53. package/dist/esm/table/EmptyCell.js +4 -4
  54. package/dist/esm/table/HeaderCell.js +80 -54
  55. package/dist/esm/table/HtmlTable.js +84 -0
  56. package/dist/esm/table/{Context.js → Provider.js} +11 -12
  57. package/dist/esm/table/Table.js +100 -34
  58. package/dist/esm/{tree/types.js → table/context.js} +8 -4
  59. package/dist/esm/table/types.js +29 -0
  60. package/dist/esm/table/useResizer.js +10 -10
  61. package/dist/esm/table/useTableColumns.js +4 -4
  62. package/dist/esm/table/useVirtualTable.js +131 -24
  63. package/dist/esm/tree/TreeNode.js +69 -49
  64. package/dist/esm/tree/TreePanel.js +62 -26
  65. package/dist/esm/tree/useTree.js +215 -50
  66. package/dist/esm/tree/utils.js +64 -35
  67. package/dist/esm/utils/getColor.js +58 -0
  68. package/dist/esm/virtual/Gallery.js +121 -63
  69. package/dist/esm/virtual/List.js +118 -57
  70. package/dist/esm/virtual/Scroller.js +17 -9
  71. package/dist/types/checklist/CheckList.d.ts +25 -6
  72. package/dist/types/histogram/Histogram.d.ts +28 -6
  73. package/dist/types/hooks/useFilteredList.d.ts +62 -5
  74. package/dist/types/hooks/usePagination.d.ts +18 -2
  75. package/dist/types/hooks/useSelectableList.d.ts +24 -1
  76. package/dist/types/index.d.ts +27 -0
  77. package/dist/types/json/JsonViewer.d.ts +23 -3
  78. package/dist/types/pagination/Pagination.d.ts +8 -2
  79. package/dist/types/table/AddColumn.d.ts +2 -2
  80. package/dist/types/table/BodyCell.d.ts +2 -2
  81. package/dist/types/table/BodyRow.d.ts +9 -9
  82. package/dist/types/table/CheckboxCell.d.ts +3 -3
  83. package/dist/types/table/ColumnFilters.d.ts +12 -0
  84. package/dist/types/table/EmptyCell.d.ts +1 -1
  85. package/dist/types/table/HeaderCell.d.ts +1 -1
  86. package/dist/types/table/HtmlTable.d.ts +21 -0
  87. package/dist/types/table/Provider.d.ts +2 -0
  88. package/dist/types/table/Table.d.ts +10 -1
  89. package/dist/types/table/context.d.ts +7 -0
  90. package/dist/types/table/types.d.ts +52 -10
  91. package/dist/types/table/useResizer.d.ts +1 -1
  92. package/dist/types/table/useTableColumns.d.ts +1 -1
  93. package/dist/types/table/useVirtualTable.d.ts +31 -12
  94. package/dist/types/tree/TreeNode.d.ts +1 -1
  95. package/dist/types/tree/TreePanel.d.ts +36 -1
  96. package/dist/types/tree/types.d.ts +75 -28
  97. package/dist/types/tree/useTree.d.ts +8 -12
  98. package/dist/types/tree/utils.d.ts +15 -8
  99. package/dist/types/utils/getColor.d.ts +43 -0
  100. package/dist/types/virtual/Gallery.d.ts +37 -6
  101. package/dist/types/virtual/List.d.ts +38 -6
  102. package/dist/types/virtual/Scroller.d.ts +1 -1
  103. package/package.json +17 -19
  104. package/src/checklist/CheckList.tsx +68 -71
  105. package/src/histogram/Histogram.tsx +47 -48
  106. package/src/hooks/useFilteredList.tsx +111 -28
  107. package/src/hooks/usePagination.tsx +39 -39
  108. package/src/hooks/useSelectableList.ts +45 -33
  109. package/src/i18n/{ar.json → ar/data.json} +5 -0
  110. package/src/i18n/{en.json → en/data.json} +5 -0
  111. package/src/i18n/index.ts +2 -2
  112. package/src/index.ts +23 -17
  113. package/src/json/JsonViewer.tsx +89 -120
  114. package/src/pagination/Pagination.tsx +104 -105
  115. package/src/table/AddColumn.tsx +6 -15
  116. package/src/table/BodyCell.tsx +27 -36
  117. package/src/table/BodyRow.tsx +36 -59
  118. package/src/table/CheckboxCell.tsx +12 -15
  119. package/src/table/ColumnFilters.tsx +93 -0
  120. package/src/table/EmptyCell.tsx +5 -18
  121. package/src/table/HeaderCell.tsx +72 -53
  122. package/src/table/HtmlTable.tsx +106 -0
  123. package/src/table/{Context.tsx → Provider.tsx} +11 -28
  124. package/src/table/Table.tsx +98 -83
  125. package/src/table/context.ts +33 -0
  126. package/src/table/types.ts +53 -27
  127. package/src/table/useResizer.ts +5 -9
  128. package/src/table/useTableColumns.ts +4 -6
  129. package/src/table/useVirtualTable.ts +136 -37
  130. package/src/tree/TreeNode.tsx +91 -86
  131. package/src/tree/TreePanel.tsx +87 -51
  132. package/src/tree/types.ts +85 -46
  133. package/src/tree/useTree.ts +210 -65
  134. package/src/tree/utils.ts +81 -62
  135. package/src/utils/getColor.ts +55 -0
  136. package/src/virtual/Gallery.tsx +129 -120
  137. package/src/virtual/List.tsx +124 -91
  138. package/src/virtual/Scroller.tsx +25 -9
  139. package/dist/cjs/histogram/Histogram.module.css +0 -1
  140. package/dist/esm/histogram/Histogram.module.css +0 -1
  141. package/dist/types/table/Context.d.ts +0 -8
@@ -1,18 +1,37 @@
1
- /// <reference types="react" />
2
- interface DataState {
3
- expanded: Key[];
4
- checked: Key[];
5
- allChecked: 0 | 1 | 2;
1
+ interface DataGroup {
2
+ __GROUP__: true;
3
+ key: Key;
4
+ open: boolean;
5
+ itemCount: number;
6
6
  }
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>;
12
- virtualizer: import("@tanstack/virtual-core").Virtualizer<HTMLDivElement, Element>;
7
+ export declare function useVirtualTable<T extends KeyValue = KeyValue>(data: T[], options: {
8
+ checked?: Key[];
9
+ keyProperty: keyof T;
10
+ groupProperty?: keyof T;
11
+ loading?: boolean;
12
+ total: number;
13
+ onLoadMore?: (startIndex: number) => void;
14
+ onCheckChanged?: (checked: AnyObject[]) => void;
15
+ }): {
16
+ scrollerRef: import("react").RefObject<HTMLDivElement | null>;
17
+ items: import("@tanstack/virtual-core").VirtualItem[];
18
+ checkState: {
19
+ allChecked: number;
20
+ data: T[];
21
+ items: (DataGroup | T)[];
22
+ grouped: KeyValue<T[]>;
23
+ groups: DataGroup[];
24
+ expanded: Key[];
25
+ checked: Key[];
26
+ };
27
+ getData: (index: number) => DataGroup | T;
28
+ virtualizer: import("@tanstack/react-virtual").ReactVirtualizer<HTMLDivElement, Element>;
29
+ hasActiveSticky: boolean;
30
+ isActiveSticky: (index: number) => boolean;
13
31
  top: number | undefined;
14
32
  totalSize: () => number;
15
- measureElement: (node: Element | null | undefined) => void;
33
+ measureElement: (node: Element | null) => void;
34
+ toggleGroupExpand: (key: Key) => void;
16
35
  toggleExpand: (key: Key) => void;
17
36
  toggleChecked: (key: Key) => void;
18
37
  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 function TreeNode<T extends KeyValue>({ node, noLines, expanders, checkable, selectable, defaultLeafIcon, defaultNodeIcon, onToggle, onClick, onSelect, onChecked, children, leafClassName, nodeClassName, }: TreeNodeProps<T>): import("react").JSX.Element;
@@ -1,2 +1,37 @@
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
+ * @example
8
+ * ```jsx
9
+ * <TreePanel
10
+ * items={items}
11
+ * selected={selectedItem}
12
+ * checked={checkedItems}
13
+ * checkable={true}
14
+ * renderer={(item) => <span>{item.name}</span>}
15
+ * searchable={true}
16
+ * selectable={true}
17
+ * matcher={(item, query) => item.name.toLowerCase().includes(query.toLowerCase())}
18
+ * filterPlaceholder="Search..."
19
+ * defaultLeafIcon={<Icon icon="icon-[mdi--file]" />}
20
+ * defaultNodeIcon={<Icon icon="icon-[mdi--folder]" />}
21
+ * expander="caret"
22
+ * onChecked={(checkedItems) => console.log(checkedItems)}
23
+ * onLoad={(id) => console.log(`Load children for ${id}`)}
24
+ * onQuery={(query) => console.log(`Query: ${query}`)}
25
+ * onSelect={(selectedItem) => console.log(selectedItem)}
26
+ * onClick={(item) => console.log(`Clicked on ${item.id}`)}
27
+ * sorter={(a, b) => a.label.localeCompare(b.label)}
28
+ * makeLabel={(item) => item.name}
29
+ * makeIcon={(item) => item.icon ? <Icon icon={item.icon} /> : null}
30
+ * defaultExpanded={["root"]}
31
+ * onExpandToggle={(id, expanded) => console.log(`Toggle expand for ${id}: ${expanded}`)}
32
+ * leafClassName="leaf-node"
33
+ * nodeClassName="tree-node"
34
+ * />
35
+ * ```
36
+ */
37
+ export declare function 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.Element;
@@ -1,11 +1,16 @@
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 { BadgeType } from "@/core/dist/types/components/badge/Badge";
2
+ import { type IconProps } from "@react-fabric/core/dist/types/components/icon/Icon";
3
+ import { type ChildProp, type CssProp, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
4
+ interface TreeBaseNode<T> extends CssProp, TestProps {
4
5
  id: string;
5
6
  /**
6
7
  * display label
7
8
  */
8
- label: Elements<JSX.Element>;
9
+ label: React.ReactNode;
10
+ /**
11
+ * icon path or props
12
+ */
13
+ icon?: IconProps;
9
14
  /**
10
15
  * full text to be used for querying purposes
11
16
  */
@@ -22,26 +27,26 @@ interface TreeBaseNode<T> extends IconProps, CssProp, TestProps {
22
27
  * disable selection
23
28
  */
24
29
  disabled?: boolean;
25
- data?: T;
30
+ data: T;
26
31
  }
27
32
  export type TreeNodeType<T extends KeyValue = KeyValue> = TreeBaseNode<T> & ({
28
33
  leaf: true;
29
34
  children?: never;
30
35
  } | {
31
- leaf?: false;
36
+ leaf?: boolean;
32
37
  children?: Array<TreeNodeType<T>>;
33
38
  open?: boolean;
34
39
  iconOpen?: string;
35
40
  });
36
- export interface InternalNode extends IconProps, CssProp, TestProps {
41
+ export interface InternalNode<T> extends CssProp, TestProps {
37
42
  id: string;
38
- label: Elements<JSX.Element>;
43
+ label: React.ReactNode;
39
44
  queryable?: string;
40
45
  badge?: string | number | BadgeType;
41
46
  disabled?: boolean;
42
47
  leaf: boolean;
43
48
  open: boolean;
44
- children?: InternalNode[];
49
+ children?: InternalNode<T>[];
45
50
  level: number;
46
51
  loading: boolean;
47
52
  filtered: boolean;
@@ -50,31 +55,63 @@ export interface InternalNode extends IconProps, CssProp, TestProps {
50
55
  loaded: boolean;
51
56
  parent?: string;
52
57
  empty?: boolean;
58
+ icon?: IconProps;
53
59
  errored?: string;
54
60
  selected?: true;
55
61
  childSelected?: true;
56
62
  checked: 0 | 1 | 2;
57
- data?: AnyObject;
63
+ data: T;
58
64
  last?: boolean;
59
65
  lines: Array<0 | 1 | 2 | 3>;
60
66
  }
61
- export interface TreeNodeProps extends ChildProp {
62
- node: InternalNode;
67
+ export interface TreeNodeProps<T> extends ChildProp {
68
+ node: InternalNode<T>;
63
69
  expanders: [string, string];
64
- defaultNodeIcon?: string;
65
- defaultLeafIcon?: string;
70
+ defaultNodeIcon?: string | React.ReactElement;
71
+ defaultLeafIcon?: string | React.ReactElement;
66
72
  noLines?: boolean;
67
73
  selectable?: true | "leafOnly";
68
74
  checkable?: true | "leafOnly";
75
+ leafClassName?: string;
76
+ nodeClassName?: string;
69
77
  onToggle: (id: string) => void;
70
- onSelect: (id: string) => void;
78
+ onSelect: (id: string, shiftKey?: boolean) => void;
71
79
  onChecked: (id: string) => void;
80
+ onClick?: (id: string, node: T) => void;
72
81
  }
73
82
  export interface TreeRef {
74
83
  select: (id: string) => void;
75
84
  open: (id: string) => void;
85
+ openAndLoad: (list: string[]) => void;
76
86
  }
77
- export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps, RefProp<TreeRef> {
87
+ export type TreePanelProps<T extends KeyValue = KeyValue> = BaseTreePanelProps<T> & ({
88
+ /**
89
+ * enable multi select
90
+ */
91
+ multiple?: false;
92
+ /**
93
+ * selected item id
94
+ */
95
+ selected?: string;
96
+ /**
97
+ * callback on selection of tree node
98
+ */
99
+ onSelect?: (id: string, data: T) => void;
100
+ } | {
101
+ /**
102
+ * enable multi select
103
+ */
104
+ multiple?: true;
105
+ /**
106
+ * selected item id
107
+ */
108
+ selected?: string[];
109
+ /**
110
+ * callback on selection of tree node
111
+ */
112
+ onSelect?: (id: string[], data: T) => void;
113
+ });
114
+ export interface BaseTreePanelProps<T extends KeyValue = KeyValue> extends TestProps, RefProp<TreeRef> {
78
115
  items?: Array<TreeNodeType<T>>;
79
116
  /**
80
117
  * make tree searchable
@@ -89,17 +126,18 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
89
126
  */
90
127
  selectable?: true | "leafOnly";
91
128
  /**
92
- * enable checkable
129
+ * enable multi select
93
130
  */
94
- checkable?: true | "leafOnly";
131
+ multiple?: boolean;
95
132
  /**
96
- * selected item id
133
+ * enable checkable
97
134
  */
98
- selected?: string;
135
+ checkable?: true | "leafOnly";
99
136
  /**
100
137
  * checked items
101
138
  */
102
139
  checked?: string[];
140
+ selected?: string | string[];
103
141
  /**
104
142
  * default node icon
105
143
  */
@@ -121,22 +159,31 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
121
159
  */
122
160
  onLoad?: (id: string) => Promise<Array<TreeNodeType<T>> | undefined> | Array<TreeNodeType<T>> | undefined;
123
161
  /**
124
- * callback on selection of tree node
162
+ * callback to load tree using search query
125
163
  */
126
- onSelect?: (id: string) => void;
164
+ onQuery?: (query: string) => void;
127
165
  /**
128
- * callback on change of checked list
166
+ * callback on click of tree node
129
167
  */
130
- onChecked?: (leafs: string[], nodes: string[]) => void;
168
+ onClick?: (id: string, data: T) => void;
131
169
  /**
132
- * item label renderer
170
+ * callback on change of checked list
171
+ * @param leafs - list of checked leaf nodes
172
+ * @param nodes - list of checked nodes
173
+ * @param partials - list of partially checked nodes
133
174
  */
134
- renderer?: (data: T) => JSX.Element;
175
+ onChecked?: (leafs: string[], nodes: string[], partials: string[]) => void;
135
176
  /**
136
177
  * item filter matcher
137
178
  */
138
179
  matcher?: (data: T, query: string) => boolean;
180
+ onSelect?: (id: string | string[], data: T) => void;
181
+ sorter?: false | ((a: TreeNodeType<T>, b: TreeNodeType<T>) => number);
182
+ makeLabel?: (node: T) => React.ReactNode;
183
+ makeIcon?: (node: T) => React.ReactElement;
184
+ defaultExpanded?: string[];
185
+ onExpandToggle?: (id: string[]) => void;
186
+ leafClassName?: string;
187
+ nodeClassName?: string;
139
188
  }
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
189
  export {};
@@ -1,21 +1,17 @@
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;
9
- }) => {
10
- tree: InternalNode[];
1
+ import type { BaseTreePanelProps, InternalNode } from "./types";
2
+ export declare function useTree<T extends KeyValue>({ items, checked, selected, multiple, sorter, matcher, onLoad, onQuery, onSelect, onChecked, defaultExpanded, onExpandToggle, }: Partial<BaseTreePanelProps<T>>): {
3
+ tree: InternalNode<T>[];
4
+ query: string | undefined;
5
+ selected: string | string[] | undefined;
11
6
  toggleExpand: (id: string) => void;
12
7
  expandAll: () => void;
13
8
  collapseAll: () => void;
14
9
  toggleCheck: (id: string) => void;
15
- select: (id: string) => void;
10
+ expandAndLoad: (expandList: string[]) => void;
11
+ select: (id: string, shiftKey?: boolean) => void;
16
12
  expand: (id: string) => void;
17
13
  onFilter: {
18
- (...args: any): void;
14
+ (...args: unknown[]): void;
19
15
  cancel(): void;
20
16
  };
21
17
  };
@@ -1,10 +1,17 @@
1
- import { type InternalNode, type TreeNodeType } from "./types";
2
- export declare const refactorTree: (nodes: TreeNodeType[], options?: {
1
+ import type { InternalNode, TreeNodeType } from "./types";
2
+ export declare function refactorTree<T extends KeyValue>(nodes: TreeNodeType<T>[], { sorter, defaultExpanded, }: {
3
+ sorter?: false | ((a: TreeNodeType<T>, b: TreeNodeType<T>) => number);
4
+ defaultExpanded?: string[];
5
+ }, options?: {
3
6
  level: number;
4
7
  parent?: string;
5
- }) => InternalNode[];
6
- export declare const makeTreeMap: (nodes: InternalNode[], map?: Map<any, any>) => Map<any, any>;
7
- 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;
10
- export declare const filterTree: (nodes: Map<string, InternalNode>, query?: string, matcher?: AnyObject) => void;
8
+ }): InternalNode<T>[];
9
+ export declare function makeTreeMap<T extends KeyValue>(nodes: InternalNode<T>[], map?: Map<string, InternalNode<T>>): Map<string, InternalNode<T>>;
10
+ export declare function flattenTree<T extends KeyValue>(nodes: InternalNode<T>[], lines?: Array<0 | 1 | 2 | 3>): InternalNode<T>[];
11
+ export declare function updateSelection<T extends KeyValue>({ nodes, multiple, selected, }: {
12
+ nodes: Map<string, InternalNode<T>>;
13
+ multiple?: boolean;
14
+ selected?: string | string[];
15
+ }): void;
16
+ export declare function updateChecked<T extends KeyValue>(list: Map<string, InternalNode<T>>, id: string, checked?: 0 | 1 | 2): void;
17
+ export declare function filterTree<T extends KeyValue>(nodes: Map<string, InternalNode<T>>, query?: string, matcher?: (data: T, query: string) => boolean): void;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Resolves a color value to a CSS color string.
27
+ *
28
+ * If the input is a valid CSS color (e.g., `"#ff0000"`, `"rgb(255,0,0)"`), it is returned as-is.
29
+ * Otherwise, it is treated as a design token name and resolved to a CSS custom property
30
+ * (e.g., `"primary-500"` → `"var(--color-primary-500)"`).
31
+ *
32
+ * @param {ColorUnion} color - The color value to resolve. Accepts CSS color strings or design token names.
33
+ * @returns The resolved CSS color string, or `undefined` if color is falsy.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * getColor("primary-500"); // "var(--color-primary-500)"
38
+ * getColor("#ff0000"); // "#ff0000"
39
+ * getColor("red"); // "var(--color-red)"
40
+ * getColor(undefined); // undefined
41
+ * ```
42
+ */
43
+ export declare function getColor(color?: string): string | undefined;
@@ -7,7 +7,7 @@ export interface VirtualGalleryRef {
7
7
  }
8
8
  export interface VirtualGalleryProps<T> extends TestProps {
9
9
  children: (props: {
10
- data: T;
10
+ item: T;
11
11
  index: number;
12
12
  isLast: boolean;
13
13
  }) => ReactElement;
@@ -24,6 +24,12 @@ export interface VirtualGalleryProps<T> extends TestProps {
24
24
  * default item width
25
25
  */
26
26
  defaultWidth?: number;
27
+ /**
28
+ * full width list
29
+ */
30
+ fullWidth?: boolean;
31
+ maxWidth?: string | number;
32
+ minWidth?: string | number;
27
33
  /**
28
34
  * padding
29
35
  */
@@ -32,6 +38,7 @@ export interface VirtualGalleryProps<T> extends TestProps {
32
38
  * data list
33
39
  */
34
40
  items: T[];
41
+ total?: number;
35
42
  /**
36
43
  * loading state
37
44
  */
@@ -44,13 +51,37 @@ export interface VirtualGalleryProps<T> extends TestProps {
44
51
  /**
45
52
  * load more callback
46
53
  */
47
- onLoadMore?: () => void;
54
+ onLoadMore?: (lastIndex?: number) => void;
48
55
  /**
49
56
  * scroll handler
50
57
  */
51
58
  onScroll?: (top: number) => void;
52
59
  }
53
- export declare const VirtualGallery: {
54
- <T extends KeyValue<any>>({ items, children, columns, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, ...aria }: VirtualGalleryProps<T>): import("react/jsx-runtime").JSX.Element;
55
- displayName: string;
56
- };
60
+ /**
61
+ * VirtualGallery component provides a virtualized gallery view for displaying a large list of items efficiently.
62
+ * It supports features like fixed columns, loading states, and customizable item rendering.
63
+ * The component uses virtualization to render only the visible items, improving performance for large datasets.
64
+ * It also provides a scroller for easy navigation through the items.
65
+ *
66
+ * @example
67
+ * ```jsx
68
+ * <VirtualGallery
69
+ * items={items}
70
+ * columns={3}
71
+ * defaultHeight={100}
72
+ * defaultWidth={100}
73
+ * fullWidth={true}
74
+ * onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
75
+ * onScroll={(top) => console.log("Scrolled to top:", top)}
76
+ * >
77
+ * {({ item, index, isLast }) => (
78
+ * <div className="gallery-item" key={item.id}>
79
+ * <img src={item.image} alt={item.label} />
80
+ * <p>{item.label}</p>
81
+ * </div>
82
+ * )}
83
+ * </VirtualGallery>
84
+ * ```
85
+ * @see {@link https://tanstack.com/docs/react-virtual/latest/overview}
86
+ */
87
+ export declare const VirtualGallery: <T extends unknown>({ items, children, columns, fullWidth, maxWidth, minWidth, total, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, ...aria }: VirtualGalleryProps<T>) => import("react").JSX.Element;
@@ -7,7 +7,7 @@ export interface VirtualListRef {
7
7
  }
8
8
  export interface VirtualListProps<T> extends TestProps {
9
9
  children: (props: {
10
- data: T;
10
+ item: T;
11
11
  index: number;
12
12
  isLast: boolean;
13
13
  }) => ReactElement;
@@ -24,6 +24,8 @@ export interface VirtualListProps<T> extends TestProps {
24
24
  * full width list
25
25
  */
26
26
  fullWidth?: boolean;
27
+ maxWidth?: string | number;
28
+ minWidth?: string | number;
27
29
  /**
28
30
  * padding
29
31
  */
@@ -36,6 +38,7 @@ export interface VirtualListProps<T> extends TestProps {
36
38
  * data list
37
39
  */
38
40
  items: T[];
41
+ total?: number;
39
42
  initialScroll?: number;
40
43
  /**
41
44
  * loading state
@@ -48,13 +51,42 @@ export interface VirtualListProps<T> extends TestProps {
48
51
  /**
49
52
  * load more callback
50
53
  */
51
- onLoadMore?: (page?: number) => void;
54
+ onLoadMore?: (lastIndex?: number) => void;
52
55
  /**
53
56
  * scroll handler
54
57
  */
55
58
  onScroll?: (top: number) => void;
56
59
  }
57
- export declare const VirtualList: {
58
- <T extends KeyValue<any>>({ items, children, fullWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, ...aria }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
59
- displayName: string;
60
- };
60
+ /**
61
+ * VirtualList component for rendering large lists efficiently using virtualization.
62
+ * It supports horizontal and vertical orientations, custom item heights and widths,
63
+ * and provides a scroller for navigating through the list.
64
+ * It also supports loading more items on scroll and provides a way to hilight items.
65
+ * It can be used with a ref to control scrolling and hilighting of items.
66
+ *
67
+ * @example
68
+ * ```jsx
69
+ * <VirtualList
70
+ * items={items}
71
+ * children={({ item, index, isLast }) => (
72
+ * <div key={index} className="item">
73
+ * {item.label}
74
+ * </div>
75
+ * )}
76
+ * fullWidth={true}
77
+ * orientation="vertical"
78
+ * defaultHeight={50}
79
+ * onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
80
+ * onScroll={(top) => console.log("Scrolled to top:", top)}
81
+ * listRef={virtualListRef}
82
+ * >
83
+ * {({ item, index, isLast }) => (
84
+ * <div className="gallery-item" key={item.id}>
85
+ * <img src={item.image} alt={item.label} />
86
+ * <p>{item.label}</p>
87
+ * </div>
88
+ * )}
89
+ * </VirtualList>
90
+ * ```
91
+ */
92
+ export declare const VirtualList: <T extends unknown>({ items, total, children, fullWidth, maxWidth, minWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, ...aria }: VirtualListProps<T>) => import("react").JSX.Element;
@@ -5,4 +5,4 @@ export declare const Scroller: ({ vertical, scrollActive, onStart, onEnd, onPrev
5
5
  onEnd: () => void;
6
6
  onPrevious: () => void;
7
7
  onNext: () => void;
8
- }) => import("react/jsx-runtime").JSX.Element;
8
+ }) => import("react").JSX.Element;
package/package.json CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "@react-fabric/data",
3
- "version": "1.0.0-beta.8",
3
+ "version": "1.0.1",
4
4
  "description": "RUF: Data package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
7
- "repository": "https://github.com/adarshpastakia/react-ui-framework/tree/main/packages/data",
7
+ "repository": "https://github.com/adarshpastakia/react-fabric/tree/main/packages/data",
8
8
  "source": "src/index.ts",
9
9
  "main": "dist/cjs/index.js",
10
10
  "module": "dist/esm/index.js",
11
11
  "types": "dist/types/index.d.ts",
12
12
  "directories": {
13
13
  "src": "src",
14
+ "styles": "css",
14
15
  "test": "tests"
15
16
  },
16
17
  "files": [
18
+ "css",
17
19
  "src",
18
20
  "dist"
19
21
  ],
@@ -22,8 +24,6 @@
22
24
  "registry": "https://registry.npmjs.org/"
23
25
  },
24
26
  "scripts": {
25
- "makelink": "yarn link",
26
- "removelink": "yarn unlink",
27
27
  "prebuild": "rm -rf ./dist",
28
28
  "build:dts": "tsc -p ./tsconfig.build.json",
29
29
  "build:rollup": "rollup -c ../../rollup.config.mjs",
@@ -33,24 +33,22 @@
33
33
  "watch": "npm-run-all -p watch:rollup watch:dts"
34
34
  },
35
35
  "dependencies": {
36
- "@react-fabric/core": "^1.0.0-beta.8",
37
- "@react-fabric/date": "^1.0.0-beta.8",
38
- "@react-fabric/form": "^1.0.0-beta.8",
39
- "@react-fabric/utilities": "^1.0.0-beta.8",
40
- "@tanstack/react-virtual": "^3.8.6",
41
- "classnames": "^2.5.1",
42
- "color": "^4.2.3",
43
- "memoize-one": "^6.0.0"
36
+ "@react-fabric/core": "^1.0.1",
37
+ "@react-fabric/date": "^1.0.1",
38
+ "@react-fabric/form": "^1.0.1",
39
+ "@react-fabric/utilities": "^1.0.1",
40
+ "@tanstack/react-virtual": "~3.14.9",
41
+ "memoize-one": "~6.0.0"
44
42
  },
45
43
  "peerDependencies": {
46
- "i18next": "^23.15.1",
47
- "react": ">=18.0.0 <20.0.0",
48
- "react-dom": ">=18.0.0 <20.0.0",
49
- "react-i18next": "^15.0.2"
44
+ "i18next": "~26.3.6",
45
+ "react": "~19.3.0",
46
+ "react-dom": "~19.3.0",
47
+ "react-i18next": "~17.0.11"
50
48
  },
51
49
  "engines": {
52
- "node": ">=18.12.0",
53
- "npm": ">=8.19.0"
50
+ "node": ">=24.0.0",
51
+ "npm": ">=11.0.0"
54
52
  },
55
- "gitHead": "9f1ede6e9629c9e79121354332cdebabad5878c5"
53
+ "gitHead": "1419a9df05b5e3850e1d2b4e896ab63df702c7e8"
56
54
  }