@stenajs-webui/grid 13.2.0 → 13.3.0
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/features/standard-table/components/StandardTableRow.d.ts +4 -1
- package/dist/features/standard-table/context/StandardTableStateContext.d.ts +1 -2
- package/dist/features/standard-table/features/checkboxes/StandardTableRowCheckbox.d.ts +3 -0
- package/dist/features/standard-table/features/checkboxes/UseRowCheckbox.d.ts +2 -1
- package/dist/features/standard-table/redux/ReducerIdFactory.d.ts +1 -1
- package/dist/features/standard-table/redux/StandardTableActionsAndSelectors.d.ts +4 -4
- package/dist/features/standard-table/redux/StandardTableReducer.d.ts +8 -4
- package/dist/features/standard-table/util/ActionsFactory.d.ts +6 -4
- package/dist/features/standard-table/util/IdListPartial.d.ts +1 -0
- package/dist/features/standard-table/util/__tests__/IdListPartial.test.d.ts +1 -0
- package/dist/index.es.js +109 -24
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +108 -23
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -743,6 +743,7 @@ var createInternalStandardTableActions = function () { return ({
|
|
|
743
743
|
sortOrder: redux.createSortOrderActions(),
|
|
744
744
|
selectedIds: redux.createSelectedIdsActions(),
|
|
745
745
|
expandedRows: redux.createSelectedIdsActions(),
|
|
746
|
+
fields: redux.createEntityActions(),
|
|
746
747
|
}); };
|
|
747
748
|
|
|
748
749
|
var getReducerIdFor = function (reducerId, reducerIdSuffix) { return reducerId + "." + reducerIdSuffix; };
|
|
@@ -756,16 +757,19 @@ var createStandardTableInitialState = function (sortBy, desc, selectedIds, expan
|
|
|
756
757
|
sortOrder: redux.createSortOrderReducerInitialState(sortBy, desc),
|
|
757
758
|
selectedIds: redux.createSelectedIdsReducerInitialState(selectedIds),
|
|
758
759
|
expandedRows: redux.createSelectedIdsReducerInitialState(expandedRows),
|
|
760
|
+
fields: { lastSelectedId: undefined },
|
|
759
761
|
});
|
|
760
762
|
};
|
|
761
763
|
var createStandardTableReducer = function (reducerId) {
|
|
762
764
|
var sortOrder = redux.reducerIdGate(getReducerIdFor(reducerId, "sortOrder"), redux.createSortOrderReducer());
|
|
763
765
|
var selectedIds = redux.reducerIdGate(getReducerIdFor(reducerId, "selectedIds"), redux.createSelectedIdsReducer());
|
|
764
766
|
var expandedRows = redux.reducerIdGate(getReducerIdFor(reducerId, "expandedRows"), redux.createSelectedIdsReducer());
|
|
767
|
+
var fields = redux.reducerIdGate(getReducerIdFor(reducerId, "fields"), redux.createEntityReducer({}));
|
|
765
768
|
return redux$1.combineReducers({
|
|
766
769
|
sortOrder: sortOrder,
|
|
767
770
|
selectedIds: selectedIds,
|
|
768
771
|
expandedRows: expandedRows,
|
|
772
|
+
fields: fields,
|
|
769
773
|
});
|
|
770
774
|
};
|
|
771
775
|
|
|
@@ -1212,7 +1216,7 @@ var getStickyPropsPerColumnWithGroups = function (config) {
|
|
|
1212
1216
|
|
|
1213
1217
|
var createStandardTableActions = function (tableId, actions) {
|
|
1214
1218
|
return {
|
|
1215
|
-
|
|
1219
|
+
setSelectedIds: function (ids) {
|
|
1216
1220
|
return redux.reducerIdGateAction(getReducerIdFor(tableId, "selectedIds"), actions.selectedIds.setSelectedIds(ids));
|
|
1217
1221
|
},
|
|
1218
1222
|
clearSelection: function () {
|
|
@@ -1230,6 +1234,9 @@ var createStandardTableActions = function (tableId, actions) {
|
|
|
1230
1234
|
clearSortOrder: function () {
|
|
1231
1235
|
return redux.reducerIdGateAction(getReducerIdFor(tableId, "sortOrder"), actions.sortOrder.clearSortOrder());
|
|
1232
1236
|
},
|
|
1237
|
+
setLastSelectedId: function (lastSelectedId) {
|
|
1238
|
+
return redux.reducerIdGateAction(getReducerIdFor(tableId, "fields"), actions.fields.setEntityFields({ lastSelectedId: lastSelectedId }));
|
|
1239
|
+
},
|
|
1233
1240
|
};
|
|
1234
1241
|
};
|
|
1235
1242
|
|
|
@@ -1306,7 +1313,7 @@ var useColumnValueResolver = function (columnId) {
|
|
|
1306
1313
|
};
|
|
1307
1314
|
|
|
1308
1315
|
var StandardTableRowCheckbox = React.memo(function StandardTableRowCheckbox(_a) {
|
|
1309
|
-
var value = _a.value, onValueChange = _a.onValueChange, colIndex = _a.colIndex, rowIndex = _a.rowIndex, numRows = _a.numRows, disabled = _a.disabled;
|
|
1316
|
+
var value = _a.value, onValueChange = _a.onValueChange, colIndex = _a.colIndex, rowIndex = _a.rowIndex, numRows = _a.numRows, disabled = _a.disabled, onValueChangeAndShift = _a.onValueChangeAndShift, shiftPressedRef = _a.shiftPressedRef;
|
|
1310
1317
|
var totalNumColumns = useTotalNumColumnsForRows();
|
|
1311
1318
|
var tableId = useStandardTableId();
|
|
1312
1319
|
var gridCell = useGridCell(Boolean(value), {
|
|
@@ -1317,27 +1324,82 @@ var StandardTableRowCheckbox = React.memo(function StandardTableRowCheckbox(_a)
|
|
|
1317
1324
|
tableId: tableId,
|
|
1318
1325
|
});
|
|
1319
1326
|
var requiredProps = gridCell.requiredProps;
|
|
1320
|
-
|
|
1327
|
+
var internalOnValueChange = React.useCallback(function (value) {
|
|
1328
|
+
if (shiftPressedRef.current) {
|
|
1329
|
+
onValueChangeAndShift === null || onValueChangeAndShift === void 0 ? void 0 : onValueChangeAndShift(value);
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(value);
|
|
1333
|
+
}
|
|
1334
|
+
}, [onValueChange, onValueChangeAndShift, shiftPressedRef]);
|
|
1335
|
+
return (React.createElement(forms.Checkbox, __assign({ size: "small", disabled: disabled, value: value, onValueChange: internalOnValueChange }, requiredProps)));
|
|
1321
1336
|
});
|
|
1322
1337
|
|
|
1323
|
-
var
|
|
1338
|
+
var getIdsBetweenSelected = function (idList, selected1, selected2) {
|
|
1339
|
+
if (selected1 == null || selected2 == null || idList == null) {
|
|
1340
|
+
return undefined;
|
|
1341
|
+
}
|
|
1342
|
+
if (selected1 === selected2) {
|
|
1343
|
+
return undefined;
|
|
1344
|
+
}
|
|
1345
|
+
var i1 = idList.indexOf(selected1);
|
|
1346
|
+
var i2 = idList.indexOf(selected2);
|
|
1347
|
+
if (i1 < 0 || i2 < 0) {
|
|
1348
|
+
return undefined;
|
|
1349
|
+
}
|
|
1350
|
+
var start = Math.min(i1, i2);
|
|
1351
|
+
var end = Math.max(i1, i2);
|
|
1352
|
+
return idList.slice(start, end + 1);
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
var useRowCheckbox = function (item, itemIdList) {
|
|
1324
1356
|
var keyResolver = useStandardTableConfig().keyResolver;
|
|
1325
|
-
var
|
|
1326
|
-
var
|
|
1357
|
+
var _a = useStandardTableState(), selectedIds = _a.selectedIds.selectedIds, lastSelectedId = _a.fields.lastSelectedId;
|
|
1358
|
+
var _b = useStandardTableActions(), _c = _b.actions, setSelectedIds = _c.setSelectedIds, setLastSelectedId = _c.setLastSelectedId, dispatch = _b.dispatch;
|
|
1327
1359
|
var itemKey = React.useMemo(function () { return keyResolver(item); }, [keyResolver, item]);
|
|
1328
1360
|
var isSelected = React.useMemo(function () { return selectedIds.includes(itemKey); }, [
|
|
1329
1361
|
selectedIds,
|
|
1330
1362
|
itemKey,
|
|
1331
1363
|
]);
|
|
1332
|
-
var
|
|
1333
|
-
|
|
1334
|
-
|
|
1364
|
+
var _d = core.useArraySet(selectedIds, function (ids) { return dispatch(setSelectedIds(ids)); }), toggle = _d.toggle, addMultiple = _d.addMultiple, removeMultiple = _d.removeMultiple;
|
|
1365
|
+
var shiftAndToggleSelected = React.useCallback(function () {
|
|
1366
|
+
if (itemIdList && lastSelectedId) {
|
|
1367
|
+
var idList = getIdsBetweenSelected(itemIdList, lastSelectedId, itemKey);
|
|
1368
|
+
if (idList === null || idList === void 0 ? void 0 : idList.length) {
|
|
1369
|
+
if (isSelected) {
|
|
1370
|
+
removeMultiple(idList);
|
|
1371
|
+
}
|
|
1372
|
+
else {
|
|
1373
|
+
addMultiple(idList);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
else {
|
|
1377
|
+
toggle(itemKey);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
else {
|
|
1381
|
+
toggle(itemKey);
|
|
1382
|
+
}
|
|
1383
|
+
dispatch(setLastSelectedId(itemKey));
|
|
1384
|
+
}, [
|
|
1385
|
+
itemIdList,
|
|
1386
|
+
lastSelectedId,
|
|
1387
|
+
dispatch,
|
|
1388
|
+
setLastSelectedId,
|
|
1389
|
+
itemKey,
|
|
1390
|
+
isSelected,
|
|
1391
|
+
removeMultiple,
|
|
1392
|
+
addMultiple,
|
|
1393
|
+
toggle,
|
|
1394
|
+
]);
|
|
1335
1395
|
var toggleSelected = React.useCallback(function () {
|
|
1336
1396
|
toggle(itemKey);
|
|
1337
|
-
|
|
1397
|
+
dispatch(setLastSelectedId(itemKey));
|
|
1398
|
+
}, [toggle, itemKey, dispatch, setLastSelectedId]);
|
|
1338
1399
|
return {
|
|
1339
1400
|
isSelected: isSelected,
|
|
1340
1401
|
toggleSelected: toggleSelected,
|
|
1402
|
+
shiftAndToggleSelected: shiftAndToggleSelected,
|
|
1341
1403
|
};
|
|
1342
1404
|
};
|
|
1343
1405
|
|
|
@@ -1569,7 +1631,7 @@ var TrWithHoverBackground = styled__default['default'].tr(templateObject_1 || (t
|
|
|
1569
1631
|
var templateObject_1;
|
|
1570
1632
|
|
|
1571
1633
|
var StandardTableRow = React.memo(function StandardTableRow(_a) {
|
|
1572
|
-
var item = _a.item, rowIndex = _a.rowIndex, numRows = _a.numRows, colIndexOffset = _a.colIndexOffset, alwaysVisible = _a.alwaysVisible;
|
|
1634
|
+
var item = _a.item, itemIdList = _a.itemIdList, rowIndex = _a.rowIndex, numRows = _a.numRows, colIndexOffset = _a.colIndexOffset, alwaysVisible = _a.alwaysVisible, shiftPressedRef = _a.shiftPressedRef;
|
|
1573
1635
|
var trRef = React.useRef(null);
|
|
1574
1636
|
var totalNumColumns = useTotalNumColumns();
|
|
1575
1637
|
var stickyCheckboxColumn = useStandardTableConfig().stickyCheckboxColumn;
|
|
@@ -1577,7 +1639,7 @@ var StandardTableRow = React.memo(function StandardTableRow(_a) {
|
|
|
1577
1639
|
var columnIndexPerColumnId = useColumnIndexPerColumnIdContext().columnIndexPerColumnId;
|
|
1578
1640
|
var _b = useStandardTableConfig(), showRowCheckbox = _b.showRowCheckbox, rowBackgroundResolver = _b.rowBackgroundResolver, checkboxDisabledResolver = _b.checkboxDisabledResolver, enableGridCell = _b.enableGridCell, rowIndent = _b.rowIndent, enableExpandCollapse = _b.enableExpandCollapse;
|
|
1579
1641
|
var isExpanded = useExpandCollapseActions(item).isExpanded;
|
|
1580
|
-
var _c = useRowCheckbox(item), isSelected = _c.isSelected, toggleSelected = _c.toggleSelected;
|
|
1642
|
+
var _c = useRowCheckbox(item, itemIdList), isSelected = _c.isSelected, toggleSelected = _c.toggleSelected, shiftAndToggleSelected = _c.shiftAndToggleSelected;
|
|
1581
1643
|
var visible = core.useOnScreen(trRef, {
|
|
1582
1644
|
rootMargin: "400px 0px 400px 0px",
|
|
1583
1645
|
threshold: 0,
|
|
@@ -1630,7 +1692,7 @@ var StandardTableRow = React.memo(function StandardTableRow(_a) {
|
|
|
1630
1692
|
: undefined,
|
|
1631
1693
|
} },
|
|
1632
1694
|
React.createElement(core.Row, { width: "var(--swui-checkbox-cell-width)", minWidth: "var(--swui-checkbox-cell-width)", alignItems: "center", justifyContent: "center" },
|
|
1633
|
-
React.createElement(StandardTableRowCheckbox, { disabled: disabled, value: isSelected, onValueChange: toggleSelected, colIndex: colIndexOffset + (enableExpandCollapse ? 1 : 0), rowIndex: rowIndex, numRows: numRows })))),
|
|
1695
|
+
React.createElement(StandardTableRowCheckbox, { disabled: disabled, value: isSelected, onValueChange: toggleSelected, onValueChangeAndShift: shiftAndToggleSelected, colIndex: colIndexOffset + (enableExpandCollapse ? 1 : 0), rowIndex: rowIndex, numRows: numRows, shiftPressedRef: shiftPressedRef })))),
|
|
1634
1696
|
groupConfigsAndIds.map(function (_a, groupIndex) {
|
|
1635
1697
|
var groupConfig = _a.groupConfig, groupId = _a.groupId;
|
|
1636
1698
|
return (React.createElement(React.Fragment, { key: groupId }, groupConfig.columnOrder.map(function (columnId, index) { return (React.createElement(StandardTableCell, { key: columnId, columnId: columnId, item: item, colIndex: colIndexOffset + columnIndexPerColumnId[columnId], rowIndex: rowIndex, numRows: numRows, borderFromGroup: getCellBorderFromGroup(groupIndex, index, groupConfig.borderLeft), disableBorderLeft: groupIndex === 0 && index === 0 })); })));
|
|
@@ -1653,6 +1715,8 @@ var StandardTableRow = React.memo(function StandardTableRow(_a) {
|
|
|
1653
1715
|
numRows,
|
|
1654
1716
|
rowIndent,
|
|
1655
1717
|
rowIndex,
|
|
1718
|
+
shiftAndToggleSelected,
|
|
1719
|
+
shiftPressedRef,
|
|
1656
1720
|
showRowCheckbox,
|
|
1657
1721
|
stickyCheckboxColumn,
|
|
1658
1722
|
toggleSelected,
|
|
@@ -1707,6 +1771,7 @@ var StandardTableRowList = React.memo(function StandardTableRowList(_a) {
|
|
|
1707
1771
|
* rows after sorting.
|
|
1708
1772
|
*/
|
|
1709
1773
|
var sortCounterRef = React.useRef(0);
|
|
1774
|
+
var shiftPressedRef = React.useRef(false);
|
|
1710
1775
|
var _d = useStandardTableConfig(), keyResolver = _d.keyResolver, disableInfiniteList = _d.disableInfiniteList;
|
|
1711
1776
|
var _e = useStandardTableState().sortOrder, sortBy = _e.sortBy, desc = _e.desc;
|
|
1712
1777
|
var valueResolver = useColumnValueResolver(sortBy);
|
|
@@ -1727,7 +1792,29 @@ var StandardTableRowList = React.memo(function StandardTableRowList(_a) {
|
|
|
1727
1792
|
sortCounterRef.current++;
|
|
1728
1793
|
return sortedList;
|
|
1729
1794
|
}, [items, valueResolver, desc]);
|
|
1730
|
-
|
|
1795
|
+
var itemIdList = React.useMemo(function () { return sortedItems.map(function (l) { return keyResolver(l); }); }, [
|
|
1796
|
+
sortedItems,
|
|
1797
|
+
keyResolver,
|
|
1798
|
+
]);
|
|
1799
|
+
React.useEffect(function () {
|
|
1800
|
+
var keyUp = function (ev) {
|
|
1801
|
+
if (ev.key === "Shift") {
|
|
1802
|
+
shiftPressedRef.current = false;
|
|
1803
|
+
}
|
|
1804
|
+
};
|
|
1805
|
+
var keyDown = function (ev) {
|
|
1806
|
+
if (ev.key === "Shift") {
|
|
1807
|
+
shiftPressedRef.current = true;
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
document.addEventListener("keyup", keyUp);
|
|
1811
|
+
document.addEventListener("keydown", keyDown);
|
|
1812
|
+
return function () {
|
|
1813
|
+
document.removeEventListener("keyup", keyUp);
|
|
1814
|
+
document.removeEventListener("keydown", keyDown);
|
|
1815
|
+
};
|
|
1816
|
+
}, []);
|
|
1817
|
+
return (React.createElement(React.Fragment, { key: sortCounterRef.current }, sortedItems.map(function (item, index) { return (React.createElement(StandardTableRow, { alwaysVisible: disableInfiniteList || sortedItems.length < 30, item: item, itemIdList: itemIdList, key: itemIdList[index], colIndexOffset: colIndexOffset, rowIndex: index + rowIndexOffset, numRows: sortedItems.length, shiftPressedRef: shiftPressedRef })); })));
|
|
1731
1818
|
});
|
|
1732
1819
|
|
|
1733
1820
|
var StandardTableContent = React.memo(function StandardTableContent(_a) {
|
|
@@ -1761,7 +1848,7 @@ var StandardTableContent = React.memo(function StandardTableContent(_a) {
|
|
|
1761
1848
|
var useTableHeadCheckbox = function (items) {
|
|
1762
1849
|
var keyResolver = useStandardTableConfig().keyResolver;
|
|
1763
1850
|
var selectedIds = useStandardTableState().selectedIds.selectedIds;
|
|
1764
|
-
var _a = useStandardTableActions(), _b = _a.actions,
|
|
1851
|
+
var _a = useStandardTableActions(), _b = _a.actions, setSelectedIds = _b.setSelectedIds, clearSelection = _b.clearSelection, dispatch = _a.dispatch;
|
|
1765
1852
|
var selectionIsEmpty = selectedIds.length === 0;
|
|
1766
1853
|
var allItemsAreSelected = !items
|
|
1767
1854
|
? false
|
|
@@ -1769,7 +1856,7 @@ var useTableHeadCheckbox = function (items) {
|
|
|
1769
1856
|
var onClickCheckbox = React.useCallback(function () {
|
|
1770
1857
|
if (items) {
|
|
1771
1858
|
if (selectionIsEmpty) {
|
|
1772
|
-
dispatch(
|
|
1859
|
+
dispatch(setSelectedIds(items.map(function (item) { return keyResolver(item); })));
|
|
1773
1860
|
}
|
|
1774
1861
|
else {
|
|
1775
1862
|
dispatch(clearSelection());
|
|
@@ -1781,7 +1868,7 @@ var useTableHeadCheckbox = function (items) {
|
|
|
1781
1868
|
dispatch,
|
|
1782
1869
|
items,
|
|
1783
1870
|
keyResolver,
|
|
1784
|
-
|
|
1871
|
+
setSelectedIds,
|
|
1785
1872
|
]);
|
|
1786
1873
|
return {
|
|
1787
1874
|
selectionIsEmpty: selectionIsEmpty,
|
|
@@ -1974,12 +2061,10 @@ var StandardTable = function StandardTable(_a) {
|
|
|
1974
2061
|
var localTableContext = useLocalStateTableContext(tableId !== null && tableId !== void 0 ? tableId : generatedTableId, createStandardTableInitialState(initialSortOrder, initialSortOrderDesc)).tableContext;
|
|
1975
2062
|
var currentTableContext = tableContext || localTableContext;
|
|
1976
2063
|
var state = currentTableContext.state, actions = currentTableContext.actions, dispatch = currentTableContext.dispatch;
|
|
1977
|
-
var actionsContext = React.useMemo(function () {
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
};
|
|
1982
|
-
}, [actions, dispatch]);
|
|
2064
|
+
var actionsContext = React.useMemo(function () { return ({
|
|
2065
|
+
actions: actions,
|
|
2066
|
+
dispatch: dispatch,
|
|
2067
|
+
}); }, [actions, dispatch]);
|
|
1983
2068
|
var usingColumnGroups = Boolean(columnGroupOrder !== null && columnGroupOrder !== void 0 ? columnGroupOrder : "columnGroupOrder" in config);
|
|
1984
2069
|
var columnGroupsFromConfig = "columnGroups" in config ? config.columnGroups : undefined;
|
|
1985
2070
|
var columnGroupOrderFromConfig = "columnGroupOrder" in config ? config.columnGroupOrder : undefined;
|