@react-fabric/data 1.0.0-beta.0 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/table/AddColumn.js +56 -0
- package/dist/cjs/table/BodyCell.js +13 -4
- 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 +77 -32
- package/dist/cjs/table/Table.js +168 -93
- 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 +42 -25
- package/dist/cjs/tree/TreePanel.js +14 -2
- package/dist/cjs/tree/useTree.js +7 -0
- package/dist/esm/table/AddColumn.js +56 -0
- package/dist/esm/table/BodyCell.js +13 -4
- 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 +79 -34
- package/dist/esm/table/Table.js +169 -94
- 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 +43 -26
- package/dist/esm/tree/TreePanel.js +15 -3
- package/dist/esm/tree/useTree.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/table/AddColumn.d.ts +5 -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 +30 -3
- package/dist/types/table/useResizer.d.ts +1 -0
- package/dist/types/table/useTableColumns.d.ts +6 -4
- package/dist/types/table/useVirtualTable.d.ts +9 -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/package.json +5 -5
- package/src/index.ts +2 -0
- package/src/table/AddColumn.tsx +55 -0
- package/src/table/BodyCell.tsx +18 -4
- 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 +92 -25
- package/src/table/Table.tsx +178 -88
- package/src/table/types.ts +28 -2
- package/src/table/useResizer.ts +66 -0
- package/src/table/useTableColumns.ts +51 -18
- package/src/table/useVirtualTable.ts +47 -2
- package/src/tree/TreePanel.tsx +12 -1
- package/src/tree/types.ts +8 -1
- package/src/tree/useTree.ts +5 -0
package/dist/cjs/table/Table.js
CHANGED
|
@@ -1,132 +1,207 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var core = require('@react-fabric/core');
|
|
5
|
+
var classNames = require('classnames');
|
|
4
6
|
var react = require('react');
|
|
7
|
+
var reactI18next = require('react-i18next');
|
|
8
|
+
var AddColumn = require('./AddColumn.js');
|
|
5
9
|
var BodyCell = require('./BodyCell.js');
|
|
10
|
+
var CheckboxCell = require('./CheckboxCell.js');
|
|
11
|
+
var Context = require('./Context.js');
|
|
12
|
+
var EmptyCell = require('./EmptyCell.js');
|
|
6
13
|
var HeaderCell = require('./HeaderCell.js');
|
|
7
14
|
var useTableColumns = require('./useTableColumns.js');
|
|
8
15
|
var useVirtualTable = require('./useVirtualTable.js');
|
|
9
|
-
var classNames = require('classnames');
|
|
10
16
|
var jsxRuntime = require('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$start3, _state$cols3, _state$end3;
|
|
22
|
+
var ref = _ref.ref,
|
|
23
|
+
data = _ref.data,
|
|
24
|
+
columns = _ref.columns,
|
|
25
|
+
keyProperty = _ref.keyProperty,
|
|
26
|
+
checkableRows = _ref.checkableRows,
|
|
27
|
+
hideableColumns = _ref.hideableColumns,
|
|
28
|
+
sort = _ref.sort,
|
|
29
|
+
loading = _ref.loading,
|
|
30
|
+
onSort = _ref.onSort,
|
|
31
|
+
onRowClick = _ref.onRowClick,
|
|
32
|
+
onCheckedChanged = _ref.onCheckedChanged;
|
|
33
|
+
var _useTranslation = reactI18next.useTranslation("data"),
|
|
34
|
+
t = _useTranslation.t;
|
|
35
|
+
var fireCheckChanged = core.useDebounce(function (checkedIds) {
|
|
36
|
+
return onCheckedChanged === null || onCheckedChanged === void 0 ? void 0 : onCheckedChanged(checkedIds);
|
|
37
|
+
}, []);
|
|
18
38
|
var _useTableColumns = useTableColumns.useTableColumns(columns),
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
state = _useTableColumns.state,
|
|
40
|
+
onHide = _useTableColumns.onHide;
|
|
41
|
+
var _useVirtualTable = useVirtualTable.useVirtualTable(data, keyProperty, fireCheckChanged),
|
|
21
42
|
scrollerRef = _useVirtualTable.scrollerRef,
|
|
22
43
|
items = _useVirtualTable.items,
|
|
44
|
+
checkState = _useVirtualTable.checkState,
|
|
45
|
+
toggleChecked = _useVirtualTable.toggleChecked,
|
|
46
|
+
toggleAllChecked = _useVirtualTable.toggleAllChecked,
|
|
23
47
|
getData = _useVirtualTable.getData,
|
|
24
48
|
totalSize = _useVirtualTable.totalSize,
|
|
25
49
|
measureElement = _useVirtualTable.measureElement;
|
|
50
|
+
var refBody = react.useRef(null);
|
|
26
51
|
var wrapperStart = react.useMemo(function () {
|
|
27
52
|
return "bg-inherit sticky start-0 flex flex-nowrap z-1";
|
|
28
53
|
}, []);
|
|
29
54
|
var wrapperEnd = react.useMemo(function () {
|
|
30
55
|
return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
|
|
31
56
|
}, []);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
react.useImperativeHandle(ref, function () {
|
|
58
|
+
return {
|
|
59
|
+
hilight: function hilight(row) {
|
|
60
|
+
var _refBody$current, _refBody$current2;
|
|
61
|
+
(_refBody$current = refBody.current) === null || _refBody$current === void 0 || _refBody$current.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
|
|
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"
|
|
68
|
+
});
|
|
69
|
+
el && (el.dataset.hilight = "true");
|
|
70
|
+
},
|
|
71
|
+
unhilight: function unhilight() {
|
|
72
|
+
var _refBody$current3;
|
|
73
|
+
(_refBody$current3 = refBody.current) === null || _refBody$current3 === void 0 || _refBody$current3.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
|
|
74
|
+
return el && (el.dataset.hilight = undefined);
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
scrollTo: function scrollTo(row) {
|
|
78
|
+
var _refBody$current4;
|
|
79
|
+
var el = (_refBody$current4 = refBody.current) === null || _refBody$current4 === void 0 ? void 0 : _refBody$current4.querySelector("[data-row=\"".concat(row, "\"]"));
|
|
80
|
+
el === null || el === void 0 || el.scrollIntoView({
|
|
81
|
+
behavior: "smooth"
|
|
82
|
+
});
|
|
40
83
|
}
|
|
41
|
-
}
|
|
84
|
+
};
|
|
42
85
|
}, []);
|
|
43
|
-
return /*#__PURE__*/jsxRuntime.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
gridTemplate: "\"head\" auto \"content\" 1fr \"foot\" auto/1fr"
|
|
47
|
-
},
|
|
48
|
-
ref: scrollerRef,
|
|
49
|
-
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
50
|
-
className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
|
|
51
|
-
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
52
|
-
className: wrapperStart,
|
|
53
|
-
children: (_columnMap$start = columnMap.start) === null || _columnMap$start === void 0 ? void 0 : _columnMap$start.map(function (col, idx) {
|
|
54
|
-
return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread({}, col), idx);
|
|
55
|
-
})
|
|
56
|
-
}), (_columnMap$cols = columnMap.cols) === null || _columnMap$cols === void 0 ? void 0 : _columnMap$cols.map(function (col, idx) {
|
|
57
|
-
return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread({}, col), idx);
|
|
58
|
-
}), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread({}, col), idx);
|
|
62
|
-
})
|
|
63
|
-
})]
|
|
64
|
-
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
65
|
-
className: "area-content flex flex-col flex-nowrap",
|
|
86
|
+
return /*#__PURE__*/jsxRuntime.jsx(Context.TableProvider, {
|
|
87
|
+
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
88
|
+
className: "grid area-content overflow-auto relative",
|
|
66
89
|
style: {
|
|
67
|
-
|
|
90
|
+
gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
|
|
68
91
|
},
|
|
69
|
-
|
|
92
|
+
ref: scrollerRef,
|
|
93
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
94
|
+
className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
|
|
95
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
96
|
+
className: wrapperStart,
|
|
97
|
+
children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
|
|
98
|
+
state: checkState.allChecked,
|
|
99
|
+
onClick: toggleAllChecked
|
|
100
|
+
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
|
|
101
|
+
return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
|
|
102
|
+
sort: sort,
|
|
103
|
+
onSort: onSort
|
|
104
|
+
}), idx);
|
|
105
|
+
})]
|
|
106
|
+
}), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idx) {
|
|
107
|
+
return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
|
|
108
|
+
sort: sort,
|
|
109
|
+
onSort: onSort
|
|
110
|
+
}), idx);
|
|
111
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
112
|
+
className: wrapperEnd,
|
|
113
|
+
children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, idx) {
|
|
114
|
+
return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
|
|
115
|
+
sort: sort,
|
|
116
|
+
onSort: onSort
|
|
117
|
+
}), idx);
|
|
118
|
+
}), hideableColumns && /*#__PURE__*/jsxRuntime.jsx(AddColumn.AddColumn, {
|
|
119
|
+
onClick: onHide,
|
|
120
|
+
columns: state.columns.filter(function (col) {
|
|
121
|
+
return col.hideable !== false;
|
|
122
|
+
})
|
|
123
|
+
})]
|
|
124
|
+
})]
|
|
125
|
+
}), loading && /*#__PURE__*/jsxRuntime.jsx(core.Loading, {}), data.length > 0 && /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
126
|
+
className: "area-content flex flex-col flex-nowrap",
|
|
70
127
|
style: {
|
|
71
|
-
height: (
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
128
|
+
height: totalSize()
|
|
129
|
+
},
|
|
130
|
+
ref: refBody,
|
|
131
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
132
|
+
style: {
|
|
133
|
+
height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
|
|
134
|
+
}
|
|
135
|
+
}), items.map(function (_ref2) {
|
|
136
|
+
var _state$start2, _state$cols2, _state$end2;
|
|
137
|
+
var index = _ref2.index,
|
|
138
|
+
key = _ref2.key;
|
|
139
|
+
var data = getData(index);
|
|
140
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
141
|
+
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
|
+
onClick: function onClick() {
|
|
145
|
+
return checkableRows && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
|
|
146
|
+
},
|
|
147
|
+
"data-index": index,
|
|
148
|
+
ref: measureElement,
|
|
149
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
150
|
+
className: wrapperStart,
|
|
151
|
+
children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
|
|
152
|
+
onClick: function onClick() {
|
|
153
|
+
return toggleChecked(data[keyProperty]);
|
|
154
|
+
},
|
|
155
|
+
state: checkState.checked.includes(data[keyProperty]) ? 1 : 0
|
|
156
|
+
}), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col, ids) {
|
|
157
|
+
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.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) {
|
|
84
163
|
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
85
164
|
column: col,
|
|
86
|
-
item:
|
|
87
|
-
}, "".concat(key, ":").concat(
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
165
|
+
item: data
|
|
166
|
+
}, "".concat(key, ":").concat(idc));
|
|
167
|
+
}), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
171
|
+
column: col,
|
|
172
|
+
item: data
|
|
173
|
+
}, "".concat(key, ":").concat(ide));
|
|
174
|
+
}), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
175
|
+
className: "w-6"
|
|
176
|
+
})]
|
|
177
|
+
})]
|
|
178
|
+
}, key);
|
|
179
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
180
|
+
className: "flex-1 flex flex-nowrap",
|
|
181
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
182
|
+
className: wrapperStart,
|
|
183
|
+
children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
184
|
+
className: "w-6"
|
|
185
|
+
}), (_state$start3 = state.start) === null || _state$start3 === void 0 ? void 0 : _state$start3.map(function (col) {
|
|
186
|
+
return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
|
|
187
|
+
})]
|
|
188
|
+
}), (_state$cols3 = state.cols) === null || _state$cols3 === void 0 ? void 0 : _state$cols3.map(function (col) {
|
|
189
|
+
return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
|
|
190
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
95
191
|
className: wrapperEnd,
|
|
96
|
-
children: (
|
|
97
|
-
return /*#__PURE__*/jsxRuntime.jsx(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})
|
|
192
|
+
children: [(_state$end3 = state.end) === null || _state$end3 === void 0 ? void 0 : _state$end3.map(function (col) {
|
|
193
|
+
return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
|
|
194
|
+
}), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
195
|
+
className: "w-6"
|
|
196
|
+
})]
|
|
102
197
|
})]
|
|
103
|
-
}, key);
|
|
104
|
-
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
105
|
-
className: "flex-1 flex flex-nowrap",
|
|
106
|
-
children: [/*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx("div", {
|
|
110
|
-
className: wrapperEnd,
|
|
111
|
-
children: (_columnMap$end3 = columnMap.end) === null || _columnMap$end3 === void 0 ? void 0 : _columnMap$end3.map(emptyCol)
|
|
112
198
|
})]
|
|
199
|
+
}), !loading && data.length === 0 && /*#__PURE__*/jsxRuntime.jsx(core.EmptyContent, {
|
|
200
|
+
size: "sm",
|
|
201
|
+
className: "bg-dimmed",
|
|
202
|
+
message: t("datagrid.empty")
|
|
113
203
|
})]
|
|
114
|
-
})
|
|
115
|
-
className: "area-foot bg-dimmed border-t sticky bottom-0 flex flex-nowrap z-2",
|
|
116
|
-
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
117
|
-
className: wrapperStart,
|
|
118
|
-
children: (_columnMap$start4 = columnMap.start) === null || _columnMap$start4 === void 0 ? void 0 : _columnMap$start4.map(function (col, idx) {
|
|
119
|
-
return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.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__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread({}, col), idx);
|
|
123
|
-
}), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread({}, col), idx);
|
|
127
|
-
})
|
|
128
|
-
})]
|
|
129
|
-
})]
|
|
204
|
+
})
|
|
130
205
|
});
|
|
131
206
|
};
|
|
132
207
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
exports.COL_DEFAULT_WIDTH = COL_DEFAULT_WIDTH;
|
|
31
|
+
exports.COL_MAX_WIDTH = COL_MAX_WIDTH;
|
|
32
|
+
exports.COL_MIN_WIDTH = COL_MIN_WIDTH;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
exports.useResizer = useResizer;
|
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
3
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
5
|
var utilities = require('@react-fabric/utilities');
|
|
5
6
|
var react = require('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 = react.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 = utilities.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
|
react.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,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
3
5
|
var reactVirtual = require('@tanstack/react-virtual');
|
|
4
6
|
var react = require('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) {
|
|
30
11
|
// TODO: refactor data into item list, apply grouping if groupColumn provided
|
|
31
12
|
// TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
|
|
32
13
|
|
|
@@ -40,6 +21,30 @@ var useVirtualTable = function useVirtualTable(data) {
|
|
|
40
21
|
return 24;
|
|
41
22
|
}
|
|
42
23
|
});
|
|
24
|
+
var _useReducer = react.useReducer(function (state, action) {
|
|
25
|
+
if (action.type === "check") {
|
|
26
|
+
if (state.checked.includes(action.key)) state.checked.splice(state.checked.indexOf(action.key), 1);else state.checked.push(action.key);
|
|
27
|
+
}
|
|
28
|
+
if (action.type === "checkall") {
|
|
29
|
+
if (state.allChecked !== 0) {
|
|
30
|
+
state.checked = [];
|
|
31
|
+
} else {
|
|
32
|
+
state.checked = data.map(function (item) {
|
|
33
|
+
return item[keyProperty];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
onCheckChanged(state.checked);
|
|
38
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
39
|
+
allChecked: state.checked.length === data.length ? 1 : state.checked.length ? 2 : 0
|
|
40
|
+
});
|
|
41
|
+
}, {
|
|
42
|
+
checked: [],
|
|
43
|
+
allChecked: 0
|
|
44
|
+
}),
|
|
45
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
46
|
+
state = _useReducer2[0],
|
|
47
|
+
dispatch = _useReducer2[1];
|
|
43
48
|
var virtualItems = virtualizer.getVirtualItems();
|
|
44
49
|
var getData = react.useCallback(function (index) {
|
|
45
50
|
return data[index];
|
|
@@ -47,9 +52,21 @@ var useVirtualTable = function useVirtualTable(data) {
|
|
|
47
52
|
return {
|
|
48
53
|
scrollerRef: scrollerRef,
|
|
49
54
|
items: virtualItems,
|
|
55
|
+
checkState: state,
|
|
50
56
|
getData: getData,
|
|
51
57
|
totalSize: virtualizer.getTotalSize,
|
|
52
|
-
measureElement: virtualizer.measureElement
|
|
58
|
+
measureElement: virtualizer.measureElement,
|
|
59
|
+
toggleChecked: function toggleChecked(key) {
|
|
60
|
+
return dispatch({
|
|
61
|
+
type: "check",
|
|
62
|
+
key: key
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
toggleAllChecked: function toggleAllChecked() {
|
|
66
|
+
return dispatch({
|
|
67
|
+
type: "checkall"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
53
70
|
};
|
|
54
71
|
};
|
|
55
72
|
|
|
@@ -11,12 +11,13 @@ var types = require('./types.js');
|
|
|
11
11
|
var useTree = require('./useTree.js');
|
|
12
12
|
var jsxRuntime = require('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 = react.useRef(null);
|
|
53
55
|
var virtualizer = reactVirtual.useVirtualizer({
|
|
@@ -66,6 +68,16 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
66
68
|
if (expander === "folder") return [core.CoreIcons.folderClosed, core.CoreIcons.folderOpen];
|
|
67
69
|
return [core.CoreIcons.expand, core.CoreIcons.collapse];
|
|
68
70
|
}, [expander]);
|
|
71
|
+
react.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__*/jsxRuntime.jsxs(core.Section, {
|
|
70
82
|
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Header, {
|
|
71
83
|
flex: true,
|
package/dist/cjs/tree/useTree.js
CHANGED
|
@@ -151,6 +151,12 @@ var useTree = function useTree(_ref) {
|
|
|
151
151
|
id: id
|
|
152
152
|
});
|
|
153
153
|
}, []);
|
|
154
|
+
var expand = react.useCallback(function (id) {
|
|
155
|
+
dispatch({
|
|
156
|
+
type: "expand",
|
|
157
|
+
id: id
|
|
158
|
+
});
|
|
159
|
+
}, []);
|
|
154
160
|
var expandAll = react.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
|
};
|