@react-fabric/data 1.0.0-beta.54 → 1.0.0-beta.55

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 (42) hide show
  1. package/dist/cjs/hooks/useFilteredList.js +68 -10
  2. package/dist/cjs/table/HeaderCell.js +3 -2
  3. package/dist/cjs/table/Table.js +7 -1
  4. package/dist/cjs/table/useVirtualTable.js +18 -0
  5. package/dist/cjs/tree/TreeNode.js +2 -2
  6. package/dist/cjs/tree/TreePanel.js +5 -4
  7. package/dist/cjs/tree/useTree.js +62 -15
  8. package/dist/cjs/tree/utils.js +3 -3
  9. package/dist/cjs/virtual/Gallery.js +2 -2
  10. package/dist/cjs/virtual/List.js +2 -2
  11. package/dist/esm/hooks/useFilteredList.js +69 -11
  12. package/dist/esm/table/HeaderCell.js +3 -2
  13. package/dist/esm/table/Table.js +7 -1
  14. package/dist/esm/table/useVirtualTable.js +19 -1
  15. package/dist/esm/tree/TreeNode.js +2 -2
  16. package/dist/esm/tree/TreePanel.js +5 -4
  17. package/dist/esm/tree/useTree.js +63 -16
  18. package/dist/esm/tree/utils.js +3 -3
  19. package/dist/esm/virtual/Gallery.js +2 -2
  20. package/dist/esm/virtual/List.js +2 -2
  21. package/dist/types/hooks/useFilteredList.d.ts +49 -6
  22. package/dist/types/table/HeaderCell.d.ts +1 -1
  23. package/dist/types/table/Table.d.ts +1 -1
  24. package/dist/types/table/types.d.ts +3 -0
  25. package/dist/types/table/useVirtualTable.d.ts +3 -0
  26. package/dist/types/tree/TreePanel.d.ts +1 -1
  27. package/dist/types/tree/types.d.ts +11 -13
  28. package/dist/types/tree/useTree.d.ts +1 -0
  29. package/dist/types/tree/utils.d.ts +1 -1
  30. package/package.json +5 -5
  31. package/src/hooks/useFilteredList.tsx +90 -9
  32. package/src/table/HeaderCell.tsx +3 -2
  33. package/src/table/Table.tsx +5 -0
  34. package/src/table/types.ts +4 -0
  35. package/src/table/useVirtualTable.ts +24 -1
  36. package/src/tree/TreeNode.tsx +3 -5
  37. package/src/tree/TreePanel.tsx +3 -3
  38. package/src/tree/types.ts +12 -12
  39. package/src/tree/useTree.ts +57 -13
  40. package/src/tree/utils.ts +8 -3
  41. package/src/virtual/Gallery.tsx +1 -1
  42. package/src/virtual/List.tsx +1 -1
@@ -3,7 +3,7 @@
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
5
5
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
- import { groupBy, compareValues } from '@react-fabric/utilities';
6
+ import { groupBy, compareValues, debounce } from '@react-fabric/utilities';
7
7
  import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
8
8
  import { useReducer, useRef, useMemo, useState, useCallback, useEffect } from 'react';
9
9
 
@@ -137,6 +137,24 @@ var useVirtualTable = function useVirtualTable(data, options) {
137
137
  checked: (_options$checked = options.checked) !== null && _options$checked !== void 0 ? _options$checked : []
138
138
  });
139
139
  }, [options.checked]);
