@react-fabric/data 1.0.0-beta.0 → 1.0.0-beta.1

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 (44) 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 +136 -94
  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/esm/table/AddColumn.js +56 -0
  13. package/dist/esm/table/BodyCell.js +13 -4
  14. package/dist/esm/table/CheckboxCell.js +44 -0
  15. package/dist/esm/table/Context.js +42 -0
  16. package/dist/esm/table/EmptyCell.js +52 -0
  17. package/dist/esm/table/HeaderCell.js +79 -34
  18. package/dist/esm/table/Table.js +137 -95
  19. package/dist/esm/table/types.js +30 -0
  20. package/dist/esm/table/useResizer.js +65 -0
  21. package/dist/esm/table/useTableColumns.js +46 -9
  22. package/dist/esm/table/useVirtualTable.js +43 -26
  23. package/dist/types/table/AddColumn.d.ts +5 -0
  24. package/dist/types/table/CheckboxCell.d.ts +4 -0
  25. package/dist/types/table/Context.d.ts +8 -0
  26. package/dist/types/table/EmptyCell.d.ts +2 -0
  27. package/dist/types/table/HeaderCell.d.ts +2 -2
  28. package/dist/types/table/Table.d.ts +1 -1
  29. package/dist/types/table/types.d.ts +23 -1
  30. package/dist/types/table/useResizer.d.ts +1 -0
  31. package/dist/types/table/useTableColumns.d.ts +6 -4
  32. package/dist/types/table/useVirtualTable.d.ts +9 -1
  33. package/package.json +5 -5
  34. package/src/table/AddColumn.tsx +55 -0
  35. package/src/table/BodyCell.tsx +18 -4
  36. package/src/table/CheckboxCell.tsx +48 -0
  37. package/src/table/Context.tsx +70 -0
  38. package/src/table/EmptyCell.tsx +57 -0
  39. package/src/table/HeaderCell.tsx +92 -25
  40. package/src/table/Table.tsx +149 -89
  41. package/src/table/types.ts +20 -1
  42. package/src/table/useResizer.ts +66 -0
  43. package/src/table/useTableColumns.ts +51 -18
  44. package/src/table/useVirtualTable.ts +47 -2
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var core = require('@react-fabric/core');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
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 AddColumn = function AddColumn(_ref) {
30
+ var columns = _ref.columns,
31
+ onClick = _ref.onClick;
32
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
33
+ className: "group font-medium w-6 flex flex-nowrap text-start items-end",
34
+ children: /*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
35
+ placement: "bottom-end",
36
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Icon, {
37
+ icon: core.CoreIcons.insert,
38
+ className: "p-1 rounded-t rounded-b-none hover:outline"
39
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Menu, {
40
+ className: "text-sm",
41
+ onClick: onClick,
42
+ children: columns.map(function (col) {
43
+ var _col$label;
44
+ return /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
45
+ id: String(col.id),
46
+ "data-dropdown-dismiss": "false",
47
+ label: "".concat((_col$label = col.label) !== null && _col$label !== void 0 ? _col$label : String(col.id)),
48
+ icon: !col.hidden ? core.CoreIcons.tick : ""
49
+ }, String(col.id));
50
+ })
51
+ })]
52
+ })
53
+ });
54
+ };
55
+
56
+ exports.AddColumn = AddColumn;
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var classNames = require('classnames');
4
+ var react = require('react');
5
+ var Context = require('./Context.js');
6
+ var types = require('./types.js');
4
7
  var jsxRuntime = require('react/jsx-runtime');
5
8
 
6
9
  /*
@@ -27,15 +30,21 @@ var jsxRuntime = require('react/jsx-runtime');
27
30
  */
28
31
 
29
32
  var BodyCell = function BodyCell(_ref) {
30
- var _column$width, _column$minWidth, _column$maxWidth, _column$renderer, _column$renderer2;
33
+ var _column$minWidth, _column$maxWidth, _column$renderer, _column$renderer2;
31
34
  var column = _ref.column,
32
35
  item = _ref.item;
36
+ var _useTableContext = Context.useTableContext(),
37
+ widths = _useTableContext.widths;
38
+ var width = react.useMemo(function () {
39
+ var _widths$get;
40
+ return (_widths$get = widths.get(column.id.toString())) !== null && _widths$get !== void 0 ? _widths$get : column.width;
41
+ }, [widths, column]);
33
42
  return /*#__PURE__*/jsxRuntime.jsx("div", {
34
43
  className: "overflow-hidden bg-inherit start-0",
35
44
  style: {
36
- width: (_column$width = column.width) !== null && _column$width !== void 0 ? _column$width : "12rem",
37
- minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : "2rem",
38
- maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth : "32rem"
45
+ width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
46
+ minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : types.COL_MIN_WIDTH,
47
+ maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth : types.COL_MAX_WIDTH
39
48
  },
40
49
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
41
50
  className: classNames("px-2 py-1 border-e truncate", column.align === "center" && "text-center", column.align === "end" && "text-end"),
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var core = require('@react-fabric/core');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
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 CheckboxCell = function CheckboxCell(_ref) {
30
+ var state = _ref.state,
31
+ _onClick = _ref.onClick;
32
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
33
+ className: "group font-medium border-e w-6 flex flex-nowrap text-start items-center",
34
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
35
+ icon: state === 2 ? core.CoreIcons.checkboxInt : state === 1 ? core.CoreIcons.checkboxOn : core.CoreIcons.checkboxOff,
36
+ className: "p-1 text-tint-700 hover:text-primary-600",
37
+ onClick: function onClick(e) {
38
+ return [_onClick === null || _onClick === void 0 ? void 0 : _onClick(), e.stopPropagation()];
39
+ }
40
+ })
41
+ });
42
+ };
43
+
44
+ exports.CheckboxCell = CheckboxCell;
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var react = require('react');
5
+ var useResizer = require('./useResizer.js');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+
8
+ var TableContext = /*#__PURE__*/react.createContext({});
9
+ var TableProvider = function TableProvider(_ref) {
10
+ var children = _ref.children;
11
+ var ghostRef = react.useRef(null);
12
+ var _useState = react.useState(new Map()),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ widths = _useState2[0],
15
+ setWidths = _useState2[1];
16
+ var startResize = react.useCallback(function (col) {
17
+ if (col) {
18
+ ghostRef.current != null && useResizer.useResizer(col, ghostRef.current, function (width) {
19
+ var _col$dataset$id;
20
+ setWidths(new Map(widths.set((_col$dataset$id = col.dataset.id) !== null && _col$dataset$id !== void 0 ? _col$dataset$id : "", width)));
21
+ });
22
+ }
23
+ }, [widths]);
24
+ return /*#__PURE__*/jsxRuntime.jsxs(TableContext.Provider, {
25
+ value: {
26
+ startResize: startResize,
27
+ widths: widths
28
+ },
29
+ children: [children, /*#__PURE__*/jsxRuntime.jsx("div", {
30
+ className: "absolute inset-0 hidden z-20 cursor-col-resize",
31
+ ref: ghostRef,
32
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
33
+ className: "absolute inset-y-0 bg-muted opacity-50 border-primary border-e-2"
34
+ })
35
+ })]
36
+ });
37
+ };
38
+ var useTableContext = function useTableContext() {
39
+ return react.useContext(TableContext);
40
+ };
41
+
42
+ exports.TableProvider = TableProvider;
43
+ exports.useTableContext = useTableContext;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var Context = require('./Context.js');
5
+ var types = require('./types.js');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+
8
+ /*
9
+ * React Fabric
10
+ * @version: 1.0.0
11
+ *
12
+ *
13
+ * The MIT License (MIT)
14
+ * Copyright (c) 2024 Adarsh Pastakia
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
17
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
18
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
19
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
20
+ * subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
23
+ * portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
26
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ */
30
+
31
+ var EmptyCell = function EmptyCell(_ref) {
32
+ var id = _ref.id,
33
+ _width = _ref.width,
34
+ maxWidth = _ref.maxWidth,
35
+ minWidth = _ref.minWidth;
36
+ var _useTableContext = Context.useTableContext(),
37
+ widths = _useTableContext.widths;
38
+ var width = react.useMemo(function () {
39
+ var _widths$get;
40
+ return (_widths$get = widths.get(id.toString())) !== null && _widths$get !== void 0 ? _widths$get : _width;
41
+ }, [widths, id, _width]);
42
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
43
+ className: "overflow-hidden border-e",
44
+ style: {
45
+ width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
46
+ minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : types.COL_MIN_WIDTH,
47
+ maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : types.COL_MAX_WIDTH
48
+ }
49
+ }, "blank:".concat(id.toString()));
50
+ };
51
+
52
+ exports.EmptyCell = EmptyCell;
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@react-fabric/core');
4
+ var react = require('react');
5
+ var Context = require('./Context.js');
6
+ var types = require('./types.js');
4
7
  var jsxRuntime = require('react/jsx-runtime');
