@envisiongroup/porygon 1.0.0-rc.2 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-components/tables/EFWTable/EFWTable.js +209 -209
- package/dist/react-components/tables/EFWTable/EFWTable.types.d.ts +3 -3
- package/dist/react-components/tables/EFWTable/hooks/useTableController/useTableController copy.js +15 -15
- package/dist/react-components/tables/EFWTable/hooks/useTableController/useTableController.js +15 -15
- package/dist/react-components/tables/EFWTable/utils/cache.js +19 -19
- package/package.json +1 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import { useRef as B, useState as q, useCallback as
|
|
4
|
-
import { useReactTable as
|
|
5
|
-
import { makeStyles as bt, tokens as K, mergeClasses as Et, Checkbox as $e, Card as
|
|
6
|
-
import { useTableSelection as
|
|
7
|
-
import { renderCellContent as
|
|
8
|
-
import { useDefaultAddButton as
|
|
9
|
-
import { useDefaultUpdateButton as
|
|
10
|
-
import { useDefaultDeleteButton as
|
|
1
|
+
import { jsx as C, jsxs as Ye } from "react/jsx-runtime";
|
|
2
|
+
import * as wt from "react";
|
|
3
|
+
import { useRef as B, useState as q, useCallback as v, useEffect as k, useMemo as F } from "react";
|
|
4
|
+
import { useReactTable as It, getSortedRowModel as xt, getFilteredRowModel as yt, getCoreRowModel as zt } from "@tanstack/react-table";
|
|
5
|
+
import { makeStyles as bt, tokens as K, mergeClasses as Et, Checkbox as $e, Card as _t } from "@fluentui/react-components";
|
|
6
|
+
import { useTableSelection as Ct } from "./hooks/useTableSelection/useTableSelection.js";
|
|
7
|
+
import { renderCellContent as vt } from "./utils/index.js";
|
|
8
|
+
import { useDefaultAddButton as Rt } from "./hooks/useDefaultAddButton/useDefaultAddButton.js";
|
|
9
|
+
import { useDefaultUpdateButton as Mt } from "./hooks/useDefaultUpdateButton/useDefaultUpdateButton.js";
|
|
10
|
+
import { useDefaultDeleteButton as Nt } from "./hooks/useDefaultDeleteButton/useDefaultDeleteButton.js";
|
|
11
11
|
import { generateId as E } from "./utils/general.js";
|
|
12
|
-
import { EFWTableCommandBar as
|
|
13
|
-
import { EFWTableHeader as
|
|
14
|
-
import { EFWTableBody as
|
|
12
|
+
import { EFWTableCommandBar as Wt } from "./components/EFWTableCommandBar/EFWTableCommandBar.js";
|
|
13
|
+
import { EFWTableHeader as kt } from "./components/EFWTableHeader/EFWTableHeader.js";
|
|
14
|
+
import { EFWTableBody as Tt } from "./components/EFWTableBody/EFWTableBody.js";
|
|
15
15
|
import { EFWTableEmpty as At } from "./components/EFWTableEmpty/EFWTableEmpty.js";
|
|
16
|
-
const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [],
|
|
16
|
+
const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], w = 120, T = 80, J = 2500, O = 48, Qt = 48, Ft = bt({
|
|
17
17
|
"efw-table": {},
|
|
18
18
|
/* Transición suave para el box-shadow en las celdas y cabeceras fijas */
|
|
19
19
|
"efw-table-scroll-container": {
|
|
@@ -67,7 +67,7 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
67
67
|
height: ne = 700,
|
|
68
68
|
itemSize: Ve = 32,
|
|
69
69
|
// tableStyle = 'row',
|
|
70
|
-
enableSelection:
|
|
70
|
+
enableSelection: y = !0,
|
|
71
71
|
enableCommandBar: V = !0,
|
|
72
72
|
defaultSelectedItems: Ze = Bt,
|
|
73
73
|
onSelectionChange: Qe,
|
|
@@ -75,37 +75,37 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
75
75
|
resizableColumns: Q = !1,
|
|
76
76
|
columnSizing: z = G,
|
|
77
77
|
useVirtualization: Ue = !1,
|
|
78
|
-
autoSizeColumns:
|
|
78
|
+
autoSizeColumns: R = !1,
|
|
79
79
|
tableRef: et,
|
|
80
80
|
onItemsChange: se,
|
|
81
81
|
onScroll: re,
|
|
82
82
|
addButtonConfig: tt = G,
|
|
83
83
|
updateButtonConfig: nt = G,
|
|
84
84
|
deleteButtonConfig: st = G,
|
|
85
|
-
alwaysButtons:
|
|
85
|
+
alwaysButtons: ce = X,
|
|
86
86
|
noSelectionButtons: rt = X,
|
|
87
|
-
singleSelectionButtons:
|
|
88
|
-
multiSelectionButtons:
|
|
87
|
+
singleSelectionButtons: ct = X,
|
|
88
|
+
multiSelectionButtons: oe = X,
|
|
89
89
|
beforeAddItems: L,
|
|
90
90
|
beforeUpdateItems: D,
|
|
91
91
|
beforeDeleteItems: H,
|
|
92
|
-
columnRenderers:
|
|
92
|
+
columnRenderers: ie,
|
|
93
93
|
useDefaultRendererAsFallback: ae = !0
|
|
94
94
|
}) => {
|
|
95
|
-
const le = Ft(),
|
|
95
|
+
const le = Ft(), ot = Et(Je, le["efw-table"]), M = B(!1), ue = te !== void 0, [it, at] = q(() => (Ke || qe).map((t) => ({
|
|
96
96
|
...t,
|
|
97
|
-
|
|
98
|
-
}))), b = ue ? te || qe :
|
|
97
|
+
_rowId: t._rowId || E()
|
|
98
|
+
}))), b = ue ? te || qe : it, [S, j] = q(() => {
|
|
99
99
|
const e = {};
|
|
100
100
|
return f.forEach((t) => {
|
|
101
101
|
const n = z[t.internalName];
|
|
102
102
|
if (n?.width) {
|
|
103
|
-
const s = n.minWidth ??
|
|
103
|
+
const s = n.minWidth ?? T, r = n.maxWidth ?? J;
|
|
104
104
|
e[t.internalName] = Math.min(Math.max(n.width ?? 0, s), r);
|
|
105
105
|
}
|
|
106
106
|
}), e;
|
|
107
|
-
}), de = B(z), [
|
|
108
|
-
rowSelection:
|
|
107
|
+
}), de = B(z), [_, fe] = q(0), {
|
|
108
|
+
rowSelection: N,
|
|
109
109
|
setRowSelection: he,
|
|
110
110
|
// selectedIndexes,
|
|
111
111
|
deselectAll: me,
|
|
@@ -114,32 +114,32 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
114
114
|
// selectMultiple,
|
|
115
115
|
getSelectedItems: ge,
|
|
116
116
|
getSelectedRows: Se
|
|
117
|
-
} =
|
|
117
|
+
} = Ct({
|
|
118
118
|
initialSelection: Ze,
|
|
119
119
|
onSelectionChange: Qe,
|
|
120
|
-
enableSelection:
|
|
121
|
-
}),
|
|
122
|
-
|
|
120
|
+
enableSelection: y
|
|
121
|
+
}), we = B(null), [P, ut] = q(null), dt = v((e) => {
|
|
122
|
+
we.current = e, ut(e);
|
|
123
123
|
}, []), p = B(b);
|
|
124
|
-
|
|
124
|
+
k(() => {
|
|
125
125
|
p.current = b;
|
|
126
126
|
}, [b]);
|
|
127
|
-
const U = B(/* @__PURE__ */ new Set()),
|
|
127
|
+
const U = B(/* @__PURE__ */ new Set()), Ie = F(() => {
|
|
128
128
|
const e = [], t = {};
|
|
129
129
|
let n = 0;
|
|
130
|
-
return
|
|
130
|
+
return y && (e.push("select"), t.select = n, n += O), f.forEach((s) => {
|
|
131
131
|
const r = z[s.internalName] || {};
|
|
132
132
|
if (!r.hidden && r.sticky) {
|
|
133
133
|
e.push(s.internalName), t[s.internalName] = n;
|
|
134
|
-
const
|
|
135
|
-
n +=
|
|
134
|
+
const c = S[s.internalName] || r.width || w;
|
|
135
|
+
n += c;
|
|
136
136
|
}
|
|
137
137
|
}), { stickyColumns: e, stickyPositions: t };
|
|
138
|
-
}, [f,
|
|
138
|
+
}, [f, y, z, S]), I = F(() => {
|
|
139
139
|
const e = [];
|
|
140
|
-
return
|
|
140
|
+
return y && e.push({
|
|
141
141
|
id: "select",
|
|
142
|
-
header: ({ table: t }) => /* @__PURE__ */
|
|
142
|
+
header: ({ table: t }) => /* @__PURE__ */ C(
|
|
143
143
|
$e,
|
|
144
144
|
{
|
|
145
145
|
shape: "circular",
|
|
@@ -148,7 +148,7 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
148
148
|
"data-checkbox": "true"
|
|
149
149
|
}
|
|
150
150
|
),
|
|
151
|
-
cell: ({ row: t }) => /* @__PURE__ */
|
|
151
|
+
cell: ({ row: t }) => /* @__PURE__ */ C(
|
|
152
152
|
$e,
|
|
153
153
|
{
|
|
154
154
|
shape: "circular",
|
|
@@ -168,57 +168,57 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
168
168
|
const n = z[t.internalName] || {};
|
|
169
169
|
if (n.hidden)
|
|
170
170
|
return;
|
|
171
|
-
const s = t.typeAsString === "Note" ?
|
|
171
|
+
const s = t.typeAsString === "Note" ? w * 2 : w, r = n.width || s, c = n.minWidth || T, a = n.maxWidth || J;
|
|
172
172
|
e.push({
|
|
173
173
|
id: t.internalName,
|
|
174
174
|
accessorKey: t.internalName,
|
|
175
175
|
header: t.title || t.internalName,
|
|
176
|
-
cell: ({ row:
|
|
176
|
+
cell: ({ row: o }) => vt(
|
|
177
177
|
t,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
o.original[t.internalName],
|
|
179
|
+
o.original,
|
|
180
|
+
o.index,
|
|
181
|
+
ie,
|
|
182
182
|
ae
|
|
183
183
|
),
|
|
184
|
-
size: Math.min(Math.max(r,
|
|
185
|
-
minSize:
|
|
184
|
+
size: Math.min(Math.max(r, c), a),
|
|
185
|
+
minSize: c,
|
|
186
186
|
maxSize: a,
|
|
187
187
|
enableResizing: Q
|
|
188
188
|
});
|
|
189
189
|
}), e;
|
|
190
190
|
}, [
|
|
191
191
|
f,
|
|
192
|
-
|
|
192
|
+
y,
|
|
193
193
|
Q,
|
|
194
194
|
z,
|
|
195
|
-
|
|
195
|
+
ie,
|
|
196
196
|
ae
|
|
197
197
|
]);
|
|
198
|
-
|
|
198
|
+
k(() => {
|
|
199
199
|
const e = de.current;
|
|
200
200
|
j((t) => {
|
|
201
201
|
let n = !1;
|
|
202
|
-
const s = { ...t }, r = new Set(f.map((
|
|
203
|
-
return Object.keys(s).forEach((
|
|
204
|
-
r.has(
|
|
205
|
-
}), f.forEach((
|
|
206
|
-
const a =
|
|
207
|
-
if (
|
|
208
|
-
const u =
|
|
202
|
+
const s = { ...t }, r = new Set(f.map((c) => c.internalName));
|
|
203
|
+
return Object.keys(s).forEach((c) => {
|
|
204
|
+
r.has(c) || (delete s[c], n = !0);
|
|
205
|
+
}), f.forEach((c) => {
|
|
206
|
+
const a = c.internalName, o = z[a], i = e[a];
|
|
207
|
+
if (o?.width !== void 0) {
|
|
208
|
+
const u = o.minWidth ?? T, h = o.maxWidth ?? J, d = Math.min(Math.max(o.width, u), h);
|
|
209
209
|
s[a] !== d && (s[a] = d, n = !0);
|
|
210
|
-
} else
|
|
210
|
+
} else i?.width !== void 0 && s[a] !== void 0 && (delete s[a], n = !0);
|
|
211
211
|
}), n ? s : t;
|
|
212
212
|
}), de.current = z;
|
|
213
213
|
}, [z, f]);
|
|
214
|
-
const Y = F(() =>
|
|
215
|
-
const s = f.find((
|
|
214
|
+
const Y = F(() => I.reduce((e, t) => {
|
|
215
|
+
const s = f.find((c) => c.internalName === t.id)?.typeAsString === "Note" ? w * 2 : w, r = S[t.id] || (typeof t.size == "number" ? t.size : s);
|
|
216
216
|
return e + r;
|
|
217
|
-
}, 0), [
|
|
217
|
+
}, 0), [I, S, f]), xe = It({
|
|
218
218
|
data: b,
|
|
219
|
-
columns:
|
|
219
|
+
columns: I,
|
|
220
220
|
state: {
|
|
221
|
-
rowSelection:
|
|
221
|
+
rowSelection: N,
|
|
222
222
|
columnSizing: S
|
|
223
223
|
},
|
|
224
224
|
onRowSelectionChange: he,
|
|
@@ -226,40 +226,40 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
226
226
|
j((t) => {
|
|
227
227
|
const n = typeof e == "function" ? e(t) : e, s = {};
|
|
228
228
|
return Object.keys(n).forEach((r) => {
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
-
const a =
|
|
232
|
-
|
|
229
|
+
const c = I.find((a) => a.id === r);
|
|
230
|
+
if (c) {
|
|
231
|
+
const a = c.minSize || T, o = c.maxSize || J;
|
|
232
|
+
M.current ? s[r] = Math.max(n[r], a) : s[r] = Math.min(Math.max(n[r], a), o);
|
|
233
233
|
}
|
|
234
234
|
}), { ...t, ...s };
|
|
235
235
|
});
|
|
236
236
|
},
|
|
237
237
|
//getRowId: row => row.id as string,
|
|
238
238
|
getCoreRowModel: zt(),
|
|
239
|
-
getFilteredRowModel:
|
|
240
|
-
getSortedRowModel:
|
|
239
|
+
getFilteredRowModel: yt(),
|
|
240
|
+
getSortedRowModel: xt(),
|
|
241
241
|
columnResizeMode: "onChange",
|
|
242
242
|
enableRowSelection: !0,
|
|
243
|
-
enableMultiRowSelection:
|
|
243
|
+
enableMultiRowSelection: y
|
|
244
244
|
});
|
|
245
|
-
|
|
245
|
+
k(() => {
|
|
246
246
|
const e = /* @__PURE__ */ new Set();
|
|
247
|
-
Object.keys(
|
|
248
|
-
if (
|
|
247
|
+
Object.keys(N).forEach((t) => {
|
|
248
|
+
if (N[t]) {
|
|
249
249
|
const n = parseInt(t), s = p.current[n];
|
|
250
|
-
s?.
|
|
250
|
+
s?._rowId && e.add(s._rowId);
|
|
251
251
|
}
|
|
252
252
|
}), U.current = e;
|
|
253
|
-
}, [
|
|
254
|
-
const ft =
|
|
253
|
+
}, [N]);
|
|
254
|
+
const ft = v((e) => {
|
|
255
255
|
re?.(e);
|
|
256
|
-
}, [re]),
|
|
256
|
+
}, [re]), ye = (e) => {
|
|
257
257
|
const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
|
|
258
|
-
return Object.keys(
|
|
259
|
-
if (!
|
|
258
|
+
return Object.keys(N).forEach((r) => {
|
|
259
|
+
if (!N[r])
|
|
260
260
|
return;
|
|
261
|
-
const
|
|
262
|
-
a && (s.add(
|
|
261
|
+
const c = Number(r), a = e[c];
|
|
262
|
+
a && (s.add(c), a._rowId && t.add(a._rowId), n.add(a));
|
|
263
263
|
}), {
|
|
264
264
|
hasSelection: t.size > 0 || n.size > 0 || s.size > 0,
|
|
265
265
|
selectedIds: t,
|
|
@@ -271,35 +271,35 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
271
271
|
if (!t.hasSelection)
|
|
272
272
|
return;
|
|
273
273
|
const n = t.sourceLength !== e.length, s = {};
|
|
274
|
-
e.forEach((r,
|
|
274
|
+
e.forEach((r, c) => {
|
|
275
275
|
if (!r)
|
|
276
276
|
return;
|
|
277
|
-
const a = r.
|
|
278
|
-
(a ||
|
|
277
|
+
const a = r._rowId ? t.selectedIds.has(r._rowId) : !1, o = t.selectedRefs.has(r), i = !r._rowId && !n && t.selectedIndexes.has(c);
|
|
278
|
+
(a || o || i) && (s[c.toString()] = !0);
|
|
279
279
|
}), he(s);
|
|
280
280
|
}, g = (e) => {
|
|
281
281
|
if (ue) {
|
|
282
282
|
const t = b, n = typeof e == "function" ? e(t) : e;
|
|
283
283
|
p.current = n;
|
|
284
|
-
const s =
|
|
284
|
+
const s = ye(t);
|
|
285
285
|
U.current = s.selectedIds, ze(n, s), se?.(n);
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
288
|
at((t) => {
|
|
289
289
|
const n = typeof e == "function" ? e(t) : e;
|
|
290
290
|
p.current = n;
|
|
291
|
-
const s =
|
|
291
|
+
const s = ye(t);
|
|
292
292
|
return U.current = s.selectedIds, ze(n, s), se?.(n), n;
|
|
293
293
|
});
|
|
294
|
-
}, be =
|
|
294
|
+
}, be = v(() => f, [f]), Ee = async (e) => {
|
|
295
295
|
try {
|
|
296
296
|
if (L) {
|
|
297
|
-
const t = {
|
|
297
|
+
const t = { _rowId: E(), ...e }, n = await L([t], x);
|
|
298
298
|
if (n) {
|
|
299
299
|
if (n.successful.length > 0) {
|
|
300
300
|
const s = n.successful.map((r) => {
|
|
301
|
-
const
|
|
302
|
-
return
|
|
301
|
+
const c = r.item;
|
|
302
|
+
return c._rowId ? c : { ...c, _rowId: E() };
|
|
303
303
|
});
|
|
304
304
|
g((r) => [...s, ...r]);
|
|
305
305
|
}
|
|
@@ -310,7 +310,7 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
310
310
|
failed: []
|
|
311
311
|
};
|
|
312
312
|
} else {
|
|
313
|
-
const t = {
|
|
313
|
+
const t = { _rowId: E(), ...e };
|
|
314
314
|
return g((n) => [t, ...n]), {
|
|
315
315
|
successful: [{ index: 0, item: t }],
|
|
316
316
|
failed: []
|
|
@@ -322,7 +322,7 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
322
322
|
failed: [{ index: -1, item: e, error: String(t) }]
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
|
-
},
|
|
325
|
+
}, _e = async (e) => {
|
|
326
326
|
if (e.length === 0)
|
|
327
327
|
return {
|
|
328
328
|
successful: [],
|
|
@@ -331,14 +331,14 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
331
331
|
try {
|
|
332
332
|
if (L) {
|
|
333
333
|
const t = e.map((s) => ({
|
|
334
|
-
|
|
334
|
+
_rowId: E(),
|
|
335
335
|
...s
|
|
336
|
-
})), n = await L(t,
|
|
336
|
+
})), n = await L(t, x);
|
|
337
337
|
if (n) {
|
|
338
338
|
if (n.successful.length > 0) {
|
|
339
339
|
const s = n.successful.map((r) => {
|
|
340
|
-
const
|
|
341
|
-
return
|
|
340
|
+
const c = r.item;
|
|
341
|
+
return c._rowId ? c : { ...c, _rowId: E() };
|
|
342
342
|
});
|
|
343
343
|
g((r) => [...s, ...r]);
|
|
344
344
|
}
|
|
@@ -350,7 +350,7 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
350
350
|
};
|
|
351
351
|
} else {
|
|
352
352
|
const t = e.map((n) => ({
|
|
353
|
-
|
|
353
|
+
_rowId: E(),
|
|
354
354
|
...n
|
|
355
355
|
}));
|
|
356
356
|
return g((n) => [...t, ...n]), {
|
|
@@ -368,7 +368,7 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
368
368
|
}))
|
|
369
369
|
};
|
|
370
370
|
}
|
|
371
|
-
},
|
|
371
|
+
}, Ce = async (e, t) => {
|
|
372
372
|
const n = p.current;
|
|
373
373
|
if (e < 0 || e >= n.length)
|
|
374
374
|
return {
|
|
@@ -377,18 +377,18 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
377
377
|
};
|
|
378
378
|
try {
|
|
379
379
|
if (D) {
|
|
380
|
-
const r = await D([{ index: e, item: t }],
|
|
380
|
+
const r = await D([{ index: e, item: t }], x);
|
|
381
381
|
if (r)
|
|
382
|
-
return r.successful.length && g((
|
|
383
|
-
const a = [...
|
|
384
|
-
return r.successful.forEach(({ index:
|
|
382
|
+
return r.successful.length && g((c) => {
|
|
383
|
+
const a = [...c];
|
|
384
|
+
return r.successful.forEach(({ index: o, item: i }) => a[o] = i), a;
|
|
385
385
|
}), r;
|
|
386
386
|
}
|
|
387
387
|
let s;
|
|
388
388
|
return g((r) => {
|
|
389
389
|
s = { ...r[e], ...t };
|
|
390
|
-
const
|
|
391
|
-
return
|
|
390
|
+
const c = [...r];
|
|
391
|
+
return c[e] = s, c;
|
|
392
392
|
}), { successful: [{ index: e, item: s }], failed: [] };
|
|
393
393
|
} catch (s) {
|
|
394
394
|
return {
|
|
@@ -396,44 +396,44 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
396
396
|
failed: [{ index: e, item: t, error: String(s) }]
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
|
-
},
|
|
399
|
+
}, ve = async (e) => {
|
|
400
400
|
if (!e.length) return { successful: [], failed: [] };
|
|
401
|
-
const t = p.current, n = (
|
|
401
|
+
const t = p.current, n = (c) => c >= 0 && c < t.length, s = e.filter(({ index: c }) => !n(c)).map(({ index: c, item: a }) => ({ index: c, item: a, error: "Invalid index" })), r = e.filter(({ index: c }) => n(c));
|
|
402
402
|
try {
|
|
403
403
|
if (D) {
|
|
404
|
-
const
|
|
405
|
-
if (
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
const
|
|
409
|
-
return
|
|
404
|
+
const o = await D(e, x);
|
|
405
|
+
if (o) {
|
|
406
|
+
const i = o.successful.filter(({ index: l }) => n(l));
|
|
407
|
+
i.length && g((l) => {
|
|
408
|
+
const W = [...l];
|
|
409
|
+
return i.forEach(({ index: m, item: A }) => W[m] = A), W;
|
|
410
410
|
});
|
|
411
|
-
const u = new Set(
|
|
411
|
+
const u = new Set(o.failed.map((l) => l.index)), h = [...o.failed];
|
|
412
412
|
return s.forEach((l) => {
|
|
413
413
|
u.has(l.index) || h.push(l);
|
|
414
|
-
}),
|
|
414
|
+
}), o.successful.filter(({ index: l }) => !n(l)).map(({ index: l, item: W }) => ({ index: l, item: W, error: "Invalid index" })).forEach((l) => {
|
|
415
415
|
u.has(l.index) || h.push(l);
|
|
416
|
-
}), { successful:
|
|
416
|
+
}), { successful: i, failed: h };
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
const
|
|
420
|
-
return g((
|
|
421
|
-
const
|
|
419
|
+
const c = [], a = [...s];
|
|
420
|
+
return g((o) => {
|
|
421
|
+
const i = [...o];
|
|
422
422
|
return r.forEach(({ index: u, item: h }) => {
|
|
423
|
-
|
|
424
|
-
}),
|
|
425
|
-
}), { successful:
|
|
426
|
-
} catch (
|
|
423
|
+
i[u] = { ...i[u], ...h }, c.push({ index: u, item: i[u] });
|
|
424
|
+
}), i;
|
|
425
|
+
}), { successful: c, failed: a };
|
|
426
|
+
} catch (c) {
|
|
427
427
|
return {
|
|
428
428
|
successful: [],
|
|
429
|
-
failed: e.map(({ index: a, item:
|
|
429
|
+
failed: e.map(({ index: a, item: o }) => ({
|
|
430
430
|
index: a,
|
|
431
|
-
item:
|
|
432
|
-
error: String(
|
|
431
|
+
item: o,
|
|
432
|
+
error: String(c)
|
|
433
433
|
}))
|
|
434
434
|
};
|
|
435
435
|
}
|
|
436
|
-
},
|
|
436
|
+
}, Re = async (e) => {
|
|
437
437
|
const t = p.current;
|
|
438
438
|
if (e < 0 || e >= t.length)
|
|
439
439
|
return {
|
|
@@ -442,27 +442,27 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
442
442
|
};
|
|
443
443
|
try {
|
|
444
444
|
if (H) {
|
|
445
|
-
const s = b[e], r = await H([{ index: e, item: s }],
|
|
445
|
+
const s = b[e], r = await H([{ index: e, item: s }], x);
|
|
446
446
|
if (r)
|
|
447
|
-
return r.successful.length && g((
|
|
447
|
+
return r.successful.length && g((c) => c.filter((a, o) => o !== e)), r;
|
|
448
448
|
}
|
|
449
449
|
let n;
|
|
450
|
-
return g((s) => (n = s[e], s.filter((r,
|
|
450
|
+
return g((s) => (n = s[e], s.filter((r, c) => c !== e))), { successful: [{ index: e, item: n }], failed: [] };
|
|
451
451
|
} catch (n) {
|
|
452
452
|
return {
|
|
453
453
|
successful: [],
|
|
454
454
|
failed: [{ index: e, error: String(n) }]
|
|
455
455
|
};
|
|
456
456
|
}
|
|
457
|
-
},
|
|
457
|
+
}, Me = async (e) => {
|
|
458
458
|
if (!e.length) return { successful: [], failed: [] };
|
|
459
459
|
const t = p.current, n = Array.from(new Set(e)), { validIndexes: s, invalidFailures: r } = n.reduce(
|
|
460
|
-
(
|
|
460
|
+
(o, i) => (i >= 0 && i < t.length ? o.validIndexes.push(i) : o.invalidFailures.push({ index: i, error: "Invalid index" }), o),
|
|
461
461
|
{ validIndexes: [], invalidFailures: [] }
|
|
462
|
-
),
|
|
462
|
+
), c = n.map((o) => ({ index: o, item: b[o] })), a = new Set(s);
|
|
463
463
|
try {
|
|
464
464
|
if (H) {
|
|
465
|
-
const u = await H(
|
|
465
|
+
const u = await H(c, x);
|
|
466
466
|
if (u) {
|
|
467
467
|
const h = u.successful.filter(({ index: m }) => a.has(m));
|
|
468
468
|
if (h.length) {
|
|
@@ -477,122 +477,122 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
477
477
|
}), { successful: h, failed: l };
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
|
-
const
|
|
480
|
+
const o = new Set(s), i = [];
|
|
481
481
|
return g((u) => {
|
|
482
482
|
const h = [];
|
|
483
483
|
return u.forEach((d, l) => {
|
|
484
|
-
|
|
484
|
+
o.has(l) ? i.push({ index: l, item: d }) : h.push(d);
|
|
485
485
|
}), h;
|
|
486
|
-
}), { successful:
|
|
487
|
-
} catch (
|
|
486
|
+
}), { successful: i, failed: r };
|
|
487
|
+
} catch (o) {
|
|
488
488
|
return {
|
|
489
489
|
successful: [],
|
|
490
|
-
failed: n.map((
|
|
490
|
+
failed: n.map((i) => ({ index: i, error: String(o) }))
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
},
|
|
493
|
+
}, Ne = v((e) => p.current.find((t) => t._rowId === e), []), We = (e) => p.current[e], ke = (e) => {
|
|
494
494
|
g(
|
|
495
|
-
e.map((t) => ({ ...t,
|
|
495
|
+
e.map((t) => ({ ...t, _rowId: t._rowId ?? E() }))
|
|
496
496
|
);
|
|
497
|
-
},
|
|
497
|
+
}, Te = () => {
|
|
498
498
|
g([]);
|
|
499
|
-
}, Ae = (e) => p.current.findIndex((t) => t.
|
|
499
|
+
}, Ae = (e) => p.current.findIndex((t) => t._rowId === e), Be = (e) => p.current.some((t) => t._rowId === e), Fe = () => p.current.length, Oe = () => [...p.current], Le = v(() => ge(p.current), [ge]), De = v(() => Se(p.current), [Se]), x = F(() => ({
|
|
500
500
|
getFields: be,
|
|
501
501
|
addItem: Ee,
|
|
502
|
-
addItems:
|
|
503
|
-
updateItem:
|
|
504
|
-
updateItems:
|
|
505
|
-
deleteItem:
|
|
506
|
-
deleteItems:
|
|
507
|
-
getItem:
|
|
508
|
-
getItemByIndex:
|
|
502
|
+
addItems: _e,
|
|
503
|
+
updateItem: Ce,
|
|
504
|
+
updateItems: ve,
|
|
505
|
+
deleteItem: Re,
|
|
506
|
+
deleteItems: Me,
|
|
507
|
+
getItem: Ne,
|
|
508
|
+
getItemByIndex: We,
|
|
509
509
|
getItems: Oe,
|
|
510
510
|
getItemsCount: Fe,
|
|
511
511
|
itemExists: Be,
|
|
512
512
|
getItemIndex: Ae,
|
|
513
|
-
replaceAllItems:
|
|
514
|
-
clearItems:
|
|
513
|
+
replaceAllItems: ke,
|
|
514
|
+
clearItems: Te,
|
|
515
515
|
deselectAllRows: me,
|
|
516
516
|
getSelectedItems: Le,
|
|
517
517
|
getSelectedRows: De
|
|
518
518
|
}), [
|
|
519
519
|
Ee,
|
|
520
|
-
Ce,
|
|
521
520
|
_e,
|
|
521
|
+
Te,
|
|
522
|
+
Re,
|
|
522
523
|
Me,
|
|
523
|
-
Ne,
|
|
524
524
|
me,
|
|
525
525
|
f,
|
|
526
526
|
be,
|
|
527
|
+
Ne,
|
|
527
528
|
We,
|
|
528
|
-
ke,
|
|
529
529
|
Ae,
|
|
530
530
|
Oe,
|
|
531
531
|
Fe,
|
|
532
532
|
Le,
|
|
533
533
|
De,
|
|
534
534
|
Be,
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
535
|
+
ke,
|
|
536
|
+
Ce,
|
|
537
|
+
ve
|
|
538
538
|
]);
|
|
539
|
-
|
|
540
|
-
const ht =
|
|
541
|
-
t?.target && t.target.closest('[data-checkbox="true"]') || (
|
|
542
|
-
}, [
|
|
543
|
-
const n = f.find((r) => r.internalName === e.id)?.typeAsString === "Note" ?
|
|
539
|
+
wt.useImperativeHandle(et, () => x, [x]);
|
|
540
|
+
const ht = v((e, t) => {
|
|
541
|
+
t?.target && t.target.closest('[data-checkbox="true"]') || (y && pe(e.index), Z && Z(e.original, e.index));
|
|
542
|
+
}, [y, Z, pe]), He = F(() => I.map((e) => {
|
|
543
|
+
const n = f.find((r) => r.internalName === e.id)?.typeAsString === "Note" ? w * 2 : w, s = S[e.id] || (typeof e.size == "number" ? e.size : n);
|
|
544
544
|
return e.id === "select" ? `${O}px` : `${s}px`;
|
|
545
|
-
}).join(" "), [
|
|
546
|
-
|
|
545
|
+
}).join(" "), [I, S, f]);
|
|
546
|
+
k(() => {
|
|
547
547
|
if (!P) return;
|
|
548
548
|
const e = new ResizeObserver((t) => {
|
|
549
549
|
for (const n of t)
|
|
550
550
|
fe(n.contentRect.width);
|
|
551
551
|
});
|
|
552
552
|
return e.observe(P), fe(P.clientWidth), () => e.disconnect();
|
|
553
|
-
}, [P]),
|
|
554
|
-
if (!
|
|
553
|
+
}, [P]), k(() => {
|
|
554
|
+
if (!R || _ <= 0 || M.current) return;
|
|
555
555
|
let e = 0, t = 0;
|
|
556
556
|
const n = [];
|
|
557
|
-
if (
|
|
558
|
-
const h = f.find((m) => m.internalName ===
|
|
559
|
-
!(
|
|
557
|
+
if (I.forEach((i) => {
|
|
558
|
+
const h = f.find((m) => m.internalName === i.id)?.typeAsString === "Note" ? w * 2 : w, d = S[i.id] || (typeof i.size == "number" ? i.size : h);
|
|
559
|
+
!(i.id === "select") ? (t += d, n.push(i)) : e += d;
|
|
560
560
|
}), n.length === 0)
|
|
561
561
|
return;
|
|
562
562
|
const s = e + t;
|
|
563
|
-
if (Math.abs(s -
|
|
564
|
-
const r =
|
|
565
|
-
let
|
|
566
|
-
n.forEach((
|
|
567
|
-
const h = S[
|
|
563
|
+
if (Math.abs(s - _) < 1) return;
|
|
564
|
+
const r = _ - e, c = r / t, a = { ...S };
|
|
565
|
+
let o = 0;
|
|
566
|
+
n.forEach((i, u) => {
|
|
567
|
+
const h = S[i.id] || (typeof i.size == "number" ? i.size : w), d = i.minSize || T;
|
|
568
568
|
let l;
|
|
569
|
-
u === n.length - 1 ? l = r -
|
|
570
|
-
}),
|
|
571
|
-
|
|
569
|
+
u === n.length - 1 ? l = r - o : l = Math.round(h * c), l = Math.max(d, l), a[i.id] = l, o += l;
|
|
570
|
+
}), M.current = !0, j(a), requestAnimationFrame(() => {
|
|
571
|
+
M.current = !1;
|
|
572
572
|
});
|
|
573
|
-
}, [
|
|
574
|
-
if (
|
|
573
|
+
}, [R, _, I, f]), k(() => {
|
|
574
|
+
if (R || _ <= 0)
|
|
575
575
|
return;
|
|
576
|
-
const e =
|
|
576
|
+
const e = _ - Y;
|
|
577
577
|
if (Math.abs(e) < 1)
|
|
578
578
|
return;
|
|
579
|
-
const t =
|
|
579
|
+
const t = I.filter((d) => d.id && d.id !== "select");
|
|
580
580
|
if (t.length === 0) return;
|
|
581
|
-
const n = t[t.length - 1], s = n.id,
|
|
582
|
-
Math.abs(h - u) < 1 || (
|
|
581
|
+
const n = t[t.length - 1], s = n.id, c = f.find((d) => d.internalName === s)?.typeAsString === "Note" ? w * 2 : w, o = (S[s] || (typeof n.size == "number" ? n.size : c)) + e, i = n.minSize || T, u = Math.max(i, o), h = S[s];
|
|
582
|
+
Math.abs(h - u) < 1 || (M.current = !0, j((d) => ({
|
|
583
583
|
...d,
|
|
584
584
|
[s]: u
|
|
585
|
-
})),
|
|
586
|
-
}, [
|
|
587
|
-
const je =
|
|
585
|
+
})), M.current = !1);
|
|
586
|
+
}, [R, _, Y, I, f]);
|
|
587
|
+
const je = Rt(tt), Pe = Mt(nt), $ = Nt(st), mt = je ? [je, ...ce] : ce, ee = [];
|
|
588
588
|
Pe && ee.push(Pe), $ && ee.push($);
|
|
589
|
-
const pt = [...ee, ...
|
|
589
|
+
const pt = [...ee, ...ct], gt = $ ? [$, ...oe] : oe;
|
|
590
590
|
return /* @__PURE__ */ Ye(
|
|
591
|
-
|
|
591
|
+
_t,
|
|
592
592
|
{
|
|
593
593
|
size: "small",
|
|
594
594
|
appearance: Ge,
|
|
595
|
-
className:
|
|
595
|
+
className: ot,
|
|
596
596
|
style: {
|
|
597
597
|
backgroundColor: K.colorNeutralBackground1,
|
|
598
598
|
maxWidth: "100%",
|
|
@@ -602,18 +602,18 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
602
602
|
...Xe
|
|
603
603
|
},
|
|
604
604
|
children: [
|
|
605
|
-
V && /* @__PURE__ */
|
|
606
|
-
|
|
605
|
+
V && /* @__PURE__ */ C(
|
|
606
|
+
Wt,
|
|
607
607
|
{
|
|
608
|
-
tableMethods:
|
|
608
|
+
tableMethods: x,
|
|
609
609
|
alwaysButtons: mt,
|
|
610
610
|
noSelectionButtons: rt,
|
|
611
611
|
singleSelectionButtons: pt,
|
|
612
612
|
multiSelectionButtons: gt,
|
|
613
|
-
selectedRows:
|
|
613
|
+
selectedRows: x.getSelectedRows()
|
|
614
614
|
}
|
|
615
615
|
),
|
|
616
|
-
b.length > 0 ? /* @__PURE__ */
|
|
616
|
+
b.length > 0 ? /* @__PURE__ */ C(
|
|
617
617
|
"div",
|
|
618
618
|
{
|
|
619
619
|
ref: dt,
|
|
@@ -632,32 +632,32 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
632
632
|
{
|
|
633
633
|
className: "table-container",
|
|
634
634
|
style: {
|
|
635
|
-
minWidth:
|
|
636
|
-
width:
|
|
635
|
+
minWidth: R ? "100%" : Y,
|
|
636
|
+
width: R ? "100%" : Math.max(Y, 300)
|
|
637
637
|
},
|
|
638
638
|
children: [
|
|
639
|
-
/* @__PURE__ */
|
|
640
|
-
|
|
639
|
+
/* @__PURE__ */ C(
|
|
640
|
+
kt,
|
|
641
641
|
{
|
|
642
|
-
table:
|
|
642
|
+
table: xe,
|
|
643
643
|
gridTemplateColumns: He,
|
|
644
644
|
columnSizing: S,
|
|
645
|
-
stickyColumnsInfo:
|
|
645
|
+
stickyColumnsInfo: Ie,
|
|
646
646
|
resizableColumns: Q
|
|
647
647
|
}
|
|
648
648
|
),
|
|
649
|
-
/* @__PURE__ */
|
|
650
|
-
|
|
649
|
+
/* @__PURE__ */ C(
|
|
650
|
+
Tt,
|
|
651
651
|
{
|
|
652
|
-
table:
|
|
652
|
+
table: xe,
|
|
653
653
|
fields: f,
|
|
654
|
-
tableContainerRef:
|
|
654
|
+
tableContainerRef: we,
|
|
655
655
|
useVirtualization: Ue,
|
|
656
|
-
enableSelection:
|
|
656
|
+
enableSelection: y,
|
|
657
657
|
itemSize: Ve,
|
|
658
658
|
gridTemplateColumns: He,
|
|
659
659
|
columnSizing: S,
|
|
660
|
-
stickyColumnsInfo:
|
|
660
|
+
stickyColumnsInfo: Ie,
|
|
661
661
|
onRowClick: ht
|
|
662
662
|
}
|
|
663
663
|
)
|
|
@@ -665,15 +665,15 @@ const G = {}, Bt = /* @__PURE__ */ new Set(), qe = [], X = [], x = 120, _ = 80,
|
|
|
665
665
|
}
|
|
666
666
|
)
|
|
667
667
|
}
|
|
668
|
-
) : /* @__PURE__ */
|
|
668
|
+
) : /* @__PURE__ */ C(At, { height: 250 })
|
|
669
669
|
]
|
|
670
670
|
}
|
|
671
671
|
);
|
|
672
672
|
};
|
|
673
673
|
export {
|
|
674
|
-
|
|
674
|
+
w as COLS_DEF_WIDTH,
|
|
675
675
|
J as COLS_MAX_WIDTH,
|
|
676
|
-
|
|
676
|
+
T as COLS_MIN_WIDTH,
|
|
677
677
|
Ut as EFWTable,
|
|
678
678
|
Qt as SELECTOR_CELL_HEIGHT,
|
|
679
679
|
O as SELECTOR_CELL_WIDTH
|
|
@@ -4,7 +4,7 @@ import { DefaultDrawerButtonProps, EFWTableCommandBarButton } from './components
|
|
|
4
4
|
import { EFWFormFieldProps, EFWFormFieldType, EFWFormFieldValue } from '../../forms/EFWForm';
|
|
5
5
|
|
|
6
6
|
export interface EFWTableItem {
|
|
7
|
-
readonly
|
|
7
|
+
readonly _rowId?: string;
|
|
8
8
|
[key: string]: EFWFormFieldValue | undefined;
|
|
9
9
|
}
|
|
10
10
|
export interface EFWTableRow<T = EFWTableItem> {
|
|
@@ -28,8 +28,8 @@ export interface OperationResult<T> {
|
|
|
28
28
|
*/
|
|
29
29
|
export interface EFWTableMethods {
|
|
30
30
|
getFields: () => EFWFormFieldProps[];
|
|
31
|
-
addItem: (item: Omit<EFWTableItem, '
|
|
32
|
-
addItems: (items: Omit<EFWTableItem, '
|
|
31
|
+
addItem: (item: Omit<EFWTableItem, '_rowId'>) => Promise<OperationResult<EFWTableItem>>;
|
|
32
|
+
addItems: (items: Omit<EFWTableItem, '_rowId'>[]) => Promise<OperationResult<EFWTableItem>>;
|
|
33
33
|
updateItem: (index: number, item: Partial<EFWTableItem>) => Promise<OperationResult<EFWTableItem>>;
|
|
34
34
|
updateItems: (items: {
|
|
35
35
|
index: number;
|
package/dist/react-components/tables/EFWTable/hooks/useTableController/useTableController copy.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
const
|
|
3
|
-
const c =
|
|
1
|
+
import { useRef as D, useState as m, useCallback as u, useEffect as I } from "react";
|
|
2
|
+
const H = (d) => {
|
|
3
|
+
const c = D(null), [l, a] = m([]), [i, g] = m(d || []), h = u(() => c.current?.getFields?.() || i, [i]), p = u((t) => {
|
|
4
4
|
g(t);
|
|
5
5
|
}, []);
|
|
6
|
-
|
|
6
|
+
I(() => {
|
|
7
7
|
(() => {
|
|
8
8
|
const e = c.current?.getItems?.();
|
|
9
9
|
e && a(e);
|
|
@@ -135,21 +135,21 @@ const J = (I) => {
|
|
|
135
135
|
}))
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
}, []), v = u((t) => c.current?.getItem?.(t) || l.find((e) => e.
|
|
138
|
+
}, []), v = u((t) => c.current?.getItem?.(t) || l.find((e) => e._rowId === t), [l]), T = u((t) => c.current?.getItemByIndex?.(t) || l[t], [l]), C = u((t) => {
|
|
139
139
|
c.current?.replaceAllItems?.(t), a(t);
|
|
140
140
|
}, []), x = u(() => {
|
|
141
141
|
c.current?.clearItems?.(), a([]);
|
|
142
|
-
}, []), A = u((t) => c.current?.getItemIndex?.(t) ?? l.findIndex((e) => e.
|
|
142
|
+
}, []), A = u((t) => c.current?.getItemIndex?.(t) ?? l.findIndex((e) => e._rowId === t), [l]), F = u((t) => c.current?.itemExists?.(t) ?? l.some((e) => e._rowId === t), [l]), _ = u(() => c.current?.getItemsCount?.() ?? l.length, [l.length]), B = u(() => c.current?.getItems?.() ?? l, [l]), k = u(() => {
|
|
143
143
|
c.current?.deselectAllRows?.();
|
|
144
|
-
}, []),
|
|
145
|
-
return
|
|
144
|
+
}, []), j = u(() => c.current?.getSelectedItems?.() ?? { items: [], indexes: [] }, []), q = u(() => c.current?.getSelectedRows?.() ?? [], []), z = u(() => c.current !== null, []);
|
|
145
|
+
return I(() => () => {
|
|
146
146
|
c.current = null;
|
|
147
147
|
}, []), {
|
|
148
148
|
tableRef: c,
|
|
149
149
|
// Configuración
|
|
150
150
|
getFields: h,
|
|
151
151
|
setFieldsConfig: p,
|
|
152
|
-
isTableReady:
|
|
152
|
+
isTableReady: z,
|
|
153
153
|
// Operaciones CRUD
|
|
154
154
|
addItem: y,
|
|
155
155
|
addItems: b,
|
|
@@ -160,19 +160,19 @@ const J = (I) => {
|
|
|
160
160
|
// Consultas
|
|
161
161
|
getItem: v,
|
|
162
162
|
getItemByIndex: T,
|
|
163
|
-
getItems:
|
|
164
|
-
getItemsCount:
|
|
163
|
+
getItems: B,
|
|
164
|
+
getItemsCount: _,
|
|
165
165
|
getItemIndex: A,
|
|
166
166
|
itemExists: F,
|
|
167
167
|
// Manipulación masiva
|
|
168
168
|
replaceAllItems: C,
|
|
169
169
|
clearItems: x,
|
|
170
170
|
// Selección
|
|
171
|
-
deselectAllRows:
|
|
172
|
-
getSelectedItems:
|
|
173
|
-
getSelectedRows:
|
|
171
|
+
deselectAllRows: k,
|
|
172
|
+
getSelectedItems: j,
|
|
173
|
+
getSelectedRows: q
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
176
|
export {
|
|
177
|
-
|
|
177
|
+
H as useTableController
|
|
178
178
|
};
|
package/dist/react-components/tables/EFWTable/hooks/useTableController/useTableController.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
const
|
|
3
|
-
const c =
|
|
1
|
+
import { useRef as D, useState as m, useCallback as u, useEffect as I } from "react";
|
|
2
|
+
const H = (d) => {
|
|
3
|
+
const c = D(null), [l, a] = m([]), [i, g] = m(d || []), h = u(() => c.current?.getFields?.() || i, [i]), p = u((t) => {
|
|
4
4
|
g(t);
|
|
5
5
|
}, []);
|
|
6
|
-
|
|
6
|
+
I(() => {
|
|
7
7
|
(() => {
|
|
8
8
|
const e = c.current?.getItems?.();
|
|
9
9
|
e && a(e);
|
|
@@ -135,21 +135,21 @@ const J = (I) => {
|
|
|
135
135
|
}))
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
}, []), v = u((t) => c.current?.getItem?.(t) || l.find((e) => e.
|
|
138
|
+
}, []), v = u((t) => c.current?.getItem?.(t) || l.find((e) => e._rowId === t), [l]), T = u((t) => c.current?.getItemByIndex?.(t) || l[t], [l]), C = u((t) => {
|
|
139
139
|
c.current?.replaceAllItems?.(t), a(t);
|
|
140
140
|
}, []), x = u(() => {
|
|
141
141
|
c.current?.clearItems?.(), a([]);
|
|
142
|
-
}, []), A = u((t) => c.current?.getItemIndex?.(t) ?? l.findIndex((e) => e.
|
|
142
|
+
}, []), A = u((t) => c.current?.getItemIndex?.(t) ?? l.findIndex((e) => e._rowId === t), [l]), F = u((t) => c.current?.itemExists?.(t) ?? l.some((e) => e._rowId === t), [l]), _ = u(() => c.current?.getItemsCount?.() ?? l.length, [l.length]), B = u(() => c.current?.getItems?.() ?? l, [l]), k = u(() => {
|
|
143
143
|
c.current?.deselectAllRows?.();
|
|
144
|
-
}, []),
|
|
145
|
-
return
|
|
144
|
+
}, []), j = u(() => c.current?.getSelectedItems?.() ?? { items: [], indexes: [] }, []), q = u(() => c.current?.getSelectedRows?.() ?? [], []), z = u(() => c.current !== null, []);
|
|
145
|
+
return I(() => () => {
|
|
146
146
|
c.current = null;
|
|
147
147
|
}, []), {
|
|
148
148
|
tableRef: c,
|
|
149
149
|
// Configuración
|
|
150
150
|
getFields: h,
|
|
151
151
|
setFieldsConfig: p,
|
|
152
|
-
isTableReady:
|
|
152
|
+
isTableReady: z,
|
|
153
153
|
// Operaciones CRUD
|
|
154
154
|
addItem: y,
|
|
155
155
|
addItems: b,
|
|
@@ -160,19 +160,19 @@ const J = (I) => {
|
|
|
160
160
|
// Consultas
|
|
161
161
|
getItem: v,
|
|
162
162
|
getItemByIndex: T,
|
|
163
|
-
getItems:
|
|
164
|
-
getItemsCount:
|
|
163
|
+
getItems: B,
|
|
164
|
+
getItemsCount: _,
|
|
165
165
|
getItemIndex: A,
|
|
166
166
|
itemExists: F,
|
|
167
167
|
// Manipulación masiva
|
|
168
168
|
replaceAllItems: C,
|
|
169
169
|
clearItems: x,
|
|
170
170
|
// Selección
|
|
171
|
-
deselectAllRows:
|
|
172
|
-
getSelectedItems:
|
|
173
|
-
getSelectedRows:
|
|
171
|
+
deselectAllRows: k,
|
|
172
|
+
getSelectedItems: j,
|
|
173
|
+
getSelectedRows: q
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
176
|
export {
|
|
177
|
-
|
|
177
|
+
H as useTableController
|
|
178
178
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CACHE_CONFIG as f } from "./constants.js";
|
|
2
|
-
import { getRenderContextVersion as
|
|
3
|
-
import { hashString as p, extractDateIdentifiers as
|
|
2
|
+
import { getRenderContextVersion as w } from "./context.js";
|
|
3
|
+
import { hashString as p, extractDateIdentifiers as y, extractAttachmentIdentifiers as g, extractOptionIdentifiers as S } from "./hashing.js";
|
|
4
4
|
function C(t, e) {
|
|
5
5
|
if (t == null)
|
|
6
6
|
return "null";
|
|
@@ -20,17 +20,17 @@ function C(t, e) {
|
|
|
20
20
|
n = S(t);
|
|
21
21
|
break;
|
|
22
22
|
case "Attachments":
|
|
23
|
-
n =
|
|
23
|
+
n = g(t);
|
|
24
24
|
break;
|
|
25
25
|
case "Date":
|
|
26
|
-
n =
|
|
26
|
+
n = y(t);
|
|
27
27
|
break;
|
|
28
28
|
default:
|
|
29
|
-
n = t.map((
|
|
29
|
+
n = t.map((i, l) => `${l}-${String(i)}`);
|
|
30
30
|
}
|
|
31
31
|
n.sort();
|
|
32
|
-
const c = n.slice(0, 5).join(","),
|
|
33
|
-
return `array-${r}-${c}-${
|
|
32
|
+
const c = n.slice(0, 5).join(","), o = p(n.join("|"));
|
|
33
|
+
return `array-${r}-${c}-${o}`;
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
36
|
return `object-${p(JSON.stringify(t))}`;
|
|
@@ -38,14 +38,14 @@ function C(t, e) {
|
|
|
38
38
|
return "complex-object";
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function I(t, e, r, n, c) {
|
|
42
42
|
return [
|
|
43
43
|
t.internalName || t.id,
|
|
44
44
|
t.typeAsString,
|
|
45
45
|
C(e, t.typeAsString),
|
|
46
|
-
r.
|
|
46
|
+
r._rowId || `row-${n}`,
|
|
47
47
|
c ? p(JSON.stringify(Object.keys(c))) : "no-renderers",
|
|
48
|
-
|
|
48
|
+
w().toString()
|
|
49
49
|
].join("|");
|
|
50
50
|
}
|
|
51
51
|
const s = /* @__PURE__ */ new Map();
|
|
@@ -68,16 +68,16 @@ function d() {
|
|
|
68
68
|
function b() {
|
|
69
69
|
const t = Math.floor(f.MAX_SIZE * 0.8);
|
|
70
70
|
if (s.size <= t) return;
|
|
71
|
-
const e = Array.from(s.entries()), r = Date.now(), n = e.map(([
|
|
72
|
-
const l = r -
|
|
73
|
-
return { key:
|
|
71
|
+
const e = Array.from(s.entries()), r = Date.now(), n = e.map(([o, i]) => {
|
|
72
|
+
const l = r - i.timestamp, u = i.hits / Math.max(1, l / 1e3);
|
|
73
|
+
return { key: o, score: u, entry: i };
|
|
74
74
|
});
|
|
75
|
-
n.sort((
|
|
75
|
+
n.sort((o, i) => o.score - i.score);
|
|
76
76
|
const c = n.slice(0, s.size - t);
|
|
77
|
-
for (const { key:
|
|
78
|
-
s.delete(
|
|
77
|
+
for (const { key: o } of c)
|
|
78
|
+
s.delete(o);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function k(t) {
|
|
81
81
|
const e = s.get(t);
|
|
82
82
|
if (!e) return;
|
|
83
83
|
if (Date.now() - e.timestamp >= f.TTL_MS) {
|
|
@@ -119,8 +119,8 @@ function $(t) {
|
|
|
119
119
|
}
|
|
120
120
|
export {
|
|
121
121
|
T as clearRenderCache,
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
I as createCacheKey,
|
|
123
|
+
k as getCachedResult,
|
|
124
124
|
E as getRenderCacheStats,
|
|
125
125
|
$ as prewarmCache,
|
|
126
126
|
M as setCachedResult
|