@pdg/react-table 1.0.125 → 1.0.127

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/README.md CHANGED
@@ -8,7 +8,7 @@ https://parkdigy.github.io/react-table/
8
8
 
9
9
  ## 설치
10
10
  ```shell
11
- npm install -D @pdg/react-table @dnd-kit/core @dnd-kit/sortable @emotion/react @emotion/styled @mui/icons-material @mui/material @mui/x-date-pickers @pdg/react-component @pdg/react-hook @pdg/react-form @tinymce/tinymce-react @types/uuid classnames dayjs copy-to-clipboard react-number-format react-resize-detector simplebar-react uuid
11
+ npm install -D @pdg/react-table @dnd-kit/core @dnd-kit/sortable @emotion/react @emotion/styled @mui/icons-material @mui/material @mui/x-date-pickers @pdg/react-component @pdg/react-hook @pdg/react-form @tinymce/tinymce-react @types/uuid classnames dayjs copy-to-clipboard react-number-format react-resize-detector simplebar-react uuid react-intersection-observer
12
12
  ```
13
13
 
14
14
  ### simplebar-react css 추가
@@ -66,7 +66,7 @@ export interface TableColumn<T = TableItem> {
66
66
  onGetSx?(item: T, index: number): TableCommonSxProps['sx'];
67
67
  onHide?(item: T, index: number): boolean;
68
68
  onGetTooltip?(item: T, index: number): ReactNode;
69
- onRender?(item: T, index: number): ReactNode;
69
+ onRender?(item: T, index: number, inView: boolean): ReactNode;
70
70
  onClick?(item: T, index: number): void;
71
71
  onInitChecked?(item: T): boolean;
72
72
  onCheckDisabled?(item: T): boolean;
@@ -94,6 +94,7 @@ export interface TableProps<T = TableItem> extends TableCommonSxProps {
94
94
  showOddColor?: boolean;
95
95
  showEvenColor?: boolean;
96
96
  cellPadding?: string | number;
97
+ inViewRender?: boolean;
97
98
  footer?: boolean;
98
99
  noData?: ReactNode;
99
100
  pagination?: {
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { TableBodyCellProps as Props } from './TableBodyCell.types';
3
- declare const TableBodyCell: React.FC<Props>;
3
+ declare const TableBodyCell: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLTableCellElement>>;
4
4
  export default TableBodyCell;
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { TableCommonCellProps } from './TableCommonCell.types';
3
- declare const TableCommonCell: React.FC<TableCommonCellProps>;
3
+ declare const TableCommonCell: React.ForwardRefExoticComponent<TableCommonCellProps & React.RefAttributes<HTMLTableCellElement>>;
4
4
  export default TableCommonCell;
@@ -4,6 +4,7 @@ import { TableHeadCellCommands } from '../TableHeadCell';
4
4
  export interface TableContextValue {
5
5
  menuOpen: boolean;
6
6
  openMenuId?: string;
7
+ inViewRender?: boolean;
7
8
  setMenuOpen(menuOpen: boolean, openMenuId?: string): void;
8
9
  setItemColumnChecked(item: TableItem, column: TableColumn, checked: boolean): void;
9
10
  setItemColumnCheckDisabled(item: TableItem, column: TableColumn, checkDisabled: boolean): void;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React,{createContext,useContext,useMemo,useCallback,useState,useEffect,useRef,useLayoutEffect,useId}from'react';import classNames from'classnames';import {styled,TableRow,lighten,TableCell,Box,Tooltip,Checkbox,Stack,Pagination,useTheme,TableHead,TableBody,Icon,TableFooter,Paper,Table as Table$1,Grid,Popper,Grow,ClickAwayListener,IconButton}from'@mui/material';import {useResizeDetector}from'react-resize-detector';import {useSortable,sortableKeyboardCoordinates,arrayMove,SortableContext,verticalListSortingStrategy}from'@dnd-kit/sortable';import dayjs from'dayjs';import {personalNoAutoDash,companyNoAutoDash,telNoAutoDash,numberFormat,notEmpty,equal,empty}from'@pdg/util';import {useAutoUpdateLayoutState}from'@pdg/react-hook';import {useSensors,useSensor,MouseSensor,TouchSensor,KeyboardSensor,DndContext,closestCenter}from'@dnd-kit/core';import SimpleBar from'simplebar-react';import'simplebar-react/dist/simplebar.min.css';import {v4}from'uuid';import {Search,SearchGroup,FormHidden}from'@pdg/react-form';import {PdgButton,PdgIcon,PdgCopyToClipboard}from'@pdg/react-component';function styleInject(css, ref) {
1
+ import React,{createContext,useContext,useMemo,useCallback,useState,useEffect,useRef,useLayoutEffect,useId}from'react';import classNames from'classnames';import {styled,TableRow,lighten,TableCell,Box,Tooltip,Checkbox,Stack,Pagination,useTheme,TableHead,TableBody,Icon,TableFooter,Paper,Table as Table$1,Grid,Popper,Grow,ClickAwayListener,IconButton}from'@mui/material';import {useResizeDetector}from'react-resize-detector';import {useSortable,sortableKeyboardCoordinates,arrayMove,SortableContext,verticalListSortingStrategy}from'@dnd-kit/sortable';import dayjs from'dayjs';import {personalNoAutoDash,companyNoAutoDash,telNoAutoDash,numberFormat,notEmpty,equal,empty}from'@pdg/util';import {useInView}from'react-intersection-observer';import {useAutoUpdateLayoutState}from'@pdg/react-hook';import {useSensors,useSensor,MouseSensor,TouchSensor,KeyboardSensor,DndContext,closestCenter}from'@dnd-kit/core';import SimpleBar from'simplebar-react';import'simplebar-react/dist/simplebar.min.css';import {v4}from'uuid';import {Search,SearchGroup,FormHidden}from'@pdg/react-form';import {PdgButton,PdgIcon,PdgCopyToClipboard}from'@pdg/react-component';function styleInject(css, ref) {
2
2
  if ( ref === void 0 ) ref = {};
3
3
  var insertAt = ref.insertAt;
4
4
 
@@ -170,6 +170,7 @@ function typographyColorToSxColor(color) {
170
170
  }var TableContextDefaultValue = {
171
171
  menuOpen: false,
172
172
  openMenuId: undefined,
173
+ inViewRender: false,
173
174
  setMenuOpen: function () { },
174
175
  setItemColumnChecked: function () { },
175
176
  setItemColumnCheckDisabled: function () { },
@@ -183,7 +184,7 @@ function typographyColorToSxColor(color) {
183
184
  }
184
185
  return value;
185
186
  }var StyledTableCell = styled(TableCell)(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"], ["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"])));
186
- var TableCommonCell = function (_a) {
187
+ var TableCommonCell = React.forwardRef(function (_a, ref) {
187
188
  /********************************************************************************************************************
188
189
  * Use
189
190
  * ******************************************************************************************************************/
@@ -337,20 +338,21 @@ var TableCommonCell = function (_a) {
337
338
  /********************************************************************************************************************
338
339
  * Render
339
340
  * ******************************************************************************************************************/
340
- return (React.createElement(StyledTableCell, { align: align, className: classNames(className, 'TableCommonCell', ellipsis && 'ellipsis', column.type ? "column-type-".concat(column.type) : false), style: style, sx: sx, onClick: type === 'body' ? handleClick : undefined }, children));
341
- };
341
+ return (React.createElement(StyledTableCell, { ref: ref, align: align, className: classNames(className, 'TableCommonCell', ellipsis && 'ellipsis', column.type ? "column-type-".concat(column.type) : false), style: style, sx: sx, onClick: type === 'body' ? handleClick : undefined }, children));
342
+ });
342
343
  var templateObject_1$3;var StyledButtonsBox = styled(Box)(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"], ["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"])));
343
- var TableBodyCell = function (_a) {
344
+ var TableBodyCell = React.forwardRef(function (_a, ref) {
344
345
  /********************************************************************************************************************
345
346
  * Use
346
347
  * ******************************************************************************************************************/
347
348
  var className = _a.className, style = _a.style, sx = _a.sx, item = _a.item, index = _a.index, column = _a.column, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, onClick = _a.onClick, onCheckChange = _a.onCheckChange;
348
- var _b = useTableState(), menuOpen = _b.menuOpen, setItemColumnChecked = _b.setItemColumnChecked, setItemColumnCheckDisabled = _b.setItemColumnCheckDisabled, setItemColumnCommands = _b.setItemColumnCommands;
349
+ var _b = useTableState(), menuOpen = _b.menuOpen, inViewRender = _b.inViewRender, setItemColumnChecked = _b.setItemColumnChecked, setItemColumnCheckDisabled = _b.setItemColumnCheckDisabled, setItemColumnCommands = _b.setItemColumnCommands;
350
+ var _c = useInView({ threshold: 0 }), inViewRef = _c.ref, inView = _c.inView;
349
351
  /********************************************************************************************************************
350
352
  * State
351
353
  * ******************************************************************************************************************/
352
- var _c = useState(false), checked = _c[0], setChecked = _c[1];
353
- var _d = useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
354
+ var _d = useState(false), checked = _d[0], setChecked = _d[1];
355
+ var _e = useState(false), checkDisabled = _e[0], setCheckDisabled = _e[1];
354
356
  /********************************************************************************************************************
355
357
  * Effect
356
358
  * ******************************************************************************************************************/
@@ -404,7 +406,7 @@ var TableBodyCell = function (_a) {
404
406
  var data;
405
407
  if (column.type !== 'check') {
406
408
  if (column.onRender) {
407
- data = column.onRender(item, index);
409
+ data = column.onRender(item, index, inView);
408
410
  }
409
411
  else if (column.name) {
410
412
  data = item[column.name];
@@ -513,7 +515,7 @@ var TableBodyCell = function (_a) {
513
515
  }
514
516
  }
515
517
  return data;
516
- }, [column, item, index, menuOpen, checked, checkDisabled, buttonsBoxJustifyContent, onCheckChange]);
518
+ }, [column, item, index, inView, menuOpen, checked, checkDisabled, buttonsBoxJustifyContent, onCheckChange]);
517
519
  /********************************************************************************************************************
518
520
  * Event Handler
519
521
  * ******************************************************************************************************************/
@@ -529,8 +531,20 @@ var TableBodyCell = function (_a) {
529
531
  /********************************************************************************************************************
530
532
  * Render
531
533
  * ******************************************************************************************************************/
532
- return (React.createElement(TableCommonCell, { type: 'body', className: classNames('TableBodyCell', className), style: style, sx: sx, column: column, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, item: item, index: index, onClick: column.onClick || onClick ? handleClick : undefined }, !isHidden && data));
533
- };
534
+ return (React.createElement(TableCommonCell, { ref: function (cellRef) {
535
+ if (inViewRender) {
536
+ inViewRef(cellRef);
537
+ }
538
+ if (ref) {
539
+ if (typeof ref === 'function') {
540
+ ref(cellRef);
541
+ }
542
+ else {
543
+ ref.current = cellRef;
544
+ }
545
+ }
546
+ }, type: 'body', className: classNames('TableBodyCell', className), style: style, sx: sx, column: column, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, item: item, index: index, onClick: column.onClick || onClick ? handleClick : undefined }, !isHidden && data));
547
+ });
534
548
  var templateObject_1$2;var StyledBodyRow = styled(TableRow)(function (_a) {
535
549
  var theme = _a.theme;
536
550
  return ({
@@ -556,8 +570,9 @@ var TableBodyRow = function (_a) {
556
570
  /********************************************************************************************************************
557
571
  * Render
558
572
  * ******************************************************************************************************************/
559
- return (React.createElement(StyledBodyRow, __assign({ className: classNames('TableBodyRow', className), style: sortable
560
- ? __assign(__assign({}, style), { transform: CSS.Transform.toString(transform), transition: transition }) : style }, props, sortableProps), columns.map(function (column, columnIdx) { return (React.createElement(TableBodyCell, { className: onGetColumnClassName ? onGetColumnClassName(column, item, index) : undefined, sx: onGetColumnSx ? onGetColumnSx(column, item, index) : undefined, style: onGetColumnStyle ? onGetColumnStyle(column, item, index) : undefined, key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick, onCheckChange: onCheckChange })); })));
573
+ return (React.createElement(React.Fragment, null,
574
+ React.createElement(StyledBodyRow, __assign({ className: classNames('TableBodyRow', className), style: sortable
575
+ ? __assign(__assign({}, style), { transform: CSS.Transform.toString(transform), transition: transition }) : style }, props, sortableProps), columns.map(function (column, columnIdx) { return (React.createElement(TableBodyCell, { className: onGetColumnClassName ? onGetColumnClassName(column, item, index) : undefined, sx: onGetColumnSx ? onGetColumnSx(column, item, index) : undefined, style: onGetColumnStyle ? onGetColumnStyle(column, item, index) : undefined, key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick, onCheckChange: onCheckChange })); }))));
561
576
  };var TableFooterCell = function (_a) {
562
577
  /********************************************************************************************************************
563
578
  * Memo
@@ -784,7 +799,7 @@ var Table = React.forwardRef(function (_a, ref) {
784
799
  /********************************************************************************************************************
785
800
  * Ref
786
801
  * ******************************************************************************************************************/
787
- var className = _a.className, initStyle = _a.style, sx = _a.sx, caption = _a.caption, topHeadRows = _a.topHeadRows, initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, _b = _a.pagingAlign, pagingAlign = _b === void 0 ? 'center' : _b, _c = _a.defaultAlign, defaultAlign = _c === void 0 ? 'left' : _c, defaultEllipsis = _a.defaultEllipsis, initStickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, _d = _a.cellPadding, cellPadding = _d === void 0 ? 13 : _d, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable = _a.sortable, onClick = _a.onClick, onGetBodyRowClassName = _a.onGetBodyRowClassName, onGetBodyRowStyle = _a.onGetBodyRowStyle, onGetBodyRowSx = _a.onGetBodyRowSx, onGetBodyColumnClassName = _a.onGetBodyColumnClassName, onGetBodyColumnStyle = _a.onGetBodyColumnStyle, onGetBodyColumnSx = _a.onGetBodyColumnSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange, onCheckChange = _a.onCheckChange;
802
+ var className = _a.className, initStyle = _a.style, sx = _a.sx, caption = _a.caption, topHeadRows = _a.topHeadRows, initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, _b = _a.pagingAlign, pagingAlign = _b === void 0 ? 'center' : _b, _c = _a.defaultAlign, defaultAlign = _c === void 0 ? 'left' : _c, defaultEllipsis = _a.defaultEllipsis, initStickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, _d = _a.cellPadding, cellPadding = _d === void 0 ? 13 : _d, inViewRender = _a.inViewRender, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable = _a.sortable, onClick = _a.onClick, onGetBodyRowClassName = _a.onGetBodyRowClassName, onGetBodyRowStyle = _a.onGetBodyRowStyle, onGetBodyRowSx = _a.onGetBodyRowSx, onGetBodyColumnClassName = _a.onGetBodyColumnClassName, onGetBodyColumnStyle = _a.onGetBodyColumnStyle, onGetBodyColumnSx = _a.onGetBodyColumnSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange, onCheckChange = _a.onCheckChange;
788
803
  var localHeaderDataRef = useRef({});
789
804
  var localBodyDataRef = useRef({});
790
805
  var updateHeadCheckTimer = useRef(undefined);
@@ -1312,6 +1327,7 @@ var Table = React.forwardRef(function (_a, ref) {
1312
1327
  return finalColumns ? (React.createElement(TableContextProvider, { value: {
1313
1328
  menuOpen: menuOpen,
1314
1329
  openMenuId: openMenuId,
1330
+ inViewRender: inViewRender,
1315
1331
  setMenuOpen: TableContextSetMenuOpen,
1316
1332
  setItemColumnChecked: TableContextSetItemColumnChecked,
1317
1333
  setItemColumnCheckDisabled: TableContextSetItemColumnCheckDisabled,
@@ -1359,7 +1375,6 @@ var deHash = function () {
1359
1375
  /********************************************************************************************************************
1360
1376
  * Ref
1361
1377
  * ******************************************************************************************************************/
1362
- var _b, _c;
1363
1378
  var className = _a.className, initStyle = _a.style, sx = _a.sx, color = _a.color, hash = _a.hash, stickyHeader = _a.stickyHeader, fullHeight = _a.fullHeight, search = _a.search, table = _a.table, betweenSearchTableComponent = _a.betweenSearchTableComponent, onGetData = _a.onGetData, onRequestHashChange = _a.onRequestHashChange;
1364
1379
  var initPathRef = useRef(window.location.pathname);
1365
1380
  var searchRef = useRef(undefined);
@@ -1368,13 +1383,13 @@ var deHash = function () {
1368
1383
  /********************************************************************************************************************
1369
1384
  * State
1370
1385
  * ******************************************************************************************************************/
1371
- var _d = useState(true), isFirstSearchSubmit = _d[0], setIsFirstSearchSubmit = _d[1];
1372
- var _e = useState(), tableData = _e[0], setTableData = _e[1];
1386
+ var _b = useState(true), isFirstSearchSubmit = _b[0], setIsFirstSearchSubmit = _b[1];
1387
+ var _c = useState(), tableData = _c[0], setTableData = _c[1];
1373
1388
  /********************************************************************************************************************
1374
1389
  * searchInfo
1375
1390
  * ******************************************************************************************************************/
1376
1391
  var searchInfoFirstUseEffect = useRef(true);
1377
- var _f = useState(function () { return getSearchInfo(search); }), searchInfo = _f[0], setSearchInfo = _f[1];
1392
+ var _d = useState(function () { return getSearchInfo(search); }), searchInfo = _d[0], setSearchInfo = _d[1];
1378
1393
  useEffect(function () {
1379
1394
  if (searchInfoFirstUseEffect.current) {
1380
1395
  searchInfoFirstUseEffect.current = false;
@@ -1387,7 +1402,7 @@ var deHash = function () {
1387
1402
  * tableInfo
1388
1403
  * ******************************************************************************************************************/
1389
1404
  var tableInfoFirstUseEffect = useRef(true);
1390
- var _g = useState(function () { return getTableInfo(table); }), tableInfo = _g[0], setTableInfo = _g[1];
1405
+ var _e = useState(function () { return getTableInfo(table); }), tableInfo = _e[0], setTableInfo = _e[1];
1391
1406
  useEffect(function () {
1392
1407
  if (tableInfoFirstUseEffect.current) {
1393
1408
  tableInfoFirstUseEffect.current = false;
@@ -1721,25 +1736,25 @@ var deHash = function () {
1721
1736
  /********************************************************************************************************************
1722
1737
  * Render
1723
1738
  * ******************************************************************************************************************/
1724
- return (React.createElement(Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: fullHeight ? __assign(__assign({}, initStyle), { flex: 1, display: 'flex' }) : initStyle, sx: sx },
1725
- React.createElement(Grid, { sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
1726
- React.createElement(Search, __assign({ color: color }, searchInfo.props, { ref: function (commands) {
1727
- if (searchInfo.ref) {
1728
- if (typeof searchInfo.ref === 'function') {
1729
- searchInfo.ref(commands);
1730
- }
1731
- else {
1732
- searchInfo.ref.current = commands;
1733
- }
1739
+ var searchView = useMemo(function () { return (React.createElement(Grid, { sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
1740
+ React.createElement(Search, __assign({ color: color }, searchInfo.props, { ref: function (commands) {
1741
+ if (searchInfo.ref) {
1742
+ if (typeof searchInfo.ref === 'function') {
1743
+ searchInfo.ref(commands);
1734
1744
  }
1735
- searchRef.current = commands || undefined;
1736
- }, autoSubmit: true, onSubmit: handleSearchSubmit }),
1737
- React.createElement(SearchGroup, { hidden: true },
1738
- React.createElement(FormHidden, { name: 'page', value: 1 })),
1739
- searchInfo.searchGroups)),
1740
- betweenSearchTableComponent && React.createElement(Grid, null, betweenSearchTableComponent),
1741
- React.createElement(Grid, { style: fullHeight ? { flex: 1, display: 'flex', flexDirection: 'column' } : undefined },
1742
- React.createElement(Table, __assign({}, tableInfo.props, { stickyHeader: stickyHeader || ((_b = tableInfo.props) === null || _b === void 0 ? void 0 : _b.stickyHeader), fullHeight: fullHeight || ((_c = tableInfo.props) === null || _c === void 0 ? void 0 : _c.fullHeight), ref: function (commands) {
1745
+ else {
1746
+ searchInfo.ref.current = commands;
1747
+ }
1748
+ }
1749
+ searchRef.current = commands || undefined;
1750
+ }, autoSubmit: true, onSubmit: handleSearchSubmit }),
1751
+ React.createElement(SearchGroup, { hidden: true },
1752
+ React.createElement(FormHidden, { name: 'page', value: 1 })),
1753
+ searchInfo.searchGroups))); }, [color, handleSearchSubmit, searchInfo]);
1754
+ var tableView = useMemo(function () {
1755
+ var _a, _b;
1756
+ return (React.createElement(Grid, { style: fullHeight ? { flex: 1, display: 'flex', flexDirection: 'column' } : undefined },
1757
+ React.createElement(Table, __assign({}, tableInfo.props, { stickyHeader: stickyHeader || ((_a = tableInfo.props) === null || _a === void 0 ? void 0 : _a.stickyHeader), fullHeight: fullHeight || ((_b = tableInfo.props) === null || _b === void 0 ? void 0 : _b.fullHeight), ref: function (commands) {
1743
1758
  if (tableInfo.ref) {
1744
1759
  if (typeof tableInfo.ref === 'function') {
1745
1760
  tableInfo.ref(commands);
@@ -1749,7 +1764,12 @@ var deHash = function () {
1749
1764
  }
1750
1765
  }
1751
1766
  tableRef.current = commands || undefined;
1752
- }, items: tableData === null || tableData === void 0 ? void 0 : tableData.items, paging: tableData === null || tableData === void 0 ? void 0 : tableData.paging, onPageChange: handlePageChange })))));
1767
+ }, items: tableData === null || tableData === void 0 ? void 0 : tableData.items, paging: tableData === null || tableData === void 0 ? void 0 : tableData.paging, onPageChange: handlePageChange }))));
1768
+ }, [fullHeight, handlePageChange, stickyHeader, tableData === null || tableData === void 0 ? void 0 : tableData.items, tableData === null || tableData === void 0 ? void 0 : tableData.paging, tableInfo]);
1769
+ return (React.createElement(Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: fullHeight ? __assign(__assign({}, initStyle), { flex: 1, display: 'flex' }) : initStyle, sx: sx },
1770
+ searchView,
1771
+ betweenSearchTableComponent && React.createElement(Grid, null, betweenSearchTableComponent),
1772
+ tableView));
1753
1773
  });var TableButton = React.forwardRef(function (_a, ref) {
1754
1774
  var children = _a.children, className = _a.className, initSx = _a.sx, _b = _a.variant, variant = _b === void 0 ? 'outlined' : _b, _c = _a.color, color = _c === void 0 ? 'primary' : _c, startIcon = _a.startIcon, endIcon = _a.endIcon, onClick = _a.onClick, props = __rest(_a, ["children", "className", "sx", "variant", "color", "startIcon", "endIcon", "onClick"]);
1755
1775
  return (React.createElement(PdgButton, __assign({ ref: ref, className: classNames(className, 'TableButton'), variant: variant, type: 'button', size: 'small', sx: __assign({ minWidth: 0, px: empty(startIcon) && empty(endIcon)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var React=require('react'),classNames=require('classnames'),material=require('@mui/material'),reactResizeDetector=require('react-resize-detector'),sortable=require('@dnd-kit/sortable'),dayjs=require('dayjs'),util=require('@pdg/util'),reactHook=require('@pdg/react-hook'),core=require('@dnd-kit/core'),SimpleBar=require('simplebar-react');require('simplebar-react/dist/simplebar.min.css');var uuid=require('uuid'),reactForm=require('@pdg/react-form'),reactComponent=require('@pdg/react-component');function styleInject(css, ref) {
1
+ 'use strict';var React=require('react'),classNames=require('classnames'),material=require('@mui/material'),reactResizeDetector=require('react-resize-detector'),sortable=require('@dnd-kit/sortable'),dayjs=require('dayjs'),util=require('@pdg/util'),reactIntersectionObserver=require('react-intersection-observer'),reactHook=require('@pdg/react-hook'),core=require('@dnd-kit/core'),SimpleBar=require('simplebar-react');require('simplebar-react/dist/simplebar.min.css');var uuid=require('uuid'),reactForm=require('@pdg/react-form'),reactComponent=require('@pdg/react-component');function styleInject(css, ref) {
2
2
  if ( ref === void 0 ) ref = {};
3
3
  var insertAt = ref.insertAt;
4
4
 
@@ -170,6 +170,7 @@ function typographyColorToSxColor(color) {
170
170
  }var TableContextDefaultValue = {
171
171
  menuOpen: false,
172
172
  openMenuId: undefined,
173
+ inViewRender: false,
173
174
  setMenuOpen: function () { },
174
175
  setItemColumnChecked: function () { },
175
176
  setItemColumnCheckDisabled: function () { },
@@ -183,7 +184,7 @@ function typographyColorToSxColor(color) {
183
184
  }
184
185
  return value;
185
186
  }var StyledTableCell = material.styled(material.TableCell)(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"], ["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"])));
186
- var TableCommonCell = function (_a) {
187
+ var TableCommonCell = React.forwardRef(function (_a, ref) {
187
188
  /********************************************************************************************************************
188
189
  * Use
189
190
  * ******************************************************************************************************************/
@@ -337,20 +338,21 @@ var TableCommonCell = function (_a) {
337
338
  /********************************************************************************************************************
338
339
  * Render
339
340
  * ******************************************************************************************************************/
340
- return (React.createElement(StyledTableCell, { align: align, className: classNames(className, 'TableCommonCell', ellipsis && 'ellipsis', column.type ? "column-type-".concat(column.type) : false), style: style, sx: sx, onClick: type === 'body' ? handleClick : undefined }, children));
341
- };
341
+ return (React.createElement(StyledTableCell, { ref: ref, align: align, className: classNames(className, 'TableCommonCell', ellipsis && 'ellipsis', column.type ? "column-type-".concat(column.type) : false), style: style, sx: sx, onClick: type === 'body' ? handleClick : undefined }, children));
342
+ });
342
343
  var templateObject_1$3;var StyledButtonsBox = material.styled(material.Box)(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"], ["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"])));
343
- var TableBodyCell = function (_a) {
344
+ var TableBodyCell = React.forwardRef(function (_a, ref) {
344
345
  /********************************************************************************************************************
345
346
  * Use
346
347
  * ******************************************************************************************************************/
347
348
  var className = _a.className, style = _a.style, sx = _a.sx, item = _a.item, index = _a.index, column = _a.column, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, onClick = _a.onClick, onCheckChange = _a.onCheckChange;
348
- var _b = useTableState(), menuOpen = _b.menuOpen, setItemColumnChecked = _b.setItemColumnChecked, setItemColumnCheckDisabled = _b.setItemColumnCheckDisabled, setItemColumnCommands = _b.setItemColumnCommands;
349
+ var _b = useTableState(), menuOpen = _b.menuOpen, inViewRender = _b.inViewRender, setItemColumnChecked = _b.setItemColumnChecked, setItemColumnCheckDisabled = _b.setItemColumnCheckDisabled, setItemColumnCommands = _b.setItemColumnCommands;
350
+ var _c = reactIntersectionObserver.useInView({ threshold: 0 }), inViewRef = _c.ref, inView = _c.inView;
349
351
  /********************************************************************************************************************
350
352
  * State
351
353
  * ******************************************************************************************************************/
352
- var _c = React.useState(false), checked = _c[0], setChecked = _c[1];
353
- var _d = React.useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
354
+ var _d = React.useState(false), checked = _d[0], setChecked = _d[1];
355
+ var _e = React.useState(false), checkDisabled = _e[0], setCheckDisabled = _e[1];
354
356
  /********************************************************************************************************************
355
357
  * Effect
356
358
  * ******************************************************************************************************************/
@@ -404,7 +406,7 @@ var TableBodyCell = function (_a) {
404
406
  var data;
405
407
  if (column.type !== 'check') {
406
408
  if (column.onRender) {
407
- data = column.onRender(item, index);
409
+ data = column.onRender(item, index, inView);
408
410
  }
409
411
  else if (column.name) {
410
412
  data = item[column.name];
@@ -513,7 +515,7 @@ var TableBodyCell = function (_a) {
513
515
  }
514
516
  }
515
517
  return data;
516
- }, [column, item, index, menuOpen, checked, checkDisabled, buttonsBoxJustifyContent, onCheckChange]);
518
+ }, [column, item, index, inView, menuOpen, checked, checkDisabled, buttonsBoxJustifyContent, onCheckChange]);
517
519
  /********************************************************************************************************************
518
520
  * Event Handler
519
521
  * ******************************************************************************************************************/
@@ -529,8 +531,20 @@ var TableBodyCell = function (_a) {
529
531
  /********************************************************************************************************************
530
532
  * Render
531
533
  * ******************************************************************************************************************/
532
- return (React.createElement(TableCommonCell, { type: 'body', className: classNames('TableBodyCell', className), style: style, sx: sx, column: column, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, item: item, index: index, onClick: column.onClick || onClick ? handleClick : undefined }, !isHidden && data));
533
- };
534
+ return (React.createElement(TableCommonCell, { ref: function (cellRef) {
535
+ if (inViewRender) {
536
+ inViewRef(cellRef);
537
+ }
538
+ if (ref) {
539
+ if (typeof ref === 'function') {
540
+ ref(cellRef);
541
+ }
542
+ else {
543
+ ref.current = cellRef;
544
+ }
545
+ }
546
+ }, type: 'body', className: classNames('TableBodyCell', className), style: style, sx: sx, column: column, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, item: item, index: index, onClick: column.onClick || onClick ? handleClick : undefined }, !isHidden && data));
547
+ });
534
548
  var templateObject_1$2;var StyledBodyRow = material.styled(material.TableRow)(function (_a) {
535
549
  var theme = _a.theme;
536
550
  return ({
@@ -556,8 +570,9 @@ var TableBodyRow = function (_a) {
556
570
  /********************************************************************************************************************
557
571
  * Render
558
572
  * ******************************************************************************************************************/
559
- return (React.createElement(StyledBodyRow, __assign({ className: classNames('TableBodyRow', className), style: sortable$1
560
- ? __assign(__assign({}, style), { transform: CSS.Transform.toString(transform), transition: transition }) : style }, props, sortableProps), columns.map(function (column, columnIdx) { return (React.createElement(TableBodyCell, { className: onGetColumnClassName ? onGetColumnClassName(column, item, index) : undefined, sx: onGetColumnSx ? onGetColumnSx(column, item, index) : undefined, style: onGetColumnStyle ? onGetColumnStyle(column, item, index) : undefined, key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick, onCheckChange: onCheckChange })); })));
573
+ return (React.createElement(React.Fragment, null,
574
+ React.createElement(StyledBodyRow, __assign({ className: classNames('TableBodyRow', className), style: sortable$1
575
+ ? __assign(__assign({}, style), { transform: CSS.Transform.toString(transform), transition: transition }) : style }, props, sortableProps), columns.map(function (column, columnIdx) { return (React.createElement(TableBodyCell, { className: onGetColumnClassName ? onGetColumnClassName(column, item, index) : undefined, sx: onGetColumnSx ? onGetColumnSx(column, item, index) : undefined, style: onGetColumnStyle ? onGetColumnStyle(column, item, index) : undefined, key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick, onCheckChange: onCheckChange })); }))));
561
576
  };var TableFooterCell = function (_a) {
562
577
  /********************************************************************************************************************
563
578
  * Memo
@@ -784,7 +799,7 @@ var Table = React.forwardRef(function (_a, ref) {
784
799
  /********************************************************************************************************************
785
800
  * Ref
786
801
  * ******************************************************************************************************************/
787
- var className = _a.className, initStyle = _a.style, sx = _a.sx, caption = _a.caption, topHeadRows = _a.topHeadRows, initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, _b = _a.pagingAlign, pagingAlign = _b === void 0 ? 'center' : _b, _c = _a.defaultAlign, defaultAlign = _c === void 0 ? 'left' : _c, defaultEllipsis = _a.defaultEllipsis, initStickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, _d = _a.cellPadding, cellPadding = _d === void 0 ? 13 : _d, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable$1 = _a.sortable, onClick = _a.onClick, onGetBodyRowClassName = _a.onGetBodyRowClassName, onGetBodyRowStyle = _a.onGetBodyRowStyle, onGetBodyRowSx = _a.onGetBodyRowSx, onGetBodyColumnClassName = _a.onGetBodyColumnClassName, onGetBodyColumnStyle = _a.onGetBodyColumnStyle, onGetBodyColumnSx = _a.onGetBodyColumnSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange, onCheckChange = _a.onCheckChange;
802
+ var className = _a.className, initStyle = _a.style, sx = _a.sx, caption = _a.caption, topHeadRows = _a.topHeadRows, initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, _b = _a.pagingAlign, pagingAlign = _b === void 0 ? 'center' : _b, _c = _a.defaultAlign, defaultAlign = _c === void 0 ? 'left' : _c, defaultEllipsis = _a.defaultEllipsis, initStickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, _d = _a.cellPadding, cellPadding = _d === void 0 ? 13 : _d, inViewRender = _a.inViewRender, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable$1 = _a.sortable, onClick = _a.onClick, onGetBodyRowClassName = _a.onGetBodyRowClassName, onGetBodyRowStyle = _a.onGetBodyRowStyle, onGetBodyRowSx = _a.onGetBodyRowSx, onGetBodyColumnClassName = _a.onGetBodyColumnClassName, onGetBodyColumnStyle = _a.onGetBodyColumnStyle, onGetBodyColumnSx = _a.onGetBodyColumnSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange, onCheckChange = _a.onCheckChange;
788
803
  var localHeaderDataRef = React.useRef({});
789
804
  var localBodyDataRef = React.useRef({});
790
805
  var updateHeadCheckTimer = React.useRef(undefined);
@@ -1312,6 +1327,7 @@ var Table = React.forwardRef(function (_a, ref) {
1312
1327
  return finalColumns ? (React.createElement(TableContextProvider, { value: {
1313
1328
  menuOpen: menuOpen,
1314
1329
  openMenuId: openMenuId,
1330
+ inViewRender: inViewRender,
1315
1331
  setMenuOpen: TableContextSetMenuOpen,
1316
1332
  setItemColumnChecked: TableContextSetItemColumnChecked,
1317
1333
  setItemColumnCheckDisabled: TableContextSetItemColumnCheckDisabled,
@@ -1359,7 +1375,6 @@ var deHash = function () {
1359
1375
  /********************************************************************************************************************
1360
1376
  * Ref
1361
1377
  * ******************************************************************************************************************/
1362
- var _b, _c;
1363
1378
  var className = _a.className, initStyle = _a.style, sx = _a.sx, color = _a.color, hash = _a.hash, stickyHeader = _a.stickyHeader, fullHeight = _a.fullHeight, search = _a.search, table = _a.table, betweenSearchTableComponent = _a.betweenSearchTableComponent, onGetData = _a.onGetData, onRequestHashChange = _a.onRequestHashChange;
1364
1379
  var initPathRef = React.useRef(window.location.pathname);
1365
1380
  var searchRef = React.useRef(undefined);
@@ -1368,13 +1383,13 @@ var deHash = function () {
1368
1383
  /********************************************************************************************************************
1369
1384
  * State
1370
1385
  * ******************************************************************************************************************/
1371
- var _d = React.useState(true), isFirstSearchSubmit = _d[0], setIsFirstSearchSubmit = _d[1];
1372
- var _e = React.useState(), tableData = _e[0], setTableData = _e[1];
1386
+ var _b = React.useState(true), isFirstSearchSubmit = _b[0], setIsFirstSearchSubmit = _b[1];
1387
+ var _c = React.useState(), tableData = _c[0], setTableData = _c[1];
1373
1388
  /********************************************************************************************************************
1374
1389
  * searchInfo
1375
1390
  * ******************************************************************************************************************/
1376
1391
  var searchInfoFirstUseEffect = React.useRef(true);
1377
- var _f = React.useState(function () { return getSearchInfo(search); }), searchInfo = _f[0], setSearchInfo = _f[1];
1392
+ var _d = React.useState(function () { return getSearchInfo(search); }), searchInfo = _d[0], setSearchInfo = _d[1];
1378
1393
  React.useEffect(function () {
1379
1394
  if (searchInfoFirstUseEffect.current) {
1380
1395
  searchInfoFirstUseEffect.current = false;
@@ -1387,7 +1402,7 @@ var deHash = function () {
1387
1402
  * tableInfo
1388
1403
  * ******************************************************************************************************************/
1389
1404
  var tableInfoFirstUseEffect = React.useRef(true);
1390
- var _g = React.useState(function () { return getTableInfo(table); }), tableInfo = _g[0], setTableInfo = _g[1];
1405
+ var _e = React.useState(function () { return getTableInfo(table); }), tableInfo = _e[0], setTableInfo = _e[1];
1391
1406
  React.useEffect(function () {
1392
1407
  if (tableInfoFirstUseEffect.current) {
1393
1408
  tableInfoFirstUseEffect.current = false;
@@ -1721,25 +1736,25 @@ var deHash = function () {
1721
1736
  /********************************************************************************************************************
1722
1737
  * Render
1723
1738
  * ******************************************************************************************************************/
1724
- return (React.createElement(material.Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: fullHeight ? __assign(__assign({}, initStyle), { flex: 1, display: 'flex' }) : initStyle, sx: sx },
1725
- React.createElement(material.Grid, { sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
1726
- React.createElement(reactForm.Search, __assign({ color: color }, searchInfo.props, { ref: function (commands) {
1727
- if (searchInfo.ref) {
1728
- if (typeof searchInfo.ref === 'function') {
1729
- searchInfo.ref(commands);
1730
- }
1731
- else {
1732
- searchInfo.ref.current = commands;
1733
- }
1739
+ var searchView = React.useMemo(function () { return (React.createElement(material.Grid, { sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
1740
+ React.createElement(reactForm.Search, __assign({ color: color }, searchInfo.props, { ref: function (commands) {
1741
+ if (searchInfo.ref) {
1742
+ if (typeof searchInfo.ref === 'function') {
1743
+ searchInfo.ref(commands);
1734
1744
  }
1735
- searchRef.current = commands || undefined;
1736
- }, autoSubmit: true, onSubmit: handleSearchSubmit }),
1737
- React.createElement(reactForm.SearchGroup, { hidden: true },
1738
- React.createElement(reactForm.FormHidden, { name: 'page', value: 1 })),
1739
- searchInfo.searchGroups)),
1740
- betweenSearchTableComponent && React.createElement(material.Grid, null, betweenSearchTableComponent),
1741
- React.createElement(material.Grid, { style: fullHeight ? { flex: 1, display: 'flex', flexDirection: 'column' } : undefined },
1742
- React.createElement(Table, __assign({}, tableInfo.props, { stickyHeader: stickyHeader || ((_b = tableInfo.props) === null || _b === void 0 ? void 0 : _b.stickyHeader), fullHeight: fullHeight || ((_c = tableInfo.props) === null || _c === void 0 ? void 0 : _c.fullHeight), ref: function (commands) {
1745
+ else {
1746
+ searchInfo.ref.current = commands;
1747
+ }
1748
+ }
1749
+ searchRef.current = commands || undefined;
1750
+ }, autoSubmit: true, onSubmit: handleSearchSubmit }),
1751
+ React.createElement(reactForm.SearchGroup, { hidden: true },
1752
+ React.createElement(reactForm.FormHidden, { name: 'page', value: 1 })),
1753
+ searchInfo.searchGroups))); }, [color, handleSearchSubmit, searchInfo]);
1754
+ var tableView = React.useMemo(function () {
1755
+ var _a, _b;
1756
+ return (React.createElement(material.Grid, { style: fullHeight ? { flex: 1, display: 'flex', flexDirection: 'column' } : undefined },
1757
+ React.createElement(Table, __assign({}, tableInfo.props, { stickyHeader: stickyHeader || ((_a = tableInfo.props) === null || _a === void 0 ? void 0 : _a.stickyHeader), fullHeight: fullHeight || ((_b = tableInfo.props) === null || _b === void 0 ? void 0 : _b.fullHeight), ref: function (commands) {
1743
1758
  if (tableInfo.ref) {
1744
1759
  if (typeof tableInfo.ref === 'function') {
1745
1760
  tableInfo.ref(commands);
@@ -1749,7 +1764,12 @@ var deHash = function () {
1749
1764
  }
1750
1765
  }
1751
1766
  tableRef.current = commands || undefined;
1752
- }, items: tableData === null || tableData === void 0 ? void 0 : tableData.items, paging: tableData === null || tableData === void 0 ? void 0 : tableData.paging, onPageChange: handlePageChange })))));
1767
+ }, items: tableData === null || tableData === void 0 ? void 0 : tableData.items, paging: tableData === null || tableData === void 0 ? void 0 : tableData.paging, onPageChange: handlePageChange }))));
1768
+ }, [fullHeight, handlePageChange, stickyHeader, tableData === null || tableData === void 0 ? void 0 : tableData.items, tableData === null || tableData === void 0 ? void 0 : tableData.paging, tableInfo]);
1769
+ return (React.createElement(material.Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: fullHeight ? __assign(__assign({}, initStyle), { flex: 1, display: 'flex' }) : initStyle, sx: sx },
1770
+ searchView,
1771
+ betweenSearchTableComponent && React.createElement(material.Grid, null, betweenSearchTableComponent),
1772
+ tableView));
1753
1773
  });var TableButton = React.forwardRef(function (_a, ref) {
1754
1774
  var children = _a.children, className = _a.className, initSx = _a.sx, _b = _a.variant, variant = _b === void 0 ? 'outlined' : _b, _c = _a.color, color = _c === void 0 ? 'primary' : _c, startIcon = _a.startIcon, endIcon = _a.endIcon, onClick = _a.onClick, props = __rest(_a, ["children", "className", "sx", "variant", "color", "startIcon", "endIcon", "onClick"]);
1755
1775
  return (React.createElement(reactComponent.PdgButton, __assign({ ref: ref, className: classNames(className, 'TableButton'), variant: variant, type: 'button', size: 'small', sx: __assign({ minWidth: 0, px: util.empty(startIcon) && util.empty(endIcon)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pdg/react-table",
3
3
  "title": "React Table",
4
- "version": "1.0.125",
4
+ "version": "1.0.127",
5
5
  "description": "React Table",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
@@ -58,6 +58,7 @@
58
58
  "dayjs": "^1.0.0",
59
59
  "react": ">=17.0.0",
60
60
  "react-dom": ">=17.0.0",
61
+ "react-intersection-observer": "^9.16.0",
61
62
  "react-number-format": "^5.0.0",
62
63
  "react-resize-detector": "^12.0.0",
63
64
  "simplebar-react": "^3.0.0",