5
8
 
6
9
  /*
@@ -27,51 +30,93 @@ var jsxRuntime = require('react/jsx-runtime');
27
30
  */
28
31
 
29
32
  var HeaderCell = function HeaderCell(_ref) {
30
- var label = _ref.label,
33
+ var id = _ref.id,
34
+ label = _ref.label,
31
35
  icon = _ref.icon,
32
36
  iconBg = _ref.iconBg,
33
37
  iconColor = _ref.iconColor,
34
38
  rtlFlip = _ref.rtlFlip;
35
39
  _ref.actions;
36
40
  _ref.locked;
37
- var resizable = _ref.resizable,
38
- width = _ref.width,
41
+ var sortable = _ref.sortable,
42
+ resizable = _ref.resizable,
43
+ _width = _ref.width,
39
44
  maxWidth = _ref.maxWidth,
40
- minWidth = _ref.minWidth;
45
+ minWidth = _ref.minWidth,
46
+ sort = _ref.sort,
47
+ onSort = _ref.onSort;
48
+ var _useTableContext = Context.useTableContext(),
49
+ startResize = _useTableContext.startResize,
50
+ widths = _useTableContext.widths;
51
+ var width = react.useMemo(function () {
52
+ var _widths$get;
53
+ return (_widths$get = widths.get(id.toString())) !== null && _widths$get !== void 0 ? _widths$get : _width;
54
+ }, [widths, _width, id]);
55
+ var handleSort = react.useCallback(function () {
56
+ sortable && (onSort === null || onSort === void 0 ? void 0 : onSort({
57
+ id: id.toString(),
58
+ order: (sort === null || sort === void 0 ? void 0 : sort.id) === id && sort.order === "asc" ? "desc" : "asc"
59
+ }));
60
+ }, [onSort, name, sort, sortable]);
61
+ var menus = react.useMemo(function () {
62
+ var ret = [];
63
+ if (sortable) {
64
+ ret.push( /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
65
+ label: "Sort ascending",
66
+ icon: core.CoreIcons.sortAsc
67
+ }, "sort-asc"), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
68
+ label: "Sort descending",
69
+ icon: core.CoreIcons.sortDesc
70
+ }, "sort-desc"));
71
+ }
72
+ return ret;
73
+ }, [sortable]);
41
74
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
42
- className: "group font-medium border-e flex flex-nowrap text-start items-center",
75
+ role: "none",
76
+ "data-id": id,
77
+ onClick: handleSort,
78
+ className: "group font-medium border-e flex flex-nowrap text-start items-center table-header-cell",
43
79
  style: {
44
- width: width !== null && width !== void 0 ? width : "12rem",
45
- minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : "2rem",
46
- maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : "32rem"
80
+ width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
81
+ minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : types.COL_MIN_WIDTH,
82
+ maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : types.COL_MAX_WIDTH
47
83
  },
