lecom-ui 5.2.15 → 5.2.16
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/components/DataTable/DataTable.js +62 -37
- package/dist/index.d.ts +12 -0
- package/package.json +1 -1
|
@@ -21,6 +21,13 @@ function DataTable({
|
|
|
21
21
|
onIsSelected
|
|
22
22
|
}) {
|
|
23
23
|
const [sorting, setSorting] = React.useState([]);
|
|
24
|
+
const dataTableContainerStyle = React.useMemo(
|
|
25
|
+
() => ({
|
|
26
|
+
width: vwDiff ? `calc(100vw - ${vwDiff}px)` : "100%",
|
|
27
|
+
height: vhDiff ? `calc(100vh - ${vhDiff}px)` : "100%"
|
|
28
|
+
}),
|
|
29
|
+
[vwDiff, vhDiff]
|
|
30
|
+
);
|
|
24
31
|
const table = useReactTable({
|
|
25
32
|
data,
|
|
26
33
|
columns: buildColumns({ columns, size }),
|
|
@@ -31,19 +38,27 @@ function DataTable({
|
|
|
31
38
|
sorting
|
|
32
39
|
}
|
|
33
40
|
});
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
height: vhDiff ? `calc(100vh - ${vhDiff}px)` : "100%"
|
|
37
|
-
});
|
|
41
|
+
const scrollAreaRef = React.useRef(null);
|
|
42
|
+
const fixedElementsCache = React.useRef({ elements: [], separators: [], lastUpdate: 0 });
|
|
38
43
|
const hasPagination = () => {
|
|
39
44
|
if (!pagination) {
|
|
40
45
|
return null;
|
|
41
46
|
}
|
|
42
47
|
return /* @__PURE__ */ React.createElement(Pagination, { ...pagination });
|
|
43
48
|
};
|
|
44
|
-
React.
|
|
45
|
-
if (
|
|
46
|
-
|
|
49
|
+
const setupFixedElements = React.useCallback(() => {
|
|
50
|
+
if (isLoading) return;
|
|
51
|
+
const tableElement = document.querySelector(
|
|
52
|
+
"table#data-table"
|
|
53
|
+
);
|
|
54
|
+
if (!tableElement) return;
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
const cacheValidTime = 1e3;
|
|
57
|
+
if (now - fixedElementsCache.current.lastUpdate < cacheValidTime) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const listRows = tableElement.querySelectorAll("tr");
|
|
61
|
+
requestAnimationFrame(() => {
|
|
47
62
|
listRows.forEach((listRow, listRowIndex) => {
|
|
48
63
|
const rowsElem = listRow.querySelectorAll("[data-fixed]");
|
|
49
64
|
rowsElem.forEach((rowElem, rowElemIndex) => {
|
|
@@ -56,44 +71,54 @@ function DataTable({
|
|
|
56
71
|
const currentElemIsTh = currentElem.tagName === "TH";
|
|
57
72
|
const boxShadowWidth = currentElemIsTh ? "-1.5px" : "-0.5px";
|
|
58
73
|
const boxShadow = `#c9c9c9 0px ${lastRow ? "0px" : boxShadowWidth} 0px inset`;
|
|
59
|
-
currentElem.style
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
Object.assign(currentElem.style, {
|
|
75
|
+
position: "sticky",
|
|
76
|
+
left: `${beforeElemWidth + beforeElemLeft}px`,
|
|
77
|
+
boxShadow
|
|
78
|
+
});
|
|
62
79
|
if (lastColumnFixed) {
|
|
63
80
|
currentElem.setAttribute("data-separator-fixed", "true");
|
|
64
81
|
}
|
|
65
82
|
});
|
|
66
83
|
});
|
|
67
|
-
|
|
84
|
+
fixedElementsCache.current = {
|
|
85
|
+
elements: Array.from(tableElement.querySelectorAll("[data-fixed]")),
|
|
86
|
+
separators: Array.from(
|
|
87
|
+
tableElement.querySelectorAll("[data-separator-fixed]")
|
|
88
|
+
),
|
|
89
|
+
lastUpdate: now
|
|
90
|
+
};
|
|
91
|
+
});
|
|
68
92
|
}, [isLoading]);
|
|
69
|
-
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
setupFixedElements();
|
|
95
|
+
}, [setupFixedElements, data.length]);
|
|
96
|
+
const onScroll = React.useCallback((e) => {
|
|
70
97
|
const target = e.target;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
const { separators } = fixedElementsCache.current;
|
|
99
|
+
if (separators.length === 0) return;
|
|
100
|
+
requestAnimationFrame(() => {
|
|
101
|
+
const countSeparator = separators.length - 1;
|
|
102
|
+
const isScrolledRight = target.scrollLeft > 0;
|
|
103
|
+
separators.forEach((separator, i) => {
|
|
104
|
+
const isLastSeparator = countSeparator === i;
|
|
105
|
+
const isFirstSeparator = i === 0;
|
|
106
|
+
if (isScrolledRight) {
|
|
107
|
+
separator.style.boxShadow = isLastSeparator ? "#c9c9c9 -0.5px 0px 0px inset" : `#c9c9c9 -0.5px ${isFirstSeparator ? "-1.5px" : "-0.5px"} 0px inset`;
|
|
78
108
|
} else {
|
|
79
|
-
separator.style.boxShadow =
|
|
109
|
+
separator.style.boxShadow = isFirstSeparator ? "#c9c9c9 0px -1.5px 0px inset" : `#c9c9c9 0px ${isLastSeparator ? "0px" : "-0.5px"} 0px inset`;
|
|
80
110
|
}
|
|
81
111
|
});
|
|
82
|
-
}
|
|
83
|
-
elemSeparator.forEach((elem, i) => {
|
|
84
|
-
const separator = elem;
|
|
85
|
-
if (i === 0) {
|
|
86
|
-
separator.style.boxShadow = "#c9c9c9 0px -1.5px 0px inset";
|
|
87
|
-
} else {
|
|
88
|
-
separator.style.boxShadow = `#c9c9c9 0px ${countSeparator === i ? "0px" : "-0.5px"} 0px inset`;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
React.useEffect(() => {
|
|
94
|
-
document.querySelector("[data-radix-scroll-area-viewport]")?.addEventListener("scroll", onScroll);
|
|
95
|
-
return () => document.querySelector("[data-radix-scroll-area-viewport]")?.removeEventListener("scroll", onScroll);
|
|
112
|
+
});
|
|
96
113
|
}, []);
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
const scrollElement = scrollAreaRef.current?.querySelector(
|
|
116
|
+
"[data-radix-scroll-area-viewport]"
|
|
117
|
+
);
|
|
118
|
+
if (!scrollElement) return;
|
|
119
|
+
scrollElement.addEventListener("scroll", onScroll, { passive: true });
|
|
120
|
+
return () => scrollElement.removeEventListener("scroll", onScroll);
|
|
121
|
+
}, [onScroll]);
|
|
97
122
|
const renderTable = () => /* @__PURE__ */ React.createElement(
|
|
98
123
|
Table,
|
|
99
124
|
{
|
|
@@ -113,13 +138,13 @@ function DataTable({
|
|
|
113
138
|
"bg-white rounded-[8px] p-2 transition-all duration-500",
|
|
114
139
|
className
|
|
115
140
|
),
|
|
116
|
-
style: noScroll ? void 0 : { width:
|
|
141
|
+
style: noScroll ? void 0 : { width: dataTableContainerStyle.width }
|
|
117
142
|
},
|
|
118
|
-
noScroll ? renderTable() : /* @__PURE__ */ React.createElement(ScrollArea, { type: "always", className: "p-2" }, /* @__PURE__ */ React.createElement(
|
|
143
|
+
noScroll ? renderTable() : /* @__PURE__ */ React.createElement(ScrollArea, { ref: scrollAreaRef, type: "always", className: "p-2" }, /* @__PURE__ */ React.createElement(
|
|
119
144
|
"div",
|
|
120
145
|
{
|
|
121
146
|
className: "transition-all duration-500",
|
|
122
|
-
style: { maxHeight:
|
|
147
|
+
style: { maxHeight: dataTableContainerStyle.height }
|
|
123
148
|
},
|
|
124
149
|
renderTable()
|
|
125
150
|
), /* @__PURE__ */ React.createElement(ScrollBar, { orientation: "horizontal" }))
|
package/dist/index.d.ts
CHANGED
|
@@ -524,6 +524,18 @@ interface TableProps<TData, TValue> {
|
|
|
524
524
|
onIsSelected?: (row: Row$1<TData>) => boolean;
|
|
525
525
|
}
|
|
526
526
|
|
|
527
|
+
/**
|
|
528
|
+
* DataTable Component - Versão Otimizada para Performance
|
|
529
|
+
*
|
|
530
|
+
* Otimizações implementadas:
|
|
531
|
+
* 1. Memoização de estilos para evitar recálculos em resize
|
|
532
|
+
* 2. Cache de elementos DOM para reduzir queries repetitivas
|
|
533
|
+
* 3. requestAnimationFrame para operações DOM não bloqueantes
|
|
534
|
+
* 4. Event listeners com passive: true para melhor scroll performance
|
|
535
|
+
* 5. Batch de operações DOM para reduzir reflows/repaints
|
|
536
|
+
* 6. Sistema de cache com timestamp para evitar recálculos desnecessários
|
|
537
|
+
*/
|
|
538
|
+
|
|
527
539
|
declare function DataTable<TData, TValue>({ isLoading, columns, data, noResults, pagination, vwDiff, vhDiff, className, noScroll, size, skeleton, onIsSelected, }: DataTableProps<TData, TValue>): React$1.JSX.Element;
|
|
528
540
|
declare namespace DataTable {
|
|
529
541
|
var displayName: string;
|