lecom-ui 5.2.17 → 5.2.19
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 +38 -53
- package/dist/index.d.ts +0 -12
- package/package.json +1 -1
|
@@ -39,80 +39,59 @@ function DataTable({
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
const scrollAreaRef = React.useRef(null);
|
|
42
|
+
const offsets = React.useRef([]);
|
|
42
43
|
const fixedElementsCache = React.useRef({ elements: [], separators: [], lastUpdate: 0 });
|
|
43
|
-
const hasPagination = () => {
|
|
44
|
-
if (!pagination) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return /* @__PURE__ */ React.createElement(Pagination, { ...pagination });
|
|
48
|
-
};
|
|
49
44
|
const setupFixedElements = React.useCallback(() => {
|
|
50
45
|
if (isLoading) return;
|
|
51
46
|
const tableElement = document.querySelector(
|
|
52
47
|
"table#data-table"
|
|
53
48
|
);
|
|
54
49
|
if (!tableElement) return;
|
|
55
|
-
const now = Date.now();
|
|
56
|
-
const cacheValidTime = 1e3;
|
|
57
|
-
if (now - fixedElementsCache.current.lastUpdate < cacheValidTime) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
50
|
const listRows = tableElement.querySelectorAll("tr");
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (lastColumnFixed) {
|
|
80
|
-
currentElem.setAttribute("data-separator-fixed", "true");
|
|
81
|
-
}
|
|
82
|
-
});
|
|
51
|
+
if (!listRows[0]) return;
|
|
52
|
+
offsets.current = [];
|
|
53
|
+
let offset = 0;
|
|
54
|
+
const fixedCells = Array.from(
|
|
55
|
+
listRows[0].querySelectorAll("[data-fixed]")
|
|
56
|
+
);
|
|
57
|
+
fixedCells.forEach((cell, idx) => {
|
|
58
|
+
offsets.current[idx] = offset;
|
|
59
|
+
offset += cell.getBoundingClientRect().width;
|
|
60
|
+
});
|
|
61
|
+
listRows.forEach((row) => {
|
|
62
|
+
const cells = Array.from(
|
|
63
|
+
row.querySelectorAll("[data-fixed]")
|
|
64
|
+
);
|
|
65
|
+
cells.forEach((cell, idx) => {
|
|
66
|
+
cell.style.position = "sticky";
|
|
67
|
+
cell.style.left = `${offsets.current[idx]}px`;
|
|
68
|
+
cell.style.boxShadow = idx === offsets.current.length - 1 ? "#c9c9c9 -0.5px 0px 0px inset" : "";
|
|
83
69
|
});
|
|
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
70
|
});
|
|
71
|
+
fixedElementsCache.current = {
|
|
72
|
+
elements: Array.from(
|
|
73
|
+
tableElement.querySelectorAll("[data-fixed]")
|
|
74
|
+
),
|
|
75
|
+
separators: [],
|
|
76
|
+
lastUpdate: Date.now()
|
|
77
|
+
};
|
|
92
78
|
}, [isLoading]);
|
|
93
79
|
React.useEffect(() => {
|
|
94
80
|
setupFixedElements();
|
|
95
|
-
}, [setupFixedElements, data.length]);
|
|
81
|
+
}, [setupFixedElements, data.length, columns, size]);
|
|
96
82
|
React.useEffect(() => {
|
|
97
83
|
if (noScroll) return;
|
|
98
84
|
const container = scrollAreaRef.current;
|
|
99
85
|
if (!container) return;
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
86
|
+
const handleResize = () => {
|
|
87
|
+
setupFixedElements();
|
|
88
|
+
};
|
|
89
|
+
const resizeObserver = new window.ResizeObserver(handleResize);
|
|
104
90
|
resizeObserver.observe(container);
|
|
105
91
|
return () => {
|
|
106
92
|
resizeObserver.disconnect();
|
|
107
93
|
};
|
|
108
|
-
}, [setupFixedElements, noScroll]);
|
|
109
|
-
function debounce(fn, delay) {
|
|
110
|
-
let timer;
|
|
111
|
-
return (...args) => {
|
|
112
|
-
clearTimeout(timer);
|
|
113
|
-
timer = setTimeout(() => fn(...args), delay);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
94
|
+
}, [setupFixedElements, noScroll, vwDiff, vhDiff]);
|
|
116
95
|
const onScroll = React.useCallback((e) => {
|
|
117
96
|
const target = e.target;
|
|
118
97
|
const { separators } = fixedElementsCache.current;
|
|
@@ -139,6 +118,12 @@ function DataTable({
|
|
|
139
118
|
scrollElement.addEventListener("scroll", onScroll, { passive: true });
|
|
140
119
|
return () => scrollElement.removeEventListener("scroll", onScroll);
|
|
141
120
|
}, [onScroll]);
|
|
121
|
+
const hasPagination = () => {
|
|
122
|
+
if (!pagination) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return /* @__PURE__ */ React.createElement(Pagination, { ...pagination });
|
|
126
|
+
};
|
|
142
127
|
const renderTable = () => /* @__PURE__ */ React.createElement(
|
|
143
128
|
Table,
|
|
144
129
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -524,18 +524,6 @@ 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
|
-
|
|
539
527
|
declare function DataTable<TData, TValue>({ isLoading, columns, data, noResults, pagination, vwDiff, vhDiff, className, noScroll, size, skeleton, onIsSelected, }: DataTableProps<TData, TValue>): React$1.JSX.Element;
|
|
540
528
|
declare namespace DataTable {
|
|
541
529
|
var displayName: string;
|