@apia/table 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/index.d.ts +787 -24
  2. package/dist/index.js +3667 -24
  3. package/dist/index.js.map +1 -1
  4. package/package.json +7 -7
  5. package/dist/Cell.js +0 -52
  6. package/dist/Cell.js.map +0 -1
  7. package/dist/FilterCell.js +0 -68
  8. package/dist/FilterCell.js.map +0 -1
  9. package/dist/Header.js +0 -171
  10. package/dist/Header.js.map +0 -1
  11. package/dist/HeaderCell.js +0 -223
  12. package/dist/HeaderCell.js.map +0 -1
  13. package/dist/KeyHandler.js +0 -28
  14. package/dist/KeyHandler.js.map +0 -1
  15. package/dist/ResponsiveTable.d.ts +0 -8
  16. package/dist/ResponsiveTable.d.ts.map +0 -1
  17. package/dist/ResponsiveTable.js +0 -29
  18. package/dist/ResponsiveTable.js.map +0 -1
  19. package/dist/ResponsiveTableContext.d.ts +0 -8
  20. package/dist/ResponsiveTableContext.d.ts.map +0 -1
  21. package/dist/ResponsiveTableContext.js +0 -140
  22. package/dist/ResponsiveTableContext.js.map +0 -1
  23. package/dist/Row.js +0 -230
  24. package/dist/Row.js.map +0 -1
  25. package/dist/SeparatorCell.js +0 -20
  26. package/dist/SeparatorCell.js.map +0 -1
  27. package/dist/StateCell.js +0 -19
  28. package/dist/StateCell.js.map +0 -1
  29. package/dist/filters/RangeFilter.js +0 -61
  30. package/dist/filters/RangeFilter.js.map +0 -1
  31. package/dist/renderers/AccordionCell.d.ts +0 -15
  32. package/dist/renderers/AccordionCell.d.ts.map +0 -1
  33. package/dist/renderers/AccordionCell.js +0 -23
  34. package/dist/renderers/AccordionCell.js.map +0 -1
  35. package/dist/renderers/AccordionDocNameCellRenderer.d.ts +0 -11
  36. package/dist/renderers/AccordionDocNameCellRenderer.d.ts.map +0 -1
  37. package/dist/renderers/AccordionDocNameCellRenderer.js +0 -39
  38. package/dist/renderers/AccordionDocNameCellRenderer.js.map +0 -1
  39. package/dist/renderers/AccordionElement.d.ts +0 -11
  40. package/dist/renderers/AccordionElement.d.ts.map +0 -1
  41. package/dist/renderers/AccordionElement.js +0 -115
  42. package/dist/renderers/AccordionElement.js.map +0 -1
  43. package/dist/renderers/AccordionHTMLCellRenderer.d.ts +0 -8
  44. package/dist/renderers/AccordionHTMLCellRenderer.d.ts.map +0 -1
  45. package/dist/renderers/AccordionHTMLCellRenderer.js +0 -37
  46. package/dist/renderers/AccordionHTMLCellRenderer.js.map +0 -1
  47. package/dist/renderers/AccordionRenderer.d.ts +0 -6
  48. package/dist/renderers/AccordionRenderer.d.ts.map +0 -1
  49. package/dist/renderers/AccordionRenderer.js +0 -76
  50. package/dist/renderers/AccordionRenderer.js.map +0 -1
  51. package/dist/renderers/AdditionalColumnDefaultRenderer.d.ts +0 -7
  52. package/dist/renderers/AdditionalColumnDefaultRenderer.d.ts.map +0 -1
  53. package/dist/renderers/AdditionalColumnDefaultRenderer.js +0 -31
  54. package/dist/renderers/AdditionalColumnDefaultRenderer.js.map +0 -1
  55. package/dist/renderers/DefaultCellRenderer.d.ts +0 -11
  56. package/dist/renderers/DefaultCellRenderer.d.ts.map +0 -1
  57. package/dist/renderers/DefaultCellRenderer.js +0 -49
  58. package/dist/renderers/DefaultCellRenderer.js.map +0 -1
  59. package/dist/renderers/DefaultRowRenderer.d.ts +0 -6
  60. package/dist/renderers/DefaultRowRenderer.d.ts.map +0 -1
  61. package/dist/renderers/DefaultRowRenderer.js +0 -26
  62. package/dist/renderers/DefaultRowRenderer.js.map +0 -1
  63. package/dist/renderers/DocNameCellRenderer.d.ts +0 -10
  64. package/dist/renderers/DocNameCellRenderer.d.ts.map +0 -1
  65. package/dist/renderers/DocNameCellRenderer.js +0 -43
  66. package/dist/renderers/DocNameCellRenderer.js.map +0 -1
  67. package/dist/renderers/HTMLCellRenderer.d.ts +0 -8
  68. package/dist/renderers/HTMLCellRenderer.d.ts.map +0 -1
  69. package/dist/renderers/HTMLCellRenderer.js +0 -29
  70. package/dist/renderers/HTMLCellRenderer.js.map +0 -1
  71. package/dist/renderers/IsLoadingRenderer.d.ts +0 -6
  72. package/dist/renderers/IsLoadingRenderer.d.ts.map +0 -1
  73. package/dist/renderers/IsLoadingRenderer.js +0 -9
  74. package/dist/renderers/IsLoadingRenderer.js.map +0 -1
  75. package/dist/renderers/NoRegistersRenderer.d.ts +0 -6
  76. package/dist/renderers/NoRegistersRenderer.d.ts.map +0 -1
  77. package/dist/renderers/NoRegistersRenderer.js +0 -11
  78. package/dist/renderers/NoRegistersRenderer.js.map +0 -1
  79. package/dist/renderers/PriorityAccordionRenderer.d.ts +0 -6
  80. package/dist/renderers/PriorityAccordionRenderer.d.ts.map +0 -1
  81. package/dist/renderers/PriorityAccordionRenderer.js +0 -36
  82. package/dist/renderers/PriorityAccordionRenderer.js.map +0 -1
  83. package/dist/renderers/PriorityRenderer.d.ts +0 -9
  84. package/dist/renderers/PriorityRenderer.d.ts.map +0 -1
  85. package/dist/renderers/PriorityRenderer.js +0 -46
  86. package/dist/renderers/PriorityRenderer.js.map +0 -1
  87. package/dist/renderers/RowStatesRenderer.d.ts +0 -9
  88. package/dist/renderers/RowStatesRenderer.d.ts.map +0 -1
  89. package/dist/renderers/RowStatesRenderer.js +0 -34
  90. package/dist/renderers/RowStatesRenderer.js.map +0 -1
  91. package/dist/renderers/StatusAccordionRenderer.d.ts +0 -6
  92. package/dist/renderers/StatusAccordionRenderer.d.ts.map +0 -1
  93. package/dist/renderers/StatusAccordionRenderer.js +0 -23
  94. package/dist/renderers/StatusAccordionRenderer.js.map +0 -1
  95. package/dist/renderers/StatusRenderer.d.ts +0 -9
  96. package/dist/renderers/StatusRenderer.d.ts.map +0 -1
  97. package/dist/renderers/StatusRenderer.js +0 -54
  98. package/dist/renderers/StatusRenderer.js.map +0 -1
  99. package/dist/renderers/TableRenderer.d.ts +0 -6
  100. package/dist/renderers/TableRenderer.d.ts.map +0 -1
  101. package/dist/renderers/TableRenderer.js +0 -50
  102. package/dist/renderers/TableRenderer.js.map +0 -1
  103. package/dist/renderers/makeAccordionAsyncRenderer.d.ts +0 -9
  104. package/dist/renderers/makeAccordionAsyncRenderer.d.ts.map +0 -1
  105. package/dist/renderers/makeAccordionAsyncRenderer.js +0 -35
  106. package/dist/renderers/makeAccordionAsyncRenderer.js.map +0 -1
  107. package/dist/renderers/makeAsyncRenderer.d.ts +0 -10
  108. package/dist/renderers/makeAsyncRenderer.d.ts.map +0 -1
  109. package/dist/renderers/makeAsyncRenderer.js +0 -47
  110. package/dist/renderers/makeAsyncRenderer.js.map +0 -1
  111. package/dist/store/index.d.ts +0 -72
  112. package/dist/store/index.d.ts.map +0 -1
  113. package/dist/store/index.js +0 -131
  114. package/dist/store/index.js.map +0 -1
  115. package/dist/store/selection/getInitialState.js +0 -22
  116. package/dist/store/selection/getInitialState.js.map +0 -1
  117. package/dist/store/selection/getReduxActions.js +0 -42
  118. package/dist/store/selection/getReduxActions.js.map +0 -1
  119. package/dist/store/selection/handleKey.js +0 -143
  120. package/dist/store/selection/handleKey.js.map +0 -1
  121. package/dist/store/selection/makeKeyHandler.js +0 -336
  122. package/dist/store/selection/makeKeyHandler.js.map +0 -1
  123. package/dist/store/selection/setNewFocused.js +0 -101
  124. package/dist/store/selection/setNewFocused.js.map +0 -1
  125. package/dist/store/selection/types.d.ts +0 -150
  126. package/dist/store/selection/types.d.ts.map +0 -1
  127. package/dist/store/selection/useDomProps.js +0 -181
  128. package/dist/store/selection/useDomProps.js.map +0 -1
  129. package/dist/store/types.d.ts +0 -19
  130. package/dist/store/types.d.ts.map +0 -1
  131. package/dist/types.d.ts +0 -315
  132. package/dist/types.d.ts.map +0 -1
  133. package/dist/types.js +0 -6
  134. package/dist/types.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,25 +1,3668 @@
