@synerise/ds-table 0.48.1 → 0.48.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.48.3](https://github.com/synerise/synerise-design/compare/@synerise/ds-table@0.48.2...@synerise/ds-table@0.48.3) (2024-04-03)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-table
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.48.2](https://github.com/synerise/synerise-design/compare/@synerise/ds-table@0.48.1...@synerise/ds-table@0.48.2) (2024-04-02)
15
+
16
+ **Note:** Version bump only for package @synerise/ds-table
17
+
18
+
19
+
20
+
21
+
6
22
  ## [0.48.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-table@0.48.0...@synerise/ds-table@0.48.1) (2024-03-29)
7
23
 
8
24
  **Note:** Version bump only for package @synerise/ds-table
@@ -10,7 +10,8 @@ export var BackToTopButton = function BackToTopButton(props) {
10
10
  color: "grey",
11
11
  icon: /*#__PURE__*/React.createElement(Icon, {
12
12
  component: /*#__PURE__*/React.createElement(ArrowUpCircleM, null)
13
- })
13
+ }),
14
+ className: "virtual-table-back-to-top-button"
14
15
  }, props));
15
16
  };
16
17
  export default BackToTopButton;
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { LoaderItemProps } from './InfiniteLoaderItem.types';
3
- declare const InfiniteLoaderItem: ({ infiniteScroll }: LoaderItemProps) => React.ReactElement;
3
+ declare const InfiniteLoaderItem: ({ infiniteScroll, position }: LoaderItemProps) => React.ReactElement;
4
4
  export default InfiniteLoaderItem;
@@ -51,19 +51,24 @@ var ErrorItem = function ErrorItem(_ref) {
51
51
  };
52
52
 
53
53
  var InfiniteLoaderItem = function InfiniteLoaderItem(_ref2) {
54
- var infiniteScroll = _ref2.infiniteScroll;
54
+ var infiniteScroll = _ref2.infiniteScroll,
55
+ position = _ref2.position;
55
56
  var hasMore = infiniteScroll.hasMore,
56
57
  isLoading = infiniteScroll.isLoading,
57
58
  hasError = infiniteScroll.hasError,
58
59
  onRetryButtonClick = infiniteScroll.onRetryButtonClick,
59
60
  render = infiniteScroll.render;
60
61
 
62
+ var handleRetryClick = function handleRetryClick() {
63
+ onRetryButtonClick && onRetryButtonClick(position);
64
+ };
65
+
61
66
  if (typeof render === 'function') {
62
67
  return render(infiniteScrollPropsToState(infiniteScroll));
63
68
  }
64
69
 
65
70
  return /*#__PURE__*/React.createElement(React.Fragment, null, isLoading && /*#__PURE__*/React.createElement(LoadingItem, null), !isLoading && !hasMore && /*#__PURE__*/React.createElement(NoMoreItem, null), !isLoading && hasError && /*#__PURE__*/React.createElement(ErrorItem, {
66
- onRetryClick: onRetryButtonClick
71
+ onRetryClick: handleRetryClick
67
72
  }));
68
73
  };
69
74
 
