@react-fabric/data 1.0.0-beta.0 → 1.0.0-beta.11
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/checklist/CheckList.js +143 -0
- package/dist/cjs/histogram/Histogram.js +14 -5
- package/dist/cjs/hooks/useSelectableList.js +54 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/table/AddColumn.js +56 -0
- package/dist/cjs/table/BodyCell.js +47 -6
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/CheckboxCell.js +44 -0
- package/dist/cjs/table/Context.js +43 -0
- package/dist/cjs/table/EmptyCell.js +52 -0
- package/dist/cjs/table/HeaderCell.js +78 -32
- package/dist/cjs/table/Table.js +173 -96
- package/dist/cjs/table/types.js +32 -0
- package/dist/cjs/table/useResizer.js +65 -0
- package/dist/cjs/table/useTableColumns.js +45 -8
- package/dist/cjs/table/useVirtualTable.js +56 -25
- package/dist/cjs/tree/TreePanel.js +14 -2
- package/dist/cjs/tree/useTree.js +7 -0
- package/dist/cjs/virtual/Gallery.js +11 -4
- package/dist/cjs/virtual/List.js +11 -4
- package/dist/esm/checklist/CheckList.js +143 -0
- package/dist/esm/histogram/Histogram.js +14 -5
- package/dist/esm/hooks/useSelectableList.js +54 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/table/AddColumn.js +56 -0
- package/dist/esm/table/BodyCell.js +47 -6
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/CheckboxCell.js +44 -0
- package/dist/esm/table/Context.js +42 -0
- package/dist/esm/table/EmptyCell.js +52 -0
- package/dist/esm/table/HeaderCell.js +80 -34
- package/dist/esm/table/Table.js +174 -97
- package/dist/esm/table/types.js +30 -0
- package/dist/esm/table/useResizer.js +65 -0
- package/dist/esm/table/useTableColumns.js +46 -9
- package/dist/esm/table/useVirtualTable.js +57 -26
- package/dist/esm/tree/TreePanel.js +15 -3
- package/dist/esm/tree/useTree.js +7 -0
- package/dist/esm/virtual/Gallery.js +11 -4
- package/dist/esm/virtual/List.js +11 -4
- package/dist/types/checklist/CheckList.d.ts +30 -0
- package/dist/types/histogram/Histogram.d.ts +3 -3
- package/dist/types/hooks/useSelectableList.d.ts +28 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/table/AddColumn.d.ts +5 -0
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/CheckboxCell.d.ts +4 -0
- package/dist/types/table/Context.d.ts +8 -0
- package/dist/types/table/EmptyCell.d.ts +2 -0
- package/dist/types/table/HeaderCell.d.ts +2 -2
- package/dist/types/table/Table.d.ts +1 -1
- package/dist/types/table/types.d.ts +41 -7
- package/dist/types/table/useResizer.d.ts +1 -0
- package/dist/types/table/useTableColumns.d.ts +8 -6
- package/dist/types/table/useVirtualTable.d.ts +13 -1
- package/dist/types/tree/TreePanel.d.ts +1 -1
- package/dist/types/tree/types.d.ts +6 -2
- package/dist/types/tree/useTree.d.ts +1 -0
- package/dist/types/virtual/Gallery.d.ts +3 -2
- package/dist/types/virtual/List.d.ts +3 -2
- package/package.json +6 -5
- package/src/checklist/CheckList.tsx +222 -0
- package/src/histogram/Histogram.tsx +7 -2
- package/src/hooks/useSelectableList.ts +94 -0
- package/src/index.ts +3 -0
- package/src/table/AddColumn.tsx +55 -0
- package/src/table/BodyCell.tsx +47 -6
- package/src/table/BodyRow.tsx +142 -0
- package/src/table/CheckboxCell.tsx +48 -0
- package/src/table/Context.tsx +70 -0
- package/src/table/EmptyCell.tsx +57 -0
- package/src/table/HeaderCell.tsx +93 -25
- package/src/table/Table.tsx +194 -87
- package/src/table/types.ts +42 -6
- package/src/table/useResizer.ts +66 -0
- package/src/table/useTableColumns.ts +52 -19
- package/src/table/useVirtualTable.ts +61 -2
- package/src/tree/TreePanel.tsx +12 -1
- package/src/tree/types.ts +8 -1
- package/src/tree/useTree.ts +5 -0
- package/src/virtual/Gallery.tsx +4 -1
- package/src/virtual/List.tsx +4 -1
package/dist/esm/table/Table.js
CHANGED
|
@@ -1,132 +1,209 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useDebounce, Loading, EmptyContent } from '@react-fabric/core';
|
|
5
|
+
import { debounce } from '@react-fabric/utilities';
|
|
6
|
+
import { useRef, useMemo, useLayoutEffect, useImperativeHandle, useEffect } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { AddColumn } from './AddColumn.js';
|
|
9
|
+
import { BodyRow } from './BodyRow.js';
|
|
10
|
+
import { CheckboxCell } from './CheckboxCell.js';
|
|
11
|
+
import { TableProvider } from './Context.js';
|
|
12
|
+
import { EmptyCell } from './EmptyCell.js';
|
|
6
13
|
import { HeaderCell } from './HeaderCell.js';
|
|
7
14
|
import { useTableColumns } from './useTableColumns.js';
|
|
8
15
|
import { useVirtualTable } from './useVirtualTable.js';
|
|
9
|
-
import classNames from 'classnames';
|
|
10
16
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
11
17
|
|
|
12
18
|
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; }
|
|
13
19
|
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; }
|
|
14
20
|
var Table = function Table(_ref) {
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
|
|
21
|
+
var _state$start, _state$cols, _state$end, _items$, _state$start2, _state$cols2, _state$end2;
|
|
22
|
+
var ref = _ref.ref,
|
|
23
|
+
data = _ref.data,
|
|
24
|
+
columns = _ref.columns,
|
|
25
|
+
keyProperty = _ref.keyProperty,
|
|
26
|
+
checkableRows = _ref.checkableRows,
|
|
27
|
+
initialScroll = _ref.initialScroll,
|
|
28
|
+
hideableColumns = _ref.hideableColumns,
|
|
29
|
+
sort = _ref.sort,
|
|
30
|
+
loading = _ref.loading,
|
|
31
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
32
|
+
canExpand = _ref.canExpand,
|
|
33
|
+
children = _ref.children,
|
|
34
|
+
onSort = _ref.onSort,
|
|
35
|
+
onScroll = _ref.onScroll,
|
|
36
|
+
onRowClick = _ref.onRowClick,
|
|
37
|
+
onCheckedChanged = _ref.onCheckedChanged;
|
|
38
|
+
var _useTranslation = useTranslation("data"),
|
|
39
|
+
t = _useTranslation.t;
|
|
40
|
+
var fireCheckChanged = useDebounce(function (checkedIds) {
|
|
41
|
+
return onCheckedChanged === null || onCheckedChanged === void 0 ? void 0 : onCheckedChanged(checkedIds);
|
|
42
|
+
}, []);
|
|
18
43
|
var _useTableColumns = useTableColumns(columns),
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
state = _useTableColumns.state,
|
|
45
|
+
onHide = _useTableColumns.onHide;
|
|
46
|
+
var _useVirtualTable = useVirtualTable(data, keyProperty, fireCheckChanged),
|
|
21
47
|
scrollerRef = _useVirtualTable.scrollerRef,
|
|
22
48
|
items = _useVirtualTable.items,
|
|
49
|
+
top = _useVirtualTable.top,
|
|
50
|
+
checkState = _useVirtualTable.checkState,
|
|
51
|
+
virtualizer = _useVirtualTable.virtualizer,
|
|
52
|
+
toggleExpand = _useVirtualTable.toggleExpand,
|
|
53
|
+
toggleChecked = _useVirtualTable.toggleChecked,
|
|
54
|
+
toggleAllChecked = _useVirtualTable.toggleAllChecked,
|
|
23
55
|
getData = _useVirtualTable.getData,
|
|
24
56
|
totalSize = _useVirtualTable.totalSize,
|
|
25
57
|
measureElement = _useVirtualTable.measureElement;
|
|
58
|
+
var refBody = useRef(null);
|
|
26
59
|
var wrapperStart = useMemo(function () {
|
|
27
60
|
return "bg-inherit sticky start-0 flex flex-nowrap z-1";
|
|
28
61
|
}, []);
|
|
29
62
|
var wrapperEnd = useMemo(function () {
|
|
30
63
|
return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
|
|
31
64
|
}, []);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
65
|
+
useLayoutEffect(function () {
|
|
66
|
+
setTimeout(function () {
|
|
67
|
+
initialScroll && virtualizer.scrollToIndex(initialScroll, {
|
|
68
|
+
align: "start"
|
|
69
|
+
});
|
|
70
|
+
}, 100);
|
|
71
|
+
}, []);
|
|
72
|
+
useImperativeHandle(ref, function () {
|
|
73
|
+
return {
|
|
74
|
+
scrollTo: function scrollTo(row) {
|
|
75
|
+
virtualizer.scrollToIndex(row, {
|
|
76
|
+
align: "start"
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
hilight: function hilight(row) {
|
|
80
|
+
var _scrollerRef$current;
|
|
81
|
+
(_scrollerRef$current = scrollerRef.current) === null || _scrollerRef$current === void 0 || (_scrollerRef$current = _scrollerRef$current.querySelector(".hilight")) === null || _scrollerRef$current === void 0 || _scrollerRef$current.classList.remove("hilight", "ring-1");
|
|
82
|
+
virtualizer.scrollToIndex(Math.floor(row), {
|
|
83
|
+
align: "start"
|
|
84
|
+
});
|
|
85
|
+
setTimeout(function () {
|
|
86
|
+
var _scrollerRef$current2;
|
|
87
|
+
(_scrollerRef$current2 = scrollerRef.current) === null || _scrollerRef$current2 === void 0 || (_scrollerRef$current2 = _scrollerRef$current2.querySelector("[data-index=\"".concat(row, "\"]"))) === null || _scrollerRef$current2 === void 0 || _scrollerRef$current2.classList.add("hilight", "ring-1");
|
|
88
|
+
}, 100);
|
|
89
|
+
},
|
|
90
|
+
unhilight: function unhilight() {
|
|
91
|
+
var _scrollerRef$current3;
|
|
92
|
+
(_scrollerRef$current3 = scrollerRef.current) === null || _scrollerRef$current3 === void 0 || (_scrollerRef$current3 = _scrollerRef$current3.querySelector(".hilight")) === null || _scrollerRef$current3 === void 0 || _scrollerRef$current3.classList.remove("hilight", "ring-1");
|
|
40
93
|
}
|
|
41
|
-
}
|
|
94
|
+
};
|
|
42
95
|
}, []);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
}), (_columnMap$cols = columnMap.cols) === null || _columnMap$cols === void 0 ? void 0 : _columnMap$cols.map(function (col, idx) {
|
|
57
|
-
return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
|
|
58
|
-
}), /*#__PURE__*/jsx("div", {
|
|
59
|
-
className: wrapperEnd,
|
|
60
|
-
children: (_columnMap$end = columnMap.end) === null || _columnMap$end === void 0 ? void 0 : _columnMap$end.map(function (col, idx) {
|
|
61
|
-
return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
|
|
62
|
-
})
|
|
63
|
-
})]
|
|
64
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
65
|
-
className: "area-content flex flex-col flex-nowrap",
|
|
96
|
+
useEffect(function () {
|
|
97
|
+
var handle = debounce(function (top) {
|
|
98
|
+
onScroll === null || onScroll === void 0 || onScroll(top !== null && top !== void 0 ? top : 0);
|
|
99
|
+
});
|
|
100
|
+
handle(top);
|
|
101
|
+
return function () {
|
|
102
|
+
handle.cancel();
|
|
103
|
+
};
|
|
104
|
+
}, [top]);
|
|
105
|
+
return /*#__PURE__*/jsx(TableProvider, {
|
|
106
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
107
|
+
className: "grid area-content overflow-auto relative",
|
|
66
108
|
style: {
|
|
67
|
-
|
|
109
|
+
gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
|
|
68
110
|
},
|
|
69
|
-
|
|
111
|
+
ref: scrollerRef,
|
|
112
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
113
|
+
className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
|
|
114
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
115
|
+
className: wrapperStart,
|
|
116
|
+
children: [canExpand && /*#__PURE__*/jsx("div", {
|
|
117
|
+
className: "w-6"
|
|
118
|
+
}), checkableRows && /*#__PURE__*/jsx(CheckboxCell, {
|
|
119
|
+
state: checkState.allChecked,
|
|
120
|
+
onClick: toggleAllChecked
|
|
121
|
+
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
|
|
122
|
+
return /*#__PURE__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
|
|
123
|
+
sort: sort,
|
|
124
|
+
onSort: onSort
|
|
125
|
+
}), idx);
|
|
126
|
+
})]
|
|
127
|
+
}), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idx) {
|
|
128
|
+
return /*#__PURE__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
|
|
129
|
+
sort: sort,
|
|
130
|
+
onSort: onSort
|
|
131
|
+
}), idx);
|
|
132
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
133
|
+
className: wrapperEnd,
|
|
134
|
+
children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, idx) {
|
|
135
|
+
return /*#__PURE__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
|
|
136
|
+
sort: sort,
|
|
137
|
+
onSort: onSort
|
|
138
|
+
}), idx);
|
|
139
|
+
}), hideableColumns && /*#__PURE__*/jsx(AddColumn, {
|
|
140
|
+
onClick: onHide,
|
|
141
|
+
columns: state.columns.filter(function (col) {
|
|
142
|
+
return col.hideable !== false;
|
|
143
|
+
})
|
|
144
|
+
})]
|
|
145
|
+
})]
|
|
146
|
+
}), loading && /*#__PURE__*/jsx(Loading, {}), data.length > 0 && /*#__PURE__*/jsxs("div", {
|
|
147
|
+
className: "area-content flex flex-col flex-nowrap",
|
|
70
148
|
style: {
|
|
71
|
-
height: (
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
149
|
+
height: totalSize()
|
|
150
|
+
},
|
|
151
|
+
ref: refBody,
|
|
152
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
153
|
+
style: {
|
|
154
|
+
height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
|
|
155
|
+
}
|
|
156
|
+
}), items.map(function (_ref2) {
|
|
157
|
+
var index = _ref2.index,
|
|
158
|
+
key = _ref2.key;
|
|
159
|
+
var data = getData(index);
|
|
160
|
+
return /*#__PURE__*/jsx(BodyRow, {
|
|
161
|
+
rowKey: key,
|
|
162
|
+
index: index,
|
|
163
|
+
checkableRows: checkableRows,
|
|
164
|
+
checked: keyProperty && checkState.checked.includes(data[keyProperty]) ? 1 : 0,
|
|
165
|
+
expanded: !!keyProperty && checkState.expanded.includes(data[keyProperty]),
|
|
166
|
+
data: data,
|
|
167
|
+
hideableColumns: hideableColumns,
|
|
168
|
+
keyProperty: keyProperty,
|
|
169
|
+
measureElement: measureElement,
|
|
170
|
+
onRowClick: onRowClick,
|
|
171
|
+
state: state,
|
|
172
|
+
canExpand: canExpand,
|
|
173
|
+
toggleExpand: toggleExpand,
|
|
174
|
+
expandRow: children,
|
|
175
|
+
toggleChecked: toggleChecked,
|
|
176
|
+
wrapperEnd: wrapperEnd,
|
|
177
|
+
wrapperStart: wrapperStart
|
|
178
|
+
}, key);
|
|
179
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
180
|
+
className: "flex-1 flex flex-nowrap",
|
|
181
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
82
182
|
className: wrapperStart,
|
|
83
|
-
children:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}, "".concat(key, ":").concat(idc));
|
|
94
|
-
}), /*#__PURE__*/jsx("div", {
|
|
183
|
+
children: [canExpand && /*#__PURE__*/jsx("div", {
|
|
184
|
+
className: "w-6"
|
|
185
|
+
}), checkableRows && /*#__PURE__*/jsx("div", {
|
|
186
|
+
className: "w-6"
|
|
187
|
+
}), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col) {
|
|
188
|
+
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
189
|
+
})]
|
|
190
|
+
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col) {
|
|
191
|
+
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
192
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
95
193
|
className: wrapperEnd,
|
|
96
|
-
children: (
|
|
97
|
-
return /*#__PURE__*/jsx(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})
|
|
194
|
+
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col) {
|
|
195
|
+
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
196
|
+
}), hideableColumns && /*#__PURE__*/jsx("div", {
|
|
197
|
+
className: "w-6"
|
|
198
|
+
})]
|
|
102
199
|
})]
|
|
103
|
-
}, key);
|
|
104
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
105
|
-
className: "flex-1 flex flex-nowrap",
|
|
106
|
-
children: [/*#__PURE__*/jsx("div", {
|
|
107
|
-
className: wrapperStart,
|
|
108
|
-
children: (_columnMap$start3 = columnMap.start) === null || _columnMap$start3 === void 0 ? void 0 : _columnMap$start3.map(emptyCol)
|
|
109
|
-
}), (_columnMap$cols3 = columnMap.cols) === null || _columnMap$cols3 === void 0 ? void 0 : _columnMap$cols3.map(emptyCol), /*#__PURE__*/jsx("div", {
|
|
110
|
-
className: wrapperEnd,
|
|
111
|
-
children: (_columnMap$end3 = columnMap.end) === null || _columnMap$end3 === void 0 ? void 0 : _columnMap$end3.map(emptyCol)
|
|
112
200
|
})]
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
|
|
120
|
-
})
|
|
121
|
-
}), (_columnMap$cols4 = columnMap.cols) === null || _columnMap$cols4 === void 0 ? void 0 : _columnMap$cols4.map(function (col, idx) {
|
|
122
|
-
return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
|
|
123
|
-
}), /*#__PURE__*/jsx("div", {
|
|
124
|
-
className: wrapperEnd,
|
|
125
|
-
children: (_columnMap$end4 = columnMap.end) === null || _columnMap$end4 === void 0 ? void 0 : _columnMap$end4.map(function (col, idx) {
|
|
126
|
-
return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
|
|
127
|
-
})
|
|
128
|
-
})]
|
|
129
|
-
})]
|
|
201
|
+
}), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsx(EmptyContent, {
|
|
202
|
+
size: "sm",
|
|
203
|
+
className: "bg-dimmed",
|
|
204
|
+
message: t("datagrid.empty")
|
|
205
|
+
}))]
|
|
206
|
+
})
|
|
130
207
|
});
|
|
131
208
|
};
|
|
132
209
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version: 1.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
12
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
* subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
18
|
+
* portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
var COL_MIN_WIDTH = "3rem";
|
|
27
|
+
var COL_MAX_WIDTH = "64rem";
|
|
28
|
+
var COL_DEFAULT_WIDTH = "12rem";
|
|
29
|
+
|
|
30
|
+
export { COL_DEFAULT_WIDTH, COL_MAX_WIDTH, COL_MIN_WIDTH };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version: 1.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
12
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
* subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
18
|
+
* portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
var useResizer = function useResizer(colEl, ghostEl, callback) {
|
|
27
|
+
var placeholder = ghostEl.firstElementChild;
|
|
28
|
+
var isRtl = getComputedStyle(colEl).direction === "rtl";
|
|
29
|
+
var onResize = function onResize(evt) {
|
|
30
|
+
/** ***************** check if reverse enabled of RTL *******************/
|
|
31
|
+
var box = colEl.getBoundingClientRect();
|
|
32
|
+
var x = isRtl ? box.left - evt.clientX : evt.clientX - box.right;
|
|
33
|
+
placeholder.style.width = "".concat(colEl.offsetWidth + x, "px");
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** ***************** dettach handlers on mouseup *******************/
|
|
37
|
+
var onResizeEnd = function onResizeEnd() {
|
|
38
|
+
callback(placeholder.offsetWidth);
|
|
39
|
+
ghostEl.style.display = "none";
|
|
40
|
+
document.removeEventListener("mousemove", onResize);
|
|
41
|
+
document.removeEventListener("mouseup", onResizeEnd);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** ***************** attach handlers *******************/
|
|
45
|
+
var box = colEl.getBoundingClientRect();
|
|
46
|
+
if (colEl.parentElement != null) {
|
|
47
|
+
var _colEl$parentElement;
|
|
48
|
+
var parentBox = (_colEl$parentElement = colEl.parentElement) === null || _colEl$parentElement === void 0 ? void 0 : _colEl$parentElement.getBoundingClientRect();
|
|
49
|
+
if (isRtl) {
|
|
50
|
+
placeholder.style.left = "unset";
|
|
51
|
+
placeholder.style.right = "".concat(box.right - parentBox.right, "px");
|
|
52
|
+
} else {
|
|
53
|
+
placeholder.style.right = "unset";
|
|
54
|
+
placeholder.style.left = "".concat(box.left - parentBox.left, "px");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
placeholder.style.width = "".concat(colEl.offsetWidth, "px");
|
|
58
|
+
placeholder.style.minWidth = colEl.style.minWidth || "48px";
|
|
59
|
+
placeholder.style.maxWidth = colEl.style.maxWidth || "75vw";
|
|
60
|
+
ghostEl.style.display = "block";
|
|
61
|
+
document.addEventListener("mousemove", onResize);
|
|
62
|
+
document.addEventListener("mouseup", onResizeEnd);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { useResizer };
|
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
5
|
import { groupBy } from '@react-fabric/utilities';
|
|
5
|
-
import {
|
|
6
|
+
import { useReducer, useEffect } from 'react';
|
|
6
7
|
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
7
10
|
var useTableColumns = function useTableColumns(columns) {
|
|
8
|
-
var
|
|
11
|
+
var _useReducer = useReducer(function (state, action) {
|
|
12
|
+
if (action.type === "columns") {
|
|
13
|
+
state.columns = action.columns;
|
|
14
|
+
}
|
|
15
|
+
if (action.type === "hide") {
|
|
16
|
+
var col = state.columns.find(function (col) {
|
|
17
|
+
return col.id === action.id;
|
|
18
|
+
});
|
|
19
|
+
col && state.columns.splice(state.columns.indexOf(col), 1, _objectSpread(_objectSpread({}, col), {}, {
|
|
20
|
+
hidden: col.hidden !== true
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
var _groupBy = groupBy(state.columns.filter(function (col) {
|
|
24
|
+
return col.hidden !== true;
|
|
25
|
+
}), "locked", "cols"),
|
|
26
|
+
_groupBy$start = _groupBy.start,
|
|
27
|
+
start = _groupBy$start === void 0 ? [] : _groupBy$start,
|
|
28
|
+
_groupBy$end = _groupBy.end,
|
|
29
|
+
end = _groupBy$end === void 0 ? [] : _groupBy$end,
|
|
30
|
+
_groupBy$cols = _groupBy.cols,
|
|
31
|
+
cols = _groupBy$cols === void 0 ? [] : _groupBy$cols;
|
|
32
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
33
|
+
start: start,
|
|
34
|
+
end: end,
|
|
35
|
+
cols: cols
|
|
36
|
+
});
|
|
37
|
+
}, {
|
|
38
|
+
columns: [],
|
|
9
39
|
start: [],
|
|
10
40
|
end: [],
|
|
11
41
|
cols: []
|
|
12
42
|
}),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
43
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
44
|
+
state = _useReducer2[0],
|
|
45
|
+
dispatch = _useReducer2[1];
|
|
16
46
|
useEffect(function () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
dispatch({
|
|
48
|
+
type: "columns",
|
|
49
|
+
columns: columns
|
|
50
|
+
});
|
|
20
51
|
}, [columns]);
|
|
21
52
|
return {
|
|
22
|
-
|
|
53
|
+
state: state,
|
|
54
|
+
onHide: function onHide(id) {
|
|
55
|
+
return dispatch({
|
|
56
|
+
type: "hide",
|
|
57
|
+
id: id
|
|
58
|
+
});
|
|
59
|
+
}
|
|
23
60
|
};
|
|
24
61
|
};
|
|
25
62
|
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
5
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
4
|
-
import { useRef, useCallback } from 'react';
|
|
6
|
+
import { useRef, useReducer, useCallback } from 'react';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* The MIT License (MIT)
|
|
12
|
-
* Copyright (c) 2024 Adarsh Pastakia
|
|
13
|
-
*
|
|
14
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
15
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
16
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
*
|
|
20
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
21
|
-
* portions of the Software.
|
|
22
|
-
*
|
|
23
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
24
|
-
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
25
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
26
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
var useVirtualTable = function useVirtualTable(data) {
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged) {
|
|
11
|
+
var _virtualizer$range;
|
|
30
12
|
// TODO: refactor data into item list, apply grouping if groupColumn provided
|
|
31
13
|
// TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
|
|
32
14
|
|
|
@@ -40,6 +22,35 @@ var useVirtualTable = function useVirtualTable(data) {
|
|
|
40
22
|
return 24;
|
|
41
23
|
}
|
|
42
24
|
});
|
|
25
|
+
var _useReducer = useReducer(function (state, action) {
|
|
26
|
+
if (action.type === "expand") {
|
|
27
|
+
if (state.expanded.includes(action.key)) state.expanded.splice(state.expanded.indexOf(action.key), 1);else state.expanded.push(action.key);
|
|
28
|
+
}
|
|
29
|
+
if (action.type === "check") {
|
|
30
|
+
if (state.checked.includes(action.key)) state.checked.splice(state.checked.indexOf(action.key), 1);else state.checked.push(action.key);
|
|
31
|
+
onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
|
|
32
|
+
}
|
|
33
|
+
if (action.type === "checkall") {
|
|
34
|
+
if (state.allChecked !== 0) {
|
|
35
|
+
state.checked = [];
|
|
36
|
+
} else if (keyProperty) {
|
|
37
|
+
state.checked = data.map(function (item) {
|
|
38
|
+
return item[keyProperty];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
|
|
42
|
+
}
|
|
43
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
44
|
+
allChecked: state.checked.length === data.length ? 1 : state.checked.length ? 2 : 0
|
|
45
|
+
});
|
|
46
|
+
}, {
|
|
47
|
+
checked: [],
|
|
48
|
+
expanded: [],
|
|
49
|
+
allChecked: 0
|
|
50
|
+
}),
|
|
51
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
52
|
+
state = _useReducer2[0],
|
|
53
|
+
dispatch = _useReducer2[1];
|
|
43
54
|
var virtualItems = virtualizer.getVirtualItems();
|
|
44
55
|
var getData = useCallback(function (index) {
|
|
45
56
|
return data[index];
|
|
@@ -47,9 +58,29 @@ var useVirtualTable = function useVirtualTable(data) {
|
|
|
47
58
|
return {
|
|
48
59
|
scrollerRef: scrollerRef,
|
|
49
60
|
items: virtualItems,
|
|
61
|
+
checkState: state,
|
|
50
62
|
getData: getData,
|
|
63
|
+
virtualizer: virtualizer,
|
|
64
|
+
top: (_virtualizer$range = virtualizer.range) === null || _virtualizer$range === void 0 ? void 0 : _virtualizer$range.startIndex,
|
|
51
65
|
totalSize: virtualizer.getTotalSize,
|
|
52
|
-
measureElement: virtualizer.measureElement
|
|
66
|
+
measureElement: virtualizer.measureElement,
|
|
67
|
+
toggleExpand: function toggleExpand(key) {
|
|
68
|
+
return dispatch({
|
|
69
|
+
type: "expand",
|
|
70
|
+
key: key
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
toggleChecked: function toggleChecked(key) {
|
|
74
|
+
return dispatch({
|
|
75
|
+
type: "check",
|
|
76
|
+
key: key
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
toggleAllChecked: function toggleAllChecked() {
|
|
80
|
+
return dispatch({
|
|
81
|
+
type: "checkall"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
53
84
|
};
|
|
54
85
|
};
|
|
55
86
|
|
|
@@ -5,18 +5,19 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
5
5
|
import { CoreIcons, Section, Header, Icon, ButtonGroup, Button } from '@react-fabric/core';
|
|
6
6
|
import { Search } from '@react-fabric/form';
|
|
7
7
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
8
|
-
import { useRef, useMemo } from 'react';
|
|
8
|
+
import { useRef, useMemo, useImperativeHandle } from 'react';
|
|
9
9
|
import { TreeNode } from './TreeNode.js';
|
|
10
10
|
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 = ["items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
|
|
14
|
+
var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
|
|
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) {
|
|
18
18
|
var _virtualItems$;
|
|
19
|
-
var
|
|
19
|
+
var ref = _ref.ref,
|
|
20
|
+
items = _ref.items,
|
|
20
21
|
selected = _ref.selected,
|
|
21
22
|
checked = _ref.checked,
|
|
22
23
|
checkable = _ref.checkable,
|
|
@@ -48,6 +49,7 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
48
49
|
expandAll = _useTree.expandAll,
|
|
49
50
|
collapseAll = _useTree.collapseAll,
|
|
50
51
|
select = _useTree.select,
|
|
52
|
+
expand = _useTree.expand,
|
|
51
53
|
onFilter = _useTree.onFilter;
|
|
52
54
|
var scrollerRef = useRef(null);
|
|
53
55
|
var virtualizer = useVirtualizer({
|
|
@@ -66,6 +68,16 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
66
68
|
if (expander === "folder") return [CoreIcons.folderClosed, CoreIcons.folderOpen];
|
|
67
69
|
return [CoreIcons.expand, CoreIcons.collapse];
|
|
68
70
|
}, [expander]);
|
|
71
|
+
useImperativeHandle(ref, function () {
|
|
72
|
+
return {
|
|
73
|
+
open: function open(id) {
|
|
74
|
+
return expand(id);
|
|
75
|
+
},
|
|
76
|
+
select: function select(id) {
|
|
77
|
+
return expand(id);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}, []);
|
|
69
81
|
return /*#__PURE__*/jsxs(Section, {
|
|
70
82
|
children: [/*#__PURE__*/jsxs(Header, {
|
|
71
83
|
flex: true,
|
package/dist/esm/tree/useTree.js
CHANGED
|
@@ -151,6 +151,12 @@ var useTree = function useTree(_ref) {
|
|
|
151
151
|
id: id
|
|
152
152
|
});
|
|
153
153
|
}, []);
|
|
154
|
+
var expand = useCallback(function (id) {
|
|
155
|
+
dispatch({
|
|
156
|
+
type: "expand",
|
|
157
|
+
id: id
|
|
158
|
+
});
|
|
159
|
+
}, []);
|
|
154
160
|
var expandAll = useCallback(function () {
|
|
155
161
|
dispatch({
|
|
156
162
|
type: "expandAll"
|
|
@@ -174,6 +180,7 @@ var useTree = function useTree(_ref) {
|
|
|
174
180
|
collapseAll: collapseAll,
|
|
175
181
|
toggleCheck: toggleCheck,
|
|
176
182
|
select: select,
|
|
183
|
+
expand: expand,
|
|
177
184
|
onFilter: onFilter
|
|
178
185
|
};
|
|
179
186
|
};
|