48
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
49
- className: "flex-1 px-2 py-1 text-sm truncate sticky start-0",
50
- children: [icon && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
51
- icon: icon,
52
- bg: iconBg,
53
- color: iconColor,
54
- rtlFlip: rtlFlip
55
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
56
- children: label !== null && label !== void 0 ? label : " "
57
- })]
58
- }), /*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
59
- placement: "bottom-start",
60
- children: [/*#__PURE__*/jsxRuntime.jsx(core.Icon, {
61
- icon: core.CoreIcons.caretDown,
62
- className: "outline bg-base me-0.5 flex-content hidden group-hover:inline-block data-[dropdown-open]:inline-block"
63
- }), /*#__PURE__*/jsxRuntime.jsxs(core.Menu, {
64
- className: "text-sm",
65
- children: [/*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
66
- label: "Sort ascending",
67
- icon: core.CoreIcons.sortAsc
68
- }), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
69
- label: "Sort descending",
70
- icon: core.CoreIcons.sortDesc
84
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
85
+ content: label,
86
+ disabled: !label,
87
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
88
+ className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
89
+ children: [icon && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
90
+ icon: icon,
91
+ bg: iconBg,
92
+ color: iconColor,
93
+ rtlFlip: rtlFlip
94
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
95
+ children: label !== null && label !== void 0 ? label : " "
71
96
  })]
97
+ })
98
+ }), sortable && /*#__PURE__*/jsxRuntime.jsxs("div", {
99
+ className: "text-sm text-tint-300",
100
+ children: [(sort === null || sort === void 0 ? void 0 : sort.id) === id && (sort === null || sort === void 0 ? void 0 : sort.order) === "desc" && /*#__PURE__*/jsxRuntime.jsx("span", {
101
+ children: "\u25BC"
102
+ }), (sort === null || sort === void 0 ? void 0 : sort.id) === id && (sort === null || sort === void 0 ? void 0 : sort.order) === "asc" && /*#__PURE__*/jsxRuntime.jsx("span", {
103
+ children: "\u25B2"
72
104
  })]
105
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
106
+ className: "flex-1"
107
+ }), menus.length > 0 && /*#__PURE__*/jsxRuntime.jsx(core.DropdownTool, {
108
+ groupHover: true,
109
+ placement: "bottom-end",
110
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Menu, {
111
+ className: "text-sm",
112
+ children: menus
113
+ })
73
114
  }), resizable && /*#__PURE__*/jsxRuntime.jsx("div", {
74
- className: "cursor-col-resize border-e bg-transparent border-tint-200 w-[5px] self-stretch"
115
+ role: "none",
116
+ className: "cursor-col-resize border-e bg-transparent border-tint-200 w-[5px] self-stretch",
117
+ onMouseDown: function onMouseDown(e) {
118
+ return e.currentTarget.parentElement && startResize(e.currentTarget.parentElement);
119
+ }
75
120
  })]
76
121
  });
