@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.
Files changed (56) hide show
  1. package/dist/cjs/table/AddColumn.js +56 -0
  2. package/dist/cjs/table/BodyCell.js +13 -4
  3. package/dist/cjs/table/CheckboxCell.js +44 -0
  4. package/dist/cjs/table/Context.js +43 -0
  5. package/dist/cjs/table/EmptyCell.js +52 -0
  6. package/dist/cjs/table/HeaderCell.js +77 -32
  7. package/dist/cjs/table/Table.js +168 -93
  8. package/dist/cjs/table/types.js +32 -0
  9. package/dist/cjs/table/useResizer.js +65 -0
  10. package/dist/cjs/table/useTableColumns.js +45 -8
  11. package/dist/cjs/table/useVirtualTable.js +42 -25
  12. package/dist/cjs/tree/TreePanel.js +14 -2
  13. package/dist/cjs/tree/useTree.js +7 -0
  14. package/dist/esm/table/AddColumn.js +56 -0
  15. package/dist/esm/table/BodyCell.js +13 -4
  16. package/dist/esm/table/CheckboxCell.js +44 -0
  17. package/dist/esm/table/Context.js +42 -0
  18. package/dist/esm/table/EmptyCell.js +52 -0
  19. package/dist/esm/table/HeaderCell.js +79 -34
  20. package/dist/esm/table/Table.js +169 -94
  21. package/dist/esm/table/types.js +30 -0
  22. package/dist/esm/table/useResizer.js +65 -0
  23. package/dist/esm/table/useTableColumns.js +46 -9
  24. package/dist/esm/table/useVirtualTable.js +43 -26
  25. package/dist/esm/tree/TreePanel.js +15 -3
  26. package/dist/esm/tree/useTree.js +7 -0
  27. package/dist/types/index.d.ts +2 -0
  28. package/dist/types/table/AddColumn.d.ts +5 -0
  29. package/dist/types/table/CheckboxCell.d.ts +4 -0
  30. package/dist/types/table/Context.d.ts +8 -0
  31. package/dist/types/table/EmptyCell.d.ts +2 -0
  32. package/dist/types/table/HeaderCell.d.ts +2 -2
  33. package/dist/types/table/Table.d.ts +1 -1
  34. package/dist/types/table/types.d.ts +30 -3
  35. package/dist/types/table/useResizer.d.ts +1 -0
  36. package/dist/types/table/useTableColumns.d.ts +6 -4
  37. package/dist/types/table/useVirtualTable.d.ts +9 -1
  38. package/dist/types/tree/TreePanel.d.ts +1 -1
  39. package/dist/types/tree/types.d.ts +6 -2
  40. package/dist/types/tree/useTree.d.ts +1 -0
  41. package/package.json +5 -5
  42. package/src/index.ts +2 -0
  43. package/src/table/AddColumn.tsx +55 -0
  44. package/src/table/BodyCell.tsx +18 -4
  45. package/src/table/CheckboxCell.tsx +48 -0
  46. package/src/table/Context.tsx +70 -0
  47. package/src/table/EmptyCell.tsx +57 -0
  48. package/src/table/HeaderCell.tsx +92 -25
  49. package/src/table/Table.tsx +178 -88
  50. package/src/table/types.ts +28 -2
  51. package/src/table/useResizer.ts +66 -0
  52. package/src/table/useTableColumns.ts +51 -18
  53. package/src/table/useVirtualTable.ts +47 -2
  54. package/src/tree/TreePanel.tsx +12 -1
  55. package/src/tree/types.ts +8 -1
  56. package/src/tree/useTree.ts +5 -0
@@ -1,132 +1,207 @@
1
1
  'use client';
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
- import { useMemo, useCallback } from 'react';
4
+ import { useDebounce, Loading, EmptyContent } from '@react-fabric/core';
5
+ import classNames from 'classnames';
6
+ import { useRef, useMemo, useImperativeHandle } from 'react';
7
+ import { useTranslation } from 'react-i18next';
8
+ import { AddColumn } from './AddColumn.js';
5
9
  import { BodyCell } from './BodyCell.js';
