@react-fabric/data 1.0.0-beta.41 → 1.0.0-beta.43
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.
- package/dist/cjs/table/BodyCell.js +2 -2
- package/dist/cjs/table/BodyRow.js +1 -1
- package/dist/cjs/table/Table.js +1 -1
- package/dist/cjs/table/useVirtualTable.js +13 -10
- package/dist/esm/table/BodyCell.js +2 -2
- package/dist/esm/table/BodyRow.js +1 -1
- package/dist/esm/table/Table.js +1 -1
- package/dist/esm/table/useVirtualTable.js +13 -10
- package/dist/types/table/useVirtualTable.d.ts +1 -0
- package/package.json +6 -6
- package/src/table/BodyCell.tsx +2 -2
- package/src/table/BodyRow.tsx +1 -1
- package/src/table/Table.tsx +1 -1
- package/src/table/useVirtualTable.ts +17 -10
|
@@ -46,7 +46,7 @@ var BodyCell = function BodyCell(_ref) {
|
|
|
46
46
|
var _column$dataType;
|
|
47
47
|
var value = utilities.getByPath(item, column.id.toString());
|
|
48
48
|
if (column.renderer != null) {
|
|
49
|
-
return column.renderer(
|
|
49
|
+
return column.renderer(value, item, index);
|
|
50
50
|
}
|
|
51
51
|
if (column.dataType === "boolean") {
|
|
52
52
|
var _column$valueMap;
|
|
@@ -73,7 +73,7 @@ var BodyCell = function BodyCell(_ref) {
|
|
|
73
73
|
return value !== null && value !== void 0 ? value : "";
|
|
74
74
|
}, [item, column]);
|
|
75
75
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
76
|
-
className: "overflow-hidden bg-inherit start-0 border-e",
|
|
76
|
+
className: "overflow-hidden bg-inherit start-0 border-e group/table-col",
|
|
77
77
|
style: {
|
|
78
78
|
width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
|
|
79
79
|
minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : types.COL_MIN_WIDTH,
|
|
@@ -55,7 +55,7 @@ var BodyRow = function BodyRow(_ref) {
|
|
|
55
55
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
56
56
|
role: "none",
|
|
57
57
|
"data-row": index,
|
|
58
|
-
className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", onRowClick && "hover:bg-primary-50 active:bg-primary-100", index % 2 ? "bg-even" : "bg-odd"),
|
|
58
|
+
className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500 group/table-row", onRowClick && "hover:bg-primary-50 active:bg-primary-100", index % 2 ? "bg-even" : "bg-odd"),
|
|
59
59
|
onClick: function onClick() {
|
|
60
60
|
return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
|
|
61
61
|
},
|
package/dist/cjs/table/Table.js
CHANGED
|
@@ -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 === "
|
|
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
|
-
|
|
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: "
|
|
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({
|
|
@@ -46,7 +46,7 @@ var BodyCell = function BodyCell(_ref) {
|
|
|
46
46
|
var _column$dataType;
|
|
47
47
|
var value = getByPath(item, column.id.toString());
|
|
48
48
|
if (column.renderer != null) {
|
|
49
|
-
return column.renderer(
|
|
49
|
+
return column.renderer(value, item, index);
|
|
50
50
|
}
|
|
51
51
|
if (column.dataType === "boolean") {
|
|
52
52
|
var _column$valueMap;
|
|
@@ -73,7 +73,7 @@ var BodyCell = function BodyCell(_ref) {
|
|
|
73
73
|
return value !== null && value !== void 0 ? value : "";
|
|
74
74
|
}, [item, column]);
|
|
75
75
|
return /*#__PURE__*/jsx("div", {
|
|
76
|
-
className: "overflow-hidden bg-inherit start-0 border-e",
|
|
76
|
+
className: "overflow-hidden bg-inherit start-0 border-e group/table-col",
|
|
77
77
|
style: {
|
|
78
78
|
width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
|
|
79
79
|
minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : COL_MIN_WIDTH,
|
|
@@ -55,7 +55,7 @@ var BodyRow = function BodyRow(_ref) {
|
|
|
55
55
|
children: [/*#__PURE__*/jsxs("div", {
|
|
56
56
|
role: "none",
|
|
57
57
|
"data-row": index,
|
|
58
|
-
className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", onRowClick && "hover:bg-primary-50 active:bg-primary-100", index % 2 ? "bg-even" : "bg-odd"),
|
|
58
|
+
className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500 group/table-row", onRowClick && "hover:bg-primary-50 active:bg-primary-100", index % 2 ? "bg-even" : "bg-odd"),
|
|
59
59
|
onClick: function onClick() {
|
|
60
60
|
return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
|
|
61
61
|
},
|
package/dist/esm/table/Table.js
CHANGED
|
@@ -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 === "
|
|
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
|
-
|
|
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: "
|
|
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({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/data",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.43",
|
|
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.
|
|
39
|
-
"@react-fabric/date": "^1.0.0-beta.
|
|
40
|
-
"@react-fabric/form": "^1.0.0-beta.
|
|
41
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
38
|
+
"@react-fabric/core": "^1.0.0-beta.43",
|
|
39
|
+
"@react-fabric/date": "^1.0.0-beta.43",
|
|
40
|
+
"@react-fabric/form": "^1.0.0-beta.43",
|
|
41
|
+
"@react-fabric/utilities": "^1.0.0-beta.43",
|
|
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": "
|
|
57
|
+
"gitHead": "92cd2fc5c71e3f0e00a9cff83ff924c51d7adb57"
|
|
58
58
|
}
|
package/src/table/BodyCell.tsx
CHANGED
|
@@ -52,7 +52,7 @@ export const BodyCell = ({
|
|
|
52
52
|
const content = useMemo(() => {
|
|
53
53
|
const value = getByPath(item, column.id.toString());
|
|
54
54
|
if (column.renderer != null) {
|
|
55
|
-
return column.renderer(
|
|
55
|
+
return column.renderer(value, item, index);
|
|
56
56
|
}
|
|
57
57
|
if (column.dataType === "boolean") {
|
|
58
58
|
const map = column.valueMap ?? { true: "Yes", false: "no" };
|
|
@@ -74,7 +74,7 @@ export const BodyCell = ({
|
|
|
74
74
|
|
|
75
75
|
return (
|
|
76
76
|
<div
|
|
77
|
-
className="overflow-hidden bg-inherit start-0 border-e"
|
|
77
|
+
className="overflow-hidden bg-inherit start-0 border-e group/table-col"
|
|
78
78
|
style={{
|
|
79
79
|
width: width ?? COL_DEFAULT_WIDTH,
|
|
80
80
|
minWidth: column.minWidth ?? COL_MIN_WIDTH,
|
package/src/table/BodyRow.tsx
CHANGED
|
@@ -74,7 +74,7 @@ export const BodyRow = ({
|
|
|
74
74
|
role="none"
|
|
75
75
|
data-row={index}
|
|
76
76
|
className={classNames(
|
|
77
|
-
"flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500",
|
|
77
|
+
"flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500 group/table-row",
|
|
78
78
|
onRowClick && "hover:bg-primary-50 active:bg-primary-100",
|
|
79
79
|
index % 2 ? "bg-even" : "bg-odd",
|
|
80
80
|
)}
|
package/src/table/Table.tsx
CHANGED
|
@@ -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: "
|
|
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 === "
|
|
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 ===
|
|
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
|
-
|
|
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: "
|
|
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 ?? [] });
|