77
122
  };
@@ -1,25 +1,48 @@
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 _columnMap$start, _columnMap$cols, _columnMap$end, _items$, _columnMap$start3, _columnMap$cols3, _columnMap$end3, _columnMap$start4, _columnMap$cols4, _columnMap$end4;
21
+ var _state$start, _state$cols, _state$end, _items$, _state$start3, _state$cols3, _state$end3;
16
22
  var data = _ref.data,
17
- columns = _ref.columns;
23
+ columns = _ref.columns,
24
+ keyProperty = _ref.keyProperty,
25
+ checkableRows = _ref.checkableRows,
26
+ hideableColumns = _ref.hideableColumns,
27
+ sort = _ref.sort,
28
+ loading = _ref.loading,
29
+ onSort = _ref.onSort,
30
+ onRowClick = _ref.onRowClick,
31
+ onCheckedChanged = _ref.onCheckedChanged;
32
+ var _useTranslation = reactI18next.useTranslation("data"),
33
+ t = _useTranslation.t;
34
+ var fireCheckChanged = core.useDebounce(function (checkedIds) {
35
+ return onCheckedChanged === null || onCheckedChanged === void 0 ? void 0 : onCheckedChanged(checkedIds);
36
+ }, []);
18
37
  var _useTableColumns = useTableColumns.useTableColumns(columns),
19
- columnMap = _useTableColumns.columnMap;
20
- var _useVirtualTable = useVirtualTable.useVirtualTable(data),
38
+ state = _useTableColumns.state,
39
+ onHide = _useTableColumns.onHide;
40
+ var _useVirtualTable = useVirtualTable.useVirtualTable(data, keyProperty, fireCheckChanged),
21
41
  scrollerRef = _useVirtualTable.scrollerRef,
22
42
  items = _useVirtualTable.items,
43
+ checkState = _useVirtualTable.checkState,
44
+ toggleChecked = _useVirtualTable.toggleChecked,
45
+ toggleAllChecked = _useVirtualTable.toggleAllChecked,
23
46
  getData = _useVirtualTable.getData,
24
47
  totalSize = _useVirtualTable.totalSize,
25
48
  measureElement = _useVirtualTable.measureElement;