10
+ import { CheckboxCell } from './CheckboxCell.js';
11
+ import { TableProvider } from './Context.js';
12
+ import { EmptyCell } from './EmptyCell.js';
6
13
  import { HeaderCell } from './HeaderCell.js';
7
14
  import { useTableColumns } from './useTableColumns.js';
8
15
  import { useVirtualTable } from './useVirtualTable.js';
9
- import classNames from 'classnames';
10
16
  import { jsx, jsxs } from 'react/jsx-runtime';
11
17
 
12
18
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
19
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
20
  var Table = function Table(_ref) {
15
- var _columnMap$start, _columnMap$cols, _columnMap$end, _items$, _columnMap$start3, _columnMap$cols3, _columnMap$end3, _columnMap$start4, _columnMap$cols4, _columnMap$end4;
16
- var data = _ref.data,
17
- columns = _ref.columns;
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 = useTranslation("data"),
34
+ t = _useTranslation.t;
35
+ var fireCheckChanged = useDebounce(function (checkedIds) {
36
+ return onCheckedChanged === null || onCheckedChanged === void 0 ? void 0 : onCheckedChanged(checkedIds);
37
+ }, []);
18
38
  var _useTableColumns = useTableColumns(columns),
19
- columnMap = _useTableColumns.columnMap;
20
- var _useVirtualTable = useVirtualTable(data),
39
+ state = _useTableColumns.state,
40
+ onHide = _useTableColumns.onHide;
41
+ var _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 = useRef(null);
26
51
  var wrapperStart = useMemo(function () {
27
52
  return "bg-inherit sticky start-0 flex flex-nowrap z-1";
28
53
  }, []);
29
54
  var wrapperEnd = useMemo(function () {
30
55
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
31
56
  }, []);
32
- var emptyCol = useCallback(function (col, idc) {
33
- var _col$width, _col$minWidth, _col$maxWidth;
34
- return /*#__PURE__*/jsx("div", {
35
- className: "overflow-hidden border-e",
36
- style: {
37
- width: (_col$width = col.width) !== null && _col$width !== void 0 ? _col$width : "12rem",
38
- minWidth: (_col$minWidth = col.minWidth) !== null && _col$minWidth !== void 0 ? _col$minWidth : "2rem",
39
- maxWidth: (_col$maxWidth = col.maxWidth) !== null && _col$maxWidth !== void 0 ? _col$maxWidth : "32rem"
57
+ 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
- }, "blank:".concat(idc));
84
+ };
42
85
  }, []);
43
- return /*#__PURE__*/jsxs("div", {
44
- className: "grid area-content overflow-auto relative",
45
- style: {
46
- gridTemplate: "\"head\" auto \"content\" 1fr \"foot\" auto/1fr"
47
- },
48
- ref: scrollerRef,
49
- children: [/*#__PURE__*/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__*/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__*/jsx(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__*/jsx(HeaderCell, _objectSpread({}, col), idx);
58
- }), /*#__PURE__*/jsx("div", {
59
- className: wrapperEnd,
60
- children: (_columnMap$end = columnMap.end) === null || _columnMap$end === void 0 ? void 0 : _columnMap$end.map(function (col, idx) {
61
- return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
62
- })
63
- })]
64
- }), /*#__PURE__*/jsxs("div", {
65
- className: "area-content flex flex-col flex-nowrap",
86
+ return /*#__PURE__*/jsx(TableProvider, {
87
+ children: /*#__PURE__*/jsxs("div", {
88
+ className: "grid area-content overflow-auto relative",
66
89
  style: {
67
- height: totalSize()
90
+ gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
68
91
  },
69
- children: [/*#__PURE__*/jsx("div", {
92
+ ref: scrollerRef,
93
+ children: [/*#__PURE__*/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__*/jsxs("div", {
96
+ className: wrapperStart,
97
+ children: [checkableRows && /*#__PURE__*/jsx(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__*/jsx(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__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
108
+ sort: sort,
109
+ onSort: onSort
110
+ }), idx);
111
+ }), /*#__PURE__*/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__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
115
+ sort: sort,
116
+ onSort: onSort
117
+ }), idx);
118
+ }), hideableColumns && /*#__PURE__*/jsx(AddColumn, {
119
+ onClick: onHide,
120
+ columns: state.columns.filter(function (col) {
121
+ return col.hideable !== false;
122
+ })
123
+ })]
124
+ })]
125
+ }), loading && /*#__PURE__*/jsx(Loading, {}), data.length > 0 && /*#__PURE__*/jsxs("div", {
126
+ className: "area-content flex flex-col flex-nowrap",
70
127
  style: {
71
- height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
72
- }
73
- }), items.map(function (_ref2) {
74
- var _columnMap$start2, _columnMap$cols2, _columnMap$end2;
75
- var index = _ref2.index,
76
- key = _ref2.key;
77
- return /*#__PURE__*/jsxs("div", {
78
- className: classNames("flex flex-nowrap", index % 2 ? "bg-even" : "bg-odd"),
79
- "data-index": index,
80
- ref: measureElement,
81
- children: [/*#__PURE__*/jsx("div", {
82
- className: wrapperStart,
83
- children: (_columnMap$start2 = columnMap.start) === null || _columnMap$start2 === void 0 ? void 0 : _columnMap$start2.map(function (col, ids) {
128
+ height: totalSize()
129
+ },
130
+ ref: refBody,
131
+ children: [/*#__PURE__*/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__*/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__*/jsxs("div", {
150
+ className: wrapperStart,
151
+ children: [checkableRows && /*#__PURE__*/jsx(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__*/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) {
84
163
  return /*#__PURE__*/jsx(BodyCell, {
85
164
  column: col,
86
- item: getData(index)
87
- }, "".concat(key, ":").concat(ids));
88
- })
89
- }), (_columnMap$cols2 = columnMap.cols) === null || _columnMap$cols2 === void 0 ? void 0 : _columnMap$cols2.map(function (col, idc) {
90
- return /*#__PURE__*/jsx(BodyCell, {
91
- column: col,
92
- item: getData(index)
93
- }, "".concat(key, ":").concat(idc));
94
- }), /*#__PURE__*/jsx("div", {
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"
176
+ })]
177
+ })]
178
+ }, key);
179
+ }), /*#__PURE__*/jsxs("div", {
180
+ className: "flex-1 flex flex-nowrap",
181
+ children: [/*#__PURE__*/jsxs("div", {
182
+ className: wrapperStart,
183
+ children: [checkableRows && /*#__PURE__*/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__*/jsx(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__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
190
+ }), /*#__PURE__*/jsxs("div", {
95
191
  className: wrapperEnd,
96
- children: (_columnMap$end2 = columnMap.end) === null || _columnMap$end2 === void 0 ? void 0 : _columnMap$end2.map(function (col, ide) {
97
- return /*#__PURE__*/jsx(BodyCell, {
98
- column: col,
99
- item: getData(index)
100
- }, "".concat(key, ":").concat(ide));
101
- })
192
+ children: [(_state$end3 = state.end) === null || _state$end3 === void 0 ? void 0 : _state$end3.map(function (col) {
193
+ return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
194
+ }), hideableColumns && /*#__PURE__*/jsx("div", {
195
+ className: "w-6"
196
+ })]
102
197
  })]
103
- }, key);
104
- }), /*#__PURE__*/jsxs("div", {
105
- className: "flex-1 flex flex-nowrap",
106
- children: [/*#__PURE__*/jsx("div", {
107
- className: wrapperStart,
108
- children: (_columnMap$start3 = columnMap.start) === null || _columnMap$start3 === void 0 ? void 0 : _columnMap$start3.map(emptyCol)
109
- }), (_columnMap$cols3 = columnMap.cols) === null || _columnMap$cols3 === void 0 ? void 0 : _columnMap$cols3.map(emptyCol), /*#__PURE__*/jsx("div", {
110
- className: wrapperEnd,
111
- children: (_columnMap$end3 = columnMap.end) === null || _columnMap$end3 === void 0 ? void 0 : _columnMap$end3.map(emptyCol)
112
198
  })]
199
+ }), !loading && data.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
200
+ size: "sm",
201
+ className: "bg-dimmed",
202
+ message: t("datagrid.empty")
113
203
  })]
