@apia/table 4.0.102 → 5.0.1

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 (191) 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 -772
  72. package/dist/index.js +34 -3821
  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 -8
  191. package/LICENSE.md +0 -6
package/dist/index.js CHANGED
@@ -1,3822 +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
- const minColumnWidth = 50;
1171
- function getColumnWidth(width) {
1172
- if (typeof width === "string") {
1173
- if (width.match(/(%|px|vw|vh|vmin|vmax|cm|mm|in|pt|pc)/))
1174
- return width;
1175
- if (width === "")
1176
- return "auto";
1177
- const numberValue = Number.parseInt(width, 10);
1178
- if (isNaN(numberValue))
1179
- return "auto";
1180
- return numberValue;
1181
- }
1182
- if (typeof width === "number")
1183
- return width;
1184
- return width;
1185
- }
1186
- function getColumnWidthAsNumber(width) {
1187
- const columnWidth = getColumnWidth(width);
1188
- if (typeof columnWidth === "number")
1189
- return columnWidth;
1190
- if (typeof columnWidth === "string" && columnWidth.endsWith("px")) {
1191
- const parsedWidth = Number.parseInt(columnWidth, 10);
1192
- if (!Number.isNaN(parsedWidth))
1193
- return parsedWidth;
1194
- }
1195
- return void 0;
1196
- }
1197
- function normalizeResizedWidth(width) {
1198
- return Math.max(minColumnWidth, Math.round(width));
1199
- }
1200
- function setHeaderCellWidth(cell, width) {
1201
- const normalizedWidth = normalizeResizedWidth(width);
1202
- const cssWidth = `${normalizedWidth}px`;
1203
- cell.dataset.resizedWidth = String(normalizedWidth);
1204
- cell.style.width = cssWidth;
1205
- cell.style.minWidth = cssWidth;
1206
- cell.style.maxWidth = cssWidth;
1207
- }
1208
- function syncTableWidthFromHeaderCell(cell) {
1209
- const row = cell.closest("tr");
1210
- const table = cell.closest("table");
1211
- if (!(row instanceof HTMLElement) || !(table instanceof HTMLElement))
1212
- return;
1213
- const tableWidth = Array.from(row.children).reduce((total, current) => {
1214
- if (!(current instanceof HTMLElement))
1215
- return total;
1216
- const resizedWidth = Number.parseFloat(current.dataset.resizedWidth ?? "");
1217
- return total + (Number.isFinite(resizedWidth) ? resizedWidth : current.getBoundingClientRect().width);
1218
- }, 0);
1219
- if (tableWidth <= 0)
1220
- return;
1221
- const normalizedTableWidth = `${normalizeResizedWidth(tableWidth)}px`;
1222
- table.style.width = normalizedTableWidth;
1223
- table.style.minWidth = normalizedTableWidth;
1224
- }
1225
- debugDispatcher.on(
1226
- "cleanTableSizes",
1227
- ([tableName]) => {
1228
- const currentWidths = persistentStorage[widthStorageName] ?? {};
1229
- delete currentWidths[tableName];
1230
- persistentStorage[widthStorageName] = currentWidths;
1231
- },
1232
- 'Se usa para borrar el estado de una tabla. Uso: dd.cleanTableSizes("TableName")'
1233
- );
1234
- function makeColumnName(tableName, columnName) {
1235
- return `${tableName}${columnName}`;
1236
- }
1237
- const thWidthEmitter = new class ThWidthEmitter extends EventEmitter {
1238
- }();
1239
- const NoMemoHeaderCell = ({
1240
- apiaColumnIndex,
1241
- columnIndex,
1242
- inTableColumnIndex
1243
- }) => {
1244
- const { name, onSortChange } = useResponsiveTableContext();
1245
- const uniqueId = window.location.href.match(/busEntId=(\d+)/)?.[1] ?? window.location.href.match(/query=(\d+)/)?.[1] ?? "";
1246
- const isGlobal = window.isGlobal ? "isGlobal" : "notGlobal";
1247
- const actualName = name + uniqueId + String(isGlobal);
1248
- const columns = useResponsiveTable((global) => {
1249
- const tableState = global.responsiveTableSlice[name];
1250
- return tableState?.columns;
1251
- }, shallowEqual);
1252
- const column = columns[columnIndex];
1253
- const storedWidth = persistentStorage[widthStorageName]?.[actualName]?.[column.name];
1254
- const [width, setStateWidth] = React.useState(
1255
- normalizeResizedWidth(
1256
- storedWidth ?? getColumnWidthAsNumber(column.width) ?? 200
1257
- )
1258
- );
1259
- const [isResize, setIsResize] = React.useState(storedWidth !== void 0);
1260
- const thRef = React.useRef(null);
1261
- const dragWidth = React.useRef(null);
1262
- const setWidth = React.useCallback((newWidth) => {
1263
- setIsResize(true);
1264
- setStateWidth(normalizeResizedWidth(newWidth));
1265
- }, []);
1266
- React.useEffect(() => {
1267
- return thWidthEmitter.on("resize", (ev) => {
1268
- if (ev.name === makeColumnName(actualName, column.name)) {
1269
- setWidth(ev.width);
1270
- }
1271
- });
1272
- }, [column.name, actualName, setWidth]);
1273
- React.useEffect(() => {
1274
- if (!isResize || !thRef.current)
1275
- return;
1276
- syncTableWidthFromHeaderCell(thRef.current);
1277
- }, [isResize, width]);
1278
- const isFilterRequired = useResponsiveTable((global) => {
1279
- const tableState = global.responsiveTableSlice[name];
1280
- const columnFilter = tableState?.filters.find(
1281
- (current) => current.column === column.title
1282
- );
1283
- return columnFilter?.required;
1284
- }, shallowEqual);
1285
- const isSortingAllowed = useResponsiveTable((global) => {
1286
- const tableState = global.responsiveTableSlice[name];
1287
- return tableState?.allowSorting;
1288
- });
1289
- const isLoading = useResponsiveTable((global) => {
1290
- const tableState = global.responsiveTableSlice[name];
1291
- return tableState?.isLoading;
1292
- });
1293
- const domProps = useDomProps(
1294
- "th",
1295
- {
1296
- columnIndex: inTableColumnIndex
1297
- },
1298
- domPropsSelector(name)
1299
- );
1300
- const sx = React.useMemo(
1301
- () => !isResize ? {
1302
- minWidth: getColumnWidth(column.minWidth ?? column.width),
1303
- maxWidth: column.maxWidth !== void 0 ? getColumnWidth(column.maxWidth) : void 0,
1304
- width: getColumnWidth(column.width),
1305
- position: "relative"
1306
- } : {
1307
- width: `${width}px`,
1308
- minWidth: `${width}px`,
1309
- maxWidth: `${width}px`,
1310
- position: "relative"
1311
- },
1312
- [column.maxWidth, column.minWidth, column.width, isResize, width]
1313
- );
1314
- const lastIsLoading = useLatest(isLoading);
1315
- const buttonProps = useOtherTagButton(
1316
- React.useMemo(
1317
- () => ({
1318
- className: "headButton",
1319
- onClick: (ev) => {
1320
- if (lastIsLoading.current)
1321
- return;
1322
- if (isChild(
1323
- ev.target,
1324
- (current) => current.classList.contains("headButton__resizer")
1325
- ))
1326
- return;
1327
- if (onSortChange && column.allowSorting !== false && isSortingAllowed !== false)
1328
- onSortChange({
1329
- column,
1330
- columnIndex: apiaColumnIndex,
1331
- name: column.name,
1332
- sortValue: ["Asc", "Desc"][column.currentSorting !== "A" ? 0 : 1]
1333
- });
1334
- }
1335
- }),
1336
- [apiaColumnIndex, column, isSortingAllowed, lastIsLoading, onSortChange]
1337
- )
1338
- );
1339
- return /* @__PURE__ */ jsx(
1340
- Box,
1341
- {
1342
- as: "th",
1343
- ...{ sx },
1344
- "data-columnname": column.name,
1345
- "data-resized-width": isResize ? width : void 0,
1346
- title: column.title ?? column.label ?? column.name,
1347
- ...buttonProps,
1348
- ...domProps,
1349
- role: "rowheader",
1350
- className: `${isFilterRequired && window.SHOW_REQUIRED_POSITION ? "requiredFilterColumn" : ""}`,
1351
- ref: (el) => {
1352
- thRef.current = el instanceof HTMLTableCellElement ? el : null;
1353
- if (!column?.autoAdjustWidth)
1354
- return;
1355
- if (el instanceof HTMLElement && !el.dataset.resized && storedWidth === void 0) {
1356
- const clone = el.cloneNode(true);
1357
- const child = clone.querySelector(
1358
- ".headButton__label"
1359
- );
1360
- child.style.opacity = "0";
1361
- document.body.append(child);
1362
- child.style.position = "fixed";
1363
- child.style.maxWidth = "0";
1364
- child.style.minWidth = "0";
1365
- child.style.width = "0";
1366
- child.style.overflow = "auto";
1367
- child.style.textWrap = "nowrap";
1368
- window.requestAnimationFrame(() => {
1369
- const idealWidth = child.scrollWidth;
1370
- const currentWidth = el.querySelector(".headButton__label").getBoundingClientRect().width;
1371
- const elWidth = el.getBoundingClientRect().width;
1372
- const diff = idealWidth - currentWidth;
1373
- setWidth(elWidth + diff + 5);
1374
- el.dataset.resized = "true";
1375
- child.remove();
1376
- });
1377
- }
1378
- },
1379
- children: /* @__PURE__ */ jsxs(Box, { as: "span", className: "headButton__container", children: [
1380
- /* @__PURE__ */ jsx(
1381
- Box,
1382
- {
1383
- as: "span",
1384
- className: `${isFilterRequired ? "requiredFilter__Column" : ""} headButton__label`,
1385
- children: /* @__PURE__ */ jsx(
1386
- AutoEllipsis,
1387
- {
1388
- overrideStyles: (el) => {
1389
- const th = el.closest("th");
1390
- return {
1391
- width: `${Math.max(
1392
- 100,
1393
- Number.parseInt(window.getComputedStyle(th).width)
1394
- )}px`
1395
- };
1396
- },
1397
- children: column.label
1398
- }
1399
- )
1400
- }
1401
- ),
1402
- /* @__PURE__ */ jsxs(Box, { as: "span", className: "headButton__sortIcon", children: [
1403
- column.allowSorting !== false && column.currentSorting === "A" && /* @__PURE__ */ jsx(FaSortUp, {}),
1404
- column.allowSorting !== false && column.currentSorting === "D" && /* @__PURE__ */ jsx(FaSortDown, {}),
1405
- column.allowSorting !== false && !column.currentSorting && /* @__PURE__ */ jsx(FaSort, {})
1406
- ] }),
1407
- /* @__PURE__ */ jsx(
1408
- Box,
1409
- {
1410
- className: "headButton__resizer",
1411
- onMouseDown: (ev) => {
1412
- if (!isResize) {
1413
- const trElement = getSpecificParent(
1414
- ev.target,
1415
- (current) => current.tagName === "TR"
1416
- );
1417
- trElement?.querySelectorAll("th").forEach((current) => {
1418
- const columnName = current.dataset.columnname;
1419
- if (!columnName)
1420
- return;
1421
- setHeaderCellWidth(
1422
- current,
1423
- current.clientWidth
1424
- );
1425
- thWidthEmitter.emit("resize", {
1426
- name: makeColumnName(actualName, columnName),
1427
- width: current.clientWidth
1428
- });
1429
- });
1430
- setIsResize(true);
1431
- }
1432
- const th = getSpecificParent(
1433
- ev.target,
1434
- (current) => current.tagName === "TH"
1435
- );
1436
- if (!th)
1437
- throw new Error("There is no th");
1438
- const initialX = ev.clientX;
1439
- const initialWidth = th.clientWidth;
1440
- let animationFrame = 0;
1441
- const scheduleTableWidthSync = () => {
1442
- if (animationFrame)
1443
- return;
1444
- animationFrame = window.requestAnimationFrame(() => {
1445
- animationFrame = 0;
1446
- syncTableWidthFromHeaderCell(th);
1447
- });
1448
- };
1449
- const resize = (mousemoveEv) => {
1450
- const dif = mousemoveEv.clientX - initialX;
1451
- const newWidth = normalizeResizedWidth(initialWidth + dif);
1452
- dragWidth.current = newWidth;
1453
- setHeaderCellWidth(th, newWidth);
1454
- scheduleTableWidthSync();
1455
- };
1456
- const unsuscribe = () => {
1457
- if (animationFrame) {
1458
- window.cancelAnimationFrame(animationFrame);
1459
- animationFrame = 0;
1460
- }
1461
- const trElement = getSpecificParent(
1462
- ev.target,
1463
- (current) => current.tagName === "TR"
1464
- );
1465
- trElement?.querySelectorAll("th").forEach((current) => {
1466
- const columnName = current.dataset.columnname;
1467
- if (!columnName)
1468
- return;
1469
- const resizedWidth = Number.parseFloat(
1470
- current.dataset.resizedWidth ?? ""
1471
- );
1472
- persistentStorage[widthStorageName] = {
1473
- ...persistentStorage[widthStorageName],
1474
- [actualName]: {
1475
- ...persistentStorage[widthStorageName]?.[actualName],
1476
- [columnName]: normalizeResizedWidth(
1477
- Number.isFinite(resizedWidth) ? resizedWidth : current.getBoundingClientRect().width
1478
- )
1479
- }
1480
- };
1481
- });
1482
- if (dragWidth.current !== null) {
1483
- setWidth(dragWidth.current);
1484
- dragWidth.current = null;
1485
- }
1486
- syncTableWidthFromHeaderCell(th);
1487
- document.removeEventListener("mousemove", resize);
1488
- document.removeEventListener("mouseup", unsuscribe);
1489
- };
1490
- document.addEventListener("mousemove", resize);
1491
- document.addEventListener("mouseup", unsuscribe);
1492
- return false;
1493
- }
1494
- }
1495
- )
1496
- ] })
1497
- }
1498
- );
1499
- };
1500
- const HeaderCell = React.memo(NoMemoHeaderCell);
1501
-
1502
- const NoMemoRowStatesRenderer = ({
1503
- state
1504
- }) => {
1505
- const { Icon } = state;
1506
- return /* @__PURE__ */ jsx(
1507
- Box,
1508
- {
1509
- sx: React.useMemo(
1510
- () => ({
1511
- "&, svg, path": {
1512
- color: state.color ?? ""
1513
- }
1514
- }),
1515
- [state.color]
1516
- ),
1517
- children: /* @__PURE__ */ jsx(
1518
- Icon,
1519
- {
1520
- ...getVariant("inherit"),
1521
- title: state.tooltip,
1522
- className: `${state.className ?? "state"}_icon state_icon`
1523
- }
1524
- )
1525
- }
1526
- );
1527
- };
1528
- const RowStatesRenderer = React.memo(NoMemoRowStatesRenderer);
1529
-
1530
- const StateCell = ({ index, rowIndex, state, isHeader }) => {
1531
- const { name } = useResponsiveTableContext();
1532
- const domProps = useDomProps(
1533
- isHeader ? "headerStateCell" : "stateCell",
1534
- { columnIndex: index, rowIndex },
1535
- domPropsSelector(name)
1536
- );
1537
- return /* @__PURE__ */ jsx(Box, { as: "td", className: "stateCell", ...domProps, children: state?.Icon ? /* @__PURE__ */ jsx(RowStatesRenderer, { state }) : "" });
1538
- };
1539
-
1540
- const units = ["B", "KB", "MB", "GB"];
1541
- const NoMemoRangeFilter = ({
1542
- filter,
1543
- tableName,
1544
- className
1545
- }) => {
1546
- const { onFilterBlur, onFilterChange, onFilterPressEnter } = useResponsiveTableContext(tableName);
1547
- const filterLow = {
1548
- ...filter,
1549
- changeFiltersTimestamp: filter?.changeFiltersTimestamp,
1550
- currentValue: filter.currentValue,
1551
- deleteFiltersTimestamp: filter?.deleteFiltersTimestamp,
1552
- id: filter.id,
1553
- toolTip: filter.toolTip,
1554
- type: "apiaNumber"
1555
- };
1556
- const multiplier = useRef(1);
1557
- const lastEmittedHigh = useRef(null);
1558
- const lastEmittedLow = useRef(null);
1559
- const lastEmittedMultiplier = useRef(1);
1560
- const previousChangeTimestamp = usePrevious(filter?.changeFiltersTimestamp);
1561
- const previousDeleteTimestamp = usePrevious(filter?.deleteFiltersTimestamp);
1562
- if (previousChangeTimestamp.current !== filter?.changeFiltersTimestamp) {
1563
- lastEmittedLow.current = filterLow.currentValue;
1564
- lastEmittedHigh.current = filterLow.filterToValue || "";
1565
- }
1566
- if (previousDeleteTimestamp.current !== filter?.deleteFiltersTimestamp) {
1567
- lastEmittedLow.current = "";
1568
- lastEmittedHigh.current = "";
1569
- }
1570
- const emitLow = (method, currentValue) => {
1571
- const numberValue = currentValue ?? "";
1572
- if (lastEmittedLow.current === numberValue && lastEmittedMultiplier.current === multiplier.current) {
1573
- return;
1574
- }
1575
- lastEmittedLow.current = numberValue;
1576
- lastEmittedMultiplier.current = multiplier.current;
1577
- const emitValue = numberValue;
1578
- void method?.({
1579
- ...filterLow,
1580
- currentValue: emitValue,
1581
- filterToValue: lastEmittedHigh.current ?? "",
1582
- sizeMultiplier: multiplier.current
1583
- });
1584
- };
1585
- const emitHigh = (method, currentValue) => {
1586
- const numberValue = currentValue ?? "";
1587
- if (lastEmittedHigh.current === numberValue && lastEmittedMultiplier.current === multiplier.current) {
1588
- return;
1589
- }
1590
- lastEmittedHigh.current = numberValue;
1591
- lastEmittedMultiplier.current = multiplier.current;
1592
- const emitValue = numberValue;
1593
- void method?.({
1594
- ...filterLow,
1595
- currentValue: lastEmittedLow.current ?? "",
1596
- filterToValue: emitValue,
1597
- sizeMultiplier: multiplier.current
1598
- });
1599
- };
1600
- const [lowValue, setLowValue] = useIntermediateValue(filterLow.currentValue);
1601
- const [highValue, setHighValue] = useIntermediateValue(
1602
- filterLow.filterToValue
1603
- );
1604
- const [unit, setUnit] = useIntermediateValue(filterLow.sizeMultiplier);
1605
- return /* @__PURE__ */ jsxs(
1606
- Box,
1607
- {
1608
- className: `ApiaFilter__Range ${className || ""}`,
1609
- ...getVariant("layout.common.filters.rangeFilter"),
1610
- children: [
1611
- /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__Low", children: /* @__PURE__ */ jsx(
1612
- Input,
1613
- {
1614
- onChange: ({ target: { value: currentValue } }) => {
1615
- setLowValue(currentValue);
1616
- emitLow(onFilterChange, currentValue);
1617
- },
1618
- onBlur: ({ target: { value: currentValue } }) => {
1619
- emitLow(onFilterBlur, currentValue);
1620
- },
1621
- onKeyDown: ({ code, target }) => {
1622
- if (code === "Enter") {
1623
- emitLow(onFilterPressEnter, target.value);
1624
- }
1625
- },
1626
- value: lowValue
1627
- }
1628
- ) }),
1629
- " - ",
1630
- /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__High", children: /* @__PURE__ */ jsx(
1631
- Input,
1632
- {
1633
- onChange: ({ target: { value: currentValue } }) => {
1634
- setHighValue(currentValue);
1635
- emitHigh(onFilterChange, currentValue);
1636
- },
1637
- onBlur: ({ target: { value: currentValue } }) => {
1638
- emitHigh(onFilterBlur, currentValue);
1639
- },
1640
- onKeyDown: ({ code, target }) => {
1641
- if (code === "Enter") {
1642
- emitHigh(onFilterPressEnter, target.value);
1643
- }
1644
- },
1645
- value: highValue
1646
- }
1647
- ) }),
1648
- filter.isSize && /* @__PURE__ */ jsx(
1649
- Select,
1650
- {
1651
- className: "ApiaFilter__Range__UnitSelector",
1652
- onChange: (ev) => {
1653
- const unit2 = ev.target.value;
1654
- const index = units.indexOf(unit2);
1655
- if (index !== -1) {
1656
- multiplier.current = 2 ** (index * 10);
1657
- setUnit(multiplier.current);
1658
- emitLow(onFilterChange, lastEmittedLow.current ?? "");
1659
- }
1660
- },
1661
- value: units[Math.log2(unit || 1) / 10],
1662
- children: units.map((c) => /* @__PURE__ */ jsx("option", { value: c, children: c }, c))
1663
- }
1664
- )
1665
- ]
1666
- }
1667
- );
1668
- };
1669
- const RangeFilter = NoMemoRangeFilter;
1670
-
1671
- const FilterCell = ({ columnIndex, filter, Renderer }) => {
1672
- const { name, onFilterBlur, onFilterChange, onFilterPressEnter } = useResponsiveTableContext();
1673
- const domProps = useDomProps(
1674
- "filterTd",
1675
- {
1676
- columnIndex
1677
- },
1678
- domPropsSelector(name)
1679
- );
1680
- const handleOnBlur = React.useCallback(
1681
- (currentValue) => {
1682
- if (filter && onFilterBlur)
1683
- onFilterBlur({ ...filter, currentValue });
1684
- },
1685
- [filter, onFilterBlur]
1686
- );
1687
- const handleOnChange = React.useCallback(
1688
- (currentValue) => {
1689
- if (filter && onFilterChange)
1690
- return onFilterChange({ ...filter, currentValue });
1691
- return true;
1692
- },
1693
- [filter, onFilterChange]
1694
- );
1695
- const handleOnPressEnter = React.useCallback(
1696
- (currentValue) => {
1697
- if (filter && onFilterPressEnter)
1698
- onFilterPressEnter({ ...filter, currentValue });
1699
- },
1700
- [filter, onFilterPressEnter]
1701
- );
1702
- function findFilter() {
1703
- if (filter?.isRange) {
1704
- return /* @__PURE__ */ jsx(RangeFilter, { filter });
1705
- }
1706
- if (filter && !(filter.asAdditional || !filter.column || filter.isRange)) {
1707
- return /* @__PURE__ */ jsx(
1708
- ApiaFilter,
1709
- {
1710
- onBlur: handleOnBlur,
1711
- onChange: handleOnChange,
1712
- onPressEnter: handleOnPressEnter,
1713
- filter
1714
- }
1715
- );
1716
- }
1717
- let label;
1718
- if (filter && (filter.asAdditional || !filter.column || filter.isRange)) {
1719
- label = window.LBL_ADDITIONAL_FILTER;
1720
- } else {
1721
- label = window.LBL_NO_COLUMN_FILTER;
1722
- }
1723
- return /* @__PURE__ */ jsx(Input, { "aria-label": label, disabled: true });
1724
- }
1725
- return /* @__PURE__ */ jsx("td", { ...domProps, children: Renderer ? /* @__PURE__ */ jsx(Renderer, { filter }) : findFilter() });
1726
- };
1727
-
1728
- const NoMemoHeader = () => {
1729
- const { name, FiltersRenderer, showFilters } = useResponsiveTableContext();
1730
- const columns = useResponsiveTable(
1731
- (global) => global.responsiveTableSlice[name]?.columns
1732
- );
1733
- const hasNonAdditionalFilters = useResponsiveTable(
1734
- (global) => global.responsiveTableSlice[name]?.hasNonAdditionalFilters
1735
- );
1736
- const focusedColumn = useResponsiveTable(
1737
- (global) => global.responsiveTableSlice[name]?.focusedColumn
1738
- );
1739
- const focusedRow = useResponsiveTable(
1740
- (global) => global.responsiveTableSlice[name]?.focusedRow
1741
- );
1742
- const statesColumns = useResponsiveTable((global) => {
1743
- const state = global.responsiveTableSlice[name];
1744
- return Array(
1745
- Math.max(
1746
- 0,
1747
- state?.reserveColumnsForStates || 0,
1748
- state?.statesColumns?.length || 0
1749
- )
1750
- ).fill(1).map((_, index) => {
1751
- const r = {
1752
- Icon: "",
1753
- iconColor: "transparent",
1754
- id: String(index),
1755
- tooltip: "",
1756
- ...state.statesColumns?.[index]
1757
- };
1758
- return r;
1759
- });
1760
- });
1761
- const filters = useResponsiveTable(
1762
- (global) => {
1763
- const tableState = global.responsiveTableSlice[name];
1764
- const returnObject = tableState?.filters?.map((current) => ({
1765
- columnIndex: tableState.columns.findIndex(
1766
- (search) => search.name === current.column
1767
- ),
1768
- definition: current
1769
- })).filter((current) => current.columnIndex >= 0);
1770
- return returnObject;
1771
- },
1772
- (a, b) => {
1773
- return a?.length === b?.length && a?.reduce((result, current, index) => {
1774
- return result && shallowEqual$1(current.definition, b[index].definition);
1775
- }, true);
1776
- }
1777
- );
1778
- const additionalColumns = React.useMemo(
1779
- () => columns?.reduce(
1780
- (count, column) => count + (column.showAsAdditional ? 1 : 0),
1781
- 0
1782
- ),
1783
- [columns]
1784
- );
1785
- const [isFiltersRowVisible, setIsFiltersRowVisible] = React.useState(
1786
- showFilters ?? false
1787
- );
1788
- React.useEffect(() => {
1789
- persistentStorage.showResponsiveTableFilters = isFiltersRowVisible;
1790
- }, [isFiltersRowVisible]);
1791
- const buttonProps = useOtherTagButton(
1792
- React.useMemo(
1793
- () => ({
1794
- className: "additionalColumn",
1795
- onClick: () => setIsFiltersRowVisible((current) => !current)
1796
- }),
1797
- []
1798
- )
1799
- );
1800
- const [ref, setRef] = useState(null);
1801
- useUpdateEffect(() => {
1802
- const handleFocus = (ev) => {
1803
- ev.stopPropagation();
1804
- setIsFiltersRowVisible(true);
1805
- };
1806
- ref?.addEventListener(customEvents.focus, handleFocus);
1807
- return () => {
1808
- ref?.removeEventListener(customEvents.focus, handleFocus);
1809
- };
1810
- }, [ref]);
1811
- const domProps = useDomProps("headerTr", {}, domPropsSelector(name));
1812
- return /* @__PURE__ */ jsxs("thead", { children: [
1813
- /* @__PURE__ */ jsxs("tr", { ...domProps, children: [
1814
- (additionalColumns > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx(
1815
- "th",
1816
- {
1817
- "aria-colindex": 1,
1818
- "aria-rowindex": 1,
1819
- "data-focused": focusedColumn === 1 && focusedRow === -1 - (hasNonAdditionalFilters ? 1 : 0),
1820
- ...buttonProps,
1821
- tabIndex: focusedColumn === 1 && focusedRow === -1 - (hasNonAdditionalFilters ? 1 : 0) ? 0 : -1,
1822
- "aria-label": isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text,
1823
- role: "rowheader",
1824
- children: hasNonAdditionalFilters ? /* @__PURE__ */ jsx(
1825
- Icon,
1826
- {
1827
- className: "filterButton",
1828
- name: "Filter",
1829
- title: isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text,
1830
- "aria-label": isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text
1831
- }
1832
- ) : /* @__PURE__ */ jsxs(Fragment, { children: [
1833
- /* @__PURE__ */ jsx("span", { style: { display: "none" }, children: isFiltersRowVisible ? getLabel("lblHideFilters").text : getLabel("lblShowFilters").text }),
1834
- /* @__PURE__ */ jsx("span", { children: "\xA0" })
1835
- ] })
1836
- }
1837
- ),
1838
- statesColumns.map(({ id, ...state }, i) => /* @__PURE__ */ jsx(StateCell, { isHeader: true, index: i, rowIndex: 1, state }, id)),
1839
- columns?.map((current, actualColumnIndex) => ({
1840
- ...current,
1841
- actualTableColumnIndex: actualColumnIndex
1842
- })).filter((current) => !current.showAsAdditional).map((current, columnIndex) => {
1843
- if (current.hidden)
1844
- return null;
1845
- return /* @__PURE__ */ jsx(
1846
- HeaderCell,
1847
- {
1848
- apiaColumnIndex: current.actualTableColumnIndex,
1849
- columnIndex: current.actualTableColumnIndex,
1850
- inTableColumnIndex: columnIndex
1851
- },
1852
- current.name
1853
- );
1854
- })
1855
- ] }),
1856
- (filters?.length ?? 0) > 0 && /* @__PURE__ */ jsxs(
1857
- "tr",
1858
- {
1859
- "aria-rowindex": 2,
1860
- "data-rowindex": -1,
1861
- ref: setRef,
1862
- "data-focusindex": 2,
1863
- className: `responsiveTable__filters__row ${isFiltersRowVisible ? "" : "hidden"}`,
1864
- children: [
1865
- (additionalColumns > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx(
1866
- "td",
1867
- {
1868
- className: "noFilter",
1869
- "aria-colindex": 1,
1870
- "aria-rowindex": 2,
1871
- tabIndex: focusedColumn === 1 && focusedRow === -1 ? 0 : -1,
1872
- "data-focused": focusedColumn === 1 && focusedRow === -1,
1873
- children: "\xA0"
1874
- }
1875
- ),
1876
- statesColumns.map(({ id }, i) => /* @__PURE__ */ jsx(StateCell, { isHeader: true, index: i, rowIndex: 2 }, id)),
1877
- columns?.filter((current) => !current.showAsAdditional && !current.hidden).map((current, columnIndex) => {
1878
- const filter = filters.find(
1879
- (search) => search.definition.column === current.name
1880
- );
1881
- const RenderComponent = filter ? FiltersRenderer?.(String(filter.definition.id)) : void 0;
1882
- return current.showAsAdditional ? null : /* @__PURE__ */ jsx(
1883
- FilterCell,
1884
- {
1885
- columnIndex,
1886
- filter: filter?.definition,
1887
- Renderer: RenderComponent
1888
- },
1889
- current.name
1890
- );
1891
- })
1892
- ]
1893
- }
1894
- )
1895
- ] });
1896
- };
1897
- const Header = React.memo(NoMemoHeader);
1898
-
1899
- const NoMemoAdditionalColumnDefaultRenderer = ({
1900
- column,
1901
- cell
1902
- }) => {
1903
- return /* @__PURE__ */ jsxs(
1904
- Box,
1905
- {
1906
- className: `${cell.className ?? ""} responsiveTable__additionalInfoItem`,
1907
- id: cell.id,
1908
- title: cell.title,
1909
- children: [
1910
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
1911
- column.label ?? column.name,
1912
- ":"
1913
- ] }),
1914
- " ",
1915
- cell.children
1916
- ]
1917
- }
1918
- );
1919
- };
1920
- const AdditionalColumnDefaultRenderer = React.memo(
1921
- NoMemoAdditionalColumnDefaultRenderer
1922
- );
1923
-
1924
- const SeparatorCell = ({
1925
- colSpan,
1926
- rowIndex
1927
- }) => {
1928
- const { name } = useResponsiveTableContext();
1929
- const domProps = useDomProps(
1930
- "separator",
1931
- { rowIndex },
1932
- domPropsSelector(name)
1933
- );
1934
- return /* @__PURE__ */ jsx("td", { className: "row__separator__cell", colSpan, ...domProps });
1935
- };
1936
-
1937
- const NoMemoDefaultRowRenderer = React.forwardRef(({ row, rowIndex, ...props }, currentRef) => /* @__PURE__ */ jsx(
1938
- Box,
1939
- {
1940
- as: "tr",
1941
- sx: useMemo(
1942
- () => ({
1943
- "&.colored, & > *": {
1944
- color: row.color,
1945
- background: row.background
1946
- }
1947
- }),
1948
- [row.background, row.color]
1949
- ),
1950
- ref: currentRef,
1951
- "data-test-id": props.id,
1952
- ...props
1953
- }
1954
- ));
1955
- NoMemoDefaultRowRenderer.displayName = "DefaultRowRenderer";
1956
- const DefaultRowRenderer = NoMemoDefaultRowRenderer;
1957
-
1958
- const NoMemoDefaultCellRenderer = React.forwardRef(
1959
- ({
1960
- cell: { Renderer, rendererProps, AccordionRenderer, ariaLabel, ...cell },
1961
- column,
1962
- row,
1963
- ...props
1964
- }, currentRef) => {
1965
- const { avoidAutoEllipsis } = useResponsiveTableContext();
1966
- return /* @__PURE__ */ jsx(
1967
- Box,
1968
- {
1969
- as: "td",
1970
- sx: useMemo(
1971
- () => ({
1972
- "&.colored": {
1973
- background: cell.background,
1974
- color: cell.color,
1975
- fontWeight: "bold"
1976
- }
1977
- }),
1978
- [cell.background, cell.color]
1979
- ),
1980
- ref: currentRef,
1981
- ...props,
1982
- ...cell,
1983
- "aria-label": ariaLabel,
1984
- children: !avoidAutoEllipsis ? /* @__PURE__ */ jsx(
1985
- AutoEllipsis,
1986
- {
1987
- overrideStyles: (el) => {
1988
- const td = el.closest("td");
1989
- return {
1990
- width: window.getComputedStyle(td).width
1991
- };
1992
- },
1993
- children: props.children ?? cell.children
1994
- }
1995
- ) : props.children ?? cell.children
1996
- }
1997
- );
1998
- }
1999
- );
2000
- NoMemoDefaultCellRenderer.displayName = "DefaultCellRenderer";
2001
- const DefaultCellRenderer = NoMemoDefaultCellRenderer;
2002
-
2003
- const NoMemoCell = ({
2004
- columnIndex,
2005
- inTableColumnIndex,
2006
- rowIndex
2007
- }) => {
2008
- const { name } = useResponsiveTableContext();
2009
- const domProps = useDomProps(
2010
- "td",
2011
- { columnIndex: inTableColumnIndex, rowIndex },
2012
- domPropsSelector(name)
2013
- );
2014
- const cell = useResponsiveTable((global) => {
2015
- const tableState = global.responsiveTableSlice[name];
2016
- return tableState?.rows[rowIndex]?.cells[columnIndex];
2017
- }, shallowEqual);
2018
- const column = useResponsiveTable((global) => {
2019
- const tableState = global.responsiveTableSlice[name];
2020
- return tableState?.columns[columnIndex];
2021
- }, shallowEqual);
2022
- const row = useResponsiveTable((global) => {
2023
- const tableState = global.responsiveTableSlice[name];
2024
- return tableState?.rows[rowIndex];
2025
- }, shallowEqual);
2026
- const Renderer = React.useMemo(
2027
- () => cell?.Renderer ?? column.Renderer ?? DefaultCellRenderer,
2028
- [cell?.Renderer, column.Renderer]
2029
- );
2030
- if (!Renderer || !cell)
2031
- return row.separator ? /* @__PURE__ */ jsx("div", { className: "separator" }) : null;
2032
- return /* @__PURE__ */ jsx(
2033
- Renderer,
2034
- {
2035
- ...domProps,
2036
- cell,
2037
- column,
2038
- row,
2039
- onFocus: (ev) => {
2040
- if (ev.target instanceof HTMLElement) {
2041
- const cell2 = ev.target.closest("td,th");
2042
- if (ev.target === cell2) {
2043
- const widget = cell2?.querySelector(getFocusSelector());
2044
- if (cell2 && widget) {
2045
- widget.focus();
2046
- cell2.tabIndex = -1;
2047
- }
2048
- }
2049
- }
2050
- }
2051
- }
2052
- );
2053
- };
2054
- const Cell = React.memo(NoMemoCell);
2055
-
2056
- const NoMemoRow = ({ rowIndex }) => {
2057
- const { name } = useResponsiveTableContext();
2058
- const { columns, hasNonAdditionalFilters, isScrolledIntoView } = useResponsiveTable((global) => {
2059
- const tableState = global.responsiveTableSlice[name];
2060
- return {
2061
- columns: tableState?.columns ?? [],
2062
- hasNonAdditionalFilters: tableState?.hasNonAdditionalFilters,
2063
- isScrolledIntoView: tableState.scrollIntoViewRow === rowIndex
2064
- };
2065
- }, shallowEqual);
2066
- const row = useResponsiveTable(
2067
- (global) => global.responsiveTableSlice[name].rows[rowIndex],
2068
- shallowEqual
2069
- );
2070
- const additionalCells = useResponsiveTable(
2071
- (global) => {
2072
- const tableState = global.responsiveTableSlice[name];
2073
- return tableState.columns.map(
2074
- (current, index) => current.showAsAdditional ? {
2075
- index,
2076
- column: current
2077
- } : null
2078
- ).filter(
2079
- (current) => !!current
2080
- ).map((current) => {
2081
- return {
2082
- cell: tableState.rows[rowIndex]?.cells[current.index],
2083
- column: current.column,
2084
- columnIndex: current.index
2085
- };
2086
- });
2087
- },
2088
- (currentValue, newValue) => {
2089
- return currentValue.reduce(
2090
- (accumulatedBoolean, currentCell, cellIndex) => {
2091
- return accumulatedBoolean && shallowEqual(currentCell, newValue[cellIndex]);
2092
- },
2093
- true
2094
- );
2095
- }
2096
- );
2097
- const { isDragging, isExpanded, shouldForbidSelection } = useResponsiveTable(
2098
- (global) => {
2099
- const tableState = global.responsiveTableSlice[name];
2100
- return {
2101
- isExpanded: tableState.expandedRows.includes(rowIndex),
2102
- isDragging: tableState.draggingRow === rowIndex,
2103
- shouldForbidSelection: tableState.rows[rowIndex]?.forbidSelection
2104
- };
2105
- },
2106
- shallowEqual
2107
- );
2108
- const domProps = useDomProps(
2109
- "tr",
2110
- {
2111
- isThisRowExpanded: isExpanded,
2112
- rowIndex
2113
- },
2114
- domPropsSelector(name)
2115
- );
2116
- const expandedRowDomProps = useDomProps(
2117
- "tr",
2118
- {
2119
- isTheExpandedRow: true,
2120
- rowIndex
2121
- },
2122
- domPropsSelector(name)
2123
- );
2124
- const handleExpandedState = React.useCallback(
2125
- (ev) => {
2126
- const willBeExpanded = typeof ev === "boolean" ? ev : !isExpanded;
2127
- if (!willBeExpanded)
2128
- responsiveTableStore.dispatch(
2129
- responsiveTableActions.update({
2130
- tableName: name,
2131
- expandedRows: responsiveTableStore.getState().responsiveTableSlice[name].expandedRows.filter((current) => current !== rowIndex)
2132
- })
2133
- );
2134
- else
2135
- responsiveTableStore.dispatch(
2136
- responsiveTableActions.update({
2137
- tableName: name,
2138
- expandedRows: [
2139
- ...responsiveTableStore.getState().responsiveTableSlice[name].expandedRows,
2140
- rowIndex
2141
- ]
2142
- })
2143
- );
2144
- },
2145
- [isExpanded, name, rowIndex]
2146
- );
2147
- const statesCount = useResponsiveTable((globalState) => {
2148
- const state = globalState.responsiveTableSlice[name];
2149
- return Math.max(
2150
- state?.reserveColumnsForStates || 0,
2151
- state?.statesColumns?.length ?? 0,
2152
- 0
2153
- );
2154
- }, shallowEqual);
2155
- const states = React.useMemo(
2156
- () => (row.states ?? []).map((current) => ({ ...current, id: uniqueId() })),
2157
- [row.states]
2158
- );
2159
- const { ref, ...additionalCellDomProps } = useDomProps(
2160
- "additionalTd",
2161
- { rowIndex },
2162
- domPropsSelector(name)
2163
- );
2164
- const Renderer = React.useMemo(
2165
- () => row.renderer ?? DefaultRowRenderer,
2166
- [row.renderer]
2167
- );
2168
- const hasScrolled = useRef(false);
2169
- return /* @__PURE__ */ jsxs(Fragment, { children: [
2170
- /* @__PURE__ */ jsx(
2171
- Renderer,
2172
- {
2173
- ...domProps,
2174
- row,
2175
- rowIndex,
2176
- 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" : ""}`,
2177
- onKeyDown: React.useCallback(
2178
- (ev) => {
2179
- if (ev.key.toLowerCase() === "arrowleft" && ev.ctrlKey) {
2180
- ev.preventDefault();
2181
- ev.stopPropagation();
2182
- handleExpandedState(false);
2183
- }
2184
- if (ev.key.toLowerCase() === "arrowright" && ev.ctrlKey) {
2185
- ev.preventDefault();
2186
- ev.stopPropagation();
2187
- handleExpandedState(true);
2188
- }
2189
- },
2190
- [handleExpandedState]
2191
- ),
2192
- ...{
2193
- ref: (el) => {
2194
- if (el && isScrolledIntoView && !hasScrolled.current) {
2195
- hasScrolled.current = true;
2196
- scrollParentIntoElement(el);
2197
- }
2198
- }
2199
- },
2200
- children: row.separator ? /* @__PURE__ */ jsx(
2201
- SeparatorCell,
2202
- {
2203
- colSpan: (additionalCells.length > 0 || hasNonAdditionalFilters ? 1 : 0) + statesCount + columns.filter((current) => !current.showAsAdditional).length,
2204
- rowIndex
2205
- }
2206
- ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2207
- (additionalCells.length > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx("td", { className: "additionalInfo__cell", ...additionalCellDomProps, children: additionalCells.length > 0 && /* @__PURE__ */ jsx(
2208
- IconButton,
2209
- {
2210
- size: "Lg",
2211
- ...getVariant("icon-outline"),
2212
- icon: isExpanded ? MdKeyboardArrowDown : MdKeyboardArrowRight,
2213
- "aria-label": isExpanded ? getLabel("lblCollapseRow").text : getLabel("lblExpandRow").text,
2214
- className: "moreInformationButton",
2215
- onClick: handleExpandedState
2216
- }
2217
- ) }),
2218
- Array(statesCount).fill("").map((_, i) => {
2219
- return /* @__PURE__ */ jsx(
2220
- StateCell,
2221
- {
2222
- index: i,
2223
- state: states[i],
2224
- rowIndex
2225
- },
2226
- states[i]?.id ?? i
2227
- );
2228
- }),
2229
- columns.map((current, actualColumnIndex) => ({
2230
- ...current,
2231
- actualColumnIndex
2232
- })).filter((current) => !current.showAsAdditional).map((current, inTableColumnIndex) => {
2233
- if (current.hidden)
2234
- return null;
2235
- return /* @__PURE__ */ jsx(
2236
- Cell,
2237
- {
2238
- columnIndex: current.actualColumnIndex,
2239
- rowIndex,
2240
- inTableColumnIndex
2241
- },
2242
- current.name
2243
- );
2244
- })
2245
- ] })
2246
- }
2247
- ),
2248
- isExpanded && /* @__PURE__ */ jsx("tr", { className: "expandedRow", ...expandedRowDomProps, children: /* @__PURE__ */ jsx(
2249
- "td",
2250
- {
2251
- colSpan: columns.length - additionalCells.length + states.length + 1,
2252
- children: /* @__PURE__ */ jsx(Box, { className: "responsiveTable__additionalInfoContainer", children: additionalCells.map((current) => {
2253
- const { Renderer: ColumnRenderer } = current.column;
2254
- if (ColumnRenderer)
2255
- return /* @__PURE__ */ jsx(
2256
- ColumnRenderer,
2257
- {
2258
- cell: current.cell,
2259
- column: current.column,
2260
- row
2261
- },
2262
- current.column.name
2263
- );
2264
- return /* @__PURE__ */ jsx(
2265
- AdditionalColumnDefaultRenderer,
2266
- {
2267
- cell: current.cell,
2268
- column: current.column,
2269
- row
2270
- },
2271
- current.column.name
2272
- );
2273
- }) })
2274
- }
2275
- ) })
2276
- ] });
2277
- };
2278
- const Row = React.memo(NoMemoRow);
2279
-
2280
- const TableLoadingContext = createContext({
2281
- current: true
2282
- });
2283
-
2284
- const NoRegistersRenderer = () => {
2285
- const { labels } = useResponsiveTableContext();
2286
- const { current } = useContext(TableLoadingContext);
2287
- return /* @__PURE__ */ jsx(Box, { className: "no__registers", children: current ? labels.noRegisters : "" });
2288
- };
2289
-
2290
- const NoMemoTableRenderer = ({ variant }) => {
2291
- const { name, label, labels } = useResponsiveTableContext();
2292
- const domProps = useDomProps(
2293
- "table",
2294
- {},
2295
- (global) => global.responsiveTableSlice[name]
2296
- );
2297
- const rows = useResponsiveTable((global) => {
2298
- const tableState = global.responsiveTableSlice[name];
2299
- return tableState?.rows?.map((current) => current.id);
2300
- }, shallowEqual);
2301
- const columnsCount = useResponsiveTable(
2302
- (global) => (global.responsiveTableSlice[name]?.nonAdditionalColumnsCount ?? 0) + (global.responsiveTableSlice[name]?.hasNonAdditionalFilters ? 1 : 0) + (global.responsiveTableSlice[name]?.statesColumns?.length ?? 0) + (global.responsiveTableSlice[name]?.columns.find(
2303
- (current) => current.showAsAdditional
2304
- ) ? 1 : 0)
2305
- );
2306
- const rowsCount = useResponsiveTable(
2307
- (global) => global.responsiveTableSlice[name]?.rows.length || 0
2308
- );
2309
- return /* @__PURE__ */ jsxs(
2310
- Box,
2311
- {
2312
- ...domProps,
2313
- as: "table",
2314
- className: "responsiveTable__table",
2315
- ...getVariant(variant || "layout.common.tables.primary"),
2316
- "aria-label": label,
2317
- children: [
2318
- /* @__PURE__ */ jsx(Header, {}),
2319
- /* @__PURE__ */ jsx("tbody", { children: rowsCount > 0 ? rows?.map((row, index) => {
2320
- return /* @__PURE__ */ jsx(Row, { rowIndex: index }, row ?? `${row}-${index}`);
2321
- }) : labels.noRegisters ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columnsCount, children: /* @__PURE__ */ jsx(NoRegistersRenderer, {}) }) }) : null })
2322
- ]
2323
- }
2324
- );
2325
- };
2326
- const TableRenderer = React.memo(NoMemoTableRenderer);
2327
-
2328
- const NoMemoAccordionCell = ({ cell, column }) => {
2329
- return /* @__PURE__ */ jsxs(
2330
- Box,
2331
- {
2332
- className: `responsiveTable__accordionElement__column ${cell.className ?? ""}`,
2333
- children: [
2334
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
2335
- column.label ?? column.name,
2336
- ": "
2337
- ] }),
2338
- /* @__PURE__ */ jsx(Box, { as: "span", sx: { color: cell.color, background: cell.background }, children: cell?.children })
2339
- ]
2340
- },
2341
- column.name
2342
- );
2343
- };
2344
- const AccordionCell = NoMemoAccordionCell;
2345
-
2346
- const NoMemoAccordionElement = ({ row, rowIndex }) => {
2347
- const { name } = useResponsiveTableContext();
2348
- const indexColumns = useResponsiveTable((global) => {
2349
- const tableState = global.responsiveTableSlice[name];
2350
- return tableState?.accordionIndexColumns;
2351
- }, shallowEqual);
2352
- const columns = useResponsiveTable((global) => {
2353
- const tableState = global.responsiveTableSlice[name];
2354
- return tableState?.columns;
2355
- }, shallowEqual);
2356
- const title = React.useMemo(() => {
2357
- if (row.title)
2358
- return row.title;
2359
- if (Array.isArray(indexColumns)) {
2360
- return indexColumns.map(
2361
- (current) => (
2362
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2363
- row.cells[current.index].title || row.cells[current.index].children
2364
- )
2365
- ).join(" | ");
2366
- }
2367
- return row.cells[0].title ?? row.cells[0].children;
2368
- }, [indexColumns, row]);
2369
- const isSelected = useResponsiveTable(
2370
- (global) => global.responsiveTableSlice[name].allowSelection !== false ? global.responsiveTableSlice[name].selectedRows.includes(rowIndex) : void 0
2371
- );
2372
- const isFocused = useResponsiveTable(
2373
- (global) => global.responsiveTableSlice[name].focusedRow === rowIndex
2374
- );
2375
- const buttonProps = useMemo(() => {
2376
- const htmlTitles = [];
2377
- const hasAccordionTitleColumn = columns.some((c) => c.showInAccordionTitle);
2378
- row.cells.forEach((cell, i) => {
2379
- if (hasAccordionTitleColumn && columns[i].showInAccordionTitle && cell.isHtml || !hasAccordionTitleColumn && i === 0 && cell.isHtml) {
2380
- htmlTitles.push(true);
2381
- }
2382
- });
2383
- return {
2384
- title,
2385
- ariaLabel: title,
2386
- label: title,
2387
- checked: isSelected,
2388
- isHtml: htmlTitles,
2389
- onChange: (isChecked) => {
2390
- const isMultiple = responsiveTableStore.getState().responsiveTableSlice[name].isMultiple;
2391
- responsiveTableStore.dispatch(
2392
- responsiveTableActions.update({
2393
- tableName: name,
2394
- selectedRows: isMultiple ? isChecked ? [
2395
- ...responsiveTableStore.getState().responsiveTableSlice[name].selectedRows,
2396
- rowIndex
2397
- ] : responsiveTableStore.getState().responsiveTableSlice[name].selectedRows.filter((current) => current !== rowIndex) : [rowIndex]
2398
- })
2399
- );
2400
- },
2401
- tabIndex: isFocused ? 0 : -1,
2402
- rightButtons: row.accordionButtonProps?.rightButtons,
2403
- onUserPressEnter: row.accordionButtonProps?.onUserPressEnter,
2404
- domButtonProps: {
2405
- buttonSx: {
2406
- "&.accordion__item__button .accordion__item__button__label": {
2407
- color: row.color
2408
- }
2409
- }
2410
- }
2411
- };
2412
- }, [
2413
- columns,
2414
- isFocused,
2415
- isSelected,
2416
- name,
2417
- row.accordionButtonProps?.onUserPressEnter,
2418
- row.accordionButtonProps?.rightButtons,
2419
- row.cells,
2420
- row.color,
2421
- rowIndex,
2422
- title
2423
- ]);
2424
- if (!Array.isArray(indexColumns) || !columns)
2425
- return null;
2426
- return /* @__PURE__ */ jsxs(AccordionItem, { id: row.id, buttonProps, children: [
2427
- columns.map((currentColumn, columnIndex) => {
2428
- const Renderer = row.cells[columnIndex].AccordionRenderer ?? currentColumn.AccordionRenderer ?? AccordionCell;
2429
- return currentColumn.hideFromAccordion || currentColumn.showAsAdditional ? null : /* @__PURE__ */ jsx(
2430
- Renderer,
2431
- {
2432
- cell: row.cells[columnIndex],
2433
- column: currentColumn,
2434
- columnIndex,
2435
- row,
2436
- rowIndex
2437
- },
2438
- currentColumn.name
2439
- );
2440
- }),
2441
- columns.filter((current) => !!current.showAsAdditional).map((currentColumn, columnIndex) => {
2442
- const Renderer = row.cells[columnIndex].AccordionRenderer ?? currentColumn.AccordionRenderer ?? AccordionCell;
2443
- return currentColumn.hideFromAccordion ? null : /* @__PURE__ */ jsx(
2444
- Renderer,
2445
- {
2446
- cell: row.cells[columnIndex],
2447
- column: currentColumn,
2448
- columnIndex,
2449
- row,
2450
- rowIndex
2451
- },
2452
- currentColumn.name
2453
- );
2454
- })
2455
- ] });
2456
- };
2457
- const AccordionElement = memo(NoMemoAccordionElement);
2458
-
2459
- const NoMemoAccordionRenderer = () => {
2460
- const { name } = useResponsiveTableContext();
2461
- const { columns, rows } = useResponsiveTable((global) => {
2462
- const tableState = global.responsiveTableSlice[name];
2463
- return {
2464
- columns: tableState?.columns,
2465
- rows: tableState?.rows
2466
- };
2467
- }, shallowEqual);
2468
- React.useEffect(() => {
2469
- if (columns && rows) {
2470
- const markedAsTitleColumns = [];
2471
- columns.forEach((column, index) => {
2472
- if (column.showInAccordionTitle)
2473
- markedAsTitleColumns.push({ column, index });
2474
- });
2475
- if (markedAsTitleColumns.length > 0) {
2476
- responsiveTableStore.dispatch(
2477
- responsiveTableActions.update({
2478
- tableName: name,
2479
- accordionIndexColumns: markedAsTitleColumns
2480
- })
2481
- );
2482
- } else {
2483
- const columnsLength = columns.length;
2484
- let indexColumn = null;
2485
- let currentIndex = 0;
2486
- while (!indexColumn && currentIndex < columns.length) {
2487
- let isAnyEmptyRow = false;
2488
- for (const row of rows) {
2489
- if (!row.cells[currentIndex].children) {
2490
- isAnyEmptyRow = true;
2491
- break;
2492
- }
2493
- }
2494
- if (!isAnyEmptyRow && columns[currentIndex]) {
2495
- indexColumn = columns[currentIndex];
2496
- } else {
2497
- currentIndex += 1;
2498
- if (currentIndex === columnsLength)
2499
- break;
2500
- }
2501
- }
2502
- if (!indexColumn) {
2503
- [indexColumn] = columns;
2504
- currentIndex = 0;
2505
- }
2506
- responsiveTableStore.dispatch(
2507
- responsiveTableActions.update({
2508
- tableName: name,
2509
- accordionIndexColumns: [
2510
- { column: indexColumn, index: currentIndex }
2511
- ]
2512
- })
2513
- );
2514
- }
2515
- }
2516
- }, [columns, name, rows]);
2517
- return /* @__PURE__ */ jsxs(Accordion, { children: [
2518
- !rows || rows.length === 0 && /* @__PURE__ */ jsx(NoRegistersRenderer, {}),
2519
- rows?.map((current, rowIndex) => /* @__PURE__ */ jsx(AccordionElement, { row: current, rowIndex }, current.id))
2520
- ] });
2521
- };
2522
- const AccordionRenderer = React.memo(NoMemoAccordionRenderer);
2523
-
2524
- const domPropsSelector = (name) => (global) => global.responsiveTableSlice[name];
2525
- const NoMemoResponsiveTable = React.forwardRef(({ className, variant, ...props }, ref) => {
2526
- const breakpoint = useBreakpointIndex({ defaultIndex: 3 });
2527
- const { currentBreakPoint, forceAccordion } = useResponsiveTableContext();
2528
- const actualBreakpoint = currentBreakPoint ?? breakpoint;
2529
- return /* @__PURE__ */ jsx(
2530
- Box,
2531
- {
2532
- ...props,
2533
- ...getVariant("layout.common.tables.responsive"),
2534
- className: `responsiveTable__wrapper ${className ?? ""}`,
2535
- ref,
2536
- children: actualBreakpoint >= 3 && !forceAccordion ? /* @__PURE__ */ jsx(KeyHandler, { children: /* @__PURE__ */ jsx(TableRenderer, { variant }) }) : /* @__PURE__ */ jsx(AccordionRenderer, {})
2537
- }
2538
- );
2539
- });
2540
- NoMemoResponsiveTable.displayName = "ResponsiveTable";
2541
- const ResponsiveTable = React.memo(NoMemoResponsiveTable);
2542
-
2543
- const NoMemoSort = ({ tableName }) => {
2544
- const { name, onSortChange } = useResponsiveTableContext(tableName);
2545
- const columns = useResponsiveTable((global) => {
2546
- return global.responsiveTableSlice[name]?.columns;
2547
- }, shallowEqual);
2548
- return /* @__PURE__ */ jsx(Fragment, { children: columns?.map((column, columnIndex) => {
2549
- return column.showAsAdditional || column.allowSorting === false ? null : /* @__PURE__ */ jsxs(Label, { children: [
2550
- /* @__PURE__ */ jsx(Box, { as: "span", children: column.label ?? column.name }),
2551
- /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
2552
- Select,
2553
- {
2554
- value: column.currentSorting === null ? "" : column.currentSorting,
2555
- onChange: (ev) => {
2556
- if (onSortChange)
2557
- onSortChange({
2558
- columnIndex,
2559
- column,
2560
- name: column.name,
2561
- sortValue: ev.target.value === "" ? null : ev.target.value
2562
- });
2563
- },
2564
- children: [
2565
- /* @__PURE__ */ jsx("option", { value: "" }),
2566
- /* @__PURE__ */ jsx("option", { value: "A", children: window.ORDER_ASC_LABEL }),
2567
- /* @__PURE__ */ jsx("option", { value: "D", children: window.ORDER_DESC_LABEL })
2568
- ]
2569
- }
2570
- ) })
2571
- ] }, column.name);
2572
- }) });
2573
- };
2574
- const Sort = React.memo(NoMemoSort);
2575
-
2576
- dayjs.extend(customParseFormat);
2577
- const dateFormat = getDateFormat();
2578
- function controlDatesOrder(first, last) {
2579
- if (!first || !last)
2580
- return true;
2581
- if (dayjs(last, dateFormat).isBefore(dayjs(first, dateFormat))) {
2582
- return window.MSG_FEC_FIN_MAY_FEC_INI;
2583
- }
2584
- return true;
2585
- }
2586
- const NoMemoInnerRender = React.forwardRef(
2587
- ({
2588
- filters,
2589
- tableName
2590
- }, ref) => {
2591
- const {
2592
- onFilterBlur,
2593
- onFilterChange,
2594
- onFilterPressEnter,
2595
- name,
2596
- FiltersRenderer
2597
- } = useResponsiveTableContext(tableName);
2598
- const [lastEmittedValue, setLastEmittedValue] = React.useState(null);
2599
- const [lastEmittedValueByPartner, setLastEmittedValueByPartner] = React.useState(null);
2600
- return /* @__PURE__ */ jsx(Box, { ref, className: "filtersRender", children: filters?.map((filter, key) => {
2601
- if (filter.hide)
2602
- return null;
2603
- const Renderer = FiltersRenderer?.(String(filter.id));
2604
- const isDate = filter.type === "D" || filter.type === "date";
2605
- const filterToId = filter.filterToId ?? `${filter.id}i`;
2606
- const filterTo = {
2607
- ...filter,
2608
- hide: filter.filterToId === void 0,
2609
- id: filterToId,
2610
- currentValue: filter.filterToValue ?? "",
2611
- required: false
2612
- };
2613
- const column = responsiveTableStore.getState().responsiveTableSlice[name].columns.find((current) => current.name === filter.column);
2614
- const filterTitle = filter.title || column?.label || column?.title || column?.name || "noFilterNorColumnTitle";
2615
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2616
- /* @__PURE__ */ jsx(
2617
- Box,
2618
- {
2619
- className: filter.type === "D" || filter.type === "date" ? "twoColumns" : "",
2620
- children: /* @__PURE__ */ jsxs(
2621
- Label,
2622
- {
2623
- title: isDate ? window.LBL_DATE_FILTER_FROM_TOOLTIP : filterTitle,
2624
- children: [
2625
- window.SHOW_REQUIRED_POSITION !== "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: filter.required }),
2626
- !filter?.avoidLabel && /* @__PURE__ */ jsx(Box, { as: "span", children: isDate && !filter.hideToFilter ? formatMessage(window.LBL_DATE_FILTER_FROM_TXT, {
2627
- TOK1: filterTitle
2628
- }) : filterTitle }),
2629
- Renderer ? /* @__PURE__ */ jsx(Renderer, { filter }) : filter.isRange ? /* @__PURE__ */ jsx(RangeFilter, { filter }) : /* @__PURE__ */ jsx(
2630
- ApiaFilter,
2631
- {
2632
- filter,
2633
- onChange: (currentValue) => {
2634
- const result = controlDatesOrder(
2635
- currentValue,
2636
- lastEmittedValueByPartner
2637
- );
2638
- if (result === true) {
2639
- setLastEmittedValue(currentValue);
2640
- if (onFilterChange)
2641
- void onFilterChange({ ...filter, currentValue });
2642
- }
2643
- return result;
2644
- },
2645
- onBlur: (currentValue) => {
2646
- if (onFilterBlur)
2647
- void onFilterBlur({ ...filter, currentValue });
2648
- },
2649
- onPressEnter: (currentValue) => {
2650
- if (onFilterPressEnter)
2651
- void onFilterPressEnter({
2652
- ...filter,
2653
- currentValue
2654
- });
2655
- }
2656
- }
2657
- ),
2658
- window.SHOW_REQUIRED_POSITION === "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: filter.required })
2659
- ]
2660
- }
2661
- )
2662
- },
2663
- filter.id ?? filter.column ?? key
2664
- ),
2665
- isDate && !filter.hideToFilter && /* @__PURE__ */ jsx(
2666
- Box,
2667
- {
2668
- className: filter.type === "D" || filter.type === "date" ? "twoColumns" : "",
2669
- children: /* @__PURE__ */ jsxs(Label, { title: window.LBL_DATE_FILTER_TO_TOOLTIP, children: [
2670
- !filter?.avoidLabel && /* @__PURE__ */ jsx(Box, { as: "span", children: formatMessage(window.LBL_DATE_FILTER_TO_TXT, {
2671
- TOK1: filterTitle
2672
- }) }),
2673
- /* @__PURE__ */ jsx(
2674
- ApiaFilter,
2675
- {
2676
- filter: filterTo,
2677
- onChange: (currentValue) => {
2678
- const result = controlDatesOrder(
2679
- lastEmittedValue,
2680
- currentValue
2681
- );
2682
- if (result === true) {
2683
- setLastEmittedValueByPartner(currentValue);
2684
- if (onFilterChange)
2685
- void onFilterChange({
2686
- ...filter,
2687
- filterToId,
2688
- filterToValue: currentValue
2689
- });
2690
- }
2691
- return result;
2692
- },
2693
- onBlur: (currentValue) => {
2694
- if (onFilterBlur)
2695
- void onFilterBlur({
2696
- ...filter,
2697
- filterToId,
2698
- filterToValue: currentValue
2699
- });
2700
- },
2701
- onPressEnter: (currentValue) => {
2702
- if (onFilterPressEnter)
2703
- void onFilterPressEnter({
2704
- ...filter,
2705
- filterToId,
2706
- filterToValue: currentValue
2707
- });
2708
- }
2709
- }
2710
- )
2711
- ] })
2712
- }
2713
- )
2714
- ] }, filter.id ?? filter.column ?? key);
2715
- }) });
2716
- }
2717
- );
2718
- NoMemoInnerRender.displayName = "FiltersInnerRender";
2719
- const InnerRender = React.memo(NoMemoInnerRender);
2720
-
2721
- const NoMemoAdditional = ({ tableName }) => {
2722
- const { name } = useResponsiveTableContext(tableName);
2723
- const additionalFilters = useResponsiveTable((global) => {
2724
- const state = global.responsiveTableSlice[name];
2725
- return state?.filters.filter(
2726
- (current) => !current.group && (!current.isMeta && !state?.columns.find(
2727
- (search) => search.name === current.column && !current.asAdditional
2728
- ) || state?.columns.find(
2729
- (search) => search.name === current.column && search.showAsAdditional
2730
- ) || current.asAdditional)
2731
- );
2732
- }, shallowEqual);
2733
- return /* @__PURE__ */ jsx(InnerRender, { tableName, filters: additionalFilters });
2734
- };
2735
- const Additional = React.memo(NoMemoAdditional);
2736
-
2737
- const NoMemoResponsive = ({ tableName }) => {
2738
- const { name } = useResponsiveTableContext(tableName);
2739
- const nonAdditionalFilters = useResponsiveTable((global) => {
2740
- const state = global.responsiveTableSlice[name];
2741
- return state?.filters.filter(
2742
- (current) => !current.isMeta && state?.columns.find((search) => search.name === current.column)
2743
- );
2744
- }, shallowEqual);
2745
- return /* @__PURE__ */ jsx(
2746
- InnerRender,
2747
- {
2748
- tableName,
2749
- isResponsive: true,
2750
- filters: nonAdditionalFilters
2751
- }
2752
- );
2753
- };
2754
- const Responsive = React.memo(NoMemoResponsive);
2755
-
2756
- var __defProp$1 = Object.defineProperty;
2757
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2758
- var __publicField$1 = (obj, key, value) => {
2759
- __defNormalProp$1(obj, key + "" , value);
2760
- return value;
2761
- };
2762
- const maximizationPersist = {
2763
- getState(id) {
2764
- const current = persistentStorage.maximizationPersist ?? {};
2765
- return current[id];
2766
- },
2767
- setState(id, isMaximized) {
2768
- const current = persistentStorage.maximizationPersist ?? {};
2769
- current[id] = isMaximized;
2770
- persistentStorage.maximizationPersist = current;
2771
- }
2772
- };
2773
- class Maximization extends EventEmitter {
2774
- constructor() {
2775
- super(...arguments);
2776
- __publicField$1(this, "components", {});
2777
- }
2778
- checkComponentExists(id) {
2779
- return this.components[id] === void 0;
2780
- }
2781
- emit(eventName, params) {
2782
- if (eventName === "toggle") {
2783
- const { id, isMaximized } = params;
2784
- this.checkComponentExists(id);
2785
- if (!this.components[id])
2786
- return;
2787
- this.components[id].isMaximized = isMaximized ?? !this.components[id].isMaximized;
2788
- maximizationPersist.setState(id, this.components[id].isMaximized);
2789
- this.isMaximized(id);
2790
- super.emit(eventName, {
2791
- id,
2792
- isMaximized: this.components[id].isMaximized
2793
- });
2794
- }
2795
- }
2796
- isMaximized(id) {
2797
- this.checkComponentExists(id);
2798
- const selector = this.components[id]?.selector;
2799
- if (selector === void 0)
2800
- return void 0;
2801
- const content = typeof selector === "string" ? document.querySelector(selector) : selector?.();
2802
- if (content)
2803
- content.classList.toggle("maximized", this.components[id].isMaximized);
2804
- return this.components[id]?.isMaximized;
2805
- }
2806
- registerMaximizableComponent(id, selector) {
2807
- this.components[id] = {
2808
- selector: selector ?? this.components[id]?.selector,
2809
- isMaximized: false
2810
- // isDefaultMaximized ??
2811
- // (conf<boolean>('lists.persistMaximized', true, 'boolean')
2812
- // ? maximizationPersist.getState(id)
2813
- // : undefined) ??
2814
- // isConfDefaultMaximized,
2815
- };
2816
- }
2817
- toggleIsMaximized(id, isMaximized) {
2818
- this.emit("toggle", { id, isMaximized });
2819
- }
2820
- }
2821
- const maximizationController = new Maximization();
2822
- function useIsMaximized(id) {
2823
- React.useEffect(() => {
2824
- maximizationController.registerMaximizableComponent(id);
2825
- }, [id]);
2826
- const [isInnerMaximized, innerSetIsMaximized] = React.useState(
2827
- maximizationController.isMaximized(id) ?? false
2828
- );
2829
- React.useEffect(() => {
2830
- const handleToggle = ({
2831
- id: eventId,
2832
- isMaximized: eventIsMaximized
2833
- }) => {
2834
- if (id === eventId)
2835
- innerSetIsMaximized((current) => eventIsMaximized ?? !current);
2836
- };
2837
- const unsuscribe1 = maximizationController.on("toggle", handleToggle);
2838
- innerSetIsMaximized(
2839
- maximizationController.components[id].isMaximized ?? false
2840
- );
2841
- return () => {
2842
- unsuscribe1();
2843
- };
2844
- }, [id]);
2845
- return {
2846
- isMaximized: isInnerMaximized,
2847
- toggleIsMaximized: React.useCallback(
2848
- (isMaximized) => {
2849
- maximizationController.emit("toggle", { id, isMaximized });
2850
- },
2851
- [id]
2852
- )
2853
- };
2854
- }
2855
-
2856
- const NoMemoPagination = ({
2857
- listId: outerListId,
2858
- onPageChange,
2859
- ...props
2860
- }) => {
2861
- const listId = useResponsiveTableContext().name;
2862
- const { isMaximized, toggleIsMaximized } = useIsMaximized(
2863
- outerListId ?? listId
2864
- );
2865
- const numberCurrentPage = Number(props.currentPage);
2866
- const [internCurrentPage, setCurrentPage] = useState(
2867
- numberCurrentPage ?? 1
2868
- );
2869
- const [lastEmittedPage, setLastEmittedPage] = useState(
2870
- numberCurrentPage ?? 1
2871
- );
2872
- const previousPage = usePrevious(props.currentPage);
2873
- if (previousPage.current !== props.currentPage) {
2874
- setLastEmittedPage(props.currentPage);
2875
- }
2876
- const setCurrentAndDispatch = useCallback(
2877
- (page) => {
2878
- if (page !== lastEmittedPage) {
2879
- setCurrentPage(page);
2880
- onPageChange?.(page);
2881
- setLastEmittedPage(page);
2882
- }
2883
- },
2884
- [lastEmittedPage, onPageChange]
2885
- );
2886
- useEffect(() => {
2887
- setCurrentPage(numberCurrentPage);
2888
- }, [numberCurrentPage]);
2889
- return /* @__PURE__ */ jsx(
2890
- Pagination$1,
2891
- {
2892
- ...{ ...props, isMaximized, onMaximize: toggleIsMaximized },
2893
- currentPage: internCurrentPage,
2894
- onPageChange: setCurrentAndDispatch
2895
- }
2896
- );
2897
- };
2898
- const Pagination = React.memo(NoMemoPagination);
2899
-
2900
- const NoMemoGrouped = ({
2901
- group,
2902
- tableName
2903
- }) => {
2904
- const { name } = useResponsiveTableContext(tableName);
2905
- const groupedFilters = useResponsiveTable((global) => {
2906
- const state = global.responsiveTableSlice[name];
2907
- return state?.filters.filter((current) => current.group === group);
2908
- }, shallowEqual);
2909
- return /* @__PURE__ */ jsx(InnerRender, { tableName, filters: groupedFilters });
2910
- };
2911
- const Grouped = React.memo(NoMemoGrouped);
2912
-
2913
- function setAriaAttributes(element, attribute, value) {
2914
- element.setAttribute(attribute, value);
2915
- }
2916
- function getRowDomProps(rowIndex, state) {
2917
- const elementType = getIndex(
2918
- ["headerTr", "filtersTr", "tr"],
2919
- [
2920
- rowIndex == -2 || !state.hasNonAdditionalFilters && rowIndex == -1,
2921
- rowIndex == -1,
2922
- true
2923
- ]
2924
- );
2925
- return getDomProps(
2926
- getDomStoreProps(
2927
- elementType,
2928
- {
2929
- rowIndex
2930
- },
2931
- () => state
2932
- ),
2933
- elementType,
2934
- { rowIndex }
2935
- );
2936
- }
2937
- function applyRowSelectionAttributes(row, state) {
2938
- if (!(row instanceof HTMLElement))
2939
- return;
2940
- const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
2941
- const props = getRowDomProps(rowIndex, state);
2942
- Object.entries(props).forEach(([key, value]) => {
2943
- let match;
2944
- match = key.match(/aria-(\w+)/);
2945
- if (match) {
2946
- setAriaAttributes(row, key, value);
2947
- } else if (match = key.match(/data-(\w+)/)) {
2948
- row.dataset[match[1]] = value;
2949
- }
2950
- });
2951
- }
2952
- function applySelectionAttributes(table, _previousState, state) {
2953
- const previousSelectedRows = table.querySelectorAll(
2954
- '[aria-selected="true"]'
2955
- );
2956
- previousSelectedRows.forEach((c) => applyRowSelectionAttributes(c, state));
2957
- if (state.selectedRows.length) {
2958
- const newSelectedRows = table.querySelectorAll(
2959
- state.selectedRows.map((index) => `tr[data-rowindex="${index}"]`).join(",")
2960
- );
2961
- newSelectedRows.forEach((c) => applyRowSelectionAttributes(c, state));
2962
- }
2963
- }
2964
-
2965
- function handleMouseDownEvent(ev) {
2966
- const target = ev.target;
2967
- if (target instanceof HTMLElement) {
2968
- const cell = target.closest("th,td");
2969
- const row = target.closest("tr");
2970
- const table = target.closest("table");
2971
- if (cell && row && table) {
2972
- const state = this.getState();
2973
- const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
2974
- const colIndex = Number.parseInt(cell.ariaColIndex || "a", 10);
2975
- if (!isNaN(rowIndex) && !isNaN(colIndex)) {
2976
- if (!ev.ctrlKey && !ev.shiftKey || state.isMultiple === false) {
2977
- state.selectedRows = [rowIndex];
2978
- } else if (ev.ctrlKey) {
2979
- if (state.selectedRows.includes(rowIndex)) {
2980
- state.selectedRows = state.selectedRows.filter(
2981
- (c) => c !== rowIndex
2982
- );
2983
- } else {
2984
- state.selectedRows = [...state.selectedRows, rowIndex];
2985
- }
2986
- } else if (ev.shiftKey) {
2987
- const previousFocused = this.getState().focusedRow;
2988
- state.selectedRows = [...state.selectedRows];
2989
- const min = Math.min(previousFocused, rowIndex);
2990
- const max = Math.max(previousFocused, rowIndex);
2991
- for (let i = min; i <= max; i++) {
2992
- state.selectedRows.push(i);
2993
- }
2994
- }
2995
- state.focusedColumn = colIndex;
2996
- state.focusedRow = rowIndex;
2997
- state.isFocused = true;
2998
- applySelectionAttributes(table, this.getState(), state);
2999
- this.setState(state);
3000
- this.events.emit("onRowClick", [
3001
- { row: state.rows[state.focusedRow], index: state.focusedRow },
3002
- state.focusedRow
3003
- ]);
3004
- } else {
3005
- console.warn("Cannot parse rowIndex or colIndex");
3006
- }
3007
- } else {
3008
- console.warn("Cannot find cell, row or table");
3009
- }
3010
- }
3011
- }
3012
-
3013
- function applyFocusAttributes(table, _previousState, state, focus = state.isFocused, target) {
3014
- focus = focus && table.contains(document.activeElement);
3015
- table.querySelectorAll(getFocusSelector()).forEach((e) => {
3016
- e.tabIndex = -1;
3017
- });
3018
- if (state.focusedColumn === 0) {
3019
- const focusedRow = table.querySelector(
3020
- `tr[data-rowindex="${state.focusedRow}"]`
3021
- );
3022
- if (focusedRow) {
3023
- focusedRow.tabIndex = 0;
3024
- window.requestAnimationFrame(() => {
3025
- if (focus) {
3026
- focusedRow.focus();
3027
- }
3028
- });
3029
- }
3030
- } else {
3031
- const focusedCell = table.querySelector(
3032
- `tr[data-rowindex="${state.focusedRow}"] td[aria-colindex="${state.focusedColumn}"], tr[data-rowindex="${state.focusedRow}"] th[aria-colindex="${state.focusedColumn}"]`
3033
- );
3034
- if (focusedCell instanceof HTMLElement) {
3035
- const widgets = [];
3036
- if (state.isEditionMode) {
3037
- widgets.push(
3038
- ...focusedCell.querySelectorAll(getFocusSelector())
3039
- );
3040
- } else {
3041
- const widget = focusedCell.querySelector(getFocusSelector());
3042
- if (widget) {
3043
- widgets.push(widget);
3044
- }
3045
- }
3046
- if (widgets.length) {
3047
- widgets.forEach((widget, i) => {
3048
- widget.tabIndex = 0;
3049
- if (i === 0)
3050
- window.requestAnimationFrame(() => {
3051
- if (focus) {
3052
- widget.focus();
3053
- }
3054
- });
3055
- });
3056
- } else {
3057
- focusedCell.tabIndex = 0;
3058
- window.requestAnimationFrame(() => {
3059
- if (focus) {
3060
- focusedCell.focus();
3061
- }
3062
- });
3063
- }
3064
- }
3065
- }
3066
- }
3067
-
3068
- function handleKeyDownEvent(ev) {
3069
- const target = ev.target;
3070
- const state = this.getState();
3071
- if (target instanceof HTMLElement) {
3072
- const table = target.closest("table");
3073
- const row = target.closest("tr");
3074
- const cell = target.closest("th,td");
3075
- if (table && row) {
3076
- if (state.isEditionMode) {
3077
- if (ev.code === "Escape" || ev.code === "Enter") {
3078
- state.isEditionMode = false;
3079
- this.setState(state);
3080
- applyFocusAttributes(table, this.getState(), state);
3081
- }
3082
- } else {
3083
- const rowIndex = Number.parseInt(row.dataset.rowindex || "a", 10);
3084
- const colIndex = Number.parseInt(cell?.ariaColIndex || "0", 10);
3085
- if (!isNaN(rowIndex) && !isNaN(colIndex)) {
3086
- if ([
3087
- "ArrowDown",
3088
- "ArrowUp",
3089
- "ArrowLeft",
3090
- "ArrowRight",
3091
- "End",
3092
- "Enter",
3093
- "Home",
3094
- "PageUp",
3095
- "PageDown"
3096
- ].includes(ev.code) || ev.code === "Space" && ev.ctrlKey) {
3097
- ev.preventDefault();
3098
- let mustFocus = false;
3099
- const maxColumnIndex = state.columns.length + Math.max(
3100
- state.reserveColumnsForStates ?? 0,
3101
- state.statesColumns?.length ?? 0
3102
- ) + (state.hasNonAdditionalFilters ? 1 : 0);
3103
- switch (ev.code) {
3104
- case "Space":
3105
- if (state.selectedRows.includes(rowIndex)) {
3106
- state.selectedRows = state.selectedRows.filter(
3107
- (c) => c !== rowIndex
3108
- );
3109
- } else {
3110
- state.selectedRows = [...state.selectedRows, rowIndex];
3111
- }
3112
- break;
3113
- case "ArrowDown":
3114
- state.focusedRow = addBoundary(
3115
- state.focusedRow + 1,
3116
- state.hasNonAdditionalFilters ? -2 : -1,
3117
- state.rows.length - 1
3118
- );
3119
- mustFocus = true;
3120
- if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
3121
- state.selectedRows = [
3122
- ...state.selectedRows,
3123
- state.focusedRow
3124
- ];
3125
- } else {
3126
- state.selectedRows = [state.focusedRow];
3127
- }
3128
- break;
3129
- case "ArrowUp":
3130
- state.focusedRow = addBoundary(
3131
- state.focusedRow - 1,
3132
- state.hasNonAdditionalFilters ? -2 : -1,
3133
- state.rows.length - 1
3134
- );
3135
- mustFocus = true;
3136
- if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
3137
- state.selectedRows = [
3138
- ...state.selectedRows,
3139
- state.focusedRow
3140
- ];
3141
- } else {
3142
- state.selectedRows = [state.focusedRow];
3143
- }
3144
- break;
3145
- case "ArrowLeft":
3146
- state.focusedColumn = addBoundary(
3147
- state.focusedColumn - 1,
3148
- 0,
3149
- maxColumnIndex
3150
- );
3151
- mustFocus = true;
3152
- break;
3153
- case "ArrowRight":
3154
- state.focusedColumn = addBoundary(
3155
- state.focusedColumn + 1,
3156
- 0,
3157
- maxColumnIndex
3158
- );
3159
- mustFocus = true;
3160
- break;
3161
- case "Home":
3162
- mustFocus = true;
3163
- if (state.focusedColumn === 0) {
3164
- state.focusedRow = state.hasNonAdditionalFilters ? -2 : -1;
3165
- if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
3166
- const max = Math.max(
3167
- state.focusedRow,
3168
- this.getState().focusedRow
3169
- );
3170
- const min = Math.min(
3171
- state.focusedRow,
3172
- this.getState().focusedRow
3173
- );
3174
- for (let i = min; i <= max; i++) {
3175
- state.selectedRows.push(i);
3176
- }
3177
- } else {
3178
- state.selectedRows = [state.focusedRow];
3179
- }
3180
- } else {
3181
- state.focusedColumn = 1;
3182
- }
3183
- break;
3184
- case "End":
3185
- mustFocus = true;
3186
- if (state.focusedColumn === 0) {
3187
- state.focusedRow = state.rows.length - 1;
3188
- if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
3189
- const max = Math.max(
3190
- state.focusedRow,
3191
- this.getState().focusedRow
3192
- );
3193
- const min = Math.min(
3194
- state.focusedRow,
3195
- this.getState().focusedRow
3196
- );
3197
- for (let i = min; i <= max; i++) {
3198
- state.selectedRows.push(i);
3199
- }
3200
- } else {
3201
- state.selectedRows = [state.focusedRow];
3202
- }
3203
- } else {
3204
- state.focusedColumn = maxColumnIndex;
3205
- }
3206
- break;
3207
- case "PageUp":
3208
- mustFocus = true;
3209
- state.focusedRow = addBoundary(
3210
- state.focusedRow - 6,
3211
- state.hasNonAdditionalFilters ? -2 : -1,
3212
- state.rows.length - 1
3213
- );
3214
- if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
3215
- const previousFocused = this.getState().focusedRow;
3216
- state.selectedRows = [...state.selectedRows];
3217
- const min = Math.min(previousFocused, state.focusedRow);
3218
- const max = Math.max(previousFocused, state.focusedRow);
3219
- for (let i = min; i <= max; i++) {
3220
- state.selectedRows.push(i);
3221
- }
3222
- } else {
3223
- state.selectedRows = [state.focusedRow];
3224
- }
3225
- break;
3226
- case "PageDown":
3227
- mustFocus = true;
3228
- state.focusedRow = addBoundary(
3229
- state.focusedRow + 6,
3230
- state.hasNonAdditionalFilters ? -2 : -1,
3231
- state.rows.length - 1
3232
- );
3233
- if (ev.ctrlKey) ; else if (ev.shiftKey && state.isMultiple !== false) {
3234
- const previousFocused = this.getState().focusedRow;
3235
- state.selectedRows = [...state.selectedRows];
3236
- const min = Math.min(previousFocused, state.focusedRow);
3237
- const max = Math.max(previousFocused, state.focusedRow);
3238
- for (let i = min; i <= max; i++) {
3239
- state.selectedRows.push(i);
3240
- }
3241
- } else {
3242
- state.selectedRows = [state.focusedRow];
3243
- }
3244
- break;
3245
- case "Enter": {
3246
- mustFocus = true;
3247
- state.isEditionMode = true;
3248
- this.setState(state);
3249
- if (state.focusedRow >= 0) {
3250
- this.events.emit("onSelectRows", [
3251
- this.getSelection().map((index) => ({
3252
- index,
3253
- row: this.getState().rows[index]
3254
- })),
3255
- state.focusedRow
3256
- ]);
3257
- }
3258
- return;
3259
- }
3260
- }
3261
- state.isFocused = true;
3262
- applySelectionAttributes(table, this.getState(), state);
3263
- applyFocusAttributes(table, this.getState(), state, mustFocus);
3264
- this.setState(state);
3265
- }
3266
- }
3267
- }
3268
- }
3269
- }
3270
- }
3271
-
3272
- var __defProp = Object.defineProperty;
3273
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3274
- var __publicField = (obj, key, value) => {
3275
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3276
- return value;
3277
- };
3278
- var __accessCheck = (obj, member, msg) => {
3279
- if (!member.has(obj))
3280
- throw TypeError("Cannot " + msg);
3281
- };
3282
- var __privateGet = (obj, member, getter) => {
3283
- __accessCheck(obj, member, "read from private field");
3284
- return getter ? getter.call(obj) : member.get(obj);
3285
- };
3286
- var __privateAdd = (obj, member, value) => {
3287
- if (member.has(obj))
3288
- throw TypeError("Cannot add the same private member more than once");
3289
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3290
- };
3291
- var __privateSet = (obj, member, value, setter) => {
3292
- __accessCheck(obj, member, "write to private field");
3293
- member.set(obj, value);
3294
- return value;
3295
- };
3296
- var _unsubscribe;
3297
- class Controller2 {
3298
- constructor(tableName) {
3299
- this.tableName = tableName;
3300
- __publicField(this, "events", new EventEmitter());
3301
- __privateAdd(this, _unsubscribe, () => {
3302
- });
3303
- __publicField(this, "unsubscribe", () => {
3304
- });
3305
- __publicField(this, "el", null);
3306
- __publicField(this, "setRef", (el) => {
3307
- this.unsubscribe();
3308
- this.el = el;
3309
- if (el) {
3310
- el.addEventListener("keydown", this.handleKeyDownEvent);
3311
- el.addEventListener("mousedown", this.handleClickEvent);
3312
- el.addEventListener("dblclick", this.handleDoubleClickEvent);
3313
- this.unsubscribe = () => {
3314
- el.removeEventListener("keydown", this.handleKeyDownEvent);
3315
- el.removeEventListener("mousedown", this.handleClickEvent);
3316
- el.removeEventListener("dblclick", this.handleDoubleClickEvent);
3317
- };
3318
- }
3319
- });
3320
- __publicField(this, "handleClickEvent");
3321
- __publicField(this, "handleKeyDownEvent");
3322
- __publicField(this, "handleDoubleClickEvent", (ev) => {
3323
- const target = ev.target;
3324
- if (target instanceof HTMLElement) {
3325
- const row = target.closest("tr");
3326
- const table = target.closest("table");
3327
- const selectedRows = this.getSelection().reduce((acc, index) => {
3328
- if (index >= 0) {
3329
- acc.push({
3330
- index,
3331
- row: this.getState().rows[index]
3332
- });
3333
- }
3334
- return acc;
3335
- }, []);
3336
- const rowIndex = noNaN(row?.dataset.rowindex || "a", -1);
3337
- if (row && table && selectedRows.length > 0 && rowIndex >= 0) {
3338
- this.events.emit("onSelectRows", [
3339
- selectedRows,
3340
- this.getState().focusedRow
3341
- ]);
3342
- }
3343
- }
3344
- });
3345
- this.handleClickEvent = handleMouseDownEvent.bind(this);
3346
- this.handleKeyDownEvent = handleKeyDownEvent.bind(this);
3347
- }
3348
- setResponsiveTableContextEvents(evs) {
3349
- __privateGet(this, _unsubscribe).call(this);
3350
- const u1 = this.events.on(
3351
- "onChangeSelection",
3352
- (a) => evs.onChangeSelection?.(...a)
3353
- );
3354
- const u2 = this.events.on("onRowClick", (a) => evs.onRowClick?.(...a));
3355
- const u3 = this.events.on("onSelectRows", (a) => evs.onSelectRows?.(...a));
3356
- __privateSet(this, _unsubscribe, () => {
3357
- u1();
3358
- u2();
3359
- u3();
3360
- });
3361
- }
3362
- /**
3363
- * Returns a copy of the current state object
3364
- */
3365
- getState() {
3366
- return {
3367
- ...responsiveTableStore.getState().responsiveTableSlice[this.tableName]
3368
- };
3369
- }
3370
- getSelection() {
3371
- const selectedRows = new Set(this.getState().selectedRows);
3372
- return [...selectedRows.values()];
3373
- }
3374
- setState(state) {
3375
- if (state.selectedRows && !shallowEqual$1(state.selectedRows, this.getState().selectedRows)) {
3376
- this.events.emit("onChangeSelection", [
3377
- state.selectedRows.map((index) => ({
3378
- index,
3379
- row: this.getState().rows[index]
3380
- }))
3381
- ]);
3382
- }
3383
- if (state.scrollIntoViewRow !== void 0 && state.scrollIntoViewRow !== this.getState().scrollIntoViewRow) {
3384
- const row = this.el?.querySelector(
3385
- `tr[data-rowindex="${state.scrollIntoViewRow}"]`
3386
- );
3387
- if (row) {
3388
- row.scrollIntoView({ block: "nearest", inline: "nearest" });
3389
- }
3390
- }
3391
- responsiveTableStore.dispatch(
3392
- responsiveTableActions.controller2UpdateSelectionState({
3393
- tableName: this.tableName,
3394
- ...state
3395
- })
3396
- );
3397
- }
3398
- updateSelectionState() {
3399
- window.requestAnimationFrame(() => {
3400
- if (this.el) {
3401
- const table = this.el.querySelector("table");
3402
- if (table) {
3403
- applyFocusAttributes(table, this.getState(), this.getState());
3404
- }
3405
- }
3406
- });
3407
- }
3408
- }
3409
- _unsubscribe = new WeakMap();
3410
- const Controller2Component = ({
3411
- controller,
3412
- ...props
3413
- }) => {
3414
- controller.setResponsiveTableContextEvents({
3415
- onChangeSelection: props.onChangeSelection,
3416
- onSelectRows: props.onSelectRows,
3417
- onRowClick: props.onRowClick
3418
- });
3419
- const previousColumns = useRef([]);
3420
- const previousRows = useRef([]);
3421
- const box = useRef(null);
3422
- useResponsiveTable((state) => {
3423
- if (!Object.is(
3424
- state.responsiveTableSlice[controller.tableName]?.columns,
3425
- previousColumns.current
3426
- )) {
3427
- previousColumns.current = state.responsiveTableSlice[controller.tableName]?.columns;
3428
- controller.updateSelectionState();
3429
- }
3430
- if (!Object.is(
3431
- state.responsiveTableSlice[controller.tableName]?.rows,
3432
- previousRows.current
3433
- )) {
3434
- previousRows.current = state.responsiveTableSlice[controller.tableName]?.rows;
3435
- controller.updateSelectionState();
3436
- }
3437
- });
3438
- return /* @__PURE__ */ jsx(
3439
- Box,
3440
- {
3441
- ...props,
3442
- ref: (el) => {
3443
- controller.setRef(el);
3444
- box.current = el;
3445
- }
3446
- }
3447
- );
3448
- };
3449
- function makeController2(tableName) {
3450
- const controller = new Controller2(tableName);
3451
- return [
3452
- controller,
3453
- (props) => {
3454
- return /* @__PURE__ */ jsx(Controller2Component, { ...props, controller });
3455
- }
3456
- ];
3457
- }
3458
-
3459
- const TableContextReproducer = ({
3460
- children,
3461
- tableName
3462
- }) => {
3463
- const context = useResponsiveTableContext(tableName);
3464
- return /* @__PURE__ */ jsx(ResponsiveTableReactContext.Provider, { value: context, children });
3465
- };
3466
-
3467
- const NoMemoDocNameCellRenderer = React.forwardRef(
3468
- ({
3469
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3470
- column,
3471
- row,
3472
- ...props
3473
- }, currentRef) => /* @__PURE__ */ jsx(
3474
- "td",
3475
- {
3476
- ref: currentRef,
3477
- ...props,
3478
- ...cell,
3479
- children: /* @__PURE__ */ jsxs(
3480
- Link,
3481
- {
3482
- className: "cell__download__document",
3483
- title: rendererProps?.docName,
3484
- href: rendererProps?.docUrl,
3485
- onClick: (ev) => {
3486
- ev.preventDefault();
3487
- if (rendererProps?.docUrl)
3488
- void downloadUrl(rendererProps?.docUrl);
3489
- },
3490
- children: [
3491
- /* @__PURE__ */ jsx(Icon, { title: "", name: "Download" }),
3492
- rendererProps?.docName
3493
- ]
3494
- }
3495
- )
3496
- }
3497
- )
3498
- );
3499
- NoMemoDocNameCellRenderer.displayName = "DocNameCellRenderer";
3500
- const DocNameCellRenderer = NoMemoDocNameCellRenderer;
3501
-
3502
- const NoMemoAccordionDocNameCellRenderer = React.forwardRef(
3503
- ({
3504
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3505
- column
3506
- }, currentRef) => /* @__PURE__ */ jsxs(Box, { ref: currentRef, ...cell, children: [
3507
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3508
- column.label ?? column.name,
3509
- ": "
3510
- ] }),
3511
- /* @__PURE__ */ jsxs(
3512
- Link,
3513
- {
3514
- className: "cell__download__document",
3515
- title: rendererProps?.docName,
3516
- href: rendererProps?.docUrl,
3517
- onClick: (ev) => {
3518
- ev.preventDefault();
3519
- if (rendererProps?.docUrl)
3520
- void downloadUrl(rendererProps?.docUrl);
3521
- },
3522
- children: [
3523
- /* @__PURE__ */ jsx(Icon, { title: "", name: "Download" }),
3524
- rendererProps?.docName
3525
- ]
3526
- }
3527
- )
3528
- ] })
3529
- );
3530
- NoMemoAccordionDocNameCellRenderer.displayName = "AccordionDocNameCellRenderer";
3531
- const AccordionDocNameCellRenderer = NoMemoAccordionDocNameCellRenderer;
3532
-
3533
- const NoMemoAccordionHTMLCellRenderer = React.forwardRef(
3534
- ({
3535
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3536
- column,
3537
- row,
3538
- ...props
3539
- }, currentRef) => /* @__PURE__ */ jsxs(Box, { children: [
3540
- column.label.trim() !== "" && /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3541
- column.label,
3542
- ": "
3543
- ] }),
3544
- /* @__PURE__ */ jsx(
3545
- Box,
3546
- {
3547
- ref: currentRef,
3548
- ...props,
3549
- ...cell,
3550
- className: "accordion__cell__renderer",
3551
- dangerouslySetInnerHTML: {
3552
- __html: String(rendererProps?.html ?? children ?? "").replaceAll(
3553
- /<TOK(\d+)/g,
3554
- "&lt;TOK$1"
3555
- )
3556
- },
3557
- as: "span"
3558
- }
3559
- )
3560
- ] })
3561
- );
3562
- NoMemoAccordionHTMLCellRenderer.displayName = "AccordionHTMLCellRenderer";
3563
- const AccordionHTMLCellRenderer = NoMemoAccordionHTMLCellRenderer;
3564
-
3565
- const NoMemoHTMLCellRenderer = React.forwardRef(
3566
- ({
3567
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3568
- column,
3569
- row,
3570
- ...props
3571
- }, currentRef) => /* @__PURE__ */ jsx(
3572
- "td",
3573
- {
3574
- ref: currentRef,
3575
- ...props,
3576
- ...cell,
3577
- dangerouslySetInnerHTML: {
3578
- __html: String(rendererProps?.html ?? children ?? "").replaceAll(
3579
- /<TOK(\d+)/g,
3580
- "&lt;TOK$1"
3581
- )
3582
- }
3583
- }
3584
- )
3585
- );
3586
- NoMemoHTMLCellRenderer.displayName = "HTMLCellRenderer";
3587
- const HTMLCellRenderer = NoMemoHTMLCellRenderer;
3588
-
3589
- const IsLoadingRenderer = () => {
3590
- return /* @__PURE__ */ jsx(Box, { className: "responsiveTable__isLoading", children: /* @__PURE__ */ jsx(Spinner, {}) });
3591
- };
3592
-
3593
- function makeAccordionAsyncRenderer(additionalInfoGetter) {
3594
- const InnerRender = forwardRef(({ row }, ref) => {
3595
- const [moreInfo, setMoreInfo] = useState(null);
3596
- const loadMore = useCallback(async () => {
3597
- const result = await additionalInfoGetter(row);
3598
- setMoreInfo(result);
3599
- }, [row]);
3600
- return /* @__PURE__ */ jsx(Fragment, { children: moreInfo ? /* @__PURE__ */ jsxs(Fragment, { children: [
3601
- /* @__PURE__ */ jsx(IconButton, { icon: "Minus", onClick: () => setMoreInfo(null) }),
3602
- arrayOrArray(moreInfo).map(
3603
- (dataCell) => {
3604
- return /* @__PURE__ */ jsxs(Box, { ref, as: "div", children: [
3605
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3606
- dataCell.name,
3607
- ":"
3608
- ] }),
3609
- " ",
3610
- dataCell.label
3611
- ] }, dataCell.name);
3612
- }
3613
- )
3614
- ] }) : /* @__PURE__ */ jsx(IconButton, { icon: "Plus", onClick: () => void loadMore() }) });
3615
- });
3616
- InnerRender.displayName = "MakeAccordionAsyncRenderer";
3617
- return InnerRender;
3618
- }
3619
-
3620
- function makeAsyncRenderer(additionalInfoGetter) {
3621
- const InnerRender = forwardRef(({ row }, ref) => {
3622
- const [moreInfo, setMoreInfo] = useState(null);
3623
- useMount$1(() => {
3624
- void (async () => {
3625
- const result = await additionalInfoGetter(row);
3626
- setMoreInfo(result);
3627
- })();
3628
- });
3629
- return /* @__PURE__ */ jsx(Fragment, { children: moreInfo ? arrayOrArray(moreInfo).map((dataCell) => {
3630
- return /* @__PURE__ */ jsx(
3631
- Box,
3632
- {
3633
- ref,
3634
- className: `responsiveTable__additionalInfoItem ${dataCell.newline ? "separator" : ""}`,
3635
- children: dataCell.newline ? /* @__PURE__ */ jsxs(Fragment, { children: [
3636
- /* @__PURE__ */ jsxs(Box, { sx: { height: "20px" }, as: "strong", children: [
3637
- dataCell.name,
3638
- ":"
3639
- ] }),
3640
- " ",
3641
- dataCell.label ?? dataCell?.content
3642
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3643
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3644
- dataCell.name,
3645
- ":"
3646
- ] }),
3647
- " ",
3648
- dataCell.label ?? dataCell?.content
3649
- ] })
3650
- },
3651
- `${dataCell.name}-${uniqueId()}`
3652
- );
3653
- }) : /* @__PURE__ */ jsx(Spinner, { size: 15 }) });
3654
- });
3655
- InnerRender.displayName = "MakeAsyncRenderer";
3656
- return InnerRender;
3657
- }
3658
-
3659
- const NoMemoNoEllipsisCellRenderer = React.forwardRef(
3660
- ({
3661
- cell: { Renderer, rendererProps, AccordionRenderer, ariaLabel, ...cell },
3662
- column,
3663
- row,
3664
- ...props
3665
- }, currentRef) => /* @__PURE__ */ jsx(
3666
- Box,
3667
- {
3668
- as: "td",
3669
- sx: useMemo(
3670
- () => ({
3671
- "&.colored": {
3672
- background: cell.background,
3673
- color: cell.color,
3674
- fontWeight: "bold"
3675
- }
3676
- }),
3677
- [cell.background, cell.color]
3678
- ),
3679
- ref: currentRef,
3680
- ...props,
3681
- ...cell,
3682
- "aria-label": ariaLabel,
3683
- children: props.children ?? cell.children
3684
- }
3685
- )
3686
- );
3687
- NoMemoNoEllipsisCellRenderer.displayName = "DefaultCellRenderer";
3688
- const NoEllipsisCellRenderer = memo(NoMemoNoEllipsisCellRenderer);
3689
-
3690
- function getPriorityHandler(priority) {
3691
- let prio;
3692
- if (priority?.includes("priority0"))
3693
- prio = "priorityNone";
3694
- if (priority?.includes("priority1"))
3695
- prio = "priorityLow";
3696
- if (priority?.includes("priority2"))
3697
- prio = "priorityNormal";
3698
- if (priority?.includes("priority3"))
3699
- prio = "priorityHigh";
3700
- if (priority?.includes("priority4"))
3701
- prio = "priorityUrgent";
3702
- return prio;
3703
- }
3704
- const NoMemoPriorityRenderer = React.forwardRef(
3705
- ({
3706
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3707
- column,
3708
- row,
3709
- ...props
3710
- }, currentRef) => {
3711
- const taskPriorityColor = getPriorityHandler(rendererProps?.src);
3712
- return /* @__PURE__ */ jsx(
3713
- "td",
3714
- {
3715
- ...props,
3716
- ...cell,
3717
- ref: currentRef,
3718
- className: "priority",
3719
- sx: {
3720
- color: taskPriorityColor
3721
- },
3722
- children: /* @__PURE__ */ jsx(FaSquare, {})
3723
- }
3724
- );
3725
- }
3726
- );
3727
- NoMemoPriorityRenderer.displayName = "PriorityRenderer";
3728
- const PriorityRenderer = NoMemoPriorityRenderer;
3729
-
3730
- const NoMemoPriorityAccordionRenderer = React.forwardRef(
3731
- ({ cell, column }, currentRef) => {
3732
- const taskPriorityColor = getPriorityHandler(
3733
- cell.rendererProps?.src
3734
- );
3735
- const title = column.label ?? column.name;
3736
- return /* @__PURE__ */ jsxs(Box, { ref: currentRef, className: "priority_container", children: [
3737
- title && /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3738
- column.label ?? column.name,
3739
- ": "
3740
- ] }),
3741
- /* @__PURE__ */ jsx(
3742
- Box,
3743
- {
3744
- as: "span",
3745
- className: "priority",
3746
- sx: {
3747
- color: taskPriorityColor
3748
- },
3749
- children: /* @__PURE__ */ jsx(FaSquare, {})
3750
- }
3751
- )
3752
- ] });
3753
- }
3754
- );
3755
- NoMemoPriorityAccordionRenderer.displayName = "PriorityAccordionRenderer";
3756
- const PriorityAccordionRenderer = NoMemoPriorityAccordionRenderer;
3757
-
3758
- function getStatusRendererClassName(cellValue, columnName) {
3759
- if (cellValue === void 0)
3760
- return "";
3761
- const cellValueDate = cellValue.split(" ")[0];
3762
- const cellValueHour = cellValue.split(" ")[1] ?? "00:00:00";
3763
- const dateFormat = getDateFormat();
3764
- const currentDate = dayjs();
3765
- const currentHour = Number(dayjs().format("HHmm"));
3766
- const queriedDate = dayjs(cellValueDate, dateFormat);
3767
- const queriedHour = Number(dayjs(cellValueHour, dateFormat));
3768
- let statusClassName = "";
3769
- if (currentDate >= queriedDate) {
3770
- statusClassName = columnName;
3771
- }
3772
- if (!queriedHour)
3773
- return statusClassName;
3774
- if (currentDate <= queriedDate && currentHour < queriedHour) {
3775
- statusClassName = columnName;
3776
- }
3777
- return statusClassName;
3778
- }
3779
- const NoMemoStatusRenderer = React.forwardRef(
3780
- ({
3781
- cell: { children, Renderer, rendererProps, AccordionRenderer, ...cell },
3782
- column,
3783
- row,
3784
- ...props
3785
- }, currentRef) => {
3786
- const taskStatusClassName = getStatusRendererClassName(
3787
- children,
3788
- column.name
3789
- );
3790
- return /* @__PURE__ */ jsx(
3791
- "td",
3792
- {
3793
- ...props,
3794
- ...cell,
3795
- ref: currentRef,
3796
- className: taskStatusClassName,
3797
- children
3798
- }
3799
- );
3800
- }
3801
- );
3802
- NoMemoStatusRenderer.displayName = "StatusRenderer";
3803
- const StatusRenderer = NoMemoStatusRenderer;
3804
-
3805
- const NoMemoStatusAccordionRenderer = React.forwardRef(({ cell, column }, currentRef) => {
3806
- const taskStatusClassName = getStatusRendererClassName(
3807
- cell.children,
3808
- column.name
3809
- );
3810
- return /* @__PURE__ */ jsxs(Box, { ref: currentRef, children: [
3811
- /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
3812
- column.label ?? column.name,
3813
- ": "
3814
- ] }),
3815
- /* @__PURE__ */ jsx(Box, { as: "span", className: taskStatusClassName, children: cell.children })
3816
- ] });
3817
- });
3818
- NoMemoStatusAccordionRenderer.displayName = "StatusAccordionRenderer";
3819
- const StatusAccordionRenderer = NoMemoStatusAccordionRenderer;
3820
-
3821
- 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';
3822
35
  //# sourceMappingURL=index.js.map