140
+ useEffect(function () {
141
+ if (options.onLoadMore) {
142
+ var _virtualItems$, _virtualItems$slice$p;
143
+ var firstItem = (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index;
144
+ var lastItem = virtualItems === null || virtualItems === void 0 || (_virtualItems$slice$p = virtualItems.slice(-1).pop()) === null || _virtualItems$slice$p === void 0 ? void 0 : _virtualItems$slice$p.index;
145
+ var canLoadPrevPage = firstItem !== undefined && state.items[firstItem] === null;
146
+ var canLoadNextPage = lastItem !== undefined && lastItem === state.items.length - 1 && state.items.length < options.total;
147
+ var db = debounce(options.onLoadMore);
148
+ if (canLoadPrevPage) {
149
+ db(firstItem);
150
+ } else if (!options.loading && canLoadNextPage) {
151
+ db(lastItem + 1);
152
+ }
153
+ return function () {
154
+ return db.cancel();
155
+ };
156
+ }
157
+ }, [options.onLoadMore, virtualItems]);
140
158
  return {
141
159
  scrollerRef: scrollerRef,
142
160
  items: virtualItems,
@@ -63,7 +63,7 @@ var TreeNode = function TreeNode(_ref) {
63
63
  return /*#__PURE__*/jsxs("div", {
64
64
  role: "treeitem",
65
65
  "aria-selected": node.selected,
66
- className: classNames("flex flex-nowrap items-center", node.className, node.leaf ? leafClassName : nodeClassName),
66
+ className: classNames("flex flex-nowrap items-center"),
67
67
  "data-testid": node["data-testid"],
68
68
  "data-test-value": node["data-test-value"],
69
69
  children: [filler, node.loading && /*#__PURE__*/jsx("div", {
@@ -93,7 +93,7 @@ var TreeNode = function TreeNode(_ref) {
93
93
  })
94
94
  }), !node.empty && /*#__PURE__*/jsxs("div", {
95
95
  role: "none",
96
- className: classNames("group/tool data-[selected]:bg-primary-100 flex flex-nowrap flex-1 overflow-hidden select-none", node.childSelected && "font-medium", node.disabled && "text-muted opacity-65", !node.disabled && (canSelect || onClick) && "hover:bg-primary-50 cursor-pointer"),
96
+ className: classNames("group/tool data-[selected]:bg-primary-100 flex flex-nowrap flex-1 overflow-hidden select-none", node.childSelected && "font-medium", node.disabled && "text-muted opacity-65", node.className, node.leaf ? leafClassName : nodeClassName, !node.disabled && (canSelect || onClick) && "hover:bg-primary-50 cursor-pointer"),
97
97
  "data-selected": node.selected,
98
98
  onClick: node.disabled ? undefined : function () {
99
99
  onClick === null || onClick === void 0 || onClick(node.id, node.data);
@@ -11,7 +11,7 @@ import { iconExpandAll, iconCollapseAll } from './types.js';
11
11
  import { useTree } from './useTree.js';
12
12
  import { jsxs, jsx } from 'react/jsx-runtime';
13
13
 
14
- var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onQuery", "onSelect", "onClick", "sorter", "makeLabel", "makeIcon", "defaultExpanded", "onExpandToggle", "leafClassName", "nodeClassName"];
14
+ var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onQuery", "onSelect", "onClick", "sorter", "makeLabel", "makeIcon", "defaultExpanded", "onExpandToggle", "leafClassName", "nodeClassName"];
15
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
16
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
17
  var TreePanel = function TreePanel(_ref) {
@@ -22,7 +22,6 @@ var TreePanel = function TreePanel(_ref) {
22
22
  checked = _ref.checked,
23
23
  checkable = _ref.checkable,
24
24
  noLines = _ref.noLines,
25
- renderer = _ref.renderer,
26
25
  searchable = _ref.searchable,
27
26
  selectable = _ref.selectable,
28
27
  matcher = _ref.matcher,
@@ -58,6 +57,7 @@ var TreePanel = function TreePanel(_ref) {
58
57
  onExpandToggle: onExpandToggle
59
58
  }),
60
59
  tree = _useTree.tree,
60
+ query = _useTree.query,
61
61
  toggleExpand = _useTree.toggleExpand,
62
62
  toggleCheck = _useTree.toggleCheck,
63
63
  expandAll = _useTree.expandAll,
@@ -97,6 +97,7 @@ var TreePanel = function TreePanel(_ref) {
97
97
  flex: true,
98
98
  className: "items-center p-px justify-end overflow-hidden border-b",
99
99
  children: [searchable && /*#__PURE__*/jsx(Search, {
100
+ value: query,
100
101
  onSearch: onFilter,
101
102
  allowClear: true,
102
103
  placeholder: filterPlaceholder,
@@ -134,7 +135,7 @@ var TreePanel = function TreePanel(_ref) {
134
135
  height: (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.start
135
136
  }
136
137
  }), virtualItems.map(function (_ref2) {
137
- var _makeIcon, _ref3, _ref4;
138
+ var _makeIcon, _ref3;
138
139
  var index = _ref2.index,
139
140
  key = _ref2.key;
140
141
  return /*#__PURE__*/jsx("div", {
@@ -154,7 +155,7 @@ var TreePanel = function TreePanel(_ref) {
154
155
  onClick: onClick,
155
156
  leafClassName: leafClassName,
156
157
  nodeClassName: nodeClassName,
157
- children: (_ref3 = (_ref4 = tree[index].data && (renderer === null || renderer === void 0 ? void 0 : renderer(tree[index].data))) !== null && _ref4 !== void 0 ? _ref4 : makeLabel === null || makeLabel === void 0 ? void 0 : makeLabel(tree[index].data)) !== null && _ref3 !== void 0 ? _ref3 : tree[index].label
158
+ children: (_ref3 = tree[index].data && (makeLabel === null || makeLabel === void 0 ? void 0 : makeLabel(tree[index].data))) !== null && _ref3 !== void 0 ? _ref3 : tree[index].label
158
159
  })
159
160
  }, key);
160
161
  })]
@@ -6,7 +6,7 @@ import { useDebounce } from '@react-fabric/core';
6
6
  import { EMPTY_ARRAY } from '@react-fabric/utilities';
7
7
  import memoizeOne from 'memoize-one';
8
8
  import { useRef, useCallback, useReducer, useEffect } from 'react';
9
- import { refactorTree, makeTreeMap, flattenTree, updateSelection, filterTree, updateChecked } from './utils.js';
9
+ import { refactorTree, makeTreeMap, flattenTree, updateSelection, updateChecked, filterTree } from './utils.js';
10
10
 
11
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
12
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -78,6 +78,14 @@ var useTree = function useTree(_ref) {
78
78
  });
79
79
  }
80
80
  }, [onLoad]);
81
+ var fireSelected = useDebounce(function (nodeId, data) {
82
+ var _componentEvents$curr, _componentEvents$curr2;
83
+ (_componentEvents$curr = (_componentEvents$curr2 = componentEvents.current).onSelect) === null || _componentEvents$curr === void 0 || _componentEvents$curr.call(_componentEvents$curr2, nodeId, data);
84
+ }, [onSelect]);
85
+ var fireChecked = useDebounce(function (leafs, nodes, partials) {
86
+ var _componentEvents$curr3, _componentEvents$curr4;
87
+ (_componentEvents$curr3 = (_componentEvents$curr4 = componentEvents.current).onChecked) === null || _componentEvents$curr3 === void 0 || _componentEvents$curr3.call(_componentEvents$curr4, leafs, nodes, partials);
88
+ }, [onChecked]);
81
89
  var _useReducer = useReducer(function (state, action) {
82
90
  if (action.type === "load") {
83
91
  state.items = refactorTree(action.items, {
@@ -86,6 +94,9 @@ var useTree = function useTree(_ref) {
86
94
  });
87
95
  state.itemMap = makeTreeMap(state.items);
88
96
  state.tree = flattenTree(state.items);
97
+ state.selected = undefined;
98
+ state.checked = undefined;
99
+ state.query = "";
89
100
  return _objectSpread({}, state);
90
101
  }
91
102
  if (action.type === "toggleExpand") {
@@ -97,10 +108,14 @@ var useTree = function useTree(_ref) {
97
108
  }
98
109
  }
99
110
  if (action.type === "loaded") {
111
+ var _state$checked;
100
112
  state.itemMap = makeTreeMap(state.items);
101
113
  fireExpandToggle(Array.from(state.itemMap.values()));
102
114
  state.tree = flattenTree(state.items);
103
115
  state.selected && updateSelection(state.itemMap, state.selected, true);
116
+ (_state$checked = state.checked) === null || _state$checked === void 0 || _state$checked.forEach(function (id) {
117
+ return updateChecked(state.itemMap, id, 1);
118
+ });
104
119
  return _objectSpread({}, state);
105
120
  }
106
121
  if (action.type === "expand") {
@@ -141,36 +156,58 @@ var useTree = function useTree(_ref) {
141
156
  } else {
142
157
  filterTree(state.itemMap, action.query, matcher);
143
158
  state.tree = flattenTree(state.items);
144
- return _objectSpread({}, state);
145
159
  }
160
+ return _objectSpread(_objectSpread({}, state), {}, {
161
+ query: action.query
162
+ });
163
+ }
164
+ if (action.type === "toggleSelect") {
165
+ if (state.selected) {
166
+ updateSelection(state.itemMap, state.selected);
167
+ }
168
+ if (!onSelect) {
169
+ updateSelection(state.itemMap, action.id, true);
170
+ state.selected = action.id;
171
+ state.tree = flattenTree(state.items);
172
+ } else {
173
+ var _state$itemMap$get;
174
+ fireSelected(action.id, (_state$itemMap$get = state.itemMap.get(action.id)) === null || _state$itemMap$get === void 0 ? void 0 : _state$itemMap$get.data);
175
+ }
176
+ return _objectSpread({}, state);
146
177
  }
147
178
  if (action.type === "select") {
148
- var _componentEvents$curr, _componentEvents$curr2, _state$itemMap$get;
149
179
  if (state.selected) {
150
180
  updateSelection(state.itemMap, state.selected);
151
181
  }
152
182
  updateSelection(state.itemMap, action.id, true);
183
+ state.selected = action.id;
153
184
  state.tree = flattenTree(state.items);
154
- (_componentEvents$curr = (_componentEvents$curr2 = componentEvents.current).onSelect) === null || _componentEvents$curr === void 0 || _componentEvents$curr.call(_componentEvents$curr2, action.id, (_state$itemMap$get = state.itemMap.get(action.id)) === null || _state$itemMap$get === void 0 ? void 0 : _state$itemMap$get.data);
155
- return _objectSpread(_objectSpread({}, state), {}, {
156
- selected: action.id
157
- });
185
+ return _objectSpread({}, state);
158
186
  }
159
187
  if (action.type === "toggleCheck") {
160
- var _componentEvents$curr3, _componentEvents$curr4;
161
188
  updateChecked(state.itemMap, action.id);
162
- var checkList = [[], []];
189
+ var checkList = [[], [], []];
163
190
  Array.from(state.itemMap.values()).filter(function (node) {
164
- return node.checked === 1;
191
+ return node.checked !== 0;
165
192
  }).forEach(function (node) {
166
- return checkList[node.leaf ? 0 : 1].push(node.id);
193
+ return checkList[node.leaf ? 0 : node.checked].push(node.id);
194
+ });
195
+ fireChecked(checkList[0],
196
+ // leafs
197
+ checkList[1],
198
+ // nodes
199
+ checkList[2] // partials
200
+ );
201
+ return _objectSpread(_objectSpread({}, state), {}, {
202
+ checked: checkList[0]
167
203
  });
168
- (_componentEvents$curr3 = (_componentEvents$curr4 = componentEvents.current).onChecked) === null || _componentEvents$curr3 === void 0 || _componentEvents$curr3.call(_componentEvents$curr4, checkList[0], checkList[1]);
169
- return _objectSpread({}, state);
170
204
  }
171
205
  if (action.type === "checked") {
206
+ state.itemMap.forEach(function (item) {
207
+ return item.checked = 0;
208
+ });
172
209
  action.id.forEach(function (id) {
173
- return updateChecked(state.itemMap, id);
210
+ return updateChecked(state.itemMap, id, 1);
174
211
  });
175
212
  return _objectSpread(_objectSpread({}, state), {}, {
176
213
  checked: action.id
@@ -181,7 +218,8 @@ var useTree = function useTree(_ref) {
181
218
  itemMap: new Map(),
182
219
  items: [],
183
220
  tree: [],
184
- checked: []
221
+ checked: [],
222
+ query: ""
185
223
  }),
186
224
  _useReducer2 = _slicedToArray(_useReducer, 2),
187
225
  state = _useReducer2[0],
@@ -202,6 +240,14 @@ var useTree = function useTree(_ref) {
202
240
  type: "expand",
203
241
  id: intialExpand.current.shift()
204
242
  });
243
+ selected && dispatch({
244
+ type: "select",
245
+ id: selected
246
+ });
247
+ checked && dispatch({
248
+ type: "checked",
249
+ id: checked
250
+ });
205
251
  }, [itemList]);
206
252
  useEffect(function () {
207
253
  selected && dispatch({
@@ -229,7 +275,7 @@ var useTree = function useTree(_ref) {
229
275
  }, []);
230
276
  var select = useCallback(function (id) {
231
277
  dispatch({
232
- type: "select",
278
+ type: "toggleSelect",
233
279
  id: id
234
280
  });
235
281
  }, []);
@@ -257,6 +303,7 @@ var useTree = function useTree(_ref) {
257
303
  }, [], 300);
258
304
  return {
259
305
  tree: state.tree,
306
+ query: state.query,
260
307
  toggleExpand: toggleExpand,
261
308
  expandAll: expandAll,
262
309
  collapseAll: collapseAll,
@@ -105,15 +105,15 @@ var updateSelection = function updateSelection(nodes, id, selected) {
105
105
  while (parent) {
106
106
  var parentNode = nodes.get(parent);
107
107
  parentNode && (parentNode.childSelected = selected);
108
- selected && parentNode && (parentNode.open = true);
108
+ // selected && parentNode && (parentNode.open = true);
109
109
  parent = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent;
110
110
  }
111
111
  }
112
112
  };
113
- var updateChecked = function updateChecked(list, id) {
113
+ var updateChecked = function updateChecked(list, id, checked) {
114
114
  var node = list.get(id);
115
115
  if (node) {
116
- node.checked = node.checked === 1 ? 0 : 1;
116
+ node.checked = checked === undefined ? node.checked === 0 ? 1 : 0 : checked;
117
117
  // check all children
118
118
  node.children && getChildren(node.children).forEach(function (child) {
119
119
  return child.checked = node.checked;
@@ -92,8 +92,8 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
92
92
  var virtualItems = virtualizer.getVirtualItems();
93
93
  var currentIndex = useRef(0);
94
94
  useEffect(function () {
95
- var _virtualItems$1$index, _virtualItems$;
96
- currentIndex.current = (_virtualItems$1$index = (_virtualItems$ = virtualItems[1]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$1$index !== void 0 ? _virtualItems$1$index : 0;
95
+ var _virtualItems$2$index, _virtualItems$;
96
+ currentIndex.current = (_virtualItems$2$index = (_virtualItems$ = virtualItems[2]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$2$index !== void 0 ? _virtualItems$2$index : 0;
97
97
  if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
98
98
  }, [virtualItems]);
99
99
  var calculateActiveScroll = useCallback(function () {
@@ -68,8 +68,8 @@ var _VirtualList = function _VirtualList(_ref) {
68
68
  var virtualItems = virtualizer.getVirtualItems();
69
69
  var currentIndex = useRef(0);
70
70
  useEffect(function () {
71
- var _virtualItems$1$index, _virtualItems$;
72
- currentIndex.current = (_virtualItems$1$index = (_virtualItems$ = virtualItems[1]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$1$index !== void 0 ? _virtualItems$1$index : 0;
71
+ var _virtualItems$2$index, _virtualItems$;
72
+ currentIndex.current = (_virtualItems$2$index = (_virtualItems$ = virtualItems[2]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$2$index !== void 0 ? _virtualItems$2$index : 0;
73
73
  if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
74
74
  }, [virtualItems]);
75
75
  var calculateActiveScroll = useCallback(function () {
@@ -1,3 +1,29 @@
1
+ interface RetType<T, Q> {
2
+ onSearch: (query?: Q) => void;
3
+ query: Q;
4
+ filteredList: T[];
5
+ isSearching: boolean;
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>;
1
27
  /**
2
28
  * Custom hook to filter a list of items based on a query.
3
29
  * It provides a way to search through the items and returns the filtered list.
@@ -17,9 +43,26 @@
17
43
  *
18
44
  * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
19
45
  */
20
- export declare const useFilteredList: <T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matcher?: (item: T, query: Q) => boolean) => {
21
- onSearch: import("react").Dispatch<import("react").SetStateAction<Q | undefined>>;
22
- query: Q | undefined;
23
- filteredList: T[];
24
- isSearching: boolean;
25
- };
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 {};
@@ -1,2 +1,2 @@
1
1
  import { type TableColumn, type TableProps } from "./types";
2
- export declare const HeaderCell: ({ id, dataType, label, icon, iconBg, iconColor, rtlFlip, 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;
2
+ export declare const HeaderCell: ({ id, field, dataType, label, icon, iconBg, iconColor, rtlFlip, 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;
@@ -12,4 +12,4 @@ import { type TableProps } from "./types";
12
12
  * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/data-table--table}
13
13
  * @see {@link https://tanstack.com/table/v8/docs/api/virtual}
14
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, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
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;
@@ -33,6 +33,7 @@ export declare const COL_DEFAULT_WIDTH = "12rem";
33
33
  */
34
34
  export interface TableColumn<T = KeyValue> extends CssProp, IconProps, TestProps {
35
35
  id: keyof T | string;
36
+ field?: string;
36
37
  label?: string;
37
38
  tooltip?: string;
38
39
  actions?: ReactElement[];
@@ -91,4 +92,6 @@ export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
91
92
  canExpand?: (record: T) => boolean;
92
93
  children?: (record: T) => Elements<AnyObject>;
93
94
  onFilter?: (id: keyof T | string, value?: AnyObject) => void;
95
+ total?: number;
96
+ onLoadMore?: (lastIndex?: number) => void;
94
97
  }
@@ -11,6 +11,9 @@ export declare const useVirtualTable: <T extends KeyValue = KeyValue>(data: T[],
11
11
  checked?: AnyObject[];
12
12
  keyProperty: keyof T;
13
13
  groupProperty?: keyof T;
14
+ loading?: boolean;
15
+ total: number;
16
+ onLoadMore?: (startIndex: number) => void;
14
17
  onCheckChanged?: (checked: AnyObject[]) => void;
15
18
  }) => {
16
19
  scrollerRef: import("react").RefObject<HTMLDivElement | null>;
@@ -40,4 +40,4 @@ import { type TreePanelProps } from "./types";
40
40
  *
41
41
  * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-treepanel--docs}
42
42
  */
43
- export declare const TreePanel: <T extends KeyValue>({ ref, items, selected, checked, checkable, noLines, renderer, searchable, selectable, 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;
43
+ export declare const TreePanel: <T extends KeyValue>({ ref, items, selected, checked, checkable, noLines, searchable, selectable, 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,5 +1,4 @@
1
1
  import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
2
- import { type ElementType } from "react";
3
2
  interface TreeBaseNode<T> extends Omit<IconProps, "icon">, CssProp, TestProps {
4
3
  id: string;
5
4
  /**
@@ -23,7 +22,7 @@ interface TreeBaseNode<T> extends Omit<IconProps, "icon">, CssProp, TestProps {
23
22
  */
24
23
  disabled?: boolean;
25
24
  data?: T;
26
- icon?: ElementType<IconProps> | string;
25
+ icon?: Elements<JSX.Element>;
27
26
  }
28
27
  export type TreeNodeType<T extends KeyValue = KeyValue> = TreeBaseNode<T> & ({
29
28
  leaf: true;
@@ -51,7 +50,7 @@ export interface InternalNode extends Omit<IconProps, "icon">, CssProp, TestProp
51
50
  loaded: boolean;
52
51
  parent?: string;
53
52
  empty?: boolean;
54
- icon?: ElementType<IconProps> | string;
53
+ icon?: Elements<JSX.Element>;
55
54
  errored?: string;
56
55
  selected?: true;
57
56
  childSelected?: true;
@@ -63,8 +62,8 @@ export interface InternalNode extends Omit<IconProps, "icon">, CssProp, TestProp
63
62
  export interface TreeNodeProps extends ChildProp {
64
63
  node: InternalNode;
65
64
  expanders: [string, string];
66
- defaultNodeIcon?: string;
67
- defaultLeafIcon?: string;
65
+ defaultNodeIcon?: Elements<JSX.Element>;
66
+ defaultLeafIcon?: Elements<JSX.Element>;
68
67
  noLines?: boolean;
69
68
  selectable?: true | "leafOnly";
70
69
  checkable?: true | "leafOnly";
@@ -136,22 +135,21 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
136
135
  /**
137
136
  * callback on selection of tree node
138
137
  */
139
- onSelect?: (id: string, data: T) => void;
138
+ onSelect?: (id: string, data: T) => boolean | undefined;
140
139
  /**
141
140
  * callback on change of checked list
141
+ * @param leafs - list of checked leaf nodes
142
+ * @param nodes - list of checked nodes
143
+ * @param partials - list of partially checked nodes
142
144
  */
143
- onChecked?: (leafs: string[], nodes: string[]) => void;
144
- /**
145
- * item label renderer
146
- */
147
- renderer?: (data: T) => JSX.Element;
145
+ onChecked?: (leafs: string[], nodes: string[], partials: string[]) => void;
148
146
  /**
149
147
  * item filter matcher
150
148
  */
151
149
  matcher?: (data: T, query: string) => boolean;
152
150
  sorter?: false | ((a: T, b: T) => number);
153
- makeLabel?: (node: T) => string;
154
- makeIcon?: (node: T) => string;
151
+ makeLabel?: (node: T) => Elements<JSX.Element>;
152
+ makeIcon?: (node: T) => Elements<JSX.Element>;
155
153
  defaultExpanded?: string[];
156
154
  onExpandToggle?: (id: string[]) => void;
157
155
  leafClassName?: string;
@@ -1,6 +1,7 @@
1
1
  import { type InternalNode, type TreePanelProps } from "./types";
2
2
  export declare const useTree: <T extends KeyValue>({ items, checked, selected, sorter, matcher, onLoad, onQuery, onSelect, onChecked, defaultExpanded, onExpandToggle, }: Partial<TreePanelProps<T>>) => {
3
3
  tree: InternalNode[];
4
+ query: string | undefined;
4
5
  toggleExpand: (id: string) => void;
5
6
  expandAll: () => void;
6
7
  collapseAll: () => void;
@@ -9,5 +9,5 @@ export declare const refactorTree: (nodes: TreeNodeType[], { sorter, defaultExpa
9
9
  export declare const makeTreeMap: (nodes: InternalNode[], map?: Map<any, any>) => Map<any, any>;
10
10
  export declare const flattenTree: (nodes: InternalNode[], lines?: Array<0 | 1 | 2 | 3>) => InternalNode[];
11
11
  export declare const updateSelection: (nodes: Map<string, InternalNode>, id: string, selected?: true) => void;
12
- export declare const updateChecked: (list: Map<string, AnyObject>, id: string) => void;
12
+ export declare const updateChecked: (list: Map<string, AnyObject>, id: string, checked?: 0 | 1 | 2) => void;
13
13
  export declare const filterTree: (nodes: Map<string, InternalNode>, query?: string, matcher?: AnyObject) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/data",
3
- "version": "1.0.0-beta.54",
3
+ "version": "1.0.0-beta.55",
4
4
  "description": "RUF: Data package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -35,9 +35,9 @@
35
35
  "watch": "npm-run-all -p watch:rollup watch:dts"
36
36
  },
37
37
  "dependencies": {
38
- "@react-fabric/core": "^1.0.0-beta.54",
39
- "@react-fabric/date": "^1.0.0-beta.54",
40
- "@react-fabric/form": "^1.0.0-beta.54",
38
+ "@react-fabric/core": "^1.0.0-beta.55",
39
+ "@react-fabric/date": "^1.0.0-beta.55",
40
+ "@react-fabric/form": "^1.0.0-beta.55",
41
41
  "@react-fabric/utilities": "^1.0.0-beta.52",
42
42
  "@tanstack/react-virtual": "^3.13.9",
43
43
  "classnames": "^2.5.1",
@@ -54,5 +54,5 @@
54
54
  "node": ">=18.12.0",
55
55
  "npm": ">=8.19.0"
56
56
  },
57
- "gitHead": "242f15e3de29d365cce6f41f4ef99ab36bb6b995"
57
+ "gitHead": "c8454798fb7546174ee8c7ea10e491c5e903e789"
58
58
  }