@apia/table 2.0.9 → 2.0.11

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/Cell.js +52 -0
  2. package/dist/Cell.js.map +1 -0
  3. package/dist/FilterCell.js +68 -0
  4. package/dist/FilterCell.js.map +1 -0
  5. package/dist/Header.js +171 -0
  6. package/dist/Header.js.map +1 -0
  7. package/dist/HeaderCell.js +223 -0
  8. package/dist/HeaderCell.js.map +1 -0
  9. package/dist/KeyHandler.js +28 -0
  10. package/dist/KeyHandler.js.map +1 -0
  11. package/dist/ResponsiveTable.d.ts +8 -0
  12. package/dist/ResponsiveTable.d.ts.map +1 -0
  13. package/dist/ResponsiveTable.js +29 -0
  14. package/dist/ResponsiveTable.js.map +1 -0
  15. package/dist/ResponsiveTableContext.d.ts +8 -0
  16. package/dist/ResponsiveTableContext.d.ts.map +1 -0
  17. package/dist/ResponsiveTableContext.js +143 -0
  18. package/dist/ResponsiveTableContext.js.map +1 -0
  19. package/dist/Row.js +230 -0
  20. package/dist/Row.js.map +1 -0
  21. package/dist/SeparatorCell.js +20 -0
  22. package/dist/SeparatorCell.js.map +1 -0
  23. package/dist/StateCell.js +19 -0
  24. package/dist/StateCell.js.map +1 -0
  25. package/dist/filters/RangeFilter.js +61 -0
  26. package/dist/filters/RangeFilter.js.map +1 -0
  27. package/dist/index.d.ts +24 -787
  28. package/dist/index.js +24 -3648
  29. package/dist/index.js.map +1 -1
  30. package/dist/renderers/AccordionCell.d.ts +15 -0
  31. package/dist/renderers/AccordionCell.d.ts.map +1 -0
  32. package/dist/renderers/AccordionCell.js +23 -0
  33. package/dist/renderers/AccordionCell.js.map +1 -0
  34. package/dist/renderers/AccordionDocNameCellRenderer.d.ts +11 -0
  35. package/dist/renderers/AccordionDocNameCellRenderer.d.ts.map +1 -0
  36. package/dist/renderers/AccordionDocNameCellRenderer.js +39 -0
  37. package/dist/renderers/AccordionDocNameCellRenderer.js.map +1 -0
  38. package/dist/renderers/AccordionElement.d.ts +11 -0
  39. package/dist/renderers/AccordionElement.d.ts.map +1 -0
  40. package/dist/renderers/AccordionElement.js +115 -0
  41. package/dist/renderers/AccordionElement.js.map +1 -0
  42. package/dist/renderers/AccordionHTMLCellRenderer.d.ts +8 -0
  43. package/dist/renderers/AccordionHTMLCellRenderer.d.ts.map +1 -0
  44. package/dist/renderers/AccordionHTMLCellRenderer.js +37 -0
  45. package/dist/renderers/AccordionHTMLCellRenderer.js.map +1 -0
  46. package/dist/renderers/AccordionRenderer.d.ts +6 -0
  47. package/dist/renderers/AccordionRenderer.d.ts.map +1 -0
  48. package/dist/renderers/AccordionRenderer.js +76 -0
  49. package/dist/renderers/AccordionRenderer.js.map +1 -0
  50. package/dist/renderers/AdditionalColumnDefaultRenderer.d.ts +7 -0
  51. package/dist/renderers/AdditionalColumnDefaultRenderer.d.ts.map +1 -0
  52. package/dist/renderers/AdditionalColumnDefaultRenderer.js +31 -0
  53. package/dist/renderers/AdditionalColumnDefaultRenderer.js.map +1 -0
  54. package/dist/renderers/DefaultCellRenderer.d.ts +11 -0
  55. package/dist/renderers/DefaultCellRenderer.d.ts.map +1 -0
  56. package/dist/renderers/DefaultCellRenderer.js +49 -0
  57. package/dist/renderers/DefaultCellRenderer.js.map +1 -0
  58. package/dist/renderers/DefaultRowRenderer.d.ts +6 -0
  59. package/dist/renderers/DefaultRowRenderer.d.ts.map +1 -0
  60. package/dist/renderers/DefaultRowRenderer.js +26 -0
  61. package/dist/renderers/DefaultRowRenderer.js.map +1 -0
  62. package/dist/renderers/DocNameCellRenderer.d.ts +10 -0
  63. package/dist/renderers/DocNameCellRenderer.d.ts.map +1 -0
  64. package/dist/renderers/DocNameCellRenderer.js +43 -0
  65. package/dist/renderers/DocNameCellRenderer.js.map +1 -0
  66. package/dist/renderers/HTMLCellRenderer.d.ts +8 -0
  67. package/dist/renderers/HTMLCellRenderer.d.ts.map +1 -0
  68. package/dist/renderers/HTMLCellRenderer.js +29 -0
  69. package/dist/renderers/HTMLCellRenderer.js.map +1 -0
  70. package/dist/renderers/IsLoadingRenderer.d.ts +6 -0
  71. package/dist/renderers/IsLoadingRenderer.d.ts.map +1 -0
  72. package/dist/renderers/IsLoadingRenderer.js +9 -0
  73. package/dist/renderers/IsLoadingRenderer.js.map +1 -0
  74. package/dist/renderers/NoRegistersRenderer.d.ts +6 -0
  75. package/dist/renderers/NoRegistersRenderer.d.ts.map +1 -0
  76. package/dist/renderers/NoRegistersRenderer.js +11 -0
  77. package/dist/renderers/NoRegistersRenderer.js.map +1 -0
  78. package/dist/renderers/PriorityAccordionRenderer.d.ts +6 -0
  79. package/dist/renderers/PriorityAccordionRenderer.d.ts.map +1 -0
  80. package/dist/renderers/PriorityAccordionRenderer.js +36 -0
  81. package/dist/renderers/PriorityAccordionRenderer.js.map +1 -0
  82. package/dist/renderers/PriorityRenderer.d.ts +9 -0
  83. package/dist/renderers/PriorityRenderer.d.ts.map +1 -0
  84. package/dist/renderers/PriorityRenderer.js +46 -0
  85. package/dist/renderers/PriorityRenderer.js.map +1 -0
  86. package/dist/renderers/RowStatesRenderer.d.ts +9 -0
  87. package/dist/renderers/RowStatesRenderer.d.ts.map +1 -0
  88. package/dist/renderers/RowStatesRenderer.js +34 -0
  89. package/dist/renderers/RowStatesRenderer.js.map +1 -0
  90. package/dist/renderers/StatusAccordionRenderer.d.ts +6 -0
  91. package/dist/renderers/StatusAccordionRenderer.d.ts.map +1 -0
  92. package/dist/renderers/StatusAccordionRenderer.js +23 -0
  93. package/dist/renderers/StatusAccordionRenderer.js.map +1 -0
  94. package/dist/renderers/StatusRenderer.d.ts +9 -0
  95. package/dist/renderers/StatusRenderer.d.ts.map +1 -0
  96. package/dist/renderers/StatusRenderer.js +54 -0
  97. package/dist/renderers/StatusRenderer.js.map +1 -0
  98. package/dist/renderers/TableRenderer.d.ts +6 -0
  99. package/dist/renderers/TableRenderer.d.ts.map +1 -0
  100. package/dist/renderers/TableRenderer.js +50 -0
  101. package/dist/renderers/TableRenderer.js.map +1 -0
  102. package/dist/renderers/makeAccordionAsyncRenderer.d.ts +9 -0
  103. package/dist/renderers/makeAccordionAsyncRenderer.d.ts.map +1 -0
  104. package/dist/renderers/makeAccordionAsyncRenderer.js +35 -0
  105. package/dist/renderers/makeAccordionAsyncRenderer.js.map +1 -0
  106. package/dist/renderers/makeAsyncRenderer.d.ts +10 -0
  107. package/dist/renderers/makeAsyncRenderer.d.ts.map +1 -0
  108. package/dist/renderers/makeAsyncRenderer.js +47 -0
  109. package/dist/renderers/makeAsyncRenderer.js.map +1 -0
  110. package/dist/store/index.d.ts +72 -0
  111. package/dist/store/index.d.ts.map +1 -0
  112. package/dist/store/index.js +131 -0
  113. package/dist/store/index.js.map +1 -0
  114. package/dist/store/selection/getInitialState.js +22 -0
  115. package/dist/store/selection/getInitialState.js.map +1 -0
  116. package/dist/store/selection/getReduxActions.js +42 -0
  117. package/dist/store/selection/getReduxActions.js.map +1 -0
  118. package/dist/store/selection/handleKey.js +143 -0
  119. package/dist/store/selection/handleKey.js.map +1 -0
  120. package/dist/store/selection/makeKeyHandler.js +336 -0
  121. package/dist/store/selection/makeKeyHandler.js.map +1 -0
  122. package/dist/store/selection/setNewFocused.js +101 -0
  123. package/dist/store/selection/setNewFocused.js.map +1 -0
  124. package/dist/store/selection/types.d.ts +150 -0
  125. package/dist/store/selection/types.d.ts.map +1 -0
  126. package/dist/store/selection/useDomProps.js +181 -0
  127. package/dist/store/selection/useDomProps.js.map +1 -0
  128. package/dist/store/types.d.ts +19 -0
  129. package/dist/store/types.d.ts.map +1 -0
  130. package/dist/types.d.ts +315 -0
  131. package/dist/types.d.ts.map +1 -0
  132. package/dist/types.js +6 -0
  133. package/dist/types.js.map +1 -0
  134. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -1,3649 +1,25 @@
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
- const widget = cell2?.querySelector(getFocusSelector());
1783
- if (cell2 && widget) {
1784
- widget.focus();
1785
- cell2.tabIndex = -1;
1786
- }
1787
- }
1788
- }
1789
- }
1790
- );
1791
- };
1792
- const Cell = React.memo(NoMemoCell);
1793
-
1794
- const NoMemoRow = ({ rowIndex }) => {
1795
- const { name } = useResponsiveTableContext();
1796
- const { columns, hasNonAdditionalFilters, isScrolledIntoView } = useResponsiveTable((global) => {
1797
- const tableState = global.responsiveTableSlice[name];
1798
- return {
1799
- columns: tableState?.columns ?? [],
1800
- hasNonAdditionalFilters: tableState?.hasNonAdditionalFilters,
1801
- isScrolledIntoView: tableState.scrollIntoViewRow === rowIndex
1802
- };
1803
- }, shallowEqual);
1804
- const row = useResponsiveTable(
1805
- (global) => global.responsiveTableSlice[name].rows[rowIndex],
1806
- shallowEqual
1807
- );
1808
- const additionalCells = useResponsiveTable(
1809
- (global) => {
1810
- const tableState = global.responsiveTableSlice[name];
1811
- return tableState.columns.map(
1812
- (current, index) => current.showAsAdditional ? {
1813
- index,
1814
- column: current
1815
- } : null
1816
- ).filter(
1817
- (current) => !!current
1818
- ).map((current) => {
1819
- return {
1820
- cell: tableState.rows[rowIndex]?.cells[current.index],
1821
- column: current.column,
1822
- columnIndex: current.index
1823
- };
1824
- });
1825
- },
1826
- (currentValue, newValue) => {
1827
- return currentValue.reduce(
1828
- (accumulatedBoolean, currentCell, cellIndex) => {
1829
- return accumulatedBoolean && shallowEqual(currentCell, newValue[cellIndex]);
1830
- },
1831
- true
1832
- );
1833
- }
1834
- );
1835
- const { isDragging, isExpanded, shouldForbidSelection } = useResponsiveTable(
1836
- (global) => {
1837
- const tableState = global.responsiveTableSlice[name];
1838
- return {
1839
- isExpanded: tableState.expandedRows.includes(rowIndex),
1840
- isDragging: tableState.draggingRow === rowIndex,
1841
- shouldForbidSelection: tableState.rows[rowIndex]?.forbidSelection
1842
- };
1843
- },
1844
- shallowEqual
1845
- );
1846
- const domProps = useDomProps(
1847
- "tr",
1848
- {
1849
- isThisRowExpanded: isExpanded,
1850
- rowIndex
1851
- },
1852
- domPropsSelector(name)
1853
- );
1854
- const expandedRowDomProps = useDomProps(
1855
- "tr",
1856
- {
1857
- isTheExpandedRow: true,
1858
- rowIndex
1859
- },
1860
- domPropsSelector(name)
1861
- );
1862
- const handleExpandedState = React.useCallback(
1863
- (ev) => {
1864
- const willBeExpanded = typeof ev === "boolean" ? ev : !isExpanded;
1865
- if (!willBeExpanded)
1866
- responsiveTableStore.dispatch(
1867
- responsiveTableActions.update({
1868
- tableName: name,
1869
- expandedRows: responsiveTableStore.getState().responsiveTableSlice[name].expandedRows.filter((current) => current !== rowIndex)
1870
- })
1871
- );
1872
- else
1873
- responsiveTableStore.dispatch(
1874
- responsiveTableActions.update({
1875
- tableName: name,
1876
- expandedRows: [
1877
- ...responsiveTableStore.getState().responsiveTableSlice[name].expandedRows,
1878
- rowIndex
1879
- ]
1880
- })
1881
- );
1882
- },
1883
- [isExpanded, name, rowIndex]
1884
- );
1885
- const statesCount = useResponsiveTable((globalState) => {
1886
- const state = globalState.responsiveTableSlice[name];
1887
- return state?.statesColumns ?? 0;
1888
- }, shallowEqual);
1889
- const states = React.useMemo(
1890
- () => (row.states ?? []).map((current) => ({ ...current, id: uniqueId() })),
1891
- [row.states]
1892
- );
1893
- const { ref, ...additionalCellDomProps } = useDomProps(
1894
- "additionalTd",
1895
- { rowIndex },
1896
- domPropsSelector(name)
1897
- );
1898
- const Renderer = React.useMemo(
1899
- () => row.renderer ?? DefaultRowRenderer,
1900
- [row.renderer]
1901
- );
1902
- const hasScrolled = useRef(false);
1903
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1904
- /* @__PURE__ */ jsx(
1905
- Renderer,
1906
- {
1907
- ...domProps,
1908
- row,
1909
- rowIndex,
1910
- 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" : ""}`,
1911
- onKeyDown: React.useCallback(
1912
- (ev) => {
1913
- if (ev.key.toLowerCase() === "arrowleft" && ev.ctrlKey) {
1914
- ev.preventDefault();
1915
- ev.stopPropagation();
1916
- handleExpandedState(false);
1917
- }
1918
- if (ev.key.toLowerCase() === "arrowright" && ev.ctrlKey) {
1919
- ev.preventDefault();
1920
- ev.stopPropagation();
1921
- handleExpandedState(true);
1922
- }
1923
- },
1924
- [handleExpandedState]
1925
- ),
1926
- ...{
1927
- ref: (el) => {
1928
- if (el && isScrolledIntoView && !hasScrolled.current) {
1929
- hasScrolled.current = true;
1930
- scrollParentIntoElement(el);
1931
- }
1932
- }
1933
- },
1934
- children: row.separator ? /* @__PURE__ */ jsx(
1935
- SeparatorCell,
1936
- {
1937
- colSpan: (additionalCells.length > 0 || hasNonAdditionalFilters ? 1 : 0) + statesCount + columns.filter((current) => !current.showAsAdditional).length,
1938
- rowIndex
1939
- }
1940
- ) : /* @__PURE__ */ jsxs(Fragment, { children: [
1941
- (additionalCells.length > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx("td", { className: "additionalInfo__cell", ...additionalCellDomProps, children: additionalCells.length > 0 && /* @__PURE__ */ jsx(
1942
- IconButton,
1943
- {
1944
- size: "Lg",
1945
- ...getVariant("icon-outline"),
1946
- icon: isExpanded ? MdKeyboardArrowDown : MdKeyboardArrowRight,
1947
- "aria-label": isExpanded ? getLabel("lblCollapseRow").text : getLabel("lblExpandRow").text,
1948
- className: "moreInformationButton",
1949
- onClick: handleExpandedState
1950
- }
1951
- ) }),
1952
- Array(statesCount).fill("").map((_, i) => {
1953
- return /* @__PURE__ */ jsx(
1954
- StateCell,
1955
- {
1956
- index: i,
1957
- state: states[i],
1958
- rowIndex
1959
- },
1960
- states[i]?.id ?? i
1961
- );
1962
- }),
1963
- columns.map((current, actualColumnIndex) => ({
1964
- ...current,
1965
- actualColumnIndex
1966
- })).filter((current) => !current.showAsAdditional).map((current, inTableColumnIndex) => {
1967
- if (current.hidden)
1968
- return null;
1969
- return /* @__PURE__ */ jsx(
1970
- Cell,
1971
- {
1972
- columnIndex: current.actualColumnIndex,
1973
- rowIndex,
1974
- inTableColumnIndex
1975
- },
1976
- current.name
1977
- );
1978
- })
1979
- ] })
1980
- }
1981
- ),
1982
- isExpanded && /* @__PURE__ */ jsx("tr", { className: "expandedRow", ...expandedRowDomProps, children: /* @__PURE__ */ jsx(
1983
- "td",
1984
- {
1985
- colSpan: columns.length - additionalCells.length + states.length + 1,
1986
- children: /* @__PURE__ */ jsx(Box, { className: "responsiveTable__additionalInfoContainer", children: additionalCells.map((current) => {
1987
- const { Renderer: ColumnRenderer } = current.column;
1988
- if (ColumnRenderer)
1989
- return /* @__PURE__ */ jsx(
1990
- ColumnRenderer,
1991
- {
1992
- cell: current.cell,
1993
- column: current.column,
1994
- row
1995
- },
1996
- current.column.name
1997
- );
1998
- return /* @__PURE__ */ jsx(
1999
- AdditionalColumnDefaultRenderer,
2000
- {
2001
- cell: current.cell,
2002
- column: current.column,
2003
- row
2004
- },
2005
- current.column.name
2006
- );
2007
- }) })
2008
- }
2009
- ) })
2010
- ] });
2011
- };
2012
- const Row = React.memo(NoMemoRow);
2013
-
2014
- const NoRegistersRenderer = () => {
2015
- const { labels } = useResponsiveTableContext();
2016
- return /* @__PURE__ */ jsx(Box, { className: "no__registers", children: labels.noRegisters });
2017
- };
2018
-
2019
- const NoMemoTableRenderer = ({ variant }) => {
2020
- const { name, label, labels } = useResponsiveTableContext();
2021
- const domProps = useDomProps(
2022
- "table",
2023
- {},
2024
- (global) => global.responsiveTableSlice[name]
2025
- );
2026
- const rows = useResponsiveTable((global) => {
2027
- const tableState = global.responsiveTableSlice[name];
2028
- return tableState?.rows?.map((current) => current.id);
2029
- }, shallowEqual);
2030
- const columnsCount = useResponsiveTable(
2031
- (global) => (global.responsiveTableSlice[name]?.nonAdditionalColumnsCount ?? 0) + (global.responsiveTableSlice[name]?.hasNonAdditionalFilters ? 1 : 0) + (global.responsiveTableSlice[name]?.statesColumns ?? 0) + (global.responsiveTableSlice[name]?.columns.find(
2032
- (current) => current.showAsAdditional
2033
- ) ? 1 : 0)
2034
- );
2035
- const rowsCount = useResponsiveTable(
2036
- (global) => global.responsiveTableSlice[name]?.rows.length || 0
2037
- );
2038
- return /* @__PURE__ */ jsxs(
2039
- Box,
2040
- {
2041
- ...domProps,
2042
- as: "table",
2043
- className: "responsiveTable__table",
2044
- ...getVariant(variant || "layout.common.tables.primary"),
2045
- "aria-label": label,
2046
- children: [
2047
- /* @__PURE__ */ jsx(Header, {}),
2048
- /* @__PURE__ */ jsx("tbody", { children: rowsCount > 0 ? rows?.map((row, index) => {
2049
- return /* @__PURE__ */ jsx(Row, { rowIndex: index }, row ?? `${row}-${index}`);
2050
- }) : labels.noRegisters ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columnsCount, children: /* @__PURE__ */ jsx(NoRegistersRenderer, {}) }) }) : null })
2051
- ]
2052
- }
2053
- );
2054
- };
2055
- const TableRenderer = React.memo(NoMemoTableRenderer);
2056
-
2057
- const NoMemoAccordionCell = ({ cell, column }) => {
2058
- return /* @__PURE__ */ jsxs(
2059
- Box,
2060
- {
2061
- className: `responsiveTable__accordionElement__column ${cell.className ?? ""}`,
2062
- children: [
2063
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
2064
- column.label ?? column.name,
2065
- ": "
2066
- ] }),
2067
- /* @__PURE__ */ jsx(Box, { as: "span", sx: { color: cell.color, background: cell.background }, children: cell?.children })
2068
- ]
2069
- },
2070
- column.name
2071
- );
2072
- };
2073
- const AccordionCell = NoMemoAccordionCell;
2074
-
2075
- const NoMemoAccordionElement = ({ row, rowIndex }) => {
2076
- const { name } = useResponsiveTableContext();
2077
- const indexColumns = useResponsiveTable((global) => {
2078
- const tableState = global.responsiveTableSlice[name];
2079
- return tableState?.accordionIndexColumns;
2080
- }, shallowEqual);
2081
- const columns = useResponsiveTable((global) => {
2082
- const tableState = global.responsiveTableSlice[name];
2083
- return tableState?.columns;
2084
- }, shallowEqual);
2085
- const title = React.useMemo(() => {
2086
- if (row.title)
2087
- return row.title;
2088
- if (Array.isArray(indexColumns))
2089
- return indexColumns.map(
2090
- (current) => (
2091
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2092
- row.cells[current.index].title || row.cells[current.index].children
2093
- )
2094
- ).join(" | ");
2095
- return row.cells[0].title ?? row.cells[0].children;
2096
- }, [indexColumns, row.cells, row.title]);
2097
- const isSelected = useResponsiveTable(
2098
- (global) => global.responsiveTableSlice[name].allowSelection !== false ? global.responsiveTableSlice[name].selectedRows.includes(rowIndex) : void 0
2099
- );
2100
- const isFocused = useResponsiveTable(
2101
- (global) => global.responsiveTableSlice[name].focusedRow === rowIndex
2102
- );
2103
- const buttonProps = useMemo(
2104
- () => ({
2105
- title,
2106
- ariaLabel: title,
2107
- label: title,
2108
- checked: isSelected,
2109
- onChange: (isChecked) => {
2110
- const isMultiple = responsiveTableStore.getState().responsiveTableSlice[name].isMultiple;
2111
- responsiveTableStore.dispatch(
2112
- responsiveTableActions.update({
2113
- tableName: name,
2114
- selectedRows: isMultiple ? isChecked ? [
2115
- ...responsiveTableStore.getState().responsiveTableSlice[name].selectedRows,
2116
- rowIndex
2117
- ] : responsiveTableStore.getState().responsiveTableSlice[name].selectedRows.filter((current) => current !== rowIndex) : [rowIndex]
2118
- })
2119
- );
2120
- },
2121
- tabIndex: isFocused ? 0 : -1,
2122
- rightButtons: row.accordionButtonProps?.rightButtons,
2123
- onUserPressEnter: row.accordionButtonProps?.onUserPressEnter,
2124
- domButtonProps: {
2125
- buttonSx: {
2126
- "&.accordion__item__button .accordion__item__button__label": {
2127
- color: row.color
2128
- }
2129
- }
2130
- }
2131
- }),
2132
- [
2133
- isFocused,
2134
- isSelected,
2135
- name,
2136
- row.accordionButtonProps?.onUserPressEnter,
2137
- row.accordionButtonProps?.rightButtons,
2138
- row.color,
2139
- rowIndex,
2140
- title
2141
- ]
2142
- );
2143
- if (!Array.isArray(indexColumns) || !columns)
2144
- return null;
2145
- return /* @__PURE__ */ jsxs(AccordionItem, { id: row.id, buttonProps, children: [
2146
- columns.map((currentColumn, columnIndex) => {
2147
- const Renderer = row.cells[columnIndex].AccordionRenderer ?? currentColumn.AccordionRenderer ?? AccordionCell;
2148
- return currentColumn.hideFromAccordion || currentColumn.showAsAdditional ? null : /* @__PURE__ */ jsx(
2149
- Renderer,
2150
- {
2151
- cell: row.cells[columnIndex],
2152
- column: currentColumn,
2153
- columnIndex,
2154
- row,
2155
- rowIndex
2156
- },
2157
- currentColumn.name
2158
- );
2159
- }),
2160
- columns.filter((current) => !!current.showAsAdditional).map((currentColumn, columnIndex) => {
2161
- const Renderer = row.cells[columnIndex].AccordionRenderer ?? currentColumn.AccordionRenderer ?? AccordionCell;
2162
- return currentColumn.hideFromAccordion ? null : /* @__PURE__ */ jsx(
2163
- Renderer,
2164
- {
2165
- cell: row.cells[columnIndex],
2166
- column: currentColumn,
2167
- columnIndex,
2168
- row,
2169
- rowIndex
2170
- },
2171
- currentColumn.name
2172
- );
2173
- })
2174
- ] });
2175
- };
2176
- const AccordionElement = memo(NoMemoAccordionElement);
2177
-
2178
- const NoMemoAccordionRenderer = () => {
2179
- const { name } = useResponsiveTableContext();
2180
- const { columns, rows } = useResponsiveTable((global) => {
2181
- const tableState = global.responsiveTableSlice[name];
2182
- return {
2183
- columns: tableState?.columns,
2184
- rows: tableState?.rows
2185
- };
2186
- }, shallowEqual);
2187
- React.useEffect(() => {
2188
- if (columns && rows) {
2189
- const markedAsTitleColumns = [];
2190
- columns.forEach((column, index) => {
2191
- if (column.showInAccordionTitle)
2192
- markedAsTitleColumns.push({ column, index });
2193
- });
2194
- if (markedAsTitleColumns.length > 0) {
2195
- responsiveTableStore.dispatch(
2196
- responsiveTableActions.update({
2197
- tableName: name,
2198
- accordionIndexColumns: markedAsTitleColumns
2199
- })
2200
- );
2201
- } else {
2202
- const columnsLength = columns.length;
2203
- let indexColumn = null;
2204
- let currentIndex = 0;
2205
- while (!indexColumn && currentIndex < columns.length) {
2206
- let isAnyEmptyRow = false;
2207
- for (const row of rows) {
2208
- if (!row.cells[currentIndex].children) {
2209
- isAnyEmptyRow = true;
2210
- break;
2211
- }
2212
- }
2213
- if (!isAnyEmptyRow && columns[currentIndex]) {
2214
- indexColumn = columns[currentIndex];
2215
- } else {
2216
- currentIndex += 1;
2217
- if (currentIndex === columnsLength)
2218
- break;
2219
- }
2220
- }
2221
- if (!indexColumn) {
2222
- [indexColumn] = columns;
2223
- currentIndex = 0;
2224
- }
2225
- responsiveTableStore.dispatch(
2226
- responsiveTableActions.update({
2227
- tableName: name,
2228
- accordionIndexColumns: [
2229
- { column: indexColumn, index: currentIndex }
2230
- ]
2231
- })
2232
- );
2233
- }
2234
- }
2235
- }, [columns, name, rows]);
2236
- return /* @__PURE__ */ jsxs(Accordion, { children: [
2237
- !rows || rows.length === 0 && /* @__PURE__ */ jsx(NoRegistersRenderer, {}),
2238
- rows?.map((current, rowIndex) => /* @__PURE__ */ jsx(AccordionElement, { row: current, rowIndex }, current.id))
2239
- ] });
2240
- };
2241
- const AccordionRenderer = React.memo(NoMemoAccordionRenderer);
2242
-
2243
- const domPropsSelector = (name) => (global) => global.responsiveTableSlice[name];
2244
- const NoMemoResponsiveTable = React.forwardRef(({ className, variant, ...props }, ref) => {
2245
- const breakpoint = useBreakpointIndex({ defaultIndex: 3 });
2246
- const { currentBreakPoint } = useResponsiveTableContext();
2247
- const actualBreakpoint = currentBreakPoint ?? breakpoint;
2248
- return /* @__PURE__ */ jsx(
2249
- Box,
2250
- {
2251
- ...props,
2252
- ...getVariant("layout.common.tables.responsive"),
2253
- className: `responsiveTable__wrapper ${className ?? ""}`,
2254
- ref,
2255
- children: actualBreakpoint >= 3 ? /* @__PURE__ */ jsx(KeyHandler, { children: /* @__PURE__ */ jsx(TableRenderer, { variant }) }) : /* @__PURE__ */ jsx(AccordionRenderer, {})
2256
- }
2257
- );
2258
- });
2259
- NoMemoResponsiveTable.displayName = "ResponsiveTable";
2260
- const ResponsiveTable = React.memo(NoMemoResponsiveTable);
2261
-
2262
- const NoMemoSort = ({ tableName }) => {
2263
- const { name, onSortChange } = useResponsiveTableContext(tableName);
2264
- const columns = useResponsiveTable((global) => {
2265
- return global.responsiveTableSlice[name]?.columns;
2266
- }, shallowEqual);
2267
- return /* @__PURE__ */ jsx(Fragment, { children: columns?.map((column, columnIndex) => {
2268
- return column.showAsAdditional || column.allowSorting === false ? null : /* @__PURE__ */ jsxs(Label, { children: [
2269
- /* @__PURE__ */ jsx(Box, { as: "span", children: column.label ?? column.name }),
2270
- /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
2271
- Select,
2272
- {
2273
- value: column.currentSorting === null ? "" : column.currentSorting,
2274
- onChange: (ev) => {
2275
- if (onSortChange)
2276
- onSortChange({
2277
- columnIndex,
2278
- column,
2279
- name: column.name,
2280
- sortValue: ev.target.value === "" ? null : ev.target.value
2281
- });
2282
- },
2283
- children: [
2284
- /* @__PURE__ */ jsx("option", { value: "" }),
2285
- /* @__PURE__ */ jsx("option", { value: "A", children: window.ORDER_ASC_LABEL }),
2286
- /* @__PURE__ */ jsx("option", { value: "D", children: window.ORDER_DESC_LABEL })
2287
- ]
2288
- }
2289
- ) })
2290
- ] }, column.name);
2291
- }) });
2292
- };
2293
- const Sort = React.memo(NoMemoSort);
2294
-
2295
- dayjs.extend(customParseFormat);
2296
- const dateFormat = getDateFormat();
2297
- function controlDatesOrder(first, last) {
2298
- if (!first || !last)
2299
- return true;
2300
- if (dayjs(last, dateFormat).isBefore(dayjs(first, dateFormat))) {
2301
- return window.MSG_FEC_FIN_MAY_FEC_INI;
2302
- }
2303
- return true;
2304
- }
2305
- const NoMemoInnerRender = React.forwardRef(
2306
- ({
2307
- filters,
2308
- tableName
2309
- }, ref) => {
2310
- const { onFilterBlur, onFilterChange, onFilterPressEnter, name } = useResponsiveTableContext(tableName);
2311
- const [lastEmittedValue, setLastEmittedValue] = React.useState(null);
2312
- const [lastEmittedValueByPartner, setLastEmittedValueByPartner] = React.useState(null);
2313
- return /* @__PURE__ */ jsx(Box, { ref, className: "filtersRender", children: filters?.map((filter, key) => {
2314
- if (filter.hide)
2315
- return null;
2316
- const isDate = filter.type === "D" || filter.type === "date";
2317
- const filterToId = filter.filterToId ?? `${filter.id}i`;
2318
- const filterTo = {
2319
- ...filter,
2320
- hide: filter.filterToId === void 0,
2321
- id: filterToId,
2322
- currentValue: filter.filterToValue ?? "",
2323
- required: false
2324
- };
2325
- const column = responsiveTableStore.getState().responsiveTableSlice[name].columns.find((current) => current.name === filter.column);
2326
- const filterTitle = filter.title || column?.label || column?.title || column?.name || "noFilterNorColumnTitle";
2327
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2328
- /* @__PURE__ */ jsx(
2329
- Box,
2330
- {
2331
- className: filter.type === "D" || filter.type === "date" ? "twoColumns" : "",
2332
- children: /* @__PURE__ */ jsxs(
2333
- Label,
2334
- {
2335
- title: isDate ? window.LBL_DATE_FILTER_FROM_TOOLTIP : filterTitle,
2336
- children: [
2337
- window.SHOW_REQUIRED_POSITION !== "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: filter.required }),
2338
- /* @__PURE__ */ jsx(Box, { as: "span", children: isDate && !filter.hideToFilter ? formatMessage(window.LBL_DATE_FILTER_FROM_TXT, {
2339
- TOK1: filterTitle
2340
- }) : filterTitle }),
2341
- filter.isRange ? /* @__PURE__ */ jsx(RangeFilter, { filter }) : /* @__PURE__ */ jsx(
2342
- ApiaFilter,
2343
- {
2344
- filter,
2345
- onChange: (currentValue) => {
2346
- const result = controlDatesOrder(
2347
- currentValue,
2348
- lastEmittedValueByPartner
2349
- );
2350
- if (result === true) {
2351
- setLastEmittedValue(currentValue);
2352
- if (onFilterChange)
2353
- void onFilterChange({ ...filter, currentValue });
2354
- }
2355
- return result;
2356
- },
2357
- onBlur: (currentValue) => {
2358
- if (onFilterBlur)
2359
- void onFilterBlur({ ...filter, currentValue });
2360
- },
2361
- onPressEnter: (currentValue) => {
2362
- if (onFilterPressEnter)
2363
- void onFilterPressEnter({
2364
- ...filter,
2365
- currentValue
2366
- });
2367
- }
2368
- }
2369
- ),
2370
- window.SHOW_REQUIRED_POSITION === "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: filter.required })
2371
- ]
2372
- }
2373
- )
2374
- },
2375
- filter.id ?? filter.column ?? key
2376
- ),
2377
- isDate && !filter.hideToFilter && /* @__PURE__ */ jsx(
2378
- Box,
2379
- {
2380
- className: filter.type === "D" || filter.type === "date" ? "twoColumns" : "",
2381
- children: /* @__PURE__ */ jsxs(Label, { title: window.LBL_DATE_FILTER_TO_TOOLTIP, children: [
2382
- /* @__PURE__ */ jsx(Box, { as: "span", children: formatMessage(window.LBL_DATE_FILTER_TO_TXT, {
2383
- TOK1: filterTitle
2384
- }) }),
2385
- /* @__PURE__ */ jsx(
2386
- ApiaFilter,
2387
- {
2388
- filter: filterTo,
2389
- onChange: (currentValue) => {
2390
- const result = controlDatesOrder(
2391
- lastEmittedValue,
2392
- currentValue
2393
- );
2394
- if (result === true) {
2395
- setLastEmittedValueByPartner(currentValue);
2396
- if (onFilterChange)
2397
- void onFilterChange({
2398
- ...filter,
2399
- filterToId,
2400
- filterToValue: currentValue
2401
- });
2402
- }
2403
- return result;
2404
- },
2405
- onBlur: (currentValue) => {
2406
- if (onFilterBlur)
2407
- void onFilterBlur({
2408
- ...filter,
2409
- filterToId,
2410
- filterToValue: currentValue
2411
- });
2412
- },
2413
- onPressEnter: (currentValue) => {
2414
- if (onFilterPressEnter)
2415
- void onFilterPressEnter({
2416
- ...filter,
2417
- filterToId,
2418
- filterToValue: currentValue
2419
- });
2420
- }
2421
- }
2422
- )
2423
- ] })
2424
- }
2425
- )
2426
- ] }, filter.id ?? filter.column ?? key);
2427
- }) });
2428
- }
2429
- );
2430
- NoMemoInnerRender.displayName = "FiltersInnerRender";
2431
- const InnerRender = React.memo(NoMemoInnerRender);
2432
-
2433
- const NoMemoAdditional = ({ tableName }) => {
2434
- const { name } = useResponsiveTableContext(tableName);
2435
- const additionalFilters = useResponsiveTable((global) => {
2436
- const state = global.responsiveTableSlice[name];
2437
- return state?.filters.filter(
2438
- (current) => !current.group && (!current.isMeta && !state?.columns.find(
2439
- (search) => search.name === current.column && !current.asAdditional
2440
- ) || state?.columns.find(
2441
- (search) => search.name === current.column && search.showAsAdditional
2442
- ) || current.asAdditional)
2443
- );
2444
- }, shallowEqual);
2445
- return /* @__PURE__ */ jsx(InnerRender, { tableName, filters: additionalFilters });
2446
- };
2447
- const Additional = React.memo(NoMemoAdditional);
2448
-
2449
- const NoMemoResponsive = ({ tableName }) => {
2450
- const { name } = useResponsiveTableContext(tableName);
2451
- const nonAdditionalFilters = useResponsiveTable((global) => {
2452
- const state = global.responsiveTableSlice[name];
2453
- return state?.filters.filter(
2454
- (current) => !current.isMeta && state?.columns.find((search) => search.name === current.column)
2455
- );
2456
- }, shallowEqual);
2457
- return /* @__PURE__ */ jsx(
2458
- InnerRender,
2459
- {
2460
- tableName,
2461
- isResponsive: true,
2462
- filters: nonAdditionalFilters
2463
- }
2464
- );
2465
- };
2466
- const Responsive = React.memo(NoMemoResponsive);
2467
-
2468
- var __defProp$1 = Object.defineProperty;
2469
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2470
- var __publicField$1 = (obj, key, value) => {
2471
- __defNormalProp$1(obj, key + "" , value);
2472
- return value;
2473
- };
2474
- const maximizationPersist = {
2475
- getState(id) {
2476
- const current = persistentStorage.maximizationPersist ?? {};
2477
- return current[id];
2478
- },
2479
- setState(id, isMaximized) {
2480
- const current = persistentStorage.maximizationPersist ?? {};
2481
- current[id] = isMaximized;
2482
- persistentStorage.maximizationPersist = current;
2483
- }
2484
- };
2485
- class Maximization extends EventEmitter {
2486
- constructor() {
2487
- super(...arguments);
2488
- __publicField$1(this, "components", {});
2489
- }
2490
- checkComponentExists(id) {
2491
- return this.components[id] === void 0;
2492
- }
2493
- emit(eventName, params) {
2494
- if (eventName === "toggle") {
2495
- const { id, isMaximized } = params;
2496
- this.checkComponentExists(id);
2497
- if (!this.components[id])
2498
- return;
2499
- this.components[id].isMaximized = isMaximized ?? !this.components[id].isMaximized;
2500
- maximizationPersist.setState(id, this.components[id].isMaximized);
2501
- this.isMaximized(id);
2502
- super.emit(eventName, {
2503
- id,
2504
- isMaximized: this.components[id].isMaximized
2505
- });
2506
- }
2507
- }
2508
- isMaximized(id) {
2509
- this.checkComponentExists(id);
2510
- const selector = this.components[id]?.selector;
2511
- if (selector === void 0)
2512
- return void 0;
2513
- const content = typeof selector === "string" ? document.querySelector(selector) : selector?.();
2514
- if (content)
2515
- content.classList.toggle("maximized", this.components[id].isMaximized);
2516
- return this.components[id]?.isMaximized;
2517
- }
2518
- registerMaximizableComponent(id, selector) {
2519
- this.components[id] = {
2520
- selector: selector ?? this.components[id]?.selector,
2521
- isMaximized: false
2522
- // isDefaultMaximized ??
2523
- // (conf<boolean>('lists.persistMaximized', true, 'boolean')
2524
- // ? maximizationPersist.getState(id)
2525
- // : undefined) ??
2526
- // isConfDefaultMaximized,
2527
- };
2528
- }
2529
- toggleIsMaximized(id, isMaximized) {
2530
- this.emit("toggle", { id, isMaximized });
2531
- }
2532
- }
2533
- const maximizationController = new Maximization();
2534
- function useIsMaximized(id) {
2535
- React.useEffect(() => {
2536
- maximizationController.registerMaximizableComponent(id);
2537
- }, [id]);
2538
- const [isInnerMaximized, innerSetIsMaximized] = React.useState(
2539
- maximizationController.isMaximized(id) ?? false
2540
- );
2541
- React.useEffect(() => {
2542
- const handleToggle = ({
2543
- id: eventId,
2544
- isMaximized: eventIsMaximized
2545
- }) => {
2546
- if (id === eventId)
2547
- innerSetIsMaximized((current) => eventIsMaximized ?? !current);
2548
- };
2549
- const unsuscribe1 = maximizationController.on("toggle", handleToggle);
2550
- innerSetIsMaximized(
2551
- maximizationController.components[id].isMaximized ?? false
2552
- );
2553
- return () => {
2554
- unsuscribe1();
2555
- };
2556
- }, [id]);
2557
- return {
2558
- isMaximized: isInnerMaximized,
2559
- toggleIsMaximized: React.useCallback(
2560
- (isMaximized) => {
2561
- maximizationController.emit("toggle", { id, isMaximized });
2562
- },
2563
- [id]
2564
- )
2565
- };
2566
- }
2567
-
2568
- const NoMemoPagination = ({
2569
- appliedFilters,
2570
- areAllFiltersApplied,
2571
- className,
2572
- currentPage,
2573
- disabled,
2574
- disableReduced,
2575
- hasMore,
2576
- hideMaximizeButton,
2577
- hideRefreshButton,
2578
- isLoading,
2579
- isPerforming,
2580
- listId: outerListId,
2581
- onDeleteFilters,
2582
- onPageChange,
2583
- onRefresh,
2584
- pageCount,
2585
- recordsCount: outerRecordsCount,
2586
- reachedMax,
2587
- showMaximizeOnSmallBreakpoints,
2588
- variant = "primary"
2589
- }) => {
2590
- const numberPageCount = Number(pageCount);
2591
- const breakPoint = useBreakpointIndex();
2592
- const numberCurrentPage = Number(currentPage);
2593
- const recordsCount = outerRecordsCount;
2594
- const [internCurrentPage, setCurrentPage] = useState(
2595
- numberCurrentPage ?? 1
2596
- );
2597
- const [lastEmittedPage, setLastEmittedPage] = useState(
2598
- numberCurrentPage ?? 1
2599
- );
2600
- const [hasNoValue, setHasNoValue] = useState(false);
2601
- useEffect(() => {
2602
- setCurrentPage(numberCurrentPage);
2603
- }, [numberCurrentPage]);
2604
- const setCurrentAndDispatch = useCallback(
2605
- (page) => {
2606
- setCurrentPage(page);
2607
- onPageChange(page);
2608
- setLastEmittedPage(page);
2609
- },
2610
- [onPageChange]
2611
- );
2612
- const InputRef = createRef();
2613
- const listId = useResponsiveTableContext().name;
2614
- const { isMaximized, toggleIsMaximized } = useIsMaximized(
2615
- outerListId ?? listId
2616
- );
2617
- const options = [];
2618
- for (let i = 1; i <= numberPageCount; i++) {
2619
- options.push(i);
2620
- }
2621
- const [infoButtonRef, setInfoButtonRef] = React.useState(
2622
- null
2623
- );
2624
- const recordsCountLabel = `${window.GNR_TOT_RECORDS}: ${recordsCount}`;
2625
- const tooltipProps = React.useMemo(
2626
- () => ({
2627
- 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}`,
2628
- attachToElement: { current: infoButtonRef },
2629
- closeOnClickOut: true
2630
- // closeOnClickOutChecker(element) {
2631
- // return !getSpecificParent(element, (current) =>
2632
- // current.classList.contains('pagination__information'),
2633
- // );
2634
- // },
2635
- }),
2636
- [breakPoint, hasMore, infoButtonRef, reachedMax, recordsCountLabel]
2637
- );
2638
- return /* @__PURE__ */ jsxs(
2639
- Box,
2640
- {
2641
- as: "nav",
2642
- variant: `layout.common.components.pagination.${variant}`,
2643
- "aria-label": getLabel("lblQryParamPag").text,
2644
- className: `pagination ${numberPageCount <= 1 && !disableReduced ? "onlyRefresh" : ""} ${className ?? ""}`,
2645
- children: [
2646
- /* @__PURE__ */ jsxs(Box, { className: "pagination__leftToolbar", children: [
2647
- !hideMaximizeButton && (showMaximizeOnSmallBreakpoints || breakPoint > 4) && /* @__PURE__ */ jsx(
2648
- IconButton,
2649
- {
2650
- variant: "icon",
2651
- className: "pagination__fullScreenButton",
2652
- onClick: toggleIsMaximized.bind(toggleIsMaximized, void 0),
2653
- icon: !isMaximized ? "Maximize" : "Minimize",
2654
- title: !isMaximized ? window.LBL_MAXIMIZE : window.LBL_MINIMIZE,
2655
- "aria-label": !isMaximized ? window.LBL_MAXIMIZE : window.LBL_MINIMIZE,
2656
- iconSize: "Md"
2657
- }
2658
- ),
2659
- ((reachedMax || hasMore) && breakPoint > 3 || breakPoint <= 3) && className !== "grid__pagination" ? /* @__PURE__ */ jsx(
2660
- IconButton,
2661
- {
2662
- variant: "icon-primary",
2663
- icon: "Info",
2664
- className: `pagination__information ${reachedMax || hasMore ? "pagination__alertInfo" : ""}`,
2665
- onClick: () => ApiaUtil.instance.tooltips.open(tooltipProps),
2666
- ref: setInfoButtonRef,
2667
- iconSize: "Md",
2668
- "aria-label": window.BTN_FILE_INFO_TOOLTIP,
2669
- title: window.BTN_FILE_INFO_TOOLTIP
2670
- }
2671
- ) : "",
2672
- breakPoint > 3 && /* @__PURE__ */ jsx(
2673
- Box,
2674
- {
2675
- as: "span",
2676
- className: "recordsCounter pagination__deleteLabels",
2677
- title: recordsCountLabel,
2678
- children: recordsCount !== -1 && `${window.GNR_TOT_RECORDS}: ${recordsCount} `
2679
- }
2680
- )
2681
- ] }),
2682
- /* @__PURE__ */ jsx(Box, { className: "pagination__controls", children: (numberPageCount > 0 || disableReduced) && /* @__PURE__ */ jsxs(Fragment, { children: [
2683
- breakPoint > 2 && /* @__PURE__ */ jsx(
2684
- IconButton,
2685
- {
2686
- variant: "icon-primary",
2687
- disabled: disabled || internCurrentPage === 1 || isLoading || isPerforming,
2688
- "aria-label": window.NAV_FIRST_PAGE,
2689
- type: "button",
2690
- onClick: () => {
2691
- setCurrentAndDispatch(1);
2692
- },
2693
- icon: "First",
2694
- iconSize: "Sm"
2695
- }
2696
- ),
2697
- /* @__PURE__ */ jsx(
2698
- IconButton,
2699
- {
2700
- variant: "icon-primary",
2701
- disabled: disabled || internCurrentPage <= 1 || isLoading || isPerforming,
2702
- "aria-label": window.NAV_PREVIOUS_PAGE,
2703
- type: "button",
2704
- onClick: () => {
2705
- setCurrentAndDispatch(internCurrentPage - 1);
2706
- },
2707
- icon: "Previous",
2708
- iconSize: "Sm"
2709
- }
2710
- ),
2711
- breakPoint > 2 && /* @__PURE__ */ jsxs(Box, { className: "input", children: [
2712
- /* @__PURE__ */ jsx(
2713
- Input,
2714
- {
2715
- className: "pagination__controls__input",
2716
- "aria-label": window.NAV_INPUT_LABEL,
2717
- title: `${window.PAGE}: ${internCurrentPage} `,
2718
- ref: InputRef,
2719
- value: hasNoValue ? "" : internCurrentPage,
2720
- onKeyDown: (ev) => {
2721
- const regex = /([0-9])|(Backspace)|(Tab)/;
2722
- if (!ev.key.match(regex)) {
2723
- ev.stopPropagation();
2724
- ev.preventDefault();
2725
- }
2726
- if (ev.key === "Enter") {
2727
- ev.stopPropagation();
2728
- ev.preventDefault();
2729
- setCurrentAndDispatch(internCurrentPage);
2730
- }
2731
- },
2732
- onBlur: () => {
2733
- if (lastEmittedPage !== internCurrentPage) {
2734
- setCurrentAndDispatch(internCurrentPage);
2735
- }
2736
- },
2737
- onFocus: (ev) => {
2738
- ev.currentTarget.select();
2739
- },
2740
- onChange: (ev) => {
2741
- setHasNoValue(ev.target.value === "");
2742
- setCurrentPage(
2743
- Math.max(
2744
- 1,
2745
- Math.min(
2746
- noNaN(Number(ev.currentTarget.value)),
2747
- pageCount
2748
- )
2749
- )
2750
- );
2751
- },
2752
- disabled: disabled || isLoading || isPerforming
2753
- }
2754
- ),
2755
- " ",
2756
- "/",
2757
- " ",
2758
- /* @__PURE__ */ jsx(
2759
- Box,
2760
- {
2761
- as: "span",
2762
- title: recordsCount !== -1 ? `${window.GNR_TOT_RECORDS} ${recordsCount}` : window.NAV_INPUT_LABEL,
2763
- children: pageCount
2764
- }
2765
- )
2766
- ] }),
2767
- breakPoint <= 2 && /* @__PURE__ */ jsxs(
2768
- Select,
2769
- {
2770
- className: "pagination__selectPage",
2771
- value: internCurrentPage,
2772
- onChange: (e) => {
2773
- setCurrentAndDispatch(Number(e.target.value));
2774
- },
2775
- children: [
2776
- /* @__PURE__ */ jsxs("option", { disabled: true, children: [
2777
- "Total: ",
2778
- numberPageCount
2779
- ] }),
2780
- options.map((current) => {
2781
- return /* @__PURE__ */ jsx("option", { children: current }, current);
2782
- })
2783
- ]
2784
- }
2785
- ),
2786
- /* @__PURE__ */ jsx(
2787
- IconButton,
2788
- {
2789
- variant: "icon-primary",
2790
- disabled: disabled || internCurrentPage >= numberPageCount || isLoading || isPerforming,
2791
- "aria-label": window.NAV_NEXT_PAGE,
2792
- type: "button",
2793
- onClick: () => {
2794
- setCurrentAndDispatch(internCurrentPage + 1);
2795
- },
2796
- icon: "Next",
2797
- iconSize: "Sm"
2798
- }
2799
- ),
2800
- breakPoint > 2 && /* @__PURE__ */ jsx(
2801
- IconButton,
2802
- {
2803
- variant: "icon-primary",
2804
- type: "button",
2805
- "aria-label": window.NAV_LAST_PAGE,
2806
- disabled: disabled || internCurrentPage >= numberPageCount || isLoading || isPerforming,
2807
- onClick: () => {
2808
- setCurrentAndDispatch(numberPageCount);
2809
- },
2810
- icon: "Last",
2811
- iconSize: "Sm"
2812
- }
2813
- )
2814
- ] }) }),
2815
- /* @__PURE__ */ jsx(Box, { className: "pagination__rightToolbar", children: (!hideRefreshButton || onDeleteFilters) && /* @__PURE__ */ jsxs(Fragment, { children: [
2816
- onDeleteFilters && /* @__PURE__ */ jsxs(
2817
- SimpleButton,
2818
- {
2819
- disabled: isPerforming,
2820
- className: "pagination__deleteFiltersButton",
2821
- onClick: onDeleteFilters,
2822
- children: [
2823
- breakPoint > 3 && /* @__PURE__ */ jsx(Box, { as: "span", className: "pagination__deleteLabels", children: window.BTN_DELETE_FILTERS }),
2824
- /* @__PURE__ */ jsx(
2825
- Box,
2826
- {
2827
- as: "span",
2828
- className: `pagination__appliedFiltersLabel ${areAllFiltersApplied ? "" : "withFilters"}`,
2829
- children: appliedFilters
2830
- }
2831
- )
2832
- ]
2833
- }
2834
- ),
2835
- !hideRefreshButton && /* @__PURE__ */ jsx(
2836
- IconButton,
2837
- {
2838
- "aria-label": window.NAV_REFRESH,
2839
- onClick: () => onRefresh(numberCurrentPage),
2840
- icon: "Refresh",
2841
- iconSize: "Md",
2842
- disabled: disabled || isLoading,
2843
- variant: "icon-primary",
2844
- isLoading: isPerforming,
2845
- className: "pagiantion__refreshIcon"
2846
- }
2847
- )
2848
- ] }) })
2849
- ]
2850
- }
2851
- );
2852
- };
2853
- const Pagination = React.memo(NoMemoPagination);
2854
-
2855
- function applyFocusAttributes(table, _previousState, state, focus = state.isFocused) {
2856
- table.querySelectorAll(getFocusSelector()).forEach((e) => {
2857
- e.tabIndex = -1;
2858
- });
2859
- if (state.focusedColumn === 0) {
2860
- const focusedRow = table.querySelector(
2861
- `tr[data-rowindex="${state.focusedRow}"]`
2862
- );
2863
- if (focusedRow) {
2864
- focusedRow.tabIndex = 0;
2865
- window.requestAnimationFrame(() => {
2866
- if (focus) {
2867
- focusedRow.focus();
2868
- }
2869
- });
2870
- }
2871
- } else {
2872
- const focusedCell = table.querySelector(
2873
- `tr[data-rowindex="${state.focusedRow}"] td[aria-colindex="${state.focusedColumn}"], tr[data-rowindex="${state.focusedRow}"] th[aria-colindex="${state.focusedColumn}"]`
2874
- );
2875
- if (focusedCell instanceof HTMLElement) {
2876
- const widget = focusedCell.querySelector(getFocusSelector());
2877
- if (widget instanceof HTMLElement) {
2878
- widget.tabIndex = 0;
2879
- window.requestAnimationFrame(() => {
2880
- if (focus) {
2881
- widget.focus();
2882
- }
2883
- });
2884
- } else {
2885
- focusedCell.tabIndex = 0;
2886
- window.requestAnimationFrame(() => {
2887
- if (focus) {
2888
- focusedCell.focus();
2889
- }
2890
- });
2891
- }
2892
- }
2893
- }
2894
- }
2895
-
2896
- function setAriaAttributes(element, attribute, value) {
2897
- element.setAttribute(attribute, value);
2898
- }
2899
- function getRowDomProps(rowIndex, state) {
2900
- return getDomProps(
2901
- getDomStoreProps(
2902
- rowIndex < 0 ? "headerTr" : "tr",
2903
- {
2904
- rowIndex
2905
- },
2906
- () => state
2907
- ),
2908
- rowIndex < 0 ? "headerTr" : "tr",
2909
- { rowIndex }
2910
- );
2911
- }
2912
- function applyRowSelectionAttributes(row, state) {
2913
- if (!(row instanceof HTMLElement))
2914
- return;
2915
- const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
2916
- const props = getRowDomProps(rowIndex, state);
2917
- Object.entries(props).forEach(([key, value]) => {
2918
- let match;
2919
- match = key.match(/aria-(\w+)/);
2920
- if (match) {
2921
- setAriaAttributes(row, key, value);
2922
- } else if (match = key.match(/data-(\w+)/)) {
2923
- row.dataset[match[1]] = value;
2924
- }
2925
- });
2926
- }
2927
- function applySelectionAttributes(table, _previousState, state) {
2928
- const previousSelectedRows = table.querySelectorAll(
2929
- '[aria-selected="true"]'
2930
- );
2931
- previousSelectedRows.forEach((c) => applyRowSelectionAttributes(c, state));
2932
- if (state.selectedRows.length) {
2933
- const newSelectedRows = table.querySelectorAll(
2934
- state.selectedRows.map((index) => `tr[data-rowindex="${index}"]`).join(",")
2935
- );
2936
- newSelectedRows.forEach((c) => applyRowSelectionAttributes(c, state));
2937
- }
2938
- }
2939
-
2940
- function handleMouseDownEvent(ev) {
2941
- const target = ev.target;
2942
- if (target instanceof HTMLElement) {
2943
- const cell = target.closest("th,td");
2944
- const row = target.closest("tr");
2945
- const table = target.closest("table");
2946
- if (cell && row && table) {
2947
- const state = this.getState();
2948
- const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
2949
- const colIndex = Number.parseInt(cell.ariaColIndex || "a", 10);
2950
- if (!isNaN(rowIndex) && !isNaN(colIndex)) {
2951
- if (!ev.ctrlKey && !ev.shiftKey) {
2952
- state.selectedRows = [rowIndex];
2953
- } else if (ev.ctrlKey) {
2954
- if (state.selectedRows.includes(rowIndex)) {
2955
- state.selectedRows = state.selectedRows.filter(
2956
- (c) => c !== rowIndex
2957
- );
2958
- } else {
2959
- state.selectedRows = [...state.selectedRows, rowIndex];
2960
- }
2961
- } else if (ev.shiftKey) {
2962
- const previousFocused = this.getState().focusedRow;
2963
- state.selectedRows = [...state.selectedRows];
2964
- const min = Math.min(previousFocused, rowIndex);
2965
- const max = Math.max(previousFocused, rowIndex);
2966
- for (let i = min; i <= max; i++) {
2967
- state.selectedRows.push(i);
2968
- }
2969
- }
2970
- state.focusedColumn = colIndex;
2971
- state.focusedRow = rowIndex;
2972
- state.isFocused = true;
2973
- applySelectionAttributes(table, this.getState(), state);
2974
- applyFocusAttributes(table, this.getState(), state);
2975
- this.setState(state);
2976
- } else {
2977
- console.warn("Cannot parse rowIndex or colIndex");
2978
- }
2979
- } else {
2980
- console.warn("Cannot find cell, row or table");
2981
- }
2982
- }
2983
- }
2984
-
2985
- function handleKeyDownEvent(ev) {
2986
- const target = ev.target;
2987
- const state = this.getState();
2988
- if (state.isEditionMode) {
2989
- if (ev.code === "Escape" || ev.code === "Enter") {
2990
- state.isEditionMode = false;
2991
- this.setState(state);
2992
- }
2993
- } else {
2994
- if (target instanceof HTMLElement) {
2995
- const row = target.closest("tr");
2996
- const table = target.closest("table");
2997
- if (row && table) {
2998
- const cell = target.closest("th,td");
2999
- const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
3000
- const colIndex = Number.parseInt(cell?.ariaColIndex || "0", 10);
3001
- if (!isNaN(rowIndex) && !isNaN(colIndex)) {
3002
- if ([
3003
- "ArrowDown",
3004
- "ArrowUp",
3005
- "ArrowLeft",
3006
- "ArrowRight",
3007
- "End",
3008
- "Enter",
3009
- "Home",
3010
- "PageUp",
3011
- "PageDown"
3012
- ].includes(ev.code) || ev.code === "Space" && ev.ctrlKey) {
3013
- ev.preventDefault();
3014
- switch (ev.code) {
3015
- case "Space":
3016
- if (state.selectedRows.includes(rowIndex)) {
3017
- state.selectedRows = state.selectedRows.filter(
3018
- (c) => c !== rowIndex
3019
- );
3020
- } else {
3021
- state.selectedRows = [...state.selectedRows, rowIndex];
3022
- }
3023
- break;
3024
- case "ArrowDown":
3025
- state.focusedRow = addBoundary(
3026
- state.focusedRow + 1,
3027
- state.hasNonAdditionalFilters ? -2 : -1,
3028
- state.rows.length - 1
3029
- );
3030
- if (ev.ctrlKey) ; else if (ev.shiftKey) {
3031
- state.selectedRows = [
3032
- ...state.selectedRows,
3033
- state.focusedRow
3034
- ];
3035
- } else {
3036
- state.selectedRows = [state.focusedRow];
3037
- }
3038
- break;
3039
- case "ArrowUp":
3040
- state.focusedRow = addBoundary(
3041
- state.focusedRow - 1,
3042
- state.hasNonAdditionalFilters ? -2 : -1,
3043
- state.rows.length - 1
3044
- );
3045
- if (ev.ctrlKey) ; else if (ev.shiftKey) {
3046
- state.selectedRows = [
3047
- ...state.selectedRows,
3048
- state.focusedRow
3049
- ];
3050
- } else {
3051
- state.selectedRows = [state.focusedRow];
3052
- }
3053
- break;
3054
- case "ArrowLeft":
3055
- state.focusedColumn = addBoundary(
3056
- state.focusedColumn - 1,
3057
- 0,
3058
- state.columns.length
3059
- );
3060
- break;
3061
- case "ArrowRight":
3062
- state.focusedColumn = addBoundary(
3063
- state.focusedColumn + 1,
3064
- 0,
3065
- state.columns.length
3066
- );
3067
- break;
3068
- case "Home":
3069
- if (state.focusedColumn === 0) {
3070
- state.focusedRow = state.hasNonAdditionalFilters ? -2 : -1;
3071
- if (ev.ctrlKey) ; else if (ev.shiftKey) {
3072
- const max = Math.max(
3073
- state.focusedRow,
3074
- this.getState().focusedRow
3075
- );
3076
- const min = Math.min(
3077
- state.focusedRow,
3078
- this.getState().focusedRow
3079
- );
3080
- for (let i = min; i <= max; i++) {
3081
- state.selectedRows.push(i);
3082
- }
3083
- } else {
3084
- state.selectedRows = [state.focusedRow];
3085
- }
3086
- } else {
3087
- state.focusedColumn = 1;
3088
- }
3089
- break;
3090
- case "End":
3091
- if (state.focusedColumn === 0) {
3092
- state.focusedRow = state.rows.length - 1;
3093
- if (ev.ctrlKey) ; else if (ev.shiftKey) {
3094
- const max = Math.max(
3095
- state.focusedRow,
3096
- this.getState().focusedRow
3097
- );
3098
- const min = Math.min(
3099
- state.focusedRow,
3100
- this.getState().focusedRow
3101
- );
3102
- for (let i = min; i <= max; i++) {
3103
- state.selectedRows.push(i);
3104
- }
3105
- } else {
3106
- state.selectedRows = [state.focusedRow];
3107
- }
3108
- } else {
3109
- state.focusedColumn = state.columns.length;
3110
- }
3111
- break;
3112
- case "PageUp":
3113
- state.focusedRow = addBoundary(
3114
- state.focusedRow - 6,
3115
- state.hasNonAdditionalFilters ? -2 : -1,
3116
- state.rows.length - 1
3117
- );
3118
- if (ev.ctrlKey) ; else if (ev.shiftKey) {
3119
- const previousFocused = this.getState().focusedRow;
3120
- state.selectedRows = [...state.selectedRows];
3121
- const min = Math.min(previousFocused, state.focusedRow);
3122
- const max = Math.max(previousFocused, state.focusedRow);
3123
- for (let i = min; i <= max; i++) {
3124
- state.selectedRows.push(i);
3125
- }
3126
- } else {
3127
- state.selectedRows = [state.focusedRow];
3128
- }
3129
- break;
3130
- case "PageDown":
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 "Enter":
3149
- state.isEditionMode = true;
3150
- this.setState(state);
3151
- return;
3152
- }
3153
- state.isFocused = true;
3154
- applySelectionAttributes(table, this.getState(), state);
3155
- applyFocusAttributes(table, this.getState(), state);
3156
- this.setState(state);
3157
- }
3158
- }
3159
- }
3160
- }
3161
- }
3162
- }
3163
-
3164
- var __defProp = Object.defineProperty;
3165
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3166
- var __publicField = (obj, key, value) => {
3167
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3168
- return value;
3169
- };
3170
- class Controller2 {
3171
- constructor(tableName) {
3172
- this.tableName = tableName;
3173
- __publicField(this, "events", {});
3174
- __publicField(this, "unsubscribe", () => {
3175
- });
3176
- __publicField(this, "el", null);
3177
- __publicField(this, "setRef", (el) => {
3178
- this.unsubscribe();
3179
- this.el = el;
3180
- if (el) {
3181
- el.addEventListener("keydown", this.handleKeyDownEvent);
3182
- el.addEventListener("mousedown", this.handleClickEvent);
3183
- this.unsubscribe = () => {
3184
- el.removeEventListener("keydown", this.handleKeyDownEvent);
3185
- el.removeEventListener("mousedown", this.handleClickEvent);
3186
- };
3187
- }
3188
- });
3189
- __publicField(this, "handleClickEvent");
3190
- __publicField(this, "handleKeyDownEvent");
3191
- this.handleClickEvent = handleMouseDownEvent.bind(this);
3192
- this.handleKeyDownEvent = handleKeyDownEvent.bind(this);
3193
- }
3194
- setEvents(events) {
3195
- this.events = events;
3196
- }
3197
- /**
3198
- * Returns a copy of the current state object
3199
- */
3200
- getState() {
3201
- return {
3202
- ...responsiveTableStore.getState().responsiveTableSlice[this.tableName]
3203
- };
3204
- }
3205
- setState(state) {
3206
- if (state.selectedRows && !shallowEqual$1(state.selectedRows, this.getState().selectedRows)) {
3207
- this.events.onChangeSelection?.(
3208
- state.selectedRows.map((index) => ({
3209
- index,
3210
- row: this.getState().rows[index]
3211
- }))
3212
- );
3213
- this.events.onSelectRows?.(
3214
- state.selectedRows.map((index) => ({
3215
- index,
3216
- row: this.getState().rows[index]
3217
- })),
3218
- state.focusedRow
3219
- );
3220
- }
3221
- if (state.scrollIntoViewRow !== void 0 && state.scrollIntoViewRow !== this.getState().scrollIntoViewRow) {
3222
- const row = this.el?.querySelector(
3223
- `tr[data-rowindex="${state.scrollIntoViewRow}"]`
3224
- );
3225
- if (row) {
3226
- row.scrollIntoView({ block: "nearest", inline: "nearest" });
3227
- }
3228
- }
3229
- responsiveTableStore.dispatch(
3230
- responsiveTableActions.controller2UpdateSelectionState({
3231
- tableName: this.tableName,
3232
- ...state
3233
- })
3234
- );
3235
- }
3236
- updateSelectionState() {
3237
- window.requestAnimationFrame(() => {
3238
- if (this.el) {
3239
- const table = this.el.querySelector("table");
3240
- if (table) {
3241
- applyFocusAttributes(table, this.getState(), this.getState());
3242
- }
3243
- }
3244
- });
3245
- }
3246
- }
3247
- const Controller2Component = ({
3248
- controller,
3249
- ...props
3250
- }) => {
3251
- controller.setEvents({
3252
- onChangeSelection: props.onChangeSelection,
3253
- onSelectRows: props.onSelectRows
3254
- });
3255
- const previousColumns = useRef([]);
3256
- const previousRows = useRef([]);
3257
- const box = useRef(null);
3258
- useResponsiveTable((state) => {
3259
- if (!Object.is(
3260
- state.responsiveTableSlice[controller.tableName]?.columns,
3261
- previousColumns.current
3262
- )) {
3263
- previousColumns.current = state.responsiveTableSlice[controller.tableName]?.columns;
3264
- controller.updateSelectionState();
3265
- }
3266
- if (!Object.is(
3267
- state.responsiveTableSlice[controller.tableName]?.rows,
3268
- previousRows.current
3269
- )) {
3270
- previousRows.current = state.responsiveTableSlice[controller.tableName]?.rows;
3271
- controller.updateSelectionState();
3272
- }
3273
- });
3274
- return /* @__PURE__ */ jsx(
3275
- Box,
3276
- {
3277
- ...props,
3278
- ref: (el) => {
3279
- controller.setRef(el);
3280
- box.current = el;
3281
- }
3282
- }
3283
- );
3284
- };
3285
- function makeController2(tableName) {
3286
- const controller = new Controller2(tableName);
3287
- return [
3288
- controller,
3289
- (props) => {
3290
- return /* @__PURE__ */ jsx(Controller2Component, { ...props, controller });
3291
- }
3292
- ];
3293
- }
3294
-
3295
- const NoMemoDocNameCellRenderer = React.forwardRef(
3296
- ({
3297
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3298
- column,
3299
- row,
3300
- ...props
3301
- }, currentRef) => /* @__PURE__ */ jsx(
3302
- "td",
3303
- {
3304
- ref: currentRef,
3305
- ...props,
3306
- ...cell,
3307
- children: /* @__PURE__ */ jsxs(
3308
- Link,
3309
- {
3310
- className: "cell__download__document",
3311
- title: rendererProps?.docName,
3312
- href: rendererProps?.docUrl,
3313
- onClick: (ev) => {
3314
- ev.preventDefault();
3315
- if (rendererProps?.docUrl)
3316
- void downloadUrl(rendererProps?.docUrl);
3317
- },
3318
- children: [
3319
- /* @__PURE__ */ jsx(Icon, { title: "", name: "Download" }),
3320
- rendererProps?.docName
3321
- ]
3322
- }
3323
- )
3324
- }
3325
- )
3326
- );
3327
- NoMemoDocNameCellRenderer.displayName = "DocNameCellRenderer";
3328
- const DocNameCellRenderer = NoMemoDocNameCellRenderer;
3329
-
3330
- const NoMemoAccordionDocNameCellRenderer = React.forwardRef(
3331
- ({
3332
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3333
- column
3334
- }, currentRef) => /* @__PURE__ */ jsxs(Box, { ref: currentRef, ...cell, children: [
3335
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3336
- column.label ?? column.name,
3337
- ": "
3338
- ] }),
3339
- /* @__PURE__ */ jsxs(
3340
- Link,
3341
- {
3342
- className: "cell__download__document",
3343
- title: rendererProps?.docName,
3344
- href: rendererProps?.docUrl,
3345
- onClick: (ev) => {
3346
- ev.preventDefault();
3347
- if (rendererProps?.docUrl)
3348
- void downloadUrl(rendererProps?.docUrl);
3349
- },
3350
- children: [
3351
- /* @__PURE__ */ jsx(Icon, { title: "", name: "Download" }),
3352
- rendererProps?.docName
3353
- ]
3354
- }
3355
- )
3356
- ] })
3357
- );
3358
- NoMemoAccordionDocNameCellRenderer.displayName = "AccordionDocNameCellRenderer";
3359
- const AccordionDocNameCellRenderer = NoMemoAccordionDocNameCellRenderer;
3360
-
3361
- const NoMemoAccordionHTMLCellRenderer = React.forwardRef(
3362
- ({
3363
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3364
- column,
3365
- row,
3366
- ...props
3367
- }, currentRef) => (
3368
- /**
3369
- * Aca falta el title de la columna
3370
- */
3371
- /* @__PURE__ */ jsx(
3372
- Box,
3373
- {
3374
- ref: currentRef,
3375
- ...props,
3376
- ...cell,
3377
- className: "accordion__cell__renderer",
3378
- dangerouslySetInnerHTML: {
3379
- __html: String(rendererProps?.html ?? children ?? "").replaceAll(
3380
- /<TOK(\d+)/g,
3381
- "&lt;TOK$1"
3382
- )
3383
- },
3384
- as: "span"
3385
- }
3386
- )
3387
- )
3388
- );
3389
- NoMemoAccordionHTMLCellRenderer.displayName = "AccordionHTMLCellRenderer";
3390
- const AccordionHTMLCellRenderer = NoMemoAccordionHTMLCellRenderer;
3391
-
3392
- const NoMemoHTMLCellRenderer = React.forwardRef(
3393
- ({
3394
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3395
- column,
3396
- row,
3397
- ...props
3398
- }, currentRef) => /* @__PURE__ */ jsx(
3399
- "td",
3400
- {
3401
- ref: currentRef,
3402
- ...props,
3403
- ...cell,
3404
- dangerouslySetInnerHTML: {
3405
- __html: String(rendererProps?.html ?? children ?? "").replaceAll(
3406
- /<TOK(\d+)/g,
3407
- "&lt;TOK$1"
3408
- )
3409
- }
3410
- }
3411
- )
3412
- );
3413
- NoMemoHTMLCellRenderer.displayName = "HTMLCellRenderer";
3414
- const HTMLCellRenderer = NoMemoHTMLCellRenderer;
3415
-
3416
- const IsLoadingRenderer = () => {
3417
- return /* @__PURE__ */ jsx(Box, { className: "responsiveTable__isLoading", children: /* @__PURE__ */ jsx(Spinner, {}) });
3418
- };
3419
-
3420
- function makeAccordionAsyncRenderer(additionalInfoGetter) {
3421
- const InnerRender = forwardRef(({ row }, ref) => {
3422
- const [moreInfo, setMoreInfo] = useState(null);
3423
- const loadMore = useCallback(async () => {
3424
- const result = await additionalInfoGetter(row);
3425
- setMoreInfo(result);
3426
- }, [row]);
3427
- return /* @__PURE__ */ jsx(Fragment, { children: moreInfo ? /* @__PURE__ */ jsxs(Fragment, { children: [
3428
- /* @__PURE__ */ jsx(IconButton, { icon: "Minus", onClick: () => setMoreInfo(null) }),
3429
- arrayOrArray(moreInfo).map(
3430
- (dataCell) => {
3431
- return /* @__PURE__ */ jsxs(Box, { ref, as: "div", children: [
3432
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3433
- dataCell.name,
3434
- ":"
3435
- ] }),
3436
- " ",
3437
- dataCell.label
3438
- ] }, dataCell.name);
3439
- }
3440
- )
3441
- ] }) : /* @__PURE__ */ jsx(IconButton, { icon: "Plus", onClick: () => void loadMore() }) });
3442
- });
3443
- InnerRender.displayName = "MakeAccordionAsyncRenderer";
3444
- return InnerRender;
3445
- }
3446
-
3447
- function makeAsyncRenderer(additionalInfoGetter) {
3448
- const InnerRender = forwardRef(({ row }, ref) => {
3449
- const [moreInfo, setMoreInfo] = useState(null);
3450
- useMount$1(() => {
3451
- void (async () => {
3452
- const result = await additionalInfoGetter(row);
3453
- setMoreInfo(result);
3454
- })();
3455
- });
3456
- return /* @__PURE__ */ jsx(Fragment, { children: moreInfo ? arrayOrArray(moreInfo).map((dataCell) => {
3457
- return /* @__PURE__ */ jsx(
3458
- Box,
3459
- {
3460
- ref,
3461
- className: `responsiveTable__additionalInfoItem ${dataCell.newline ? "separator" : ""}`,
3462
- children: dataCell.newline ? /* @__PURE__ */ jsxs(Fragment, { children: [
3463
- /* @__PURE__ */ jsxs(Box, { sx: { height: "20px" }, as: "strong", children: [
3464
- dataCell.name,
3465
- ":"
3466
- ] }),
3467
- " ",
3468
- dataCell.label
3469
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3470
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3471
- dataCell.name,
3472
- ":"
3473
- ] }),
3474
- " ",
3475
- dataCell.label
3476
- ] })
3477
- },
3478
- `${dataCell.name}-${uniqueId()}`
3479
- );
3480
- }) : /* @__PURE__ */ jsx(Spinner, { size: 15 }) });
3481
- });
3482
- InnerRender.displayName = "MakeAsyncRenderer";
3483
- return InnerRender;
3484
- }
3485
-
3486
- const NoMemoNoEllipsisCellRenderer = React.forwardRef(
3487
- ({
3488
- cell: { Renderer, rendererProps, AccordionRenderer, ariaLabel, ...cell },
3489
- column,
3490
- row,
3491
- ...props
3492
- }, currentRef) => /* @__PURE__ */ jsx(
3493
- Box,
3494
- {
3495
- as: "td",
3496
- sx: useMemo(
3497
- () => ({
3498
- "&.colored": {
3499
- background: cell.background,
3500
- color: cell.color,
3501
- fontWeight: "bold"
3502
- }
3503
- }),
3504
- [cell.background, cell.color]
3505
- ),
3506
- ref: currentRef,
3507
- ...props,
3508
- ...cell,
3509
- "aria-label": ariaLabel,
3510
- children: props.children ?? cell.children
3511
- }
3512
- )
3513
- );
3514
- NoMemoNoEllipsisCellRenderer.displayName = "DefaultCellRenderer";
3515
- const NoEllipsisCellRenderer = memo(NoMemoNoEllipsisCellRenderer);
3516
-
3517
- function getPriorityHandler(priority) {
3518
- let prio;
3519
- if (priority?.includes("priority0"))
3520
- prio = "priorityNone";
3521
- if (priority?.includes("priority1"))
3522
- prio = "priorityLow";
3523
- if (priority?.includes("priority2"))
3524
- prio = "priorityNormal";
3525
- if (priority?.includes("priority3"))
3526
- prio = "priorityHigh";
3527
- if (priority?.includes("priority4"))
3528
- prio = "priorityUrgent";
3529
- return prio;
3530
- }
3531
- const NoMemoPriorityRenderer = React.forwardRef(
3532
- ({
3533
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3534
- column,
3535
- row,
3536
- ...props
3537
- }, currentRef) => {
3538
- const taskPriorityColor = getPriorityHandler(rendererProps?.src);
3539
- return /* @__PURE__ */ jsx(
3540
- "td",
3541
- {
3542
- ...props,
3543
- ...cell,
3544
- ref: currentRef,
3545
- className: "priority",
3546
- sx: {
3547
- color: taskPriorityColor
3548
- },
3549
- children: /* @__PURE__ */ jsx(FaSquare, {})
3550
- }
3551
- );
3552
- }
3553
- );
3554
- NoMemoPriorityRenderer.displayName = "PriorityRenderer";
3555
- const PriorityRenderer = NoMemoPriorityRenderer;
3556
-
3557
- const NoMemoPriorityAccordionRenderer = React.forwardRef(
3558
- ({ cell, column }, currentRef) => {
3559
- const taskPriorityColor = getPriorityHandler(
3560
- cell.rendererProps?.src
3561
- );
3562
- const title = column.label ?? column.name;
3563
- return /* @__PURE__ */ jsxs(Box, { ref: currentRef, className: "priority_container", children: [
3564
- title && /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3565
- column.label ?? column.name,
3566
- ": "
3567
- ] }),
3568
- /* @__PURE__ */ jsx(
3569
- Box,
3570
- {
3571
- as: "span",
3572
- className: "priority",
3573
- sx: {
3574
- color: taskPriorityColor
3575
- },
3576
- children: /* @__PURE__ */ jsx(FaSquare, {})
3577
- }
3578
- )
3579
- ] });
3580
- }
3581
- );
3582
- NoMemoPriorityAccordionRenderer.displayName = "PriorityAccordionRenderer";
3583
- const PriorityAccordionRenderer = NoMemoPriorityAccordionRenderer;
3584
-
3585
- function getStatusRendererClassName(cellValue, columnName) {
3586
- if (cellValue === void 0)
3587
- return "";
3588
- const cellValueDate = cellValue.split(" ")[0];
3589
- const cellValueHour = cellValue.split(" ")[1] ?? "00:00:00";
3590
- const dateFormat = getDateFormat();
3591
- const currentDate = dayjs();
3592
- const currentHour = Number(dayjs().format("HHmm"));
3593
- const queriedDate = dayjs(cellValueDate, dateFormat);
3594
- const queriedHour = Number(dayjs(cellValueHour, dateFormat));
3595
- let statusClassName = "";
3596
- if (currentDate >= queriedDate) {
3597
- statusClassName = columnName;
3598
- }
3599
- if (!queriedHour)
3600
- return statusClassName;
3601
- if (currentDate <= queriedDate && currentHour < queriedHour) {
3602
- statusClassName = columnName;
3603
- }
3604
- return statusClassName;
3605
- }
3606
- const NoMemoStatusRenderer = React.forwardRef(
3607
- ({
3608
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3609
- column,
3610
- row,
3611
- ...props
3612
- }, currentRef) => {
3613
- const taskStatusClassName = getStatusRendererClassName(
3614
- children,
3615
- column.name
3616
- );
3617
- return /* @__PURE__ */ jsx(
3618
- "td",
3619
- {
3620
- ...props,
3621
- ...cell,
3622
- ref: currentRef,
3623
- className: taskStatusClassName,
3624
- children
3625
- }
3626
- );
3627
- }
3628
- );
3629
- NoMemoStatusRenderer.displayName = "StatusRenderer";
3630
- const StatusRenderer = NoMemoStatusRenderer;
3631
-
3632
- const NoMemoStatusAccordionRenderer = React.forwardRef(({ cell, column }, currentRef) => {
3633
- const taskStatusClassName = getStatusRendererClassName(
3634
- cell.children,
3635
- column.name
3636
- );
3637
- return /* @__PURE__ */ jsxs(Box, { ref: currentRef, children: [
3638
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3639
- column.label ?? column.name,
3640
- ": "
3641
- ] }),
3642
- /* @__PURE__ */ jsx(Box, { as: "span", className: taskStatusClassName, children: cell.children })
3643
- ] });
3644
- });
3645
- NoMemoStatusAccordionRenderer.displayName = "StatusAccordionRenderer";
3646
- const StatusAccordionRenderer = NoMemoStatusAccordionRenderer;
3647
-
3648
- 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 };
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';
3649
25
  //# sourceMappingURL=index.js.map