@apia/table 4.0.25 → 4.0.26
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.d.ts +4 -3
- package/dist/index.js +145 -102
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -255,6 +255,7 @@ type TResponsiveTableStoreProps = {
|
|
|
255
255
|
* definida de estados con este parámetro.
|
|
256
256
|
*/
|
|
257
257
|
reserveColumnsForStates?: number;
|
|
258
|
+
statesColumns?: TResponsiveTableRowState[];
|
|
258
259
|
};
|
|
259
260
|
type TResponsiveTableRowsSelectionEvent = {
|
|
260
261
|
index: number;
|
|
@@ -519,7 +520,7 @@ interface ISelectableState<ColumnType extends IBasicColumn = IBasicColumn, Filte
|
|
|
519
520
|
* automáticamente por el keyHandler.
|
|
520
521
|
*/
|
|
521
522
|
selectedRows: number[];
|
|
522
|
-
statesColumns:
|
|
523
|
+
statesColumns: TResponsiveTableContextProps['statesColumns'];
|
|
523
524
|
}
|
|
524
525
|
type TKeyHandlerProps = BoxProps & {
|
|
525
526
|
/**
|
|
@@ -590,7 +591,7 @@ declare const Pagination: React__default.MemoExoticComponent<({ appliedFilters,
|
|
|
590
591
|
|
|
591
592
|
declare function getResponsiveTableContext(tableName: string): TResponsiveTableContext;
|
|
592
593
|
declare function useResponsiveTableContext(tableName?: string): TResponsiveTableContext;
|
|
593
|
-
declare const ResponsiveTableContext: React__default.MemoExoticComponent<({ allowEdition, allowRowsKeyboardSorting, avoidAutoEllipsis, allowSelection, allowSorting, avoidReparseSelectionOnRowChange, children, className, currentBreakPoint, customLabels, columns, filters, FiltersRenderer, rows, label, isMultiple, name, onChangeSelection, onFilterBlur, onFilterChange, onFilterPressEnter, onRowClick, onSelectRows, onSortChange, reserveColumnsForStates, SelectionHandler, variant, }: TResponsiveTableContextProps) => React__default.JSX.Element>;
|
|
594
|
+
declare const ResponsiveTableContext: React__default.MemoExoticComponent<({ allowEdition, allowRowsKeyboardSorting, avoidAutoEllipsis, allowSelection, allowSorting, avoidReparseSelectionOnRowChange, children, className, currentBreakPoint, customLabels, columns, filters, FiltersRenderer, rows, label, isMultiple, isLoading, name, statesColumns, onChangeSelection, onFilterBlur, onFilterChange, onFilterPressEnter, onRowClick, onSelectRows, onSortChange, reserveColumnsForStates, SelectionHandler, variant, }: TResponsiveTableContextProps) => React__default.JSX.Element>;
|
|
594
595
|
|
|
595
596
|
type TPayloadWithId$1<P = Record<string, unknown>, T extends string = string, M = never, E = never> = PayloadAction$1<P & {
|
|
596
597
|
id: string;
|
|
@@ -671,6 +672,7 @@ declare class Controller2 {
|
|
|
671
672
|
allowSorting?: boolean | undefined;
|
|
672
673
|
isMultiple?: boolean;
|
|
673
674
|
reserveColumnsForStates?: number | undefined;
|
|
675
|
+
statesColumns: TResponsiveTableContextProps["statesColumns"];
|
|
674
676
|
allowEdition?: boolean;
|
|
675
677
|
allowRowsKeyboardSorting?: boolean;
|
|
676
678
|
allowSelection?: boolean;
|
|
@@ -687,7 +689,6 @@ declare class Controller2 {
|
|
|
687
689
|
rows: TResponsiveTableRow<any>[];
|
|
688
690
|
scrollIntoViewRow?: number;
|
|
689
691
|
selectedRows: number[];
|
|
690
|
-
statesColumns: number;
|
|
691
692
|
accordionIndexColumns: TResponsiveTableIndexColumns;
|
|
692
693
|
isLoading: boolean;
|
|
693
694
|
};
|
package/dist/index.js
CHANGED
|
@@ -32,8 +32,8 @@ function getInitialState$1() {
|
|
|
32
32
|
isMultiple: true,
|
|
33
33
|
nonAdditionalColumnsCount: 0,
|
|
34
34
|
rows: [],
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
statesColumns: [],
|
|
36
|
+
selectedRows: []
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -353,14 +353,6 @@ const responsiveTableSlice = createSlice({
|
|
|
353
353
|
(current) => !current.showAsAdditional
|
|
354
354
|
).length;
|
|
355
355
|
}
|
|
356
|
-
if (rest.rows) {
|
|
357
|
-
state[tableName].statesColumns = Math.max(
|
|
358
|
-
state[tableName]?.reserveColumnsForStates ?? 0,
|
|
359
|
-
...state[tableName]?.rows?.map(
|
|
360
|
-
(current) => current.states?.length ?? 0
|
|
361
|
-
) ?? [0]
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
356
|
if (rest.filters) {
|
|
365
357
|
state[tableName].hasNonAdditionalFilters = rest.filters.filter(
|
|
366
358
|
(current) => !current.asAdditional && (rest.columns ?? state[tableName].columns)?.find(
|
|
@@ -470,7 +462,9 @@ const NoMemoResponsiveTableContext = ({
|
|
|
470
462
|
rows,
|
|
471
463
|
label,
|
|
472
464
|
isMultiple,
|
|
465
|
+
isLoading,
|
|
473
466
|
name,
|
|
467
|
+
statesColumns,
|
|
474
468
|
onChangeSelection,
|
|
475
469
|
onFilterBlur,
|
|
476
470
|
onFilterChange,
|
|
@@ -505,7 +499,9 @@ const NoMemoResponsiveTableContext = ({
|
|
|
505
499
|
onRowClick,
|
|
506
500
|
onSelectRows,
|
|
507
501
|
onSortChange,
|
|
508
|
-
SelectionHandler
|
|
502
|
+
SelectionHandler,
|
|
503
|
+
statesColumns,
|
|
504
|
+
isLoading
|
|
509
505
|
}),
|
|
510
506
|
[
|
|
511
507
|
currentBreakPoint,
|
|
@@ -521,7 +517,9 @@ const NoMemoResponsiveTableContext = ({
|
|
|
521
517
|
onRowClick,
|
|
522
518
|
onSelectRows,
|
|
523
519
|
onSortChange,
|
|
524
|
-
SelectionHandler
|
|
520
|
+
SelectionHandler,
|
|
521
|
+
statesColumns,
|
|
522
|
+
isLoading
|
|
525
523
|
]
|
|
526
524
|
);
|
|
527
525
|
tableContexts[actualName] = contextValue;
|
|
@@ -538,7 +536,9 @@ const NoMemoResponsiveTableContext = ({
|
|
|
538
536
|
isMultiple,
|
|
539
537
|
tableName: actualName,
|
|
540
538
|
reserveColumnsForStates,
|
|
541
|
-
handleFocus: !SelectionHandler
|
|
539
|
+
handleFocus: !SelectionHandler,
|
|
540
|
+
statesColumns,
|
|
541
|
+
isLoading
|
|
542
542
|
})
|
|
543
543
|
);
|
|
544
544
|
});
|
|
@@ -578,6 +578,22 @@ const NoMemoResponsiveTableContext = ({
|
|
|
578
578
|
})
|
|
579
579
|
);
|
|
580
580
|
}, [filters]);
|
|
581
|
+
useUpdateEffect(() => {
|
|
582
|
+
responsiveTableStore.dispatch(
|
|
583
|
+
responsiveTableActions.update({
|
|
584
|
+
tableName: actualName,
|
|
585
|
+
statesColumns
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
}, [statesColumns]);
|
|
589
|
+
useUpdateEffect(() => {
|
|
590
|
+
responsiveTableStore.dispatch(
|
|
591
|
+
responsiveTableActions.update({
|
|
592
|
+
tableName: actualName,
|
|
593
|
+
isLoading
|
|
594
|
+
})
|
|
595
|
+
);
|
|
596
|
+
}, [isLoading]);
|
|
581
597
|
useUnmount(() => {
|
|
582
598
|
responsiveTableStore.dispatch(
|
|
583
599
|
responsiveTableActions.destroy({ tableName: actualName })
|
|
@@ -949,7 +965,7 @@ function getDomStoreProps(element, elementProps, stateSelector) {
|
|
|
949
965
|
const tableState = stateSelector(globalState);
|
|
950
966
|
const hasNonAdditionalFilters = tableState?.hasNonAdditionalFilters;
|
|
951
967
|
const startDataRowIndex = hasNonAdditionalFilters ? 2 : 1;
|
|
952
|
-
const statesColumns = tableState?.statesColumns ?? 0;
|
|
968
|
+
const statesColumns = tableState?.statesColumns?.length ?? 0;
|
|
953
969
|
let expandedBeforeThisRow = 0;
|
|
954
970
|
if (element === "tr")
|
|
955
971
|
expandedBeforeThisRow = tableState?.expandedRows.filter(
|
|
@@ -1023,7 +1039,7 @@ function getDomProps(state, element, elementProps) {
|
|
|
1023
1039
|
case "filterTd": {
|
|
1024
1040
|
const castedProps = elementProps;
|
|
1025
1041
|
returnObject = {
|
|
1026
|
-
"aria-colindex": castedProps.columnIndex + 1 + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0),
|
|
1042
|
+
"aria-colindex": castedProps.columnIndex + 1 + (state.statesColumns?.length || 0) + (state.hasNonAdditionalFilters ? 1 : 0),
|
|
1027
1043
|
"data-editionmode": state.isEditionMode && state.isFocused,
|
|
1028
1044
|
"data-focused": state.isFocused,
|
|
1029
1045
|
tabIndex: state.isFocused ? 0 : -1,
|
|
@@ -1077,7 +1093,7 @@ function getDomProps(state, element, elementProps) {
|
|
|
1077
1093
|
case "td": {
|
|
1078
1094
|
const castedProps = elementProps;
|
|
1079
1095
|
returnObject = {
|
|
1080
|
-
"aria-colindex": castedProps.columnIndex + 1 + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0),
|
|
1096
|
+
"aria-colindex": castedProps.columnIndex + 1 + (state.statesColumns?.length ?? 0) + (state.hasNonAdditionalFilters ? 1 : 0),
|
|
1081
1097
|
"data-editionmode": state.isEditionMode && state.isFocused,
|
|
1082
1098
|
"data-focused": state.isFocused,
|
|
1083
1099
|
tabIndex: state.isFocused ? 0 : -1,
|
|
@@ -1121,7 +1137,7 @@ function getDomProps(state, element, elementProps) {
|
|
|
1121
1137
|
case "th": {
|
|
1122
1138
|
const castedProps = elementProps;
|
|
1123
1139
|
returnObject = {
|
|
1124
|
-
"aria-colindex": castedProps.columnIndex + 1 + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0),
|
|
1140
|
+
"aria-colindex": castedProps.columnIndex + 1 + (state.statesColumns?.length ?? 0) + (state.hasNonAdditionalFilters ? 1 : 0),
|
|
1125
1141
|
"aria-sort": ["ascending", "descending", void 0][["Asc", "Desc", null].findIndex(
|
|
1126
1142
|
(current) => current === state.columns[castedProps.columnIndex].currentSorting
|
|
1127
1143
|
)],
|
|
@@ -1211,6 +1227,10 @@ const NoMemoHeaderCell = ({
|
|
|
1211
1227
|
const tableState = global.responsiveTableSlice[name];
|
|
1212
1228
|
return tableState?.allowSorting;
|
|
1213
1229
|
});
|
|
1230
|
+
const isLoading = useResponsiveTable((global) => {
|
|
1231
|
+
const tableState = global.responsiveTableSlice[name];
|
|
1232
|
+
return tableState?.isLoading;
|
|
1233
|
+
});
|
|
1214
1234
|
const domProps = useDomProps(
|
|
1215
1235
|
"th",
|
|
1216
1236
|
{
|
|
@@ -1231,11 +1251,14 @@ const NoMemoHeaderCell = ({
|
|
|
1231
1251
|
},
|
|
1232
1252
|
[column.maxWidth, column.minWidth, column.width, isResize, width]
|
|
1233
1253
|
);
|
|
1254
|
+
const lastIsLoading = useLatest(isLoading);
|
|
1234
1255
|
const buttonProps = useOtherTagButton(
|
|
1235
1256
|
React.useMemo(
|
|
1236
1257
|
() => ({
|
|
1237
1258
|
className: "headButton",
|
|
1238
1259
|
onClick: (ev) => {
|
|
1260
|
+
if (lastIsLoading.current)
|
|
1261
|
+
return;
|
|
1239
1262
|
if (isChild(
|
|
1240
1263
|
ev.target,
|
|
1241
1264
|
(current) => current.classList.contains("headButton__resizer")
|
|
@@ -1424,7 +1447,7 @@ const StateCell = ({ index, rowIndex, state, isHeader }) => {
|
|
|
1424
1447
|
{ columnIndex: index, rowIndex },
|
|
1425
1448
|
domPropsSelector(name)
|
|
1426
1449
|
);
|
|
1427
|
-
return /* @__PURE__ */ jsx(Box, { as: "td", className: "stateCell", ...domProps, children: state ? /* @__PURE__ */ jsx(RowStatesRenderer, { state }) : "" });
|
|
1450
|
+
return /* @__PURE__ */ jsx(Box, { as: "td", className: "stateCell", ...domProps, children: state?.Icon ? /* @__PURE__ */ jsx(RowStatesRenderer, { state }) : "" });
|
|
1428
1451
|
};
|
|
1429
1452
|
|
|
1430
1453
|
const units = ["B", "KB", "MB", "GB"];
|
|
@@ -1629,6 +1652,25 @@ const NoMemoHeader = () => {
|
|
|
1629
1652
|
const focusedRow = useResponsiveTable(
|
|
1630
1653
|
(global) => global.responsiveTableSlice[name]?.focusedRow
|
|
1631
1654
|
);
|
|
1655
|
+
const statesColumns = useResponsiveTable((global) => {
|
|
1656
|
+
const state = global.responsiveTableSlice[name];
|
|
1657
|
+
return Array(
|
|
1658
|
+
Math.max(
|
|
1659
|
+
0,
|
|
1660
|
+
state?.reserveColumnsForStates || 0,
|
|
1661
|
+
state?.statesColumns?.length || 0
|
|
1662
|
+
)
|
|
1663
|
+
).fill(1).map((_, index) => {
|
|
1664
|
+
const r = {
|
|
1665
|
+
Icon: "",
|
|
1666
|
+
iconColor: "transparent",
|
|
1667
|
+
id: String(index),
|
|
1668
|
+
tooltip: "",
|
|
1669
|
+
...state.statesColumns?.[index]
|
|
1670
|
+
};
|
|
1671
|
+
return r;
|
|
1672
|
+
});
|
|
1673
|
+
});
|
|
1632
1674
|
const filters = useResponsiveTable(
|
|
1633
1675
|
(global) => {
|
|
1634
1676
|
const tableState = global.responsiveTableSlice[name];
|
|
@@ -1646,10 +1688,6 @@ const NoMemoHeader = () => {
|
|
|
1646
1688
|
}, true);
|
|
1647
1689
|
}
|
|
1648
1690
|
);
|
|
1649
|
-
const statesCount = useResponsiveTable((globalState) => {
|
|
1650
|
-
const state = globalState.responsiveTableSlice[name];
|
|
1651
|
-
return state?.statesColumns ?? 0;
|
|
1652
|
-
}, shallowEqual$1);
|
|
1653
1691
|
const additionalColumns = React.useMemo(
|
|
1654
1692
|
() => columns?.reduce(
|
|
1655
1693
|
(count, column) => count + (column.showAsAdditional ? 1 : 0),
|
|
@@ -1657,9 +1695,6 @@ const NoMemoHeader = () => {
|
|
|
1657
1695
|
),
|
|
1658
1696
|
[columns]
|
|
1659
1697
|
);
|
|
1660
|
-
const statesIds = React.useMemo(() => {
|
|
1661
|
-
return Array(statesCount).fill("").map(() => uniqueId());
|
|
1662
|
-
}, [statesCount]);
|
|
1663
1698
|
const [isFiltersRowVisible, setIsFiltersRowVisible] = React.useState(
|
|
1664
1699
|
/* (persistentStorage.showResponsiveTableFilters as boolean) ?? */
|
|
1665
1700
|
false
|
|
@@ -1714,7 +1749,7 @@ const NoMemoHeader = () => {
|
|
|
1714
1749
|
] })
|
|
1715
1750
|
}
|
|
1716
1751
|
),
|
|
1717
|
-
|
|
1752
|
+
statesColumns.map(({ id, ...state }, i) => /* @__PURE__ */ jsx(StateCell, { isHeader: true, index: i, rowIndex: 1, state }, id)),
|
|
1718
1753
|
columns?.map((current, actualColumnIndex) => ({
|
|
1719
1754
|
...current,
|
|
1720
1755
|
actualTableColumnIndex: actualColumnIndex
|
|
@@ -1752,7 +1787,7 @@ const NoMemoHeader = () => {
|
|
|
1752
1787
|
children: "\xA0"
|
|
1753
1788
|
}
|
|
1754
1789
|
),
|
|
1755
|
-
|
|
1790
|
+
statesColumns.map(({ id }, i) => /* @__PURE__ */ jsx(StateCell, { isHeader: true, index: i, rowIndex: 2 }, id)),
|
|
1756
1791
|
columns?.filter((current) => !current.showAsAdditional && !current.hidden).map((current, columnIndex) => {
|
|
1757
1792
|
const filter = filters.find(
|
|
1758
1793
|
(search) => search.definition.column === current.name
|
|
@@ -2024,7 +2059,11 @@ const NoMemoRow = ({ rowIndex }) => {
|
|
|
2024
2059
|
);
|
|
2025
2060
|
const statesCount = useResponsiveTable((globalState) => {
|
|
2026
2061
|
const state = globalState.responsiveTableSlice[name];
|
|
2027
|
-
return
|
|
2062
|
+
return Math.max(
|
|
2063
|
+
state?.reserveColumnsForStates || 0,
|
|
2064
|
+
state?.statesColumns?.length ?? 0,
|
|
2065
|
+
0
|
|
2066
|
+
);
|
|
2028
2067
|
}, shallowEqual);
|
|
2029
2068
|
const states = React.useMemo(
|
|
2030
2069
|
() => (row.states ?? []).map((current) => ({ ...current, id: uniqueId() })),
|
|
@@ -2173,7 +2212,7 @@ const NoMemoTableRenderer = ({ variant }) => {
|
|
|
2173
2212
|
return tableState?.rows?.map((current) => current.id);
|
|
2174
2213
|
}, shallowEqual);
|
|
2175
2214
|
const columnsCount = useResponsiveTable(
|
|
2176
|
-
(global) => (global.responsiveTableSlice[name]?.nonAdditionalColumnsCount ?? 0) + (global.responsiveTableSlice[name]?.hasNonAdditionalFilters ? 1 : 0) + (global.responsiveTableSlice[name]?.statesColumns ?? 0) + (global.responsiveTableSlice[name]?.columns.find(
|
|
2215
|
+
(global) => (global.responsiveTableSlice[name]?.nonAdditionalColumnsCount ?? 0) + (global.responsiveTableSlice[name]?.hasNonAdditionalFilters ? 1 : 0) + (global.responsiveTableSlice[name]?.statesColumns?.length ?? 0) + (global.responsiveTableSlice[name]?.columns.find(
|
|
2177
2216
|
(current) => current.showAsAdditional
|
|
2178
2217
|
) ? 1 : 0)
|
|
2179
2218
|
);
|
|
@@ -3007,63 +3046,6 @@ const NoMemoPagination = ({
|
|
|
3007
3046
|
};
|
|
3008
3047
|
const Pagination = React.memo(NoMemoPagination);
|
|
3009
3048
|
|
|
3010
|
-
function applyFocusAttributes(table, _previousState, state, focus = state.isFocused, target) {
|
|
3011
|
-
table.querySelectorAll(getFocusSelector()).forEach((e) => {
|
|
3012
|
-
e.tabIndex = -1;
|
|
3013
|
-
});
|
|
3014
|
-
if (state.focusedColumn === 0) {
|
|
3015
|
-
const focusedRow = table.querySelector(
|
|
3016
|
-
`tr[data-rowindex="${state.focusedRow}"]`
|
|
3017
|
-
);
|
|
3018
|
-
if (focusedRow) {
|
|
3019
|
-
focusedRow.tabIndex = 0;
|
|
3020
|
-
window.requestAnimationFrame(() => {
|
|
3021
|
-
if (focus) {
|
|
3022
|
-
focusedRow.focus();
|
|
3023
|
-
}
|
|
3024
|
-
});
|
|
3025
|
-
}
|
|
3026
|
-
} else {
|
|
3027
|
-
const focusedCell = table.querySelector(
|
|
3028
|
-
`tr[data-rowindex="${state.focusedRow}"] td[aria-colindex="${state.focusedColumn}"], tr[data-rowindex="${state.focusedRow}"] th[aria-colindex="${state.focusedColumn}"]`
|
|
3029
|
-
);
|
|
3030
|
-
if (target) {
|
|
3031
|
-
target.focus();
|
|
3032
|
-
}
|
|
3033
|
-
if (focusedCell instanceof HTMLElement) {
|
|
3034
|
-
const widgets = [];
|
|
3035
|
-
if (state.isEditionMode) {
|
|
3036
|
-
widgets.push(
|
|
3037
|
-
...focusedCell.querySelectorAll(getFocusSelector())
|
|
3038
|
-
);
|
|
3039
|
-
} else {
|
|
3040
|
-
const widget = focusedCell.querySelector(getFocusSelector());
|
|
3041
|
-
if (widget) {
|
|
3042
|
-
widgets.push(widget);
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
if (widgets.length) {
|
|
3046
|
-
widgets.forEach((widget, i) => {
|
|
3047
|
-
widget.tabIndex = 0;
|
|
3048
|
-
if (i === 0)
|
|
3049
|
-
window.requestAnimationFrame(() => {
|
|
3050
|
-
if (!target && focus) {
|
|
3051
|
-
widget.focus();
|
|
3052
|
-
}
|
|
3053
|
-
});
|
|
3054
|
-
});
|
|
3055
|
-
} else {
|
|
3056
|
-
focusedCell.tabIndex = 0;
|
|
3057
|
-
window.requestAnimationFrame(() => {
|
|
3058
|
-
if (!target && focus) {
|
|
3059
|
-
focusedCell.focus();
|
|
3060
|
-
}
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
}
|
|
3065
|
-
}
|
|
3066
|
-
|
|
3067
3049
|
function setAriaAttributes(element, attribute, value) {
|
|
3068
3050
|
element.setAttribute(attribute, value);
|
|
3069
3051
|
}
|
|
@@ -3150,18 +3132,11 @@ function handleMouseDownEvent(ev) {
|
|
|
3150
3132
|
state.focusedRow = rowIndex;
|
|
3151
3133
|
state.isFocused = true;
|
|
3152
3134
|
applySelectionAttributes(table, this.getState(), state);
|
|
3153
|
-
applyFocusAttributes(
|
|
3154
|
-
table,
|
|
3155
|
-
this.getState(),
|
|
3156
|
-
state,
|
|
3157
|
-
state.isFocused,
|
|
3158
|
-
target
|
|
3159
|
-
);
|
|
3160
3135
|
this.setState(state);
|
|
3161
|
-
this.events.onRowClick
|
|
3136
|
+
this.events.emit("onRowClick", [
|
|
3162
3137
|
{ row: state.rows[state.focusedRow], index: state.focusedRow },
|
|
3163
3138
|
state.focusedRow
|
|
3164
|
-
);
|
|
3139
|
+
]);
|
|
3165
3140
|
} else {
|
|
3166
3141
|
console.warn("Cannot parse rowIndex or colIndex");
|
|
3167
3142
|
}
|
|
@@ -3171,6 +3146,61 @@ function handleMouseDownEvent(ev) {
|
|
|
3171
3146
|
}
|
|
3172
3147
|
}
|
|
3173
3148
|
|
|
3149
|
+
function applyFocusAttributes(table, _previousState, state, focus = state.isFocused, target) {
|
|
3150
|
+
focus = focus && table.contains(document.activeElement);
|
|
3151
|
+
table.querySelectorAll(getFocusSelector()).forEach((e) => {
|
|
3152
|
+
e.tabIndex = -1;
|
|
3153
|
+
});
|
|
3154
|
+
if (state.focusedColumn === 0) {
|
|
3155
|
+
const focusedRow = table.querySelector(
|
|
3156
|
+
`tr[data-rowindex="${state.focusedRow}"]`
|
|
3157
|
+
);
|
|
3158
|
+
if (focusedRow) {
|
|
3159
|
+
focusedRow.tabIndex = 0;
|
|
3160
|
+
window.requestAnimationFrame(() => {
|
|
3161
|
+
if (focus) {
|
|
3162
|
+
focusedRow.focus();
|
|
3163
|
+
}
|
|
3164
|
+
});
|
|
3165
|
+
}
|
|
3166
|
+
} else {
|
|
3167
|
+
const focusedCell = table.querySelector(
|
|
3168
|
+
`tr[data-rowindex="${state.focusedRow}"] td[aria-colindex="${state.focusedColumn}"], tr[data-rowindex="${state.focusedRow}"] th[aria-colindex="${state.focusedColumn}"]`
|
|
3169
|
+
);
|
|
3170
|
+
if (focusedCell instanceof HTMLElement) {
|
|
3171
|
+
const widgets = [];
|
|
3172
|
+
if (state.isEditionMode) {
|
|
3173
|
+
widgets.push(
|
|
3174
|
+
...focusedCell.querySelectorAll(getFocusSelector())
|
|
3175
|
+
);
|
|
3176
|
+
} else {
|
|
3177
|
+
const widget = focusedCell.querySelector(getFocusSelector());
|
|
3178
|
+
if (widget) {
|
|
3179
|
+
widgets.push(widget);
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
if (widgets.length) {
|
|
3183
|
+
widgets.forEach((widget, i) => {
|
|
3184
|
+
widget.tabIndex = 0;
|
|
3185
|
+
if (i === 0)
|
|
3186
|
+
window.requestAnimationFrame(() => {
|
|
3187
|
+
if (focus) {
|
|
3188
|
+
widget.focus();
|
|
3189
|
+
}
|
|
3190
|
+
});
|
|
3191
|
+
});
|
|
3192
|
+
} else {
|
|
3193
|
+
focusedCell.tabIndex = 0;
|
|
3194
|
+
window.requestAnimationFrame(() => {
|
|
3195
|
+
if (focus) {
|
|
3196
|
+
focusedCell.focus();
|
|
3197
|
+
}
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3174
3204
|
function handleKeyDownEvent(ev) {
|
|
3175
3205
|
const target = ev.target;
|
|
3176
3206
|
const state = this.getState();
|
|
@@ -3201,6 +3231,11 @@ function handleKeyDownEvent(ev) {
|
|
|
3201
3231
|
"PageDown"
|
|
3202
3232
|
].includes(ev.code) || ev.code === "Space" && ev.ctrlKey) {
|
|
3203
3233
|
ev.preventDefault();
|
|
3234
|
+
let mustFocus = false;
|
|
3235
|
+
const maxColumnIndex = state.columns.length + Math.max(
|
|
3236
|
+
state.reserveColumnsForStates ?? 0,
|
|
3237
|
+
state.statesColumns?.length ?? 0
|
|
3238
|
+
) + (state.hasNonAdditionalFilters ? 1 : 0);
|
|
3204
3239
|
switch (ev.code) {
|
|
3205
3240
|
case "Space":
|
|
3206
3241
|
if (state.selectedRows.includes(rowIndex)) {
|
|
@@ -3217,6 +3252,7 @@ function handleKeyDownEvent(ev) {
|
|
|
3217
3252
|
state.hasNonAdditionalFilters ? -2 : -1,
|
|
3218
3253
|
state.rows.length - 1
|
|
3219
3254
|
);
|
|
3255
|
+
mustFocus = true;
|
|
3220
3256
|
if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
|
|
3221
3257
|
state.selectedRows = [
|
|
3222
3258
|
...state.selectedRows,
|
|
@@ -3232,6 +3268,7 @@ function handleKeyDownEvent(ev) {
|
|
|
3232
3268
|
state.hasNonAdditionalFilters ? -2 : -1,
|
|
3233
3269
|
state.rows.length - 1
|
|
3234
3270
|
);
|
|
3271
|
+
mustFocus = true;
|
|
3235
3272
|
if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
|
|
3236
3273
|
state.selectedRows = [
|
|
3237
3274
|
...state.selectedRows,
|
|
@@ -3245,17 +3282,20 @@ function handleKeyDownEvent(ev) {
|
|
|
3245
3282
|
state.focusedColumn = addBoundary(
|
|
3246
3283
|
state.focusedColumn - 1,
|
|
3247
3284
|
0,
|
|
3248
|
-
|
|
3285
|
+
maxColumnIndex
|
|
3249
3286
|
);
|
|
3287
|
+
mustFocus = true;
|
|
3250
3288
|
break;
|
|
3251
3289
|
case "ArrowRight":
|
|
3252
3290
|
state.focusedColumn = addBoundary(
|
|
3253
3291
|
state.focusedColumn + 1,
|
|
3254
3292
|
0,
|
|
3255
|
-
|
|
3293
|
+
maxColumnIndex
|
|
3256
3294
|
);
|
|
3295
|
+
mustFocus = true;
|
|
3257
3296
|
break;
|
|
3258
3297
|
case "Home":
|
|
3298
|
+
mustFocus = true;
|
|
3259
3299
|
if (state.focusedColumn === 0) {
|
|
3260
3300
|
state.focusedRow = state.hasNonAdditionalFilters ? -2 : -1;
|
|
3261
3301
|
if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
|
|
@@ -3278,6 +3318,7 @@ function handleKeyDownEvent(ev) {
|
|
|
3278
3318
|
}
|
|
3279
3319
|
break;
|
|
3280
3320
|
case "End":
|
|
3321
|
+
mustFocus = true;
|
|
3281
3322
|
if (state.focusedColumn === 0) {
|
|
3282
3323
|
state.focusedRow = state.rows.length - 1;
|
|
3283
3324
|
if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
|
|
@@ -3296,10 +3337,11 @@ function handleKeyDownEvent(ev) {
|
|
|
3296
3337
|
state.selectedRows = [state.focusedRow];
|
|
3297
3338
|
}
|
|
3298
3339
|
} else {
|
|
3299
|
-
state.focusedColumn =
|
|
3340
|
+
state.focusedColumn = maxColumnIndex;
|
|
3300
3341
|
}
|
|
3301
3342
|
break;
|
|
3302
3343
|
case "PageUp":
|
|
3344
|
+
mustFocus = true;
|
|
3303
3345
|
state.focusedRow = addBoundary(
|
|
3304
3346
|
state.focusedRow - 6,
|
|
3305
3347
|
state.hasNonAdditionalFilters ? -2 : -1,
|
|
@@ -3318,6 +3360,7 @@ function handleKeyDownEvent(ev) {
|
|
|
3318
3360
|
}
|
|
3319
3361
|
break;
|
|
3320
3362
|
case "PageDown":
|
|
3363
|
+
mustFocus = true;
|
|
3321
3364
|
state.focusedRow = addBoundary(
|
|
3322
3365
|
state.focusedRow + 6,
|
|
3323
3366
|
state.hasNonAdditionalFilters ? -2 : -1,
|
|
@@ -3336,24 +3379,24 @@ function handleKeyDownEvent(ev) {
|
|
|
3336
3379
|
}
|
|
3337
3380
|
break;
|
|
3338
3381
|
case "Enter": {
|
|
3382
|
+
mustFocus = true;
|
|
3339
3383
|
state.isEditionMode = true;
|
|
3340
3384
|
this.setState(state);
|
|
3341
|
-
applyFocusAttributes(table, this.getState(), state);
|
|
3342
3385
|
if (state.focusedRow >= 0) {
|
|
3343
|
-
this.events.onSelectRows
|
|
3386
|
+
this.events.emit("onSelectRows", [
|
|
3344
3387
|
this.getSelection().map((index) => ({
|
|
3345
3388
|
index,
|
|
3346
3389
|
row: this.getState().rows[index]
|
|
3347
3390
|
})),
|
|
3348
3391
|
state.focusedRow
|
|
3349
|
-
);
|
|
3392
|
+
]);
|
|
3350
3393
|
}
|
|
3351
3394
|
return;
|
|
3352
3395
|
}
|
|
3353
3396
|
}
|
|
3354
3397
|
state.isFocused = true;
|
|
3355
3398
|
applySelectionAttributes(table, this.getState(), state);
|
|
3356
|
-
applyFocusAttributes(table, this.getState(), state);
|
|
3399
|
+
applyFocusAttributes(table, this.getState(), state, mustFocus);
|
|
3357
3400
|
this.setState(state);
|
|
3358
3401
|
}
|
|
3359
3402
|
}
|