@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.
- 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 +136 -94
- 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/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 +137 -95
- 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/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 +23 -1
- 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/package.json +5 -5
- 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 +149 -89
- package/src/table/types.ts +20 -1
- package/src/table/useResizer.ts +66 -0
- package/src/table/useTableColumns.ts +51 -18
- package/src/table/useVirtualTable.ts +47 -2
|
@@ -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
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Dropdown, Icon, CoreIcons, Menu, MenuItem } from '@react-fabric/core';
|
|
4
|
+
import { jsx, jsxs } from '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__*/jsx("div", {
|
|
33
|
+
className: "group font-medium w-6 flex flex-nowrap text-start items-end",
|
|
34
|
+
children: /*#__PURE__*/jsxs(Dropdown, {
|
|
35
|
+
placement: "bottom-end",
|
|
36
|
+
children: [/*#__PURE__*/jsx(Icon, {
|
|
37
|
+
icon: CoreIcons.insert,
|
|
38
|
+
className: "p-1 rounded-t rounded-b-none hover:outline"
|
|
39
|
+
}), /*#__PURE__*/jsx(Menu, {
|
|
40
|
+
className: "text-sm",
|
|
41
|
+
onClick: onClick,
|
|
42
|
+
children: columns.map(function (col) {
|
|
43
|
+
var _col$label;
|
|
44
|
+
return /*#__PURE__*/jsx(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 ? CoreIcons.tick : ""
|
|
49
|
+
}, String(col.id));
|
|
50
|
+
})
|
|
51
|
+
})]
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { AddColumn };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { useTableContext } from './Context.js';
|
|
6
|
+
import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
|
|
4
7
|
import { jsx } from 'react/jsx-runtime';
|
|
5
8
|
|
|
6
9
|
/*
|
|
@@ -27,15 +30,21 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
27
30
|
*/
|
|
28
31
|
|
|
29
32
|
var BodyCell = function BodyCell(_ref) {
|
|
30
|
-
var _column$
|
|
33
|
+
var _column$minWidth, _column$maxWidth, _column$renderer, _column$renderer2;
|
|
31
34
|
var column = _ref.column,
|
|
32
35
|
item = _ref.item;
|
|
36
|
+
var _useTableContext = useTableContext(),
|
|
37
|
+
widths = _useTableContext.widths;
|
|
38
|
+
var width = 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__*/jsx("div", {
|
|
34
43
|
className: "overflow-hidden bg-inherit start-0",
|
|
35
44
|
style: {
|
|
36
|
-
width:
|
|
37
|
-
minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth :
|
|
38
|
-
maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth :
|
|
45
|
+
width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
|
|
46
|
+
minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : COL_MIN_WIDTH,
|
|
47
|
+
maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth : COL_MAX_WIDTH
|
|
39
48
|
},
|
|
40
49
|
children: /*#__PURE__*/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 client';
|
|
2
|
+
|
|
3
|
+
import { Icon, CoreIcons } from '@react-fabric/core';
|
|
4
|
+
import { jsx } from '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__*/jsx("div", {
|
|
33
|
+
className: "group font-medium border-e w-6 flex flex-nowrap text-start items-center",
|
|
34
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
35
|
+
icon: state === 2 ? CoreIcons.checkboxInt : state === 1 ? CoreIcons.checkboxOn : 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
|
+
export { CheckboxCell };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
+
import { useRef, useState, useCallback, createContext, useContext } from 'react';
|
|
5
|
+
import { useResizer } from './useResizer.js';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var TableContext = /*#__PURE__*/createContext({});
|
|
9
|
+
var TableProvider = function TableProvider(_ref) {
|
|
10
|
+
var children = _ref.children;
|
|
11
|
+
var ghostRef = useRef(null);
|
|
12
|
+
var _useState = useState(new Map()),
|
|
13
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
14
|
+
widths = _useState2[0],
|
|
15
|
+
setWidths = _useState2[1];
|
|
16
|
+
var startResize = useCallback(function (col) {
|
|
17
|
+
if (col) {
|
|
18
|
+
ghostRef.current != null && 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__*/jsxs(TableContext.Provider, {
|
|
25
|
+
value: {
|
|
26
|
+
startResize: startResize,
|
|
27
|
+
widths: widths
|
|
28
|
+
},
|
|
29
|
+
children: [children, /*#__PURE__*/jsx("div", {
|
|
30
|
+
className: "absolute inset-0 hidden z-20 cursor-col-resize",
|
|
31
|
+
ref: ghostRef,
|
|
32
|
+
children: /*#__PURE__*/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 useContext(TableContext);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { TableProvider, useTableContext };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useTableContext } from './Context.js';
|
|
5
|
+
import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
|
|
6
|
+
import { jsx } from '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 = useTableContext(),
|
|
37
|
+
widths = _useTableContext.widths;
|
|
38
|
+
var width = 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__*/jsx("div", {
|
|
43
|
+
className: "overflow-hidden border-e",
|
|
44
|
+
style: {
|
|
45
|
+
width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
|
|
46
|
+
minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : COL_MIN_WIDTH,
|
|
47
|
+
maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : COL_MAX_WIDTH
|
|
48
|
+
}
|
|
49
|
+
}, "blank:".concat(id.toString()));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { EmptyCell };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { MenuItem, CoreIcons, Tooltip, Icon, DropdownTool, Menu } from '@react-fabric/core';
|
|
4
|
+
import { useMemo, useCallback } from 'react';
|
|
5
|
+
import { useTableContext } from './Context.js';
|
|
6
|
+
import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
|
|
7
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
8
|
|
|
6
9
|
/*
|
|
7
10
|
* React Fabric
|
|
@@ -27,51 +30,93 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
27
30
|
*/
|
|
28
31
|
|
|
29
32
|
var HeaderCell = function HeaderCell(_ref) {
|
|
30
|
-
var
|
|
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
|
|
38
|
-
|
|
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 = useTableContext(),
|
|
49
|
+
startResize = _useTableContext.startResize,
|
|
50
|
+
widths = _useTableContext.widths;
|
|
51
|
+
var width = 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 = 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 = useMemo(function () {
|
|
62
|
+
var ret = [];
|
|
63
|
+
if (sortable) {
|
|
64
|
+
ret.push( /*#__PURE__*/jsx(MenuItem, {
|
|
65
|
+
label: "Sort ascending",
|
|
66
|
+
icon: CoreIcons.sortAsc
|
|
67
|
+
}, "sort-asc"), /*#__PURE__*/jsx(MenuItem, {
|
|
68
|
+
label: "Sort descending",
|
|
69
|
+
icon: CoreIcons.sortDesc
|
|
70
|
+
}, "sort-desc"));
|
|
71
|
+
}
|
|
72
|
+
return ret;
|
|
73
|
+
}, [sortable]);
|
|
41
74
|
return /*#__PURE__*/jsxs("div", {
|
|
42
|
-
|
|
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 :
|
|
45
|
-
minWidth: minWidth !== null && minWidth !== void 0 ? minWidth :
|
|
46
|
-
maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth :
|
|
80
|
+
width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
|
|
81
|
+
minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : COL_MIN_WIDTH,
|
|
82
|
+
maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : COL_MAX_WIDTH
|
|
47
83
|
},
|
|
48
|
-
children: [/*#__PURE__*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
children: [/*#__PURE__*/jsx(Icon, {
|
|
61
|
-
icon: CoreIcons.caretDown,
|
|
62
|
-
className: "outline bg-base me-0.5 flex-content hidden group-hover:inline-block data-[dropdown-open]:inline-block"
|
|
63
|
-
}), /*#__PURE__*/jsxs(Menu, {
|
|
64
|
-
className: "text-sm",
|
|
65
|
-
children: [/*#__PURE__*/jsx(MenuItem, {
|
|
66
|
-
label: "Sort ascending",
|
|
67
|
-
icon: CoreIcons.sortAsc
|
|
68
|
-
}), /*#__PURE__*/jsx(MenuItem, {
|
|
69
|
-
label: "Sort descending",
|
|
70
|
-
icon: CoreIcons.sortDesc
|
|
84
|
+
children: [/*#__PURE__*/jsx(Tooltip, {
|
|
85
|
+
content: label,
|
|
86
|
+
disabled: !label,
|
|
87
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
88
|
+
className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
|
|
89
|
+
children: [icon && /*#__PURE__*/jsx(Icon, {
|
|
90
|
+
icon: icon,
|
|
91
|
+
bg: iconBg,
|
|
92
|
+
color: iconColor,
|
|
93
|
+
rtlFlip: rtlFlip
|
|
94
|
+
}), /*#__PURE__*/jsx("span", {
|
|
95
|
+
children: label !== null && label !== void 0 ? label : " "
|
|
71
96
|
})]
|
|
97
|
+
})
|
|
98
|
+
}), sortable && /*#__PURE__*/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__*/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__*/jsx("span", {
|
|
103
|
+
children: "\u25B2"
|
|
72
104
|
})]
|
|
105
|
+
}), /*#__PURE__*/jsx("div", {
|
|
106
|
+
className: "flex-1"
|
|
107
|
+
}), menus.length > 0 && /*#__PURE__*/jsx(DropdownTool, {
|
|
108
|
+
groupHover: true,
|
|
109
|
+
placement: "bottom-end",
|
|
110
|
+
children: /*#__PURE__*/jsx(Menu, {
|
|
111
|
+
className: "text-sm",
|
|
112
|
+
children: menus
|
|
113
|
+
})
|
|
73
114
|
}), resizable && /*#__PURE__*/jsx("div", {
|
|
74
|
-
|
|
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
|
};
|