1
- export { ResponsiveTable } from './ResponsiveTable.js';
2
- export { ResponsiveTableContext, useResponsiveTableContext } from './ResponsiveTableContext.js';
3
- export { responsiveTableActions, responsiveTableStore, useResponsiveTable } from './store/index.js';
4
- export { defaultLabels } from './types.js';
5
- export { AccordionCell } from './renderers/AccordionCell.js';
6
- export { AccordionDocNameCellRenderer } from './renderers/AccordionDocNameCellRenderer.js';
7
- export { AccordionElement } from './renderers/AccordionElement.js';
8
- export { AccordionHTMLCellRenderer } from './renderers/AccordionHTMLCellRenderer.js';
9
- export { AccordionRenderer } from './renderers/AccordionRenderer.js';
10
- export { AdditionalColumnDefaultRenderer } from './renderers/AdditionalColumnDefaultRenderer.js';
11
- export { DefaultCellRenderer } from './renderers/DefaultCellRenderer.js';
12
- export { DefaultRowRenderer } from './renderers/DefaultRowRenderer.js';
13
- export { HTMLCellRenderer } from './renderers/HTMLCellRenderer.js';
14
- export { IsLoadingRenderer } from './renderers/IsLoadingRenderer.js';
15
- export { makeAccordionAsyncRenderer } from './renderers/makeAccordionAsyncRenderer.js';
16
- export { makeAsyncRenderer } from './renderers/makeAsyncRenderer.js';
17
- export { NoRegistersRenderer } from './renderers/NoRegistersRenderer.js';
18
- export { PriorityAccordionRenderer } from './renderers/PriorityAccordionRenderer.js';
19
- export { PriorityRenderer, getPriorityHandler } from './renderers/PriorityRenderer.js';
20
- export { RowStatesRenderer } from './renderers/RowStatesRenderer.js';
21
- export { StatusAccordionRenderer } from './renderers/StatusAccordionRenderer.js';
22
- export { StatusRenderer, getStatusRendererClassName } from './renderers/StatusRenderer.js';
23
- export { TableRenderer } from './renderers/TableRenderer.js';
24
- export { DocNameCellRenderer } from './renderers/DocNameCellRenderer.js';
1
+ import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
2
+ import React, { useMemo, useState, useRef, memo, useEffect, useCallback, createRef, forwardRef } from 'react';
3
+ import { Box, getVariant, Input, useBreakpointIndex, Label, Select, Link, Spinner } from '@apia/theme';
4
+ import { useMount, useUpdateEffect, useUnmount, useThrottleFn } from 'ahooks';
5
+ import uniqueId from 'lodash-es/uniqueId';
6
+ import { createSlice, injectReducers, shallowEqual as shallowEqual$1 } from '@apia/store';
7
+ import { addBoundary, useLatest, useUpdateEffect as useUpdateEffect$1, getSpecificParent, isChild, autoDisconnectMutationObserver, getFocusSelector, cantFocusSelector, globalFocus, scrollParentIntoElement, customEvents, debugDispatcher, persistentStorage, EventEmitter, getLabel, getDateFormat, formatMessage, noNaN, downloadUrl, arrayOrArray, useMount as useMount$1 } from '@apia/util';
8
+ import { shallowEqual } from 'react-redux';
9
+ import { useOtherTagButton, AutoEllipsis, ApiaFilter, IconButton, AccordionItem, Accordion, RequiredMark, ApiaUtil, SimpleButton } from '@apia/components';
10
+ import { Icon } from '@apia/icons';
11
+ import { FaSortUp, FaSortDown, FaSort, FaSquare } from '@meronex/icons/fa';
12
+ import { MdKeyboardArrowDown, MdKeyboardArrowRight } from '@meronex/icons/md/';
13
+ import dayjs from 'dayjs';
14
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
15
+
16
+ const defaultLabels = {
17
+ noRegisters: window.FINDER_NO_DATA
18
+ };
19
+
20
+ function getInitialState$1() {
21
+ return {
22
+ allowEdition: false,
23
+ allowSelection: true,
24
+ columns: [],
25
+ expandedRows: [],
26
+ isEditionMode: false,
27
+ isFocused: false,
28
+ filters: [],
29
+ focusedColumn: 0,
30
+ focusedRow: 0,
31
+ hasNonAdditionalFilters: false,
32
+ isMultiple: true,
33
+ nonAdditionalColumnsCount: 0,
34
+ rows: [],
35
+ selectedRows: [],
36
+ statesColumns: 0
37
+ };
38
+ }
39
+
40
+ function addRowBoundary(newRow, state) {
41
+ const hasFiltersRow = !!state.filters.find(
42
+ (current) => !!state.columns.find((search) => search.name === current.column)
43
+ );
44
+ return addBoundary({
45
+ number: newRow,
46
+ min: hasFiltersRow ? -2 : -1,
47
+ max: Math.max(0, state.rows.length - 1)
48
+ });
49
+ }
50
+ function addColumnBoundary(newColumn, state) {
51
+ return addBoundary({
52
+ number: newColumn,
53
+ min: 0,
54
+ max: state.nonAdditionalColumnsCount + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0)
55
+ });
56
+ }
57
+ function isBasicRow(row) {
58
+ return typeof row === "object" && !!row && "forbidSelection" in row;
59
+ }
60
+ function filterNonSellectableRows(state, newSelection) {
61
+ let expandedRowsBefore = 0;
62
+ return newSelection.filter((selectedRowIndex) => {
63
+ const row = state.rows[selectedRowIndex + expandedRowsBefore];
64
+ if (state.expandedRows.includes(selectedRowIndex))
65
+ expandedRowsBefore += 1;
66
+ return !(isBasicRow(row) && row.forbidSelection);
67
+ });
68
+ }
69
+ function setNewFocused(state, {
70
+ /**
71
+ * Propiedad proveniente del evento click o keydown.
72
+ */
73
+ ctrlKey,
74
+ /**
75
+ * Propiedad proveniente del evento click o keydown.
76
+ */
77
+ shiftKey,
78
+ newFocusedColumn,
79
+ newFocusedRow,
80
+ /**
81
+ * Con este método se puede seleccionar cuál celda
82
+ * va a recibir el foco y la selección, o solamente
83
+ * el foco si esta propiedad es pasada en false.
84
+ */
85
+ shouldSelectNewFocused
86
+ }) {
87
+ let actualNewFocusedRow = Math.round(
88
+ addRowBoundary(newFocusedRow ?? state.focusedRow ?? 0, state) * 2
89
+ ) / 2;
90
+ const actualNewFocusedColumn = addColumnBoundary(
91
+ newFocusedColumn ?? state.focusedColumn,
92
+ state
93
+ );
94
+ state.focusedColumn = actualNewFocusedColumn;
95
+ state.focusedRow = actualNewFocusedRow;
96
+ state.isFocused = shouldSelectNewFocused ?? false;
97
+ if (shouldSelectNewFocused === false || actualNewFocusedRow < 0)
98
+ return;
99
+ if (Math.round(actualNewFocusedRow) - actualNewFocusedRow !== 0)
100
+ actualNewFocusedRow = Math.floor(actualNewFocusedRow);
101
+ const isDeselectingWithCtrl = ctrlKey && state.selectedRows.includes(actualNewFocusedRow);
102
+ if (state.allowSelection !== false) {
103
+ if (!ctrlKey && !shiftKey || state.isMultiple === false && !isDeselectingWithCtrl)
104
+ state.selectedRows = filterNonSellectableRows(state, [
105
+ actualNewFocusedRow
106
+ ]);
107
+ else if (ctrlKey && state.isMultiple || isDeselectingWithCtrl) {
108
+ state.selectedRows = filterNonSellectableRows(
109
+ state,
110
+ state.selectedRows.includes(actualNewFocusedRow) ? state.selectedRows.filter(
111
+ (current) => current !== actualNewFocusedRow
112
+ ) : [...state.selectedRows, actualNewFocusedRow]
113
+ );
114
+ } else if (shiftKey && state.isMultiple) {
115
+ const sortedSelectedRows = [...state.selectedRows].sort((a, b) => a - b);
116
+ let minSelectedRow = sortedSelectedRows[0];
117
+ let maxSelectedRow = sortedSelectedRows[sortedSelectedRows.length - 1];
118
+ if (minSelectedRow === void 0) {
119
+ state.selectedRows = filterNonSellectableRows(state, [
120
+ actualNewFocusedRow
121
+ ]);
122
+ return;
123
+ }
124
+ if (actualNewFocusedRow < minSelectedRow)
125
+ minSelectedRow = actualNewFocusedRow;
126
+ if (actualNewFocusedRow > maxSelectedRow)
127
+ maxSelectedRow = actualNewFocusedRow;
128
+ const newSelectedRows = filterNonSellectableRows(
129
+ state,
130
+ new Array(maxSelectedRow - minSelectedRow + 1).fill("").map((_, i) => i + (minSelectedRow ?? 0))
131
+ );
132
+ state.selectedRows = filterNonSellectableRows(state, newSelectedRows);
133
+ }
134
+ }
135
+ }
136
+
137
+ function willHandleKey(ev, state) {
138
+ const actualKey = ev.key.toLowerCase();
139
+ if (state.isEditionMode)
140
+ return false;
141
+ if (actualKey === " " && ev.ctrlKey)
142
+ return true;
143
+ if (actualKey === "a" && ev.ctrlKey)
144
+ return true;
145
+ if (actualKey === "m" && ev.ctrlKey)
146
+ return true;
147
+ if (state.draggingRow !== void 0) {
148
+ return ["Escape", "Enter"].includes(ev.key);
149
+ }
150
+ return [
151
+ "arrowup",
152
+ "arrowdown",
153
+ "arrowleft",
154
+ "arrowright",
155
+ "end",
156
+ "enter",
157
+ "home",
158
+ "pageup",
159
+ "pagedown"
160
+ ].includes(ev.key.toLowerCase());
161
+ }
162
+ function handleKey(state, { ev }) {
163
+ const {
164
+ altKey: isAltPressed,
165
+ ctrlKey: isCtrlPressed,
166
+ key,
167
+ shiftKey: isShiftPressed
168
+ } = ev;
169
+ if (willHandleKey(ev, state))
170
+ ev.preventDefault();
171
+ const actualKey = key.toLowerCase();
172
+ const setFocus = ({
173
+ newFocusedColumn,
174
+ newFocusedRow,
175
+ ...rest
176
+ }) => setNewFocused(state, {
177
+ altKey: isAltPressed,
178
+ ctrlKey: isCtrlPressed,
179
+ shiftKey: isShiftPressed,
180
+ newFocusedColumn,
181
+ newFocusedRow,
182
+ ...rest
183
+ });
184
+ if (!state.isEditionMode) {
185
+ if (actualKey === "enter" && (state.allowEdition === true || state.focusedRow < 0))
186
+ state.isEditionMode = true;
187
+ else
188
+ switch (actualKey) {
189
+ case "arrowup": {
190
+ let sumRate = state.expandedRows.includes(state.focusedRow - 1) ? 0.6 : 1;
191
+ if (Math.round(state.focusedRow) - state.focusedRow !== 0)
192
+ sumRate = 0.5;
193
+ setFocus({
194
+ newFocusedRow: state.focusedRow - sumRate,
195
+ shouldSelectNewFocused: !isCtrlPressed
196
+ });
197
+ break;
198
+ }
199
+ case "arrowdown": {
200
+ let sumRate = state.expandedRows.includes(state.focusedRow) ? 0.6 : 1;
201
+ if (Math.round(state.focusedRow) - state.focusedRow !== 0)
202
+ sumRate = 0.5;
203
+ setFocus({
204
+ newFocusedRow: state.focusedRow + sumRate,
205
+ shouldSelectNewFocused: !isCtrlPressed
206
+ });
207
+ break;
208
+ }
209
+ case "arrowleft":
210
+ case "arrowright": {
211
+ setFocus({
212
+ newFocusedColumn: state.focusedColumn + (actualKey === "arrowleft" ? -1 : 1),
213
+ shouldSelectNewFocused: !isCtrlPressed
214
+ });
215
+ break;
216
+ }
217
+ case "home": {
218
+ if (isCtrlPressed)
219
+ setFocus({ newFocusedColumn: 0, newFocusedRow: 0, ctrlKey: false });
220
+ else
221
+ setFocus({ newFocusedColumn: 0 });
222
+ break;
223
+ }
224
+ case "end": {
225
+ if (isCtrlPressed)
226
+ setFocus({
227
+ newFocusedRow: Number.POSITIVE_INFINITY,
228
+ newFocusedColumn: Number.POSITIVE_INFINITY,
229
+ ctrlKey: false
230
+ });
231
+ else
232
+ setFocus({
233
+ newFocusedColumn: Number.POSITIVE_INFINITY
234
+ });
235
+ break;
236
+ }
237
+ case "pageup": {
238
+ setFocus({
239
+ newFocusedRow: state.focusedRow - 5,
240
+ shouldSelectNewFocused: !isCtrlPressed
241
+ });
242
+ break;
243
+ }
244
+ case "pagedown": {
245
+ setFocus({
246
+ newFocusedRow: state.focusedRow + 5,
247
+ shouldSelectNewFocused: !isCtrlPressed
248
+ });
249
+ break;
250
+ }
251
+ case " ": {
252
+ if (isCtrlPressed)
253
+ setFocus({
254
+ newFocusedRow: state.focusedRow
255
+ });
256
+ break;
257
+ }
258
+ case "a": {
259
+ if (isCtrlPressed && state.allowSelection)
260
+ state.selectedRows = state.rows.map((_, i) => i);
261
+ break;
262
+ }
263
+ }
264
+ } else
265
+ switch (actualKey) {
266
+ case "escape":
267
+ case "enter": {
268
+ if (state.isEditionMode)
269
+ state.isEditionMode = false;
270
+ ev.stopPropagation();
271
+ break;
272
+ }
273
+ }
274
+ }
275
+
276
+ function getReduxActions() {
277
+ return {
278
+ handleKey(state, { payload }) {
279
+ handleKey(state[payload.id], payload);
280
+ },
281
+ selectionStateUpdate(state, { payload: { id, ...payload } }) {
282
+ state[id] = { ...state[id], ...payload };
283
+ },
284
+ setNewFocused(state, { payload: { id, ...payload } }) {
285
+ setNewFocused(state[id], payload);
286
+ },
287
+ updateByClick(state, {
288
+ payload: {
289
+ id,
290
+ colIndex,
291
+ rowIndex,
292
+ ariaColIndex,
293
+ ariaRowIndex,
294
+ isFocused,
295
+ ...payload
296
+ }
297
+ }) {
298
+ const hasFiltersRow = state[id].hasNonAdditionalFilters;
299
+ state[id].isEditionMode = false;
300
+ const newFocusedColumn = colIndex ?? ariaColIndex ?? 1;
301
+ const newFocusedRow = ariaRowIndex !== void 0 ? ariaRowIndex : (rowIndex ?? 0) - (1 + (hasFiltersRow ? 2 : 1));
302
+ setNewFocused(state[id], {
303
+ ...payload,
304
+ newFocusedColumn,
305
+ newFocusedRow
306
+ });
307
+ if (isFocused !== void 0)
308
+ state[id].isFocused = isFocused;
309
+ }
310
+ };
311
+ }
312
+
313
+ function getController2ReduxActions() {
314
+ return {
315
+ controller2UpdateSelectionState(state, {
316
+ payload: { tableName, ...payload }
317
+ }) {
318
+ Object.assign(state[tableName], payload);
319
+ }
320
+ };
321
+ }
322
+
323
+ function getInitialState() {
324
+ const newState = {
325
+ ...getInitialState$1(),
326
+ allowSelection: true,
327
+ allowSorting: true,
328
+ filters: [],
329
+ isLoading: false,
330
+ isMultiple: true,
331
+ accordionIndexColumns: {},
332
+ expandedRows: []
333
+ };
334
+ return newState;
335
+ }
336
+ const responsiveTableSlice = createSlice({
337
+ name: "responsiveTableSlice",
338
+ initialState: {},
339
+ reducers: {
340
+ update(state, {
341
+ payload: { tableName, handleFocus, ...rest }
342
+ }) {
343
+ if (!state[tableName])
344
+ state[tableName] = getInitialState();
345
+ state[tableName] = { ...state[tableName], ...rest };
346
+ if (handleFocus !== false) {
347
+ setNewFocused(state[tableName], {
348
+ altKey: false,
349
+ ctrlKey: false,
350
+ shiftKey: false,
351
+ shouldSelectNewFocused: rest.isFocused ?? state[tableName].isFocused
352
+ });
353
+ }
354
+ if (rest.columns) {
355
+ state[tableName].nonAdditionalColumnsCount = rest.columns.filter(
356
+ (current) => !current.showAsAdditional
357
+ ).length;
358
+ }
359
+ if (rest.rows) {
360
+ state[tableName].statesColumns = Math.max(
361
+ state[tableName]?.reserveColumnsForStates ?? 0,
362
+ ...state[tableName]?.rows?.map(
363
+ (current) => current.states?.length ?? 0
364
+ ) ?? [0]
365
+ );
366
+ }
367
+ if (rest.filters) {
368
+ state[tableName].hasNonAdditionalFilters = rest.filters.filter(
369
+ (current) => !current.asAdditional && (rest.columns ?? state[tableName].columns)?.find(
370
+ (search) => search.name === current.column
371
+ )
372
+ ).length > 0;
373
+ }
374
+ },
375
+ addRows(state, { payload }) {
376
+ if (!state[payload.tableName])
377
+ state[payload.tableName] = getInitialState();
378
+ state[payload.tableName].rows = state[payload.tableName].rows.concat(
379
+ ...payload.newRows
380
+ );
381
+ setNewFocused(state[payload.tableName], {
382
+ altKey: false,
383
+ ctrlKey: false,
384
+ shiftKey: false,
385
+ shouldSelectNewFocused: true,
386
+ newFocusedRow: state[payload.tableName].rows.length
387
+ });
388
+ },
389
+ deleteRows(state, { payload }) {
390
+ const table = state[payload.tableName];
391
+ const minIndex = payload.rowIndices.reduce((min, current) => {
392
+ return current < min ? current : min;
393
+ }, Infinity);
394
+ table.rows = table.rows.filter(
395
+ (_, index) => !payload.rowIndices.includes(index)
396
+ );
397
+ setNewFocused(state[payload.tableName], {
398
+ altKey: false,
399
+ ctrlKey: false,
400
+ shiftKey: false,
401
+ shouldSelectNewFocused: true,
402
+ newFocusedRow: minIndex
403
+ });
404
+ state[payload.tableName].isFocused = false;
405
+ },
406
+ destroy(state, { payload: { tableName } }) {
407
+ delete state[tableName];
408
+ },
409
+ swapFocusedRow(state, {
410
+ payload: { newIndex, tableName }
411
+ }) {
412
+ const tableState = state[tableName];
413
+ const focusedIndex = tableState.focusedRow;
414
+ if (focusedIndex === void 0 || newIndex < 0 || newIndex >= tableState.rows.length)
415
+ return;
416
+ if (focusedIndex === newIndex) {
417
+ if (tableState.draggingRow === newIndex)
418
+ tableState.draggingRow = void 0;
419
+ else
420
+ tableState.draggingRow = newIndex;
421
+ return;
422
+ }
423
+ const isSelected = tableState.selectedRows.includes(focusedIndex);
424
+ if (isSelected) {
425
+ tableState.selectedRows = [
426
+ ...tableState.selectedRows.filter(
427
+ (current) => current !== focusedIndex
428
+ ),
429
+ newIndex
430
+ ];
431
+ }
432
+ const aux = tableState.rows[newIndex];
433
+ tableState.rows[newIndex] = tableState.rows[focusedIndex];
434
+ tableState.rows[focusedIndex] = aux;
435
+ tableState.focusedRow = newIndex;
436
+ tableState.draggingRow = newIndex;
437
+ },
438
+ // Rows selection
439
+ ...getReduxActions(),
440
+ ...getController2ReduxActions()
441
+ }
442
+ });
443
+ const { store: responsiveTableStore, useSelector } = injectReducers({
444
+ responsiveTableSlice: responsiveTableSlice.reducer
445
+ });
446
+ const useResponsiveTable = useSelector;
447
+ const responsiveTableActions = responsiveTableSlice.actions;
448
+
449
+ const ResponsiveTableReactContext = React.createContext({});
450
+ const tableContexts = {};
451
+ function useResponsiveTableContext(tableName) {
452
+ const reactContext = React.useContext(ResponsiveTableReactContext);
453
+ const context = tableName ? tableContexts[tableName] : reactContext;
454
+ if (!context)
455
+ throw new Error("There is no ResponsiveTableContext");
456
+ return context;
457
+ }
458
+ const NoMemoResponsiveTableContext = ({
459
+ allowEdition,
460
+ allowRowsKeyboardSorting,
461
+ allowSelection,
462
+ allowSorting,
463
+ avoidReparseSelectionOnRowChange,
464
+ children = /* @__PURE__ */ jsx(ResponsiveTable, {}),
465
+ className,
466
+ currentBreakPoint,
467
+ customLabels,
468
+ columns,
469
+ filters,
470
+ rows,
471
+ label,
472
+ isMultiple,
473
+ name,
474
+ onChangeSelection,
475
+ onFilterBlur,
476
+ onFilterChange,
477
+ onFilterPressEnter,
478
+ onSelectRows,
479
+ onSortChange,
480
+ reserveColumnsForStates,
481
+ SelectionHandler,
482
+ variant
483
+ }) => {
484
+ const actualName = React.useMemo(
485
+ () => name ?? uniqueId("responsiveTable"),
486
+ [name]
487
+ );
488
+ const labels = React.useMemo(
489
+ () => ({ ...defaultLabels, ...customLabels }),
490
+ [customLabels]
491
+ );
492
+ const contextValue = React.useMemo(
493
+ () => ({
494
+ currentBreakPoint,
495
+ label,
496
+ labels,
497
+ name: actualName,
498
+ onChangeSelection,
499
+ onFilterBlur,
500
+ onFilterChange,
501
+ onFilterPressEnter,
502
+ onSelectRows,
503
+ onSortChange,
504
+ SelectionHandler
505
+ }),
506
+ [
507
+ actualName,
508
+ currentBreakPoint,
509
+ label,
510
+ labels,
511
+ onChangeSelection,
512
+ onFilterBlur,
513
+ onFilterChange,
514
+ onFilterPressEnter,
515
+ onSelectRows,
516
+ onSortChange,
517
+ SelectionHandler
518
+ ]
519
+ );
520
+ tableContexts[actualName] = contextValue;
521
+ useMount(() => {
522
+ responsiveTableStore.dispatch(
523
+ responsiveTableActions.update({
524
+ allowEdition,
525
+ allowRowsKeyboardSorting,
526
+ allowSelection,
527
+ allowSorting,
528
+ columns,
529
+ filters: filters ?? [],
530
+ rows,
531
+ isMultiple,
532
+ tableName: actualName,
533
+ reserveColumnsForStates,
534
+ handleFocus: !SelectionHandler
535
+ })
536
+ );
537
+ });
538
+ useUpdateEffect(() => {
539
+ responsiveTableStore.dispatch(
540
+ responsiveTableActions.update({
541
+ tableName: actualName,
542
+ columns,
543
+ handleFocus: !SelectionHandler
544
+ })
545
+ );
546
+ }, [columns]);
547
+ useUpdateEffect(() => {
548
+ responsiveTableStore.dispatch(
549
+ responsiveTableActions.update({
550
+ tableName: actualName,
551
+ rows,
552
+ handleFocus: !SelectionHandler
553
+ })
554
+ );
555
+ if (!SelectionHandler && avoidReparseSelectionOnRowChange !== true) {
556
+ const selected = rows.map((current, i) => ({ ...current, i })).filter((current) => current.initiallySelected);
557
+ responsiveTableStore.dispatch(
558
+ responsiveTableActions.update({
559
+ tableName: actualName,
560
+ selectedRows: selected.map((current) => current.i)
561
+ })
562
+ );
563
+ }
564
+ }, [rows]);
565
+ useUpdateEffect(() => {
566
+ responsiveTableStore.dispatch(
567
+ responsiveTableActions.update({
568
+ tableName: actualName,
569
+ filters,
570
+ handleFocus: !SelectionHandler
571
+ })
572
+ );
573
+ }, [filters]);
574
+ useUnmount(() => {
575
+ responsiveTableStore.dispatch(
576
+ responsiveTableActions.destroy({ tableName: actualName })
577
+ );
578
+ });
579
+ return /* @__PURE__ */ jsx(ResponsiveTableReactContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
580
+ Box,
581
+ {
582
+ id: name,
583
+ className: `responsiveTableContext__wrapper ${className ?? ""}`,
584
+ ...variant ? getVariant(variant) : null,
585
+ children
586
+ }
587
+ ) });
588
+ };
589
+ const ResponsiveTableContext = React.memo(NoMemoResponsiveTableContext);
590
+
591
+ let scrollTimeout;
592
+ function makeKeyHandler(actions, id, config) {
593
+ return function KeyHandler({
594
+ children,
595
+ onChangeSelection,
596
+ onSelectRows,
597
+ ...props
598
+ }) {
599
+ const { run: keyHandler } = useThrottleFn(
600
+ (ev) => {
601
+ if (!["shift", "alt", "control"].includes(ev.key.toLowerCase())) {
602
+ responsiveTableStore.dispatch(actions.handleKey({ id, ev }));
603
+ }
604
+ },
605
+ config?.throttleOptions ?? { wait: 100 }
606
+ );
607
+ const [ref, setRef] = React.useState(null);
608
+ const selectedRows = useResponsiveTable(
609
+ (global) => {
610
+ const state = config.stateSelector(global);
611
+ return (state?.selectedRows ?? []).map((current) => ({
612
+ index: current,
613
+ row: state.rows[current]
614
+ }));
615
+ },
616
+ (a, b) => shallowEqual(
617
+ a.map((current) => current.index),
618
+ b.map((current) => current.index)
619
+ )
620
+ );
621
+ const selectedRowsRef = useLatest(selectedRows);
622
+ const { allowKeyboardSorting, focusedCell, isEditionMode, isFocused } = useResponsiveTable((global) => {
623
+ const state = config.stateSelector(global);
624
+ return {
625
+ focusedCell: state?.focusedRow !== void 0 ? `${state?.focusedRow}_${state?.focusedColumn}` : void 0,
626
+ isEditionMode: state?.isEditionMode,
627
+ rows: state?.rows,
628
+ isFocused: state?.isFocused,
629
+ allowKeyboardSorting: state?.allowRowsKeyboardSorting
630
+ };
631
+ }, shallowEqual);
632
+ useUpdateEffect$1(() => {
633
+ if (onChangeSelection)
634
+ onChangeSelection(selectedRows);
635
+ }, [onChangeSelection, selectedRows]);
636
+ const handleClick = React.useCallback(
637
+ (ev) => {
638
+ if (ev.target.closest(".moreInformationButton"))
639
+ return;
640
+ if (ev.shiftKey) {
641
+ document.getSelection()?.removeAllRanges();
642
+ }
643
+ const parentRow = getSpecificParent(
644
+ ev.target,
645
+ (current) => {
646
+ if (current.tagName.toLowerCase() === "table")
647
+ return null;
648
+ if (current.matches("tr")) {
649
+ return true;
650
+ }
651
+ return false;
652
+ }
653
+ );
654
+ const parentCell = getSpecificParent(
655
+ ev.target,
656
+ (current) => {
657
+ if (current.tagName.toLowerCase() === "table")
658
+ return null;
659
+ if (current.matches("td,th")) {
660
+ return true;
661
+ }
662
+ return false;
663
+ }
664
+ );
665
+ if (parentCell && parentRow) {
666
+ responsiveTableStore.dispatch(
667
+ actions.updateByClick({
668
+ altKey: ev.altKey,
669
+ id,
670
+ ctrlKey: ev.ctrlKey,
671
+ ariaColIndex: Number(parentCell.getAttribute("aria-colindex")),
672
+ rowIndex: Number(parentRow.getAttribute("data-focusindex")),
673
+ shiftKey: ev.shiftKey
674
+ })
675
+ );
676
+ }
677
+ },
678
+ []
679
+ );
680
+ const handleDoubleClick = React.useCallback(
681
+ (ev) => {
682
+ if (isChild(
683
+ ev.target,
684
+ (current) => current.tagName === "THEAD"
685
+ ))
686
+ return;
687
+ ev.preventDefault();
688
+ if (onSelectRows)
689
+ onSelectRows(
690
+ selectedRowsRef.current,
691
+ config.stateSelector(responsiveTableStore.getState()).focusedRow
692
+ );
693
+ },
694
+ [onSelectRows, selectedRowsRef]
695
+ );
696
+ const initialized = React.useRef(true);
697
+ const running = React.useRef(false);
698
+ const doFocusThings = React.useCallback(() => {
699
+ if (!running.current) {
700
+ running.current = true;
701
+ if (focusedCell === void 0) {
702
+ running.current = false;
703
+ return () => {
704
+ };
705
+ }
706
+ if (ref) {
707
+ const disconnectObserver = autoDisconnectMutationObserver(
708
+ ref,
709
+ () => {
710
+ scrollTimeout = setTimeout(() => {
711
+ const focusedElement = ref.querySelector(
712
+ '[data-focused="true"]'
713
+ );
714
+ let tableCellElement = null;
715
+ let tableCellWidget = null;
716
+ if (["td", "th"].includes(
717
+ focusedElement?.tagName.toLowerCase() ?? ""
718
+ )) {
719
+ tableCellElement = focusedElement;
720
+ tableCellWidget = focusedElement?.querySelector(
721
+ getFocusSelector(":not(.debug_info__button)")
722
+ );
723
+ }
724
+ if (focusedElement?.tagName.toLowerCase() === "tr") {
725
+ tableCellElement = focusedElement.querySelector("td,th");
726
+ tableCellWidget = focusedElement.querySelector(
727
+ getFocusSelector(":not(.debug_info__button)")
728
+ ) || tableCellElement;
729
+ }
730
+ if (tableCellWidget) {
731
+ tableCellElement?.setAttribute("tabIndex", "-1");
732
+ tableCellWidget.setAttribute("tabIndex", "0");
733
+ } else
734
+ tableCellElement?.setAttribute("tabIndex", "0");
735
+ if (!isEditionMode) {
736
+ const allFocusableElements = ref?.querySelectorAll(
737
+ getFocusSelector(
738
+ `${cantFocusSelector}:not([data-focused="true"])`
739
+ )
740
+ );
741
+ allFocusableElements?.forEach((current) => {
742
+ if (current !== tableCellWidget) {
743
+ current.setAttribute("tabIndex", "-1");
744
+ }
745
+ if (tableCellWidget?.tagName === "BUTTON")
746
+ tableCellWidget.setAttribute("role", "gridcell");
747
+ });
748
+ } else {
749
+ const focusableElements = tableCellElement?.querySelectorAll('[tabindex="-1"]');
750
+ focusableElements?.forEach(
751
+ (current) => current.setAttribute("tabIndex", "0")
752
+ );
753
+ }
754
+ const focusElement = tableCellWidget ?? tableCellElement;
755
+ const row = getSpecificParent(
756
+ focusElement,
757
+ (current) => current.tagName === "TR"
758
+ );
759
+ if (focusElement && initialized.current && config.stateSelector(responsiveTableStore.getState()).isFocused) {
760
+ globalFocus.focus = focusElement;
761
+ focusElement.focus();
762
+ }
763
+ if (row) {
764
+ scrollParentIntoElement(row, 55, 2, 100, "makeKeyHandler");
765
+ }
766
+ if (!initialized.current) {
767
+ initialized.current = true;
768
+ }
769
+ }, 0);
770
+ },
771
+ { timeout: 5e3 }
772
+ );
773
+ running.current = false;
774
+ return () => {
775
+ disconnectObserver();
776
+ clearTimeout(scrollTimeout);
777
+ };
778
+ }
779
+ running.current = false;
780
+ }
781
+ return () => {
782
+ };
783
+ }, [focusedCell, ref, isEditionMode]);
784
+ React.useLayoutEffect(doFocusThings, [
785
+ focusedCell,
786
+ isFocused,
787
+ isEditionMode
788
+ ]);
789
+ React.useEffect(() => {
790
+ function handleFocus(ev) {
791
+ const targetTable = getSpecificParent(
792
+ ev.target,
793
+ (current) => current.tagName.toLowerCase() === "table"
794
+ );
795
+ const relatedTargetTable = getSpecificParent(
796
+ ev.relatedTarget,
797
+ (current) => current.tagName.toLowerCase() === "table"
798
+ );
799
+ if (!relatedTargetTable || relatedTargetTable !== targetTable)
800
+ handleClick(ev);
801
+ }
802
+ ref?.addEventListener("dblclick", handleDoubleClick);
803
+ ref?.addEventListener("mousedown", handleClick);
804
+ ref?.addEventListener("focusin", handleFocus);
805
+ ref?.addEventListener(customEvents.focus, handleClick);
806
+ return () => {
807
+ ref?.removeEventListener("mousedown", handleClick);
808
+ ref?.removeEventListener("dblclick", handleDoubleClick);
809
+ ref?.removeEventListener("focusin", handleFocus);
810
+ ref?.removeEventListener(customEvents.focus, handleClick);
811
+ };
812
+ }, [ref]);
813
+ const isDragging = React.useRef(false);
814
+ const isFocusedRef = React.useRef(false);
815
+ return /* @__PURE__ */ jsx(
816
+ Box,
817
+ {
818
+ ref: setRef,
819
+ ...props,
820
+ className: `selection__keyHandler ${props.className ?? ""}`,
821
+ onBlur: React.useCallback(
822
+ (ev) => {
823
+ if (!ev.relatedTarget || !getSpecificParent(
824
+ ev.relatedTarget,
825
+ (current) => current === ref
826
+ )) {
827
+ responsiveTableStore.dispatch(
828
+ actions.selectionStateUpdate({ id, isFocused: false })
829
+ );
830
+ isFocusedRef.current = false;
831
+ }
832
+ },
833
+ [ref]
834
+ ),
835
+ onFocus: React.useCallback(() => {
836
+ isFocusedRef.current = true;
837
+ }, []),
838
+ sx: React.useMemo(
839
+ () => ({ overflow: "auto", position: "relative" }),
840
+ []
841
+ ),
842
+ onKeyDown: React.useCallback(
843
+ (ev) => {
844
+ const state = config.stateSelector(responsiveTableStore.getState());
845
+ if (willHandleKey(
846
+ ev,
847
+ config.stateSelector(responsiveTableStore.getState())
848
+ )) {
849
+ ev.preventDefault();
850
+ ev.stopPropagation();
851
+ }
852
+ if (actions.swapFocusedRow && isDragging.current && allowKeyboardSorting) {
853
+ if ((ev.key === "Enter" || ev.key === "Escape") && isDragging.current) {
854
+ isDragging.current = false;
855
+ responsiveTableStore.dispatch(
856
+ actions.swapFocusedRow({
857
+ tableName: id,
858
+ newIndex: state.focusedRow
859
+ })
860
+ );
861
+ } else if (["ArrowDown", "ArrowUp"].includes(ev.key)) {
862
+ if (ev.key === "ArrowDown") {
863
+ responsiveTableStore.dispatch(
864
+ actions.swapFocusedRow({
865
+ tableName: id,
866
+ newIndex: state.focusedRow + 1
867
+ })
868
+ );
869
+ } else {
870
+ responsiveTableStore.dispatch(
871
+ actions.swapFocusedRow({
872
+ tableName: id,
873
+ newIndex: state.focusedRow - 1
874
+ })
875
+ );
876
+ }
877
+ }
878
+ } else if (ev.key === "m" && ev.ctrlKey && !isDragging.current && state.focusedRow >= 0 && actions.swapFocusedRow) {
879
+ isDragging.current = true;
880
+ responsiveTableStore.dispatch(
881
+ actions.swapFocusedRow({
882
+ tableName: id,
883
+ newIndex: state.focusedRow
884
+ })
885
+ );
886
+ } else {
887
+ const currentSelectedRows = (state?.selectedRows ?? []).map((current) => ({
888
+ index: current,
889
+ row: state.rows[current]
890
+ }));
891
+ if (props.onKeyDown)
892
+ props.onKeyDown(ev);
893
+ if (ev.key === "Enter" && onSelectRows && state.focusedRow >= 0) {
894
+ onSelectRows(currentSelectedRows, state.focusedRow);
895
+ }
896
+ keyHandler(ev);
897
+ }
898
+ },
899
+ [allowKeyboardSorting, keyHandler, onSelectRows, props]
900
+ ),
901
+ children
902
+ }
903
+ );
904
+ };
905
+ }
906
+
907
+ const NoMemoKeyHandler = (props) => {
908
+ const { name, onChangeSelection, onSelectRows, SelectionHandler } = useResponsiveTableContext();
909
+ const Handler = React.useMemo(
910
+ () => SelectionHandler || makeKeyHandler(responsiveTableActions, name, {
911
+ throttleOptions: { wait: 50 },
912
+ stateSelector: (global) => global.responsiveTableSlice[name]
913
+ }),
914
+ [SelectionHandler, name]
915
+ );
916
+ return /* @__PURE__ */ jsx(
917
+ Handler,
918
+ {
919
+ onChangeSelection,
920
+ onSelectRows,
921
+ ...props
922
+ }
923
+ );
924
+ };
925
+ const KeyHandler = React.memo(NoMemoKeyHandler);
926
+
927
+ function getDomStoreProps(element, elementProps, stateSelector) {
928
+ const globalState = responsiveTableStore.getState();
929
+ const tableState = stateSelector(globalState);
930
+ const hasNonAdditionalFilters = tableState?.hasNonAdditionalFilters;
931
+ const startDataRowIndex = hasNonAdditionalFilters ? 2 : 1;
932
+ const statesColumns = tableState?.statesColumns ?? 0;
933
+ let expandedBeforeThisRow = 0;
934
+ if (element === "tr")
935
+ expandedBeforeThisRow = tableState?.expandedRows.filter(
936
+ (current) => current < elementProps.rowIndex
937
+ ).length;
938
+ let isFocused = false;
939
+ let isSelected = false;
940
+ switch (element) {
941
+ case "filterTd": {
942
+ const castedProps = elementProps;
943
+ isFocused = tableState?.focusedRow === 1 - startDataRowIndex && addBoundary(tableState?.focusedColumn ?? 0, 0) - statesColumns === castedProps.columnIndex + 1 + (hasNonAdditionalFilters ? 1 : 0);
944
+ break;
945
+ }
946
+ case "tr": {
947
+ const castedProps = elementProps;
948
+ isFocused = !tableState ? false : tableState.focusedRow === castedProps.rowIndex && tableState?.focusedColumn === 0 || Math.floor(tableState?.focusedRow) === castedProps.rowIndex && Math.round(tableState?.focusedRow) - tableState.focusedRow !== 0 && !!castedProps.isTheExpandedRow;
949
+ isSelected = !castedProps.isTheExpandedRow && tableState?.selectedRows.includes(castedProps.rowIndex);
950
+ break;
951
+ }
952
+ case "headerTr": {
953
+ isFocused = !tableState ? false : tableState.focusedRow === 0 && tableState?.focusedColumn === 0;
954
+ isSelected = false;
955
+ break;
956
+ }
957
+ case "stateCell": {
958
+ const castedProps = elementProps;
959
+ isFocused = tableState?.focusedRow === castedProps.rowIndex && (tableState?.focusedColumn ?? 0) === castedProps.columnIndex + 1 + (hasNonAdditionalFilters ? 1 : 0);
960
+ break;
961
+ }
962
+ case "additionalTd": {
963
+ const castedProps = elementProps;
964
+ isFocused = tableState?.focusedRow === castedProps.rowIndex && (tableState?.focusedColumn ?? 0) === 1;
965
+ break;
966
+ }
967
+ case "td": {
968
+ const castedProps = elementProps;
969
+ isFocused = tableState?.focusedRow === castedProps.rowIndex && (tableState?.focusedColumn ?? 0) - statesColumns === castedProps.columnIndex + 1 + (hasNonAdditionalFilters ? 1 : 0);
970
+ break;
971
+ }
972
+ case "headerStateCell": {
973
+ const castedProps = elementProps;
974
+ isFocused = tableState?.focusedRow === castedProps.rowIndex - 1 - startDataRowIndex && addBoundary(tableState?.focusedColumn, 0) === castedProps.columnIndex + 1 + (hasNonAdditionalFilters ? 1 : 0);
975
+ break;
976
+ }
977
+ case "th": {
978
+ const castedProps = elementProps;
979
+ isFocused = tableState?.focusedRow === 0 - startDataRowIndex && addBoundary((tableState?.focusedColumn ?? 0) - statesColumns, 0) === castedProps.columnIndex + 1 + (hasNonAdditionalFilters ? 1 : 0);
980
+ break;
981
+ }
982
+ case "separator": {
983
+ const castedProps = elementProps;
984
+ isFocused = !tableState ? false : tableState.focusedRow === castedProps.rowIndex;
985
+ break;
986
+ }
987
+ }
988
+ return {
989
+ columns: tableState?.columns ?? [],
990
+ expandedBeforeThisRow,
991
+ isEditionMode: tableState?.isEditionMode,
992
+ hasNonAdditionalFilters,
993
+ rowsLength: element === "table" ? tableState?.rows.length : "",
994
+ isSelected,
995
+ isFocused,
996
+ startDataRowIndex,
997
+ statesColumns: tableState?.statesColumns
998
+ };
999
+ }
1000
+ function getDomProps(state, element, elementProps) {
1001
+ let returnObject = {};
1002
+ switch (element) {
1003
+ case "filterTd": {
1004
+ const castedProps = elementProps;
1005
+ returnObject = {
1006
+ "aria-colindex": castedProps.columnIndex + 1 + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0),
1007
+ "data-editionmode": state.isEditionMode && state.isFocused,
1008
+ "data-focused": state.isFocused,
1009
+ tabIndex: state.isFocused ? 0 : -1,
1010
+ "data-rowindex": 2
1011
+ };
1012
+ break;
1013
+ }
1014
+ case "separator": {
1015
+ const castedProps = elementProps;
1016
+ returnObject = {
1017
+ "aria-rowindex": castedProps.rowIndex + state.startDataRowIndex + 1 + state.expandedBeforeThisRow,
1018
+ "data-focusindex": castedProps.rowIndex + state.startDataRowIndex + 1,
1019
+ "aria-selected": state.isSelected,
1020
+ "data-focused": state.isFocused,
1021
+ "aria-expanded": false
1022
+ };
1023
+ break;
1024
+ }
1025
+ case "table": {
1026
+ returnObject = {
1027
+ role: "treegrid",
1028
+ "aria-colcount": state.columns.length,
1029
+ "aria-rowcount": state.rowsLength
1030
+ };
1031
+ break;
1032
+ }
1033
+ case "tr": {
1034
+ const castedProps = elementProps;
1035
+ returnObject = {
1036
+ "aria-rowindex": castedProps.rowIndex + state.startDataRowIndex + 1 + state.expandedBeforeThisRow + (castedProps.isTheExpandedRow ? 1 : 0),
1037
+ "data-focusindex": castedProps.rowIndex + state.startDataRowIndex + 1 + (castedProps.isTheExpandedRow ? 0.5 : 0),
1038
+ "data-rowindex": castedProps.rowIndex,
1039
+ "aria-selected": state.isSelected,
1040
+ "data-focused": state.isFocused,
1041
+ "aria-expanded": castedProps.isThisRowExpanded,
1042
+ tabIndex: state.isFocused ? 0 : -1
1043
+ };
1044
+ break;
1045
+ }
1046
+ case "headerTr": {
1047
+ returnObject = {
1048
+ "aria-rowindex": 1,
1049
+ "data-focusindex": 1,
1050
+ "data-rowindex": state.hasNonAdditionalFilters ? -2 : -1,
1051
+ "aria-selected": false,
1052
+ "data-focused": state.isFocused,
1053
+ "aria-expanded": false
1054
+ };
1055
+ break;
1056
+ }
1057
+ case "td": {
1058
+ const castedProps = elementProps;
1059
+ returnObject = {
1060
+ "aria-colindex": castedProps.columnIndex + 1 + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0),
1061
+ "data-editionmode": state.isEditionMode && state.isFocused,
1062
+ "data-focused": state.isFocused,
1063
+ tabIndex: state.isFocused ? 0 : -1,
1064
+ "data-rowindex": castedProps.rowIndex + state.startDataRowIndex + 1
1065
+ };
1066
+ break;
1067
+ }
1068
+ case "additionalTd": {
1069
+ const castedProps = elementProps;
1070
+ returnObject = {
1071
+ "aria-colindex": 1,
1072
+ "data-editionmode": state.isEditionMode && state.isFocused,
1073
+ "data-focused": state.isFocused,
1074
+ tabIndex: state.isFocused ? 0 : -1,
1075
+ "data-rowindex": castedProps.rowIndex + state.startDataRowIndex + 1
1076
+ };
1077
+ break;
1078
+ }
1079
+ case "stateCell": {
1080
+ const castedProps = elementProps;
1081
+ returnObject = {
1082
+ "aria-colindex": castedProps.columnIndex + 1 + (state.hasNonAdditionalFilters ? 1 : 0),
1083
+ "data-editionmode": state.isEditionMode && state.isFocused,
1084
+ "data-focused": state.isFocused,
1085
+ tabIndex: state.isFocused ? 0 : -1,
1086
+ "data-rowindex": castedProps.rowIndex + state.startDataRowIndex + 1
1087
+ };
1088
+ break;
1089
+ }
1090
+ case "headerStateCell": {
1091
+ const castedProps = elementProps;
1092
+ returnObject = {
1093
+ "aria-colindex": castedProps.columnIndex + 1 + (state.hasNonAdditionalFilters ? 1 : 0),
1094
+ "data-editionmode": state.isEditionMode && state.isFocused,
1095
+ "data-focused": state.isFocused,
1096
+ tabIndex: state.isFocused ? 0 : -1,
1097
+ "data-rowindex": castedProps.rowIndex
1098
+ };
1099
+ break;
1100
+ }
1101
+ case "th": {
1102
+ const castedProps = elementProps;
1103
+ returnObject = {
1104
+ "aria-colindex": castedProps.columnIndex + 1 + state.statesColumns + (state.hasNonAdditionalFilters ? 1 : 0),
1105
+ "aria-sort": ["ascending", "descending", void 0][["Asc", "Desc", null].findIndex(
1106
+ (current) => current === state.columns[castedProps.columnIndex].currentSorting
1107
+ )],
1108
+ "data-editionmode": state.isEditionMode && state.isFocused,
1109
+ "data-focused": state.isFocused,
1110
+ tabIndex: state.isFocused ? 0 : -1,
1111
+ "data-rowindex": 1
1112
+ };
1113
+ break;
1114
+ }
1115
+ }
1116
+ return returnObject;
1117
+ }
1118
+ function useDomProps(element, elementProps, stateSelector) {
1119
+ const state = useResponsiveTable(() => {
1120
+ return getDomStoreProps(element, elementProps, stateSelector);
1121
+ }, shallowEqual);
1122
+ return useMemo(() => {
1123
+ return getDomProps(state, element, elementProps);
1124
+ }, [element, elementProps, state]);
1125
+ }
1126
+
1127
+ const widthStorageName = "tablesWidths";
1128
+ function getColumnWidth(width) {
1129
+ if (typeof width === "string") {
1130
+ if (width.match(/(%|px|vw|vh|vmin|vmax|cm|mm|in|pt|pc)/))
1131
+ return width;
1132
+ if (width === "")
1133
+ return "auto";
1134
+ const numberValue = Number.parseInt(width, 10);
1135
+ if (isNaN(numberValue))
1136
+ return "auto";
1137
+ return numberValue;
1138
+ }
1139
+ if (typeof width === "number")
1140
+ return width;
1141
+ return width;
1142
+ }
1143
+ debugDispatcher.on(
1144
+ "cleanTableSizes",
1145
+ ([tableName]) => {
1146
+ const currentWidths = persistentStorage[widthStorageName];
1147
+ delete currentWidths[tableName];
1148
+ persistentStorage[widthStorageName] = currentWidths;
1149
+ },
1150
+ 'Se usa para borrar el estado de una tabla. Uso: dd.cleanTableSizes("TableName")'
1151
+ );
1152
+ function makeColumnName(tableName, columnName) {
1153
+ return `${tableName}${columnName}`;
1154
+ }
1155
+ const thWidthEmitter = new class ThWidthEmitter extends EventEmitter {
1156
+ }();
1157
+ const NoMemoHeaderCell = ({
1158
+ apiaColumnIndex,
1159
+ columnIndex,
1160
+ inTableColumnIndex
1161
+ }) => {
1162
+ const { name, onSortChange } = useResponsiveTableContext();
1163
+ const uniqueId = window.location.href.match(/busEntId=(\d+)/)?.[1] ?? window.location.href.match(/query=(\d+)/)?.[1] ?? "";
1164
+ const isGlobal = window.isGlobal ? "isGlobal" : "notGlobal";
1165
+ const actualName = name + uniqueId + String(isGlobal);
1166
+ const column = useResponsiveTable((global) => {
1167
+ const tableState = global.responsiveTableSlice[name];
1168
+ return tableState?.columns[columnIndex];
1169
+ }, shallowEqual);
1170
+ const storedWidth = persistentStorage[widthStorageName]?.[actualName]?.[column.name];
1171
+ const [width, setWidth] = React.useState(storedWidth ?? 200);
1172
+ const [isResize, setIsResize] = React.useState(storedWidth !== void 0);
1173
+ React.useEffect(() => {
1174
+ return void thWidthEmitter.on("resize", (ev) => {
1175
+ if (ev.name === makeColumnName(actualName, column.name)) {
1176
+ setIsResize(true);
1177
+ setWidth(ev.width);
1178
+ }
1179
+ });
1180
+ }, [column.name, actualName]);
1181
+ const isFilterRequired = useResponsiveTable((global) => {
1182
+ const tableState = global.responsiveTableSlice[name];
1183
+ const columnFilter = tableState?.filters.find(
1184
+ (current) => current.column === column.title
1185
+ );
1186
+ return columnFilter?.required;
1187
+ }, shallowEqual);
1188
+ const isSortingAllowed = useResponsiveTable((global) => {
1189
+ const tableState = global.responsiveTableSlice[name];
1190
+ return tableState?.allowSorting;
1191
+ });
1192
+ const domProps = useDomProps(
1193
+ "th",
1194
+ {
1195
+ columnIndex: inTableColumnIndex
1196
+ },
1197
+ domPropsSelector(name)
1198
+ );
1199
+ const sx = React.useMemo(
1200
+ () => !isResize ? {
1201
+ minWidth: getColumnWidth(column.minWidth ?? column.width),
1202
+ maxWidth: column.maxWidth !== void 0 ? getColumnWidth(column.maxWidth) : void 0,
1203
+ width: getColumnWidth(column.width),
1204
+ position: "relative"
1205
+ } : {
1206
+ width: `${width}px`,
1207
+ minWidth: `${width}px`,
1208
+ position: "relative"
1209
+ },
1210
+ [column.maxWidth, column.minWidth, column.width, isResize, width]
1211
+ );
1212
+ const buttonProps = useOtherTagButton(
1213
+ React.useMemo(
1214
+ () => ({
1215
+ className: "headButton",
1216
+ onClick: (ev) => {
1217
+ if (isChild(
1218
+ ev.target,
1219
+ (current) => current.classList.contains("headButton__resizer")
1220
+ ))
1221
+ return;
1222
+ if (onSortChange && column.allowSorting !== false && isSortingAllowed !== false)
1223
+ onSortChange({
1224
+ column,
1225
+ columnIndex: apiaColumnIndex,
1226
+ name: column.name,
1227
+ sortValue: ["Asc", "Desc"][column.currentSorting !== "A" ? 0 : 1]
1228
+ });
1229
+ }
1230
+ }),
1231
+ [apiaColumnIndex, column, isSortingAllowed, onSortChange]
1232
+ )
1233
+ );
1234
+ return /* @__PURE__ */ jsx(
1235
+ Box,
1236
+ {
1237
+ as: "th",
1238
+ style: sx,
1239
+ "data-columnname": column.name,
1240
+ title: column.title ?? column.label ?? column.name,
1241
+ ...buttonProps,
1242
+ ...domProps,
1243
+ role: "rowheader",
1244
+ className: `${isFilterRequired && window.SHOW_REQUIRED_POSITION ? "requiredFilterColumn" : ""}`,
1245
+ children: /* @__PURE__ */ jsxs(Box, { as: "span", className: "headButton__container", children: [
1246
+ /* @__PURE__ */ jsx(
1247
+ Box,
1248
+ {
1249
+ as: "span",
1250
+ className: `${isFilterRequired ? "requiredFilter__Column" : ""} headButton__label`,
1251
+ children: /* @__PURE__ */ jsx(
1252
+ AutoEllipsis,
1253
+ {
1254
+ overrideStyles: (el) => {
1255
+ const th = el.closest("th");
1256
+ return {
1257
+ width: `${Math.max(
1258
+ 100,
1259
+ Number.parseInt(window.getComputedStyle(th).width)
1260
+ )}px`
1261
+ };
1262
+ },
1263
+ children: column.label
1264
+ }
1265
+ )
1266
+ }
1267
+ ),
1268
+ /* @__PURE__ */ jsxs(Box, { as: "span", className: "headButton__sortIcon", children: [
1269
+ column.allowSorting !== false && column.currentSorting === "A" && /* @__PURE__ */ jsx(FaSortUp, {}),
1270
+ column.allowSorting !== false && column.currentSorting === "D" && /* @__PURE__ */ jsx(FaSortDown, {}),
1271
+ column.allowSorting !== false && !column.currentSorting && /* @__PURE__ */ jsx(FaSort, {})
1272
+ ] }),
1273
+ /* @__PURE__ */ jsx(
1274
+ Box,
1275
+ {
1276
+ className: "headButton__resizer",
1277
+ onMouseDown: (ev) => {
1278
+ if (!isResize) {
1279
+ const trElement = getSpecificParent(
1280
+ ev.target,
1281
+ (current) => current.tagName === "TR"
1282
+ );
1283
+ trElement?.querySelectorAll("th").forEach((current) => {
1284
+ thWidthEmitter.emit("resize", {
1285
+ name: makeColumnName(
1286
+ actualName,
1287
+ current.dataset.columnname
1288
+ ),
1289
+ width: current.clientWidth
1290
+ });
1291
+ });
1292
+ setIsResize(true);
1293
+ }
1294
+ const th = getSpecificParent(
1295
+ ev.target,
1296
+ (current) => current.tagName === "TH"
1297
+ );
1298
+ if (!th)
1299
+ throw new Error("There is no th");
1300
+ const initialX = ev.clientX;
1301
+ const initialWidth = th.clientWidth;
1302
+ const resize = (mousemoveEv) => {
1303
+ const dif = mousemoveEv.clientX - initialX;
1304
+ setWidth(initialWidth + dif);
1305
+ };
1306
+ const unsuscribe = () => {
1307
+ const trElement = getSpecificParent(
1308
+ ev.target,
1309
+ (current) => current.tagName === "TR"
1310
+ );
1311
+ trElement?.querySelectorAll("th").forEach((current) => {
1312
+ persistentStorage[widthStorageName] = {
1313
+ ...persistentStorage[widthStorageName],
1314
+ [actualName]: {
1315
+ ...persistentStorage[widthStorageName]?.[actualName],
1316
+ [current.dataset.columnname]: current.clientWidth
1317
+ }
1318
+ };
1319
+ });
1320
+ document.removeEventListener("mousemove", resize);
1321
+ document.removeEventListener("mouseup", unsuscribe);
1322
+ };
1323
+ document.addEventListener("mousemove", resize);
1324
+ document.addEventListener("mouseup", unsuscribe);
1325
+ return false;
1326
+ }
1327
+ }
1328
+ )
1329
+ ] })
1330
+ }
1331
+ );
1332
+ };
1333
+ const HeaderCell = React.memo(NoMemoHeaderCell);
1334
+
1335
+ const NoMemoRowStatesRenderer = ({
1336
+ state
1337
+ }) => {
1338
+ const { Icon } = state;
1339
+ return /* @__PURE__ */ jsx(
1340
+ Box,
1341
+ {
1342
+ sx: React.useMemo(
1343
+ () => ({
1344
+ "&, svg, path": {
1345
+ color: state.color ?? ""
1346
+ }
1347
+ }),
1348
+ [state.color]
1349
+ ),
1350
+ children: /* @__PURE__ */ jsx(
1351
+ Icon,
1352
+ {
1353
+ ...getVariant("inherit"),
1354
+ title: state.tooltip,
1355
+ className: `${state.className ?? "state"}_icon state_icon`
1356
+ }
1357
+ )
1358
+ }
1359
+ );
1360
+ };
1361
+ const RowStatesRenderer = React.memo(NoMemoRowStatesRenderer);
1362
+
1363
+ const StateCell = ({ index, rowIndex, state, isHeader }) => {
1364
+ const { name } = useResponsiveTableContext();
1365
+ const domProps = useDomProps(
1366
+ isHeader ? "headerStateCell" : "stateCell",
1367
+ { columnIndex: index, rowIndex },
1368
+ domPropsSelector(name)
1369
+ );
1370
+ return /* @__PURE__ */ jsx(Box, { as: "td", className: "stateCell", ...domProps, children: state ? /* @__PURE__ */ jsx(RowStatesRenderer, { state }) : "" });
1371
+ };
1372
+
1373
+ const NoMemoRangeFilter = ({
1374
+ filter,
1375
+ tableName
1376
+ }) => {
1377
+ const { onFilterBlur, onFilterChange, onFilterPressEnter } = useResponsiveTableContext(tableName);
1378
+ const filterLow = {
1379
+ id: filter.id,
1380
+ currentValue: filter.currentValue,
1381
+ type: "number"
1382
+ };
1383
+ const filterHigh = {
1384
+ id: filter.filterToId ?? "",
1385
+ currentValue: filter.filterToValue ?? "",
1386
+ type: "number"
1387
+ };
1388
+ return /* @__PURE__ */ jsxs(Box, { className: "ApiaFilter__Range", children: [
1389
+ /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__Low", children: /* @__PURE__ */ jsx(
1390
+ ApiaFilter,
1391
+ {
1392
+ filter: filterLow,
1393
+ onChange: (currentValue) => {
1394
+ if (onFilterChange)
1395
+ void onFilterChange({ ...filterLow, currentValue });
1396
+ },
1397
+ onBlur: (currentValue) => {
1398
+ if (onFilterBlur)
1399
+ void onFilterBlur({ ...filterLow, currentValue });
1400
+ },
1401
+ onPressEnter: (currentValue) => {
1402
+ if (onFilterPressEnter)
1403
+ void onFilterPressEnter({ ...filterLow, currentValue });
1404
+ }
1405
+ }
1406
+ ) }),
1407
+ " - ",
1408
+ /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__High", children: /* @__PURE__ */ jsx(
1409
+ ApiaFilter,
1410
+ {
1411
+ filter: filterHigh,
1412
+ onChange: (currentValue) => {
1413
+ if (onFilterChange)
1414
+ void onFilterChange({ ...filterHigh, currentValue });
1415
+ },
1416
+ onBlur: (currentValue) => {
1417
+ if (onFilterBlur)
1418
+ void onFilterBlur({ ...filterHigh, currentValue });
1419
+ },
1420
+ onPressEnter: (currentValue) => {
1421
+ if (onFilterPressEnter)
1422
+ void onFilterPressEnter({ ...filterHigh, currentValue });
1423
+ }
1424
+ }
1425
+ ) })
1426
+ ] });
1427
+ };
1428
+ const RangeFilter = NoMemoRangeFilter;
1429
+
1430
+ const FilterCell = ({ columnIndex, filter }) => {
1431
+ const { name, onFilterBlur, onFilterChange, onFilterPressEnter } = useResponsiveTableContext();
1432
+ const domProps = useDomProps(
1433
+ "filterTd",
1434
+ {
1435
+ columnIndex
1436
+ },
1437
+ domPropsSelector(name)
1438
+ );
1439
+ const handleOnBlur = React.useCallback(
1440
+ (currentValue) => {
1441
+ if (filter && onFilterBlur)
1442
+ onFilterBlur({ ...filter, currentValue });
1443
+ },
1444
+ [filter, onFilterBlur]
1445
+ );
1446
+ const handleOnChange = React.useCallback(
1447
+ (currentValue) => {
1448
+ if (filter && onFilterChange)
1449
+ return onFilterChange({ ...filter, currentValue });
1450
+ return true;
1451
+ },
1452
+ [filter, onFilterChange]
1453
+ );
1454
+ const handleOnPressEnter = React.useCallback(
1455
+ (currentValue) => {
1456
+ if (filter && onFilterPressEnter)
1457
+ onFilterPressEnter({ ...filter, currentValue });
1458
+ },
1459
+ [filter, onFilterPressEnter]
1460
+ );
1461
+ function findFilter() {
1462
+ if (filter?.isRange) {
1463
+ return /* @__PURE__ */ jsx(RangeFilter, { filter });
1464
+ }
1465
+ if (filter && !(filter.asAdditional || !filter.column || filter.isRange)) {
1466
+ return /* @__PURE__ */ jsx(
1467
+ ApiaFilter,
1468
+ {
1469
+ onBlur: handleOnBlur,
1470
+ onChange: handleOnChange,
1471
+ onPressEnter: handleOnPressEnter,
1472
+ filter
1473
+ }
1474
+ );
1475
+ }
1476
+ let label;
1477
+ if (filter && (filter.asAdditional || !filter.column || filter.isRange)) {
1478
+ label = window.LBL_ADDITIONAL_FILTER;
1479
+ } else {
1480
+ label = window.LBL_NO_COLUMN_FILTER;
1481
+ }
1482
+ return /* @__PURE__ */ jsx(Input, { "aria-label": label, disabled: true });
1483
+ }
1484
+ return /* @__PURE__ */ jsx("td", { ...domProps, children: findFilter() });
1485
+ };
1486
+
1487
+ const NoMemoHeader = () => {
1488
+ const { name } = useResponsiveTableContext();
1489
+ const columns = useResponsiveTable(
1490
+ (global) => global.responsiveTableSlice[name]?.columns
1491
+ );
1492
+ const hasNonAdditionalFilters = useResponsiveTable(
1493
+ (global) => global.responsiveTableSlice[name]?.hasNonAdditionalFilters
1494
+ );
1495
+ const focusedColumn = useResponsiveTable(
1496
+ (global) => global.responsiveTableSlice[name]?.focusedColumn
1497
+ );
1498
+ const focusedRow = useResponsiveTable(
1499
+ (global) => global.responsiveTableSlice[name]?.focusedRow
1500
+ );
1501
+ const filters = useResponsiveTable(
1502
+ (global) => {
1503
+ const tableState = global.responsiveTableSlice[name];
1504
+ const returnObject = tableState?.filters?.map((current) => ({
1505
+ columnIndex: tableState.columns.findIndex(
1506
+ (search) => search.name === current.column
1507
+ ),
1508
+ definition: current
1509
+ })).filter((current) => current.columnIndex >= 0);
1510
+ return returnObject;
1511
+ },
1512
+ (a, b) => {
1513
+ return a?.length === b?.length && a?.reduce((result, current, index) => {
1514
+ return result && shallowEqual$1(current.definition, b[index].definition);
1515
+ }, true);
1516
+ }
1517
+ );
1518
+ const statesCount = useResponsiveTable((globalState) => {
1519
+ const state = globalState.responsiveTableSlice[name];
1520
+ return state?.statesColumns ?? 0;
1521
+ }, shallowEqual$1);
1522
+ const additionalColumns = React.useMemo(
1523
+ () => columns?.reduce(
1524
+ (count, column) => count + (column.showAsAdditional ? 1 : 0),
1525
+ 0
1526
+ ),
1527
+ [columns]
1528
+ );
1529
+ const statesIds = React.useMemo(() => {
1530
+ return Array(statesCount).fill("").map(() => uniqueId());
1531
+ }, [statesCount]);
1532
+ const [isFiltersRowVisible, setIsFiltersRowVisible] = React.useState(
1533
+ /* (persistentStorage.showResponsiveTableFilters as boolean) ?? */
1534
+ false
1535
+ );
1536
+ React.useEffect(() => {
1537
+ persistentStorage.showResponsiveTableFilters = isFiltersRowVisible;
1538
+ }, [isFiltersRowVisible]);
1539
+ const buttonProps = useOtherTagButton(
1540
+ React.useMemo(
1541
+ () => ({
1542
+ className: "additionalColumn",
1543
+ onClick: () => setIsFiltersRowVisible((current) => !current)
1544
+ }),
1545
+ []
1546
+ )
1547
+ );
1548
+ const [ref, setRef] = useState(null);
1549
+ useUpdateEffect(() => {
1550
+ const handleFocus = (ev) => {
1551
+ ev.stopPropagation();
1552
+ setIsFiltersRowVisible(true);
1553
+ };
1554
+ ref?.addEventListener(customEvents.focus, handleFocus);
1555
+ return () => {
1556
+ ref?.removeEventListener(customEvents.focus, handleFocus);
1557
+ };
1558
+ }, [ref]);
1559
+ const domProps = useDomProps("headerTr", {}, domPropsSelector(name));
1560
+ return /* @__PURE__ */ jsxs("thead", { children: [
1561
+ /* @__PURE__ */ jsxs("tr", { ...domProps, children: [
1562
+ (additionalColumns > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx(
1563
+ "th",
1564
+ {
1565
+ "aria-colindex": 1,
1566
+ "aria-rowindex": 1,
1567
+ "data-focused": focusedColumn === 1 && focusedRow === -1 - (hasNonAdditionalFilters ? 1 : 0),
1568
+ ...buttonProps,
1569
+ tabIndex: focusedColumn === 1 && focusedRow === -1 - (hasNonAdditionalFilters ? 1 : 0) ? 0 : -1,
1570
+ "aria-label": isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text,
1571
+ role: "rowheader",
1572
+ children: hasNonAdditionalFilters ? /* @__PURE__ */ jsx(
1573
+ Icon,
1574
+ {
1575
+ className: "filterButton",
1576
+ name: "Filter",
1577
+ title: isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text,
1578
+ "aria-label": isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text
1579
+ }
1580
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
1581
+ /* @__PURE__ */ jsx("span", { style: { display: "none" }, children: isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text }),
1582
+ /* @__PURE__ */ jsx("span", { children: "\xA0" })
1583
+ ] })
1584
+ }
1585
+ ),
1586
+ statesIds.map((id, i) => /* @__PURE__ */ jsx(StateCell, { isHeader: true, index: i, rowIndex: 1 }, id)),
1587
+ columns?.map((current, actualColumnIndex) => ({
1588
+ ...current,
1589
+ actualTableColumnIndex: actualColumnIndex
1590
+ })).filter((current) => !current.showAsAdditional).map((current, columnIndex) => {
1591
+ if (current.hidden)
1592
+ return null;
1593
+ return /* @__PURE__ */ jsx(
1594
+ HeaderCell,
1595
+ {
1596
+ apiaColumnIndex: current.actualTableColumnIndex,
1597
+ columnIndex: current.actualTableColumnIndex,
1598
+ inTableColumnIndex: columnIndex
1599
+ },
1600
+ current.name
1601
+ );
1602
+ })
1603
+ ] }),
1604
+ (filters?.length ?? 0) > 0 && /* @__PURE__ */ jsxs(
1605
+ "tr",
1606
+ {
1607
+ ref: setRef,
1608
+ "data-focusindex": 2,
1609
+ className: `responsiveTable__filters__row ${isFiltersRowVisible ? "" : "hidden"}`,
1610
+ children: [
1611
+ (additionalColumns > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx(
1612
+ "td",
1613
+ {
1614
+ className: "noFilter",
1615
+ "aria-colindex": 1,
1616
+ "aria-rowindex": 2,
1617
+ tabIndex: focusedColumn === 1 && focusedRow === -1 ? 0 : -1,
1618
+ "data-focused": focusedColumn === 1 && focusedRow === -1,
1619
+ children: "\xA0"
1620
+ }
1621
+ ),
1622
+ statesIds.map((id, i) => /* @__PURE__ */ jsx(StateCell, { isHeader: true, index: i, rowIndex: 2 }, id)),
1623
+ columns?.filter((current) => !current.showAsAdditional).map((current, columnIndex) => {
1624
+ const filter = filters.find(
1625
+ (search) => search.definition.column === current.name
1626
+ );
1627
+ return current.showAsAdditional ? null : /* @__PURE__ */ jsx(
1628
+ FilterCell,
1629
+ {
1630
+ columnIndex,
1631
+ filter: filter?.definition
1632
+ },
1633
+ current.name
1634
+ );
1635
+ })
1636
+ ]
1637
+ }
1638
+ )
1639
+ ] });
1640
+ };
1641
+ const Header = React.memo(NoMemoHeader);
1642
+
1643
+ const NoMemoAdditionalColumnDefaultRenderer = ({
1644
+ column,
1645
+ cell
1646
+ }) => {
1647
+ return /* @__PURE__ */ jsxs(
1648
+ Box,
1649
+ {
1650
+ className: `${cell.className ?? ""} responsiveTable__additionalInfoItem`,
1651
+ id: cell.id,
1652
+ title: cell.title,
1653
+ children: [
1654
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
1655
+ column.name,
1656
+ ":"
1657
+ ] }),
1658
+ " ",
1659
+ cell.children
1660
+ ]
1661
+ }
1662
+ );
1663
+ };
1664
+ const AdditionalColumnDefaultRenderer = React.memo(
1665
+ NoMemoAdditionalColumnDefaultRenderer
1666
+ );
1667
+
1668
+ const SeparatorCell = ({
1669
+ colSpan,
1670
+ rowIndex
1671
+ }) => {
1672
+ const { name } = useResponsiveTableContext();
1673
+ const domProps = useDomProps(
1674
+ "separator",
1675
+ { rowIndex },
1676
+ domPropsSelector(name)
1677
+ );
1678
+ return /* @__PURE__ */ jsx("td", { className: "row__separator__cell", colSpan, ...domProps });
1679
+ };
1680
+
1681
+ const NoMemoDefaultRowRenderer = React.forwardRef(({ row, rowIndex, ...props }, currentRef) => /* @__PURE__ */ jsx(
1682
+ Box,
1683
+ {
1684
+ as: "tr",
1685
+ sx: useMemo(
1686
+ () => ({
1687
+ "&.colored, & > *": {
1688
+ color: row.color,
1689
+ background: row.background
1690
+ }
1691
+ }),
1692
+ [row.background, row.color]
1693
+ ),
1694
+ ref: currentRef,
1695
+ ...props
1696
+ }
1697
+ ));
1698
+ NoMemoDefaultRowRenderer.displayName = "DefaultRowRenderer";
1699
+ const DefaultRowRenderer = NoMemoDefaultRowRenderer;
1700
+
1701
+ const NoMemoDefaultCellRenderer = React.forwardRef(
1702
+ ({
1703
+ cell: { Renderer, rendererProps, AccordionRenderer, ariaLabel, ...cell },
1704
+ column,
1705
+ row,
1706
+ ...props
1707
+ }, currentRef) => /* @__PURE__ */ jsx(
1708
+ Box,
1709
+ {
1710
+ as: "td",
1711
+ sx: useMemo(
1712
+ () => ({
1713
+ "&.colored": {
1714
+ background: cell.background,
1715
+ color: cell.color,
1716
+ fontWeight: "bold"
1717
+ }
1718
+ }),
1719
+ [cell.background, cell.color]
1720
+ ),
1721
+ ref: currentRef,
1722
+ ...props,
1723
+ ...cell,
1724
+ "aria-label": ariaLabel,
1725
+ children: /* @__PURE__ */ jsx(
1726
+ AutoEllipsis,
1727
+ {
1728
+ overrideStyles: (el) => {
1729
+ const td = el.closest("td");
1730
+ return {
1731
+ width: window.getComputedStyle(td).width
1732
+ };
1733
+ },
1734
+ children: props.children ?? cell.children
1735
+ }
1736
+ )
1737
+ }
1738
+ )
1739
+ );
1740
+ NoMemoDefaultCellRenderer.displayName = "DefaultCellRenderer";
1741
+ const DefaultCellRenderer = NoMemoDefaultCellRenderer;
1742
+
1743
+ const NoMemoCell = ({
1744
+ columnIndex,
1745
+ inTableColumnIndex,
1746
+ rowIndex
1747
+ }) => {
1748
+ const { name } = useResponsiveTableContext();
1749
+ const domProps = useDomProps(
1750
+ "td",
1751
+ { columnIndex: inTableColumnIndex, rowIndex },
1752
+ domPropsSelector(name)
1753
+ );
1754
+ const cell = useResponsiveTable((global) => {
1755
+ const tableState = global.responsiveTableSlice[name];
1756
+ return tableState?.rows[rowIndex]?.cells[columnIndex];
1757
+ }, shallowEqual);
1758
+ const column = useResponsiveTable((global) => {
1759
+ const tableState = global.responsiveTableSlice[name];
1760
+ return tableState?.columns[columnIndex];
1761
+ }, shallowEqual);
1762
+ const row = useResponsiveTable((global) => {
1763
+ const tableState = global.responsiveTableSlice[name];
1764
+ return tableState?.rows[rowIndex];
1765
+ }, shallowEqual);
1766
+ const Renderer = React.useMemo(
1767
+ () => cell?.Renderer ?? column.Renderer ?? DefaultCellRenderer,
1768
+ [cell?.Renderer, column.Renderer]
1769
+ );
1770
+ if (!Renderer || !cell)
1771
+ return row.separator ? /* @__PURE__ */ jsx("div", { className: "separator" }) : null;
1772
+ return /* @__PURE__ */ jsx(
1773
+ Renderer,
1774
+ {
1775
+ ...domProps,
1776
+ cell,
1777
+ column,
1778
+ row,
1779
+ onFocus: (ev) => {
1780
+ if (ev.target instanceof HTMLElement) {
1781
+ const cell2 = ev.target.closest("td,th");
1782
+ if (ev.target === cell2) {
1783
+ const widget = cell2?.querySelector(getFocusSelector());
1784
+ if (cell2 && widget) {
1785
+ widget.focus();
1786
+ cell2.tabIndex = -1;
1787
+ }
1788
+ }
1789
+ }
1790
+ }
1791
+ }
1792
+ );
1793
+ };
1794
+ const Cell = React.memo(NoMemoCell);
1795
+
1796
+ const NoMemoRow = ({ rowIndex }) => {
1797
+ const { name } = useResponsiveTableContext();
1798
+ const { columns, hasNonAdditionalFilters, isScrolledIntoView } = useResponsiveTable((global) => {
1799
+ const tableState = global.responsiveTableSlice[name];
1800
+ return {
1801
+ columns: tableState?.columns ?? [],
1802
+ hasNonAdditionalFilters: tableState?.hasNonAdditionalFilters,
1803
+ isScrolledIntoView: tableState.scrollIntoViewRow === rowIndex
1804
+ };
1805
+ }, shallowEqual);
1806
+ const row = useResponsiveTable(
1807
+ (global) => global.responsiveTableSlice[name].rows[rowIndex],
1808
+ shallowEqual
1809
+ );
1810
+ const additionalCells = useResponsiveTable(
1811
+ (global) => {
1812
+ const tableState = global.responsiveTableSlice[name];
1813
+ return tableState.columns.map(
1814
+ (current, index) => current.showAsAdditional ? {
1815
+ index,
1816
+ column: current
1817
+ } : null
1818
+ ).filter(
1819
+ (current) => !!current
1820
+ ).map((current) => {
1821
+ return {
1822
+ cell: tableState.rows[rowIndex]?.cells[current.index],
1823
+ column: current.column,
1824
+ columnIndex: current.index
1825
+ };
1826
+ });
1827
+ },
1828
+ (currentValue, newValue) => {
1829
+ return currentValue.reduce(
1830
+ (accumulatedBoolean, currentCell, cellIndex) => {
1831
+ return accumulatedBoolean && shallowEqual(currentCell, newValue[cellIndex]);
1832
+ },
1833
+ true
1834
+ );
1835
+ }
1836
+ );
1837
+ const { isDragging, isExpanded, shouldForbidSelection } = useResponsiveTable(
1838
+ (global) => {
1839
+ const tableState = global.responsiveTableSlice[name];
1840
+ return {
1841
+ isExpanded: tableState.expandedRows.includes(rowIndex),
1842
+ isDragging: tableState.draggingRow === rowIndex,
1843
+ shouldForbidSelection: tableState.rows[rowIndex]?.forbidSelection
1844
+ };
1845
+ },
1846
+ shallowEqual
1847
+ );
1848
+ const domProps = useDomProps(
1849
+ "tr",
1850
+ {
1851
+ isThisRowExpanded: isExpanded,
1852
+ rowIndex
1853
+ },
1854
+ domPropsSelector(name)
1855
+ );
1856
+ const expandedRowDomProps = useDomProps(
1857
+ "tr",
1858
+ {
1859
+ isTheExpandedRow: true,
1860
+ rowIndex
1861
+ },
1862
+ domPropsSelector(name)
1863
+ );
1864
+ const handleExpandedState = React.useCallback(
1865
+ (ev) => {
1866
+ const willBeExpanded = typeof ev === "boolean" ? ev : !isExpanded;
1867
+ if (!willBeExpanded)
1868
+ responsiveTableStore.dispatch(
1869
+ responsiveTableActions.update({
1870
+ tableName: name,
1871
+ expandedRows: responsiveTableStore.getState().responsiveTableSlice[name].expandedRows.filter((current) => current !== rowIndex)
1872
+ })
1873
+ );
1874
+ else
1875
+ responsiveTableStore.dispatch(
1876
+ responsiveTableActions.update({
1877
+ tableName: name,
1878
+ expandedRows: [
1879
+ ...responsiveTableStore.getState().responsiveTableSlice[name].expandedRows,
1880
+ rowIndex
1881
+ ]
1882
+ })
1883
+ );
1884
+ },
1885
+ [isExpanded, name, rowIndex]
1886
+ );
1887
+ const statesCount = useResponsiveTable((globalState) => {
1888
+ const state = globalState.responsiveTableSlice[name];
1889
+ return state?.statesColumns ?? 0;
1890
+ }, shallowEqual);
1891
+ const states = React.useMemo(
1892
+ () => (row.states ?? []).map((current) => ({ ...current, id: uniqueId() })),
1893
+ [row.states]
1894
+ );
1895
+ const { ref, ...additionalCellDomProps } = useDomProps(
1896
+ "additionalTd",
1897
+ { rowIndex },
1898
+ domPropsSelector(name)
1899
+ );
1900
+ const Renderer = React.useMemo(
1901
+ () => row.renderer ?? DefaultRowRenderer,
1902
+ [row.renderer]
1903
+ );
1904
+ const hasScrolled = useRef(false);
1905
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1906
+ /* @__PURE__ */ jsx(
1907
+ Renderer,
1908
+ {
1909
+ ...domProps,
1910
+ row,
1911
+ rowIndex,
1912
+ className: `responsiveTable__row ${row.isHidden ? "hidden" : ""} ${domProps["aria-selected"] ? "selected" : ""} ${shouldForbidSelection ? "non-selectable" : ""} ${states.map((current) => current.className).join(" ")} ${row.className ?? ""} ${row.separator ? "row__separator" : ""} ${isDragging ? "draggingRow" : ""}`,
1913
+ onKeyDown: React.useCallback(
1914
+ (ev) => {
1915
+ if (ev.key.toLowerCase() === "arrowleft" && ev.ctrlKey) {
1916
+ ev.preventDefault();
1917
+ ev.stopPropagation();
1918
+ handleExpandedState(false);
1919
+ }
1920
+ if (ev.key.toLowerCase() === "arrowright" && ev.ctrlKey) {
1921
+ ev.preventDefault();
1922
+ ev.stopPropagation();
1923
+ handleExpandedState(true);
1924
+ }
1925
+ },
1926
+ [handleExpandedState]
1927
+ ),
1928
+ ...{
1929
+ ref: (el) => {
1930
+ if (el && isScrolledIntoView && !hasScrolled.current) {
1931
+ hasScrolled.current = true;
1932
+ scrollParentIntoElement(el);
1933
+ }
1934
+ }
1935
+ },
1936
+ children: row.separator ? /* @__PURE__ */ jsx(
1937
+ SeparatorCell,
1938
+ {
1939
+ colSpan: (additionalCells.length > 0 || hasNonAdditionalFilters ? 1 : 0) + statesCount + columns.filter((current) => !current.showAsAdditional).length,
1940
+ rowIndex
1941
+ }
1942
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
1943
+ (additionalCells.length > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx("td", { className: "additionalInfo__cell", ...additionalCellDomProps, children: additionalCells.length > 0 && /* @__PURE__ */ jsx(
1944
+ IconButton,
1945
+ {
1946
+ size: "Lg",
1947
+ ...getVariant("icon-outline"),
1948
+ icon: isExpanded ? MdKeyboardArrowDown : MdKeyboardArrowRight,
1949
+ "aria-label": isExpanded ? getLabel("lblCollapseRow").text : getLabel("lblExpandRow").text,
1950
+ className: "moreInformationButton",
1951
+ onClick: handleExpandedState
1952
+ }
1953
+ ) }),
1954
+ Array(statesCount).fill("").map((_, i) => {
1955
+ return /* @__PURE__ */ jsx(
1956
+ StateCell,
1957
+ {
1958
+ index: i,
1959
+ state: states[i],
1960
+ rowIndex
1961
+ },
1962
+ states[i]?.id ?? i
1963
+ );
1964
+ }),
1965
+ columns.map((current, actualColumnIndex) => ({
1966
+ ...current,
1967
+ actualColumnIndex
1968
+ })).filter((current) => !current.showAsAdditional).map((current, inTableColumnIndex) => {
1969
+ if (current.hidden)
1970
+ return null;
1971
+ return /* @__PURE__ */ jsx(
1972
+ Cell,
1973
+ {
1974
+ columnIndex: current.actualColumnIndex,
1975
+ rowIndex,
1976
+ inTableColumnIndex
1977
+ },
1978
+ current.name
1979
+ );
1980
+ })
1981
+ ] })
1982
+ }
1983
+ ),
1984
+ isExpanded && /* @__PURE__ */ jsx("tr", { className: "expandedRow", ...expandedRowDomProps, children: /* @__PURE__ */ jsx(
1985
+ "td",
1986
+ {
1987
+ colSpan: columns.length - additionalCells.length + states.length + 1,
1988
+ children: /* @__PURE__ */ jsx(Box, { className: "responsiveTable__additionalInfoContainer", children: additionalCells.map((current) => {
1989
+ const { Renderer: ColumnRenderer } = current.column;
1990
+ if (ColumnRenderer)
1991
+ return /* @__PURE__ */ jsx(
1992
+ ColumnRenderer,
1993
+ {
1994
+ cell: current.cell,
1995
+ column: current.column,
1996
+ row
1997
+ },
1998
+ current.column.name
1999
+ );
2000
+ return /* @__PURE__ */ jsx(
2001
+ AdditionalColumnDefaultRenderer,
2002
+ {
2003
+ cell: current.cell,
2004
+ column: current.column,
2005
+ row
2006
+ },
2007
+ current.column.name
2008
+ );
2009
+ }) })
2010
+ }
2011
+ ) })
2012
+ ] });
2013
+ };
2014
+ const Row = React.memo(NoMemoRow);
2015
+
2016
+ const NoRegistersRenderer = () => {
2017
+ const { labels } = useResponsiveTableContext();
2018
+ return /* @__PURE__ */ jsx(Box, { className: "no__registers", children: labels.noRegisters });
2019
+ };
2020
+
2021
+ const NoMemoTableRenderer = ({ variant }) => {
2022
+ const { name, label, labels } = useResponsiveTableContext();
2023
+ const domProps = useDomProps(
2024
+ "table",
2025
+ {},
2026
+ (global) => global.responsiveTableSlice[name]
2027
+ );
2028
+ const rows = useResponsiveTable((global) => {
2029
+ const tableState = global.responsiveTableSlice[name];
2030
+ return tableState?.rows?.map((current) => current.id);
2031
+ }, shallowEqual);
2032
+ const columnsCount = useResponsiveTable(
2033
+ (global) => (global.responsiveTableSlice[name]?.nonAdditionalColumnsCount ?? 0) + (global.responsiveTableSlice[name]?.hasNonAdditionalFilters ? 1 : 0) + (global.responsiveTableSlice[name]?.statesColumns ?? 0) + (global.responsiveTableSlice[name]?.columns.find(
2034
+ (current) => current.showAsAdditional
2035
+ ) ? 1 : 0)
2036
+ );
2037
+ const rowsCount = useResponsiveTable(
2038
+ (global) => global.responsiveTableSlice[name]?.rows.length || 0
2039
+ );
2040
+ return /* @__PURE__ */ jsxs(
2041
+ Box,
2042
+ {
2043
+ ...domProps,
2044
+ as: "table",
2045
+ className: "responsiveTable__table",
2046
+ ...getVariant(variant || "layout.common.tables.primary"),
2047
+ "aria-label": label,
2048
+ children: [
2049
+ /* @__PURE__ */ jsx(Header, {}),
2050
+ /* @__PURE__ */ jsx("tbody", { children: rowsCount > 0 ? rows?.map((row, index) => {
2051
+ return /* @__PURE__ */ jsx(Row, { rowIndex: index }, row ?? `${row}-${index}`);
2052
+ }) : labels.noRegisters ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columnsCount, children: /* @__PURE__ */ jsx(NoRegistersRenderer, {}) }) }) : null })
2053
+ ]
2054
+ }
2055
+ );
2056
+ };
2057
+ const TableRenderer = React.memo(NoMemoTableRenderer);
2058
+
2059
+ const NoMemoAccordionCell = ({ cell, column }) => {
2060
+ return /* @__PURE__ */ jsxs(
2061
+ Box,
2062
+ {
2063
+ className: `responsiveTable__accordionElement__column ${cell.className ?? ""}`,
2064
+ children: [
2065
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
2066
+ column.label ?? column.name,
2067
+ ": "
2068
+ ] }),
2069
+ /* @__PURE__ */ jsx(Box, { as: "span", sx: { color: cell.color, background: cell.background }, children: cell?.children })
2070
+ ]
2071
+ },
2072
+ column.name
2073
+ );
2074
+ };
2075
+ const AccordionCell = NoMemoAccordionCell;
2076
+
2077
+ const NoMemoAccordionElement = ({ row, rowIndex }) => {
2078
+ const { name } = useResponsiveTableContext();
2079
+ const indexColumns = useResponsiveTable((global) => {
2080
+ const tableState = global.responsiveTableSlice[name];
2081
+ return tableState?.accordionIndexColumns;
2082
+ }, shallowEqual);
2083
+ const columns = useResponsiveTable((global) => {
2084
+ const tableState = global.responsiveTableSlice[name];
2085
+ return tableState?.columns;
2086
+ }, shallowEqual);
2087
+ const title = React.useMemo(() => {
2088
+ if (row.title)
2089
+ return row.title;
2090
+ if (Array.isArray(indexColumns))
2091
+ return indexColumns.map(
2092
+ (current) => (
2093
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2094
+ row.cells[current.index].title || row.cells[current.index].children
2095
+ )
2096
+ ).join(" | ");
2097
+ return row.cells[0].title ?? row.cells[0].children;
2098
+ }, [indexColumns, row.cells, row.title]);
2099
+ const isSelected = useResponsiveTable(
2100
+ (global) => global.responsiveTableSlice[name].allowSelection !== false ? global.responsiveTableSlice[name].selectedRows.includes(rowIndex) : void 0
2101
+ );
2102
+ const isFocused = useResponsiveTable(
2103
+ (global) => global.responsiveTableSlice[name].focusedRow === rowIndex
2104
+ );
2105
+ const buttonProps = useMemo(
2106
+ () => ({
2107
+ title,
2108
+ ariaLabel: title,
2109
+ label: title,
2110
+ checked: isSelected,
2111
+ onChange: (isChecked) => {
2112
+ const isMultiple = responsiveTableStore.getState().responsiveTableSlice[name].isMultiple;
2113
+ responsiveTableStore.dispatch(
2114
+ responsiveTableActions.update({
2115
+ tableName: name,
2116
+ selectedRows: isMultiple ? isChecked ? [
2117
+ ...responsiveTableStore.getState().responsiveTableSlice[name].selectedRows,
2118
+ rowIndex
2119
+ ] : responsiveTableStore.getState().responsiveTableSlice[name].selectedRows.filter((current) => current !== rowIndex) : [rowIndex]
2120
+ })
2121
+ );
2122
+ },
2123
+ tabIndex: isFocused ? 0 : -1,
2124
+ rightButtons: row.accordionButtonProps?.rightButtons,
2125
+ onUserPressEnter: row.accordionButtonProps?.onUserPressEnter,
2126
+ domButtonProps: {
2127
+ buttonSx: {
2128
+ "&.accordion__item__button .accordion__item__button__label": {
2129
+ color: row.color
2130
+ }
2131
+ }
2132
+ }
2133
+ }),
2134
+ [
2135
+ isFocused,
2136
+ isSelected,
2137
+ name,
2138
+ row.accordionButtonProps?.onUserPressEnter,
2139
+ row.accordionButtonProps?.rightButtons,
2140
+ row.color,
2141
+ rowIndex,
2142
+ title
2143
+ ]
2144
+ );
2145
+ if (!Array.isArray(indexColumns) || !columns)
2146
+ return null;
2147
+ return /* @__PURE__ */ jsxs(AccordionItem, { id: row.id, buttonProps, children: [
2148
+ columns.map((currentColumn, columnIndex) => {
2149
+ const Renderer = row.cells[columnIndex].AccordionRenderer ?? currentColumn.AccordionRenderer ?? AccordionCell;
2150
+ return currentColumn.hideFromAccordion || currentColumn.showAsAdditional ? null : /* @__PURE__ */ jsx(
2151
+ Renderer,
2152
+ {
2153
+ cell: row.cells[columnIndex],
2154
+ column: currentColumn,
2155
+ columnIndex,
2156
+ row,
2157
+ rowIndex
2158
+ },
2159
+ currentColumn.name
2160
+ );
2161
+ }),
2162
+ columns.filter((current) => !!current.showAsAdditional).map((currentColumn, columnIndex) => {
2163
+ const Renderer = row.cells[columnIndex].AccordionRenderer ?? currentColumn.AccordionRenderer ?? AccordionCell;
2164
+ return currentColumn.hideFromAccordion ? null : /* @__PURE__ */ jsx(
2165
+ Renderer,
2166
+ {
2167
+ cell: row.cells[columnIndex],
2168
+ column: currentColumn,
2169
+ columnIndex,
2170
+ row,
2171
+ rowIndex
2172
+ },
2173
+ currentColumn.name
2174
+ );
2175
+ })
2176
+ ] });
2177
+ };
2178
+ const AccordionElement = memo(NoMemoAccordionElement);
2179
+
2180
+ const NoMemoAccordionRenderer = () => {
2181
+ const { name } = useResponsiveTableContext();
2182
+ const { columns, rows } = useResponsiveTable((global) => {
2183
+ const tableState = global.responsiveTableSlice[name];
2184
+ return {
2185
+ columns: tableState?.columns,
2186
+ rows: tableState?.rows
2187
+ };
2188
+ }, shallowEqual);
2189
+ React.useEffect(() => {
2190
+ if (columns && rows) {
2191
+ const markedAsTitleColumns = [];
2192
+ columns.forEach((column, index) => {
2193
+ if (column.showInAccordionTitle)
2194
+ markedAsTitleColumns.push({ column, index });
2195
+ });
2196
+ if (markedAsTitleColumns.length > 0) {
2197
+ responsiveTableStore.dispatch(
2198
+ responsiveTableActions.update({
2199
+ tableName: name,
2200
+ accordionIndexColumns: markedAsTitleColumns
2201
+ })
2202
+ );
2203
+ } else {
2204
+ const columnsLength = columns.length;
2205
+ let indexColumn = null;
2206
+ let currentIndex = 0;
2207
+ while (!indexColumn && currentIndex < columns.length) {
2208
+ let isAnyEmptyRow = false;
2209
+ for (const row of rows) {
2210
+ if (!row.cells[currentIndex].children) {
2211
+ isAnyEmptyRow = true;
2212
+ break;
2213
+ }
2214
+ }
2215
+ if (!isAnyEmptyRow && columns[currentIndex]) {
2216
+ indexColumn = columns[currentIndex];
2217
+ } else {
2218
+ currentIndex += 1;
2219
+ if (currentIndex === columnsLength)
2220
+ break;
2221
+ }
2222
+ }
2223
+ if (!indexColumn) {
2224
+ [indexColumn] = columns;
2225
+ currentIndex = 0;
2226
+ }
2227
+ responsiveTableStore.dispatch(
2228
+ responsiveTableActions.update({
2229
+ tableName: name,
2230
+ accordionIndexColumns: [
2231
+ { column: indexColumn, index: currentIndex }
2232
+ ]
2233
+ })
2234
+ );
2235
+ }
2236
+ }
2237
+ }, [columns, name, rows]);
2238
+ return /* @__PURE__ */ jsxs(Accordion, { children: [
2239
+ !rows || rows.length === 0 && /* @__PURE__ */ jsx(NoRegistersRenderer, {}),
2240
+ rows?.map((current, rowIndex) => /* @__PURE__ */ jsx(AccordionElement, { row: current, rowIndex }, current.id))
2241
+ ] });
2242
+ };
2243
+ const AccordionRenderer = React.memo(NoMemoAccordionRenderer);
2244
+
2245
+ const domPropsSelector = (name) => (global) => global.responsiveTableSlice[name];
2246
+ const NoMemoResponsiveTable = React.forwardRef(({ className, variant, ...props }, ref) => {
2247
+ const breakpoint = useBreakpointIndex({ defaultIndex: 3 });
2248
+ const { currentBreakPoint } = useResponsiveTableContext();
2249
+ const actualBreakpoint = currentBreakPoint ?? breakpoint;
2250
+ return /* @__PURE__ */ jsx(
2251
+ Box,
2252
+ {
2253
+ ...props,
2254
+ ...getVariant("layout.common.tables.responsive"),
2255
+ className: `responsiveTable__wrapper ${className ?? ""}`,
2256
+ ref,
2257
+ children: actualBreakpoint >= 3 ? /* @__PURE__ */ jsx(KeyHandler, { children: /* @__PURE__ */ jsx(TableRenderer, { variant }) }) : /* @__PURE__ */ jsx(AccordionRenderer, {})
2258
+ }
2259
+ );
2260
+ });
2261
+ NoMemoResponsiveTable.displayName = "ResponsiveTable";
2262
+ const ResponsiveTable = React.memo(NoMemoResponsiveTable);
2263
+
2264
+ const NoMemoSort = ({ tableName }) => {
2265
+ const { name, onSortChange } = useResponsiveTableContext(tableName);
2266
+ const columns = useResponsiveTable((global) => {
2267
+ return global.responsiveTableSlice[name]?.columns;
2268
+ }, shallowEqual);
2269
+ return /* @__PURE__ */ jsx(Fragment, { children: columns?.map((column, columnIndex) => {
2270
+ return column.showAsAdditional || column.allowSorting === false ? null : /* @__PURE__ */ jsxs(Label, { children: [
2271
+ /* @__PURE__ */ jsx(Box, { as: "span", children: column.label ?? column.name }),
2272
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
2273
+ Select,
2274
+ {
2275
+ value: column.currentSorting === null ? "" : column.currentSorting,
2276
+ onChange: (ev) => {
2277
+ if (onSortChange)
2278
+ onSortChange({
2279
+ columnIndex,
2280
+ column,
2281
+ name: column.name,
2282
+ sortValue: ev.target.value === "" ? null : ev.target.value
2283
+ });
2284
+ },
2285
+ children: [
2286
+ /* @__PURE__ */ jsx("option", { value: "" }),
2287
+ /* @__PURE__ */ jsx("option", { value: "A", children: window.ORDER_ASC_LABEL }),
2288
+ /* @__PURE__ */ jsx("option", { value: "D", children: window.ORDER_DESC_LABEL })
2289
+ ]
2290
+ }
2291
+ ) })
2292
+ ] }, column.name);
2293
+ }) });
2294
+ };
2295
+ const Sort = React.memo(NoMemoSort);
2296
+
2297
+ dayjs.extend(customParseFormat);
2298
+ const dateFormat = getDateFormat();
2299
+ function controlDatesOrder(first, last) {
2300
+ if (!first || !last)
2301
+ return true;
2302
+ if (dayjs(last, dateFormat).isBefore(dayjs(first, dateFormat))) {
2303
+ return window.MSG_FEC_FIN_MAY_FEC_INI;
2304
+ }
2305
+ return true;
2306
+ }
2307
+ const NoMemoInnerRender = React.forwardRef(
2308
+ ({
2309
+ filters,
2310
+ tableName
2311
+ }, ref) => {
2312
+ const { onFilterBlur, onFilterChange, onFilterPressEnter, name } = useResponsiveTableContext(tableName);
2313
+ const [lastEmittedValue, setLastEmittedValue] = React.useState(null);
2314
+ const [lastEmittedValueByPartner, setLastEmittedValueByPartner] = React.useState(null);
2315
+ return /* @__PURE__ */ jsx(Box, { ref, className: "filtersRender", children: filters?.map((filter, key) => {
2316
+ if (filter.hide)
2317
+ return null;
2318
+ const isDate = filter.type === "D" || filter.type === "date";
2319
+ const filterToId = filter.filterToId ?? `${filter.id}i`;
2320
+ const filterTo = {
2321
+ ...filter,
2322
+ hide: filter.filterToId === void 0,
2323
+ id: filterToId,
2324
+ currentValue: filter.filterToValue ?? "",
2325
+ required: false
2326
+ };
2327
+ const column = responsiveTableStore.getState().responsiveTableSlice[name].columns.find((current) => current.name === filter.column);
2328
+ const filterTitle = filter.title || column?.label || column?.title || column?.name || "noFilterNorColumnTitle";
2329
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2330
+ /* @__PURE__ */ jsx(
2331
+ Box,
2332
+ {
2333
+ className: filter.type === "D" || filter.type === "date" ? "twoColumns" : "",
2334
+ children: /* @__PURE__ */ jsxs(
2335
+ Label,
2336
+ {
2337
+ title: isDate ? window.LBL_DATE_FILTER_FROM_TOOLTIP : filterTitle,
2338
+ children: [
2339
+ window.SHOW_REQUIRED_POSITION !== "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: filter.required }),
2340
+ /* @__PURE__ */ jsx(Box, { as: "span", children: isDate && !filter.hideToFilter ? formatMessage(window.LBL_DATE_FILTER_FROM_TXT, {
2341
+ TOK1: filterTitle
2342
+ }) : filterTitle }),
2343
+ filter.isRange ? /* @__PURE__ */ jsx(RangeFilter, { filter }) : /* @__PURE__ */ jsx(
2344
+ ApiaFilter,
2345
+ {
2346
+ filter,
2347
+ onChange: (currentValue) => {
2348
+ const result = controlDatesOrder(
2349
+ currentValue,
2350
+ lastEmittedValueByPartner
2351
+ );
2352
+ if (result === true) {
2353
+ setLastEmittedValue(currentValue);
2354
+ if (onFilterChange)
2355
+ void onFilterChange({ ...filter, currentValue });
2356
+ }
2357
+ return result;
2358
+ },
2359
+ onBlur: (currentValue) => {
2360
+ if (onFilterBlur)
2361
+ void onFilterBlur({ ...filter, currentValue });
2362
+ },
2363
+ onPressEnter: (currentValue) => {
2364
+ if (onFilterPressEnter)
2365
+ void onFilterPressEnter({
2366
+ ...filter,
2367
+ currentValue
2368
+ });
2369
+ }
2370
+ }
2371
+ ),
2372
+ window.SHOW_REQUIRED_POSITION === "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: filter.required })
2373
+ ]
2374
+ }
2375
+ )
2376
+ },
2377
+ filter.id ?? filter.column ?? key
2378
+ ),
2379
+ isDate && !filter.hideToFilter && /* @__PURE__ */ jsx(
2380
+ Box,
2381
+ {
2382
+ className: filter.type === "D" || filter.type === "date" ? "twoColumns" : "",
2383
+ children: /* @__PURE__ */ jsxs(Label, { title: window.LBL_DATE_FILTER_TO_TOOLTIP, children: [
2384
+ /* @__PURE__ */ jsx(Box, { as: "span", children: formatMessage(window.LBL_DATE_FILTER_TO_TXT, {
2385
+ TOK1: filterTitle
2386
+ }) }),
2387
+ /* @__PURE__ */ jsx(
2388
+ ApiaFilter,
2389
+ {
2390
+ filter: filterTo,
2391
+ onChange: (currentValue) => {
2392
+ const result = controlDatesOrder(
2393
+ lastEmittedValue,
2394
+ currentValue
2395
+ );
2396
+ if (result === true) {
2397
+ setLastEmittedValueByPartner(currentValue);
2398
+ if (onFilterChange)
2399
+ void onFilterChange({
2400
+ ...filter,
2401
+ filterToId,
2402
+ filterToValue: currentValue
2403
+ });
2404
+ }
2405
+ return result;
2406
+ },
2407
+ onBlur: (currentValue) => {
2408
+ if (onFilterBlur)
2409
+ void onFilterBlur({
2410
+ ...filter,
2411
+ filterToId,
2412
+ filterToValue: currentValue
2413
+ });
2414
+ },
2415
+ onPressEnter: (currentValue) => {
2416
+ if (onFilterPressEnter)
2417
+ void onFilterPressEnter({
2418
+ ...filter,
2419
+ filterToId,
2420
+ filterToValue: currentValue
2421
+ });
2422
+ }
2423
+ }
2424
+ )
2425
+ ] })
2426
+ }
2427
+ )
2428
+ ] }, filter.id ?? filter.column ?? key);
2429
+ }) });
2430
+ }
2431
+ );
2432
+ NoMemoInnerRender.displayName = "FiltersInnerRender";
2433
+ const InnerRender = React.memo(NoMemoInnerRender);
2434
+
2435
+ const NoMemoAdditional = ({ tableName }) => {
2436
+ const { name } = useResponsiveTableContext(tableName);
2437
+ const additionalFilters = useResponsiveTable((global) => {
2438
+ const state = global.responsiveTableSlice[name];
2439
+ return state?.filters.filter(
2440
+ (current) => !current.group && (!current.isMeta && !state?.columns.find(
2441
+ (search) => search.name === current.column && !current.asAdditional
2442
+ ) || state?.columns.find(
2443
+ (search) => search.name === current.column && search.showAsAdditional
2444
+ ) || current.asAdditional)
2445
+ );
2446
+ }, shallowEqual);
2447
+ return /* @__PURE__ */ jsx(InnerRender, { tableName, filters: additionalFilters });
2448
+ };
2449
+ const Additional = React.memo(NoMemoAdditional);
2450
+
2451
+ const NoMemoResponsive = ({ tableName }) => {
2452
+ const { name } = useResponsiveTableContext(tableName);
2453
+ const nonAdditionalFilters = useResponsiveTable((global) => {
2454
+ const state = global.responsiveTableSlice[name];
2455
+ return state?.filters.filter(
2456
+ (current) => !current.isMeta && state?.columns.find((search) => search.name === current.column)
2457
+ );
2458
+ }, shallowEqual);
2459
+ return /* @__PURE__ */ jsx(
2460
+ InnerRender,
2461
+ {
2462
+ tableName,
2463
+ isResponsive: true,
2464
+ filters: nonAdditionalFilters
2465
+ }
2466
+ );
2467
+ };
2468
+ const Responsive = React.memo(NoMemoResponsive);
2469
+
2470
+ var __defProp$1 = Object.defineProperty;
2471
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2472
+ var __publicField$1 = (obj, key, value) => {
2473
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2474
+ return value;
2475
+ };
2476
+ const maximizationPersist = {
2477
+ getState(id) {
2478
+ const current = persistentStorage.maximizationPersist ?? {};
2479
+ return current[id];
2480
+ },
2481
+ setState(id, isMaximized) {
2482
+ const current = persistentStorage.maximizationPersist ?? {};
2483
+ current[id] = isMaximized;
2484
+ persistentStorage.maximizationPersist = current;
2485
+ }
2486
+ };
2487
+ class Maximization extends EventEmitter {
2488
+ constructor() {
2489
+ super(...arguments);
2490
+ __publicField$1(this, "components", {});
2491
+ }
2492
+ checkComponentExists(id) {
2493
+ return this.components[id] === void 0;
2494
+ }
2495
+ emit(eventName, params) {
2496
+ if (eventName === "toggle") {
2497
+ const { id, isMaximized } = params;
2498
+ this.checkComponentExists(id);
2499
+ if (!this.components[id])
2500
+ return;
2501
+ this.components[id].isMaximized = isMaximized ?? !this.components[id].isMaximized;
2502
+ maximizationPersist.setState(id, this.components[id].isMaximized);
2503
+ this.isMaximized(id);
2504
+ super.emit(eventName, {
2505
+ id,
2506
+ isMaximized: this.components[id].isMaximized
2507
+ });
2508
+ }
2509
+ }
2510
+ isMaximized(id) {
2511
+ this.checkComponentExists(id);
2512
+ const selector = this.components[id]?.selector;
2513
+ if (selector === void 0)
2514
+ return void 0;
2515
+ const content = typeof selector === "string" ? document.querySelector(selector) : selector?.();
2516
+ if (content)
2517
+ content.classList.toggle("maximized", this.components[id].isMaximized);
2518
+ return this.components[id]?.isMaximized;
2519
+ }
2520
+ registerMaximizableComponent(id, selector) {
2521
+ this.components[id] = {
2522
+ selector: selector ?? this.components[id]?.selector,
2523
+ isMaximized: false
2524
+ // isDefaultMaximized ??
2525
+ // (conf<boolean>('lists.persistMaximized', true, 'boolean')
2526
+ // ? maximizationPersist.getState(id)
2527
+ // : undefined) ??
2528
+ // isConfDefaultMaximized,
2529
+ };
2530
+ }
2531
+ toggleIsMaximized(id, isMaximized) {
2532
+ this.emit("toggle", { id, isMaximized });
2533
+ }
2534
+ }
2535
+ const maximizationController = new Maximization();
2536
+ function useIsMaximized(id) {
2537
+ React.useEffect(() => {
2538
+ maximizationController.registerMaximizableComponent(id);
2539
+ }, [id]);
2540
+ const [isInnerMaximized, innerSetIsMaximized] = React.useState(
2541
+ maximizationController.isMaximized(id) ?? false
2542
+ );
2543
+ React.useEffect(() => {
2544
+ const handleToggle = ({
2545
+ id: eventId,
2546
+ isMaximized: eventIsMaximized
2547
+ }) => {
2548
+ if (id === eventId)
2549
+ innerSetIsMaximized((current) => eventIsMaximized ?? !current);
2550
+ };
2551
+ const unsuscribe1 = maximizationController.on("toggle", handleToggle);
2552
+ innerSetIsMaximized(
2553
+ maximizationController.components[id].isMaximized ?? false
2554
+ );
2555
+ return () => {
2556
+ unsuscribe1();
2557
+ };
2558
+ }, [id]);
2559
+ return {
2560
+ isMaximized: isInnerMaximized,
2561
+ toggleIsMaximized: React.useCallback(
2562
+ (isMaximized) => {
2563
+ maximizationController.emit("toggle", { id, isMaximized });
2564
+ },
2565
+ [id]
2566
+ )
2567
+ };
2568
+ }
2569
+
2570
+ const NoMemoPagination = ({
2571
+ appliedFilters,
2572
+ areAllFiltersApplied,
2573
+ className,
2574
+ currentPage,
2575
+ disabled,
2576
+ disableReduced,
2577
+ hasMore,
2578
+ hideMaximizeButton,
2579
+ hideRefreshButton,
2580
+ isLoading,
2581
+ isPerforming,
2582
+ listId: outerListId,
2583
+ onDeleteFilters,
2584
+ onPageChange,
2585
+ onRefresh,
2586
+ pageCount,
2587
+ recordsCount: outerRecordsCount,
2588
+ reachedMax,
2589
+ showMaximizeOnSmallBreakpoints,
2590
+ variant = "primary"
2591
+ }) => {
2592
+ const numberPageCount = Number(pageCount);
2593
+ const breakPoint = useBreakpointIndex();
2594
+ const numberCurrentPage = Number(currentPage);
2595
+ const recordsCount = outerRecordsCount;
2596
+ const [internCurrentPage, setCurrentPage] = useState(
2597
+ numberCurrentPage ?? 1
2598
+ );
2599
+ const [lastEmittedPage, setLastEmittedPage] = useState(
2600
+ numberCurrentPage ?? 1
2601
+ );
2602
+ const [hasNoValue, setHasNoValue] = useState(false);
2603
+ useEffect(() => {
2604
+ setCurrentPage(numberCurrentPage);
2605
+ }, [numberCurrentPage]);
2606
+ const setCurrentAndDispatch = useCallback(
2607
+ (page) => {
2608
+ setCurrentPage(page);
2609
+ onPageChange(page);
2610
+ setLastEmittedPage(page);
2611
+ },
2612
+ [onPageChange]
2613
+ );
2614
+ const InputRef = createRef();
2615
+ const listId = useResponsiveTableContext().name;
2616
+ const { isMaximized, toggleIsMaximized } = useIsMaximized(
2617
+ outerListId ?? listId
2618
+ );
2619
+ const options = [];
2620
+ for (let i = 1; i <= numberPageCount; i++) {
2621
+ options.push(i);
2622
+ }
2623
+ const [infoButtonRef, setInfoButtonRef] = React.useState(
2624
+ null
2625
+ );
2626
+ const recordsCountLabel = `${window.GNR_TOT_RECORDS}: ${recordsCount}`;
2627
+ const tooltipProps = React.useMemo(
2628
+ () => ({
2629
+ text: breakPoint <= 3 ? `${recordsCountLabel}.${!reachedMax && !hasMore ? "" : reachedMax && window.GNR_TOT_RECORDS_REACHED || hasMore && window.QUERY_MORE_DATA}` : `${!reachedMax && !hasMore ? "" : reachedMax && window.GNR_TOT_RECORDS_REACHED || hasMore && window.QUERY_MORE_DATA}`,
2630
+ attachToElement: { current: infoButtonRef },
2631
+ closeOnClickOut: true
2632
+ // closeOnClickOutChecker(element) {
2633
+ // return !getSpecificParent(element, (current) =>
2634
+ // current.classList.contains('pagination__information'),
2635
+ // );
2636
+ // },
2637
+ }),
2638
+ [breakPoint, hasMore, infoButtonRef, reachedMax, recordsCountLabel]
2639
+ );
2640
+ return /* @__PURE__ */ jsxs(
2641
+ Box,
2642
+ {
2643
+ as: "nav",
2644
+ variant: `layout.common.components.pagination.${variant}`,
2645
+ "aria-label": getLabel("lblQryParamPag").text,
2646
+ className: `pagination ${numberPageCount <= 1 && !disableReduced ? "onlyRefresh" : ""} ${className ?? ""}`,
2647
+ children: [
2648
+ /* @__PURE__ */ jsxs(Box, { className: "pagination__leftToolbar", children: [
2649
+ !hideMaximizeButton && (showMaximizeOnSmallBreakpoints || breakPoint > 4) && /* @__PURE__ */ jsx(
2650
+ IconButton,
2651
+ {
2652
+ variant: "icon",
2653
+ className: "pagination__fullScreenButton",
2654
+ onClick: toggleIsMaximized.bind(toggleIsMaximized, void 0),
2655
+ icon: !isMaximized ? "Maximize" : "Minimize",
2656
+ title: !isMaximized ? window.LBL_MAXIMIZE : window.LBL_MINIMIZE,
2657
+ "aria-label": !isMaximized ? window.LBL_MAXIMIZE : window.LBL_MINIMIZE,
2658
+ iconSize: "Md"
2659
+ }
2660
+ ),
2661
+ ((reachedMax || hasMore) && breakPoint > 3 || breakPoint <= 3) && className !== "grid__pagination" ? /* @__PURE__ */ jsx(
2662
+ IconButton,
2663
+ {
2664
+ variant: "icon-primary",
2665
+ icon: "Info",
2666
+ className: `pagination__information ${reachedMax || hasMore ? "pagination__alertInfo" : ""}`,
2667
+ onClick: () => ApiaUtil.instance.tooltips.open(tooltipProps),
2668
+ ref: setInfoButtonRef,
2669
+ iconSize: "Md",
2670
+ "aria-label": window.BTN_FILE_INFO_TOOLTIP,
2671
+ title: window.BTN_FILE_INFO_TOOLTIP
2672
+ }
2673
+ ) : "",
2674
+ breakPoint > 3 && /* @__PURE__ */ jsx(
2675
+ Box,
2676
+ {
2677
+ as: "span",
2678
+ className: "recordsCounter pagination__deleteLabels",
2679
+ title: recordsCountLabel,
2680
+ children: recordsCount !== -1 && `${window.GNR_TOT_RECORDS}: ${recordsCount} `
2681
+ }
2682
+ )
2683
+ ] }),
2684
+ /* @__PURE__ */ jsx(Box, { className: "pagination__controls", children: (numberPageCount > 0 || disableReduced) && /* @__PURE__ */ jsxs(Fragment, { children: [
2685
+ breakPoint > 2 && /* @__PURE__ */ jsx(
2686
+ IconButton,
2687
+ {
2688
+ variant: "icon-primary",
2689
+ disabled: disabled || internCurrentPage === 1 || isLoading || isPerforming,
2690
+ "aria-label": window.NAV_FIRST_PAGE,
2691
+ type: "button",
2692
+ onClick: () => {
2693
+ setCurrentAndDispatch(1);
2694
+ },
2695
+ icon: "First",
2696
+ iconSize: "Sm"
2697
+ }
2698
+ ),
2699
+ /* @__PURE__ */ jsx(
2700
+ IconButton,
2701
+ {
2702
+ variant: "icon-primary",
2703
+ disabled: disabled || internCurrentPage <= 1 || isLoading || isPerforming,
2704
+ "aria-label": window.NAV_PREVIOUS_PAGE,
2705
+ type: "button",
2706
+ onClick: () => {
2707
+ setCurrentAndDispatch(internCurrentPage - 1);
2708
+ },
2709
+ icon: "Previous",
2710
+ iconSize: "Sm"
2711
+ }
2712
+ ),
2713
+ breakPoint > 2 && /* @__PURE__ */ jsxs(Box, { className: "input", children: [
2714
+ /* @__PURE__ */ jsx(
2715
+ Input,
2716
+ {
2717
+ className: "pagination__controls__input",
2718
+ "aria-label": window.NAV_INPUT_LABEL,
2719
+ title: `${window.PAGE}: ${internCurrentPage} `,
2720
+ ref: InputRef,
2721
+ value: hasNoValue ? "" : internCurrentPage,
2722
+ onKeyDown: (ev) => {
2723
+ const regex = /([0-9])|(Backspace)|(Tab)/;
2724
+ if (!ev.key.match(regex)) {
2725
+ ev.stopPropagation();
2726
+ ev.preventDefault();
2727
+ }
2728
+ if (ev.key === "Enter") {
2729
+ ev.stopPropagation();
2730
+ ev.preventDefault();
2731
+ setCurrentAndDispatch(internCurrentPage);
2732
+ }
2733
+ },
2734
+ onBlur: () => {
2735
+ if (lastEmittedPage !== internCurrentPage) {
2736
+ setCurrentAndDispatch(internCurrentPage);
2737
+ }
2738
+ },
2739
+ onFocus: (ev) => {
2740
+ ev.currentTarget.select();
2741
+ },
2742
+ onChange: (ev) => {
2743
+ setHasNoValue(ev.target.value === "");
2744
+ setCurrentPage(
2745
+ Math.max(
2746
+ 1,
2747
+ Math.min(
2748
+ noNaN(Number(ev.currentTarget.value)),
2749
+ pageCount
2750
+ )
2751
+ )
2752
+ );
2753
+ },
2754
+ disabled: disabled || isLoading || isPerforming
2755
+ }
2756
+ ),
2757
+ " ",
2758
+ "/",
2759
+ " ",
2760
+ /* @__PURE__ */ jsx(
2761
+ Box,
2762
+ {
2763
+ as: "span",
2764
+ title: recordsCount !== -1 ? `${window.GNR_TOT_RECORDS} ${recordsCount}` : window.NAV_INPUT_LABEL,
2765
+ children: pageCount
2766
+ }
2767
+ )
2768
+ ] }),
2769
+ breakPoint <= 2 && /* @__PURE__ */ jsxs(
2770
+ Select,
2771
+ {
2772
+ className: "pagination__selectPage",
2773
+ value: internCurrentPage,
2774
+ onChange: (e) => {
2775
+ setCurrentAndDispatch(Number(e.target.value));
2776
+ },
2777
+ children: [
2778
+ /* @__PURE__ */ jsxs("option", { disabled: true, children: [
2779
+ "Total: ",
2780
+ numberPageCount
2781
+ ] }),
2782
+ options.map((current) => {
2783
+ return /* @__PURE__ */ jsx("option", { children: current }, current);
2784
+ })
2785
+ ]
2786
+ }
2787
+ ),
2788
+ /* @__PURE__ */ jsx(
2789
+ IconButton,
2790
+ {
2791
+ variant: "icon-primary",
2792
+ disabled: disabled || internCurrentPage >= numberPageCount || isLoading || isPerforming,
2793
+ "aria-label": window.NAV_NEXT_PAGE,
2794
+ type: "button",
2795
+ onClick: () => {
2796
+ setCurrentAndDispatch(internCurrentPage + 1);
2797
+ },
2798
+ icon: "Next",
2799
+ iconSize: "Sm"
2800
+ }
2801
+ ),
2802
+ breakPoint > 2 && /* @__PURE__ */ jsx(
2803
+ IconButton,
2804
+ {
2805
+ variant: "icon-primary",
2806
+ type: "button",
2807
+ "aria-label": window.NAV_LAST_PAGE,
2808
+ disabled: disabled || internCurrentPage >= numberPageCount || isLoading || isPerforming,
2809
+ onClick: () => {
2810
+ setCurrentAndDispatch(numberPageCount);
2811
+ },
2812
+ icon: "Last",
2813
+ iconSize: "Sm"
2814
+ }
2815
+ )
2816
+ ] }) }),
2817
+ /* @__PURE__ */ jsx(Box, { className: "pagination__rightToolbar", children: (!hideRefreshButton || onDeleteFilters) && /* @__PURE__ */ jsxs(Fragment, { children: [
2818
+ onDeleteFilters && /* @__PURE__ */ jsxs(
2819
+ SimpleButton,
2820
+ {
2821
+ disabled: isPerforming,
2822
+ className: "pagination__deleteFiltersButton",
2823
+ onClick: onDeleteFilters,
2824
+ children: [
2825
+ breakPoint > 3 && /* @__PURE__ */ jsx(Box, { as: "span", className: "pagination__deleteLabels", children: window.BTN_DELETE_FILTERS }),
2826
+ /* @__PURE__ */ jsx(
2827
+ Box,
2828
+ {
2829
+ as: "span",
2830
+ className: `pagination__appliedFiltersLabel ${areAllFiltersApplied ? "" : "withFilters"}`,
2831
+ children: appliedFilters
2832
+ }
2833
+ )
2834
+ ]
2835
+ }
2836
+ ),
2837
+ !hideRefreshButton && /* @__PURE__ */ jsx(
2838
+ IconButton,
2839
+ {
2840
+ "aria-label": window.NAV_REFRESH,
2841
+ onClick: () => onRefresh(numberCurrentPage),
2842
+ icon: "Refresh",
2843
+ iconSize: "Md",
2844
+ disabled: disabled || isLoading,
2845
+ variant: "icon-primary",
2846
+ isLoading: isPerforming,
2847
+ className: "pagiantion__refreshIcon"
2848
+ }
2849
+ )
2850
+ ] }) })
2851
+ ]
2852
+ }
2853
+ );
2854
+ };
2855
+ const Pagination = React.memo(NoMemoPagination);
2856
+
2857
+ function applyFocusAttributes(table, _previousState, state, focus = state.isFocused) {
2858
+ table.querySelectorAll(getFocusSelector()).forEach((e) => {
2859
+ e.tabIndex = -1;
2860
+ });
2861
+ if (state.focusedColumn === 0) {
2862
+ const focusedRow = table.querySelector(
2863
+ `tr[data-rowindex="${state.focusedRow}"]`
2864
+ );
2865
+ if (focusedRow) {
2866
+ focusedRow.tabIndex = 0;
2867
+ window.requestAnimationFrame(() => {
2868
+ if (focus) {
2869
+ focusedRow.focus();
2870
+ }
2871
+ });
2872
+ }
2873
+ } else {
2874
+ const focusedCell = table.querySelector(
2875
+ `tr[data-rowindex="${state.focusedRow}"] td[aria-colindex="${state.focusedColumn}"], tr[data-rowindex="${state.focusedRow}"] th[aria-colindex="${state.focusedColumn}"]`
2876
+ );
2877
+ console.log(focusedCell);
2878
+ if (focusedCell instanceof HTMLElement) {
2879
+ const widgets = [];
2880
+ if (state.isEditionMode) {
2881
+ widgets.push(
2882
+ ...focusedCell.querySelectorAll(getFocusSelector())
2883
+ );
2884
+ } else {
2885
+ const widget = focusedCell.querySelector(getFocusSelector());
2886
+ if (widget) {
2887
+ widgets.push(widget);
2888
+ }
2889
+ }
2890
+ if (widgets.length) {
2891
+ console.log(widgets);
2892
+ widgets.forEach((widget, i) => {
2893
+ widget.tabIndex = 0;
2894
+ if (i === 0)
2895
+ window.requestAnimationFrame(() => {
2896
+ if (focus) {
2897
+ widget.focus();
2898
+ }
2899
+ });
2900
+ });
2901
+ } else {
2902
+ focusedCell.tabIndex = 0;
2903
+ window.requestAnimationFrame(() => {
2904
+ if (focus) {
2905
+ focusedCell.focus();
2906
+ }
2907
+ });
2908
+ }
2909
+ }
2910
+ }
2911
+ }
2912
+
2913
+ function setAriaAttributes(element, attribute, value) {
2914
+ element.setAttribute(attribute, value);
2915
+ }
2916
+ function getRowDomProps(rowIndex, state) {
2917
+ return getDomProps(
2918
+ getDomStoreProps(
2919
+ rowIndex < 0 ? "headerTr" : "tr",
2920
+ {
2921
+ rowIndex
2922
+ },
2923
+ () => state
2924
+ ),
2925
+ rowIndex < 0 ? "headerTr" : "tr",
2926
+ { rowIndex }
2927
+ );
2928
+ }
2929
+ function applyRowSelectionAttributes(row, state) {
2930
+ if (!(row instanceof HTMLElement))
2931
+ return;
2932
+ const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
2933
+ const props = getRowDomProps(rowIndex, state);
2934
+ Object.entries(props).forEach(([key, value]) => {
2935
+ let match;
2936
+ match = key.match(/aria-(\w+)/);
2937
+ if (match) {
2938
+ setAriaAttributes(row, key, value);
2939
+ } else if (match = key.match(/data-(\w+)/)) {
2940
+ row.dataset[match[1]] = value;
2941
+ }
2942
+ });
2943
+ }
2944
+ function applySelectionAttributes(table, _previousState, state) {
2945
+ const previousSelectedRows = table.querySelectorAll(
2946
+ '[aria-selected="true"]'
2947
+ );
2948
+ previousSelectedRows.forEach((c) => applyRowSelectionAttributes(c, state));
2949
+ if (state.selectedRows.length) {
2950
+ const newSelectedRows = table.querySelectorAll(
2951
+ state.selectedRows.map((index) => `tr[data-rowindex="${index}"]`).join(",")
2952
+ );
2953
+ newSelectedRows.forEach((c) => applyRowSelectionAttributes(c, state));
2954
+ }
2955
+ }
2956
+
2957
+ function handleMouseDownEvent(ev) {
2958
+ const target = ev.target;
2959
+ if (target instanceof HTMLElement) {
2960
+ const cell = target.closest("th,td");
2961
+ const row = target.closest("tr");
2962
+ const table = target.closest("table");
2963
+ if (cell && row && table) {
2964
+ const state = this.getState();
2965
+ const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
2966
+ const colIndex = Number.parseInt(cell.ariaColIndex || "a", 10);
2967
+ if (!isNaN(rowIndex) && !isNaN(colIndex)) {
2968
+ if (!ev.ctrlKey && !ev.shiftKey) {
2969
+ state.selectedRows = [rowIndex];
2970
+ } else if (ev.ctrlKey) {
2971
+ if (state.selectedRows.includes(rowIndex)) {
2972
+ state.selectedRows = state.selectedRows.filter(
2973
+ (c) => c !== rowIndex
2974
+ );
2975
+ } else {
2976
+ state.selectedRows = [...state.selectedRows, rowIndex];
2977
+ }
2978
+ } else if (ev.shiftKey) {
2979
+ const previousFocused = this.getState().focusedRow;
2980
+ state.selectedRows = [...state.selectedRows];
2981
+ const min = Math.min(previousFocused, rowIndex);
2982
+ const max = Math.max(previousFocused, rowIndex);
2983
+ for (let i = min; i <= max; i++) {
2984
+ state.selectedRows.push(i);
2985
+ }
2986
+ }
2987
+ state.focusedColumn = colIndex;
2988
+ state.focusedRow = rowIndex;
2989
+ state.isFocused = true;
2990
+ applySelectionAttributes(table, this.getState(), state);
2991
+ applyFocusAttributes(table, this.getState(), state);
2992
+ this.setState(state);
2993
+ } else {
2994
+ console.warn("Cannot parse rowIndex or colIndex");
2995
+ }
2996
+ } else {
2997
+ console.warn("Cannot find cell, row or table");
2998
+ }
2999
+ }
3000
+ }
3001
+
3002
+ function handleKeyDownEvent(ev) {
3003
+ const target = ev.target;
3004
+ const state = this.getState();
3005
+ if (target instanceof HTMLElement) {
3006
+ const table = target.closest("table");
3007
+ const row = target.closest("tr");
3008
+ const cell = target.closest("th,td");
3009
+ if (table && row) {
3010
+ if (state.isEditionMode) {
3011
+ if (ev.code === "Escape" || ev.code === "Enter") {
3012
+ state.isEditionMode = false;
3013
+ this.setState(state);
3014
+ applyFocusAttributes(table, this.getState(), state);
3015
+ }
3016
+ } else {
3017
+ const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
3018
+ const colIndex = Number.parseInt(cell?.ariaColIndex || "0", 10);
3019
+ if (!isNaN(rowIndex) && !isNaN(colIndex)) {
3020
+ if ([
3021
+ "ArrowDown",
3022
+ "ArrowUp",
3023
+ "ArrowLeft",
3024
+ "ArrowRight",
3025
+ "End",
3026
+ "Enter",
3027
+ "Home",
3028
+ "PageUp",
3029
+ "PageDown"
3030
+ ].includes(ev.code) || ev.code === "Space" && ev.ctrlKey) {
3031
+ ev.preventDefault();
3032
+ switch (ev.code) {
3033
+ case "Space":
3034
+ if (state.selectedRows.includes(rowIndex)) {
3035
+ state.selectedRows = state.selectedRows.filter(
3036
+ (c) => c !== rowIndex
3037
+ );
3038
+ } else {
3039
+ state.selectedRows = [...state.selectedRows, rowIndex];
3040
+ }
3041
+ break;
3042
+ case "ArrowDown":
3043
+ state.focusedRow = addBoundary(
3044
+ state.focusedRow + 1,
3045
+ state.hasNonAdditionalFilters ? -2 : -1,
3046
+ state.rows.length - 1
3047
+ );
3048
+ if (ev.ctrlKey) ; else if (ev.shiftKey) {
3049
+ state.selectedRows = [
3050
+ ...state.selectedRows,
3051
+ state.focusedRow
3052
+ ];
3053
+ } else {
3054
+ state.selectedRows = [state.focusedRow];
3055
+ }
3056
+ break;
3057
+ case "ArrowUp":
3058
+ state.focusedRow = addBoundary(
3059
+ state.focusedRow - 1,
3060
+ state.hasNonAdditionalFilters ? -2 : -1,
3061
+ state.rows.length - 1
3062
+ );
3063
+ if (ev.ctrlKey) ; else if (ev.shiftKey) {
3064
+ state.selectedRows = [
3065
+ ...state.selectedRows,
3066
+ state.focusedRow
3067
+ ];
3068
+ } else {
3069
+ state.selectedRows = [state.focusedRow];
3070
+ }
3071
+ break;
3072
+ case "ArrowLeft":
3073
+ state.focusedColumn = addBoundary(
3074
+ state.focusedColumn - 1,
3075
+ 0,
3076
+ state.columns.length
3077
+ );
3078
+ break;
3079
+ case "ArrowRight":
3080
+ state.focusedColumn = addBoundary(
3081
+ state.focusedColumn + 1,
3082
+ 0,
3083
+ state.columns.length
3084
+ );
3085
+ break;
3086
+ case "Home":
3087
+ if (state.focusedColumn === 0) {
3088
+ state.focusedRow = state.hasNonAdditionalFilters ? -2 : -1;
3089
+ if (ev.ctrlKey) ; else if (ev.shiftKey) {
3090
+ const max = Math.max(
3091
+ state.focusedRow,
3092
+ this.getState().focusedRow
3093
+ );
3094
+ const min = Math.min(
3095
+ state.focusedRow,
3096
+ this.getState().focusedRow
3097
+ );
3098
+ for (let i = min; i <= max; i++) {
3099
+ state.selectedRows.push(i);
3100
+ }
3101
+ } else {
3102
+ state.selectedRows = [state.focusedRow];
3103
+ }
3104
+ } else {
3105
+ state.focusedColumn = 1;
3106
+ }
3107
+ break;
3108
+ case "End":
3109
+ if (state.focusedColumn === 0) {
3110
+ state.focusedRow = state.rows.length - 1;
3111
+ if (ev.ctrlKey) ; else if (ev.shiftKey) {
3112
+ const max = Math.max(
3113
+ state.focusedRow,
3114
+ this.getState().focusedRow
3115
+ );
3116
+ const min = Math.min(
3117
+ state.focusedRow,
3118
+ this.getState().focusedRow
3119
+ );
3120
+ for (let i = min; i <= max; i++) {
3121
+ state.selectedRows.push(i);
3122
+ }
3123
+ } else {
3124
+ state.selectedRows = [state.focusedRow];
3125
+ }
3126
+ } else {
3127
+ state.focusedColumn = state.columns.length;
3128
+ }
3129
+ break;
3130
+ case "PageUp":
3131
+ state.focusedRow = addBoundary(
3132
+ state.focusedRow - 6,
3133
+ state.hasNonAdditionalFilters ? -2 : -1,
3134
+ state.rows.length - 1
3135
+ );
3136
+ if (ev.ctrlKey) ; else if (ev.shiftKey) {
3137
+ const previousFocused = this.getState().focusedRow;
3138
+ state.selectedRows = [...state.selectedRows];
3139
+ const min = Math.min(previousFocused, state.focusedRow);
3140
+ const max = Math.max(previousFocused, state.focusedRow);
3141
+ for (let i = min; i <= max; i++) {
3142
+ state.selectedRows.push(i);
3143
+ }
3144
+ } else {
3145
+ state.selectedRows = [state.focusedRow];
3146
+ }
3147
+ break;
3148
+ case "PageDown":
3149
+ state.focusedRow = addBoundary(
3150
+ state.focusedRow + 6,
3151
+ state.hasNonAdditionalFilters ? -2 : -1,
3152
+ state.rows.length - 1
3153
+ );
3154
+ if (ev.ctrlKey) ; else if (ev.shiftKey) {
3155
+ const previousFocused = this.getState().focusedRow;
3156
+ state.selectedRows = [...state.selectedRows];
3157
+ const min = Math.min(previousFocused, state.focusedRow);
3158
+ const max = Math.max(previousFocused, state.focusedRow);
3159
+ for (let i = min; i <= max; i++) {
3160
+ state.selectedRows.push(i);
3161
+ }
3162
+ } else {
3163
+ state.selectedRows = [state.focusedRow];
3164
+ }
3165
+ break;
3166
+ case "Enter":
3167
+ state.isEditionMode = true;
3168
+ this.setState(state);
3169
+ applyFocusAttributes(table, this.getState(), state);
3170
+ return;
3171
+ }
3172
+ state.isFocused = true;
3173
+ applySelectionAttributes(table, this.getState(), state);
3174
+ applyFocusAttributes(table, this.getState(), state);
3175
+ this.setState(state);
3176
+ }
3177
+ }
3178
+ }
3179
+ }
3180
+ }
3181
+ }
3182
+
3183
+ var __defProp = Object.defineProperty;
3184
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3185
+ var __publicField = (obj, key, value) => {
3186
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3187
+ return value;
3188
+ };
3189
+ class Controller2 {
3190
+ constructor(tableName) {
3191
+ this.tableName = tableName;
3192
+ __publicField(this, "events", {});
3193
+ __publicField(this, "unsubscribe", () => {
3194
+ });
3195
+ __publicField(this, "el", null);
3196
+ __publicField(this, "setRef", (el) => {
3197
+ this.unsubscribe();
3198
+ this.el = el;
3199
+ if (el) {
3200
+ el.addEventListener("keydown", this.handleKeyDownEvent);
3201
+ el.addEventListener("mousedown", this.handleClickEvent);
3202
+ this.unsubscribe = () => {
3203
+ el.removeEventListener("keydown", this.handleKeyDownEvent);
3204
+ el.removeEventListener("mousedown", this.handleClickEvent);
3205
+ };
3206
+ }
3207
+ });
3208
+ __publicField(this, "handleClickEvent");
3209
+ __publicField(this, "handleKeyDownEvent");
3210
+ this.handleClickEvent = handleMouseDownEvent.bind(this);
3211
+ this.handleKeyDownEvent = handleKeyDownEvent.bind(this);
3212
+ }
3213
+ setEvents(events) {
3214
+ this.events = events;
3215
+ }
3216
+ /**
3217
+ * Returns a copy of the current state object
3218
+ */
3219
+ getState() {
3220
+ return {
3221
+ ...responsiveTableStore.getState().responsiveTableSlice[this.tableName]
3222
+ };
3223
+ }
3224
+ setState(state) {
3225
+ if (state.selectedRows && !shallowEqual$1(state.selectedRows, this.getState().selectedRows)) {
3226
+ this.events.onChangeSelection?.(
3227
+ state.selectedRows.map((index) => ({
3228
+ index,
3229
+ row: this.getState().rows[index]
3230
+ }))
3231
+ );
3232
+ this.events.onSelectRows?.(
3233
+ state.selectedRows.map((index) => ({
3234
+ index,
3235
+ row: this.getState().rows[index]
3236
+ })),
3237
+ state.focusedRow
3238
+ );
3239
+ }
3240
+ if (state.scrollIntoViewRow !== void 0 && state.scrollIntoViewRow !== this.getState().scrollIntoViewRow) {
3241
+ const row = this.el?.querySelector(
3242
+ `tr[data-rowindex="${state.scrollIntoViewRow}"]`
3243
+ );
3244
+ if (row) {
3245
+ row.scrollIntoView({ block: "nearest", inline: "nearest" });
3246
+ }
3247
+ }
3248
+ responsiveTableStore.dispatch(
3249
+ responsiveTableActions.controller2UpdateSelectionState({
3250
+ tableName: this.tableName,
3251
+ ...state
3252
+ })
3253
+ );
3254
+ }
3255
+ updateSelectionState() {
3256
+ window.requestAnimationFrame(() => {
3257
+ if (this.el) {
3258
+ const table = this.el.querySelector("table");
3259
+ if (table) {
3260
+ applyFocusAttributes(table, this.getState(), this.getState());
3261
+ }
3262
+ }
3263
+ });
3264
+ }
3265
+ }
3266
+ const Controller2Component = ({
3267
+ controller,
3268
+ ...props
3269
+ }) => {
3270
+ controller.setEvents({
3271
+ onChangeSelection: props.onChangeSelection,
3272
+ onSelectRows: props.onSelectRows
3273
+ });
3274
+ const previousColumns = useRef([]);
3275
+ const previousRows = useRef([]);
3276
+ const box = useRef(null);
3277
+ useResponsiveTable((state) => {
3278
+ if (!Object.is(
3279
+ state.responsiveTableSlice[controller.tableName]?.columns,
3280
+ previousColumns.current
3281
+ )) {
3282
+ previousColumns.current = state.responsiveTableSlice[controller.tableName]?.columns;
3283
+ controller.updateSelectionState();
3284
+ }
3285
+ if (!Object.is(
3286
+ state.responsiveTableSlice[controller.tableName]?.rows,
3287
+ previousRows.current
3288
+ )) {
3289
+ previousRows.current = state.responsiveTableSlice[controller.tableName]?.rows;
3290
+ controller.updateSelectionState();
3291
+ }
3292
+ });
3293
+ return /* @__PURE__ */ jsx(
3294
+ Box,
3295
+ {
3296
+ ...props,
3297
+ ref: (el) => {
3298
+ controller.setRef(el);
3299
+ box.current = el;
3300
+ }
3301
+ }
3302
+ );
3303
+ };
3304
+ function makeController2(tableName) {
3305
+ const controller = new Controller2(tableName);
3306
+ return [
3307
+ controller,
3308
+ (props) => {
3309
+ return /* @__PURE__ */ jsx(Controller2Component, { ...props, controller });
3310
+ }
3311
+ ];
3312
+ }
3313
+
3314
+ const NoMemoDocNameCellRenderer = React.forwardRef(
3315
+ ({
3316
+ cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3317
+ column,
3318
+ row,
3319
+ ...props
3320
+ }, currentRef) => /* @__PURE__ */ jsx(
3321
+ "td",
3322
+ {
3323
+ ref: currentRef,
3324
+ ...props,
3325
+ ...cell,
3326
+ children: /* @__PURE__ */ jsxs(
3327
+ Link,
3328
+ {
3329
+ className: "cell__download__document",
3330
+ title: rendererProps?.docName,
3331
+ href: rendererProps?.docUrl,
3332
+ onClick: (ev) => {
3333
+ ev.preventDefault();
3334
+ if (rendererProps?.docUrl)
3335
+ void downloadUrl(rendererProps?.docUrl);
3336
+ },
3337
+ children: [
3338
+ /* @__PURE__ */ jsx(Icon, { title: "", name: "Download" }),
3339
+ rendererProps?.docName
3340
+ ]
3341
+ }
3342
+ )
3343
+ }
3344
+ )
3345
+ );
3346
+ NoMemoDocNameCellRenderer.displayName = "DocNameCellRenderer";
3347
+ const DocNameCellRenderer = NoMemoDocNameCellRenderer;
3348
+
3349
+ const NoMemoAccordionDocNameCellRenderer = React.forwardRef(
3350
+ ({
3351
+ cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3352
+ column
3353
+ }, currentRef) => /* @__PURE__ */ jsxs(Box, { ref: currentRef, ...cell, children: [
3354
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3355
+ column.label ?? column.name,
3356
+ ": "
3357
+ ] }),
3358
+ /* @__PURE__ */ jsxs(
3359
+ Link,
3360
+ {
3361
+ className: "cell__download__document",
3362
+ title: rendererProps?.docName,
3363
+ href: rendererProps?.docUrl,
3364
+ onClick: (ev) => {
3365
+ ev.preventDefault();
3366
+ if (rendererProps?.docUrl)
3367
+ void downloadUrl(rendererProps?.docUrl);
3368
+ },
3369
+ children: [
3370
+ /* @__PURE__ */ jsx(Icon, { title: "", name: "Download" }),
3371
+ rendererProps?.docName
3372
+ ]
3373
+ }
3374
+ )
3375
+ ] })
3376
+ );
3377
+ NoMemoAccordionDocNameCellRenderer.displayName = "AccordionDocNameCellRenderer";
3378
+ const AccordionDocNameCellRenderer = NoMemoAccordionDocNameCellRenderer;
3379
+
3380
+ const NoMemoAccordionHTMLCellRenderer = React.forwardRef(
3381
+ ({
3382
+ cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3383
+ column,
3384
+ row,
3385
+ ...props
3386
+ }, currentRef) => (
3387
+ /**
3388
+ * Aca falta el title de la columna
3389
+ */
3390
+ /* @__PURE__ */ jsx(
3391
+ Box,
3392
+ {
3393
+ ref: currentRef,
3394
+ ...props,
3395
+ ...cell,
3396
+ className: "accordion__cell__renderer",
3397
+ dangerouslySetInnerHTML: {
3398
+ __html: String(rendererProps?.html ?? children ?? "").replaceAll(
3399
+ /<TOK(\d+)/g,
3400
+ "&lt;TOK$1"
3401
+ )
3402
+ },
3403
+ as: "span"
3404
+ }
3405
+ )
3406
+ )
3407
+ );
3408
+ NoMemoAccordionHTMLCellRenderer.displayName = "AccordionHTMLCellRenderer";
3409
+ const AccordionHTMLCellRenderer = NoMemoAccordionHTMLCellRenderer;
3410
+
3411
+ const NoMemoHTMLCellRenderer = React.forwardRef(
3412
+ ({
3413
+ cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3414
+ column,
3415
+ row,
3416
+ ...props
3417
+ }, currentRef) => /* @__PURE__ */ jsx(
3418
+ "td",
3419
+ {
3420
+ ref: currentRef,
3421
+ ...props,
3422
+ ...cell,
3423
+ dangerouslySetInnerHTML: {
3424
+ __html: String(rendererProps?.html ?? children ?? "").replaceAll(
3425
+ /<TOK(\d+)/g,
3426
+ "&lt;TOK$1"
3427
+ )
3428
+ }
3429
+ }
3430
+ )
3431
+ );
3432
+ NoMemoHTMLCellRenderer.displayName = "HTMLCellRenderer";
3433
+ const HTMLCellRenderer = NoMemoHTMLCellRenderer;
3434
+
3435
+ const IsLoadingRenderer = () => {
3436
+ return /* @__PURE__ */ jsx(Box, { className: "responsiveTable__isLoading", children: /* @__PURE__ */ jsx(Spinner, {}) });
3437
+ };
3438
+
3439
+ function makeAccordionAsyncRenderer(additionalInfoGetter) {
3440
+ const InnerRender = forwardRef(({ row }, ref) => {
3441
+ const [moreInfo, setMoreInfo] = useState(null);
3442
+ const loadMore = useCallback(async () => {
3443
+ const result = await additionalInfoGetter(row);
3444
+ setMoreInfo(result);
3445
+ }, [row]);
3446
+ return /* @__PURE__ */ jsx(Fragment, { children: moreInfo ? /* @__PURE__ */ jsxs(Fragment, { children: [
3447
+ /* @__PURE__ */ jsx(IconButton, { icon: "Minus", onClick: () => setMoreInfo(null) }),
3448
+ arrayOrArray(moreInfo).map(
3449
+ (dataCell) => {
3450
+ return /* @__PURE__ */ jsxs(Box, { ref, as: "div", children: [
3451
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3452
+ dataCell.name,
3453
+ ":"
3454
+ ] }),
3455
+ " ",
3456
+ dataCell.label
3457
+ ] }, dataCell.name);
3458
+ }
3459
+ )
3460
+ ] }) : /* @__PURE__ */ jsx(IconButton, { icon: "Plus", onClick: () => void loadMore() }) });
3461
+ });
3462
+ InnerRender.displayName = "MakeAccordionAsyncRenderer";
3463
+ return InnerRender;
3464
+ }
3465
+
3466
+ function makeAsyncRenderer(additionalInfoGetter) {
3467
+ const InnerRender = forwardRef(({ row }, ref) => {
3468
+ const [moreInfo, setMoreInfo] = useState(null);
3469
+ useMount$1(() => {
3470
+ void (async () => {
3471
+ const result = await additionalInfoGetter(row);
3472
+ setMoreInfo(result);
3473
+ })();
3474
+ });
3475
+ return /* @__PURE__ */ jsx(Fragment, { children: moreInfo ? arrayOrArray(moreInfo).map((dataCell) => {
3476
+ return /* @__PURE__ */ jsx(
3477
+ Box,
3478
+ {
3479
+ ref,
3480
+ className: `responsiveTable__additionalInfoItem ${dataCell.newline ? "separator" : ""}`,
3481
+ children: dataCell.newline ? /* @__PURE__ */ jsxs(Fragment, { children: [
3482
+ /* @__PURE__ */ jsxs(Box, { sx: { height: "20px" }, as: "strong", children: [
3483
+ dataCell.name,
3484
+ ":"
3485
+ ] }),
3486
+ " ",
3487
+ dataCell.label
3488
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3489
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3490
+ dataCell.name,
3491
+ ":"
3492
+ ] }),
3493
+ " ",
3494
+ dataCell.label
3495
+ ] })
3496
+ },
3497
+ `${dataCell.name}-${uniqueId()}`
3498
+ );
3499
+ }) : /* @__PURE__ */ jsx(Spinner, { size: 15 }) });
3500
+ });
3501
+ InnerRender.displayName = "MakeAsyncRenderer";
3502
+ return InnerRender;
3503
+ }
3504
+
3505
+ const NoMemoNoEllipsisCellRenderer = React.forwardRef(
3506
+ ({
3507
+ cell: { Renderer, rendererProps, AccordionRenderer, ariaLabel, ...cell },
3508
+ column,
3509
+ row,
3510
+ ...props
3511
+ }, currentRef) => /* @__PURE__ */ jsx(
3512
+ Box,
3513
+ {
3514
+ as: "td",
3515
+ sx: useMemo(
3516
+ () => ({
3517
+ "&.colored": {
3518
+ background: cell.background,
3519
+ color: cell.color,
3520
+ fontWeight: "bold"
3521
+ }
3522
+ }),
3523
+ [cell.background, cell.color]
3524
+ ),
3525
+ ref: currentRef,
3526
+ ...props,
3527
+ ...cell,
3528
+ "aria-label": ariaLabel,
3529
+ children: props.children ?? cell.children
3530
+ }
3531
+ )
3532
+ );
3533
+ NoMemoNoEllipsisCellRenderer.displayName = "DefaultCellRenderer";
3534
+ const NoEllipsisCellRenderer = memo(NoMemoNoEllipsisCellRenderer);
3535
+
3536
+ function getPriorityHandler(priority) {
3537
+ let prio;
3538
+ if (priority?.includes("priority0"))
3539
+ prio = "priorityNone";
3540
+ if (priority?.includes("priority1"))
3541
+ prio = "priorityLow";
3542
+ if (priority?.includes("priority2"))
3543
+ prio = "priorityNormal";
3544
+ if (priority?.includes("priority3"))
3545
+ prio = "priorityHigh";
3546
+ if (priority?.includes("priority4"))
3547
+ prio = "priorityUrgent";
3548
+ return prio;
3549
+ }
3550
+ const NoMemoPriorityRenderer = React.forwardRef(
3551
+ ({
3552
+ cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3553
+ column,
3554
+ row,
3555
+ ...props
3556
+ }, currentRef) => {
3557
+ const taskPriorityColor = getPriorityHandler(rendererProps?.src);
3558
+ return /* @__PURE__ */ jsx(
3559
+ "td",
3560
+ {
3561
+ ...props,
3562
+ ...cell,
3563
+ ref: currentRef,
3564
+ className: "priority",
3565
+ sx: {
3566
+ color: taskPriorityColor
3567
+ },
3568
+ children: /* @__PURE__ */ jsx(FaSquare, {})
3569
+ }
3570
+ );
3571
+ }
3572
+ );
3573
+ NoMemoPriorityRenderer.displayName = "PriorityRenderer";
3574
+ const PriorityRenderer = NoMemoPriorityRenderer;
3575
+
3576
+ const NoMemoPriorityAccordionRenderer = React.forwardRef(
3577
+ ({ cell, column }, currentRef) => {
3578
+ const taskPriorityColor = getPriorityHandler(
3579
+ cell.rendererProps?.src
3580
+ );
3581
+ const title = column.label ?? column.name;
3582
+ return /* @__PURE__ */ jsxs(Box, { ref: currentRef, className: "priority_container", children: [
3583
+ title && /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3584
+ column.label ?? column.name,
3585
+ ": "
3586
+ ] }),
3587
+ /* @__PURE__ */ jsx(
3588
+ Box,
3589
+ {
3590
+ as: "span",
3591
+ className: "priority",
3592
+ sx: {
3593
+ color: taskPriorityColor
3594
+ },
3595
+ children: /* @__PURE__ */ jsx(FaSquare, {})
3596
+ }
3597
+ )
3598
+ ] });
3599
+ }
3600
+ );
3601
+ NoMemoPriorityAccordionRenderer.displayName = "PriorityAccordionRenderer";
3602
+ const PriorityAccordionRenderer = NoMemoPriorityAccordionRenderer;
3603
+
3604
+ function getStatusRendererClassName(cellValue, columnName) {
3605
+ if (cellValue === void 0)
3606
+ return "";
3607
+ const cellValueDate = cellValue.split(" ")[0];
3608
+ const cellValueHour = cellValue.split(" ")[1] ?? "00:00:00";
3609
+ const dateFormat = getDateFormat();
3610
+ const currentDate = dayjs();
3611
+ const currentHour = Number(dayjs().format("HHmm"));
3612
+ const queriedDate = dayjs(cellValueDate, dateFormat);
3613
+ const queriedHour = Number(dayjs(cellValueHour, dateFormat));
3614
+ let statusClassName = "";
3615
+ if (currentDate >= queriedDate) {
3616
+ statusClassName = columnName;
3617
+ }
3618
+ if (!queriedHour)
3619
+ return statusClassName;
3620
+ if (currentDate <= queriedDate && currentHour < queriedHour) {
3621
+ statusClassName = columnName;
3622
+ }
3623
+ return statusClassName;
3624
+ }
3625
+ const NoMemoStatusRenderer = React.forwardRef(
3626
+ ({
3627
+ cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3628
+ column,
3629
+ row,
3630
+ ...props
3631
+ }, currentRef) => {
3632
+ const taskStatusClassName = getStatusRendererClassName(
3633
+ children,
3634
+ column.name
3635
+ );
3636
+ return /* @__PURE__ */ jsx(
3637
+ "td",
3638
+ {
3639
+ ...props,
3640
+ ...cell,
3641
+ ref: currentRef,
3642
+ className: taskStatusClassName,
3643
+ children
3644
+ }
3645
+ );
3646
+ }
3647
+ );
3648
+ NoMemoStatusRenderer.displayName = "StatusRenderer";
3649
+ const StatusRenderer = NoMemoStatusRenderer;
3650
+
3651
+ const NoMemoStatusAccordionRenderer = React.forwardRef(({ cell, column }, currentRef) => {
3652
+ const taskStatusClassName = getStatusRendererClassName(
3653
+ cell.children,
3654
+ column.name
3655
+ );
3656
+ return /* @__PURE__ */ jsxs(Box, { ref: currentRef, children: [
3657
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3658
+ column.label ?? column.name,
3659
+ ": "
3660
+ ] }),
3661
+ /* @__PURE__ */ jsx(Box, { as: "span", className: taskStatusClassName, children: cell.children })
3662
+ ] });
3663
+ });
3664
+ NoMemoStatusAccordionRenderer.displayName = "StatusAccordionRenderer";
3665
+ const StatusAccordionRenderer = NoMemoStatusAccordionRenderer;
3666
+
3667
+ export { AccordionCell, AccordionDocNameCellRenderer, AccordionElement, AccordionHTMLCellRenderer, AccordionRenderer, Additional, AdditionalColumnDefaultRenderer, Controller2, DefaultCellRenderer, DefaultRowRenderer, DocNameCellRenderer, HTMLCellRenderer, IsLoadingRenderer, NoEllipsisCellRenderer, NoRegistersRenderer, Pagination, PriorityAccordionRenderer, PriorityRenderer, Responsive, ResponsiveTable, ResponsiveTableContext, RowStatesRenderer, Sort, StatusAccordionRenderer, StatusRenderer, TableRenderer, defaultLabels, getPriorityHandler, getStatusRendererClassName, makeAccordionAsyncRenderer, makeAsyncRenderer, makeController2, responsiveTableActions, responsiveTableStore, useResponsiveTable, useResponsiveTableContext };
25
3668
  //# sourceMappingURL=index.js.map