@apia/table 5.0.0 → 5.0.3

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