lecom-ui 5.2.18 → 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.
@@ -39,81 +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
- requestAnimationFrame(() => {
62
- listRows.forEach((listRow, listRowIndex) => {
63
- const rowsElem = listRow.querySelectorAll("[data-fixed]");
64
- rowsElem.forEach((rowElem, rowElemIndex) => {
65
- const beforeElem = rowsElem[rowElemIndex - 1];
66
- const currentElem = rowElem;
67
- const beforeElemWidth = beforeElem?.getBoundingClientRect()?.width ?? 0;
68
- const beforeElemLeft = beforeElem?.style?.left ? Number(beforeElem.style.left.replace(/px/g, "")) : 0;
69
- const lastColumnFixed = rowsElem.length - 1 === rowElemIndex;
70
- const lastRow = listRows.length - 1 === listRowIndex;
71
- const currentElemIsTh = currentElem.tagName === "TH";
72
- const boxShadowWidth = currentElemIsTh ? "-1.5px" : "-0.5px";
73
- const boxShadow = `#c9c9c9 0px ${lastRow ? "0px" : boxShadowWidth} 0px inset`;
74
- Object.assign(currentElem.style, {
75
- position: "sticky",
76
- left: `${beforeElemWidth + beforeElemLeft}px`,
77
- boxShadow
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 debouncedSetup = debounce(setupFixedElements, 120);
101
- const resizeObserver = new window.ResizeObserver(() => {
86
+ const handleResize = () => {
102
87
  setupFixedElements();
103
- debouncedSetup();
104
- });
88
+ };
89
+ const resizeObserver = new window.ResizeObserver(handleResize);
105
90
  resizeObserver.observe(container);
106
91
  return () => {
107
92
  resizeObserver.disconnect();
108
93
  };
109
- }, [setupFixedElements, noScroll]);
110
- function debounce(fn, delay) {
111
- let timer;
112
- return (...args) => {
113
- clearTimeout(timer);
114
- timer = setTimeout(() => fn(...args), delay);
115
- };
116
- }
94
+ }, [setupFixedElements, noScroll, vwDiff, vhDiff]);
117
95
  const onScroll = React.useCallback((e) => {
118
96
  const target = e.target;
119
97
  const { separators } = fixedElementsCache.current;
@@ -140,6 +118,12 @@ function DataTable({
140
118
  scrollElement.addEventListener("scroll", onScroll, { passive: true });
141
119
  return () => scrollElement.removeEventListener("scroll", onScroll);
142
120
  }, [onScroll]);
121
+ const hasPagination = () => {
122
+ if (!pagination) {
123
+ return null;
124
+ }
125
+ return /* @__PURE__ */ React.createElement(Pagination, { ...pagination });
126
+ };
143
127
  const renderTable = () => /* @__PURE__ */ React.createElement(
144
128
  Table,
145
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lecom-ui",
3
- "version": "5.2.18",
3
+ "version": "5.2.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",