114
- }), /*#__PURE__*/jsxs("div", {
115
- className: "area-foot bg-dimmed border-t sticky bottom-0 flex flex-nowrap z-2",
116
- children: [/*#__PURE__*/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__*/jsx(HeaderCell, _objectSpread({}, col), idx);
120
- })
121
- }), (_columnMap$cols4 = columnMap.cols) === null || _columnMap$cols4 === void 0 ? void 0 : _columnMap$cols4.map(function (col, idx) {
122
- return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
123
- }), /*#__PURE__*/jsx("div", {
124
- className: wrapperEnd,
125
- children: (_columnMap$end4 = columnMap.end) === null || _columnMap$end4 === void 0 ? void 0 : _columnMap$end4.map(function (col, idx) {
126
- return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
127
- })
128
- })]
129
- })]
204
+ })
130
205
  });
131
206
  };
132
207
 
@@ -0,0 +1,30 @@
1
+ 'use client';
2
+
3
+ /*
4
+ * React Fabric
5
+ * @version: 1.0.0
6
+ *
7
+ *
8
+ * The MIT License (MIT)
9
+ * Copyright (c) 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
12
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
13
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
15
+ * subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
18
+ * portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+
26
+ var COL_MIN_WIDTH = "3rem";
27
+ var COL_MAX_WIDTH = "64rem";
28
+ var COL_DEFAULT_WIDTH = "12rem";
29
+
30
+ export { COL_DEFAULT_WIDTH, COL_MAX_WIDTH, COL_MIN_WIDTH };
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+
3
+ /*
4
+ * React Fabric
5
+ * @version: 1.0.0
6
+ *
7
+ *
8
+ * The MIT License (MIT)
9
+ * Copyright (c) 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
12
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
13
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
15
+ * subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
18
+ * portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+
26
+ var useResizer = function useResizer(colEl, ghostEl, callback) {
27
+ var placeholder = ghostEl.firstElementChild;
28
+ var isRtl = getComputedStyle(colEl).direction === "rtl";
29
+ var onResize = function onResize(evt) {
30
+ /** ***************** check if reverse enabled of RTL *******************/
31
+ var box = colEl.getBoundingClientRect();
32
+ var x = isRtl ? box.left - evt.clientX : evt.clientX - box.right;
33
+ placeholder.style.width = "".concat(colEl.offsetWidth + x, "px");
34
+ };
35
+
36
+ /** ***************** dettach handlers on mouseup *******************/
37
+ var onResizeEnd = function onResizeEnd() {
38
+ callback(placeholder.offsetWidth);
39
+ ghostEl.style.display = "none";
40
+ document.removeEventListener("mousemove", onResize);
41
+ document.removeEventListener("mouseup", onResizeEnd);
42
+ };
43
+
44
+ /** ***************** attach handlers *******************/
45
+ var box = colEl.getBoundingClientRect();
46
+ if (colEl.parentElement != null) {
47
+ var _colEl$parentElement;
48
+ var parentBox = (_colEl$parentElement = colEl.parentElement) === null || _colEl$parentElement === void 0 ? void 0 : _colEl$parentElement.getBoundingClientRect();
49
+ if (isRtl) {
50
+ placeholder.style.left = "unset";
51
+ placeholder.style.right = "".concat(box.right - parentBox.right, "px");
52
+ } else {
53
+ placeholder.style.right = "unset";
54
+ placeholder.style.left = "".concat(box.left - parentBox.left, "px");
55
+ }
56
+ }
57
+ placeholder.style.width = "".concat(colEl.offsetWidth, "px");
58
+ placeholder.style.minWidth = colEl.style.minWidth || "48px";
59
+ placeholder.style.maxWidth = colEl.style.maxWidth || "75vw";
60
+ ghostEl.style.display = "block";
61
+ document.addEventListener("mousemove", onResize);
62
+ document.addEventListener("mouseup", onResizeEnd);
63
+ };
64
+
65
+ export { useResizer };
@@ -1,25 +1,62 @@
1
1
  'use client';
