@react-fabric/data 1.0.0-beta.41 → 1.0.0-beta.42

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.
@@ -159,7 +159,7 @@ var Table = function Table(_ref) {
159
159
  })]
160
160
  })]
161
161
  }), loading && /*#__PURE__*/jsxRuntime.jsx(core.Loading, {}), data.length > 0 && /*#__PURE__*/jsxRuntime.jsxs("div", {
162
- className: "area-content flex flex-col flex-nowrap",
162
+ className: "area-content flex flex-col flex-nowrap min-h-full",
163
163
  style: {
164
164
  height: totalSize()
165
165
  },
@@ -31,13 +31,13 @@ var useVirtualTable = function useVirtualTable(data, options) {
31
31
  if (state.allChecked !== 0) {
32
32
  state.checked = [];
33
33
  } else if (options.keyProperty) {
34
- state.checked = data.map(function (item) {
34
+ state.checked = state.data.map(function (item) {
35
35
  return item[options.keyProperty];
36
36
  });
37
37
  }
38
38
  (_options$onCheckChang2 = options.onCheckChanged) === null || _options$onCheckChang2 === void 0 || _options$onCheckChang2.call(options, state.checked);
39
39
  }
40
- var checkList = data.filter(function (hit) {
40
+ var checkList = state.data.filter(function (hit) {
41
41
  return state.checked.includes(hit[options.keyProperty]);
42
42
  });
43
43
  if (action.type === "groupExpand") {
@@ -52,9 +52,10 @@ var useVirtualTable = function useVirtualTable(data, options) {
52
52
  }).flat(2).filter(Boolean);
53
53
  }
54
54
  }
55
- if (action.type === "grouped") {
55
+ if (action.type === "reset") {
56
+ state.data = action.data;
56
57
  if (action.key) {
57
- state.grouped = utilities.groupBy(data, action.key);
58
+ state.grouped = utilities.groupBy(state.data, action.key);
58
59
  state.groups = Object.keys(state.grouped).sort(utilities.compareValues("asc")).map(function (group) {
59
60
  return {
60
61
  __GROUP__: true,
@@ -68,14 +69,15 @@ var useVirtualTable = function useVirtualTable(data, options) {
68
69
  return [group].concat(_toConsumableArray(state.grouped[group.key]));
69
70
  }).flat();
70
71
  } else {
71
- state.items = data;
72
+ state.items = state.data;
72
73
  }
73
74
  }
74
75
  return _objectSpread(_objectSpread({}, state), {}, {
75
- allChecked: checkList.length === data.length ? 1 : state.checked.length ? 2 : 0
76
+ allChecked: checkList.length === state.data.length ? 1 : state.checked.length ? 2 : 0
76
77
  });
77
78
  }, {
78
- items: data,
79
+ data: data,
80
+ items: [],
79
81
  grouped: {},
80
82
  groups: [],
81
83
  checked: [],
@@ -123,10 +125,11 @@ var useVirtualTable = function useVirtualTable(data, options) {
123
125
  }, [state.items]);
124
126
  react.useEffect(function () {
125
127
  dispatch({
126
- type: "grouped",
127
- key: options.groupProperty
128
+ type: "reset",
129
+ key: options.groupProperty,
130
+ data: data
128
131
  });
129
- }, [options.groupProperty]);
132
+ }, [data, options.groupProperty]);
130
133
  react.useEffect(function () {
131
134
  var _options$checked;
132
135
  dispatch({
@@ -159,7 +159,7 @@ var Table = function Table(_ref) {
159
159
  })]
160
160
  })]
161
161
  }), loading && /*#__PURE__*/jsx(Loading, {}), data.length > 0 && /*#__PURE__*/jsxs("div", {
162
- className: "area-content flex flex-col flex-nowrap",
162
+ className: "area-content flex flex-col flex-nowrap min-h-full",
163
163
  style: {
164
164
  height: totalSize()
165
165
  },
@@ -31,13 +31,13 @@ var useVirtualTable = function useVirtualTable(data, options) {
31
31
  if (state.allChecked !== 0) {
32
32
  state.checked = [];
33
33
  } else if (options.keyProperty) {
34
- state.checked = data.map(function (item) {
34
+ state.checked = state.data.map(function (item) {
35
35
  return item[options.keyProperty];
36
36
  });
37
37
  }
38
38
  (_options$onCheckChang2 = options.onCheckChanged) === null || _options$onCheckChang2 === void 0 || _options$onCheckChang2.call(options, state.checked);
39
39
  }
40
- var checkList = data.filter(function (hit) {
40
+ var checkList = state.data.filter(function (hit) {
41
41
  return state.checked.includes(hit[options.keyProperty]);
42
42
  });
43
43
  if (action.type === "groupExpand") {
@@ -52,9 +52,10 @@ var useVirtualTable = function useVirtualTable(data, options) {
52
52
  }).flat(2).filter(Boolean);
53
53
  }
54
54
  }
55
- if (action.type === "grouped") {
55
+ if (action.type === "reset") {
56
+ state.data = action.data;
56
57
  if (action.key) {
57
- state.grouped = groupBy(data, action.key);
58
+ state.grouped = groupBy(state.data, action.key);
58
59
  state.groups = Object.keys(state.grouped).sort(compareValues("asc")).map(function (group) {
59
60
  return {
60
61
  __GROUP__: true,
@@ -68,14 +69,15 @@ var useVirtualTable = function useVirtualTable(data, options) {
68
69
  return [group].concat(_toConsumableArray(state.grouped[group.key]));
69
70
  }).flat();
70
71
  } else {
71
- state.items = data;
72
+ state.items = state.data;
72
73
  }
73
74
  }
74
75
  return _objectSpread(_objectSpread({}, state), {}, {
75
- allChecked: checkList.length === data.length ? 1 : state.checked.length ? 2 : 0
76
+ allChecked: checkList.length === state.data.length ? 1 : state.checked.length ? 2 : 0
76
77
  });
77
78
  }, {
78
- items: data,
79
+ data: data,
80
+ items: [],
79
81
  grouped: {},
80
82
  groups: [],
81
83
  checked: [],
@@ -123,10 +125,11 @@ var useVirtualTable = function useVirtualTable(data, options) {
123
125
  }, [state.items]);
124
126
  useEffect(function () {
125
127
  dispatch({
126
- type: "grouped",
127
- key: options.groupProperty
128
+ type: "reset",
129
+ key: options.groupProperty,
130
+ data: data
128
131
  });
129
- }, [options.groupProperty]);
132
+ }, [data, options.groupProperty]);
130
133
  useEffect(function () {
131
134
  var _options$checked;
132
135
  dispatch({
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  interface DataState<T = KeyValue> {
3
+ data: T[];
3
4
  items: T[];
4
5
  grouped: KeyValue<T[]>;
5
6
  groups: AnyObject[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/data",
3
- "version": "1.0.0-beta.41",
3
+ "version": "1.0.0-beta.42",
4
4
  "description": "RUF: Data package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -35,10 +35,10 @@
35
35
  "watch": "npm-run-all -p watch:rollup watch:dts"
36
36
  },
37
37
  "dependencies": {
38
- "@react-fabric/core": "^1.0.0-beta.41",
39
- "@react-fabric/date": "^1.0.0-beta.41",
40
- "@react-fabric/form": "^1.0.0-beta.41",
41
- "@react-fabric/utilities": "^1.0.0-beta.41",
38
+ "@react-fabric/core": "^1.0.0-beta.42",
39
+ "@react-fabric/date": "^1.0.0-beta.42",
40
+ "@react-fabric/form": "^1.0.0-beta.42",
41
+ "@react-fabric/utilities": "^1.0.0-beta.42",
42
42
  "@tanstack/react-virtual": "^3.8.6",
43
43
  "classnames": "^2.5.1",
44
44
  "color": "^4.2.3",
@@ -54,5 +54,5 @@
54
54
  "node": ">=18.12.0",
55
55
  "npm": ">=8.19.0"
56
56
  },
57
- "gitHead": "bc737416d3c6a217a6b8c47291c3975a22722d80"
57
+ "gitHead": "61c9612bb2c7bc9a807f46922881432748c9e7a3"
58
58
  }
@@ -198,7 +198,7 @@ export const Table = <T extends KeyValue = KeyValue>({
198
198
  {loading && <Loading />}
199
199
  {data.length > 0 && (
200
200
  <div
201
- className="area-content flex flex-col flex-nowrap"
201
+ className="area-content flex flex-col flex-nowrap min-h-full"
202
202
  style={{ height: totalSize() }}
203
203
  ref={refBody}
204
204
  >
@@ -37,6 +37,7 @@ import {
37
37
  } from "react";
38
38
 
39
39
  interface DataState<T = KeyValue> {
40
+ data: T[];
40
41
  items: T[];
41
42
  grouped: KeyValue<T[]>;
42
43
  groups: AnyObject[];
@@ -48,7 +49,7 @@ interface DataState<T = KeyValue> {
48
49
  type DataAction =
49
50
  | { type: "updateState"; checked: AnyObject[] }
50
51
  | { type: "groupExpand"; key: AnyObject }
51
- | { type: "grouped"; key: AnyObject }
52
+ | { type: "reset"; key: AnyObject; data: AnyObject[] }
52
53
  | { type: "expand"; key: AnyObject }
53
54
  | { type: "check"; key: AnyObject }
54
55
  | { type: "checkall" };
@@ -85,11 +86,11 @@ export const useVirtualTable = <T extends KeyValue = KeyValue>(
85
86
  if (state.allChecked !== 0) {
86
87
  state.checked = [];
87
88
  } else if (options.keyProperty) {
88
- state.checked = data.map((item) => item[options.keyProperty]);
89
+ state.checked = state.data.map((item) => item[options.keyProperty]);
89
90
  }
90
91
  options.onCheckChanged?.(state.checked);
91
92
  }
92
- const checkList = data.filter((hit) =>
93
+ const checkList = state.data.filter((hit) =>
93
94
  state.checked.includes(hit[options.keyProperty]),
94
95
  );
95
96
  if (action.type === "groupExpand") {
@@ -106,9 +107,10 @@ export const useVirtualTable = <T extends KeyValue = KeyValue>(
106
107
  .filter(Boolean) as any;
107
108
  }
108
109
  }
109
- if (action.type === "grouped") {
110
+ if (action.type === "reset") {
111
+ state.data = action.data;
110
112
  if (action.key) {
111
- state.grouped = groupBy<T>(data, action.key);
113
+ state.grouped = groupBy<T>(state.data, action.key);
112
114
  state.groups = Object.keys(state.grouped)
113
115
  .sort(compareValues("asc"))
114
116
  .map((group) => ({
@@ -122,17 +124,22 @@ export const useVirtualTable = <T extends KeyValue = KeyValue>(
122
124
  .map((group) => [group, ...state.grouped[group.key]])
123
125
  .flat() as any;
124
126
  } else {
125
- state.items = data;
127
+ state.items = state.data;
126
128
  }
127
129
  }
128
130
  return {
129
131
  ...state,
130
132
  allChecked:
131
- checkList.length === data.length ? 1 : state.checked.length ? 2 : 0,
133
+ checkList.length === state.data.length
134
+ ? 1
135
+ : state.checked.length
136
+ ? 2
137
+ : 0,
132
138
  } as DataState<T>;
133
139
  },
134
140
  {
135
- items: data,
141
+ data,
142
+ items: [],
136
143
  grouped: {},
137
144
  groups: [],
138
145
  checked: [],
@@ -188,8 +195,8 @@ export const useVirtualTable = <T extends KeyValue = KeyValue>(
188
195
  );
189
196
 
190
197
  useEffect(() => {
191
- dispatch({ type: "grouped", key: options.groupProperty });
192
- }, [options.groupProperty]);
198
+ dispatch({ type: "reset", key: options.groupProperty, data });
199
+ }, [data, options.groupProperty]);
193
200
 
194
201
  useEffect(() => {
195
202
  dispatch({ type: "updateState", checked: options.checked ?? [] });