@@ -1,4 +1,5 @@
1
- import { ReactElement, MouseEvent as ReactMouseEvent } from 'react';
1
+ import { ReactElement } from 'react';
2
+ export type LoaderItemPosition = 'TOP' | 'BOTTOM';
2
3
  export type InfiniteScrollState = {
3
4
  hasError: boolean;
4
5
  hasMore: boolean;
@@ -7,11 +8,15 @@ export type InfiniteScrollState = {
7
8
  export type InfiniteScrollProps = InfiniteScrollState & {
8
9
  maxScroll?: number;
9
10
  showBackToTopButton?: boolean;
11
+ nextPage?: InfiniteScrollState;
12
+ prevPage?: InfiniteScrollState;
10
13
  render?: (state: InfiniteScrollState) => ReactElement;
11
- onRetryButtonClick?: (event: ReactMouseEvent<HTMLElement, MouseEvent>) => void;
12
- onScrollEndReach: () => void;
14
+ onRetryButtonClick?: (position: LoaderItemPosition | undefined) => void;
15
+ onScrollEndReach?: () => void;
13
16
  onScrollTopReach?: () => void;
17
+ onBackToTop?: () => void;
14
18
  };
15
19
  export type LoaderItemProps = {
16
- infiniteScroll: InfiniteScrollProps;
20
+ infiniteScroll: InfiniteScrollProps & InfiniteScrollState;
21
+ position?: LoaderItemPosition;
17
22
  };
@@ -1,6 +1,17 @@
1
+ /// <reference types="react" />
1
2
  import { InfiniteScrollProps, InfiniteScrollState } from './InfiniteLoaderItem.types';
2
- export declare const infiniteScrollPropsToState: ({ hasError, hasMore, isLoading, }: InfiniteScrollProps) => InfiniteScrollState;
3
+ export declare const infiniteScrollPropsToState: ({ hasError, hasMore, isLoading, }: InfiniteScrollProps & InfiniteScrollState) => InfiniteScrollState;
3
4
  declare const _default: {
4
- infiniteScrollPropsToState: ({ hasError, hasMore, isLoading, }: InfiniteScrollProps) => InfiniteScrollState;
5
+ infiniteScrollPropsToState: ({ hasError, hasMore, isLoading, }: InfiniteScrollState & {
6
+ maxScroll?: number | undefined;
7
+ showBackToTopButton?: boolean | undefined;
8
+ nextPage?: InfiniteScrollState | undefined;
9
+ prevPage?: InfiniteScrollState | undefined;
10
+ render?: ((state: InfiniteScrollState) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) | undefined;
11
+ onRetryButtonClick?: ((position: import("./InfiniteLoaderItem.types").LoaderItemPosition | undefined) => void) | undefined;
12
+ onScrollEndReach?: (() => void) | undefined;
13
+ onScrollTopReach?: (() => void) | undefined;
14
+ onBackToTop?: (() => void) | undefined;
15
+ }) => InfiniteScrollState;
5
16
  };
6
17
  export default _default;
@@ -67,7 +67,7 @@ export var InputWrapper = styled.div.withConfig({
67
67
  export var Selection = styled.div.withConfig({
68
68
  displayName: "Tablestyles__Selection",
69
69
  componentId: "dacfhr-11"
70
- })(["display:flex;align-items:center;justify-content:flex-start;width:64px;margin-right:24px;border-radius:3px;&:hover{background-color:", ";}.ant-btn.ds-button:first-of-type{border-top-right-radius:0;border-bottom-right-radius:0;}.ant-btn.ds-button:last-of-type{border-top-left-radius:0;border-bottom-left-radius:0;}", "{padding:0;}"], function (_ref2) {
70
+ })(["display:flex;align-items:center;justify-content:flex-start;max-width:64px;margin-right:24px;border-radius:3px;&:hover{background-color:", ";}.ant-btn.ds-button:first-of-type{border-top-right-radius:0;border-bottom-right-radius:0;}.ant-btn.ds-button:last-of-type{border-top-left-radius:0;border-bottom-left-radius:0;}", "{padding:0;}"], function (_ref2) {
71
71
  var theme = _ref2.theme;
72
72
  return theme.palette['grey-100'];
73
73
  }, CheckboxWrapper);
@@ -52,6 +52,7 @@ export type Locale = TableLocale & {
52
52
  groups?: string;
53
53
  };
54
54
  selectRowTooltip?: string;
55
+ selectVisible?: string;
55
56
  selectAllTooltip?: string;
56
57
  starRowTooltip?: string;
57
58
  selectionOptionsTooltip?: string;
@@ -167,10 +167,11 @@ function TableSelection(_ref) {
167
167
  }, 0) : selectedRowKeys.length;
168
168
  return allRecordsCount === selectedKeysInDataSourceCount;
169
169
  }, [isEmpty, selection, dataSource, isShowingSubset, getSelectableChildren, getRowKey]);
170
+ var selectionTooltipTitle = !allSelected ? locale == null ? void 0 : locale.selectAllTooltip : locale == null ? void 0 : locale.unselectAll;
170
171
  return selection != null && selection.selectedRowKeys ? /*#__PURE__*/React.createElement(S.Selection, {
171
172
  "data-popup-container": true
172
173
  }, /*#__PURE__*/React.createElement(Tooltip, {
173
- title: locale == null ? void 0 : locale.selectAllTooltip
174
+ title: selectionTooltipTitle
174
175
  }, /*#__PURE__*/React.createElement(Button.Checkbox, {
175
176
  disabled: isEmpty,
176
177
  "data-testid": "ds-table-batch-selection-button",
@@ -1,5 +1,6 @@
1
1
  import React, { Ref, ReactElement } from 'react';
2
2
  import { FixedSizeList as List } from 'react-window';
3
+ import { TableSticky } from 'rc-table/lib/interface';
3
4
  import { RowType, DSTableProps } from '../Table.types';
4
5
  import { Props, VirtualTableRef } from './VirtualTable.types';
5
6
  declare const _default: <T extends object & RowType<T> & {
@@ -12,11 +13,13 @@ declare const _default: <T extends object & RowType<T> & {
12
13
  x?: number | undefined;
13
14
  y: number;
14
15
  };
15
- sticky?: ((boolean | import("rc-table/lib/interface").TableSticky | undefined) & {
16
+ sticky?: ((boolean | TableSticky | undefined) & {
16
17
  scrollThreshold?: number | undefined;
17
18
  }) | undefined;
18
19
  onListRefChange?: ((ref: React.RefObject<List<any>>) => void) | undefined;
19
20
  onRowClick?: ((row: T) => void) | undefined;
21
+ onItemsRendered?: ((props: import("react-window").ListOnItemsRenderedProps) => void) | undefined;
22
+ onScrollToRecordIndex?: ((recordIndex: number, callback?: (() => void) | undefined) => void) | undefined;
20
23
  } & {
21
24
  ref?: React.Ref<VirtualTableRef> | undefined;
22
25
  }) => ReactElement;
@@ -13,25 +13,26 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
13
13
  import React, { useCallback, useState, useRef, forwardRef, useEffect, useMemo, useImperativeHandle } from 'react';
14
14
  import { FixedSizeList as List } from 'react-window';
15
15
  import ResizeObserver from 'rc-resize-observer';
16
- import classNames from 'classnames';
17
16
  import { compact } from 'lodash';
18
17
  import { useIntl } from 'react-intl';
19
18
  import { infiniteLoaderItemHeight } from '../InfiniteScroll/constants';
20
19
  import BackToTopButton from '../InfiniteScroll/BackToTopButton';
21
20
  import OuterListElement from '../InfiniteScroll/OuterListElement';
22
21
  import DSTable from '../Table';
23
- import VirtualTableRow from './VirtualTableRow';
22
+ import VirtualTableRow, { INFINITE_LOADED_ITEM_HEIGHT } from './VirtualTableRow';
24
23
  import * as S from './VirtualTable.styles';
25
24
  import { useTableLocale, calculatePixels } from '../utils';
26
25
  import { useRowKey } from '../hooks/useRowKey';
27
26
  import { useRowStar } from '../hooks/useRowStar';
28
27
  import { RowSelectionColumn } from '../RowSelection';
29
- import { EXPANDED_ROW_PROPERTY, HEADER_ROW_HEIGHT } from './constants';
28
+ import { EXPANDED_ROW_PROPERTY, HEADER_ROW_HEIGHT, LOAD_DATA_OFFSET } from './constants';
30
29
  var relativeInlineStyle = {
31
30
  position: 'relative'
32
31
  };
33
32
 
34
33
  var VirtualTable = function VirtualTable(props, ref) {
34
+ var _infiniteScroll$prevP2;
35
+
35
36
  var _props$columns = props.columns,
36
37
  columns = _props$columns === void 0 ? [] : _props$columns,
37
38
  scroll = props.scroll,
@@ -52,7 +53,9 @@ var VirtualTable = function VirtualTable(props, ref) {
52
53
  locale = props.locale,
53
54
  loading = props.loading,
54
55
  sticky = props.sticky,
55
- onListRefChange = props.onListRefChange;
56
+ onListRefChange = props.onListRefChange,
57
+ onItemsRendered = props.onItemsRendered,
58
+ onScrollToRecordIndex = props.onScrollToRecordIndex;
56
59
  var intl = useIntl();
57
60
  var tableLocale = useTableLocale(intl, locale);
58
61
  var listRef = useRef(null);
@@ -60,6 +63,77 @@ var VirtualTable = function VirtualTable(props, ref) {
60
63
  var containerRef = useRef(null);
61
64
  var horizontalScrollRef = useRef(null);
62
65
  var customBodyOnScrollRef = useRef();
66
+
67
+ var _React$useState = React.useState(null),
68
+ firstItem = _React$useState[0],
69
+ setFirstItem = _React$useState[1];
70
+
71
+ var updateFirstItem = useCallback(function (findFirstItem) {
72
+ var prevFirstItemIndex = dataSource.findIndex(findFirstItem);
73
+ setFirstItem(dataSource[0]);
74
+
75
+ if (prevFirstItemIndex >= 0 && listRef != null && listRef.current) {
76
+ if (onScrollToRecordIndex) {
77
+ onScrollToRecordIndex(prevFirstItemIndex, function () {
78
+ // error Expected an assignment or function call and instead saw an expression
79
+ (listRef == null ? void 0 : listRef.current) && listRef.current.scrollToItem(prevFirstItemIndex, 'start');
80
+ });
81
+ } else {
82
+ listRef.current.scrollToItem(prevFirstItemIndex, 'start');
83
+ }
84
+ }
85
+ }, [dataSource, setFirstItem, onScrollToRecordIndex]);
86
+ React.useEffect(function () {
87
+ try {
88
+ if (!(infiniteScroll != null && infiniteScroll.prevPage) || dataSource.length === 0) {
89
+ return;
90
+ }
91
+
92
+ if (firstItem === null) {
93
+ setFirstItem(dataSource[0]);
94
+ return;
95
+ }
96
+
97
+ if (rowKey === undefined) {
98
+ var firstItemStringified = JSON.stringify(firstItem);
99
+
100
+ if (JSON.stringify(dataSource[0]) !== firstItemStringified) {
101
+ updateFirstItem(function (item) {
102
+ return JSON.stringify(item) === firstItemStringified;
103
+ });
104
+ }
105
+
106
+ return;
107
+ }
108
+
109
+ if (typeof rowKey === 'string') {
110
+ if (dataSource[0][rowKey] !== firstItem[rowKey]) {
111
+ updateFirstItem(function (item) {
112
+ return item[rowKey] === firstItem[rowKey];
113
+ });
114
+ }
115
+
116
+ return;
117
+ }
118
+
119
+ if (typeof rowKey === 'function') {
120
+ if (rowKey(dataSource[0]) !== rowKey(firstItem)) {
121
+ updateFirstItem(function (item) {
122
+ return rowKey(item) === rowKey(firstItem);
123
+ });
124
+ }
125
+ }
126
+ } catch (error) {
127
+ throw new Error('Cannot find firs item');
128
+ }
129
+ }, [dataSource, dataSource.length, rowKey, firstItem, infiniteScroll, updateFirstItem]);
130
+ React.useEffect(function () {
131
+ var _infiniteScroll$prevP;
132
+
133
+ if (listRef.current && infiniteScroll != null && (_infiniteScroll$prevP = infiniteScroll.prevPage) != null && _infiniteScroll$prevP.hasMore) {
134
+ listRef.current.scrollTo(INFINITE_LOADED_ITEM_HEIGHT);
135
+ }
136
+ }, [listRef, infiniteScroll == null ? void 0 : (_infiniteScroll$prevP2 = infiniteScroll.prevPage) == null ? void 0 : _infiniteScroll$prevP2.hasMore]);
63
137
  useImperativeHandle(ref, function () {
64
138
  return {
65
139
  virtualListRef: listRef,
@@ -229,12 +303,15 @@ var VirtualTable = function VirtualTable(props, ref) {
229
303
  });
230
304
  }
231
305
  }, []);
306
+ var offsetScroll = sticky && sticky !== true ? sticky.offsetScroll : 0;
232
307
  var renderBody = useCallback(function (rawData, meta, defaultTableProps) {
233
308
  var _expandable$expandedR;
234
309
 
235
310
  customBodyOnScrollRef.current = meta.onScroll;
236
311
 
237
312
  var renderVirtualList = function renderVirtualList(data) {
313
+ var _infiniteScroll$nextP, _infiniteScroll$prevP3;
314
+
238
315
  var listHeight = data.length * cellHeight - scroll.y + infiniteLoaderItemHeight;
239
316
  var listMaxScroll = sticky && sticky.scrollThreshold && infiniteScroll != null && infiniteScroll.maxScroll ? (infiniteScroll == null ? void 0 : infiniteScroll.maxScroll) - sticky.scrollThreshold : listHeight;
240
317
 
@@ -248,11 +325,11 @@ var VirtualTable = function VirtualTable(props, ref) {
248
325
 
249
326
  var roundedOffset = Math.ceil(scrollOffset);
250
327
 
251
- if (scrollDirection === 'forward' && roundedOffset >= listMaxScroll && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollEndReach) === 'function') {
328
+ if (scrollDirection === 'forward' && roundedOffset >= listMaxScroll - LOAD_DATA_OFFSET && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollEndReach) === 'function') {
252
329
  infiniteScroll.onScrollEndReach();
253
330
  }
254
331
 
255
- if (scrollDirection === 'backward' && roundedOffset === 0 && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollTopReach) === 'function') {
332
+ if (scrollDirection === 'backward' && (offsetScroll && roundedOffset <= offsetScroll + LOAD_DATA_OFFSET || roundedOffset < LOAD_DATA_OFFSET) && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollTopReach) === 'function') {
256
333
  infiniteScroll.onScrollTopReach();
257
334
  }
258
335
  };
@@ -260,6 +337,10 @@ var VirtualTable = function VirtualTable(props, ref) {
260
337
  var itemData = createItemData(data, defaultTableProps);
261
338
  var scrollableHeight = sticky ? scroll.y - HEADER_ROW_HEIGHT : scroll.y;
262
339
 
340
+ if (infiniteScroll != null && (_infiniteScroll$nextP = infiniteScroll.nextPage) != null && _infiniteScroll$nextP.hasMore && (_infiniteScroll$prevP3 = infiniteScroll.prevPage) != null && _infiniteScroll$prevP3.hasMore) {
341
+ scrollableHeight += cellHeight;
342
+ }
343
+
263
344
  var handleBodyScroll = function handleBodyScroll(event) {
264
345
  var scrollLeft = event.currentTarget.scrollLeft;
265
346
  var info = {
@@ -287,6 +368,7 @@ var VirtualTable = function VirtualTable(props, ref) {
287
368
  ref: listRef,
288
369
  key: "virtual-list",
289
370
  onScroll: handleListScroll,
371
+ onItemsRendered: onItemsRendered,
290
372
  className: "virtual-grid",
291
373
  height: scrollableHeight,
292
374
  layout: "vertical",
@@ -326,10 +408,15 @@ var VirtualTable = function VirtualTable(props, ref) {
326
408
  }
327
409
 
328
410
  return renderVirtualList(rawData);
329
- }, [cellHeight, createItemData, expandable == null ? void 0 : expandable.expandedRowKeys, getRowKey, infiniteScroll, listInnerElementType, loading, outerElement, scroll.y, sticky, tableWidth]);
411
+ }, [cellHeight, createItemData, expandable == null ? void 0 : expandable.expandedRowKeys, getRowKey, infiniteScroll, listInnerElementType, loading, outerElement, scroll.y, sticky, tableWidth, offsetScroll, onItemsRendered]);
330
412
  var columnsSliceStartIndex = Number(!!selection) + Number(!!rowStar); // eslint-disable-next-line
331
413
 
332
414
  var scrollValue = !dataSource || (dataSource == null ? void 0 : dataSource.length) === 0 ? undefined : props == null ? void 0 : props.scroll;
415
+ var classNames = React.useMemo(function () {
416
+ var infiniteScrollTableClassName = infiniteScroll ? 'virtual-table-infinite-scroll' : '';
417
+ var stickyClassName = sticky ? 'with-sticky-header' : '';
418
+ return "virtual-table " + className + " " + infiniteScrollTableClassName + " " + stickyClassName;
419
+ }, [className, infiniteScroll, sticky]);
333
420
  var finalColumns = mergedColumns.slice(columnsSliceStartIndex);
334
421
  useEffect(function () {
335
422
  if (containerRef != null && containerRef.current) {
@@ -337,7 +424,6 @@ var VirtualTable = function VirtualTable(props, ref) {
337
424
  headerElement && setScrollWidth(headerElement.scrollWidth);
338
425
  }
339
426
  }, [finalColumns]);
340
- var offsetScroll = sticky && sticky !== true ? sticky.offsetScroll : 0;
341
427
  return /*#__PURE__*/React.createElement(S.VirtualTableWrapper, {
342
428
  isSticky: Boolean(sticky),
343
429
  style: sticky ? {} : relativeInlineStyle,
@@ -352,8 +438,7 @@ var VirtualTable = function VirtualTable(props, ref) {
352
438
  sticky: dataSource.length ? sticky : undefined,
353
439
  loading: loading,
354
440
  scroll: scrollValue,
355
- className: classNames(className, 'virtual-table', !!infiniteScroll && 'virtual-table-infinite-scroll', Boolean(sticky) && 'with-sticky-header') // Remove columns which cause header columns indent
356
- // @ts-ignore
441
+ className: classNames // @ts-ignore
357
442
  ,
358
443
  columns: finalColumns,
359
444
  pagination: false,
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { FixedSizeList as List } from 'react-window';
2
+ import { FixedSizeList as List, ListOnItemsRenderedProps } from 'react-window';
3
3
  import { InfiniteScrollProps } from '../InfiniteScroll/InfiniteLoaderItem.types';
4
4
  import { DSTableProps } from '../Table.types';
5
5
  export type Props<T> = DSTableProps<T> & {
@@ -15,6 +15,8 @@ export type Props<T> = DSTableProps<T> & {
15
15
  };
16
16
  onListRefChange?: (ref: RefObject<List>) => void;
17
17
  onRowClick?: (row: T) => void;
18
+ onItemsRendered?: (props: ListOnItemsRenderedProps) => void;
19
+ onScrollToRecordIndex?: (recordIndex: number, callback?: () => void) => void;
18
20
  };
19
21
  export type VirtualTableRef = {
20
22
  virtualListRef: RefObject<List>;
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  import { InfiniteScrollProps } from '../InfiniteScroll/InfiniteLoaderItem.types';
3
3
  import { RowSelection, DSTableProps } from '../Table.types';
4
4
  import { RowStar } from '../hooks/useRowStar';
5
+ export declare const INFINITE_LOADED_ITEM_HEIGHT = 64;
5
6
  export interface VirtualTableRowProps<T> {
6
7
  data: {
7
8
  dataSource: T[];
@@ -11,6 +11,7 @@ import InfiniteLoaderItem from '../InfiniteScroll/InfiniteLoaderItem';
11
11
  import { EXPANDED_ROW_PROPERTY } from './constants';
12
12
  import * as S from './VirtualTable.styles';
13
13
  import { getValueFromPath, calculatePixels } from '../utils';
14
+ export var INFINITE_LOADED_ITEM_HEIGHT = 64;
14
15
 
15
16
  var isColumnSortingActive = function isColumnSortingActive(columns, column) {
16
17
  return !!columns.find(function (c) {
@@ -23,6 +24,8 @@ var calculateToPixelsIfDefined = function calculateToPixelsIfDefined(value) {
23
24
  };
24
25
 
25
26
  function VirtualTableRow(_ref) {
27
+ var _infiniteScroll$prevP3;
28
+
26
29
  var index = _ref.index,
27
30
  style = _ref.style,
28
31
  _ref$data = _ref.data,
@@ -44,22 +47,47 @@ function VirtualTableRow(_ref) {
44
47
  var rowData = React.useMemo(function () {
45
48
  return dataSource[index];
46
49
  }, [dataSource, index]);
47
- var infiniteLoader = React.useMemo(function () {
48
- return infiniteScroll && index === dataSource.length - 1 && /*#__PURE__*/React.createElement(S.RowWrapper, {
50
+ var infiniteLoader = React.useCallback(function (position) {
51
+ var isVisible = false;
52
+ var infiniteLoaderItemProps;
53
+ var top = style.top;
54
+
55
+ if (position === 'TOP') {
56
+ var _infiniteScroll$prevP;
57
+
58
+ isVisible = Boolean(infiniteScroll && ((_infiniteScroll$prevP = infiniteScroll.prevPage) == null ? void 0 : _infiniteScroll$prevP.hasMore) && index === 0);
59
+ infiniteLoaderItemProps = infiniteScroll == null ? void 0 : infiniteScroll.prevPage;
60
+ top = "0px";
61
+ }
62
+
63
+ if (position === 'BOTTOM') {
64
+ var _infiniteScroll$prevP2;
65
+
66
+ isVisible = Boolean(index === dataSource.length - 1);
67
+ infiniteLoaderItemProps = infiniteScroll == null ? void 0 : infiniteScroll.nextPage;
68
+ var prevDataInfiniteLoaderHeight = infiniteScroll != null && (_infiniteScroll$prevP2 = infiniteScroll.prevPage) != null && _infiniteScroll$prevP2.hasMore ? INFINITE_LOADED_ITEM_HEIGHT : 0;
69
+ top = Number(style.top) + cellHeight + prevDataInfiniteLoaderHeight + "px";
70
+ }
71
+
72
+ return infiniteLoaderItemProps && isVisible && /*#__PURE__*/React.createElement(S.RowWrapper, {
49
73
  style: _objectSpread({}, style, {
50
- top: Number(style.top) + cellHeight + "px",
51
- height: '64px',
74
+ top: top,
75
+ height: INFINITE_LOADED_ITEM_HEIGHT + "px",
52
76
  padding: '16px 24px'
53
77
  })
54
78
  }, /*#__PURE__*/React.createElement(InfiniteLoaderItem, {
55
- infiniteScroll: infiniteScroll
79
+ infiniteScroll: _objectSpread({}, infiniteScroll, {}, infiniteLoaderItemProps),
80
+ position: position
56
81
  }));
57
82
  }, [cellHeight, dataSource.length, index, infiniteScroll, style]);
58
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(S.RowWrapper, {
83
+ var top = infiniteScroll != null && (_infiniteScroll$prevP3 = infiniteScroll.prevPage) != null && _infiniteScroll$prevP3.hasMore ? Number(style.top) + INFINITE_LOADED_ITEM_HEIGHT + "px" : style.top;
84
+ return /*#__PURE__*/React.createElement(React.Fragment, null, infiniteLoader('TOP'), /*#__PURE__*/React.createElement(S.RowWrapper, {
59
85
  className: classNames('virtual-table-row', {
60
86
  'ds-expanded-row': rowData[EXPANDED_ROW_PROPERTY]
61
87
  }),
62
- style: style,
88
+ style: _objectSpread({}, style, {
89
+ top: top
90
+ }),
63
91
  onClick: function onClick(event) {
64
92
  event.stopPropagation();
65
93
  onRowClick && onRowClick(rowData);
@@ -80,7 +108,7 @@ function VirtualTableRow(_ref) {
80
108
  width: column.width,
81
109
  maxWidth: calculateToPixelsIfDefined(column == null ? void 0 : column.maxWidth)
82
110
  }, renderColumn(column, rowData, columnIndex));
83
- })), infiniteLoader);
111
+ })), infiniteLoader('BOTTOM'));
84
112
  }
85
113
 
86
114
  export default React.memo(VirtualTableRow, areEqual);
@@ -1,2 +1,3 @@
1
1
  export declare const HEADER_ROW_HEIGHT = 64;
2
2
  export declare const EXPANDED_ROW_PROPERTY = "expandedChild";
3
+ export declare const LOAD_DATA_OFFSET = 800;
@@ -1,2 +1,3 @@
1
1
  export var HEADER_ROW_HEIGHT = 64;
2
- export var EXPANDED_ROW_PROPERTY = 'expandedChild';
2
+ export var EXPANDED_ROW_PROPERTY = 'expandedChild';
3
+ export var LOAD_DATA_OFFSET = 800;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-table",
3
- "version": "0.48.1",
3
+ "version": "0.48.3",
4
4
  "description": "Table UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -33,31 +33,31 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-alert": "^0.8.8",
37
- "@synerise/ds-badge": "^0.6.54",
38
- "@synerise/ds-button": "^0.19.5",
39
- "@synerise/ds-button-group": "^0.6.45",
40
- "@synerise/ds-checkbox": "^0.11.61",
41
- "@synerise/ds-column-manager": "^0.11.36",
36
+ "@synerise/ds-alert": "^0.8.9",
37
+ "@synerise/ds-badge": "^0.6.55",
38
+ "@synerise/ds-button": "^0.19.6",
39
+ "@synerise/ds-button-group": "^0.6.46",
40
+ "@synerise/ds-checkbox": "^0.11.62",
41
+ "@synerise/ds-column-manager": "^0.11.38",
42
42
  "@synerise/ds-data-format": "^0.4.8",
43
- "@synerise/ds-dropdown": "^0.17.102",
43
+ "@synerise/ds-dropdown": "^0.17.103",
44
44
  "@synerise/ds-flag": "^0.4.3",
45
- "@synerise/ds-icon": "^0.60.5",
46
- "@synerise/ds-input": "^0.20.3",
47
- "@synerise/ds-loader": "^0.3.3",
48
- "@synerise/ds-menu": "^0.18.17",
49
- "@synerise/ds-modal": "^0.17.23",
50
- "@synerise/ds-pagination": "^0.7.45",
51
- "@synerise/ds-result": "^0.6.49",
52
- "@synerise/ds-scrollbar": "^0.10.0",
53
- "@synerise/ds-search": "^0.8.84",
54
- "@synerise/ds-select": "^0.15.42",
55
- "@synerise/ds-skeleton": "^0.5.3",
56
- "@synerise/ds-status": "^0.5.106",
57
- "@synerise/ds-tags": "^0.8.36",
58
- "@synerise/ds-tooltip": "^0.14.22",
45
+ "@synerise/ds-icon": "^0.60.6",
46
+ "@synerise/ds-input": "^0.20.4",
47
+ "@synerise/ds-loader": "^0.3.4",
48
+ "@synerise/ds-menu": "^0.18.18",
49
+ "@synerise/ds-modal": "^0.17.24",
50
+ "@synerise/ds-pagination": "^0.7.46",
51
+ "@synerise/ds-result": "^0.6.50",
52
+ "@synerise/ds-scrollbar": "^0.10.1",
53
+ "@synerise/ds-search": "^0.8.85",
54
+ "@synerise/ds-select": "^0.15.43",
55
+ "@synerise/ds-skeleton": "^0.5.4",
56
+ "@synerise/ds-status": "^0.5.107",
57
+ "@synerise/ds-tags": "^0.8.37",
58
+ "@synerise/ds-tooltip": "^0.14.23",
59
59
  "@synerise/ds-typography": "^0.14.3",
60
- "@synerise/ds-utils": "^0.26.1",
60
+ "@synerise/ds-utils": "^0.26.2",
61
61
  "@types/react-window": "^1.8.5",
62
62
  "classnames": "2.3.2",
63
63
  "copy-to-clipboard": "^3.3.1",
@@ -79,5 +79,5 @@
79
79
  "devDependencies": {
80
80
  "@testing-library/react": "10.0.1"
81
81
  },
82
- "gitHead": "07304b7bf03826701df904c7be058d93588a9611"
82
+ "gitHead": "7506652551b234c2e30e3bb492d56ab822bdb5a1"
83
83
  }