2
2
 
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
5
  import { groupBy } from '@react-fabric/utilities';
5
- import { useState, useEffect } from 'react';
6
+ import { useReducer, useEffect } from 'react';
6
7
 
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
10
  var useTableColumns = function useTableColumns(columns) {
8
- var _useState = useState({
11
+ var _useReducer = useReducer(function (state, action) {
12
+ if (action.type === "columns") {
13
+ state.columns = action.columns;
14
+ }
15
+ if (action.type === "hide") {
16
+ var col = state.columns.find(function (col) {
17
+ return col.id === action.id;
18
+ });
19
+ col && state.columns.splice(state.columns.indexOf(col), 1, _objectSpread(_objectSpread({}, col), {}, {
20
+ hidden: col.hidden !== true
21
+ }));
22
+ }
23
+ var _groupBy = groupBy(state.columns.filter(function (col) {
24
+ return col.hidden !== true;
25
+ }), "locked", "cols"),
26
+ _groupBy$start = _groupBy.start,
27
+ start = _groupBy$start === void 0 ? [] : _groupBy$start,
28
+ _groupBy$end = _groupBy.end,
29
+ end = _groupBy$end === void 0 ? [] : _groupBy$end,
30
+ _groupBy$cols = _groupBy.cols,
31
+ cols = _groupBy$cols === void 0 ? [] : _groupBy$cols;
32
+ return _objectSpread(_objectSpread({}, state), {}, {
33
+ start: start,
34
+ end: end,
35
+ cols: cols
36
+ });
37
+ }, {
38
+ columns: [],
9
39
  start: [],
10
40
  end: [],
11
41
  cols: []
12
42
  }),
13
- _useState2 = _slicedToArray(_useState, 2),
14
- columnMap = _useState2[0],
15
- setColumnMap = _useState2[1];
43
+ _useReducer2 = _slicedToArray(_useReducer, 2),
44
+ state = _useReducer2[0],
45
+ dispatch = _useReducer2[1];
16
46
  useEffect(function () {
17
- setColumnMap(groupBy(columns.filter(function (col) {
18
- return !(col.hideable && col.hidden);
19
- }), "locked", "cols"));
47
+ dispatch({
48
+ type: "columns",
49
+ columns: columns
50
+ });
20
51
  }, [columns]);
21
52
  return {
22
- columnMap: columnMap
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 client';
2
2
 
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
5
  import { useVirtualizer } from '@tanstack/react-virtual';
4
- import { useRef, useCallback } from 'react';
6
+ import { useRef, useReducer, useCallback } from 'react';
5
7
 
6
- /*
7
- * React Fabric
8
- * @version: 1.0.0
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 = 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 = 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
 
@@ -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 items = _ref.items,
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,
@@ -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
  };
@@ -3,7 +3,9 @@ export { Histogram } from "./histogram/Histogram";
3
3
  export { JsonViewer } from "./json/JsonViewer";
4
4
  export { Pagination } from "./pagination/Pagination";
5
5
  export { Table } from "./table/Table";
6
+ export { type TableRef } from "./table/types";
6
7
  export { TreePanel } from "./tree/TreePanel";
8
+ export { type TreeNodeType as TreeNode } from "./tree/types";
7
9
  export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
8
10
  export { VirtualList, type VirtualListRef } from "./virtual/List";
9
11
  export * from "./hooks/useFilteredList";
@@ -0,0 +1,5 @@
1
+ import { type ColumnType } from "./types";
2
+ export declare const AddColumn: ({ columns, onClick, }: {
3
+ columns: ColumnType[];
4
+ onClick: (id: string) => void;
5
+ }) => import("react/jsx-runtime").JSX.Element;