ehscan-react-table 0.0.52 → 0.0.54

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.
@@ -32,30 +32,20 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
32
32
  }
33
33
  }, [searchTermArraySetter]);
34
34
  useEffect(() => {
35
+ const resizeTimeout = {
36
+ current: null
37
+ };
35
38
  const resizeFn = () => {
36
- if (colRefs === null || colRefs === void 0 ? void 0 : colRefs.current) {
37
- Object.keys(colRefs.current).forEach(key => {
38
- var _a;
39
- const el = colRefs.current[key];
40
- if (!el)
41
- return;
42
- const { width } = el.getBoundingClientRect();
43
- const min = ((_a = measureCols.find(c => c.col === key)) === null || _a === void 0 ? void 0 : _a.min) || 50;
44
- if (width < min) {
45
- changeColumns({ col: key, small: true });
46
- return;
47
- }
48
- changeColumns({ col: key, small: false });
49
- });
50
- }
51
- if (scrollRef.current) {
52
- const info = scrollRef.current.getBoundingClientRect();
53
- console.log(info);
54
- }
55
- if (headerRef.current) {
56
- const { bottom } = headerRef.current.getBoundingClientRect();
57
- setWrapperBottom(bottom - 20);
39
+ if (resizeTimeout.current) {
40
+ clearTimeout(resizeTimeout.current);
58
41
  }
42
+ resizeTimeout.current = setTimeout(() => {
43
+ if (scrollRef.current) {
44
+ const info = scrollRef.current.getBoundingClientRect();
45
+ console.log(info);
46
+ setWrapperBottom(info.height);
47
+ }
48
+ }, 150); // debounce delay
59
49
  };
60
50
  const handleScroll = () => {
61
51
  const el = scrollRef.current;
@@ -65,18 +55,63 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
65
55
  if (reachBottom && !nearBottom)
66
56
  setNearBottom(true);
67
57
  };
68
- resizeFn(); //init
58
+ resizeFn(); // init
69
59
  const scrollEl = scrollRef.current;
70
60
  if (scrollEl)
71
61
  scrollEl.addEventListener("scroll", handleScroll);
72
62
  window.addEventListener("resize", resizeFn);
73
63
  return () => {
74
64
  window.removeEventListener("resize", resizeFn);
75
- if (scrollEl) {
65
+ if (scrollEl)
76
66
  scrollEl.removeEventListener("scroll", handleScroll);
77
- }
67
+ if (resizeTimeout.current)
68
+ clearTimeout(resizeTimeout.current);
78
69
  };
79
70
  }, []);
71
+ // useEffect(() => {
72
+ // const resizeFn = () => {
73
+ // if (colRefs?.current) {
74
+ // Object.keys(colRefs.current).forEach(key => {
75
+ // const el = colRefs.current[key];
76
+ // if (!el) return;
77
+ // const { width } = el.getBoundingClientRect();
78
+ // const min = measureCols.find(c => c.col === key)?.min || 50;
79
+ // if (width < min) {
80
+ // changeColumns({ col: key, small: true });
81
+ // return;
82
+ // }
83
+ // changeColumns({ col: key, small: false });
84
+ // });
85
+ // }
86
+ // setTimeout(() => {
87
+ // if (scrollRef.current){
88
+ // const info = scrollRef.current.getBoundingClientRect();
89
+ // console.log(info)
90
+ // setWrapperBottom(info.height)
91
+ // }
92
+ // },100)
93
+ // };
94
+ // const handleScroll = () => {
95
+ // const el = scrollRef.current;
96
+ // if (!el) return;
97
+ // const reachBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 100;
98
+ // if (reachBottom && !nearBottom) setNearBottom(true)
99
+ // };
100
+ // resizeFn(); //init
101
+ // const scrollEl = scrollRef.current;
102
+ // if (scrollEl) scrollEl.addEventListener("scroll", handleScroll);
103
+ // window.addEventListener("resize", resizeFn);
104
+ // return () => {
105
+ // window.removeEventListener("resize", resizeFn);
106
+ // if (scrollEl) {
107
+ // scrollEl.removeEventListener("scroll", handleScroll);
108
+ // }
109
+ // };
110
+ // }, []);
111
+ // if (headerRef.current) {
112
+ // const { bottom } = headerRef.current.getBoundingClientRect();
113
+ // setWrapperBottom(bottom - 20);
114
+ // }
80
115
  const checkHead = (entry) => {
81
116
  if (entry === undefined)
82
117
  return;
@@ -176,5 +211,5 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
176
211
  return (_jsx("td", { children: _jsx("div", { className: styles.exttablediv, children: _jsx(CellComponent, { row: row, col: col.tag, small: col.small }) }) }, ci));
177
212
  }), _jsx(EndCol, {})] }, `row-${rowIndex}`))) }, 'ext-tbody'));
178
213
  };
179
- return (_jsx(_Fragment, { children: _jsxs("div", { className: `${styles.tablewrapper} ${styles['_tbl']}`, style: { maxHeight: `calc(100vh - ${wrapperBottom}px)` }, ref: scrollRef, children: [_jsxs("table", { className: styles.exttable, children: [_jsx("thead", { ref: headerRef, children: _jsx("tr", { className: styles.trstickyhead, children: _jsx(HeadCols, {}) }) }), rows && rows.length > 0 && _jsx(TableBody, {})] }), rows && rows.length === 0 && fallback()] }) }));
214
+ return (_jsx(_Fragment, { children: _jsxs("div", { className: `${styles.tablewrapper} ${styles['_tbl']}`, style: { maxHeight: `${wrapperBottom}px)` }, ref: scrollRef, children: [_jsxs("table", { className: styles.exttable, children: [_jsx("thead", { ref: headerRef, children: _jsx("tr", { className: styles.trstickyhead, children: _jsx(HeadCols, {}) }) }), rows && rows.length > 0 && _jsx(TableBody, {})] }), rows && rows.length === 0 && fallback()] }) }));
180
215
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-table",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",