@@ -29,104 +52,123 @@ var Table = function Table(_ref) {
29
52
  var wrapperEnd = react.useMemo(function () {
30
53
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
31
54
  }, []);
32
- var emptyCol = react.useCallback(function (col, idc) {
33
- var _col$width, _col$minWidth, _col$maxWidth;
34
- return /*#__PURE__*/jsxRuntime.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"
40
- }
41
- }, "blank:".concat(idc));
42
- }, []);
43
- return /*#__PURE__*/jsxRuntime.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__*/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",
55
+ return /*#__PURE__*/jsxRuntime.jsx(Context.TableProvider, {
56
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
57
+ className: "grid area-content overflow-auto relative",
66
58
  style: {
67
- height: totalSize()
59
+ gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
68
60
  },
69
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
61
+ ref: scrollerRef,
62
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
63
+ className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
64
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
65
+ className: wrapperStart,
66
+ children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
67
+ state: checkState.allChecked,
68
+ onClick: toggleAllChecked
69
+ }), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
70
+ return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
71
+ sort: sort,
72
+ onSort: onSort
73
+ }), idx);
74
+ })]
75
+ }), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idx) {
76
+ return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
77
+ sort: sort,
78
+ onSort: onSort
79
+ }), idx);
80
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
81
+ className: wrapperEnd,
82
+ children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, idx) {
83
+ return /*#__PURE__*/jsxRuntime.jsx(HeaderCell.HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
84
+ sort: sort,
85
+ onSort: onSort
86
+ }), idx);
87
+ }), hideableColumns && /*#__PURE__*/jsxRuntime.jsx(AddColumn.AddColumn, {
88
+ onClick: onHide,
89
+ columns: state.columns.filter(function (col) {
90
+ return col.hideable !== false;
91
+ })
92
+ })]
93
+ })]
94
+ }), loading && /*#__PURE__*/jsxRuntime.jsx(core.Loading, {}), data.length > 0 && /*#__PURE__*/jsxRuntime.jsxs("div", {
95
+ className: "area-content flex flex-col flex-nowrap",
70
96
  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__*/jsxRuntime.jsxs("div", {
78
- className: classNames("flex flex-nowrap", index % 2 ? "bg-even" : "bg-odd"),
79
- "data-index": index,
80
- ref: measureElement,
81
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
82
- className: wrapperStart,
83
- children: (_columnMap$start2 = columnMap.start) === null || _columnMap$start2 === void 0 ? void 0 : _columnMap$start2.map(function (col, ids) {
97
+ height: totalSize()
98
+ },
99
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
100
+ style: {
101
+ height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
102
+ }
103
+ }), items.map(function (_ref2) {
104
+ var _state$start2, _state$cols2, _state$end2;
105
+ var index = _ref2.index,
106
+ key = _ref2.key;
107
+ var data = getData(index);
108
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
109
+ role: "none",
110
+ className: classNames("flex flex-nowrap", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
111
+ onClick: function onClick() {
112
+ return checkableRows && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
113
+ },
114
+ "data-index": index,
115
+ ref: measureElement,
116
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
117
+ className: wrapperStart,
118
+ children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
119
+ onClick: function onClick() {
120
+ return toggleChecked(data[keyProperty]);
121
+ },
122
+ state: checkState.checked.includes(data[keyProperty]) ? 1 : 0
123
+ }), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col, ids) {
124
+ return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
125
+ column: col,
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) {
84
130
  return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
85
131
  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__*/jsxRuntime.jsx(BodyCell.BodyCell, {
91
- column: col,
92
- item: getData(index)
93
- }, "".concat(key, ":").concat(idc));
94
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
132
+ item: data
133
+ }, "".concat(key, ":").concat(idc));
134
+ }), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx(BodyCell.BodyCell, {
138
+ column: col,
139
+ item: data
140
+ }, "".concat(key, ":").concat(ide));
141
+ }), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
142
+ className: "w-6"
143
+ })]
144
+ })]
145
+ }, key);
146
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
147
+ className: "flex-1 flex flex-nowrap",
148
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
149
+ className: wrapperStart,
150
+ children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx("div", {
151
+ className: "w-6"
152
+ }), (_state$start3 = state.start) === null || _state$start3 === void 0 ? void 0 : _state$start3.map(function (col) {
153
+ return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
154
+ })]
155
+ }), (_state$cols3 = state.cols) === null || _state$cols3 === void 0 ? void 0 : _state$cols3.map(function (col) {
156
+ return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
157
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
95
158
  className: wrapperEnd,
96
- children: (_columnMap$end2 = columnMap.end) === null || _columnMap$end2 === void 0 ? void 0 : _columnMap$end2.map(function (col, ide) {
97
- return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
98
- column: col,
99
- item: getData(index)
100
- }, "".concat(key, ":").concat(ide));
101
- })
159
+ children: [(_state$end3 = state.end) === null || _state$end3 === void 0 ? void 0 : _state$end3.map(function (col) {
160
+ return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
161
+ }), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
162
+ className: "w-6"
163
+ })]
102
164
  })]
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
165
  })]
166
+ }), !loading && data.length === 0 && /*#__PURE__*/jsxRuntime.jsx(core.EmptyContent, {
167
+ size: "sm",
168
+ className: "bg-dimmed",
169
+ message: t("datagrid.empty")
113
170
  })]
114
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
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
- })]
171
+ })
130
172
  });
131
173
  };
132
174