trotl-table 1.0.12 → 1.0.13
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/index.cjs.js +193 -96
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +168 -72
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var React = require('react');
|
|
5
|
+
var React$1 = require('react');
|
|
6
6
|
var reactDnd = require('react-dnd');
|
|
7
7
|
var reactDndHtml5Backend = require('react-dnd-html5-backend');
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React$1);
|
|
27
27
|
|
|
28
28
|
function _classCallCheck(a, n) {
|
|
29
29
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
@@ -912,7 +912,7 @@ var CellMeasurer = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
912
912
|
if (resolvedChildren === null) {
|
|
913
913
|
return resolvedChildren;
|
|
914
914
|
}
|
|
915
|
-
return /*#__PURE__*/React.cloneElement(resolvedChildren, {
|
|
915
|
+
return /*#__PURE__*/React$1.cloneElement(resolvedChildren, {
|
|
916
916
|
ref: function ref(node) {
|
|
917
917
|
if (typeof resolvedChildren.ref === 'function') {
|
|
918
918
|
resolvedChildren.ref(node);
|
|
@@ -4140,7 +4140,7 @@ function defaultCellRangeRenderer(_ref /*:: */) {
|
|
|
4140
4140
|
warnAboutMissingStyle(parent, renderedCell);
|
|
4141
4141
|
}
|
|
4142
4142
|
if (!renderedCell.props.role) {
|
|
4143
|
-
renderedCell = /*#__PURE__*/React.cloneElement(renderedCell, {
|
|
4143
|
+
renderedCell = /*#__PURE__*/React$1.cloneElement(renderedCell, {
|
|
4144
4144
|
role: 'gridcell'
|
|
4145
4145
|
});
|
|
4146
4146
|
}
|
|
@@ -9555,7 +9555,7 @@ const Modal = ({
|
|
|
9555
9555
|
closeOnEscape = true,
|
|
9556
9556
|
closeOnOutsideClick = true
|
|
9557
9557
|
}) => {
|
|
9558
|
-
React.useEffect(() => {
|
|
9558
|
+
React$1.useEffect(() => {
|
|
9559
9559
|
const handleKey = e => {
|
|
9560
9560
|
if (e.key === 'Escape' && closeOnEscape) {
|
|
9561
9561
|
onCancel?.();
|
|
@@ -9565,22 +9565,22 @@ const Modal = ({
|
|
|
9565
9565
|
return () => document.removeEventListener('keydown', handleKey);
|
|
9566
9566
|
}, [closeOnEscape, onCancel]);
|
|
9567
9567
|
if (!isOpen) return null;
|
|
9568
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
9568
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
9569
9569
|
className: "modal-overlay",
|
|
9570
9570
|
onClick: closeOnOutsideClick ? onCancel : undefined
|
|
9571
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
9571
|
+
}, /*#__PURE__*/React$1.createElement("div", {
|
|
9572
9572
|
className: "modal-box",
|
|
9573
9573
|
onClick: e => e.stopPropagation()
|
|
9574
|
-
}, /*#__PURE__*/React.createElement("h3", {
|
|
9574
|
+
}, /*#__PURE__*/React$1.createElement("h3", {
|
|
9575
9575
|
className: "modal-title"
|
|
9576
|
-
}, title), /*#__PURE__*/React.createElement("div", {
|
|
9576
|
+
}, title), /*#__PURE__*/React$1.createElement("div", {
|
|
9577
9577
|
className: "modal-content"
|
|
9578
|
-
}, children), /*#__PURE__*/React.createElement("div", {
|
|
9578
|
+
}, children), /*#__PURE__*/React$1.createElement("div", {
|
|
9579
9579
|
className: "modal-actions"
|
|
9580
|
-
}, showCancel && /*#__PURE__*/React.createElement("button", {
|
|
9580
|
+
}, showCancel && /*#__PURE__*/React$1.createElement("button", {
|
|
9581
9581
|
className: "basic-button cancel",
|
|
9582
9582
|
onClick: onCancel
|
|
9583
|
-
}, cancelLabel), showConfirm && /*#__PURE__*/React.createElement("button", {
|
|
9583
|
+
}, cancelLabel), showConfirm && /*#__PURE__*/React$1.createElement("button", {
|
|
9584
9584
|
className: "basic-button confirm",
|
|
9585
9585
|
onClick: onConfirm
|
|
9586
9586
|
}, confirmLabel))));
|
|
@@ -9617,7 +9617,7 @@ const DraggableRow = ({
|
|
|
9617
9617
|
enableDrag,
|
|
9618
9618
|
listRef
|
|
9619
9619
|
}) => {
|
|
9620
|
-
const ref = React.useRef(null);
|
|
9620
|
+
const ref = React$1.useRef(null);
|
|
9621
9621
|
const [, drop] = reactDnd.useDrop({
|
|
9622
9622
|
accept: ITEM_TYPE,
|
|
9623
9623
|
hover(draggedItem, monitor) {
|
|
@@ -9661,13 +9661,13 @@ const DraggableRow = ({
|
|
|
9661
9661
|
})
|
|
9662
9662
|
});
|
|
9663
9663
|
// Compose drag & drop refs in effect to avoid reading ref during render
|
|
9664
|
-
const setRef = React.useCallback(node => {
|
|
9664
|
+
const setRef = React$1.useCallback(node => {
|
|
9665
9665
|
if (node) {
|
|
9666
9666
|
ref.current = node;
|
|
9667
9667
|
drag(drop(node));
|
|
9668
9668
|
}
|
|
9669
9669
|
}, [drag, drop]);
|
|
9670
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
9670
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
9671
9671
|
ref: setRef,
|
|
9672
9672
|
style: {
|
|
9673
9673
|
opacity: isDragging ? 0.5 : 1,
|
|
@@ -9696,17 +9696,18 @@ function TableInner({
|
|
|
9696
9696
|
enableMultiSelect = false,
|
|
9697
9697
|
enableExternalRowDrop = false,
|
|
9698
9698
|
onExternalRowDrop = () => {},
|
|
9699
|
-
useExternalDndContext = false
|
|
9699
|
+
useExternalDndContext = false,
|
|
9700
|
+
customColumns = []
|
|
9700
9701
|
}) {
|
|
9701
9702
|
// Local selection & sorting state (removed TableContext dependency)
|
|
9702
|
-
const [selectedRows, setSelectedRows] = React.useState([]);
|
|
9703
|
-
const [sorting, setSorting] = React.useState(null);
|
|
9703
|
+
const [selectedRows, setSelectedRows] = React$1.useState([]);
|
|
9704
|
+
const [sorting, setSorting] = React$1.useState(null);
|
|
9704
9705
|
|
|
9705
9706
|
// Option to read search param from URL
|
|
9706
|
-
const [searchTerm, setSearchTerm] = React.useState(extraSearchTerm);
|
|
9707
|
+
const [searchTerm, setSearchTerm] = React$1.useState(extraSearchTerm);
|
|
9707
9708
|
|
|
9708
9709
|
// Listen to URL changes via popstate (back/forward) and custom events
|
|
9709
|
-
React.useEffect(() => {
|
|
9710
|
+
React$1.useEffect(() => {
|
|
9710
9711
|
if (!enableSearchUrlParam) {
|
|
9711
9712
|
setSearchTerm(extraSearchTerm);
|
|
9712
9713
|
return;
|
|
@@ -9748,10 +9749,10 @@ function TableInner({
|
|
|
9748
9749
|
window.history.replaceState = originalReplaceState;
|
|
9749
9750
|
};
|
|
9750
9751
|
}, [enableSearchUrlParam, extraSearchTerm]);
|
|
9751
|
-
const toggleRowSelection = React.useCallback(rowId => {
|
|
9752
|
+
const toggleRowSelection = React$1.useCallback(rowId => {
|
|
9752
9753
|
setSelectedRows(prev => prev.includes(rowId) ? prev.filter(r => r !== rowId) : [...prev, rowId]);
|
|
9753
9754
|
}, []);
|
|
9754
|
-
const clearSelection = React.useCallback(() => setSelectedRows([]), []);
|
|
9755
|
+
const clearSelection = React$1.useCallback(() => setSelectedRows([]), []);
|
|
9755
9756
|
const setSort = column => {
|
|
9756
9757
|
setSorting(prev => {
|
|
9757
9758
|
if (!prev || prev.column !== column) return {
|
|
@@ -9768,13 +9769,13 @@ function TableInner({
|
|
|
9768
9769
|
|
|
9769
9770
|
// console.log(extraSearchTerm)
|
|
9770
9771
|
|
|
9771
|
-
const [localData, setLocalData] = React.useState(data);
|
|
9772
|
-
React.useEffect(() => setLocalData(data), [data]);
|
|
9773
|
-
const listRef = React.useRef(null);
|
|
9774
|
-
const normalizedGroups = React.useMemo(() => {
|
|
9772
|
+
const [localData, setLocalData] = React$1.useState(data);
|
|
9773
|
+
React$1.useEffect(() => setLocalData(data), [data]);
|
|
9774
|
+
const listRef = React$1.useRef(null);
|
|
9775
|
+
const normalizedGroups = React$1.useMemo(() => {
|
|
9775
9776
|
return normalizeData(isGrouped ? localData : [], isGrouped ? [] : localData);
|
|
9776
9777
|
}, [localData, isGrouped]);
|
|
9777
|
-
const filterRows = React.useCallback(rows => {
|
|
9778
|
+
const filterRows = React$1.useCallback(rows => {
|
|
9778
9779
|
if (!searchTerm) return rows;
|
|
9779
9780
|
const query = searchTerm.toLowerCase();
|
|
9780
9781
|
return rows.filter(row => columns.some(col => {
|
|
@@ -9816,7 +9817,7 @@ function TableInner({
|
|
|
9816
9817
|
if (sx > sy) return dir === "asc" ? 1 : -1;
|
|
9817
9818
|
return 0;
|
|
9818
9819
|
};
|
|
9819
|
-
const sortedGroupedData = React.useMemo(() => {
|
|
9820
|
+
const sortedGroupedData = React$1.useMemo(() => {
|
|
9820
9821
|
const sortKey = sorting?.column;
|
|
9821
9822
|
const direction = sorting?.direction || "asc";
|
|
9822
9823
|
const sortRows = rows => {
|
|
@@ -9830,14 +9831,14 @@ function TableInner({
|
|
|
9830
9831
|
rows: sortRows(g.rows || [])
|
|
9831
9832
|
}));
|
|
9832
9833
|
}, [normalizedGroups, sorting, filterRows]);
|
|
9833
|
-
const [expandedGroups, setExpandedGroups] = React.useState({});
|
|
9834
|
+
const [expandedGroups, setExpandedGroups] = React$1.useState({});
|
|
9834
9835
|
const toggleGroup = gid => {
|
|
9835
9836
|
setExpandedGroups(prev => ({
|
|
9836
9837
|
...prev,
|
|
9837
9838
|
[gid]: !prev[gid]
|
|
9838
9839
|
}));
|
|
9839
9840
|
};
|
|
9840
|
-
React.useEffect(() => {
|
|
9841
|
+
React$1.useEffect(() => {
|
|
9841
9842
|
// Pre-populate expansion state for all groups
|
|
9842
9843
|
setExpandedGroups(prev => {
|
|
9843
9844
|
const next = {
|
|
@@ -9850,7 +9851,7 @@ function TableInner({
|
|
|
9850
9851
|
return next;
|
|
9851
9852
|
});
|
|
9852
9853
|
}, [normalizedGroups, groupKey]);
|
|
9853
|
-
const groupRowsById = React.useMemo(() => {
|
|
9854
|
+
const groupRowsById = React$1.useMemo(() => {
|
|
9854
9855
|
const map = {};
|
|
9855
9856
|
for (const g of sortedGroupedData) {
|
|
9856
9857
|
const gid = g[groupKey] ?? g.groupId ?? g.groupName;
|
|
@@ -9858,8 +9859,8 @@ function TableInner({
|
|
|
9858
9859
|
}
|
|
9859
9860
|
return map;
|
|
9860
9861
|
}, [sortedGroupedData, groupKey]);
|
|
9861
|
-
const [tableDataFlat, setTableDataFlat] = React.useState([]);
|
|
9862
|
-
const flattened = React.useMemo(() => {
|
|
9862
|
+
const [tableDataFlat, setTableDataFlat] = React$1.useState([]);
|
|
9863
|
+
const flattened = React$1.useMemo(() => {
|
|
9863
9864
|
const items = [];
|
|
9864
9865
|
// Use the sortedGroupedData here so the flattened list reflects current sorting and filtering
|
|
9865
9866
|
for (const g of sortedGroupedData) {
|
|
@@ -9886,16 +9887,16 @@ function TableInner({
|
|
|
9886
9887
|
}
|
|
9887
9888
|
return items;
|
|
9888
9889
|
}, [sortedGroupedData, expandedGroups, isGrouped, groupKey]);
|
|
9889
|
-
React.useEffect(() => {
|
|
9890
|
+
React$1.useEffect(() => {
|
|
9890
9891
|
setTableDataFlat(flattened);
|
|
9891
9892
|
}, [flattened]);
|
|
9892
9893
|
|
|
9893
9894
|
// useEffect(() => setTableDataFlat(flattened), [flattened]);
|
|
9894
|
-
React.useEffect(() => selectedRowsCallback(selectedRows), [selectedRows, selectedRowsCallback]);
|
|
9895
|
+
React$1.useEffect(() => selectedRowsCallback(selectedRows), [selectedRows, selectedRowsCallback]);
|
|
9895
9896
|
|
|
9896
9897
|
// DELETE
|
|
9897
|
-
const [showConfirm, setShowConfirm] = React.useState(false);
|
|
9898
|
-
const [pendingDelete, setPendingDelete] = React.useState(null);
|
|
9898
|
+
const [showConfirm, setShowConfirm] = React$1.useState(false);
|
|
9899
|
+
const [pendingDelete, setPendingDelete] = React$1.useState(null);
|
|
9899
9900
|
const confirmDelete = async () => {
|
|
9900
9901
|
if (!pendingDelete) return;
|
|
9901
9902
|
if (deleteCallback) {
|
|
@@ -9918,18 +9919,18 @@ function TableInner({
|
|
|
9918
9919
|
};
|
|
9919
9920
|
|
|
9920
9921
|
// RENDER CELL
|
|
9921
|
-
const highlight = React.useCallback(text => {
|
|
9922
|
+
const highlight = React$1.useCallback(text => {
|
|
9922
9923
|
// Use the actual searchTerm (from URL or prop) for highlighting
|
|
9923
9924
|
if (!searchTerm || typeof text !== "string") return text;
|
|
9924
9925
|
const lower = text.toLowerCase();
|
|
9925
9926
|
const query = searchTerm.toLowerCase();
|
|
9926
9927
|
const idx = lower.indexOf(query);
|
|
9927
9928
|
if (idx === -1) return text;
|
|
9928
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, text.slice(0, idx), /*#__PURE__*/React.createElement("span", {
|
|
9929
|
+
return /*#__PURE__*/React$1.createElement(React$1.Fragment, null, text.slice(0, idx), /*#__PURE__*/React$1.createElement("span", {
|
|
9929
9930
|
className: "highlight"
|
|
9930
9931
|
}, text.slice(idx, idx + query.length)), text.slice(idx + query.length));
|
|
9931
9932
|
}, [searchTerm]);
|
|
9932
|
-
const renderCell = React.useCallback((v, accessor) => {
|
|
9933
|
+
const renderCell = React$1.useCallback((v, accessor) => {
|
|
9933
9934
|
if (accessor === "deadlineISO") {
|
|
9934
9935
|
return v ? new Date(v).toLocaleString("sl-SI", {
|
|
9935
9936
|
day: "2-digit",
|
|
@@ -9949,7 +9950,7 @@ function TableInner({
|
|
|
9949
9950
|
|
|
9950
9951
|
// MOVE ROW (internal + between groups)
|
|
9951
9952
|
// moveRow: allow toIndex to be null or an object { emptyGroupId } for empty group drop
|
|
9952
|
-
const moveRow = React.useCallback((fromIndex, toIndexOrGroup) => {
|
|
9953
|
+
const moveRow = React$1.useCallback((fromIndex, toIndexOrGroup) => {
|
|
9953
9954
|
const from = tableDataFlat[fromIndex];
|
|
9954
9955
|
let to = null;
|
|
9955
9956
|
let emptyGroupId = null;
|
|
@@ -10037,7 +10038,7 @@ function TableInner({
|
|
|
10037
10038
|
}, [tableDataFlat, isGrouped, groupKey]);
|
|
10038
10039
|
|
|
10039
10040
|
// ROW RENDERER
|
|
10040
|
-
const rowRenderer = React.useCallback(({
|
|
10041
|
+
const rowRenderer = React$1.useCallback(({
|
|
10041
10042
|
index,
|
|
10042
10043
|
key,
|
|
10043
10044
|
style
|
|
@@ -10053,7 +10054,7 @@ function TableInner({
|
|
|
10053
10054
|
if (item.expanded && rows.length === 0 && enableDragRow) {
|
|
10054
10055
|
// For empty group, drop target pushes into this group
|
|
10055
10056
|
const GroupHeaderDrop = () => {
|
|
10056
|
-
const ref = React.useRef(null);
|
|
10057
|
+
const ref = React$1.useRef(null);
|
|
10057
10058
|
const [, drop] = reactDnd.useDrop({
|
|
10058
10059
|
accept: ITEM_TYPE,
|
|
10059
10060
|
drop(draggedItem) {
|
|
@@ -10070,7 +10071,7 @@ function TableInner({
|
|
|
10070
10071
|
})
|
|
10071
10072
|
});
|
|
10072
10073
|
drop(ref);
|
|
10073
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
10074
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
10074
10075
|
ref: ref,
|
|
10075
10076
|
key: key,
|
|
10076
10077
|
style: {
|
|
@@ -10085,9 +10086,9 @@ function TableInner({
|
|
|
10085
10086
|
},
|
|
10086
10087
|
className: "table-row group-row empty-group-drop",
|
|
10087
10088
|
onClick: () => toggleGroup(gid)
|
|
10088
|
-
}, enableMultiSelect && showDelete && /*#__PURE__*/React.createElement("div", {
|
|
10089
|
+
}, enableMultiSelect && showDelete && /*#__PURE__*/React$1.createElement("div", {
|
|
10089
10090
|
className: "table-cell checkbox-cell"
|
|
10090
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
10091
|
+
}, /*#__PURE__*/React$1.createElement("input", {
|
|
10091
10092
|
type: "checkbox",
|
|
10092
10093
|
checked: allSelected,
|
|
10093
10094
|
onChange: e => {
|
|
@@ -10100,31 +10101,31 @@ function TableInner({
|
|
|
10100
10101
|
}
|
|
10101
10102
|
},
|
|
10102
10103
|
onClick: e => e.stopPropagation()
|
|
10103
|
-
})), showKey && /*#__PURE__*/React.createElement("div", {
|
|
10104
|
+
})), showKey && /*#__PURE__*/React$1.createElement("div", {
|
|
10104
10105
|
className: "table-cell key-cell"
|
|
10105
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
10106
|
+
}), /*#__PURE__*/React$1.createElement("div", {
|
|
10106
10107
|
className: "table-cell group-header",
|
|
10107
10108
|
style: {
|
|
10108
10109
|
width: '100%'
|
|
10109
10110
|
}
|
|
10110
|
-
}, item.expanded ? "▾" : "▸", " ", item.groupName, " (0) \u2014 Drop here to move into this group"), columns.slice(1).map((_, i) => /*#__PURE__*/React.createElement("div", {
|
|
10111
|
+
}, item.expanded ? "▾" : "▸", " ", item.groupName, " (0) \u2014 Drop here to move into this group"), columns.slice(1).map((_, i) => /*#__PURE__*/React$1.createElement("div", {
|
|
10111
10112
|
key: i,
|
|
10112
10113
|
className: "table-cell"
|
|
10113
|
-
})), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10114
|
+
})), showActions && /*#__PURE__*/React$1.createElement("div", {
|
|
10114
10115
|
className: "table-cell action-cell"
|
|
10115
10116
|
}));
|
|
10116
10117
|
};
|
|
10117
|
-
return /*#__PURE__*/React.createElement(GroupHeaderDrop, null);
|
|
10118
|
+
return /*#__PURE__*/React$1.createElement(GroupHeaderDrop, null);
|
|
10118
10119
|
}
|
|
10119
10120
|
// Default: normal group header
|
|
10120
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
10121
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
10121
10122
|
key: key,
|
|
10122
10123
|
style: style,
|
|
10123
10124
|
className: "table-row group-row",
|
|
10124
10125
|
onClick: () => toggleGroup(gid)
|
|
10125
|
-
}, enableMultiSelect && showDelete && /*#__PURE__*/React.createElement("div", {
|
|
10126
|
+
}, enableMultiSelect && showDelete && /*#__PURE__*/React$1.createElement("div", {
|
|
10126
10127
|
className: "table-cell checkbox-cell"
|
|
10127
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
10128
|
+
}, /*#__PURE__*/React$1.createElement("input", {
|
|
10128
10129
|
type: "checkbox",
|
|
10129
10130
|
checked: allSelected,
|
|
10130
10131
|
onChange: e => {
|
|
@@ -10137,49 +10138,75 @@ function TableInner({
|
|
|
10137
10138
|
}
|
|
10138
10139
|
},
|
|
10139
10140
|
onClick: e => e.stopPropagation()
|
|
10140
|
-
})), showKey && /*#__PURE__*/React.createElement("div", {
|
|
10141
|
+
})), showKey && /*#__PURE__*/React$1.createElement("div", {
|
|
10141
10142
|
className: "table-cell key-cell"
|
|
10142
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
10143
|
+
}), /*#__PURE__*/React$1.createElement("div", {
|
|
10143
10144
|
className: "table-cell group-header"
|
|
10144
|
-
}, item.expanded ? "▾" : "▸", " ", item.groupName, " (", item.rowCount, ")"), columns.slice(1).map((_, i) => /*#__PURE__*/React.createElement("div", {
|
|
10145
|
+
}, item.expanded ? "▾" : "▸", " ", item.groupName, " (", item.rowCount, ")"), columns.slice(1).map((_, i) => /*#__PURE__*/React$1.createElement("div", {
|
|
10145
10146
|
key: i,
|
|
10146
10147
|
className: "table-cell"
|
|
10147
|
-
})), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10148
|
+
})), showActions && /*#__PURE__*/React$1.createElement("div", {
|
|
10148
10149
|
className: "table-cell action-cell"
|
|
10149
10150
|
}));
|
|
10150
10151
|
}
|
|
10151
10152
|
const row = item.row;
|
|
10152
10153
|
const visualIndex = tableDataFlat.slice(0, index).filter(i => i.type === "row").length + 1;
|
|
10153
|
-
|
|
10154
|
+
|
|
10155
|
+
// Compose columns + custom columns
|
|
10156
|
+
const allColumns = [...columns];
|
|
10157
|
+
// Insert custom columns at specified places
|
|
10158
|
+
if (Array.isArray(customColumns)) {
|
|
10159
|
+
customColumns.forEach(col => {
|
|
10160
|
+
if (typeof col.place === 'number') {
|
|
10161
|
+
allColumns.splice(col.place, 0, {
|
|
10162
|
+
...col,
|
|
10163
|
+
isCustom: true
|
|
10164
|
+
});
|
|
10165
|
+
}
|
|
10166
|
+
});
|
|
10167
|
+
}
|
|
10168
|
+
const content = /*#__PURE__*/React$1.createElement("div", {
|
|
10154
10169
|
key: key,
|
|
10155
10170
|
style: style,
|
|
10156
10171
|
className: "table-row"
|
|
10157
|
-
}, enableMultiSelect && showDelete && /*#__PURE__*/React.createElement("div", {
|
|
10172
|
+
}, enableMultiSelect && showDelete && /*#__PURE__*/React$1.createElement("div", {
|
|
10158
10173
|
className: "table-cell checkbox-cell"
|
|
10159
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
10174
|
+
}, /*#__PURE__*/React$1.createElement("input", {
|
|
10160
10175
|
type: "checkbox",
|
|
10161
10176
|
checked: selectedRows.includes(row.id),
|
|
10162
10177
|
onChange: () => toggleRowSelection(row.id)
|
|
10163
|
-
})), showKey && /*#__PURE__*/React.createElement("div", {
|
|
10178
|
+
})), showKey && /*#__PURE__*/React$1.createElement("div", {
|
|
10164
10179
|
className: "table-cell key-cell"
|
|
10165
|
-
}, visualIndex),
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10180
|
+
}, visualIndex), allColumns.map((col, i) => {
|
|
10181
|
+
let cellStyle = col.isCustom && col.style ? {
|
|
10182
|
+
...col.style
|
|
10183
|
+
} : undefined;
|
|
10184
|
+
if (col.isCustom && col.style && col.style.width) {
|
|
10185
|
+
cellStyle = cellStyle || {};
|
|
10186
|
+
cellStyle.minWidth = col.style.width;
|
|
10187
|
+
cellStyle.maxWidth = col.style.width;
|
|
10188
|
+
cellStyle.width = col.style.width;
|
|
10189
|
+
}
|
|
10190
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
10191
|
+
key: i,
|
|
10192
|
+
className: "table-cell",
|
|
10193
|
+
style: cellStyle
|
|
10194
|
+
}, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(row[col.accessor], col.accessor, row));
|
|
10195
|
+
}), showActions && /*#__PURE__*/React$1.createElement("div", {
|
|
10169
10196
|
className: "table-cell action-cell"
|
|
10170
|
-
}, showView && /*#__PURE__*/React.createElement("button", {
|
|
10197
|
+
}, showView && /*#__PURE__*/React$1.createElement("button", {
|
|
10171
10198
|
className: "action-btn-table",
|
|
10172
10199
|
style: {
|
|
10173
10200
|
background: "#646cffaa"
|
|
10174
10201
|
},
|
|
10175
10202
|
onClick: () => viewCallback(row)
|
|
10176
|
-
}, "View"), showEdit && /*#__PURE__*/React.createElement("button", {
|
|
10203
|
+
}, "View"), showEdit && /*#__PURE__*/React$1.createElement("button", {
|
|
10177
10204
|
className: "action-btn-table",
|
|
10178
10205
|
style: {
|
|
10179
10206
|
background: "#4caf50"
|
|
10180
10207
|
},
|
|
10181
10208
|
onClick: () => editCallback(row)
|
|
10182
|
-
}, "Edit"), showDelete && /*#__PURE__*/React.createElement("button", {
|
|
10209
|
+
}, "Edit"), showDelete && /*#__PURE__*/React$1.createElement("button", {
|
|
10183
10210
|
className: "action-btn-table",
|
|
10184
10211
|
style: {
|
|
10185
10212
|
background: "#f44336"
|
|
@@ -10191,7 +10218,7 @@ function TableInner({
|
|
|
10191
10218
|
}
|
|
10192
10219
|
}, "Delete")));
|
|
10193
10220
|
if (enableDragRow && item.type === "row") {
|
|
10194
|
-
return /*#__PURE__*/React.createElement(DraggableRow, {
|
|
10221
|
+
return /*#__PURE__*/React$1.createElement(DraggableRow, {
|
|
10195
10222
|
key: key,
|
|
10196
10223
|
index: index,
|
|
10197
10224
|
moveRow: moveRow,
|
|
@@ -10202,13 +10229,13 @@ function TableInner({
|
|
|
10202
10229
|
}, content);
|
|
10203
10230
|
}
|
|
10204
10231
|
return content;
|
|
10205
|
-
}, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, viewCallback, editCallback, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId]);
|
|
10232
|
+
}, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, viewCallback, editCallback, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns]);
|
|
10206
10233
|
const rowHeightGetter = ({
|
|
10207
10234
|
index
|
|
10208
10235
|
}) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;
|
|
10209
10236
|
|
|
10210
10237
|
// Table-level drop target only when using external DnD context
|
|
10211
|
-
const tableContainerRef = React.useRef(null);
|
|
10238
|
+
const tableContainerRef = React$1.useRef(null);
|
|
10212
10239
|
const [{
|
|
10213
10240
|
isOver: isExternalOver,
|
|
10214
10241
|
canDrop: canExternalDrop
|
|
@@ -10221,13 +10248,26 @@ function TableInner({
|
|
|
10221
10248
|
onExternalRowDrop(draggedItem.row, draggedItem.sourceTableId, tableId);
|
|
10222
10249
|
}
|
|
10223
10250
|
});
|
|
10224
|
-
const setTableRef = React.useCallback(node => {
|
|
10251
|
+
const setTableRef = React$1.useCallback(node => {
|
|
10225
10252
|
tableContainerRef.current = node;
|
|
10226
10253
|
if (node && useExternalDndContext && enableExternalRowDrop) {
|
|
10227
10254
|
externalDrop(node);
|
|
10228
10255
|
}
|
|
10229
10256
|
}, [useExternalDndContext, enableExternalRowDrop, externalDrop]);
|
|
10230
|
-
|
|
10257
|
+
|
|
10258
|
+
// Compose columns + custom columns for header
|
|
10259
|
+
const allColumns = [...columns];
|
|
10260
|
+
if (Array.isArray(customColumns)) {
|
|
10261
|
+
customColumns.forEach(col => {
|
|
10262
|
+
if (typeof col.place === 'number') {
|
|
10263
|
+
allColumns.splice(col.place, 0, {
|
|
10264
|
+
...col,
|
|
10265
|
+
isCustom: true
|
|
10266
|
+
});
|
|
10267
|
+
}
|
|
10268
|
+
});
|
|
10269
|
+
}
|
|
10270
|
+
const tableMarkup = /*#__PURE__*/React$1.createElement("div", {
|
|
10231
10271
|
className: "table-container",
|
|
10232
10272
|
ref: setTableRef,
|
|
10233
10273
|
style: useExternalDndContext && enableExternalRowDrop ? {
|
|
@@ -10235,7 +10275,7 @@ function TableInner({
|
|
|
10235
10275
|
background: isExternalOver && canExternalDrop ? 'rgba(100,108,255,0.15)' : undefined,
|
|
10236
10276
|
outline: isExternalOver && canExternalDrop ? '2px dashed #646cff' : undefined
|
|
10237
10277
|
} : undefined
|
|
10238
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
10278
|
+
}, /*#__PURE__*/React$1.createElement("div", {
|
|
10239
10279
|
className: "table-header",
|
|
10240
10280
|
style: {
|
|
10241
10281
|
position: "sticky",
|
|
@@ -10243,11 +10283,11 @@ function TableInner({
|
|
|
10243
10283
|
zIndex: 10,
|
|
10244
10284
|
background: "#fff"
|
|
10245
10285
|
}
|
|
10246
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
10286
|
+
}, /*#__PURE__*/React$1.createElement("div", {
|
|
10247
10287
|
className: "table-row header-row"
|
|
10248
|
-
}, enableMultiSelect && showDelete && /*#__PURE__*/React.createElement("div", {
|
|
10288
|
+
}, enableMultiSelect && showDelete && /*#__PURE__*/React$1.createElement("div", {
|
|
10249
10289
|
className: "table-cell checkbox-cell"
|
|
10250
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
10290
|
+
}, /*#__PURE__*/React$1.createElement("input", {
|
|
10251
10291
|
type: "checkbox",
|
|
10252
10292
|
checked: tableDataFlat.filter(i => i.type === "row").length > 0 && selectedRows.length === tableDataFlat.filter(i => i.type === "row").length,
|
|
10253
10293
|
onChange: e => {
|
|
@@ -10258,33 +10298,48 @@ function TableInner({
|
|
|
10258
10298
|
clearSelection();
|
|
10259
10299
|
}
|
|
10260
10300
|
}
|
|
10261
|
-
})), showKey && /*#__PURE__*/React.createElement("div", {
|
|
10301
|
+
})), showKey && /*#__PURE__*/React$1.createElement("div", {
|
|
10262
10302
|
className: "table-cell key-cell"
|
|
10263
|
-
}, "#"),
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10303
|
+
}, "#"), allColumns.map((col, i) => {
|
|
10304
|
+
// For custom columns, apply width and textAlign to header cell
|
|
10305
|
+
let cellStyle = col.isCustom && col.style ? {
|
|
10306
|
+
...col.style,
|
|
10307
|
+
cursor: undefined,
|
|
10308
|
+
display: 'flex',
|
|
10309
|
+
alignItems: 'center',
|
|
10310
|
+
justifyContent: col.style.textAlign === 'center' ? 'center' : col.style.textAlign === 'right' ? 'flex-end' : 'flex-start'
|
|
10311
|
+
} : {
|
|
10312
|
+
cursor: col.isCustom ? undefined : "pointer"
|
|
10313
|
+
};
|
|
10314
|
+
if (col.isCustom && col.style && col.style.width) {
|
|
10315
|
+
cellStyle.minWidth = col.style.width;
|
|
10316
|
+
cellStyle.maxWidth = col.style.width;
|
|
10317
|
+
cellStyle.width = col.style.width;
|
|
10269
10318
|
}
|
|
10270
|
-
|
|
10319
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
10320
|
+
key: i,
|
|
10321
|
+
className: "table-cell",
|
|
10322
|
+
style: cellStyle,
|
|
10323
|
+
onClick: col.isCustom ? undefined : () => setSort(col.accessor)
|
|
10324
|
+
}, col.isCustom ? col.header ?? '' : col.header, !col.isCustom && sorting?.column === col.accessor && (sorting.direction === "asc" ? " ↑" : " ↓"));
|
|
10325
|
+
}), showActions && /*#__PURE__*/React$1.createElement("div", {
|
|
10271
10326
|
className: "table-cell action-cell"
|
|
10272
|
-
}, "Action"))), /*#__PURE__*/React.createElement("div", {
|
|
10327
|
+
}, "Action"))), /*#__PURE__*/React$1.createElement("div", {
|
|
10273
10328
|
className: "main-table",
|
|
10274
10329
|
ref: listRef
|
|
10275
|
-
}, tableDataFlat.length === 0 ? /*#__PURE__*/React.createElement("div", {
|
|
10330
|
+
}, tableDataFlat.length === 0 ? /*#__PURE__*/React$1.createElement("div", {
|
|
10276
10331
|
className: "table-empty"
|
|
10277
|
-
}, "No items") : /*#__PURE__*/React.createElement(AutoSizer, null, ({
|
|
10332
|
+
}, "No items") : /*#__PURE__*/React$1.createElement(AutoSizer, null, ({
|
|
10278
10333
|
height,
|
|
10279
10334
|
width
|
|
10280
|
-
}) => /*#__PURE__*/React.createElement(List, {
|
|
10335
|
+
}) => /*#__PURE__*/React$1.createElement(List, {
|
|
10281
10336
|
width: width,
|
|
10282
10337
|
height: height,
|
|
10283
10338
|
rowCount: tableDataFlat.length,
|
|
10284
10339
|
rowHeight: rowHeightGetter,
|
|
10285
10340
|
rowRenderer: rowRenderer,
|
|
10286
10341
|
overscanRowCount: 8
|
|
10287
|
-
}))), /*#__PURE__*/React.createElement(Modal, {
|
|
10342
|
+
}))), /*#__PURE__*/React$1.createElement(Modal, {
|
|
10288
10343
|
isOpen: showConfirm,
|
|
10289
10344
|
title: "Confirm delete",
|
|
10290
10345
|
onConfirm: confirmDelete,
|
|
@@ -10293,7 +10348,7 @@ function TableInner({
|
|
|
10293
10348
|
cancelLabel: "Cancel",
|
|
10294
10349
|
showCancel: true,
|
|
10295
10350
|
showConfirm: true
|
|
10296
|
-
}, /*#__PURE__*/React.createElement("p", null, "Are you sure you want to delete ", /*#__PURE__*/React.createElement("strong", null, pendingDelete?.name || pendingDelete?.id), "?")));
|
|
10351
|
+
}, /*#__PURE__*/React$1.createElement("p", null, "Are you sure you want to delete ", /*#__PURE__*/React$1.createElement("strong", null, pendingDelete?.name || pendingDelete?.id), "?")));
|
|
10297
10352
|
return tableMarkup;
|
|
10298
10353
|
}
|
|
10299
10354
|
function Table(props) {
|
|
@@ -10301,17 +10356,59 @@ function Table(props) {
|
|
|
10301
10356
|
useExternalDndContext = false
|
|
10302
10357
|
} = props;
|
|
10303
10358
|
if (useExternalDndContext) {
|
|
10304
|
-
return /*#__PURE__*/React.createElement(TableInner, props);
|
|
10359
|
+
return /*#__PURE__*/React$1.createElement(TableInner, props);
|
|
10305
10360
|
}
|
|
10306
10361
|
// Provide DnD context when not supplied externally
|
|
10307
|
-
return /*#__PURE__*/React.createElement(reactDnd.DndProvider, {
|
|
10362
|
+
return /*#__PURE__*/React$1.createElement(reactDnd.DndProvider, {
|
|
10308
10363
|
backend: reactDndHtml5Backend.HTML5Backend
|
|
10309
|
-
}, /*#__PURE__*/React.createElement(TableInner, props));
|
|
10364
|
+
}, /*#__PURE__*/React$1.createElement(TableInner, props));
|
|
10365
|
+
}
|
|
10366
|
+
|
|
10367
|
+
function Switch({
|
|
10368
|
+
checked,
|
|
10369
|
+
onChange
|
|
10370
|
+
}) {
|
|
10371
|
+
return /*#__PURE__*/React.createElement("label", {
|
|
10372
|
+
style: {
|
|
10373
|
+
display: "inline-flex",
|
|
10374
|
+
alignItems: "center",
|
|
10375
|
+
cursor: "pointer"
|
|
10376
|
+
}
|
|
10377
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
10378
|
+
type: "checkbox",
|
|
10379
|
+
checked: checked,
|
|
10380
|
+
onChange: onChange,
|
|
10381
|
+
style: {
|
|
10382
|
+
display: "none"
|
|
10383
|
+
}
|
|
10384
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
10385
|
+
style: {
|
|
10386
|
+
width: 36,
|
|
10387
|
+
height: 20,
|
|
10388
|
+
background: checked ? "#4caf50" : "#ccc",
|
|
10389
|
+
borderRadius: 12,
|
|
10390
|
+
position: "relative",
|
|
10391
|
+
transition: "background 0.2s",
|
|
10392
|
+
display: "inline-block"
|
|
10393
|
+
}
|
|
10394
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
10395
|
+
style: {
|
|
10396
|
+
position: "absolute",
|
|
10397
|
+
left: checked ? 18 : 2,
|
|
10398
|
+
top: 2,
|
|
10399
|
+
width: 16,
|
|
10400
|
+
height: 16,
|
|
10401
|
+
background: "#fff",
|
|
10402
|
+
borderRadius: "50%",
|
|
10403
|
+
transition: "left 0.2s"
|
|
10404
|
+
}
|
|
10405
|
+
})));
|
|
10310
10406
|
}
|
|
10311
10407
|
|
|
10312
10408
|
// src/index.js
|
|
10313
|
-
//
|
|
10409
|
+
// named exports for both
|
|
10314
10410
|
|
|
10411
|
+
exports.Switch = Switch;
|
|
10315
10412
|
exports.Table = Table;
|
|
10316
10413
|
exports.default = Table;
|
|
10317
10414
|
//# sourceMappingURL=index.cjs.js.map
|