@react-fabric/data 1.0.0-beta.1 → 1.0.0-beta.12
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/BodyCell.js +35 -3
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/HeaderCell.js +4 -3
- package/dist/cjs/table/Table.js +84 -49
- package/dist/cjs/table/useVirtualTable.js +16 -2
- 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/BodyCell.js +35 -3
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/HeaderCell.js +4 -3
- package/dist/esm/table/Table.js +85 -50
- package/dist/esm/table/useVirtualTable.js +16 -2
- 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 +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 -7
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +5 -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 +2 -2
- package/src/table/BodyCell.tsx +30 -3
- package/src/table/BodyRow.tsx +142 -0
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +4 -3
- package/src/table/Table.tsx +103 -56
- package/src/table/types.ts +23 -6
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +19 -5
- 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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import { useRef, useState, useTransition, useEffect, useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
var useSelectableList = function useSelectableList(_ref) {
|
|
10
|
+
var items = _ref.items,
|
|
11
|
+
selected = _ref.selected,
|
|
12
|
+
nonselected = _ref.nonselected,
|
|
13
|
+
onChange = _ref.onChange,
|
|
14
|
+
onClick = _ref.onClick;
|
|
15
|
+
var selectionRef = useRef({});
|
|
16
|
+
var _useState = useState({}),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
selection = _useState2[0],
|
|
19
|
+
setSelection = _useState2[1];
|
|
20
|
+
var _useTransition = useTransition(),
|
|
21
|
+
_useTransition2 = _slicedToArray(_useTransition, 2),
|
|
22
|
+
startTransition = _useTransition2[1];
|
|
23
|
+
useEffect(function () {
|
|
24
|
+
selectionRef.current = items.reduce(function (ret, _ref2) {
|
|
25
|
+
var _selected$includes, _nonselected$includes;
|
|
26
|
+
var id = _ref2.id;
|
|
27
|
+
return _objectSpread(_objectSpread({}, ret), {}, _defineProperty({}, id, selected !== null && selected !== void 0 && (_selected$includes = selected.includes) !== null && _selected$includes !== void 0 && _selected$includes.call(selected, id) ? 1 : nonselected !== null && nonselected !== void 0 && (_nonselected$includes = nonselected.includes) !== null && _nonselected$includes !== void 0 && _nonselected$includes.call(nonselected, id) ? -1 : 0));
|
|
28
|
+
}, {});
|
|
29
|
+
setSelection(_objectSpread({}, selectionRef.current));
|
|
30
|
+
}, [items, selected, nonselected]);
|
|
31
|
+
var toggleSelection = useCallback(function (id) {
|
|
32
|
+
var isNegative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
33
|
+
var check = isNegative ? -1 : 1;
|
|
34
|
+
if (selectionRef.current[id] !== check) selectionRef.current[id] = check;else if (selectionRef.current[id] === check) selectionRef.current[id] = 0;
|
|
35
|
+
var change = [[], []];
|
|
36
|
+
Object.entries(selectionRef.current).forEach(function (_ref3) {
|
|
37
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
38
|
+
id = _ref4[0],
|
|
39
|
+
select = _ref4[1];
|
|
40
|
+
return select === 1 ? change[0].push(id) : select === -1 ? change[1].push(id) : undefined;
|
|
41
|
+
});
|
|
42
|
+
setSelection(_objectSpread({}, selectionRef.current));
|
|
43
|
+
startTransition(function () {
|
|
44
|
+
onClick === null || onClick === void 0 || onClick(id, isNegative);
|
|
45
|
+
onChange === null || onChange === void 0 || onChange(change[0], change[1]);
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
return {
|
|
49
|
+
selection: selection,
|
|
50
|
+
toggleSelection: toggleSelection
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { useSelectableList };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { DateDisplay } from '@react-fabric/date';
|
|
4
|
+
import { getByPath, isTrue, Format } from '@react-fabric/utilities';
|
|
3
5
|
import classNames from 'classnames';
|
|
4
6
|
import { useMemo } from 'react';
|
|
5
7
|
import { useTableContext } from './Context.js';
|
|
@@ -30,15 +32,45 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
var BodyCell = function BodyCell(_ref) {
|
|
33
|
-
var _column$minWidth, _column$maxWidth
|
|
35
|
+
var _column$minWidth, _column$maxWidth;
|
|
34
36
|
var column = _ref.column,
|
|
35
|
-
item = _ref.item
|
|
37
|
+
item = _ref.item,
|
|
38
|
+
index = _ref.index;
|
|
36
39
|
var _useTableContext = useTableContext(),
|
|
37
40
|
widths = _useTableContext.widths;
|
|
38
41
|
var width = useMemo(function () {
|
|
39
42
|
var _widths$get;
|
|
40
43
|
return (_widths$get = widths.get(column.id.toString())) !== null && _widths$get !== void 0 ? _widths$get : column.width;
|
|
41
44
|
}, [widths, column]);
|
|
45
|
+
var content = useMemo(function () {
|
|
46
|
+
var value = getByPath(item, column.id.toString());
|
|
47
|
+
if (column.renderer != null) {
|
|
48
|
+
return column.renderer(item[column.id], item, index);
|
|
49
|
+
}
|
|
50
|
+
if (column.dataType === "boolean") {
|
|
51
|
+
var _column$valueMap;
|
|
52
|
+
var map = (_column$valueMap = column.valueMap) !== null && _column$valueMap !== void 0 ? _column$valueMap : {
|
|
53
|
+
"true": "Yes",
|
|
54
|
+
"false": "no"
|
|
55
|
+
};
|
|
56
|
+
return map["".concat(isTrue(value) ? "true" : "false")];
|
|
57
|
+
}
|
|
58
|
+
if (column.valueMap != null) {
|
|
59
|
+
if (column.dataType === "string" && value in column.valueMap) {
|
|
60
|
+
return column.valueMap[value];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (column.dataType === "date") {
|
|
64
|
+
return /*#__PURE__*/jsx(DateDisplay, {
|
|
65
|
+
date: value,
|
|
66
|
+
format: column.format
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (column.dataType === "number") {
|
|
70
|
+
return Format.number(value, column.format);
|
|
71
|
+
}
|
|
72
|
+
return value !== null && value !== void 0 ? value : "";
|
|
73
|
+
}, [item, column]);
|
|
42
74
|
return /*#__PURE__*/jsx("div", {
|
|
43
75
|
className: "overflow-hidden bg-inherit start-0",
|
|
44
76
|
style: {
|
|
@@ -48,7 +80,7 @@ var BodyCell = function BodyCell(_ref) {
|
|
|
48
80
|
},
|
|
49
81
|
children: /*#__PURE__*/jsx("div", {
|
|
50
82
|
className: classNames("px-2 py-1 border-e truncate", column.align === "center" && "text-center", column.align === "end" && "text-end"),
|
|
51
|
-
children:
|
|
83
|
+
children: content
|
|
52
84
|
})
|
|
53
85
|
});
|
|
54
86
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { BodyCell } from './BodyCell.js';
|
|
5
|
+
import { CheckboxCell } from './CheckboxCell.js';
|
|
6
|
+
import { Icon, CoreIcons } from '@react-fabric/core';
|
|
7
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* React Fabric
|
|
11
|
+
* @version: 1.0.0
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* The MIT License (MIT)
|
|
15
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
18
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
19
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
20
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
21
|
+
* subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
24
|
+
* portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
27
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
28
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
var BodyRow = function BodyRow(_ref) {
|
|
33
|
+
var _state$start, _state$cols, _state$end;
|
|
34
|
+
var rowKey = _ref.rowKey,
|
|
35
|
+
index = _ref.index,
|
|
36
|
+
data = _ref.data,
|
|
37
|
+
keyProperty = _ref.keyProperty,
|
|
38
|
+
measureElement = _ref.measureElement,
|
|
39
|
+
state = _ref.state,
|
|
40
|
+
hideableColumns = _ref.hideableColumns,
|
|
41
|
+
wrapperStart = _ref.wrapperStart,
|
|
42
|
+
wrapperEnd = _ref.wrapperEnd,
|
|
43
|
+
onRowClick = _ref.onRowClick,
|
|
44
|
+
checkableRows = _ref.checkableRows,
|
|
45
|
+
checked = _ref.checked,
|
|
46
|
+
toggleChecked = _ref.toggleChecked,
|
|
47
|
+
canExpand = _ref.canExpand,
|
|
48
|
+
expanded = _ref.expanded,
|
|
49
|
+
toggleExpand = _ref.toggleExpand,
|
|
50
|
+
expandRow = _ref.expandRow;
|
|
51
|
+
return /*#__PURE__*/jsxs("div", {
|
|
52
|
+
ref: measureElement,
|
|
53
|
+
"data-index": index,
|
|
54
|
+
className: index % 2 ? "bg-even" : "bg-odd",
|
|
55
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
56
|
+
role: "none",
|
|
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"),
|
|
59
|
+
onClick: function onClick() {
|
|
60
|
+
return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
|
|
61
|
+
},
|
|
62
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
63
|
+
className: wrapperStart,
|
|
64
|
+
children: [!!canExpand && /*#__PURE__*/jsx("div", {
|
|
65
|
+
className: classNames("group font-medium w-6 flex flex-nowrap text-start items-center", !canExpand(data) && "pointer-events-none opacity-35"),
|
|
66
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
67
|
+
className: "p-1 text-tint-700 hover:text-primary-600",
|
|
68
|
+
icon: expanded ? CoreIcons.collapse : CoreIcons.expand,
|
|
69
|
+
onClick: function onClick(e) {
|
|
70
|
+
return [keyProperty && toggleExpand(data[keyProperty]), e.stopPropagation()];
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}), checkableRows && keyProperty && /*#__PURE__*/jsx(CheckboxCell, {
|
|
74
|
+
onClick: function onClick() {
|
|
75
|
+
return toggleChecked(data[keyProperty]);
|
|
76
|
+
},
|
|
77
|
+
state: checked
|
|
78
|
+
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, ids) {
|
|
79
|
+
return /*#__PURE__*/jsx(BodyCell, {
|
|
80
|
+
column: col,
|
|
81
|
+
item: data,
|
|
82
|
+
index: ids
|
|
83
|
+
}, "".concat(String(rowKey), ":").concat(ids));
|
|
84
|
+
})]
|
|
85
|
+
}), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idc) {
|
|
86
|
+
return /*#__PURE__*/jsx(BodyCell, {
|
|
87
|
+
column: col,
|
|
88
|
+
item: data,
|
|
89
|
+
index: idc
|
|
90
|
+
}, "".concat(String(rowKey), ":").concat(idc));
|
|
91
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
92
|
+
className: wrapperEnd,
|
|
93
|
+
children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, ide) {
|
|
94
|
+
return /*#__PURE__*/jsx(BodyCell, {
|
|
95
|
+
column: col,
|
|
96
|
+
item: data,
|
|
97
|
+
index: ide
|
|
98
|
+
}, "".concat(String(rowKey), ":").concat(ide));
|
|
99
|
+
}), hideableColumns && /*#__PURE__*/jsx("div", {
|
|
100
|
+
className: "w-6"
|
|
101
|
+
})]
|
|
102
|
+
})]
|
|
103
|
+
}), expanded && expandRow(data)]
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { BodyRow };
|
|
@@ -38,7 +38,8 @@ var HeaderCell = function HeaderCell(_ref) {
|
|
|
38
38
|
rtlFlip = _ref.rtlFlip;
|
|
39
39
|
_ref.actions;
|
|
40
40
|
_ref.locked;
|
|
41
|
-
var
|
|
41
|
+
var tooltip = _ref.tooltip,
|
|
42
|
+
sortable = _ref.sortable,
|
|
42
43
|
resizable = _ref.resizable,
|
|
43
44
|
_width = _ref.width,
|
|
44
45
|
maxWidth = _ref.maxWidth,
|
|
@@ -82,8 +83,8 @@ var HeaderCell = function HeaderCell(_ref) {
|
|
|
82
83
|
maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : COL_MAX_WIDTH
|
|
83
84
|
},
|
|
84
85
|
children: [/*#__PURE__*/jsx(Tooltip, {
|
|
85
|
-
content: label,
|
|
86
|
-
disabled: !label,
|
|
86
|
+
content: tooltip !== null && tooltip !== void 0 ? tooltip : label,
|
|
87
|
+
disabled: !(tooltip !== null && tooltip !== void 0 ? tooltip : label),
|
|
87
88
|
children: /*#__PURE__*/jsxs("div", {
|
|
88
89
|
className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
|
|
89
90
|
children: [icon && /*#__PURE__*/jsx(Icon, {
|
package/dist/esm/table/Table.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import { useDebounce, Loading, EmptyContent } from '@react-fabric/core';
|
|
5
|
-
import
|
|
6
|
-
import { useMemo } from 'react';
|
|
5
|
+
import { debounce } from '@react-fabric/utilities';
|
|
6
|
+
import { useRef, useMemo, useLayoutEffect, useImperativeHandle, useEffect } from 'react';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { AddColumn } from './AddColumn.js';
|
|
9
|
-
import {
|
|
9
|
+
import { BodyRow } from './BodyRow.js';
|
|
10
10
|
import { CheckboxCell } from './CheckboxCell.js';
|
|
11
11
|
import { TableProvider } from './Context.js';
|
|
12
12
|
import { EmptyCell } from './EmptyCell.js';
|
|
@@ -18,15 +18,21 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
18
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; }
|
|
19
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; }
|
|
20
20
|
var Table = function Table(_ref) {
|
|
21
|
-
var _state$start, _state$cols, _state$end, _items$, _state$
|
|
22
|
-
var
|
|
21
|
+
var _state$start, _state$cols, _state$end, _items$, _state$start2, _state$cols2, _state$end2;
|
|
22
|
+
var ref = _ref.ref,
|
|
23
|
+
data = _ref.data,
|
|
23
24
|
columns = _ref.columns,
|
|
24
25
|
keyProperty = _ref.keyProperty,
|
|
25
26
|
checkableRows = _ref.checkableRows,
|
|
27
|
+
initialScroll = _ref.initialScroll,
|
|
26
28
|
hideableColumns = _ref.hideableColumns,
|
|
27
29
|
sort = _ref.sort,
|
|
28
30
|
loading = _ref.loading,
|
|
31
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
32
|
+
canExpand = _ref.canExpand,
|
|
33
|
+
children = _ref.children,
|
|
29
34
|
onSort = _ref.onSort,
|
|
35
|
+
onScroll = _ref.onScroll,
|
|
30
36
|
onRowClick = _ref.onRowClick,
|
|
31
37
|
onCheckedChanged = _ref.onCheckedChanged;
|
|
32
38
|
var _useTranslation = useTranslation("data"),
|
|
@@ -40,18 +46,62 @@ var Table = function Table(_ref) {
|
|
|
40
46
|
var _useVirtualTable = useVirtualTable(data, keyProperty, fireCheckChanged),
|
|
41
47
|
scrollerRef = _useVirtualTable.scrollerRef,
|
|
42
48
|
items = _useVirtualTable.items,
|
|
49
|
+
top = _useVirtualTable.top,
|
|
43
50
|
checkState = _useVirtualTable.checkState,
|
|
51
|
+
virtualizer = _useVirtualTable.virtualizer,
|
|
52
|
+
toggleExpand = _useVirtualTable.toggleExpand,
|
|
44
53
|
toggleChecked = _useVirtualTable.toggleChecked,
|
|
45
54
|
toggleAllChecked = _useVirtualTable.toggleAllChecked,
|
|
46
55
|
getData = _useVirtualTable.getData,
|
|
47
56
|
totalSize = _useVirtualTable.totalSize,
|
|
48
57
|
measureElement = _useVirtualTable.measureElement;
|
|
58
|
+
var refBody = useRef(null);
|
|
49
59
|
var wrapperStart = useMemo(function () {
|
|
50
60
|
return "bg-inherit sticky start-0 flex flex-nowrap z-1";
|
|
51
61
|
}, []);
|
|
52
62
|
var wrapperEnd = useMemo(function () {
|
|
53
63
|
return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
|
|
54
64
|
}, []);
|
|
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");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
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]);
|
|
55
105
|
return /*#__PURE__*/jsx(TableProvider, {
|
|
56
106
|
children: /*#__PURE__*/jsxs("div", {
|
|
57
107
|
className: "grid area-content overflow-auto relative",
|
|
@@ -63,7 +113,9 @@ var Table = function Table(_ref) {
|
|
|
63
113
|
className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
|
|
64
114
|
children: [/*#__PURE__*/jsxs("div", {
|
|
65
115
|
className: wrapperStart,
|
|
66
|
-
children: [
|
|
116
|
+
children: [canExpand && /*#__PURE__*/jsx("div", {
|
|
117
|
+
className: "w-6"
|
|
118
|
+
}), checkableRows && /*#__PURE__*/jsx(CheckboxCell, {
|
|
67
119
|
state: checkState.allChecked,
|
|
68
120
|
onClick: toggleAllChecked
|
|
69
121
|
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
|
|
@@ -96,78 +148,61 @@ var Table = function Table(_ref) {
|
|
|
96
148
|
style: {
|
|
97
149
|
height: totalSize()
|
|
98
150
|
},
|
|
151
|
+
ref: refBody,
|
|
99
152
|
children: [/*#__PURE__*/jsx("div", {
|
|
100
153
|
style: {
|
|
101
154
|
height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
|
|
102
155
|
}
|
|
103
156
|
}), items.map(function (_ref2) {
|
|
104
|
-
var _state$start2, _state$cols2, _state$end2;
|
|
105
157
|
var index = _ref2.index,
|
|
106
158
|
key = _ref2.key;
|
|
107
159
|
var data = getData(index);
|
|
108
|
-
return /*#__PURE__*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
item: data
|
|
127
|
-
}, "".concat(key, ":").concat(ids));
|
|
128
|
-
})]
|
|
129
|
-
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col, idc) {
|
|
130
|
-
return /*#__PURE__*/jsx(BodyCell, {
|
|
131
|
-
column: col,
|
|
132
|
-
item: data
|
|
133
|
-
}, "".concat(key, ":").concat(idc));
|
|
134
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
135
|
-
className: wrapperEnd,
|
|
136
|
-
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col, ide) {
|
|
137
|
-
return /*#__PURE__*/jsx(BodyCell, {
|
|
138
|
-
column: col,
|
|
139
|
-
item: data
|
|
140
|
-
}, "".concat(key, ":").concat(ide));
|
|
141
|
-
}), hideableColumns && /*#__PURE__*/jsx("div", {
|
|
142
|
-
className: "w-6"
|
|
143
|
-
})]
|
|
144
|
-
})]
|
|
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
|
|
145
178
|
}, key);
|
|
146
179
|
}), /*#__PURE__*/jsxs("div", {
|
|
147
180
|
className: "flex-1 flex flex-nowrap",
|
|
148
181
|
children: [/*#__PURE__*/jsxs("div", {
|
|
149
182
|
className: wrapperStart,
|
|
150
|
-
children: [
|
|
183
|
+
children: [canExpand && /*#__PURE__*/jsx("div", {
|
|
184
|
+
className: "w-6"
|
|
185
|
+
}), checkableRows && /*#__PURE__*/jsx("div", {
|
|
151
186
|
className: "w-6"
|
|
152
|
-
}), (_state$
|
|
187
|
+
}), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col) {
|
|
153
188
|
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
154
189
|
})]
|
|
155
|
-
}), (_state$
|
|
190
|
+
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col) {
|
|
156
191
|
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
157
192
|
}), /*#__PURE__*/jsxs("div", {
|
|
158
193
|
className: wrapperEnd,
|
|
159
|
-
children: [(_state$
|
|
194
|
+
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col) {
|
|
160
195
|
return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
|
|
161
196
|
}), hideableColumns && /*#__PURE__*/jsx("div", {
|
|
162
197
|
className: "w-6"
|
|
163
198
|
})]
|
|
164
199
|
})]
|
|
165
200
|
})]
|
|
166
|
-
}), !loading && data.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
|
|
201
|
+
}), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsx(EmptyContent, {
|
|
167
202
|
size: "sm",
|
|
168
203
|
className: "bg-dimmed",
|
|
169
204
|
message: t("datagrid.empty")
|
|
170
|
-
})]
|
|
205
|
+
}))]
|
|
171
206
|
})
|
|
172
207
|
});
|
|
173
208
|
};
|
|
@@ -8,6 +8,7 @@ import { useRef, useReducer, useCallback } from 'react';
|
|
|
8
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
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
10
|
var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged) {
|
|
11
|
+
var _virtualizer$range;
|
|
11
12
|
// TODO: refactor data into item list, apply grouping if groupColumn provided
|
|
12
13
|
// TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
|
|
13
14
|
|
|
@@ -22,24 +23,29 @@ var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged
|
|
|
22
23
|
}
|
|
23
24
|
});
|
|
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
|
+
}
|
|
25
29
|
if (action.type === "check") {
|
|
26
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);
|
|
27
32
|
}
|
|
28
33
|
if (action.type === "checkall") {
|
|
29
34
|
if (state.allChecked !== 0) {
|
|
30
35
|
state.checked = [];
|
|
31
|
-
} else {
|
|
36
|
+
} else if (keyProperty) {
|
|
32
37
|
state.checked = data.map(function (item) {
|
|
33
38
|
return item[keyProperty];
|
|
34
39
|
});
|
|
35
40
|
}
|
|
41
|
+
onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
|
|
36
42
|
}
|
|
37
|
-
onCheckChanged(state.checked);
|
|
38
43
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
39
44
|
allChecked: state.checked.length === data.length ? 1 : state.checked.length ? 2 : 0
|
|
40
45
|
});
|
|
41
46
|
}, {
|
|
42
47
|
checked: [],
|
|
48
|
+
expanded: [],
|
|
43
49
|
allChecked: 0
|
|
44
50
|
}),
|
|
45
51
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
@@ -54,8 +60,16 @@ var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged
|
|
|
54
60
|
items: virtualItems,
|
|
55
61
|
checkState: state,
|
|
56
62
|
getData: getData,
|
|
63
|
+
virtualizer: virtualizer,
|
|
64
|
+
top: (_virtualizer$range = virtualizer.range) === null || _virtualizer$range === void 0 ? void 0 : _virtualizer$range.startIndex,
|
|
57
65
|
totalSize: virtualizer.getTotalSize,
|
|
58
66
|
measureElement: virtualizer.measureElement,
|
|
67
|
+
toggleExpand: function toggleExpand(key) {
|
|
68
|
+
return dispatch({
|
|
69
|
+
type: "expand",
|
|
70
|
+
key: key
|
|
71
|
+
});
|
|
72
|
+
},
|
|
59
73
|
toggleChecked: function toggleChecked(key) {
|
|
60
74
|
return dispatch({
|
|
61
75
|
type: "check",
|
|
@@ -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
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
6
|
import { useEffectDebugger, useDebounce, Skeleton } from '@react-fabric/core';
|
|
5
7
|
import { debounce } from '@react-fabric/utilities';
|
|
6
8
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
@@ -10,6 +12,9 @@ import { useDeferredValue, useMemo, useRef, useState, useEffect, useCallback, us
|
|
|
10
12
|
import { Scroller } from './Scroller.js';
|
|
11
13
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
12
14
|
|
|
15
|
+
var _excluded = ["items", "children", "columns", "padding", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "galleryRef"];
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
13
18
|
var createItemList = memoizeOne(function (items) {
|
|
14
19
|
return items;
|
|
15
20
|
});
|
|
@@ -29,7 +34,8 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
29
34
|
loading = _ref.loading,
|
|
30
35
|
onLoadMore = _ref.onLoadMore,
|
|
31
36
|
onScroll = _ref.onScroll,
|
|
32
|
-
galleryRef = _ref.galleryRef
|
|
37
|
+
galleryRef = _ref.galleryRef,
|
|
38
|
+
aria = _objectWithoutProperties(_ref, _excluded);
|
|
33
39
|
var count = useDeferredValue(items.length);
|
|
34
40
|
var extraSize = useMemo(function () {
|
|
35
41
|
return onLoadMore ? 64 : 0;
|
|
@@ -163,10 +169,11 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
163
169
|
}
|
|
164
170
|
};
|
|
165
171
|
}, [virtualizer, columnCount]);
|
|
166
|
-
return /*#__PURE__*/jsx("div", {
|
|
172
|
+
return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
|
|
167
173
|
ref: scrollerRef,
|
|
168
174
|
onScroll: handleScroll,
|
|
169
|
-
className: classNames("area-content bg-base overflow-auto contain-strict")
|
|
175
|
+
className: classNames("area-content bg-base overflow-auto contain-strict")
|
|
176
|
+
}, aria), {}, {
|
|
170
177
|
children: /*#__PURE__*/jsxs("div", {
|
|
171
178
|
className: classNames("inline-flex flex-nowrap gap-2 justify-center min-h-full min-w-full"),
|
|
172
179
|
children: [/*#__PURE__*/jsx("div", {
|
|
@@ -220,7 +227,7 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
220
227
|
})
|
|
221
228
|
})]
|
|
222
229
|
})
|
|
223
|
-
});
|
|
230
|
+
}));
|
|
224
231
|
};
|
|
225
232
|
_VirtualGallery.displayName = "VirtualGallery";
|
|
226
233
|
var GenericMemo = memo;
|