@infinite-table/infinite-react 0.1.0 → 0.1.4

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/index.esm.js CHANGED
@@ -622,7 +622,7 @@ import {
622
622
  createElement as createElement33,
623
623
  memo as memo13,
624
624
  useEffect as useEffect24,
625
- useLayoutEffect as useLayoutEffect6
625
+ useLayoutEffect as useLayoutEffect5
626
626
  } from "react";
627
627
 
628
628
  // src/components/InfiniteTable/internalProps.ts
@@ -704,14 +704,21 @@ var ScrollListener = class {
704
704
  };
705
705
 
706
706
  // src/components/InfiniteTable/utils/toMap.ts
707
- function toMap(mapOrObject) {
707
+ function toMap(mapOrObject, weakMapCache) {
708
708
  if (!mapOrObject) {
709
709
  return new Map();
710
710
  }
711
711
  if (mapOrObject instanceof Map) {
712
712
  return mapOrObject;
713
713
  }
714
- return new Map(Object.entries(mapOrObject));
714
+ if (weakMapCache && weakMapCache.has(mapOrObject)) {
715
+ return weakMapCache.get(mapOrObject);
716
+ }
717
+ const result = new Map(Object.entries(mapOrObject));
718
+ if (weakMapCache) {
719
+ weakMapCache.set(mapOrObject, result);
720
+ }
721
+ return result;
715
722
  }
716
723
 
717
724
  // src/components/InfiniteTable/state/computeColumnGroupsDepths.ts
@@ -737,12 +744,10 @@ function computeColumnGroupsDepths(columnGroups) {
737
744
  }
738
745
 
739
746
  // src/components/InfiniteTable/state/getInitialState.ts
740
- function toColumnTypesMap(mapOrObject) {
741
- return toMap(mapOrObject);
742
- }
743
747
  function initSetupState() {
744
748
  const columnsGeneratedForGrouping = new Map();
745
749
  return {
750
+ propsCache: new Map([]),
746
751
  columnShifts: null,
747
752
  domRef: createRef(),
748
753
  scrollerDOMRef: createRef(),
@@ -767,12 +772,8 @@ function initSetupState() {
767
772
  columnsWhenInlineGroupRenderStrategy: void 0
768
773
  };
769
774
  }
770
- var forwardProps = () => {
775
+ var forwardProps = (setupState) => {
771
776
  return {
772
- columns: (columns) => {
773
- var _a;
774
- return (_a = toMap(columns)) != null ? _a : new Map();
775
- },
776
777
  scrollTopId: 1,
777
778
  components: 1,
778
779
  loadingText: 1,
@@ -790,6 +791,7 @@ var forwardProps = () => {
790
791
  onBlurWithin: 1,
791
792
  onScrollToTop: 1,
792
793
  onScrollToBottom: 1,
794
+ onScrollStop: 1,
793
795
  scrollToBottomOffset: 1,
794
796
  rowStyle: 1,
795
797
  rowProps: 1,
@@ -800,6 +802,7 @@ var forwardProps = () => {
800
802
  pivotRowLabelsColumn: 1,
801
803
  pivotColumnGroups: 1,
802
804
  onScrollbarsChange: 1,
805
+ scrollStopDelay: (scrollStopDelay) => scrollStopDelay != null ? scrollStopDelay : 100,
803
806
  viewportReservedWidth: (viewportReservedWidth) => viewportReservedWidth != null ? viewportReservedWidth : 0,
804
807
  activeIndex: (activeIndex) => activeIndex != null ? activeIndex : 0,
805
808
  columnMinWidth: (columnMinWidth) => columnMinWidth != null ? columnMinWidth : 30,
@@ -818,21 +821,13 @@ var forwardProps = () => {
818
821
  virtualizeColumns: (virtualizeColumns) => virtualizeColumns != null ? virtualizeColumns : true,
819
822
  rowHeight: (rowHeight) => typeof rowHeight === "number" ? rowHeight : 0,
820
823
  headerHeight: (headerHeight) => typeof headerHeight === "number" ? headerHeight : 0,
821
- columnVisibility: (columnVisibility) => {
822
- var _a;
823
- return (_a = toMap(columnVisibility)) != null ? _a : new Map();
824
- },
825
- columnPinning: (columnPinning) => columnPinning != null ? columnPinning : new Map(),
826
- columnSizing: (columnSizing) => {
827
- var _a;
828
- return (_a = toMap(columnSizing)) != null ? _a : new Map();
829
- },
830
- columnTypes: (columnTypes) => {
831
- var _a;
832
- return (_a = toColumnTypesMap(columnTypes)) != null ? _a : new Map();
833
- },
824
+ columns: (columns) => toMap(columns, setupState.propsCache.get("columns")),
825
+ columnVisibility: (columnVisibility) => columnVisibility != null ? columnVisibility : {},
826
+ columnPinning: (columnPinning) => toMap(columnPinning, setupState.propsCache.get("columnPinning")),
827
+ columnSizing: (columnSizing) => toMap(columnSizing, setupState.propsCache.get("columnSizing")),
828
+ columnTypes: (columnTypes) => toMap(columnTypes, setupState.propsCache.get("columnTypes")),
834
829
  collapsedColumnGroups: (collapsedColumnGroups) => collapsedColumnGroups != null ? collapsedColumnGroups : new Map(),
835
- columnGroups: (columnGroups) => columnGroups != null ? columnGroups : new Map()
830
+ columnGroups: (columnGroups) => toMap(columnGroups, setupState.propsCache.get("columnGroups"))
836
831
  };
837
832
  };
838
833
  function getGroupRenderStrategy(options) {
@@ -1215,11 +1210,11 @@ function getColumnComputedType(column, columnTypes) {
1215
1210
  // src/components/InfiniteTable/utils/getComputedVisibleColumns.ts
1216
1211
  var logError = err("getComputedVisibleColumns");
1217
1212
  var isColumnVisible = (columnVisibility, _columnVisibilityAssumeVisible, colId) => {
1218
- return !columnVisibility.has(colId) || columnVisibility.get(colId) !== false;
1213
+ return columnVisibility[colId] !== false;
1219
1214
  };
1220
1215
  var getComputedPinned = (colId, columnPinning) => {
1221
1216
  const pinned = columnPinning.get(colId);
1222
- const computedPinned = pinned === "start" || pinned === true ? "start" : pinned === "end" ? "end" : false;
1217
+ const computedPinned = pinned === "start" ? "start" : pinned === "end" ? "end" : false;
1223
1218
  return computedPinned;
1224
1219
  };
1225
1220
  var getComputedVisibleColumns = ({
@@ -1251,7 +1246,8 @@ var getComputedVisibleColumns = ({
1251
1246
  logError(`Column with id "${colId}" specified in columnOrder array cannot be found in the columns map.`);
1252
1247
  return false;
1253
1248
  }
1254
- return isColumnVisible(columnVisibility, columnVisibilityAssumeVisible, colId);
1249
+ const result2 = isColumnVisible(columnVisibility, columnVisibilityAssumeVisible, colId);
1250
+ return result2;
1255
1251
  });
1256
1252
  const columnsArray = visibleColumnOrder.map((columnId) => columns.get(columnId)).filter(Boolean);
1257
1253
  const sortedMap = (sortInfo != null ? sortInfo : []).reduce((acc, info, index) => {
@@ -1277,10 +1273,13 @@ var getComputedVisibleColumns = ({
1277
1273
  const colTypeSizing = {
1278
1274
  minWidth: colType == null ? void 0 : colType.minWidth,
1279
1275
  maxWidth: colType == null ? void 0 : colType.maxWidth,
1280
- width: colType == null ? void 0 : colType.width,
1281
- flex: colType == null ? void 0 : colType.flex
1276
+ width: colType == null ? void 0 : colType.defaultWidth,
1277
+ flex: colType == null ? void 0 : colType.defaultFlex
1278
+ };
1279
+ let colSizing = columnSizing.get(colId) || {
1280
+ width: column == null ? void 0 : column.defaultWidth,
1281
+ flex: column == null ? void 0 : column.defaultFlex
1282
1282
  };
1283
- let colSizing = columnSizing.get(colId) || {};
1284
1283
  if (colSizing.width != null) {
1285
1284
  delete colTypeSizing.flex;
1286
1285
  }
@@ -1331,7 +1330,7 @@ var getComputedVisibleColumns = ({
1331
1330
  });
1332
1331
  const firstPinnedEndAbsoluteOffset = bodySize.width - totalPinnedEndWidth;
1333
1332
  columnsArray.forEach((c, i) => {
1334
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1333
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1335
1334
  const id = visibleColumnOrder[i];
1336
1335
  const nextColumnId = visibleColumnOrder[i + 1];
1337
1336
  const colType = getColumnComputedType(c, columnTypes);
@@ -1392,6 +1391,7 @@ var getComputedVisibleColumns = ({
1392
1391
  const result2 = __spreadProps(__spreadValues({
1393
1392
  align: colType.align,
1394
1393
  verticalAlign: colType.verticalAlign,
1394
+ valueGetter: colType.valueGetter,
1395
1395
  renderValue: colType.renderValue,
1396
1396
  render: colType.render
1397
1397
  }, c), {
@@ -1399,7 +1399,7 @@ var getComputedVisibleColumns = ({
1399
1399
  computedAbsoluteOffset,
1400
1400
  computedPinningOffset,
1401
1401
  computedOffset,
1402
- computedSortable: (_e = (_d = c.sortable) != null ? _d : sortable) != null ? _e : true,
1402
+ computedSortable: (_f = (_e = (_d = c.sortable) != null ? _d : colType.sortable) != null ? _e : sortable) != null ? _f : true,
1403
1403
  computedSortInfo,
1404
1404
  computedSortIndex,
1405
1405
  computedMultiSort: multiSort,
@@ -1408,14 +1408,14 @@ var getComputedVisibleColumns = ({
1408
1408
  computedSortedDesc,
1409
1409
  computedVisibleIndex: i,
1410
1410
  computedPinned,
1411
- computedDraggable: (_g = (_f = c.draggable) != null ? _f : draggableColumns) != null ? _g : true,
1411
+ computedDraggable: (_h = (_g = c.draggable) != null ? _g : draggableColumns) != null ? _h : true,
1412
1412
  computedFirstInCategory,
1413
1413
  computedLastInCategory,
1414
1414
  computedFirst: i === 0,
1415
1415
  computedLast,
1416
1416
  toggleSort,
1417
1417
  id,
1418
- header: (_i = (_h = c.header) != null ? _h : c.name) != null ? _i : c.field
1418
+ header: (_k = (_j = (_i = c.header) != null ? _i : colType.header) != null ? _j : c.name) != null ? _k : c.field
1419
1419
  });
1420
1420
  computedOffset += computedWidth;
1421
1421
  computedVisibleColumnsMap.set(result2.id, result2);
@@ -1566,7 +1566,6 @@ var useComputedVisibleColumns = ({
1566
1566
  const columnsSizingRenderId = useRerenderOnKeyChange(columnSizing);
1567
1567
  const columnTypesRenderId = useRerenderOnKeyChange(columnTypes);
1568
1568
  const columnsRenderId = useRerenderOnKeyChange(columns);
1569
- const visibilityRenderId = useRerenderOnKeyChange(columnVisibility);
1570
1569
  const pinningRenderId = useRerenderOnKeyChange(columnPinning);
1571
1570
  const {
1572
1571
  computedRemainingSpace,
@@ -1622,7 +1621,6 @@ var useComputedVisibleColumns = ({
1622
1621
  pinnedStartMaxWidth,
1623
1622
  columnPinning,
1624
1623
  columnsRenderId,
1625
- visibilityRenderId,
1626
1624
  columnsSizingRenderId,
1627
1625
  pinningRenderId,
1628
1626
  columnTypesRenderId
@@ -1647,7 +1645,7 @@ var useComputedVisibleColumns = ({
1647
1645
  return result;
1648
1646
  };
1649
1647
 
1650
- // src/utils/sortAscending.ts
1648
+ // src/utils/DeepMap/sortAscending.ts
1651
1649
  var sortAscending = (a, b) => a - b;
1652
1650
 
1653
1651
  // src/components/InfiniteTable/hooks/useComputed.ts
@@ -1754,9 +1752,14 @@ function getReducerGeneratedActions(dispatch, getState, getProps, propsToForward
1754
1752
  if (currentValue === value) {
1755
1753
  return;
1756
1754
  }
1757
- notifyChange(props, stateKey, value);
1755
+ let notifyTheChange = true;
1758
1756
  if (interceptedActions && typeof interceptedActions[key] === "function") {
1759
- interceptedActions[key](value, { actions, state: state2 });
1757
+ if (interceptedActions[key](value, { actions, state: state2 }) === false) {
1758
+ notifyTheChange = false;
1759
+ }
1760
+ }
1761
+ if (notifyTheChange) {
1762
+ notifyChange(props, stateKey, value);
1760
1763
  }
1761
1764
  const forwardFn = propsToForward[key];
1762
1765
  if (typeof forwardFn === "function") {
@@ -1797,12 +1800,14 @@ function forwardProps2(propsToForward, props) {
1797
1800
  function getComponentStateRoot(config) {
1798
1801
  return memo(function ComponentStateRoot(props) {
1799
1802
  var _a, _b;
1803
+ const [initialSetupState] = useState2(() => {
1804
+ return config.initSetupState ? config.initSetupState() : {};
1805
+ });
1800
1806
  const propsToStateSetRef = useRef4(new Set());
1801
- const propsToForward = useMemo3(() => config.forwardProps ? config.forwardProps() : {}, []);
1807
+ const propsToForward = useMemo3(() => config.forwardProps ? config.forwardProps(initialSetupState) : {}, [initialSetupState]);
1802
1808
  const parentState = (_b = (_a = config.getParentState) == null ? void 0 : _a.call(config)) != null ? _b : null;
1803
1809
  const getParentState = useLatest(parentState);
1804
1810
  const [wholeState] = useState2(() => {
1805
- const initialSetupState = config.initSetupState ? config.initSetupState() : {};
1806
1811
  let mappedState = {};
1807
1812
  if (propsToForward) {
1808
1813
  mappedState = forwardProps2(propsToForward, props);
@@ -1832,9 +1837,12 @@ function getComponentStateRoot(config) {
1832
1837
  const getProps = useLatest(props);
1833
1838
  const theReducer = (previousState, action) => {
1834
1839
  var _a2;
1840
+ if (action.type === "REPLACE_STATE") {
1841
+ return action.payload;
1842
+ }
1835
1843
  const parentState2 = (_a2 = getParentState == null ? void 0 : getParentState()) != null ? _a2 : null;
1836
1844
  const mappedState = action.payload.mappedState;
1837
- const updatedProps = action.payload.updatedProps;
1845
+ const updatedProps = action.payload.updatedPropsToState;
1838
1846
  const newState = Object.assign({}, previousState);
1839
1847
  if (mappedState) {
1840
1848
  Object.assign(newState, mappedState);
@@ -1888,8 +1896,9 @@ function getComponentStateRoot(config) {
1888
1896
  const currentProps = props;
1889
1897
  const newMappedState = {};
1890
1898
  let newMappedStateCount = 0;
1891
- const updatedProps = {};
1892
- let updatedPropsCount = 0;
1899
+ const updatedPropsToState = {};
1900
+ let updatedPropsToStateCount = 0;
1901
+ const rawUpdatedProps = {};
1893
1902
  for (var k in props) {
1894
1903
  const key = k;
1895
1904
  const oldValue = prevProps[key];
@@ -1900,6 +1909,7 @@ function getComponentStateRoot(config) {
1900
1909
  if (oldValue === newValue) {
1901
1910
  continue;
1902
1911
  }
1912
+ rawUpdatedProps[key] = { newValue, oldValue };
1903
1913
  if (isControlled(key, props) || isControlled(key, prevProps)) {
1904
1914
  if (propsToForward.hasOwnProperty(k)) {
1905
1915
  let valueToSet = newValue;
@@ -1912,22 +1922,30 @@ function getComponentStateRoot(config) {
1912
1922
  newMappedStateCount++;
1913
1923
  }
1914
1924
  } else if (propsToStateSetRef.current.has(k)) {
1915
- updatedProps[key] = currentProps[key];
1916
- updatedPropsCount++;
1925
+ updatedPropsToState[key] = currentProps[key];
1926
+ updatedPropsToStateCount++;
1917
1927
  }
1918
1928
  }
1919
1929
  }
1920
- if (updatedPropsCount > 0 || newMappedStateCount > 0) {
1930
+ if (updatedPropsToStateCount > 0 || newMappedStateCount > 0) {
1921
1931
  debug2("Triggered by new values for the following props", ...[
1922
1932
  ...Object.keys(newMappedState != null ? newMappedState : {}),
1923
- ...Object.keys(updatedProps != null ? updatedProps : {})
1933
+ ...Object.keys(updatedPropsToState != null ? updatedPropsToState : {})
1924
1934
  ]);
1925
- dispatch({
1935
+ const action = {
1926
1936
  payload: {
1927
1937
  mappedState: newMappedStateCount ? newMappedState : null,
1928
- updatedProps: updatedPropsCount ? updatedProps : null
1938
+ updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
1929
1939
  }
1930
- });
1940
+ };
1941
+ dispatch(action);
1942
+ if (config.onPropChange) {
1943
+ for (var prop in rawUpdatedProps)
1944
+ if (rawUpdatedProps.hasOwnProperty(prop)) {
1945
+ const { newValue, oldValue } = rawUpdatedProps[prop];
1946
+ config.onPropChange({ name: prop, newValue, oldValue }, props, actions);
1947
+ }
1948
+ }
1931
1949
  }
1932
1950
  });
1933
1951
  return /* @__PURE__ */ createElement2(Context.Provider, {
@@ -1999,35 +2017,38 @@ function useColumnGroups() {
1999
2017
  return interceptMap(collapsedColumnGroups, {
2000
2018
  set: (key, visibleCol) => {
2001
2019
  const colIds = key.slice(1);
2002
- const { columnVisibility } = getComponentState();
2020
+ const columnVisibility = __spreadValues({}, getComponentState().columnVisibility);
2003
2021
  colIds.forEach((colId) => {
2004
- columnVisibility.set(colId, false);
2022
+ columnVisibility[colId] = false;
2005
2023
  });
2006
- columnVisibility.delete(visibleCol);
2024
+ delete columnVisibility[visibleCol];
2025
+ componentActions.columnVisibility = columnVisibility;
2007
2026
  },
2008
2027
  beforeClear: (currentCollapsedGroups) => {
2009
- const { columnVisibility } = getComponentState();
2028
+ const columnVisibility = __spreadValues({}, getComponentState().columnVisibility);
2010
2029
  const keys = [...currentCollapsedGroups.keys()];
2011
2030
  keys.forEach((key) => {
2012
2031
  const colIds = key.slice(1);
2013
2032
  colIds.forEach((colId) => {
2014
- columnVisibility.delete(colId);
2033
+ delete columnVisibility[colId];
2015
2034
  });
2016
2035
  });
2036
+ componentActions.columnVisibility = columnVisibility;
2017
2037
  },
2018
2038
  delete: (key) => {
2019
- const { columnVisibility } = getComponentState();
2039
+ const columnVisibility = __spreadValues({}, getComponentState().columnVisibility);
2020
2040
  const colIds = key.slice(1);
2021
2041
  colIds.forEach((colId) => {
2022
- columnVisibility.delete(colId);
2042
+ delete columnVisibility[colId];
2023
2043
  });
2044
+ componentActions.columnVisibility = columnVisibility;
2024
2045
  }
2025
2046
  });
2026
2047
  }, [collapsedColumnGroups]);
2027
2048
  }
2028
2049
 
2029
2050
  // src/components/InfiniteTable/hooks/useColumnsWhen.ts
2030
- import { useEffect as useEffect9, useMemo as useMemo5 } from "react";
2051
+ import { useEffect as useEffect9, useMemo as useMemo4 } from "react";
2031
2052
 
2032
2053
  // src/components/InfiniteTable/state/getComputedPivotColumnsFromDataSourcePivotColumns.tsx
2033
2054
  import {
@@ -2372,166 +2393,9 @@ var getMultisortFunction = (sortInfo, get) => {
2372
2393
  };
2373
2394
 
2374
2395
  // src/components/DataSource/privateHooks/useLoadData.ts
2375
- import { useEffect as useEffect8, useLayoutEffect as useLayoutEffect3, useRef as useRef6, useState as useState4 } from "react";
2376
-
2377
- // src/components/hooks/useEffectWithChanges.ts
2378
- import { useEffect as useEffect7, useRef as useRef5 } from "react";
2379
- function useEffectWithChanges(fn, deps) {
2380
- const prevRef = useRef5({});
2381
- const oldValuesRef = useRef5({});
2382
- const oldValues = oldValuesRef.current;
2383
- const changesRef = useRef5({});
2384
- const changes = changesRef.current;
2385
- const useEffectDeps = [];
2386
- for (let k in deps) {
2387
- if (deps.hasOwnProperty(k)) {
2388
- if (deps[k] !== prevRef.current[k]) {
2389
- changes[k] = deps[k];
2390
- oldValues[k] = prevRef.current[k];
2391
- }
2392
- useEffectDeps.push(deps[k]);
2393
- }
2394
- }
2395
- prevRef.current = deps;
2396
- useEffect7(() => {
2397
- const changes2 = changesRef.current;
2398
- const result = fn(changes2, oldValues);
2399
- changesRef.current = {};
2400
- oldValuesRef.current = {};
2401
- return result;
2402
- }, useEffectDeps);
2403
- }
2404
-
2405
- // src/components/DataSource/privateHooks/useLoadData.ts
2406
- function buildDataSourceDataParams(componentState) {
2407
- var _a, _b;
2408
- const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
2409
- const dataSourceParams = {
2410
- originalDataArray: componentState.originalDataArray,
2411
- sortInfo,
2412
- groupBy: componentState.groupBy,
2413
- pivotBy: componentState.pivotBy
2414
- };
2415
- if (componentState.livePagination !== void 0) {
2416
- dataSourceParams.livePaginationCursor = componentState.livePaginationCursor;
2417
- }
2418
- return dataSourceParams;
2419
- }
2420
- function notifyDataParamsChanged(componentState, actions) {
2421
- var _a;
2422
- if (typeof componentState.data === "function") {
2423
- loadData(componentState.data, componentState, actions);
2424
- }
2425
- const dataParams = buildDataSourceDataParams(componentState);
2426
- (_a = componentState.onDataParamsChange) == null ? void 0 : _a.call(componentState, dataParams);
2427
- }
2428
- function loadData(data, componentState, actions) {
2429
- const dataParams = buildDataSourceDataParams(componentState);
2430
- if (typeof data === "function") {
2431
- data = data(dataParams);
2432
- }
2433
- const dataIsPromise = typeof data === "object" && typeof data.then === "function";
2434
- if (dataIsPromise) {
2435
- actions.loading = true;
2436
- }
2437
- Promise.resolve(data).then((dataParam) => {
2438
- let dataArray = [];
2439
- if (Array.isArray(dataParam.data)) {
2440
- const remoteData = dataParam;
2441
- dataArray = remoteData.data;
2442
- if (remoteData.livePaginationCursor !== void 0) {
2443
- actions.livePaginationCursor = remoteData.livePaginationCursor;
2444
- }
2445
- } else {
2446
- dataArray = dataParam;
2447
- }
2448
- actions.originalDataArray = dataArray;
2449
- if (dataIsPromise) {
2450
- actions.loading = false;
2451
- }
2452
- });
2453
- }
2454
- function useLoadData() {
2455
- const {
2456
- getComponentState,
2457
- componentActions: actions,
2458
- componentState: { data }
2459
- } = useComponentState();
2460
- useLayoutEffect3(() => {
2461
- loadData(data, getComponentState(), actions);
2462
- }, [data]);
2463
- useLivePagination();
2464
- }
2465
- function useLivePagination() {
2466
- const {
2467
- getComponentState,
2468
- componentActions: actions,
2469
- componentState
2470
- } = useComponentState();
2471
- const {
2472
- notifyScrollbarsChange,
2473
- sortInfo,
2474
- groupBy,
2475
- pivotBy,
2476
- livePaginationCursor,
2477
- scrollBottomId
2478
- } = componentState;
2479
- const [scrollbars, setScrollbars] = useState4({
2480
- vertical: false,
2481
- horizontal: false
2482
- });
2483
- const scrollbarsRef = useRef6(scrollbars);
2484
- useEffect8(() => {
2485
- notifyScrollbarsChange.onChange((scrollbars2) => {
2486
- if (!scrollbars2) {
2487
- return;
2488
- }
2489
- scrollbarsRef.current = scrollbars2;
2490
- setScrollbars(scrollbars2);
2491
- });
2492
- return () => notifyScrollbarsChange.destroy();
2493
- }, [notifyScrollbarsChange]);
2494
- const [cursorId, updateCursorId] = useState4(void 0);
2495
- useEffect8(() => {
2496
- const frameId = requestAnimationFrame(() => {
2497
- var _a;
2498
- if (!((_a = scrollbarsRef.current) == null ? void 0 : _a.vertical)) {
2499
- updateCursorId(livePaginationCursor);
2500
- }
2501
- });
2502
- return () => cancelAnimationFrame(frameId);
2503
- }, [livePaginationCursor]);
2504
- useEffect8(() => {
2505
- const { livePaginationCursor: livePaginationCursor2, livePagination } = getComponentState();
2506
- if (!scrollbars.vertical && livePagination) {
2507
- updateCursorId(livePaginationCursor2);
2508
- }
2509
- }, [scrollbars.vertical]);
2510
- useEffect8(() => {
2511
- updateCursorId(scrollBottomId);
2512
- }, [scrollBottomId]);
2513
- const depsObject = {
2514
- sortInfo,
2515
- groupBy,
2516
- pivotBy,
2517
- cursorId
2518
- };
2519
- useEffectWithChanges(() => {
2520
- if (cursorId === void 0) {
2521
- return;
2522
- }
2523
- notifyDataParamsChanged(getComponentState(), actions);
2524
- }, depsObject);
2525
- }
2526
-
2527
- // src/components/DataSource/state/normalizeSortInfo.ts
2528
- var normalizeSortInfo = (sortInfo) => {
2529
- sortInfo = sortInfo != null ? sortInfo : [];
2530
- return Array.isArray(sortInfo) ? sortInfo : [sortInfo];
2531
- };
2396
+ import { useEffect as useEffect8, useRef as useRef6, useState as useState4 } from "react";
2532
2397
 
2533
- // src/components/hooks/useOnce.ts
2534
- import { useMemo as useMemo4 } from "react";
2398
+ // src/utils/DeepMap/once.ts
2535
2399
  function once(fn) {
2536
2400
  let called = false;
2537
2401
  let result = null;
@@ -2545,14 +2409,8 @@ function once(fn) {
2545
2409
  };
2546
2410
  return onceFn;
2547
2411
  }
2548
- function useOnce(fn) {
2549
- const onceFn = useMemo4(() => {
2550
- return once(fn);
2551
- }, []);
2552
- return onceFn();
2553
- }
2554
2412
 
2555
- // src/utils/DeepMap.ts
2413
+ // src/utils/DeepMap/index.ts
2556
2414
  var SORT_ASC_REVISION = (p1, p2) => sortAscending(p1.revision, p2.revision);
2557
2415
  var DeepMap = class {
2558
2416
  constructor(initial) {
@@ -2804,81 +2662,672 @@ var DeepMap = class {
2804
2662
  }
2805
2663
  };
2806
2664
 
2807
- // src/components/DataSource/GroupRowsState.ts
2808
- var GroupRowsState = class {
2809
- constructor(state) {
2810
- this.update(state instanceof GroupRowsState ? state.getState() : state);
2811
- }
2812
- getState() {
2813
- var _a, _b, _c, _d;
2814
- return {
2815
- expandedRows: this.expandedAll ? true : (_b = (_a = this.expandedMap) == null ? void 0 : _a.topDownKeys()) != null ? _b : [],
2816
- collapsedRows: this.collapsedAll ? true : (_d = (_c = this.collapsedMap) == null ? void 0 : _c.topDownKeys()) != null ? _d : []
2817
- };
2818
- }
2819
- destroy() {
2820
- var _a, _b;
2821
- (_a = this.expandedMap) == null ? void 0 : _a.clear();
2822
- (_b = this.collapsedMap) == null ? void 0 : _b.clear();
2823
- delete this.expandedMap;
2824
- delete this.collapsedMap;
2665
+ // src/utils/groupAndPivot/index.ts
2666
+ var LAZY_ROOT_KEY_FOR_GROUPS = "____root____";
2667
+ function DEFAULT_TO_KEY(value) {
2668
+ return value;
2669
+ }
2670
+ function initReducers(reducers) {
2671
+ if (!reducers || !Object.keys(reducers).length) {
2672
+ return {};
2825
2673
  }
2826
- update(state) {
2827
- var _a, _b, _c, _d;
2828
- this.initialState = state;
2829
- const { collapsedRows, expandedRows } = this.initialState;
2830
- this.collapsedAll = collapsedRows === true;
2831
- this.expandedAll = expandedRows === true;
2832
- if (this.collapsedAll && this.expandedAll) {
2833
- throw `Cannot have both collapsedRows and expandedRows be true!`;
2834
- }
2835
- if (collapsedRows !== true) {
2836
- (_a = this.collapsedMap) == null ? void 0 : _a.clear();
2837
- this.collapsedMap = (_b = this.collapsedMap) != null ? _b : new DeepMap(collapsedRows.map((keys) => [keys, true]));
2838
- }
2839
- if (expandedRows !== true) {
2840
- (_c = this.expandedMap) == null ? void 0 : _c.clear();
2841
- this.expandedMap = (_d = this.expandedMap) != null ? _d : new DeepMap(expandedRows.map((keys) => [keys, true]));
2674
+ const result = {};
2675
+ for (let key in reducers)
2676
+ if (reducers.hasOwnProperty(key)) {
2677
+ result[key] = reducers[key].initialValue;
2842
2678
  }
2679
+ return result;
2680
+ }
2681
+ function computeReducersFor(data, reducers, reducerResults) {
2682
+ var _a, _b;
2683
+ if (!reducers || !Object.keys(reducers).length) {
2684
+ return;
2843
2685
  }
2844
- areAllCollapsed() {
2845
- return this.collapsedAll && (this.expandedMap ? this.expandedMap.size === 0 : true);
2846
- }
2847
- areAllExpanded() {
2848
- return this.expandedAll && (this.collapsedMap ? this.collapsedMap.size === 0 : true);
2849
- }
2850
- collapseAll() {
2851
- this.update({
2852
- collapsedRows: true,
2853
- expandedRows: []
2854
- });
2855
- }
2856
- expandAll() {
2857
- this.update({
2858
- expandedRows: true,
2859
- collapsedRows: []
2860
- });
2861
- }
2862
- isGroupRowExpanded(keys) {
2863
- var _a, _b;
2864
- if (this.expandedAll === true) {
2865
- if (this.collapsedAll === true) {
2866
- throw 'Cannot have both expandedRows and collapsedRows be "true"';
2686
+ for (let key in reducers)
2687
+ if (reducers.hasOwnProperty(key)) {
2688
+ const reducer = reducers[key];
2689
+ if (typeof reducer.reducer !== "function") {
2690
+ continue;
2867
2691
  }
2868
- return !((_a = this.collapsedMap) == null ? void 0 : _a.has(keys));
2692
+ const currentValue = reducerResults[key];
2693
+ const value = reducer.field ? data[reducer.field] : (_b = (_a = reducer.getter) == null ? void 0 : _a.call(reducer, data)) != null ? _b : null;
2694
+ reducerResults[key] = reducer.reducer(currentValue, value, data);
2869
2695
  }
2870
- return (_b = this.expandedMap) == null ? void 0 : _b.has(keys);
2871
- }
2872
- isGroupRowCollapsed(keys) {
2873
- return !this.isGroupRowExpanded(keys);
2696
+ }
2697
+ function lazyGroup(groupParams, rootData) {
2698
+ const {
2699
+ reducers = {},
2700
+ pivot,
2701
+ groupBy,
2702
+ mappings
2703
+ } = groupParams;
2704
+ const deepMap = new DeepMap();
2705
+ function traverseValues(pivotDeepMap, container, pivot2, pivotIndex = 0, currentPivotKeys2 = []) {
2706
+ const last = pivotIndex === pivot2.length - 1;
2707
+ const values = container[(mappings == null ? void 0 : mappings.values) || "values"] || {};
2708
+ for (var k in values)
2709
+ if (values.hasOwnProperty(k)) {
2710
+ const pivotKey = k;
2711
+ currentPivotKeys2.push(pivotKey);
2712
+ topLevelPivotColumns.set(currentPivotKeys2, true);
2713
+ pivotDeepMap.set(currentPivotKeys2, {
2714
+ reducerResults: values[k][(mappings == null ? void 0 : mappings.totals) || "totals"] || {},
2715
+ items: []
2716
+ });
2717
+ if (!last) {
2718
+ traverseValues(pivotDeepMap, values[k], pivot2, pivotIndex + 1, currentPivotKeys2);
2719
+ }
2720
+ currentPivotKeys2.pop();
2721
+ }
2874
2722
  }
2875
- setGroupRowExpanded(keys, shouldExpand) {
2876
- var _a;
2877
- if (shouldExpand === this.isGroupRowExpanded(keys)) {
2878
- return;
2879
- }
2880
- if (shouldExpand) {
2881
- if (this.collapsedAll === true) {
2723
+ const topLevelPivotColumns = pivot ? new DeepMap() : void 0;
2724
+ let currentPivotKeys = [];
2725
+ const initialReducerValue = initReducers(reducers);
2726
+ const globalReducerResults = __spreadValues({}, initialReducerValue);
2727
+ rootData.visitDepthFirst((lazyGroupRowInfo, keys, _index, next) => {
2728
+ const [_rootKey, ...currentGroupKeys] = keys;
2729
+ const dataArray = lazyGroupRowInfo.items;
2730
+ for (let i = 0, len = dataArray.length; i < len; i++) {
2731
+ if (!dataArray[i]) {
2732
+ const deepMapGroupValue2 = {
2733
+ items: [],
2734
+ reducerResults: {}
2735
+ };
2736
+ deepMap.set([...currentGroupKeys, `not-loaded-yet-${i}`], deepMapGroupValue2);
2737
+ continue;
2738
+ }
2739
+ const dataObject = dataArray[i].data;
2740
+ const dataKeys = dataArray[i].keys;
2741
+ let item = dataObject;
2742
+ const { field: groupByProperty } = groupBy[dataKeys.length - 1];
2743
+ const key = item[groupByProperty];
2744
+ currentGroupKeys.push(key);
2745
+ const deepMapGroupValue = {
2746
+ items: [],
2747
+ reducerResults: dataArray[i].aggregations || {}
2748
+ };
2749
+ deepMap.set(currentGroupKeys, deepMapGroupValue);
2750
+ if (pivot) {
2751
+ const pivotDeepMap = deepMapGroupValue.pivotDeepMap = new DeepMap();
2752
+ const pivotContainer = dataArray[i].pivot;
2753
+ traverseValues(pivotDeepMap, pivotContainer, pivot, 0, currentPivotKeys);
2754
+ }
2755
+ currentGroupKeys.pop();
2756
+ }
2757
+ next == null ? void 0 : next();
2758
+ });
2759
+ const result = {
2760
+ deepMap,
2761
+ groupParams,
2762
+ initialData: rootData,
2763
+ reducerResults: globalReducerResults
2764
+ };
2765
+ if (pivot) {
2766
+ result.topLevelPivotColumns = topLevelPivotColumns;
2767
+ result.pivot = pivot;
2768
+ }
2769
+ return result;
2770
+ }
2771
+ function group(groupParams, data) {
2772
+ const {
2773
+ groupBy,
2774
+ defaultToKey = DEFAULT_TO_KEY,
2775
+ pivot,
2776
+ reducers
2777
+ } = groupParams;
2778
+ const groupByLength = groupBy.length;
2779
+ const topLevelPivotColumns = pivot ? new DeepMap() : void 0;
2780
+ const deepMap = new DeepMap();
2781
+ let currentGroupKeys = [];
2782
+ let currentPivotKeys = [];
2783
+ const initialReducerValue = initReducers(reducers);
2784
+ const globalReducerResults = __spreadValues({}, initialReducerValue);
2785
+ for (let i = 0, len = data.length; i < len; i++) {
2786
+ let item = data[i];
2787
+ for (let groupByIndex = 0; groupByIndex < groupByLength; groupByIndex++) {
2788
+ const { field: groupByProperty, toKey: groupToKey } = groupBy[groupByIndex];
2789
+ const key = (groupToKey || defaultToKey)(item[groupByProperty], item);
2790
+ currentGroupKeys.push(key);
2791
+ if (!deepMap.has(currentGroupKeys)) {
2792
+ const deepMapGroupValue = {
2793
+ items: [],
2794
+ reducerResults: __spreadValues({}, initialReducerValue)
2795
+ };
2796
+ if (pivot) {
2797
+ deepMapGroupValue.pivotDeepMap = new DeepMap();
2798
+ }
2799
+ deepMap.set(currentGroupKeys, deepMapGroupValue);
2800
+ }
2801
+ const {
2802
+ items: currentGroupItems,
2803
+ reducerResults,
2804
+ pivotDeepMap
2805
+ } = deepMap.get(currentGroupKeys);
2806
+ currentGroupItems.push(item);
2807
+ if (reducers) {
2808
+ computeReducersFor(item, reducers, reducerResults);
2809
+ }
2810
+ if (pivot) {
2811
+ for (let pivotIndex = 0, pivotLength = pivot.length; pivotIndex < pivotLength; pivotIndex++) {
2812
+ const { field: pivotField, toKey: pivotToKey } = pivot[pivotIndex];
2813
+ const pivotKey = (pivotToKey || defaultToKey)(item[pivotField], item);
2814
+ currentPivotKeys.push(pivotKey);
2815
+ if (!pivotDeepMap.has(currentPivotKeys)) {
2816
+ topLevelPivotColumns.set(currentPivotKeys, true);
2817
+ pivotDeepMap == null ? void 0 : pivotDeepMap.set(currentPivotKeys, {
2818
+ reducerResults: __spreadValues({}, initialReducerValue),
2819
+ items: []
2820
+ });
2821
+ }
2822
+ const {
2823
+ reducerResults: pivotReducerResults,
2824
+ items: pivotGroupItems
2825
+ } = pivotDeepMap.get(currentPivotKeys);
2826
+ pivotGroupItems.push(item);
2827
+ if (reducers) {
2828
+ computeReducersFor(item, reducers, pivotReducerResults);
2829
+ }
2830
+ }
2831
+ currentPivotKeys.length = 0;
2832
+ }
2833
+ }
2834
+ if (reducers) {
2835
+ computeReducersFor(item, reducers, globalReducerResults);
2836
+ }
2837
+ currentGroupKeys.length = 0;
2838
+ }
2839
+ if (reducers) {
2840
+ deepMap.visitDepthFirst((deepMapValue, _keys, _indexInGroup, next) => {
2841
+ completeReducers(reducers, deepMapValue.reducerResults, deepMapValue.items);
2842
+ if (pivot) {
2843
+ deepMapValue.pivotDeepMap.visitDepthFirst(({ items, reducerResults: pivotReducerResults }, _keys2, _indexInGroup2, next2) => {
2844
+ completeReducers(reducers, pivotReducerResults, items);
2845
+ next2 == null ? void 0 : next2();
2846
+ });
2847
+ }
2848
+ next == null ? void 0 : next();
2849
+ });
2850
+ }
2851
+ if (reducers) {
2852
+ completeReducers(reducers, globalReducerResults, data);
2853
+ }
2854
+ const result = {
2855
+ deepMap,
2856
+ groupParams,
2857
+ initialData: data,
2858
+ reducerResults: globalReducerResults
2859
+ };
2860
+ if (pivot) {
2861
+ result.topLevelPivotColumns = topLevelPivotColumns;
2862
+ result.pivot = pivot;
2863
+ }
2864
+ return result;
2865
+ }
2866
+ function flatten(groupResult) {
2867
+ const { groupParams, deepMap } = groupResult;
2868
+ const groupByLength = groupParams.groupBy.length;
2869
+ const result = [];
2870
+ deepMap.topDownKeys().reduce((acc, key) => {
2871
+ if (key.length === groupByLength) {
2872
+ const items = deepMap.get(key).items;
2873
+ acc.push(...items);
2874
+ }
2875
+ return acc;
2876
+ }, result);
2877
+ return result;
2878
+ }
2879
+ function getEnhancedGroupData(options, deepMapValue) {
2880
+ const { groupBy, groupKeys, collapsed, parents, reducers } = options;
2881
+ const groupNesting = groupKeys.length;
2882
+ const { items: groupItems, reducerResults, pivotDeepMap } = deepMapValue;
2883
+ let data = null;
2884
+ if (Object.keys(reducerResults).length > 0) {
2885
+ data = {};
2886
+ for (let key in reducers)
2887
+ if (reducers.hasOwnProperty(key)) {
2888
+ const reducer = reducers[key];
2889
+ const field = reducer.field;
2890
+ if (field) {
2891
+ data[field] = reducerResults[key];
2892
+ }
2893
+ }
2894
+ }
2895
+ const enhancedGroupData = {
2896
+ data,
2897
+ groupCount: groupItems.length,
2898
+ groupData: groupItems,
2899
+ groupKeys,
2900
+ id: groupKeys,
2901
+ collapsed,
2902
+ parents,
2903
+ collapsedChildrenCount: 0,
2904
+ collapsedGroupsCount: 0,
2905
+ indexInParentGroups: options.indexInParentGroups,
2906
+ indexInGroup: options.indexInGroup,
2907
+ indexInAll: options.indexInAll,
2908
+ value: groupKeys[groupKeys.length - 1],
2909
+ groupBy: groupBy.slice(0, groupNesting),
2910
+ isGroupRow: true,
2911
+ pivotValuesMap: pivotDeepMap,
2912
+ groupNesting,
2913
+ reducerResults
2914
+ };
2915
+ return enhancedGroupData;
2916
+ }
2917
+ function completeReducers(reducers, reducerResults, items) {
2918
+ if (reducers) {
2919
+ for (let key in reducers)
2920
+ if (reducers.hasOwnProperty(key)) {
2921
+ const reducer = reducers[key];
2922
+ if (reducer.done) {
2923
+ reducerResults[key] = reducer.done(reducerResults[key], items);
2924
+ }
2925
+ }
2926
+ }
2927
+ return reducerResults;
2928
+ }
2929
+ function enhancedFlatten(param) {
2930
+ const {
2931
+ groupResult,
2932
+ toPrimaryKey,
2933
+ groupRowsState,
2934
+ generateGroupRows,
2935
+ reducers = {}
2936
+ } = param;
2937
+ const { groupParams, deepMap, pivot } = groupResult;
2938
+ const { groupBy } = groupParams;
2939
+ const groupByStrings = groupBy.map((g) => g.field);
2940
+ const result = [];
2941
+ const parents = [];
2942
+ const indexInParentGroups = [];
2943
+ deepMap.visitDepthFirst((deepMapValue, groupKeys, indexInGroup, next) => {
2944
+ var _a;
2945
+ const items = deepMapValue.items;
2946
+ const groupNesting = groupKeys.length;
2947
+ const collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
2948
+ const enhancedGroupData = getEnhancedGroupData({
2949
+ groupBy: groupByStrings,
2950
+ parents: Array.from(parents),
2951
+ reducers,
2952
+ indexInGroup,
2953
+ indexInParentGroups: Array.from(indexInParentGroups),
2954
+ indexInAll: result.length,
2955
+ groupKeys,
2956
+ collapsed
2957
+ }, deepMapValue);
2958
+ const include = generateGroupRows || collapsed;
2959
+ if (include) {
2960
+ result.push(enhancedGroupData);
2961
+ }
2962
+ if (collapsed) {
2963
+ parents.forEach((parent) => {
2964
+ parent.collapsedChildrenCount += enhancedGroupData.groupCount;
2965
+ parent.collapsedGroupsCount += 1;
2966
+ });
2967
+ }
2968
+ indexInParentGroups.push(indexInGroup);
2969
+ parents.push(enhancedGroupData);
2970
+ if (!collapsed) {
2971
+ if (!next) {
2972
+ if (!pivot) {
2973
+ const startIndex = result.length;
2974
+ result.push(...items.map((item, index) => {
2975
+ return {
2976
+ id: toPrimaryKey(item),
2977
+ data: item,
2978
+ isGroupRow: false,
2979
+ collapsed: false,
2980
+ groupKeys,
2981
+ parents: Array.from(parents),
2982
+ indexInParentGroups: [...indexInParentGroups, index],
2983
+ indexInGroup: index,
2984
+ indexInAll: startIndex + index,
2985
+ groupBy: groupByStrings,
2986
+ groupNesting,
2987
+ groupCount: enhancedGroupData.groupCount
2988
+ };
2989
+ }));
2990
+ }
2991
+ } else {
2992
+ next();
2993
+ }
2994
+ }
2995
+ parents.pop();
2996
+ indexInParentGroups.pop();
2997
+ });
2998
+ return {
2999
+ data: result
3000
+ };
3001
+ }
3002
+
3003
+ // src/components/hooks/useEffectWithChanges.ts
3004
+ import { useEffect as useEffect7, useRef as useRef5 } from "react";
3005
+ function useEffectWithChanges(fn, deps) {
3006
+ const prevRef = useRef5({});
3007
+ const oldValuesRef = useRef5({});
3008
+ const oldValues = oldValuesRef.current;
3009
+ const changesRef = useRef5({});
3010
+ const changes = changesRef.current;
3011
+ const useEffectDeps = [];
3012
+ for (let k in deps) {
3013
+ if (deps.hasOwnProperty(k)) {
3014
+ if (deps[k] !== prevRef.current[k]) {
3015
+ changes[k] = deps[k];
3016
+ oldValues[k] = prevRef.current[k];
3017
+ }
3018
+ useEffectDeps.push(deps[k]);
3019
+ }
3020
+ }
3021
+ prevRef.current = deps;
3022
+ useEffect7(() => {
3023
+ const changes2 = changesRef.current;
3024
+ const result = fn(changes2, oldValues);
3025
+ changesRef.current = {};
3026
+ oldValuesRef.current = {};
3027
+ return result;
3028
+ }, useEffectDeps);
3029
+ }
3030
+
3031
+ // src/components/DataSource/privateHooks/useLoadData.ts
3032
+ var SKIP_DATA_CHANGES_KEYS = {
3033
+ originalDataArray: true,
3034
+ changes: true
3035
+ };
3036
+ function buildDataSourceDataParams(componentState, overrides) {
3037
+ var _a, _b;
3038
+ const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
3039
+ const dataSourceParams = {
3040
+ originalDataArray: componentState.originalDataArray,
3041
+ sortInfo,
3042
+ groupBy: componentState.groupBy,
3043
+ pivotBy: componentState.pivotBy,
3044
+ aggregationReducers: componentState.aggregationReducers
3045
+ };
3046
+ if (componentState.livePagination !== void 0) {
3047
+ dataSourceParams.livePaginationCursor = componentState.livePaginationCursor;
3048
+ dataSourceParams.cursorId = componentState.cursorId;
3049
+ }
3050
+ if (componentState.fullLazyLoad) {
3051
+ if (componentState.lazyLoadBatchSize != null && componentState.lazyLoadBatchSize > 0) {
3052
+ dataSourceParams.lazyLoadBatchSize = componentState.lazyLoadBatchSize;
3053
+ dataSourceParams.lazyLoadStartIndex = 0;
3054
+ }
3055
+ dataSourceParams.groupKeys = [];
3056
+ }
3057
+ if (overrides) {
3058
+ Object.assign(dataSourceParams, overrides);
3059
+ }
3060
+ const changes = {};
3061
+ const oldDataSourceParams = componentState.dataParams || {};
3062
+ for (let k in dataSourceParams) {
3063
+ if (dataSourceParams.hasOwnProperty(k) && !SKIP_DATA_CHANGES_KEYS[k]) {
3064
+ const key = k;
3065
+ if (dataSourceParams[key] !== oldDataSourceParams[key]) {
3066
+ changes[key] = true;
3067
+ }
3068
+ }
3069
+ }
3070
+ dataSourceParams.changes = changes;
3071
+ return dataSourceParams;
3072
+ }
3073
+ function loadData(data, componentState, actions, overrides) {
3074
+ const dataParams = buildDataSourceDataParams(componentState, overrides);
3075
+ if (typeof data === "function") {
3076
+ data = data(dataParams);
3077
+ }
3078
+ const dataIsPromise = typeof data === "object" && typeof data.then === "function";
3079
+ if (dataIsPromise) {
3080
+ actions.loading = true;
3081
+ }
3082
+ Promise.resolve(data).then((dataParam) => {
3083
+ var _a, _b, _c;
3084
+ let dataArray = [];
3085
+ let skipAssign = false;
3086
+ if (Array.isArray(dataParam.data)) {
3087
+ const remoteData = dataParam;
3088
+ dataArray = remoteData.data;
3089
+ if (remoteData.livePaginationCursor !== void 0) {
3090
+ actions.livePaginationCursor = remoteData.livePaginationCursor;
3091
+ }
3092
+ if (remoteData.mappings) {
3093
+ actions.pivotMappings = remoteData.mappings;
3094
+ }
3095
+ if (componentState.fullLazyLoad && dataParams.groupKeys) {
3096
+ const lazyGroupData = DeepMap.clone(componentState.originalLazyGroupData);
3097
+ const key = [LAZY_ROOT_KEY_FOR_GROUPS, ...dataParams.groupKeys];
3098
+ const newGroupRowInfo = {
3099
+ totalCount: (_a = remoteData.totalCount) != null ? _a : dataArray.length,
3100
+ items: dataArray
3101
+ };
3102
+ if (dataParams.lazyLoadBatchSize) {
3103
+ const existingGroupRowInfo = lazyGroupData.get(key);
3104
+ const currentGroupRowInfo = existingGroupRowInfo != null ? existingGroupRowInfo : {
3105
+ items: [],
3106
+ totalCount: newGroupRowInfo.totalCount
3107
+ };
3108
+ currentGroupRowInfo.items.length = currentGroupRowInfo.totalCount;
3109
+ const start = (_b = dataParams.lazyLoadStartIndex) != null ? _b : 0;
3110
+ const end = start + ((_c = dataParams.lazyLoadBatchSize) != null ? _c : dataArray.length);
3111
+ for (let i = start; i < end; i++) {
3112
+ currentGroupRowInfo.items[i] = newGroupRowInfo.items[i - start];
3113
+ }
3114
+ if (!existingGroupRowInfo) {
3115
+ lazyGroupData.set(key, currentGroupRowInfo);
3116
+ }
3117
+ } else {
3118
+ lazyGroupData.set(key, newGroupRowInfo);
3119
+ }
3120
+ skipAssign = true;
3121
+ actions.originalLazyGroupData = lazyGroupData;
3122
+ }
3123
+ } else {
3124
+ dataArray = dataParam;
3125
+ }
3126
+ if (!skipAssign) {
3127
+ actions.originalDataArray = dataArray;
3128
+ }
3129
+ if (dataIsPromise) {
3130
+ actions.loading = false;
3131
+ }
3132
+ });
3133
+ }
3134
+ function useLoadData() {
3135
+ const {
3136
+ getComponentState,
3137
+ componentActions: actions,
3138
+ componentState
3139
+ } = useComponentState();
3140
+ const {
3141
+ data,
3142
+ notifyScrollbarsChange,
3143
+ sortInfo,
3144
+ groupBy,
3145
+ pivotBy,
3146
+ livePagination,
3147
+ livePaginationCursor,
3148
+ cursorId: stateCursorId,
3149
+ lazyLoadBatchSize,
3150
+ notifyScrollStop
3151
+ } = componentState;
3152
+ const [scrollbars, setScrollbars] = useState4({
3153
+ vertical: false,
3154
+ horizontal: false
3155
+ });
3156
+ const scrollbarsRef = useRef6(scrollbars);
3157
+ useEffect8(() => {
3158
+ notifyScrollbarsChange.onChange((scrollbars2) => {
3159
+ if (!scrollbars2) {
3160
+ return;
3161
+ }
3162
+ scrollbarsRef.current = scrollbars2;
3163
+ setScrollbars(scrollbars2);
3164
+ });
3165
+ return () => notifyScrollbarsChange.destroy();
3166
+ }, [notifyScrollbarsChange]);
3167
+ useEffect8(() => {
3168
+ const frameId = requestAnimationFrame(() => {
3169
+ var _a;
3170
+ if (!((_a = scrollbarsRef.current) == null ? void 0 : _a.vertical) && livePaginationCursor) {
3171
+ actions.cursorId = livePaginationCursor;
3172
+ }
3173
+ });
3174
+ return () => cancelAnimationFrame(frameId);
3175
+ }, [livePaginationCursor]);
3176
+ useEffect8(() => {
3177
+ const { livePaginationCursor: livePaginationCursor2, livePagination: livePagination2 } = getComponentState();
3178
+ if (!scrollbars.vertical && livePagination2) {
3179
+ if (livePaginationCursor2) {
3180
+ actions.cursorId = livePaginationCursor2;
3181
+ }
3182
+ }
3183
+ }, [scrollbars.vertical]);
3184
+ const depsObject = {
3185
+ sortInfo,
3186
+ groupBy,
3187
+ pivotBy,
3188
+ cursorId: livePagination ? stateCursorId : null
3189
+ };
3190
+ const initialRef = useRef6(true);
3191
+ useEffect8(() => {
3192
+ if (lazyLoadBatchSize && lazyLoadBatchSize > 0) {
3193
+ return notifyScrollStop.onChange((param) => {
3194
+ console.log("scroll stop", param);
3195
+ if (!param) {
3196
+ return;
3197
+ }
3198
+ const componentState2 = getComponentState();
3199
+ const {
3200
+ firstVisibleRowIndex: startIndex,
3201
+ lastVisibleRowIndex: endIndex
3202
+ } = param;
3203
+ const firstBatchStart = Math.floor(startIndex / lazyLoadBatchSize) * lazyLoadBatchSize;
3204
+ const lastBatchStart = Math.floor(endIndex / lazyLoadBatchSize) * lazyLoadBatchSize;
3205
+ const isRowLoaded = (index) => componentState2.dataArray[index].data != null;
3206
+ for (let batchStartIndex = firstBatchStart; batchStartIndex <= lastBatchStart; batchStartIndex = batchStartIndex + lazyLoadBatchSize) {
3207
+ if (!isRowLoaded(batchStartIndex)) {
3208
+ loadData(componentState2.data, componentState2, actions, {
3209
+ lazyLoadBatchSize,
3210
+ lazyLoadStartIndex: batchStartIndex
3211
+ });
3212
+ }
3213
+ }
3214
+ });
3215
+ }
3216
+ return;
3217
+ }, [lazyLoadBatchSize]);
3218
+ useEffectWithChanges(() => {
3219
+ const componentState2 = getComponentState();
3220
+ if (typeof componentState2.data !== "function") {
3221
+ loadData(componentState2.data, componentState2, actions);
3222
+ }
3223
+ }, { data });
3224
+ useEffectWithChanges(() => {
3225
+ const componentState2 = getComponentState();
3226
+ if (typeof componentState2.data === "function") {
3227
+ loadData(componentState2.data, componentState2, actions);
3228
+ }
3229
+ }, __spreadProps(__spreadValues({}, depsObject), { data }));
3230
+ useEffectWithChanges((_changes, _prevValues) => {
3231
+ const componentState2 = getComponentState();
3232
+ if (initialRef.current) {
3233
+ initialRef.current = false;
3234
+ actions.dataParams = buildDataSourceDataParams(componentState2);
3235
+ }
3236
+ }, depsObject);
3237
+ }
3238
+
3239
+ // src/components/DataSource/state/normalizeSortInfo.ts
3240
+ var EMPTY_ARRAY = Object.freeze([]);
3241
+ var normalizeSortInfo = (initialSortInfo, weakMap) => {
3242
+ const sortInfo = initialSortInfo != null ? initialSortInfo : EMPTY_ARRAY;
3243
+ const result = Array.isArray(sortInfo) ? sortInfo : [sortInfo];
3244
+ if (weakMap && weakMap.has(sortInfo)) {
3245
+ const prevResult = weakMap.get(sortInfo);
3246
+ if (prevResult && prevResult.length === result.length) {
3247
+ return prevResult;
3248
+ }
3249
+ }
3250
+ if (weakMap && sortInfo) {
3251
+ weakMap.set(sortInfo, result);
3252
+ }
3253
+ return result;
3254
+ };
3255
+
3256
+ // src/components/DataSource/GroupRowsState.ts
3257
+ var GroupRowsState = class {
3258
+ constructor(state) {
3259
+ this.update(state instanceof GroupRowsState ? state.getState() : state);
3260
+ }
3261
+ getState() {
3262
+ var _a, _b, _c, _d;
3263
+ return {
3264
+ expandedRows: this.expandedAll ? true : (_b = (_a = this.expandedMap) == null ? void 0 : _a.topDownKeys()) != null ? _b : [],
3265
+ collapsedRows: this.collapsedAll ? true : (_d = (_c = this.collapsedMap) == null ? void 0 : _c.topDownKeys()) != null ? _d : []
3266
+ };
3267
+ }
3268
+ destroy() {
3269
+ var _a, _b;
3270
+ (_a = this.expandedMap) == null ? void 0 : _a.clear();
3271
+ (_b = this.collapsedMap) == null ? void 0 : _b.clear();
3272
+ delete this.expandedMap;
3273
+ delete this.collapsedMap;
3274
+ }
3275
+ update(state) {
3276
+ var _a, _b, _c, _d;
3277
+ this.initialState = state;
3278
+ const { collapsedRows, expandedRows } = this.initialState;
3279
+ this.collapsedAll = collapsedRows === true;
3280
+ this.expandedAll = expandedRows === true;
3281
+ if (this.collapsedAll && this.expandedAll) {
3282
+ throw `Cannot have both collapsedRows and expandedRows be true!`;
3283
+ }
3284
+ if (collapsedRows !== true) {
3285
+ (_a = this.collapsedMap) == null ? void 0 : _a.clear();
3286
+ this.collapsedMap = (_b = this.collapsedMap) != null ? _b : new DeepMap(collapsedRows.map((keys) => [keys, true]));
3287
+ }
3288
+ if (expandedRows !== true) {
3289
+ (_c = this.expandedMap) == null ? void 0 : _c.clear();
3290
+ this.expandedMap = (_d = this.expandedMap) != null ? _d : new DeepMap(expandedRows.map((keys) => [keys, true]));
3291
+ }
3292
+ }
3293
+ areAllCollapsed() {
3294
+ return this.collapsedAll && (this.expandedMap ? this.expandedMap.size === 0 : true);
3295
+ }
3296
+ areAllExpanded() {
3297
+ return this.expandedAll && (this.collapsedMap ? this.collapsedMap.size === 0 : true);
3298
+ }
3299
+ collapseAll() {
3300
+ this.update({
3301
+ collapsedRows: true,
3302
+ expandedRows: []
3303
+ });
3304
+ }
3305
+ expandAll() {
3306
+ this.update({
3307
+ expandedRows: true,
3308
+ collapsedRows: []
3309
+ });
3310
+ }
3311
+ isGroupRowExpanded(keys) {
3312
+ var _a, _b;
3313
+ if (this.expandedAll === true) {
3314
+ if (this.collapsedAll === true) {
3315
+ throw 'Cannot have both expandedRows and collapsedRows be "true"';
3316
+ }
3317
+ return !((_a = this.collapsedMap) == null ? void 0 : _a.has(keys));
3318
+ }
3319
+ return (_b = this.expandedMap) == null ? void 0 : _b.has(keys);
3320
+ }
3321
+ isGroupRowCollapsed(keys) {
3322
+ return !this.isGroupRowExpanded(keys);
3323
+ }
3324
+ setGroupRowExpanded(keys, shouldExpand) {
3325
+ var _a;
3326
+ if (shouldExpand === this.isGroupRowExpanded(keys)) {
3327
+ return;
3328
+ }
3329
+ if (shouldExpand) {
3330
+ if (this.collapsedAll === true) {
2882
3331
  if (!this.expandedMap) {
2883
3332
  throw `No expandedMap found when trying to expand group row ${keys.join(",")}`;
2884
3333
  }
@@ -2915,7 +3364,7 @@ var GroupRowsState = class {
2915
3364
  };
2916
3365
 
2917
3366
  // src/utils/shallowEqualObjects.ts
2918
- function shallowEqualObjects(objA, objB) {
3367
+ function shallowEqualObjects(objA, objB, ignoreKeys) {
2919
3368
  if (objA === objB) {
2920
3369
  return true;
2921
3370
  }
@@ -2924,12 +3373,21 @@ function shallowEqualObjects(objA, objB) {
2924
3373
  }
2925
3374
  var aKeys = Object.keys(objA);
2926
3375
  var bKeys = Object.keys(objB);
3376
+ if (ignoreKeys) {
3377
+ aKeys = aKeys.filter((key2) => !ignoreKeys.has(key2));
3378
+ bKeys = bKeys.filter((key2) => !ignoreKeys.has(key2));
3379
+ }
2927
3380
  var len = aKeys.length;
2928
3381
  if (bKeys.length !== len) {
2929
3382
  return false;
2930
3383
  }
2931
3384
  for (var i = 0; i < len; i++) {
2932
3385
  var key = aKeys[i];
3386
+ if (ignoreKeys) {
3387
+ if (ignoreKeys.has(key)) {
3388
+ continue;
3389
+ }
3390
+ }
2933
3391
  if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
2934
3392
  return false;
2935
3393
  }
@@ -2940,12 +3398,12 @@ function shallowEqualObjects(objA, objB) {
2940
3398
  // src/components/utils/discardCallsWithEqualArg.ts
2941
3399
  var map = new WeakMap();
2942
3400
  var getCompareDefault = (a) => a;
2943
- function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject2) {
3401
+ function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject) {
2944
3402
  map.set(fn, {
2945
3403
  lastCallTime: 0,
2946
3404
  lastCallArg: null
2947
3405
  });
2948
- const getCompare = getCompareObject2 != null ? getCompareObject2 : getCompareDefault;
3406
+ const getCompare = getCompareObject != null ? getCompareObject : getCompareDefault;
2949
3407
  return (arg) => {
2950
3408
  const { lastCallTime, lastCallArg } = map.get(fn) || {
2951
3409
  lastCallTime: 0,
@@ -2966,339 +3424,172 @@ function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject2) {
2966
3424
  }
2967
3425
 
2968
3426
  // src/components/DataSource/state/getInitialState.ts
3427
+ var defaultCursorId = Symbol("cursorId");
2969
3428
  function initSetupState2() {
2970
3429
  const now = Date.now();
2971
3430
  const originalDataArray = [];
2972
3431
  const dataArray = [];
3432
+ const originalLazyGroupData = new DeepMap();
2973
3433
  return {
2974
3434
  dataParams: void 0,
2975
3435
  notifyScrollbarsChange: buildSubscriptionCallback(),
3436
+ notifyScrollStop: buildSubscriptionCallback(),
2976
3437
  pivotTotalColumnPosition: "end",
2977
- originalDataArray,
2978
- scrollBottomId: Symbol("scrollBottomId"),
2979
- showSeparatePivotColumnForSingleAggregation: false,
2980
- pivotColumns: void 0,
2981
- pivotColumnGroups: void 0,
2982
- dataArray,
2983
- updatedAt: now,
2984
- groupedAt: 0,
2985
- sortedAt: 0,
2986
- reducedAt: now,
2987
- generateGroupRows: true,
2988
- groupDeepMap: void 0,
2989
- postSortDataArray: void 0,
2990
- postGroupDataArray: void 0,
2991
- lastSortDataArray: void 0,
2992
- lastGroupDataArray: void 0
2993
- };
2994
- }
2995
- function getCompareObject(dataParams) {
2996
- const obj = __spreadValues({}, dataParams);
2997
- delete obj.originalDataArray;
2998
- return obj;
2999
- }
3000
- var forwardProps3 = () => {
3001
- return {
3002
- onDataParamsChange: (fn) => fn ? discardCallsWithEqualArg(fn, 100, getCompareObject) : void 0,
3003
- data: 1,
3004
- pivotBy: 1,
3005
- primaryKey: 1,
3006
- livePagination: 1,
3007
- livePaginationCursor: 1,
3008
- aggregationReducers: 1,
3009
- loading: (loading) => loading != null ? loading : false,
3010
- sortInfo: (sortInfo) => normalizeSortInfo(sortInfo),
3011
- groupBy: (groupBy) => groupBy != null ? groupBy : [],
3012
- groupRowsState: (groupRowsState) => {
3013
- return groupRowsState || new GroupRowsState({
3014
- expandedRows: true,
3015
- collapsedRows: []
3016
- });
3017
- }
3018
- };
3019
- };
3020
- function mapPropsToState2(params) {
3021
- const { props } = params;
3022
- const controlledSort = isControlledValue(props.sortInfo);
3023
- return {
3024
- controlledSort,
3025
- multiSort: Array.isArray(controlledSort ? props.sortInfo : props.defaultSortInfo)
3026
- };
3027
- }
3028
- function getInterceptActions() {
3029
- return {
3030
- sortInfo: (sortInfo, { actions, state }) => {
3031
- const dataParams = buildDataSourceDataParams(state);
3032
- dataParams.sortInfo = sortInfo;
3033
- actions.dataParams = dataParams;
3034
- }
3035
- };
3036
- }
3037
-
3038
- // src/utils/groupAndPivot/index.ts
3039
- function DEFAULT_TO_KEY(value) {
3040
- return value;
3041
- }
3042
- function initReducers(reducers) {
3043
- if (!reducers || !Object.keys(reducers).length) {
3044
- return {};
3045
- }
3046
- const result = {};
3047
- for (let key in reducers)
3048
- if (reducers.hasOwnProperty(key)) {
3049
- result[key] = reducers[key].initialValue;
3050
- }
3051
- return result;
3052
- }
3053
- function computeReducersFor(data, reducers, reducerResults) {
3054
- var _a, _b;
3055
- if (!reducers || !Object.keys(reducers).length) {
3056
- return;
3057
- }
3058
- for (let key in reducers)
3059
- if (reducers.hasOwnProperty(key)) {
3060
- const reducer = reducers[key];
3061
- const currentValue = reducerResults[key];
3062
- const value = reducer.field ? data[reducer.field] : (_b = (_a = reducer.getter) == null ? void 0 : _a.call(reducer, data)) != null ? _b : null;
3063
- reducerResults[key] = reducer.reducer(currentValue, value, data);
3064
- }
3065
- }
3066
- function group(groupParams, data) {
3067
- const {
3068
- groupBy,
3069
- defaultToKey = DEFAULT_TO_KEY,
3070
- pivot,
3071
- reducers
3072
- } = groupParams;
3073
- const groupByLength = groupBy.length;
3074
- const topLevelPivotColumns = pivot ? new DeepMap() : void 0;
3075
- const deepMap = new DeepMap();
3076
- let currentGroupKeys = [];
3077
- let currentPivotKeys = [];
3078
- const initialReducerValue = initReducers(reducers);
3079
- const globalReducerResults = __spreadValues({}, initialReducerValue);
3080
- for (let i = 0, len = data.length; i < len; i++) {
3081
- let item = data[i];
3082
- for (let groupByIndex = 0; groupByIndex < groupByLength; groupByIndex++) {
3083
- const { field: groupByProperty, toKey: groupToKey } = groupBy[groupByIndex];
3084
- const key = (groupToKey || defaultToKey)(item[groupByProperty], item);
3085
- currentGroupKeys.push(key);
3086
- if (!deepMap.has(currentGroupKeys)) {
3087
- const deepMapGroupValue = {
3088
- items: [],
3089
- reducerResults: __spreadValues({}, initialReducerValue)
3090
- };
3091
- if (pivot) {
3092
- deepMapGroupValue.pivotDeepMap = new DeepMap();
3093
- }
3094
- deepMap.set(currentGroupKeys, deepMapGroupValue);
3095
- }
3096
- const {
3097
- items: currentGroupItems,
3098
- reducerResults,
3099
- pivotDeepMap
3100
- } = deepMap.get(currentGroupKeys);
3101
- currentGroupItems.push(item);
3102
- if (reducers) {
3103
- computeReducersFor(item, reducers, reducerResults);
3104
- }
3105
- if (pivot) {
3106
- for (let pivotIndex = 0, pivotLength = pivot.length; pivotIndex < pivotLength; pivotIndex++) {
3107
- const { field: pivotField, toKey: pivotToKey } = pivot[pivotIndex];
3108
- const pivotKey = (pivotToKey || defaultToKey)(item[pivotField], item);
3109
- currentPivotKeys.push(pivotKey);
3110
- if (!pivotDeepMap.has(currentPivotKeys)) {
3111
- topLevelPivotColumns.set(currentPivotKeys, true);
3112
- pivotDeepMap == null ? void 0 : pivotDeepMap.set(currentPivotKeys, {
3113
- reducerResults: __spreadValues({}, initialReducerValue),
3114
- items: []
3115
- });
3116
- }
3117
- const {
3118
- reducerResults: pivotReducerResults,
3119
- items: pivotGroupItems
3120
- } = pivotDeepMap.get(currentPivotKeys);
3121
- pivotGroupItems.push(item);
3122
- if (reducers) {
3123
- computeReducersFor(item, reducers, pivotReducerResults);
3124
- }
3125
- }
3126
- currentPivotKeys.length = 0;
3127
- }
3128
- }
3129
- if (reducers) {
3130
- computeReducersFor(item, reducers, globalReducerResults);
3438
+ originalLazyGroupData,
3439
+ originalDataArray,
3440
+ cursorId: defaultCursorId,
3441
+ showSeparatePivotColumnForSingleAggregation: false,
3442
+ propsCache: new Map([
3443
+ ["sortInfo", new WeakMap()]
3444
+ ]),
3445
+ pivotMappings: void 0,
3446
+ pivotColumns: void 0,
3447
+ pivotColumnGroups: void 0,
3448
+ dataArray,
3449
+ updatedAt: now,
3450
+ groupedAt: 0,
3451
+ sortedAt: 0,
3452
+ reducedAt: now,
3453
+ generateGroupRows: true,
3454
+ groupDeepMap: void 0,
3455
+ postSortDataArray: void 0,
3456
+ postGroupDataArray: void 0,
3457
+ lastSortDataArray: void 0,
3458
+ lastGroupDataArray: void 0
3459
+ };
3460
+ }
3461
+ function getCompareObjectForDataParams(dataParams) {
3462
+ const obj = __spreadValues({}, dataParams);
3463
+ delete obj.originalDataArray;
3464
+ return obj;
3465
+ }
3466
+ var forwardProps3 = (setupState) => {
3467
+ return {
3468
+ onDataParamsChange: (fn) => fn ? discardCallsWithEqualArg(fn, 100, getCompareObjectForDataParams) : void 0,
3469
+ fullLazyLoad: 1,
3470
+ data: 1,
3471
+ pivotBy: 1,
3472
+ primaryKey: 1,
3473
+ livePagination: 1,
3474
+ lazyLoadBatchSize: (lazyLoadBatchSize) => lazyLoadBatchSize != null ? lazyLoadBatchSize : -1,
3475
+ aggregationReducers: 1,
3476
+ collapseGroupRowsOnDataFunctionChange: (collapseGroupRowsOnDataFunctionChange) => collapseGroupRowsOnDataFunctionChange != null ? collapseGroupRowsOnDataFunctionChange : true,
3477
+ loading: (loading) => loading != null ? loading : false,
3478
+ sortInfo: (sortInfo) => normalizeSortInfo(sortInfo, setupState.propsCache.get("sortInfo")),
3479
+ groupBy: (groupBy) => groupBy != null ? groupBy : [],
3480
+ groupRowsState: (groupRowsState) => {
3481
+ return groupRowsState || new GroupRowsState({
3482
+ expandedRows: true,
3483
+ collapsedRows: []
3484
+ });
3131
3485
  }
3132
- currentGroupKeys.length = 0;
3133
- }
3134
- if (reducers) {
3135
- deepMap.visitDepthFirst((deepMapValue, _keys, _indexInGroup, next) => {
3136
- completeReducers(reducers, deepMapValue.reducerResults, deepMapValue.items);
3137
- if (pivot) {
3138
- deepMapValue.pivotDeepMap.visitDepthFirst(({ items, reducerResults: pivotReducerResults }, _keys2, _indexInGroup2, next2) => {
3139
- completeReducers(reducers, pivotReducerResults, items);
3140
- next2 == null ? void 0 : next2();
3141
- });
3142
- }
3143
- next == null ? void 0 : next();
3144
- });
3145
- }
3146
- if (reducers) {
3147
- completeReducers(reducers, globalReducerResults, data);
3148
- }
3486
+ };
3487
+ };
3488
+ function getLivePaginationCursorValue(livePaginationCursorProp, state) {
3489
+ const livePaginationCursor = typeof livePaginationCursorProp === "function" ? livePaginationCursorProp({
3490
+ array: state.originalDataArray,
3491
+ length: state.originalDataArray.length,
3492
+ lastItem: state.originalDataArray[state.originalDataArray.length - 1]
3493
+ }) : livePaginationCursorProp;
3494
+ return livePaginationCursor;
3495
+ }
3496
+ function mapPropsToState2(params) {
3497
+ const { props, state, oldState } = params;
3498
+ const controlledSort = isControlledValue(props.sortInfo);
3149
3499
  const result = {
3150
- deepMap,
3151
- groupParams,
3152
- initialData: data,
3153
- reducerResults: globalReducerResults
3500
+ controlledSort,
3501
+ multiSort: Array.isArray(controlledSort ? props.sortInfo : props.defaultSortInfo)
3154
3502
  };
3155
- if (pivot) {
3156
- result.topLevelPivotColumns = topLevelPivotColumns;
3157
- result.pivot = pivot;
3503
+ if (props.livePagination) {
3504
+ const dataArrayChanged = !oldState || oldState.originalDataArray !== state.originalDataArray;
3505
+ const livePaginationCursor = typeof props.livePaginationCursor === "function" ? dataArrayChanged ? getLivePaginationCursorValue(props.livePaginationCursor, state) : state.livePaginationCursor : props.livePaginationCursor;
3506
+ result.livePaginationCursor = livePaginationCursor;
3158
3507
  }
3159
3508
  return result;
3160
3509
  }
3161
- function flatten(groupResult) {
3162
- const { groupParams, deepMap } = groupResult;
3163
- const groupByLength = groupParams.groupBy.length;
3164
- const result = [];
3165
- deepMap.topDownKeys().reduce((acc, key) => {
3166
- if (key.length === groupByLength) {
3167
- const items = deepMap.get(key).items;
3168
- acc.push(...items);
3510
+ var debugFullLazyLoad = dbg("DataSource:fullLazyLoad");
3511
+ function onPropChange(params, props, actions) {
3512
+ const { name, newValue } = params;
3513
+ if (name === "data" && typeof newValue === "function" && !props.groupRowsState) {
3514
+ if (props.fullLazyLoad) {
3515
+ debugFullLazyLoad(`"data" function prop has changed`);
3516
+ }
3517
+ if (props.collapseGroupRowsOnDataFunctionChange !== false) {
3518
+ actions.groupRowsState = new GroupRowsState({
3519
+ collapsedRows: true,
3520
+ expandedRows: []
3521
+ });
3169
3522
  }
3170
- return acc;
3171
- }, result);
3172
- return result;
3173
- }
3174
- function getEnhancedGroupData(options, deepMapValue) {
3175
- const { groupBy, groupKeys, collapsed, parents, reducers } = options;
3176
- const groupNesting = groupKeys.length;
3177
- const { items: groupItems, reducerResults, pivotDeepMap } = deepMapValue;
3178
- let data = null;
3179
- if (Object.keys(reducerResults).length > 0) {
3180
- data = {};
3181
- for (let key in reducers)
3182
- if (reducers.hasOwnProperty(key)) {
3183
- const reducer = reducers[key];
3184
- const field = reducer.field;
3185
- if (field) {
3186
- data[field] = reducerResults[key];
3187
- }
3188
- }
3189
3523
  }
3190
- const enhancedGroupData = {
3191
- data,
3192
- groupCount: groupItems.length,
3193
- groupData: groupItems,
3194
- groupKeys,
3195
- id: groupKeys,
3196
- collapsed,
3197
- parents,
3198
- collapsedChildrenCount: 0,
3199
- collapsedGroupsCount: 0,
3200
- indexInParentGroups: options.indexInParentGroups,
3201
- indexInGroup: options.indexInGroup,
3202
- indexInAll: options.indexInAll,
3203
- value: groupKeys[groupKeys.length - 1],
3204
- groupBy: groupBy.slice(0, groupNesting),
3205
- isGroupRow: true,
3206
- pivotValuesMap: pivotDeepMap,
3207
- groupNesting,
3208
- reducerResults
3209
- };
3210
- return enhancedGroupData;
3211
3524
  }
3212
- function completeReducers(reducers, reducerResults, items) {
3213
- if (reducers) {
3214
- for (let key in reducers)
3215
- if (reducers.hasOwnProperty(key)) {
3216
- const reducer = reducers[key];
3217
- if (reducer.done) {
3218
- reducerResults[key] = reducer.done(reducerResults[key], items);
3219
- }
3525
+ var debugDataParams = dbg("DataSource:dataParams");
3526
+ function getInterceptActions() {
3527
+ return {
3528
+ sortInfo: (sortInfo, { actions, state }) => {
3529
+ const dataParams = buildDataSourceDataParams(state, {
3530
+ sortInfo,
3531
+ livePaginationCursor: null
3532
+ });
3533
+ actions.dataParams = dataParams;
3534
+ if (state.livePagination) {
3535
+ requestAnimationFrame(() => {
3536
+ actions.livePaginationCursor = null;
3537
+ });
3220
3538
  }
3221
- }
3222
- return reducerResults;
3223
- }
3224
- function enhancedFlatten(param) {
3225
- const {
3226
- groupResult,
3227
- toPrimaryKey,
3228
- groupRowsState,
3229
- generateGroupRows,
3230
- reducers = {}
3231
- } = param;
3232
- const { groupParams, deepMap, pivot } = groupResult;
3233
- const { groupBy } = groupParams;
3234
- const groupByStrings = groupBy.map((g) => g.field);
3235
- const result = [];
3236
- const parents = [];
3237
- const indexInParentGroups = [];
3238
- deepMap.visitDepthFirst((deepMapValue, groupKeys, indexInGroup, next) => {
3239
- var _a;
3240
- const items = deepMapValue.items;
3241
- const groupNesting = groupKeys.length;
3242
- const collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
3243
- const enhancedGroupData = getEnhancedGroupData({
3244
- groupBy: groupByStrings,
3245
- parents: Array.from(parents),
3246
- reducers,
3247
- indexInGroup,
3248
- indexInParentGroups: Array.from(indexInParentGroups),
3249
- indexInAll: result.length,
3250
- groupKeys,
3251
- collapsed
3252
- }, deepMapValue);
3253
- const include = generateGroupRows || collapsed;
3254
- if (include) {
3255
- result.push(enhancedGroupData);
3256
- }
3257
- if (collapsed) {
3258
- parents.forEach((parent) => {
3259
- parent.collapsedChildrenCount += enhancedGroupData.groupCount;
3260
- parent.collapsedGroupsCount += 1;
3539
+ },
3540
+ groupBy: (groupBy, { actions, state }) => {
3541
+ const dataParams = buildDataSourceDataParams(state, {
3542
+ groupBy,
3543
+ livePaginationCursor: null
3261
3544
  });
3262
- }
3263
- indexInParentGroups.push(indexInGroup);
3264
- parents.push(enhancedGroupData);
3265
- if (!collapsed) {
3266
- if (!next) {
3267
- if (!pivot) {
3268
- const startIndex = result.length;
3269
- result.push(...items.map((item, index) => {
3270
- return {
3271
- id: toPrimaryKey(item),
3272
- data: item,
3273
- isGroupRow: false,
3274
- collapsed: false,
3275
- groupKeys,
3276
- parents: Array.from(parents),
3277
- indexInParentGroups: [...indexInParentGroups, index],
3278
- indexInGroup: index,
3279
- indexInAll: startIndex + index,
3280
- groupBy: groupByStrings,
3281
- groupNesting,
3282
- groupCount: enhancedGroupData.groupCount
3283
- };
3284
- }));
3285
- }
3286
- } else {
3287
- next();
3545
+ actions.dataParams = dataParams;
3546
+ if (state.livePagination) {
3547
+ requestAnimationFrame(() => {
3548
+ actions.livePaginationCursor = null;
3549
+ });
3550
+ }
3551
+ },
3552
+ pivotBy: (pivotBy, { actions, state }) => {
3553
+ const dataParams = buildDataSourceDataParams(state, {
3554
+ pivotBy,
3555
+ livePaginationCursor: null
3556
+ });
3557
+ actions.dataParams = dataParams;
3558
+ if (state.livePagination) {
3559
+ requestAnimationFrame(() => {
3560
+ actions.livePaginationCursor = null;
3561
+ });
3562
+ }
3563
+ },
3564
+ cursorId: (cursorId, { actions, state }) => {
3565
+ const dataParams = buildDataSourceDataParams(state, {
3566
+ cursorId
3567
+ });
3568
+ actions.dataParams = dataParams;
3569
+ },
3570
+ livePaginationCursor: (livePaginationCursor, { actions, state }) => {
3571
+ const dataParams = buildDataSourceDataParams(state, {
3572
+ livePaginationCursor
3573
+ });
3574
+ actions.dataParams = dataParams;
3575
+ },
3576
+ dataParams: (dataParams, { state }) => {
3577
+ if (shallowEqualObjects(dataParams, state.dataParams, new Set([
3578
+ "changes",
3579
+ "originalDataArray"
3580
+ ]))) {
3581
+ return false;
3288
3582
  }
3583
+ debugDataParams("onDataParamsChange triggered because the following values have changed", dataParams == null ? void 0 : dataParams.changes);
3584
+ return true;
3289
3585
  }
3290
- parents.pop();
3291
- indexInParentGroups.pop();
3292
- });
3293
- return {
3294
- data: result
3295
3586
  };
3296
3587
  }
3297
3588
 
3298
3589
  // src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts
3299
3590
  function prepareColumn(column) {
3300
3591
  const { pivotByAtIndex: pivotByForColumn } = column;
3301
- if (pivotByForColumn.column) {
3592
+ if (pivotByForColumn == null ? void 0 : pivotByForColumn.column) {
3302
3593
  if (typeof pivotByForColumn.column === "function") {
3303
3594
  Object.assign(column, pivotByForColumn.column({ column }));
3304
3595
  } else {
@@ -3309,7 +3600,7 @@ function prepareColumn(column) {
3309
3600
  }
3310
3601
  function prepareColumnGroup(columnGroup) {
3311
3602
  const { pivotByAtIndex: pivotByForColumnGroup } = columnGroup;
3312
- if (pivotByForColumnGroup.columnGroup) {
3603
+ if (pivotByForColumnGroup == null ? void 0 : pivotByForColumnGroup.columnGroup) {
3313
3604
  if (typeof pivotByForColumnGroup.columnGroup === "function") {
3314
3605
  Object.assign(columnGroup, pivotByForColumnGroup.columnGroup({ columnGroup }));
3315
3606
  } else {
@@ -3338,6 +3629,9 @@ function getPivotColumnsAndColumnGroups({
3338
3629
  valueGetter: (params) => {
3339
3630
  var _a;
3340
3631
  const { rowInfo } = params;
3632
+ if (!rowInfo.data) {
3633
+ return "Loading ... TODO replace this with a loading indicator";
3634
+ }
3341
3635
  return rowInfo.groupKeys ? rowInfo.groupKeys[((_a = rowInfo.groupKeys) == null ? void 0 : _a.length) - 1] : null;
3342
3636
  }
3343
3637
  }
@@ -3369,7 +3663,7 @@ function getPivotColumnsAndColumnGroups({
3369
3663
  }));
3370
3664
  }
3371
3665
  aggregationReducers.forEach((reducer, index) => {
3372
- const header = isSingleAggregationColumn ? keys[keys.length - 1] : reducer.id;
3666
+ const header = isSingleAggregationColumn ? keys[keys.length - 1] : reducer.name || reducer.id;
3373
3667
  const computedPivotColumn = prepareColumn({
3374
3668
  pivotBy,
3375
3669
  pivotColumn: true,
@@ -3388,7 +3682,7 @@ function getPivotColumnsAndColumnGroups({
3388
3682
  return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
3389
3683
  }
3390
3684
  });
3391
- const columnId = `${keys.join("/")}-${reducer.id}`;
3685
+ const columnId = `${reducer.id}:${keys.join("/")}`;
3392
3686
  columns.set(columnId, computedPivotColumn);
3393
3687
  });
3394
3688
  } else {
@@ -3421,7 +3715,7 @@ function getPivotColumnsAndColumnGroups({
3421
3715
  }));
3422
3716
  }
3423
3717
  aggregationReducers.forEach((reducer, index) => {
3424
- const header = isSingleAggregationColumn ? `${keys[keys.length - 1]} total ` : `${reducer.id} total`;
3718
+ const header = isSingleAggregationColumn ? `${keys[keys.length - 1]} total ` : `${reducer.name || reducer.id} total`;
3425
3719
  const computedPivotColumn = prepareColumn({
3426
3720
  columnGroup: columnGroupId,
3427
3721
  header,
@@ -3440,7 +3734,7 @@ function getPivotColumnsAndColumnGroups({
3440
3734
  return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
3441
3735
  }
3442
3736
  });
3443
- columns.set(`total:${keys.join("/")}-${reducer.id}`, computedPivotColumn);
3737
+ columns.set(`total:${reducer.id}:${keys.join("/")}`, computedPivotColumn);
3444
3738
  });
3445
3739
  }
3446
3740
  }
@@ -3449,15 +3743,22 @@ function getPivotColumnsAndColumnGroups({
3449
3743
  }
3450
3744
  });
3451
3745
  if (columns.size === 1) {
3452
- columns.set("single", {
3453
- header: "Reduced",
3454
- pivotBy,
3455
- pivotColumn: true,
3456
- valueGetter: ({ rowInfo }) => {
3457
- var _a;
3458
- const key = Object.keys(rowInfo.reducerResults || {})[0];
3459
- return (_a = rowInfo.reducerResults) == null ? void 0 : _a[key];
3460
- }
3746
+ aggregationReducers.forEach((reducer, index) => {
3747
+ columns.set(`total:${reducer.id}`, prepareColumn({
3748
+ header: `${reducer.name || reducer.id} total`,
3749
+ pivotBy,
3750
+ pivotColumn: true,
3751
+ pivotTotalColumn: true,
3752
+ pivotAggregator: reducer,
3753
+ pivotAggregatorIndex: index,
3754
+ pivotGroupKeys: [],
3755
+ pivotGroupKey: "",
3756
+ pivotIndex: -1,
3757
+ valueGetter: ({ rowInfo }) => {
3758
+ var _a;
3759
+ return (_a = rowInfo.reducerResults) == null ? void 0 : _a[reducer.id];
3760
+ }
3761
+ }));
3461
3762
  });
3462
3763
  }
3463
3764
  const result = {
@@ -3494,10 +3795,11 @@ function concludeReducer(params) {
3494
3795
  const { state, previousState } = params;
3495
3796
  const sortInfo = state.sortInfo;
3496
3797
  const shouldSort = !!(sortInfo == null ? void 0 : sortInfo.length) && !state.controlledSort;
3497
- const sortDepsChanged = haveDepsChanged(previousState, state, [
3498
- "originalDataArray",
3499
- "sortInfo"
3798
+ const originalDataArrayChanged = haveDepsChanged(previousState, state, [
3799
+ "originalDataArray"
3500
3800
  ]);
3801
+ const sortInfoChanged = haveDepsChanged(previousState, state, ["sortInfo"]);
3802
+ const sortDepsChanged = originalDataArrayChanged || sortInfoChanged;
3501
3803
  const shouldSortAgain = shouldSort && (sortDepsChanged || !state.lastSortDataArray);
3502
3804
  const groupBy = state.groupBy;
3503
3805
  const pivotBy = state.pivotBy;
@@ -3505,6 +3807,7 @@ function concludeReducer(params) {
3505
3807
  const groupsDepsChanged = haveDepsChanged(previousState, state, [
3506
3808
  "generateGroupRows",
3507
3809
  "originalDataArray",
3810
+ "originalLazyGroupData",
3508
3811
  "groupBy",
3509
3812
  "groupRowsState",
3510
3813
  "pivotBy",
@@ -3529,7 +3832,12 @@ function concludeReducer(params) {
3529
3832
  };
3530
3833
  if (shouldGroup) {
3531
3834
  if (shouldGroupAgain) {
3532
- const groupResult = group({
3835
+ const groupResult = state.fullLazyLoad ? lazyGroup({
3836
+ groupBy,
3837
+ pivot: pivotBy,
3838
+ mappings: state.pivotMappings,
3839
+ reducers: state.aggregationReducers
3840
+ }, state.originalLazyGroupData) : group({
3533
3841
  groupBy,
3534
3842
  pivot: pivotBy,
3535
3843
  reducers: state.aggregationReducers
@@ -3597,6 +3905,7 @@ var DataSourceRoot = getComponentStateRoot({
3597
3905
  forwardProps: forwardProps3,
3598
3906
  concludeReducer,
3599
3907
  mapPropsToState: mapPropsToState2,
3908
+ onPropChange,
3600
3909
  interceptActions: getInterceptActions()
3601
3910
  });
3602
3911
  function DataSourceCmp({ children }) {
@@ -3628,16 +3937,22 @@ function DataSource(props) {
3628
3937
  function useToggleGroupRow() {
3629
3938
  const { getState: getDataSourceState, componentActions: dataSourceActions } = useDataSourceContextValue();
3630
3939
  const toggleGroupRow = useCallback4((groupKeys) => {
3631
- const newState = new GroupRowsState(getDataSourceState().groupRowsState);
3940
+ const state = getDataSourceState();
3941
+ const newState = new GroupRowsState(state.groupRowsState);
3632
3942
  newState.toggleGroupRow(groupKeys);
3633
3943
  dataSourceActions.groupRowsState = newState;
3944
+ if (state.fullLazyLoad && newState.isGroupRowExpanded(groupKeys)) {
3945
+ loadData(state.data, state, dataSourceActions, {
3946
+ groupKeys
3947
+ });
3948
+ }
3634
3949
  }, []);
3635
3950
  return toggleGroupRow;
3636
3951
  }
3637
3952
 
3638
3953
  // src/components/InfiniteTable/hooks/useColumnsWhen.ts
3639
3954
  function useGroupByMap(groupBy) {
3640
- const groupByMap = useMemo5(() => {
3955
+ const groupByMap = useMemo4(() => {
3641
3956
  return groupBy.reduce((acc, groupBy2, index) => {
3642
3957
  acc.set(groupBy2.field, {
3643
3958
  groupBy: groupBy2,
@@ -3825,7 +4140,7 @@ function useHideEmptyGroupColumns(groupRowsMap) {
3825
4140
  const currentState = getComponentState();
3826
4141
  const { computedColumns } = currentState;
3827
4142
  let updated = false;
3828
- const columnVisibility = new Map(currentState.columnVisibility);
4143
+ const columnVisibility = __spreadValues({}, currentState.columnVisibility);
3829
4144
  const cols = computedColumns;
3830
4145
  groupBy.forEach(({ field, column: groupColumn }, index) => {
3831
4146
  const colId = (groupColumn == null ? void 0 : groupColumn.id) || `group-by-${field}`;
@@ -3836,9 +4151,9 @@ function useHideEmptyGroupColumns(groupRowsMap) {
3836
4151
  const shouldBeHidden = index > expandedGroupsLevel && hideEmptyGroupColumns;
3837
4152
  updated = true;
3838
4153
  if (shouldBeHidden) {
3839
- columnVisibility.set(colId, false);
4154
+ columnVisibility[colId] = false;
3840
4155
  } else {
3841
- columnVisibility.delete(colId);
4156
+ delete columnVisibility[colId];
3842
4157
  }
3843
4158
  });
3844
4159
  if (updated) {
@@ -3901,7 +4216,8 @@ function useComputed() {
3901
4216
  const { componentActions, componentState } = useComponentState();
3902
4217
  const {
3903
4218
  componentActions: dataSourceActions,
3904
- componentState: dataSourceState
4219
+ componentState: dataSourceState,
4220
+ getState: getDataSourceState
3905
4221
  } = useDataSourceContextValue();
3906
4222
  const {
3907
4223
  columnOrder,
@@ -3934,7 +4250,7 @@ function useComputed() {
3934
4250
  var _a2;
3935
4251
  const newSortInfo = multiSort ? sortInfo : (_a2 = sortInfo[0]) != null ? _a2 : null;
3936
4252
  dataSourceActions.sortInfo = newSortInfo;
3937
- }, []);
4253
+ }, [getDataSourceState]);
3938
4254
  const columns = componentState.computedColumns;
3939
4255
  const {
3940
4256
  computedColumnOrder,
@@ -4188,7 +4504,7 @@ var InfiniteTableCell = memo3(InfiniteTableCellFn);
4188
4504
  var import_binary_search = __toModule(require_binary_search());
4189
4505
  import {
4190
4506
  useCallback as useCallback6,
4191
- useMemo as useMemo6,
4507
+ useMemo as useMemo5,
4192
4508
  useRef as useRef7,
4193
4509
  useState as useState6
4194
4510
  } from "react";
@@ -4235,8 +4551,8 @@ var useColumnPointerEvents = ({
4235
4551
  const dragging = draggingDiff != null;
4236
4552
  const { componentActions, computed } = useInfiniteTable();
4237
4553
  const { computedColumnOrder } = computed;
4238
- const column = useMemo6(() => columns.get(columnId), [columnId, columns]);
4239
- const { columnIndex, columnWidth, columnsArray } = useMemo6(() => {
4554
+ const column = useMemo5(() => columns.get(columnId), [columnId, columns]);
4555
+ const { columnIndex, columnWidth, columnsArray } = useMemo5(() => {
4240
4556
  const columnsArray2 = Array.from(columns.values());
4241
4557
  return {
4242
4558
  columnsArray: columnsArray2,
@@ -4559,10 +4875,10 @@ import {
4559
4875
  createElement as createElement12,
4560
4876
  memo as memo4
4561
4877
  } from "react";
4562
- import { useLayoutEffect as useLayoutEffect4, useState as useState8 } from "react";
4878
+ import { useLayoutEffect as useLayoutEffect3, useState as useState8 } from "react";
4563
4879
  function AvoidReactDiffFn(props) {
4564
4880
  const [children, setChildren] = useState8(props.updater.get());
4565
- useLayoutEffect4(() => {
4881
+ useLayoutEffect3(() => {
4566
4882
  const remove = props.updater.onChange((children2) => {
4567
4883
  setChildren(children2);
4568
4884
  });
@@ -4573,7 +4889,7 @@ function AvoidReactDiffFn(props) {
4573
4889
  var AvoidReactDiff = memo4(AvoidReactDiffFn);
4574
4890
 
4575
4891
  // src/components/RawList/useVirtualRenderer.ts
4576
- import { useMemo as useMemo7 } from "react";
4892
+ import { useMemo as useMemo6 } from "react";
4577
4893
 
4578
4894
  // src/components/RawList/ReactVirtualRenderer.tsx
4579
4895
  import {
@@ -4889,7 +5205,7 @@ function createRenderer(brain) {
4889
5205
  function useVirtualRenderer({
4890
5206
  brain
4891
5207
  }) {
4892
- return useMemo7(() => {
5208
+ return useMemo6(() => {
4893
5209
  return createRenderer(brain);
4894
5210
  }, [brain]);
4895
5211
  }
@@ -4981,7 +5297,7 @@ var InfiniteTableHeader = memo6(InfiniteTableHeaderFn);
4981
5297
  import {
4982
5298
  createElement as createElement18,
4983
5299
  memo as memo7,
4984
- useMemo as useMemo8,
5300
+ useMemo as useMemo7,
4985
5301
  useRef as useRef10
4986
5302
  } from "react";
4987
5303
 
@@ -5195,7 +5511,7 @@ function InfiniteTableHeaderUnvirtualizedFn(props) {
5195
5511
  } = useInfiniteTable();
5196
5512
  const domRef = useRef10(null);
5197
5513
  const hasColumnGroups = computedColumnGroups.size > 0;
5198
- const columnHeaderGroups = useMemo8(() => {
5514
+ const columnHeaderGroups = useMemo7(() => {
5199
5515
  return hasColumnGroups ? renderColumnHeaderGroups({
5200
5516
  columnGroups: computedColumnGroups,
5201
5517
  columnGroupsDepthsMap,
@@ -5280,6 +5596,9 @@ function TableHeaderWrapper(props) {
5280
5596
  const hasPinnedStart = computedPinnedStartColumns.length > 0;
5281
5597
  const hasPinnedEnd = computedPinnedEndColumns.length > 0;
5282
5598
  const height = columnGroupsMaxDepth ? columnGroupsMaxDepth * headerHeight : headerHeight;
5599
+ const unvirtualizedStyle = !virtualizeHeader && computedPinnedStartColumnsWidth ? {
5600
+ left: computedPinnedStartWidth
5601
+ } : void 0;
5283
5602
  const header = virtualizeHeader ? /* @__PURE__ */ createElement19(InfiniteTableHeader, {
5284
5603
  columns: computedUnpinnedColumns,
5285
5604
  repaintId: virtualizeHeader ? repaintId : void 0,
@@ -5294,6 +5613,7 @@ function TableHeaderWrapper(props) {
5294
5613
  availableWidth: computedUnpinnedColumnsWidth,
5295
5614
  totalWidth: computedUnpinnedColumnsWidth
5296
5615
  }) : /* @__PURE__ */ createElement19(InfiniteTableHeaderUnvirtualized, {
5616
+ style: unvirtualizedStyle,
5297
5617
  brain,
5298
5618
  scrollable: true,
5299
5619
  pinning: false,
@@ -6000,7 +6320,6 @@ var PinnedRowsClsVariants = { pinnedStart: "_1yeub2ve", pinnedEnd: "_1yeub2vf",
6000
6320
  var PinnedRowsContainerClsVariants = (0, import_createRuntimeFn5.createRuntimeFn)({ defaultClassName: "", variantClassNames: { pinned: { start: "_1yeub2vh", end: "_1yeub2vi", false: "_1yeub2vj" } }, defaultVariants: {}, compoundVariants: [] });
6001
6321
 
6002
6322
  // src/components/InfiniteTable/hooks/useOnContainerScroll.ts
6003
- var DELAY = 200;
6004
6323
  var TableClassName = internalProps.rootClassName;
6005
6324
  var TableClassName__Scrolling = `${TableClassName}--scrolling`;
6006
6325
  var SCROLL_BOTTOM_OFFSET = 1;
@@ -6011,15 +6330,25 @@ var useOnContainerScroll = ({
6011
6330
  }) => {
6012
6331
  const {
6013
6332
  componentState: {
6333
+ scrollStopDelay,
6014
6334
  scrollerDOMRef,
6015
6335
  domRef,
6016
6336
  scrollToBottomOffset,
6017
6337
  onScrollToBottom,
6018
6338
  onScrollToTop,
6339
+ onScrollStop: onScrollStopFromProps,
6019
6340
  bodySize
6020
6341
  }
6021
6342
  } = useInfiniteTable();
6022
- const { componentActions: dataSourceActions, getState: getDataSourceState } = useDataSourceContextValue();
6343
+ const {
6344
+ componentActions: dataSourceActions,
6345
+ getState: getDataSourceState,
6346
+ componentState: { notifyScrollStop }
6347
+ } = useDataSourceContextValue();
6348
+ const onScrollStop = useCallback13((param) => {
6349
+ onScrollStopFromProps == null ? void 0 : onScrollStopFromProps(param);
6350
+ notifyScrollStop(param);
6351
+ }, [onScrollStopFromProps, notifyScrollStop]);
6023
6352
  const timeoutIdRef = useRef15(0);
6024
6353
  const scrollingRef = useRef15(false);
6025
6354
  const scrollTopMaxRef = useRef15(0);
@@ -6038,9 +6367,17 @@ var useOnContainerScroll = ({
6038
6367
  timeoutIdRef.current = setTimeout(() => {
6039
6368
  setScrolling(false);
6040
6369
  timeoutIdRef.current = 0;
6041
- }, DELAY);
6370
+ }, scrollStopDelay);
6042
6371
  }
6043
6372
  if (prevScrolling !== scrolling) {
6373
+ if (!scrolling) {
6374
+ const range = verticalVirtualBrain.getRenderRange();
6375
+ onScrollStop({
6376
+ scrollTop: scrollPositionRef.current.scrollTop,
6377
+ firstVisibleRowIndex: range.renderStartIndex,
6378
+ lastVisibleRowIndex: range.renderEndIndex
6379
+ });
6380
+ }
6044
6381
  const classList = (_a = domRef.current) == null ? void 0 : _a.classList;
6045
6382
  if (!classList) {
6046
6383
  return;
@@ -6051,7 +6388,7 @@ var useOnContainerScroll = ({
6051
6388
  classList.remove(InfiniteClsScrolling, TableClassName__Scrolling);
6052
6389
  }
6053
6390
  }
6054
- }, []);
6391
+ }, [scrollStopDelay, onScrollStop]);
6055
6392
  const onContainerScroll = useCallback13((scrollInfo) => {
6056
6393
  verticalVirtualBrain.setScrollPosition(scrollInfo);
6057
6394
  horizontalVirtualBrain.setScrollPosition(scrollInfo);
@@ -6081,7 +6418,7 @@ var useOnContainerScroll = ({
6081
6418
  if (isScrollBottom) {
6082
6419
  onScrollToBottom == null ? void 0 : onScrollToBottom();
6083
6420
  if (getDataSourceState().livePagination) {
6084
- dataSourceActions.scrollBottomId = Date.now();
6421
+ dataSourceActions.cursorId = Date.now();
6085
6422
  }
6086
6423
  }
6087
6424
  }, [onContainerScroll, scrollToBottomOffset, onScrollToBottom, onScrollToTop]);
@@ -6094,7 +6431,7 @@ var useOnContainerScroll = ({
6094
6431
  // src/components/InfiniteTable/hooks/usePinnedRendering.tsx
6095
6432
  import {
6096
6433
  createElement as createElement29,
6097
- useMemo as useMemo9
6434
+ useMemo as useMemo8
6098
6435
  } from "react";
6099
6436
  import { useCallback as useCallback15 } from "react";
6100
6437
 
@@ -6200,7 +6537,7 @@ function PinnedRowsContainer(props) {
6200
6537
  brain,
6201
6538
  renderRow
6202
6539
  } = props;
6203
- const style = useMemo9(() => {
6540
+ const style = useMemo8(() => {
6204
6541
  const result = pinning === "end" ? {
6205
6542
  width: rowWidth,
6206
6543
  height,
@@ -6373,6 +6710,15 @@ function usePinnedStartRendering(params) {
6373
6710
  // src/components/InfiniteTable/hooks/useYourBrain.ts
6374
6711
  import { useEffect as useEffect21 } from "react";
6375
6712
 
6713
+ // src/components/hooks/useOnce.ts
6714
+ import { useMemo as useMemo9 } from "react";
6715
+ function useOnce(fn) {
6716
+ const onceFn = useMemo9(() => {
6717
+ return once(fn);
6718
+ }, []);
6719
+ return onceFn();
6720
+ }
6721
+
6376
6722
  // src/components/VirtualBrain/index.ts
6377
6723
  var import_binary_search2 = __toModule(require_binary_search());
6378
6724
  var initialScrollPosition2 = {
@@ -7268,7 +7614,7 @@ var useLicense = (licenseKey = "") => {
7268
7614
  const valid = useMemo11(() => {
7269
7615
  let valid2 = isValidLicense(licenseKey, {
7270
7616
  publishedAt: 1624970570587,
7271
- version: "0.1.0"
7617
+ version: "0.1.4"
7272
7618
  });
7273
7619
  if (!licenseKey && !valid2 && isInsideSandbox) {
7274
7620
  return true;
@@ -7282,7 +7628,7 @@ var useLicense = (licenseKey = "") => {
7282
7628
  import {
7283
7629
  createElement as createElement31,
7284
7630
  useCallback as useCallback19,
7285
- useLayoutEffect as useLayoutEffect5
7631
+ useLayoutEffect as useLayoutEffect4
7286
7632
  } from "react";
7287
7633
  import { useRef as useRef19 } from "react";
7288
7634
  var error = err("CSSVariableWatch");
@@ -7305,7 +7651,7 @@ var useCSSVariableWatch = (params) => {
7305
7651
  }
7306
7652
  }, [params.onChange]);
7307
7653
  useResizeObserver(params.ref, onResize, { earlyAttach: true });
7308
- useLayoutEffect5(() => {
7654
+ useLayoutEffect4(() => {
7309
7655
  const value = params.ref.current.getBoundingClientRect().height;
7310
7656
  if (value) {
7311
7657
  lastValueRef.current = value;
@@ -7507,7 +7853,7 @@ var InfiniteTableComponent = memo13(function InfiniteTableComponent2() {
7507
7853
  const licenseValid = useLicense(licenseKey);
7508
7854
  const domProps = useDOMProps(componentState.domProps);
7509
7855
  const LoadMaskCmp = (_a = components == null ? void 0 : components.LoadMask) != null ? _a : LoadMask;
7510
- useLayoutEffect6(() => {
7856
+ useLayoutEffect5(() => {
7511
7857
  const dataSourceState = getDataSourceState();
7512
7858
  const { onScrollbarsChange } = getInfiniteTableState();
7513
7859
  const { notifyScrollbarsChange } = dataSourceState;
@@ -7613,5 +7959,6 @@ export {
7613
7959
  interceptMap,
7614
7960
  multisort,
7615
7961
  useComponentState,
7616
- useDataSource
7962
+ useDataSource,
7963
+ useEffectWithChanges
7617
7964
  };