@react-fabric/data 1.0.0-beta.3 → 1.0.0-beta.30
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 +16 -5
- package/dist/cjs/hooks/usePagination.js +7 -4
- package/dist/cjs/hooks/useSelectableList.js +54 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/table/BodyCell.js +38 -5
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/CheckboxCell.js +1 -1
- package/dist/cjs/table/HeaderCell.js +29 -36
- package/dist/cjs/table/Table.js +104 -66
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +118 -17
- package/dist/cjs/tree/TreeNode.js +44 -24
- package/dist/cjs/tree/TreePanel.js +28 -10
- package/dist/cjs/tree/useTree.js +96 -14
- package/dist/cjs/tree/utils.js +20 -5
- package/dist/cjs/virtual/Gallery.js +41 -27
- package/dist/cjs/virtual/List.js +41 -29
- package/dist/esm/checklist/CheckList.js +143 -0
- package/dist/esm/histogram/Histogram.js +16 -5
- package/dist/esm/hooks/usePagination.js +7 -4
- package/dist/esm/hooks/useSelectableList.js +54 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/table/BodyCell.js +38 -5
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/CheckboxCell.js +1 -1
- package/dist/esm/table/HeaderCell.js +30 -37
- package/dist/esm/table/Table.js +106 -68
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +120 -19
- package/dist/esm/tree/TreeNode.js +46 -26
- package/dist/esm/tree/TreePanel.js +28 -10
- package/dist/esm/tree/useTree.js +98 -16
- package/dist/esm/tree/utils.js +20 -5
- package/dist/esm/virtual/Gallery.js +41 -27
- package/dist/esm/virtual/List.js +41 -29
- 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 +2 -1
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/EmptyCell.d.ts +2 -2
- 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 +19 -8
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +20 -5
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +1 -1
- package/dist/types/tree/types.d.ts +25 -5
- package/dist/types/tree/useTree.d.ts +2 -9
- package/dist/types/tree/utils.d.ts +4 -1
- package/dist/types/virtual/Gallery.d.ts +11 -3
- package/dist/types/virtual/List.d.ts +7 -3
- package/package.json +8 -7
- package/src/checklist/CheckList.tsx +222 -0
- package/src/histogram/Histogram.tsx +9 -2
- package/src/hooks/usePagination.tsx +13 -7
- package/src/hooks/useSelectableList.ts +94 -0
- package/src/index.ts +2 -1
- package/src/table/AddColumn.tsx +2 -2
- package/src/table/BodyCell.tsx +34 -5
- package/src/table/BodyRow.tsx +143 -0
- package/src/table/CheckboxCell.tsx +1 -1
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +27 -13
- package/src/table/Table.tsx +141 -73
- package/src/table/types.ts +22 -7
- package/src/table/useResizer.ts +5 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +142 -27
- package/src/tree/TreeNode.tsx +90 -56
- package/src/tree/TreePanel.tsx +23 -3
- package/src/tree/types.ts +32 -4
- package/src/tree/useTree.ts +102 -23
- package/src/tree/utils.ts +23 -8
- package/src/virtual/Gallery.tsx +43 -32
- package/src/virtual/List.tsx +38 -25
package/dist/esm/table/Table.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
-
import { useDebounce, Loading, EmptyContent } from '@react-fabric/core';
|
|
4
|
+
import { useDebounce, Loading, Icon, CoreIcons, EmptyContent } from '@react-fabric/core';
|
|
5
|
+
import { debounce } from '@react-fabric/utilities';
|
|
5
6
|
import classNames from 'classnames';
|
|
6
|
-
import { useRef, useMemo, useImperativeHandle } from 'react';
|
|
7
|
+
import { useRef, useMemo, useLayoutEffect, useImperativeHandle, useEffect } from 'react';
|
|
7
8
|
import { useTranslation } from 'react-i18next';
|
|
8
9
|
import { AddColumn } from './AddColumn.js';
|
|
9
|
-
import {
|
|
10
|
+
import { BodyRow } from './BodyRow.js';
|
|
10
11
|
import { CheckboxCell } from './CheckboxCell.js';
|
|
11
12
|
import { TableProvider } from './Context.js';
|
|
12
13
|
import { EmptyCell } from './EmptyCell.js';
|
|
@@ -18,16 +19,25 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
18
19
|
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; }
|
|
19
20
|
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; }
|
|
20
21
|
var Table = function Table(_ref) {
|
|
21
|
-
var _state$start, _state$cols, _state$end, _items
|
|
22
|
+
var _state$start, _state$cols, _state$end, _items, _state$start2, _state$cols2, _state$end2;
|
|
22
23
|
var ref = _ref.ref,
|
|
23
24
|
data = _ref.data,
|
|
24
25
|
columns = _ref.columns,
|
|
25
|
-
keyProperty = _ref.keyProperty,
|
|
26
|
+
_ref$keyProperty = _ref.keyProperty,
|
|
27
|
+
keyProperty = _ref$keyProperty === void 0 ? "id" : _ref$keyProperty,
|
|
28
|
+
groupProperty = _ref.groupProperty,
|
|
26
29
|
checkableRows = _ref.checkableRows,
|
|
30
|
+
initialScroll = _ref.initialScroll,
|
|
27
31
|
hideableColumns = _ref.hideableColumns,
|
|
28
32
|
sort = _ref.sort,
|
|
29
33
|
loading = _ref.loading,
|
|
34
|
+
checked = _ref.checked,
|
|
35
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
36
|
+
groupRenderer = _ref.groupRenderer,
|
|
37
|
+
canExpand = _ref.canExpand,
|
|
38
|
+
children = _ref.children,
|
|
30
39
|
onSort = _ref.onSort,
|
|
40
|
+
onScroll = _ref.onScroll,
|
|
31
41
|
onRowClick = _ref.onRowClick,
|
|
32
42
|
onCheckedChanged = _ref.onCheckedChanged;
|
|
33
43
|
var _useTranslation = useTranslation("data"),
|
|
@@ -38,14 +48,25 @@ var Table = function Table(_ref) {
|
|
|
38
48
|
var _useTableColumns = useTableColumns(columns),
|
|
39
49
|
state = _useTableColumns.state,
|
|
40
50
|
onHide = _useTableColumns.onHide;
|
|
41
|
-
var _useVirtualTable = useVirtualTable(data,
|
|
51
|
+
var _useVirtualTable = useVirtualTable(data, {
|
|
52
|
+
checked: checked,
|
|
53
|
+
keyProperty: keyProperty,
|
|
54
|
+
groupProperty: groupProperty,
|
|
55
|
+
onCheckChanged: fireCheckChanged
|
|
56
|
+
}),
|
|
42
57
|
scrollerRef = _useVirtualTable.scrollerRef,
|
|
43
58
|
items = _useVirtualTable.items,
|
|
59
|
+
top = _useVirtualTable.top,
|
|
44
60
|
checkState = _useVirtualTable.checkState,
|
|
61
|
+
virtualizer = _useVirtualTable.virtualizer,
|
|
62
|
+
hasActiveSticky = _useVirtualTable.hasActiveSticky,
|
|
63
|
+
toggleExpand = _useVirtualTable.toggleExpand,
|
|
45
64
|
toggleChecked = _useVirtualTable.toggleChecked,
|
|
46
65
|
toggleAllChecked = _useVirtualTable.toggleAllChecked,
|
|
66
|
+
toggleGroupExpand = _useVirtualTable.toggleGroupExpand,
|
|
47
67
|
getData = _useVirtualTable.getData,
|
|
48
68
|
totalSize = _useVirtualTable.totalSize,
|
|
69
|
+
isActiveSticky = _useVirtualTable.isActiveSticky,
|
|
49
70
|
measureElement = _useVirtualTable.measureElement;
|
|
50
71
|
var refBody = useRef(null);
|
|
51
72
|
var wrapperStart = useMemo(function () {
|
|
@@ -54,47 +75,62 @@ var Table = function Table(_ref) {
|
|
|
54
75
|
var wrapperEnd = useMemo(function () {
|
|
55
76
|
return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
|
|
56
77
|
}, []);
|
|
78
|
+
useLayoutEffect(function () {
|
|
79
|
+
setTimeout(function () {
|
|
80
|
+
initialScroll && virtualizer.scrollToIndex(initialScroll, {
|
|
81
|
+
align: "start"
|
|
82
|
+
});
|
|
83
|
+
}, 100);
|
|
84
|
+
}, []);
|
|
57
85
|
useImperativeHandle(ref, function () {
|
|
58
86
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return el && (el.dataset.hilight = undefined);
|
|
63
|
-
});
|
|
64
|
-
var el = (_refBody$current2 = refBody.current) === null || _refBody$current2 === void 0 ? void 0 : _refBody$current2.querySelector("[data-row=\"".concat(row, "\"]"));
|
|
65
|
-
el === null || el === void 0 || el.scrollIntoView({
|
|
66
|
-
behavior: "smooth",
|
|
67
|
-
block: "center"
|
|
87
|
+
scrollTo: function scrollTo(row) {
|
|
88
|
+
virtualizer.scrollToIndex(row, {
|
|
89
|
+
align: "start"
|
|
68
90
|
});
|
|
69
|
-
el && (el.dataset.hilight = "true");
|
|
70
91
|
},
|
|
71
|
-
|
|
72
|
-
var
|
|
73
|
-
(
|
|
74
|
-
|
|
92
|
+
hilight: function hilight(row) {
|
|
93
|
+
var _scrollerRef$current;
|
|
94
|
+
(_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");
|
|
95
|
+
virtualizer.scrollToIndex(Math.floor(row), {
|
|
96
|
+
align: "start"
|
|
75
97
|
});
|
|
98
|
+
setTimeout(function () {
|
|
99
|
+
var _scrollerRef$current2;
|
|
100
|
+
(_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");
|
|
101
|
+
}, 100);
|
|
76
102
|
},
|
|
77
|
-
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
el === null || el === void 0 || el.scrollIntoView({
|
|
81
|
-
behavior: "smooth"
|
|
82
|
-
});
|
|
103
|
+
unhilight: function unhilight() {
|
|
104
|
+
var _scrollerRef$current3;
|
|
105
|
+
(_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");
|
|
83
106
|
}
|
|
84
107
|
};
|
|
85
108
|
}, []);
|
|
109
|
+
useEffect(function () {
|
|
110
|
+
var handle = debounce(function (top) {
|
|
111
|
+
onScroll === null || onScroll === void 0 || onScroll(top !== null && top !== void 0 ? top : 0);
|
|
112
|
+
});
|
|
113
|
+
handle(top);
|
|
114
|
+
return function () {
|
|
115
|
+
handle.cancel();
|
|
116
|
+
};
|
|
117
|
+
}, [top]);
|
|
86
118
|
return /*#__PURE__*/jsx(TableProvider, {
|
|
87
119
|
children: /*#__PURE__*/jsxs("div", {
|
|
88
120
|
className: "grid area-content overflow-auto relative",
|
|
89
121
|
style: {
|
|
90
122
|
gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
|
|
91
123
|
},
|
|
124
|
+
"data-ref": "tableScroller",
|
|
92
125
|
ref: scrollerRef,
|
|
93
126
|
children: [/*#__PURE__*/jsxs("div", {
|
|
127
|
+
"data-ref": "tableHeader",
|
|
94
128
|
className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
|
|
95
129
|
children: [/*#__PURE__*/jsxs("div", {
|
|
96
130
|
className: wrapperStart,
|
|
97
|
-
children: [
|
|
131
|
+
children: [canExpand && /*#__PURE__*/jsx("div", {
|
|
132
|
+
className: "w-6"
|
|
133
|
+
}), checkableRows && /*#__PURE__*/jsx(CheckboxCell, {
|
|
98
134
|
state: checkState.allChecked,
|
|
99
135
|
onClick: toggleAllChecked
|
|
100
136
|
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
|
|
@@ -130,77 +166,79 @@ var Table = function Table(_ref) {
|
|
|
130
166
|
ref: refBody,
|
|
131
167
|
children: [/*#__PURE__*/jsx("div", {
|
|
132
168
|
style: {
|
|
133
|
-
height: (_items
|
|
169
|
+
height: (_items = items[hasActiveSticky ? 1 : 0]) === null || _items === void 0 ? void 0 : _items.start
|
|
134
170
|
}
|
|
135
171
|
}), items.map(function (_ref2) {
|
|
136
|
-
var
|
|
172
|
+
var _groupRenderer;
|
|
137
173
|
var index = _ref2.index,
|
|
138
174
|
key = _ref2.key;
|
|
139
175
|
var data = getData(index);
|
|
140
|
-
return /*#__PURE__*/jsxs("div", {
|
|
176
|
+
return "__GROUP__" in data ? /*#__PURE__*/jsxs("div", {
|
|
177
|
+
ref: measureElement,
|
|
178
|
+
"data-index": index,
|
|
179
|
+
className: classNames("px-2 py-1 text-md bg-base border-y border-tint-100 cursor-pointer flex items-center gap-1", isActiveSticky(index) && "sticky top-8 z-30"),
|
|
141
180
|
role: "none",
|
|
142
|
-
"data-row": index,
|
|
143
|
-
className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
|
|
144
181
|
onClick: function onClick() {
|
|
145
|
-
return
|
|
182
|
+
return toggleGroupExpand(data.key);
|
|
146
183
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return /*#__PURE__*/jsx(BodyCell, {
|
|
158
|
-
column: col,
|
|
159
|
-
item: data
|
|
160
|
-
}, "".concat(key, ":").concat(ids));
|
|
161
|
-
})]
|
|
162
|
-
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col, idc) {
|
|
163
|
-
return /*#__PURE__*/jsx(BodyCell, {
|
|
164
|
-
column: col,
|
|
165
|
-
item: data
|
|
166
|
-
}, "".concat(key, ":").concat(idc));
|
|
167
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
168
|
-
className: wrapperEnd,
|
|
169
|
-
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col, ide) {
|
|
170
|
-
return /*#__PURE__*/jsx(BodyCell, {
|
|
171
|
-
column: col,
|
|
172
|
-
item: data
|
|
173
|
-
}, "".concat(key, ":").concat(ide));
|
|
174
|
-
}), hideableColumns && /*#__PURE__*/jsx("div", {
|
|
175
|
-
className: "w-6"
|
|
184
|
+
children: [/*#__PURE__*/jsx(Icon, {
|
|
185
|
+
rtlFlip: true,
|
|
186
|
+
icon: data.open ? CoreIcons.chevronDown : CoreIcons.chevronRight
|
|
187
|
+
}), (_groupRenderer = groupRenderer === null || groupRenderer === void 0 ? void 0 : groupRenderer(data)) !== null && _groupRenderer !== void 0 ? _groupRenderer : /*#__PURE__*/jsxs("div", {
|
|
188
|
+
className: "flex gap-1 items-center",
|
|
189
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
190
|
+
children: data.key
|
|
191
|
+
}), /*#__PURE__*/jsxs("span", {
|
|
192
|
+
className: "text-sm",
|
|
193
|
+
children: ["(", data.itemCount, ")"]
|
|
176
194
|
})]
|
|
177
195
|
})]
|
|
196
|
+
}, key) : /*#__PURE__*/jsx(BodyRow, {
|
|
197
|
+
rowKey: key,
|
|
198
|
+
index: index,
|
|
199
|
+
checkableRows: checkableRows,
|
|
200
|
+
checked: keyProperty && checkState.checked.includes(data[keyProperty]) ? 1 : 0,
|
|
201
|
+
expanded: !!keyProperty && checkState.expanded.includes(data[keyProperty]),
|
|
202
|
+
data: data,
|
|
203
|
+
hideableColumns: hideableColumns,
|
|
204
|
+
keyProperty: keyProperty,
|
|
205
|
+
measureElement: measureElement,
|
|
206
|
+
onRowClick: onRowClick,
|
|
207
|
+
state: state,
|
|
208
|
+
canExpand: canExpand,
|
|
209
|
+
toggleExpand: toggleExpand,
|
|
210
|
+
expandRow: children,
|
|
211
|
+
toggleChecked: toggleChecked,
|
|
212
|
+
wrapperEnd: wrapperEnd,
|
|
213
|
+
wrapperStart: wrapperStart
|
|
178
214
|
}, key);
|
|
179
215
|
}), /*#__PURE__*/jsxs("div", {
|
|
180
216
|
className: "flex-1 flex flex-nowrap",
|
|
181
217
|
children: [/*#__PURE__*/jsxs("div", {
|
|
182
218
|
className: wrapperStart,
|
|
183
|
-
children: [
|
|
219
|
+
children: [canExpand && /*#__PURE__*/jsx("div", {
|
|
220
|
+
className: "w-6"
|
|
221
|
+
}), checkableRows && /*#__PURE__*/jsx("div", {
|
|
184
222
|
className: "w-6"
|
|
185
|
-
}), (_state$
|
|
223
|
+
}), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col) {
|
|
186
224
|
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
187
225
|
})]
|
|
188
|
-
}), (_state$
|
|
226
|
+
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col) {
|
|
189
227
|
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
190
228
|
}), /*#__PURE__*/jsxs("div", {
|
|
191
229
|
className: wrapperEnd,
|
|
192
|
-
children: [(_state$
|
|
230
|
+
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col) {
|
|
193
231
|
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
194
232
|
}), hideableColumns && /*#__PURE__*/jsx("div", {
|
|
195
233
|
className: "w-6"
|
|
196
234
|
})]
|
|
197
235
|
})]
|
|
198
236
|
})]
|
|
199
|
-
}), !loading && data.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
|
|
237
|
+
}), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsx(EmptyContent, {
|
|
200
238
|
size: "sm",
|
|
201
239
|
className: "bg-dimmed",
|
|
202
240
|
message: t("datagrid.empty")
|
|
203
|
-
})]
|
|
241
|
+
}))]
|
|
204
242
|
})
|
|
205
243
|
});
|
|
206
244
|
};
|
|
@@ -44,14 +44,14 @@ var useResizer = function useResizer(colEl, ghostEl, callback) {
|
|
|
44
44
|
/** ***************** attach handlers *******************/
|
|
45
45
|
var box = colEl.getBoundingClientRect();
|
|
46
46
|
if (colEl.parentElement != null) {
|
|
47
|
-
var _colEl$
|
|
48
|
-
var parentBox = (_colEl$
|
|
47
|
+
var _colEl$closest;
|
|
48
|
+
var parentBox = (_colEl$closest = colEl.closest("[data-ref='tableScroller']")) === null || _colEl$closest === void 0 ? void 0 : _colEl$closest.getBoundingClientRect();
|
|
49
49
|
if (isRtl) {
|
|
50
50
|
placeholder.style.left = "unset";
|
|
51
|
-
placeholder.style.right = "".concat(
|
|
51
|
+
placeholder.style.right = "".concat(parentBox.width - box.right, "px");
|
|
52
52
|
} else {
|
|
53
53
|
placeholder.style.right = "unset";
|
|
54
|
-
placeholder.style.left = "".concat(box.left
|
|
54
|
+
placeholder.style.left = "".concat(box.left, "px");
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
placeholder.style.width = "".concat(colEl.offsetWidth, "px");
|
|
@@ -1,61 +1,162 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { groupBy, compareValues } from '@react-fabric/utilities';
|
|
7
|
+
import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
|
|
8
|
+
import { useReducer, useRef, useMemo, useState, useCallback, useEffect } from 'react';
|
|
7
9
|
|
|
8
10
|
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
11
|
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,
|
|
12
|
+
var useVirtualTable = function useVirtualTable(data, options) {
|
|
13
|
+
var _virtualizer$range;
|
|
11
14
|
// TODO: refactor data into item list, apply grouping if groupColumn provided
|
|
12
15
|
// TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
|
|
13
16
|
|
|
14
|
-
var scrollerRef = useRef(null);
|
|
15
|
-
var virtualizer = useVirtualizer({
|
|
16
|
-
count: data.length,
|
|
17
|
-
getScrollElement: function getScrollElement() {
|
|
18
|
-
return scrollerRef.current;
|
|
19
|
-
},
|
|
20
|
-
estimateSize: function estimateSize() {
|
|
21
|
-
return 24;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
17
|
var _useReducer = useReducer(function (state, action) {
|
|
18
|
+
if (action.type === "updateState") {
|
|
19
|
+
state.checked = action.checked;
|
|
20
|
+
}
|
|
21
|
+
if (action.type === "expand") {
|
|
22
|
+
if (state.expanded.includes(action.key)) state.expanded.splice(state.expanded.indexOf(action.key), 1);else state.expanded.push(action.key);
|
|
23
|
+
}
|
|
25
24
|
if (action.type === "check") {
|
|
25
|
+
var _options$onCheckChang;
|
|
26
26
|
if (state.checked.includes(action.key)) state.checked.splice(state.checked.indexOf(action.key), 1);else state.checked.push(action.key);
|
|
27
|
+
(_options$onCheckChang = options.onCheckChanged) === null || _options$onCheckChang === void 0 || _options$onCheckChang.call(options, state.checked);
|
|
27
28
|
}
|
|
28
29
|
if (action.type === "checkall") {
|
|
30
|
+
var _options$onCheckChang2;
|
|
29
31
|
if (state.allChecked !== 0) {
|
|
30
32
|
state.checked = [];
|
|
31
|
-
} else {
|
|
33
|
+
} else if (options.keyProperty) {
|
|
32
34
|
state.checked = data.map(function (item) {
|
|
33
|
-
return item[keyProperty];
|
|
35
|
+
return item[options.keyProperty];
|
|
34
36
|
});
|
|
35
37
|
}
|
|
38
|
+
(_options$onCheckChang2 = options.onCheckChanged) === null || _options$onCheckChang2 === void 0 || _options$onCheckChang2.call(options, state.checked);
|
|
39
|
+
}
|
|
40
|
+
var checkList = data.filter(function (hit) {
|
|
41
|
+
return state.checked.includes(hit[options.keyProperty]);
|
|
42
|
+
});
|
|
43
|
+
if (action.type === "groupExpand") {
|
|
44
|
+
var group = state.groups.find(function (group) {
|
|
45
|
+
return group.key === action.key;
|
|
46
|
+
});
|
|
47
|
+
if (group) {
|
|
48
|
+
group.open = !group.open;
|
|
49
|
+
state.groups = state.groups.slice();
|
|
50
|
+
state.items = state.groups.map(function (group) {
|
|
51
|
+
return [group, group.open ? state.grouped[group.key] : undefined];
|
|
52
|
+
}).flat(2).filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (action.type === "grouped") {
|
|
56
|
+
if (action.key) {
|
|
57
|
+
state.grouped = groupBy(data, action.key);
|
|
58
|
+
state.groups = Object.keys(state.grouped).sort(compareValues("asc")).map(function (group) {
|
|
59
|
+
return {
|
|
60
|
+
__GROUP__: true,
|
|
61
|
+
open: true,
|
|
62
|
+
key: group,
|
|
63
|
+
items: state.grouped[group],
|
|
64
|
+
itemCount: state.grouped[group].length
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
state.items = state.groups.map(function (group) {
|
|
68
|
+
return [group].concat(_toConsumableArray(state.grouped[group.key]));
|
|
69
|
+
}).flat();
|
|
70
|
+
} else {
|
|
71
|
+
state.items = data;
|
|
72
|
+
}
|
|
36
73
|
}
|
|
37
|
-
onCheckChanged(state.checked);
|
|
38
74
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
39
|
-
allChecked:
|
|
75
|
+
allChecked: checkList.length === data.length ? 1 : state.checked.length ? 2 : 0
|
|
40
76
|
});
|
|
41
77
|
}, {
|
|
78
|
+
items: data,
|
|
79
|
+
grouped: {},
|
|
80
|
+
groups: [],
|
|
42
81
|
checked: [],
|
|
82
|
+
expanded: [],
|
|
43
83
|
allChecked: 0
|
|
44
84
|
}),
|
|
45
85
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
46
86
|
state = _useReducer2[0],
|
|
47
87
|
dispatch = _useReducer2[1];
|
|
88
|
+
var activeStickyIndexRef = useRef(0);
|
|
89
|
+
var stickyIndexes = useMemo(function () {
|
|
90
|
+
return state.items.map(function (hit, idx) {
|
|
91
|
+
return "__GROUP__" in hit ? idx : undefined;
|
|
92
|
+
}).filter(Boolean);
|
|
93
|
+
}, [state.items]);
|
|
94
|
+
var isActiveSticky = function isActiveSticky(index) {
|
|
95
|
+
return activeStickyIndexRef.current === index;
|
|
96
|
+
};
|
|
97
|
+
var _useState = useState(false),
|
|
98
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
99
|
+
hasActiveSticky = _useState2[0],
|
|
100
|
+
setHasActiveSticky = _useState2[1];
|
|
101
|
+
var scrollerRef = useRef(null);
|
|
102
|
+
var virtualizer = useVirtualizer({
|
|
103
|
+
count: state.items.length,
|
|
104
|
+
getScrollElement: function getScrollElement() {
|
|
105
|
+
return scrollerRef.current;
|
|
106
|
+
},
|
|
107
|
+
estimateSize: function estimateSize() {
|
|
108
|
+
return 32;
|
|
109
|
+
},
|
|
110
|
+
rangeExtractor: useCallback(function (range) {
|
|
111
|
+
var _reverse$find;
|
|
112
|
+
activeStickyIndexRef.current = (_reverse$find = _toConsumableArray(stickyIndexes).reverse().find(function (index) {
|
|
113
|
+
return range.startIndex > index;
|
|
114
|
+
})) !== null && _reverse$find !== void 0 ? _reverse$find : 0;
|
|
115
|
+
setHasActiveSticky(range.startIndex !== activeStickyIndexRef.current);
|
|
116
|
+
var next = new Set([activeStickyIndexRef.current].concat(_toConsumableArray(defaultRangeExtractor(range))));
|
|
117
|
+
return _toConsumableArray(next);
|
|
118
|
+
}, [stickyIndexes])
|
|
119
|
+
});
|
|
48
120
|
var virtualItems = virtualizer.getVirtualItems();
|
|
49
121
|
var getData = useCallback(function (index) {
|
|
50
|
-
return
|
|
51
|
-
}, [
|
|
122
|
+
return state.items[index];
|
|
123
|
+
}, [state.items]);
|
|
124
|
+
useEffect(function () {
|
|
125
|
+
dispatch({
|
|
126
|
+
type: "grouped",
|
|
127
|
+
key: options.groupProperty
|
|
128
|
+
});
|
|
129
|
+
}, [options.groupProperty]);
|
|
130
|
+
useEffect(function () {
|
|
131
|
+
var _options$checked;
|
|
132
|
+
dispatch({
|
|
133
|
+
type: "updateState",
|
|
134
|
+
checked: (_options$checked = options.checked) !== null && _options$checked !== void 0 ? _options$checked : []
|
|
135
|
+
});
|
|
136
|
+
}, [options.checked]);
|
|
52
137
|
return {
|
|
53
138
|
scrollerRef: scrollerRef,
|
|
54
139
|
items: virtualItems,
|
|
55
140
|
checkState: state,
|
|
56
141
|
getData: getData,
|
|
142
|
+
virtualizer: virtualizer,
|
|
143
|
+
hasActiveSticky: hasActiveSticky,
|
|
144
|
+
isActiveSticky: isActiveSticky,
|
|
145
|
+
top: (_virtualizer$range = virtualizer.range) === null || _virtualizer$range === void 0 ? void 0 : _virtualizer$range.startIndex,
|
|
57
146
|
totalSize: virtualizer.getTotalSize,
|
|
58
147
|
measureElement: virtualizer.measureElement,
|
|
148
|
+
toggleGroupExpand: function toggleGroupExpand(key) {
|
|
149
|
+
return dispatch({
|
|
150
|
+
type: "groupExpand",
|
|
151
|
+
key: key
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
toggleExpand: function toggleExpand(key) {
|
|
155
|
+
return dispatch({
|
|
156
|
+
type: "expand",
|
|
157
|
+
key: key
|
|
158
|
+
});
|
|
159
|
+
},
|
|
59
160
|
toggleChecked: function toggleChecked(key) {
|
|
60
161
|
return dispatch({
|
|
61
162
|
type: "check",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import { getBadgeProps, Icon, CoreIcons, Badge } from '@react-fabric/core';
|
|
5
|
+
import { isString, isEmpty } from '@react-fabric/utilities';
|
|
5
6
|
import classNames from 'classnames';
|
|
6
|
-
import { useMemo } from 'react';
|
|
7
|
-
import {
|
|
7
|
+
import { useMemo, isValidElement } from 'react';
|
|
8
|
+
import { useTranslation } from 'react-i18next';
|
|
9
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
8
10
|
|
|
9
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; }
|
|
10
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; }
|
|
@@ -17,26 +19,34 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
17
19
|
defaultLeafIcon = _ref.defaultLeafIcon,
|
|
18
20
|
defaultNodeIcon = _ref.defaultNodeIcon,
|
|
19
21
|
onToggle = _ref.onToggle,
|
|
22
|
+
_onClick = _ref.onClick,
|
|
20
23
|
onSelect = _ref.onSelect,
|
|
21
24
|
onChecked = _ref.onChecked,
|
|
22
|
-
children = _ref.children
|
|
25
|
+
children = _ref.children,
|
|
26
|
+
leafClassName = _ref.leafClassName,
|
|
27
|
+
nodeClassName = _ref.nodeClassName;
|
|
28
|
+
var _useTranslation = useTranslation("data"),
|
|
29
|
+
t = _useTranslation.t;
|
|
23
30
|
var badgeProps = useMemo(function () {
|
|
24
31
|
return getBadgeProps(node.badge);
|
|
25
32
|
}, [node.badge]);
|
|
26
33
|
var filler = useMemo(function () {
|
|
27
|
-
return node.lines.slice(
|
|
28
|
-
return /*#__PURE__*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
return node.lines.slice(1).map(function (line, idx) {
|
|
35
|
+
return /*#__PURE__*/jsx("div", {
|
|
36
|
+
className: classNames("flex-initial self-stretch flex items-center w-6 relative", !noLines && line > 0 && "before:absolute before:top-0 before:start-[7px] before:bg-tint-200 before:min-h-[50%] before:w-[2px] before:scale-x-[.625]", !noLines && line !== 2 && "before:h-full"),
|
|
37
|
+
children: /*#__PURE__*/jsxs("svg", {
|
|
38
|
+
viewBox: "0 0 24 24",
|
|
39
|
+
className: "fill-tint-200 rtl:-scale-x-100",
|
|
40
|
+
children: [line === 0 && /*#__PURE__*/jsx("path", {
|
|
41
|
+
d: ""
|
|
42
|
+
}), !noLines && line === 1 && /*#__PURE__*/jsx("path", {
|
|
43
|
+
d: "M7.45 26.1v-28.2h1.1v28.2h-1.1z"
|
|
44
|
+
}), !noLines && line === 2 && /*#__PURE__*/jsx("path", {
|
|
45
|
+
d: "M14.989 12.389l0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v14.1l0.161 0.389 0.389 0.161h6.6z"
|
|
46
|
+
}), !noLines && line === 3 && /*#__PURE__*/jsx("path", {
|
|
47
|
+
d: "M8.55 12.55h6.050l0.389-0.161 0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v28.2h1.1z"
|
|
48
|
+
})]
|
|
49
|
+
})
|
|
40
50
|
}, idx);
|
|
41
51
|
});
|
|
42
52
|
}, [noLines, node.lines]);
|
|
@@ -53,10 +63,16 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
53
63
|
return /*#__PURE__*/jsxs("div", {
|
|
54
64
|
role: "treeitem",
|
|
55
65
|
"aria-selected": node.selected,
|
|
56
|
-
className: "flex flex-nowrap",
|
|
66
|
+
className: classNames("flex flex-nowrap items-center", node.leaf ? leafClassName : nodeClassName),
|
|
57
67
|
"data-testid": node["data-testid"],
|
|
58
68
|
"data-test-value": node["data-test-value"],
|
|
59
|
-
children: [filler,
|
|
69
|
+
children: [filler, node.loading && /*#__PURE__*/jsx("div", {
|
|
70
|
+
className: "flex-initial w-6",
|
|
71
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
72
|
+
icon: CoreIcons.spinner,
|
|
73
|
+
className: "animate-spin text-muted"
|
|
74
|
+
})
|
|
75
|
+
}), !node.leaf && !node.childFiltered && !node.loading && /*#__PURE__*/jsx("div", {
|
|
60
76
|
className: "flex-initial w-6",
|
|
61
77
|
children: /*#__PURE__*/jsx(Icon, {
|
|
62
78
|
rtlFlip: true,
|
|
@@ -75,21 +91,22 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
75
91
|
icon: node.checked === 2 ? CoreIcons.checkboxInt : node.checked === 1 ? CoreIcons.checkboxOn : CoreIcons.checkboxOff,
|
|
76
92
|
className: classNames(node.disabled ? "text-muted" : "text-primary-500 hover:text-primary-600")
|
|
77
93
|
})
|
|
78
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
94
|
+
}), !node.empty && /*#__PURE__*/jsxs("div", {
|
|
79
95
|
role: "none",
|
|
80
|
-
className: classNames("group data-[selected]:bg-primary-100 flex flex-nowrap flex-1
|
|
96
|
+
className: classNames("group/tool data-[selected]:bg-primary-100 flex flex-nowrap flex-1 overflow-hidden select-none", node.childSelected && "font-medium", (canSelect || _onClick) && "hover:bg-primary-50 cursor-pointer"),
|
|
81
97
|
"data-selected": node.selected,
|
|
82
98
|
onClick: function onClick() {
|
|
83
|
-
|
|
99
|
+
_onClick === null || _onClick === void 0 || _onClick(node.id, node.data);
|
|
100
|
+
canSelect ? onSelect(node.id) : canCheck ? onChecked(node.id) : onToggle(node.id);
|
|
84
101
|
},
|
|
85
|
-
children: [nodeIcon && /*#__PURE__*/
|
|
86
|
-
className: "flex-content w-6",
|
|
87
|
-
children: /*#__PURE__*/jsx(Icon, {
|
|
102
|
+
children: [nodeIcon && /*#__PURE__*/jsxs("div", {
|
|
103
|
+
className: "flex-content w-6 self-center leading-none",
|
|
104
|
+
children: [/*#__PURE__*/isValidElement(nodeIcon) && nodeIcon, isString(nodeIcon) && /*#__PURE__*/jsx(Icon, {
|
|
88
105
|
icon: nodeIcon,
|
|
89
106
|
bg: node.iconBg,
|
|
90
107
|
color: node.iconColor,
|
|
91
108
|
rtlFlip: node.rtlFlip
|
|
92
|
-
})
|
|
109
|
+
})]
|
|
93
110
|
}), node.childSelected && !node.open && /*#__PURE__*/jsx("span", {
|
|
94
111
|
className: " flex-content text-primary-500",
|
|
95
112
|
children: "\u2022"
|
|
@@ -97,9 +114,12 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
97
114
|
role: "none",
|
|
98
115
|
className: "flex-1 truncate",
|
|
99
116
|
children: children
|
|
100
|
-
}), node.badge && /*#__PURE__*/jsx(Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
|
|
117
|
+
}), !isEmpty(node.badge) && /*#__PURE__*/jsx(Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
|
|
101
118
|
className: classNames("me-1 self-center flex-content bg-opacity-50", badgeProps.className)
|
|
102
119
|
}))]
|
|
120
|
+
}), node.empty && /*#__PURE__*/jsx("div", {
|
|
121
|
+
className: "text-muted text-sm select-none",
|
|
122
|
+
children: t("tree.noItems")
|
|
103
123
|
})]
|
|
104
124
|
});
|
|
105
125
|
};
|