@infinite-table/infinite-react 0.1.1 → 0.2.0

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) => {
@@ -1280,7 +1276,10 @@ var getComputedVisibleColumns = ({
1280
1276
  width: colType == null ? void 0 : colType.defaultWidth,
1281
1277
  flex: colType == null ? void 0 : colType.defaultFlex
1282
1278
  };
1283
- let colSizing = columnSizing.get(colId) || {};
1279
+ let colSizing = columnSizing.get(colId) || {
1280
+ width: column == null ? void 0 : column.defaultWidth,
1281
+ flex: column == null ? void 0 : column.defaultFlex
1282
+ };
1284
1283
  if (colSizing.width != null) {
1285
1284
  delete colTypeSizing.flex;
1286
1285
  }
@@ -1567,7 +1566,6 @@ var useComputedVisibleColumns = ({
1567
1566
  const columnsSizingRenderId = useRerenderOnKeyChange(columnSizing);
1568
1567
  const columnTypesRenderId = useRerenderOnKeyChange(columnTypes);
1569
1568
  const columnsRenderId = useRerenderOnKeyChange(columns);
1570
- const visibilityRenderId = useRerenderOnKeyChange(columnVisibility);
1571
1569
  const pinningRenderId = useRerenderOnKeyChange(columnPinning);
1572
1570
  const {
1573
1571
  computedRemainingSpace,
@@ -1623,7 +1621,6 @@ var useComputedVisibleColumns = ({
1623
1621
  pinnedStartMaxWidth,
1624
1622
  columnPinning,
1625
1623
  columnsRenderId,
1626
- visibilityRenderId,
1627
1624
  columnsSizingRenderId,
1628
1625
  pinningRenderId,
1629
1626
  columnTypesRenderId
@@ -1648,7 +1645,7 @@ var useComputedVisibleColumns = ({
1648
1645
  return result;
1649
1646
  };
1650
1647
 
1651
- // src/utils/sortAscending.ts
1648
+ // src/utils/DeepMap/sortAscending.ts
1652
1649
  var sortAscending = (a, b) => a - b;
1653
1650
 
1654
1651
  // src/components/InfiniteTable/hooks/useComputed.ts
@@ -1755,9 +1752,14 @@ function getReducerGeneratedActions(dispatch, getState, getProps, propsToForward
1755
1752
  if (currentValue === value) {
1756
1753
  return;
1757
1754
  }
1758
- notifyChange(props, stateKey, value);
1755
+ let notifyTheChange = true;
1759
1756
  if (interceptedActions && typeof interceptedActions[key] === "function") {
1760
- 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);
1761
1763
  }
1762
1764
  const forwardFn = propsToForward[key];
1763
1765
  if (typeof forwardFn === "function") {
@@ -1798,12 +1800,14 @@ function forwardProps2(propsToForward, props) {
1798
1800
  function getComponentStateRoot(config) {
1799
1801
  return memo(function ComponentStateRoot(props) {
1800
1802
  var _a, _b;
1803
+ const [initialSetupState] = useState2(() => {
1804
+ return config.initSetupState ? config.initSetupState() : {};
1805
+ });
1801
1806
  const propsToStateSetRef = useRef4(new Set());
1802
- const propsToForward = useMemo3(() => config.forwardProps ? config.forwardProps() : {}, []);
1807
+ const propsToForward = useMemo3(() => config.forwardProps ? config.forwardProps(initialSetupState) : {}, [initialSetupState]);
1803
1808
  const parentState = (_b = (_a = config.getParentState) == null ? void 0 : _a.call(config)) != null ? _b : null;
1804
1809
  const getParentState = useLatest(parentState);
1805
1810
  const [wholeState] = useState2(() => {
1806
- const initialSetupState = config.initSetupState ? config.initSetupState() : {};
1807
1811
  let mappedState = {};
1808
1812
  if (propsToForward) {
1809
1813
  mappedState = forwardProps2(propsToForward, props);
@@ -1833,9 +1837,12 @@ function getComponentStateRoot(config) {
1833
1837
  const getProps = useLatest(props);
1834
1838
  const theReducer = (previousState, action) => {
1835
1839
  var _a2;
1840
+ if (action.type === "REPLACE_STATE") {
1841
+ return action.payload;
1842
+ }
1836
1843
  const parentState2 = (_a2 = getParentState == null ? void 0 : getParentState()) != null ? _a2 : null;
1837
1844
  const mappedState = action.payload.mappedState;
1838
- const updatedProps = action.payload.updatedProps;
1845
+ const updatedProps = action.payload.updatedPropsToState;
1839
1846
  const newState = Object.assign({}, previousState);
1840
1847
  if (mappedState) {
1841
1848
  Object.assign(newState, mappedState);
@@ -1889,8 +1896,9 @@ function getComponentStateRoot(config) {
1889
1896
  const currentProps = props;
1890
1897
  const newMappedState = {};
1891
1898
  let newMappedStateCount = 0;
1892
- const updatedProps = {};
1893
- let updatedPropsCount = 0;
1899
+ const updatedPropsToState = {};
1900
+ let updatedPropsToStateCount = 0;
1901
+ const rawUpdatedProps = {};
1894
1902
  for (var k in props) {
1895
1903
  const key = k;
1896
1904
  const oldValue = prevProps[key];
@@ -1901,6 +1909,7 @@ function getComponentStateRoot(config) {
1901
1909
  if (oldValue === newValue) {
1902
1910
  continue;
1903
1911
  }
1912
+ rawUpdatedProps[key] = { newValue, oldValue };
1904
1913
  if (isControlled(key, props) || isControlled(key, prevProps)) {
1905
1914
  if (propsToForward.hasOwnProperty(k)) {
1906
1915
  let valueToSet = newValue;
@@ -1913,22 +1922,30 @@ function getComponentStateRoot(config) {
1913
1922
  newMappedStateCount++;
1914
1923
  }
1915
1924
  } else if (propsToStateSetRef.current.has(k)) {
1916
- updatedProps[key] = currentProps[key];
1917
- updatedPropsCount++;
1925
+ updatedPropsToState[key] = currentProps[key];
1926
+ updatedPropsToStateCount++;
1918
1927
  }
1919
1928
  }
1920
1929
  }
1921
- if (updatedPropsCount > 0 || newMappedStateCount > 0) {
1930
+ if (updatedPropsToStateCount > 0 || newMappedStateCount > 0) {
1922
1931
  debug2("Triggered by new values for the following props", ...[
1923
1932
  ...Object.keys(newMappedState != null ? newMappedState : {}),
1924
- ...Object.keys(updatedProps != null ? updatedProps : {})
1933
+ ...Object.keys(updatedPropsToState != null ? updatedPropsToState : {})
1925
1934
  ]);
1926
- dispatch({
1935
+ const action = {
1927
1936
  payload: {
1928
1937
  mappedState: newMappedStateCount ? newMappedState : null,
1929
- updatedProps: updatedPropsCount ? updatedProps : null
1938
+ updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
1930
1939
  }
1931
- });
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
+ }
1932
1949
  }
1933
1950
  });
1934
1951
  return /* @__PURE__ */ createElement2(Context.Provider, {
@@ -2000,35 +2017,38 @@ function useColumnGroups() {
2000
2017
  return interceptMap(collapsedColumnGroups, {
2001
2018
  set: (key, visibleCol) => {
2002
2019
  const colIds = key.slice(1);
2003
- const { columnVisibility } = getComponentState();
2020
+ const columnVisibility = __spreadValues({}, getComponentState().columnVisibility);
2004
2021
  colIds.forEach((colId) => {
2005
- columnVisibility.set(colId, false);
2022
+ columnVisibility[colId] = false;
2006
2023
  });
2007
- columnVisibility.delete(visibleCol);
2024
+ delete columnVisibility[visibleCol];
2025
+ componentActions.columnVisibility = columnVisibility;
2008
2026
  },
2009
2027
  beforeClear: (currentCollapsedGroups) => {
2010
- const { columnVisibility } = getComponentState();
2028
+ const columnVisibility = __spreadValues({}, getComponentState().columnVisibility);
2011
2029
  const keys = [...currentCollapsedGroups.keys()];
2012
2030
  keys.forEach((key) => {
2013
2031
  const colIds = key.slice(1);
2014
2032
  colIds.forEach((colId) => {
2015
- columnVisibility.delete(colId);
2033
+ delete columnVisibility[colId];
2016
2034
  });
2017
2035
  });
2036
+ componentActions.columnVisibility = columnVisibility;
2018
2037
  },
2019
2038
  delete: (key) => {
2020
- const { columnVisibility } = getComponentState();
2039
+ const columnVisibility = __spreadValues({}, getComponentState().columnVisibility);
2021
2040
  const colIds = key.slice(1);
2022
2041
  colIds.forEach((colId) => {
2023
- columnVisibility.delete(colId);
2042
+ delete columnVisibility[colId];
2024
2043
  });
2044
+ componentActions.columnVisibility = columnVisibility;
2025
2045
  }
2026
2046
  });
2027
2047
  }, [collapsedColumnGroups]);
2028
2048
  }
2029
2049
 
2030
2050
  // src/components/InfiniteTable/hooks/useColumnsWhen.ts
2031
- import { useEffect as useEffect9, useMemo as useMemo5 } from "react";
2051
+ import { useEffect as useEffect9, useMemo as useMemo4 } from "react";
2032
2052
 
2033
2053
  // src/components/InfiniteTable/state/getComputedPivotColumnsFromDataSourcePivotColumns.tsx
2034
2054
  import {
@@ -2373,166 +2393,9 @@ var getMultisortFunction = (sortInfo, get) => {
2373
2393
  };
2374
2394
 
2375
2395
  // src/components/DataSource/privateHooks/useLoadData.ts
2376
- import { useEffect as useEffect8, useLayoutEffect as useLayoutEffect3, useRef as useRef6, useState as useState4 } from "react";
2377
-
2378
- // src/components/hooks/useEffectWithChanges.ts
2379
- import { useEffect as useEffect7, useRef as useRef5 } from "react";
2380
- function useEffectWithChanges(fn, deps) {
2381
- const prevRef = useRef5({});
2382
- const oldValuesRef = useRef5({});
2383
- const oldValues = oldValuesRef.current;
2384
- const changesRef = useRef5({});
2385
- const changes = changesRef.current;
2386
- const useEffectDeps = [];
2387
- for (let k in deps) {
2388
- if (deps.hasOwnProperty(k)) {
2389
- if (deps[k] !== prevRef.current[k]) {
2390
- changes[k] = deps[k];
2391
- oldValues[k] = prevRef.current[k];
2392
- }
2393
- useEffectDeps.push(deps[k]);
2394
- }
2395
- }
2396
- prevRef.current = deps;
2397
- useEffect7(() => {
2398
- const changes2 = changesRef.current;
2399
- const result = fn(changes2, oldValues);
2400
- changesRef.current = {};
2401
- oldValuesRef.current = {};
2402
- return result;
2403
- }, useEffectDeps);
2404
- }
2405
-
2406
- // src/components/DataSource/privateHooks/useLoadData.ts
2407
- function buildDataSourceDataParams(componentState) {
2408
- var _a, _b;
2409
- const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
2410
- const dataSourceParams = {
2411
- originalDataArray: componentState.originalDataArray,
2412
- sortInfo,
2413
- groupBy: componentState.groupBy,
2414
- pivotBy: componentState.pivotBy
2415
- };
2416
- if (componentState.livePagination !== void 0) {
2417
- dataSourceParams.livePaginationCursor = componentState.livePaginationCursor;
2418
- }
2419
- return dataSourceParams;
2420
- }
2421
- function notifyDataParamsChanged(componentState, actions) {
2422
- var _a;
2423
- if (typeof componentState.data === "function") {
2424
- loadData(componentState.data, componentState, actions);
2425
- }
2426
- const dataParams = buildDataSourceDataParams(componentState);
2427
- (_a = componentState.onDataParamsChange) == null ? void 0 : _a.call(componentState, dataParams);
2428
- }
2429
- function loadData(data, componentState, actions) {
2430
- const dataParams = buildDataSourceDataParams(componentState);
2431
- if (typeof data === "function") {
2432
- data = data(dataParams);
2433
- }
2434
- const dataIsPromise = typeof data === "object" && typeof data.then === "function";
2435
- if (dataIsPromise) {
2436
- actions.loading = true;
2437
- }
2438
- Promise.resolve(data).then((dataParam) => {
2439
- let dataArray = [];
2440
- if (Array.isArray(dataParam.data)) {
2441
- const remoteData = dataParam;
2442
- dataArray = remoteData.data;
2443
- if (remoteData.livePaginationCursor !== void 0) {
2444
- actions.livePaginationCursor = remoteData.livePaginationCursor;
2445
- }
2446
- } else {
2447
- dataArray = dataParam;
2448
- }
2449
- actions.originalDataArray = dataArray;
2450
- if (dataIsPromise) {
2451
- actions.loading = false;
2452
- }
2453
- });
2454
- }
2455
- function useLoadData() {
2456
- const {
2457
- getComponentState,
2458
- componentActions: actions,
2459
- componentState: { data }
2460
- } = useComponentState();
2461
- useLayoutEffect3(() => {
2462
- loadData(data, getComponentState(), actions);
2463
- }, [data]);
2464
- useLivePagination();
2465
- }
2466
- function useLivePagination() {
2467
- const {
2468
- getComponentState,
2469
- componentActions: actions,
2470
- componentState
2471
- } = useComponentState();
2472
- const {
2473
- notifyScrollbarsChange,
2474
- sortInfo,
2475
- groupBy,
2476
- pivotBy,
2477
- livePaginationCursor,
2478
- scrollBottomId
2479
- } = componentState;
2480
- const [scrollbars, setScrollbars] = useState4({
2481
- vertical: false,
2482
- horizontal: false
2483
- });
2484
- const scrollbarsRef = useRef6(scrollbars);
2485
- useEffect8(() => {
2486
- notifyScrollbarsChange.onChange((scrollbars2) => {
2487
- if (!scrollbars2) {
2488
- return;
2489
- }
2490
- scrollbarsRef.current = scrollbars2;
2491
- setScrollbars(scrollbars2);
2492
- });
2493
- return () => notifyScrollbarsChange.destroy();
2494
- }, [notifyScrollbarsChange]);
2495
- const [cursorId, updateCursorId] = useState4(void 0);
2496
- useEffect8(() => {
2497
- const frameId = requestAnimationFrame(() => {
2498
- var _a;
2499
- if (!((_a = scrollbarsRef.current) == null ? void 0 : _a.vertical)) {
2500
- updateCursorId(livePaginationCursor);
2501
- }
2502
- });
2503
- return () => cancelAnimationFrame(frameId);
2504
- }, [livePaginationCursor]);
2505
- useEffect8(() => {
2506
- const { livePaginationCursor: livePaginationCursor2, livePagination } = getComponentState();
2507
- if (!scrollbars.vertical && livePagination) {
2508
- updateCursorId(livePaginationCursor2);
2509
- }
2510
- }, [scrollbars.vertical]);
2511
- useEffect8(() => {
2512
- updateCursorId(scrollBottomId);
2513
- }, [scrollBottomId]);
2514
- const depsObject = {
2515
- sortInfo,
2516
- groupBy,
2517
- pivotBy,
2518
- cursorId
2519
- };
2520
- useEffectWithChanges(() => {
2521
- if (cursorId === void 0) {
2522
- return;
2523
- }
2524
- notifyDataParamsChanged(getComponentState(), actions);
2525
- }, depsObject);
2526
- }
2527
-
2528
- // src/components/DataSource/state/normalizeSortInfo.ts
2529
- var normalizeSortInfo = (sortInfo) => {
2530
- sortInfo = sortInfo != null ? sortInfo : [];
2531
- return Array.isArray(sortInfo) ? sortInfo : [sortInfo];
2532
- };
2396
+ import { useEffect as useEffect8, useRef as useRef6, useState as useState4 } from "react";
2533
2397
 
2534
- // src/components/hooks/useOnce.ts
2535
- import { useMemo as useMemo4 } from "react";
2398
+ // src/utils/DeepMap/once.ts
2536
2399
  function once(fn) {
2537
2400
  let called = false;
2538
2401
  let result = null;
@@ -2546,14 +2409,8 @@ function once(fn) {
2546
2409
  };
2547
2410
  return onceFn;
2548
2411
  }
2549
- function useOnce(fn) {
2550
- const onceFn = useMemo4(() => {
2551
- return once(fn);
2552
- }, []);
2553
- return onceFn();
2554
- }
2555
2412
 
2556
- // src/utils/DeepMap.ts
2413
+ // src/utils/DeepMap/index.ts
2557
2414
  var SORT_ASC_REVISION = (p1, p2) => sortAscending(p1.revision, p2.revision);
2558
2415
  var DeepMap = class {
2559
2416
  constructor(initial) {
@@ -2805,81 +2662,673 @@ var DeepMap = class {
2805
2662
  }
2806
2663
  };
2807
2664
 
2808
- // src/components/DataSource/GroupRowsState.ts
2809
- var GroupRowsState = class {
2810
- constructor(state) {
2811
- this.update(state instanceof GroupRowsState ? state.getState() : state);
2812
- }
2813
- getState() {
2814
- var _a, _b, _c, _d;
2815
- return {
2816
- expandedRows: this.expandedAll ? true : (_b = (_a = this.expandedMap) == null ? void 0 : _a.topDownKeys()) != null ? _b : [],
2817
- collapsedRows: this.collapsedAll ? true : (_d = (_c = this.collapsedMap) == null ? void 0 : _c.topDownKeys()) != null ? _d : []
2818
- };
2819
- }
2820
- destroy() {
2821
- var _a, _b;
2822
- (_a = this.expandedMap) == null ? void 0 : _a.clear();
2823
- (_b = this.collapsedMap) == null ? void 0 : _b.clear();
2824
- delete this.expandedMap;
2825
- 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 {};
2826
2673
  }
2827
- update(state) {
2828
- var _a, _b, _c, _d;
2829
- this.initialState = state;
2830
- const { collapsedRows, expandedRows } = this.initialState;
2831
- this.collapsedAll = collapsedRows === true;
2832
- this.expandedAll = expandedRows === true;
2833
- if (this.collapsedAll && this.expandedAll) {
2834
- throw `Cannot have both collapsedRows and expandedRows be true!`;
2835
- }
2836
- if (collapsedRows !== true) {
2837
- (_a = this.collapsedMap) == null ? void 0 : _a.clear();
2838
- this.collapsedMap = (_b = this.collapsedMap) != null ? _b : new DeepMap(collapsedRows.map((keys) => [keys, true]));
2839
- }
2840
- if (expandedRows !== true) {
2841
- (_c = this.expandedMap) == null ? void 0 : _c.clear();
2842
- 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;
2843
2678
  }
2679
+ return result;
2680
+ }
2681
+ function computeReducersFor(data, reducers, reducerResults) {
2682
+ var _a, _b;
2683
+ if (!reducers || !Object.keys(reducers).length) {
2684
+ return;
2844
2685
  }
2845
- areAllCollapsed() {
2846
- return this.collapsedAll && (this.expandedMap ? this.expandedMap.size === 0 : true);
2847
- }
2848
- areAllExpanded() {
2849
- return this.expandedAll && (this.collapsedMap ? this.collapsedMap.size === 0 : true);
2850
- }
2851
- collapseAll() {
2852
- this.update({
2853
- collapsedRows: true,
2854
- expandedRows: []
2855
- });
2856
- }
2857
- expandAll() {
2858
- this.update({
2859
- expandedRows: true,
2860
- collapsedRows: []
2861
- });
2862
- }
2863
- isGroupRowExpanded(keys) {
2864
- var _a, _b;
2865
- if (this.expandedAll === true) {
2866
- if (this.collapsedAll === true) {
2867
- 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;
2868
2691
  }
2869
- 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);
2870
2695
  }
2871
- return (_b = this.expandedMap) == null ? void 0 : _b.has(keys);
2872
- }
2873
- isGroupRowCollapsed(keys) {
2874
- 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
+ }
2875
2722
  }
2876
- setGroupRowExpanded(keys, shouldExpand) {
2877
- var _a;
2878
- if (shouldExpand === this.isGroupRowExpanded(keys)) {
2879
- return;
2880
- }
2881
- if (shouldExpand) {
2882
- 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
+ rootGroupBy: groupBy,
2910
+ groupBy: groupNesting === groupBy.length ? groupBy : groupBy.slice(0, groupNesting),
2911
+ isGroupRow: true,
2912
+ pivotValuesMap: pivotDeepMap,
2913
+ groupNesting,
2914
+ reducerResults
2915
+ };
2916
+ return enhancedGroupData;
2917
+ }
2918
+ function completeReducers(reducers, reducerResults, items) {
2919
+ if (reducers) {
2920
+ for (let key in reducers)
2921
+ if (reducers.hasOwnProperty(key)) {
2922
+ const reducer = reducers[key];
2923
+ if (reducer.done) {
2924
+ reducerResults[key] = reducer.done(reducerResults[key], items);
2925
+ }
2926
+ }
2927
+ }
2928
+ return reducerResults;
2929
+ }
2930
+ function enhancedFlatten(param) {
2931
+ const {
2932
+ groupResult,
2933
+ toPrimaryKey,
2934
+ groupRowsState,
2935
+ generateGroupRows,
2936
+ reducers = {}
2937
+ } = param;
2938
+ const { groupParams, deepMap, pivot } = groupResult;
2939
+ const { groupBy } = groupParams;
2940
+ const groupByStrings = groupBy.map((g) => g.field);
2941
+ const result = [];
2942
+ const parents = [];
2943
+ const indexInParentGroups = [];
2944
+ deepMap.visitDepthFirst((deepMapValue, groupKeys, indexInGroup, next) => {
2945
+ var _a;
2946
+ const items = deepMapValue.items;
2947
+ const groupNesting = groupKeys.length;
2948
+ const collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
2949
+ const enhancedGroupData = getEnhancedGroupData({
2950
+ groupBy: groupByStrings,
2951
+ parents: Array.from(parents),
2952
+ reducers,
2953
+ indexInGroup,
2954
+ indexInParentGroups: Array.from(indexInParentGroups),
2955
+ indexInAll: result.length,
2956
+ groupKeys,
2957
+ collapsed
2958
+ }, deepMapValue);
2959
+ const include = generateGroupRows || collapsed;
2960
+ if (include) {
2961
+ result.push(enhancedGroupData);
2962
+ }
2963
+ if (collapsed) {
2964
+ parents.forEach((parent) => {
2965
+ parent.collapsedChildrenCount += enhancedGroupData.groupCount;
2966
+ parent.collapsedGroupsCount += 1;
2967
+ });
2968
+ }
2969
+ indexInParentGroups.push(indexInGroup);
2970
+ parents.push(enhancedGroupData);
2971
+ if (!collapsed) {
2972
+ if (!next) {
2973
+ if (!pivot) {
2974
+ const startIndex = result.length;
2975
+ result.push(...items.map((item, index) => {
2976
+ return {
2977
+ id: toPrimaryKey(item),
2978
+ data: item,
2979
+ isGroupRow: false,
2980
+ collapsed: false,
2981
+ groupKeys,
2982
+ parents: Array.from(parents),
2983
+ indexInParentGroups: [...indexInParentGroups, index],
2984
+ indexInGroup: index,
2985
+ indexInAll: startIndex + index,
2986
+ groupBy: groupByStrings,
2987
+ groupNesting,
2988
+ groupCount: enhancedGroupData.groupCount
2989
+ };
2990
+ }));
2991
+ }
2992
+ } else {
2993
+ next();
2994
+ }
2995
+ }
2996
+ parents.pop();
2997
+ indexInParentGroups.pop();
2998
+ });
2999
+ return {
3000
+ data: result
3001
+ };
3002
+ }
3003
+
3004
+ // src/components/hooks/useEffectWithChanges.ts
3005
+ import { useEffect as useEffect7, useRef as useRef5 } from "react";
3006
+ function useEffectWithChanges(fn, deps) {
3007
+ const prevRef = useRef5({});
3008
+ const oldValuesRef = useRef5({});
3009
+ const oldValues = oldValuesRef.current;
3010
+ const changesRef = useRef5({});
3011
+ const changes = changesRef.current;
3012
+ const useEffectDeps = [];
3013
+ for (let k in deps) {
3014
+ if (deps.hasOwnProperty(k)) {
3015
+ if (deps[k] !== prevRef.current[k]) {
3016
+ changes[k] = deps[k];
3017
+ oldValues[k] = prevRef.current[k];
3018
+ }
3019
+ useEffectDeps.push(deps[k]);
3020
+ }
3021
+ }
3022
+ prevRef.current = deps;
3023
+ useEffect7(() => {
3024
+ const changes2 = changesRef.current;
3025
+ const result = fn(changes2, oldValues);
3026
+ changesRef.current = {};
3027
+ oldValuesRef.current = {};
3028
+ return result;
3029
+ }, useEffectDeps);
3030
+ }
3031
+
3032
+ // src/components/DataSource/privateHooks/useLoadData.ts
3033
+ var SKIP_DATA_CHANGES_KEYS = {
3034
+ originalDataArray: true,
3035
+ changes: true
3036
+ };
3037
+ function buildDataSourceDataParams(componentState, overrides) {
3038
+ var _a, _b;
3039
+ const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
3040
+ const dataSourceParams = {
3041
+ originalDataArray: componentState.originalDataArray,
3042
+ sortInfo,
3043
+ groupBy: componentState.groupBy,
3044
+ pivotBy: componentState.pivotBy,
3045
+ aggregationReducers: componentState.aggregationReducers
3046
+ };
3047
+ if (componentState.livePagination !== void 0) {
3048
+ dataSourceParams.livePaginationCursor = componentState.livePaginationCursor;
3049
+ dataSourceParams.cursorId = componentState.cursorId;
3050
+ }
3051
+ if (componentState.fullLazyLoad) {
3052
+ if (componentState.lazyLoadBatchSize != null && componentState.lazyLoadBatchSize > 0) {
3053
+ dataSourceParams.lazyLoadBatchSize = componentState.lazyLoadBatchSize;
3054
+ dataSourceParams.lazyLoadStartIndex = 0;
3055
+ }
3056
+ dataSourceParams.groupKeys = [];
3057
+ }
3058
+ if (overrides) {
3059
+ Object.assign(dataSourceParams, overrides);
3060
+ }
3061
+ const changes = {};
3062
+ const oldDataSourceParams = componentState.dataParams || {};
3063
+ for (let k in dataSourceParams) {
3064
+ if (dataSourceParams.hasOwnProperty(k) && !SKIP_DATA_CHANGES_KEYS[k]) {
3065
+ const key = k;
3066
+ if (dataSourceParams[key] !== oldDataSourceParams[key]) {
3067
+ changes[key] = true;
3068
+ }
3069
+ }
3070
+ }
3071
+ dataSourceParams.changes = changes;
3072
+ return dataSourceParams;
3073
+ }
3074
+ function loadData(data, componentState, actions, overrides) {
3075
+ const dataParams = buildDataSourceDataParams(componentState, overrides);
3076
+ if (typeof data === "function") {
3077
+ data = data(dataParams);
3078
+ }
3079
+ const dataIsPromise = typeof data === "object" && typeof data.then === "function";
3080
+ if (dataIsPromise) {
3081
+ actions.loading = true;
3082
+ }
3083
+ Promise.resolve(data).then((dataParam) => {
3084
+ var _a, _b, _c;
3085
+ let dataArray = [];
3086
+ let skipAssign = false;
3087
+ if (Array.isArray(dataParam.data)) {
3088
+ const remoteData = dataParam;
3089
+ dataArray = remoteData.data;
3090
+ if (remoteData.livePaginationCursor !== void 0) {
3091
+ actions.livePaginationCursor = remoteData.livePaginationCursor;
3092
+ }
3093
+ if (remoteData.mappings) {
3094
+ actions.pivotMappings = remoteData.mappings;
3095
+ }
3096
+ if (componentState.fullLazyLoad && dataParams.groupKeys) {
3097
+ const lazyGroupData = DeepMap.clone(componentState.originalLazyGroupData);
3098
+ const key = [LAZY_ROOT_KEY_FOR_GROUPS, ...dataParams.groupKeys];
3099
+ const newGroupRowInfo = {
3100
+ totalCount: (_a = remoteData.totalCount) != null ? _a : dataArray.length,
3101
+ items: dataArray
3102
+ };
3103
+ if (dataParams.lazyLoadBatchSize) {
3104
+ const existingGroupRowInfo = lazyGroupData.get(key);
3105
+ const currentGroupRowInfo = existingGroupRowInfo != null ? existingGroupRowInfo : {
3106
+ items: [],
3107
+ totalCount: newGroupRowInfo.totalCount
3108
+ };
3109
+ currentGroupRowInfo.items.length = currentGroupRowInfo.totalCount;
3110
+ const start = (_b = dataParams.lazyLoadStartIndex) != null ? _b : 0;
3111
+ const end = start + ((_c = dataParams.lazyLoadBatchSize) != null ? _c : dataArray.length);
3112
+ for (let i = start; i < end; i++) {
3113
+ currentGroupRowInfo.items[i] = newGroupRowInfo.items[i - start];
3114
+ }
3115
+ if (!existingGroupRowInfo) {
3116
+ lazyGroupData.set(key, currentGroupRowInfo);
3117
+ }
3118
+ } else {
3119
+ lazyGroupData.set(key, newGroupRowInfo);
3120
+ }
3121
+ skipAssign = true;
3122
+ actions.originalLazyGroupData = lazyGroupData;
3123
+ }
3124
+ } else {
3125
+ dataArray = dataParam;
3126
+ }
3127
+ if (!skipAssign) {
3128
+ actions.originalDataArray = dataArray;
3129
+ }
3130
+ if (dataIsPromise) {
3131
+ actions.loading = false;
3132
+ }
3133
+ });
3134
+ }
3135
+ function useLoadData() {
3136
+ const {
3137
+ getComponentState,
3138
+ componentActions: actions,
3139
+ componentState
3140
+ } = useComponentState();
3141
+ const {
3142
+ data,
3143
+ notifyScrollbarsChange,
3144
+ sortInfo,
3145
+ groupBy,
3146
+ pivotBy,
3147
+ livePagination,
3148
+ livePaginationCursor,
3149
+ cursorId: stateCursorId,
3150
+ lazyLoadBatchSize,
3151
+ notifyScrollStop
3152
+ } = componentState;
3153
+ const [scrollbars, setScrollbars] = useState4({
3154
+ vertical: false,
3155
+ horizontal: false
3156
+ });
3157
+ const scrollbarsRef = useRef6(scrollbars);
3158
+ useEffect8(() => {
3159
+ notifyScrollbarsChange.onChange((scrollbars2) => {
3160
+ if (!scrollbars2) {
3161
+ return;
3162
+ }
3163
+ scrollbarsRef.current = scrollbars2;
3164
+ setScrollbars(scrollbars2);
3165
+ });
3166
+ return () => notifyScrollbarsChange.destroy();
3167
+ }, [notifyScrollbarsChange]);
3168
+ useEffect8(() => {
3169
+ const frameId = requestAnimationFrame(() => {
3170
+ var _a;
3171
+ if (!((_a = scrollbarsRef.current) == null ? void 0 : _a.vertical) && livePaginationCursor) {
3172
+ actions.cursorId = livePaginationCursor;
3173
+ }
3174
+ });
3175
+ return () => cancelAnimationFrame(frameId);
3176
+ }, [livePaginationCursor]);
3177
+ useEffect8(() => {
3178
+ const { livePaginationCursor: livePaginationCursor2, livePagination: livePagination2 } = getComponentState();
3179
+ if (!scrollbars.vertical && livePagination2) {
3180
+ if (livePaginationCursor2) {
3181
+ actions.cursorId = livePaginationCursor2;
3182
+ }
3183
+ }
3184
+ }, [scrollbars.vertical]);
3185
+ const depsObject = {
3186
+ sortInfo,
3187
+ groupBy,
3188
+ pivotBy,
3189
+ cursorId: livePagination ? stateCursorId : null
3190
+ };
3191
+ const initialRef = useRef6(true);
3192
+ useEffect8(() => {
3193
+ if (lazyLoadBatchSize && lazyLoadBatchSize > 0) {
3194
+ return notifyScrollStop.onChange((param) => {
3195
+ console.log("scroll stop", param);
3196
+ if (!param) {
3197
+ return;
3198
+ }
3199
+ const componentState2 = getComponentState();
3200
+ const {
3201
+ firstVisibleRowIndex: startIndex,
3202
+ lastVisibleRowIndex: endIndex
3203
+ } = param;
3204
+ const firstBatchStart = Math.floor(startIndex / lazyLoadBatchSize) * lazyLoadBatchSize;
3205
+ const lastBatchStart = Math.floor(endIndex / lazyLoadBatchSize) * lazyLoadBatchSize;
3206
+ const isRowLoaded = (index) => componentState2.dataArray[index].data != null;
3207
+ for (let batchStartIndex = firstBatchStart; batchStartIndex <= lastBatchStart; batchStartIndex = batchStartIndex + lazyLoadBatchSize) {
3208
+ if (!isRowLoaded(batchStartIndex)) {
3209
+ loadData(componentState2.data, componentState2, actions, {
3210
+ lazyLoadBatchSize,
3211
+ lazyLoadStartIndex: batchStartIndex
3212
+ });
3213
+ }
3214
+ }
3215
+ });
3216
+ }
3217
+ return;
3218
+ }, [lazyLoadBatchSize]);
3219
+ useEffectWithChanges(() => {
3220
+ const componentState2 = getComponentState();
3221
+ if (typeof componentState2.data !== "function") {
3222
+ loadData(componentState2.data, componentState2, actions);
3223
+ }
3224
+ }, { data });
3225
+ useEffectWithChanges(() => {
3226
+ const componentState2 = getComponentState();
3227
+ if (typeof componentState2.data === "function") {
3228
+ loadData(componentState2.data, componentState2, actions);
3229
+ }
3230
+ }, __spreadProps(__spreadValues({}, depsObject), { data }));
3231
+ useEffectWithChanges((_changes, _prevValues) => {
3232
+ const componentState2 = getComponentState();
3233
+ if (initialRef.current) {
3234
+ initialRef.current = false;
3235
+ actions.dataParams = buildDataSourceDataParams(componentState2);
3236
+ }
3237
+ }, depsObject);
3238
+ }
3239
+
3240
+ // src/components/DataSource/state/normalizeSortInfo.ts
3241
+ var EMPTY_ARRAY = Object.freeze([]);
3242
+ var normalizeSortInfo = (initialSortInfo, weakMap) => {
3243
+ const sortInfo = initialSortInfo != null ? initialSortInfo : EMPTY_ARRAY;
3244
+ const result = Array.isArray(sortInfo) ? sortInfo : [sortInfo];
3245
+ if (weakMap && weakMap.has(sortInfo)) {
3246
+ const prevResult = weakMap.get(sortInfo);
3247
+ if (prevResult && prevResult.length === result.length) {
3248
+ return prevResult;
3249
+ }
3250
+ }
3251
+ if (weakMap && sortInfo) {
3252
+ weakMap.set(sortInfo, result);
3253
+ }
3254
+ return result;
3255
+ };
3256
+
3257
+ // src/components/DataSource/GroupRowsState.ts
3258
+ var GroupRowsState = class {
3259
+ constructor(state) {
3260
+ this.update(state instanceof GroupRowsState ? state.getState() : state);
3261
+ }
3262
+ getState() {
3263
+ var _a, _b, _c, _d;
3264
+ return {
3265
+ expandedRows: this.expandedAll ? true : (_b = (_a = this.expandedMap) == null ? void 0 : _a.topDownKeys()) != null ? _b : [],
3266
+ collapsedRows: this.collapsedAll ? true : (_d = (_c = this.collapsedMap) == null ? void 0 : _c.topDownKeys()) != null ? _d : []
3267
+ };
3268
+ }
3269
+ destroy() {
3270
+ var _a, _b;
3271
+ (_a = this.expandedMap) == null ? void 0 : _a.clear();
3272
+ (_b = this.collapsedMap) == null ? void 0 : _b.clear();
3273
+ delete this.expandedMap;
3274
+ delete this.collapsedMap;
3275
+ }
3276
+ update(state) {
3277
+ var _a, _b, _c, _d;
3278
+ this.initialState = state;
3279
+ const { collapsedRows, expandedRows } = this.initialState;
3280
+ this.collapsedAll = collapsedRows === true;
3281
+ this.expandedAll = expandedRows === true;
3282
+ if (this.collapsedAll && this.expandedAll) {
3283
+ throw `Cannot have both collapsedRows and expandedRows be true!`;
3284
+ }
3285
+ if (collapsedRows !== true) {
3286
+ (_a = this.collapsedMap) == null ? void 0 : _a.clear();
3287
+ this.collapsedMap = (_b = this.collapsedMap) != null ? _b : new DeepMap(collapsedRows.map((keys) => [keys, true]));
3288
+ }
3289
+ if (expandedRows !== true) {
3290
+ (_c = this.expandedMap) == null ? void 0 : _c.clear();
3291
+ this.expandedMap = (_d = this.expandedMap) != null ? _d : new DeepMap(expandedRows.map((keys) => [keys, true]));
3292
+ }
3293
+ }
3294
+ areAllCollapsed() {
3295
+ return this.collapsedAll && (this.expandedMap ? this.expandedMap.size === 0 : true);
3296
+ }
3297
+ areAllExpanded() {
3298
+ return this.expandedAll && (this.collapsedMap ? this.collapsedMap.size === 0 : true);
3299
+ }
3300
+ collapseAll() {
3301
+ this.update({
3302
+ collapsedRows: true,
3303
+ expandedRows: []
3304
+ });
3305
+ }
3306
+ expandAll() {
3307
+ this.update({
3308
+ expandedRows: true,
3309
+ collapsedRows: []
3310
+ });
3311
+ }
3312
+ isGroupRowExpanded(keys) {
3313
+ var _a, _b;
3314
+ if (this.expandedAll === true) {
3315
+ if (this.collapsedAll === true) {
3316
+ throw 'Cannot have both expandedRows and collapsedRows be "true"';
3317
+ }
3318
+ return !((_a = this.collapsedMap) == null ? void 0 : _a.has(keys));
3319
+ }
3320
+ return (_b = this.expandedMap) == null ? void 0 : _b.has(keys);
3321
+ }
3322
+ isGroupRowCollapsed(keys) {
3323
+ return !this.isGroupRowExpanded(keys);
3324
+ }
3325
+ setGroupRowExpanded(keys, shouldExpand) {
3326
+ var _a;
3327
+ if (shouldExpand === this.isGroupRowExpanded(keys)) {
3328
+ return;
3329
+ }
3330
+ if (shouldExpand) {
3331
+ if (this.collapsedAll === true) {
2883
3332
  if (!this.expandedMap) {
2884
3333
  throw `No expandedMap found when trying to expand group row ${keys.join(",")}`;
2885
3334
  }
@@ -2916,7 +3365,7 @@ var GroupRowsState = class {
2916
3365
  };
2917
3366
 
2918
3367
  // src/utils/shallowEqualObjects.ts
2919
- function shallowEqualObjects(objA, objB) {
3368
+ function shallowEqualObjects(objA, objB, ignoreKeys) {
2920
3369
  if (objA === objB) {
2921
3370
  return true;
2922
3371
  }
@@ -2925,12 +3374,21 @@ function shallowEqualObjects(objA, objB) {
2925
3374
  }
2926
3375
  var aKeys = Object.keys(objA);
2927
3376
  var bKeys = Object.keys(objB);
3377
+ if (ignoreKeys) {
3378
+ aKeys = aKeys.filter((key2) => !ignoreKeys.has(key2));
3379
+ bKeys = bKeys.filter((key2) => !ignoreKeys.has(key2));
3380
+ }
2928
3381
  var len = aKeys.length;
2929
3382
  if (bKeys.length !== len) {
2930
3383
  return false;
2931
3384
  }
2932
3385
  for (var i = 0; i < len; i++) {
2933
3386
  var key = aKeys[i];
3387
+ if (ignoreKeys) {
3388
+ if (ignoreKeys.has(key)) {
3389
+ continue;
3390
+ }
3391
+ }
2934
3392
  if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
2935
3393
  return false;
2936
3394
  }
@@ -2941,12 +3399,12 @@ function shallowEqualObjects(objA, objB) {
2941
3399
  // src/components/utils/discardCallsWithEqualArg.ts
2942
3400
  var map = new WeakMap();
2943
3401
  var getCompareDefault = (a) => a;
2944
- function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject2) {
3402
+ function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject) {
2945
3403
  map.set(fn, {
2946
3404
  lastCallTime: 0,
2947
3405
  lastCallArg: null
2948
3406
  });
2949
- const getCompare = getCompareObject2 != null ? getCompareObject2 : getCompareDefault;
3407
+ const getCompare = getCompareObject != null ? getCompareObject : getCompareDefault;
2950
3408
  return (arg) => {
2951
3409
  const { lastCallTime, lastCallArg } = map.get(fn) || {
2952
3410
  lastCallTime: 0,
@@ -2967,339 +3425,172 @@ function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject2) {
2967
3425
  }
2968
3426
 
2969
3427
  // src/components/DataSource/state/getInitialState.ts
3428
+ var defaultCursorId = Symbol("cursorId");
2970
3429
  function initSetupState2() {
2971
3430
  const now = Date.now();
2972
3431
  const originalDataArray = [];
2973
3432
  const dataArray = [];
3433
+ const originalLazyGroupData = new DeepMap();
2974
3434
  return {
2975
3435
  dataParams: void 0,
2976
3436
  notifyScrollbarsChange: buildSubscriptionCallback(),
3437
+ notifyScrollStop: buildSubscriptionCallback(),
2977
3438
  pivotTotalColumnPosition: "end",
2978
- originalDataArray,
2979
- scrollBottomId: Symbol("scrollBottomId"),
2980
- showSeparatePivotColumnForSingleAggregation: false,
2981
- pivotColumns: void 0,
2982
- pivotColumnGroups: void 0,
2983
- dataArray,
2984
- updatedAt: now,
2985
- groupedAt: 0,
2986
- sortedAt: 0,
2987
- reducedAt: now,
2988
- generateGroupRows: true,
2989
- groupDeepMap: void 0,
2990
- postSortDataArray: void 0,
2991
- postGroupDataArray: void 0,
2992
- lastSortDataArray: void 0,
2993
- lastGroupDataArray: void 0
2994
- };
2995
- }
2996
- function getCompareObject(dataParams) {
2997
- const obj = __spreadValues({}, dataParams);
2998
- delete obj.originalDataArray;
2999
- return obj;
3000
- }
3001
- var forwardProps3 = () => {
3002
- return {
3003
- onDataParamsChange: (fn) => fn ? discardCallsWithEqualArg(fn, 100, getCompareObject) : void 0,
3004
- data: 1,
3005
- pivotBy: 1,
3006
- primaryKey: 1,
3007
- livePagination: 1,
3008
- livePaginationCursor: 1,
3009
- aggregationReducers: 1,
3010
- loading: (loading) => loading != null ? loading : false,
3011
- sortInfo: (sortInfo) => normalizeSortInfo(sortInfo),
3012
- groupBy: (groupBy) => groupBy != null ? groupBy : [],
3013
- groupRowsState: (groupRowsState) => {
3014
- return groupRowsState || new GroupRowsState({
3015
- expandedRows: true,
3016
- collapsedRows: []
3017
- });
3018
- }
3019
- };
3020
- };
3021
- function mapPropsToState2(params) {
3022
- const { props } = params;
3023
- const controlledSort = isControlledValue(props.sortInfo);
3024
- return {
3025
- controlledSort,
3026
- multiSort: Array.isArray(controlledSort ? props.sortInfo : props.defaultSortInfo)
3027
- };
3028
- }
3029
- function getInterceptActions() {
3030
- return {
3031
- sortInfo: (sortInfo, { actions, state }) => {
3032
- const dataParams = buildDataSourceDataParams(state);
3033
- dataParams.sortInfo = sortInfo;
3034
- actions.dataParams = dataParams;
3035
- }
3036
- };
3037
- }
3038
-
3039
- // src/utils/groupAndPivot/index.ts
3040
- function DEFAULT_TO_KEY(value) {
3041
- return value;
3042
- }
3043
- function initReducers(reducers) {
3044
- if (!reducers || !Object.keys(reducers).length) {
3045
- return {};
3046
- }
3047
- const result = {};
3048
- for (let key in reducers)
3049
- if (reducers.hasOwnProperty(key)) {
3050
- result[key] = reducers[key].initialValue;
3051
- }
3052
- return result;
3053
- }
3054
- function computeReducersFor(data, reducers, reducerResults) {
3055
- var _a, _b;
3056
- if (!reducers || !Object.keys(reducers).length) {
3057
- return;
3058
- }
3059
- for (let key in reducers)
3060
- if (reducers.hasOwnProperty(key)) {
3061
- const reducer = reducers[key];
3062
- const currentValue = reducerResults[key];
3063
- const value = reducer.field ? data[reducer.field] : (_b = (_a = reducer.getter) == null ? void 0 : _a.call(reducer, data)) != null ? _b : null;
3064
- reducerResults[key] = reducer.reducer(currentValue, value, data);
3065
- }
3066
- }
3067
- function group(groupParams, data) {
3068
- const {
3069
- groupBy,
3070
- defaultToKey = DEFAULT_TO_KEY,
3071
- pivot,
3072
- reducers
3073
- } = groupParams;
3074
- const groupByLength = groupBy.length;
3075
- const topLevelPivotColumns = pivot ? new DeepMap() : void 0;
3076
- const deepMap = new DeepMap();
3077
- let currentGroupKeys = [];
3078
- let currentPivotKeys = [];
3079
- const initialReducerValue = initReducers(reducers);
3080
- const globalReducerResults = __spreadValues({}, initialReducerValue);
3081
- for (let i = 0, len = data.length; i < len; i++) {
3082
- let item = data[i];
3083
- for (let groupByIndex = 0; groupByIndex < groupByLength; groupByIndex++) {
3084
- const { field: groupByProperty, toKey: groupToKey } = groupBy[groupByIndex];
3085
- const key = (groupToKey || defaultToKey)(item[groupByProperty], item);
3086
- currentGroupKeys.push(key);
3087
- if (!deepMap.has(currentGroupKeys)) {
3088
- const deepMapGroupValue = {
3089
- items: [],
3090
- reducerResults: __spreadValues({}, initialReducerValue)
3091
- };
3092
- if (pivot) {
3093
- deepMapGroupValue.pivotDeepMap = new DeepMap();
3094
- }
3095
- deepMap.set(currentGroupKeys, deepMapGroupValue);
3096
- }
3097
- const {
3098
- items: currentGroupItems,
3099
- reducerResults,
3100
- pivotDeepMap
3101
- } = deepMap.get(currentGroupKeys);
3102
- currentGroupItems.push(item);
3103
- if (reducers) {
3104
- computeReducersFor(item, reducers, reducerResults);
3105
- }
3106
- if (pivot) {
3107
- for (let pivotIndex = 0, pivotLength = pivot.length; pivotIndex < pivotLength; pivotIndex++) {
3108
- const { field: pivotField, toKey: pivotToKey } = pivot[pivotIndex];
3109
- const pivotKey = (pivotToKey || defaultToKey)(item[pivotField], item);
3110
- currentPivotKeys.push(pivotKey);
3111
- if (!pivotDeepMap.has(currentPivotKeys)) {
3112
- topLevelPivotColumns.set(currentPivotKeys, true);
3113
- pivotDeepMap == null ? void 0 : pivotDeepMap.set(currentPivotKeys, {
3114
- reducerResults: __spreadValues({}, initialReducerValue),
3115
- items: []
3116
- });
3117
- }
3118
- const {
3119
- reducerResults: pivotReducerResults,
3120
- items: pivotGroupItems
3121
- } = pivotDeepMap.get(currentPivotKeys);
3122
- pivotGroupItems.push(item);
3123
- if (reducers) {
3124
- computeReducersFor(item, reducers, pivotReducerResults);
3125
- }
3126
- }
3127
- currentPivotKeys.length = 0;
3128
- }
3129
- }
3130
- if (reducers) {
3131
- computeReducersFor(item, reducers, globalReducerResults);
3439
+ originalLazyGroupData,
3440
+ originalDataArray,
3441
+ cursorId: defaultCursorId,
3442
+ showSeparatePivotColumnForSingleAggregation: false,
3443
+ propsCache: new Map([
3444
+ ["sortInfo", new WeakMap()]
3445
+ ]),
3446
+ pivotMappings: void 0,
3447
+ pivotColumns: void 0,
3448
+ pivotColumnGroups: void 0,
3449
+ dataArray,
3450
+ updatedAt: now,
3451
+ groupedAt: 0,
3452
+ sortedAt: 0,
3453
+ reducedAt: now,
3454
+ generateGroupRows: true,
3455
+ groupDeepMap: void 0,
3456
+ postSortDataArray: void 0,
3457
+ postGroupDataArray: void 0,
3458
+ lastSortDataArray: void 0,
3459
+ lastGroupDataArray: void 0
3460
+ };
3461
+ }
3462
+ function getCompareObjectForDataParams(dataParams) {
3463
+ const obj = __spreadValues({}, dataParams);
3464
+ delete obj.originalDataArray;
3465
+ return obj;
3466
+ }
3467
+ var forwardProps3 = (setupState) => {
3468
+ return {
3469
+ onDataParamsChange: (fn) => fn ? discardCallsWithEqualArg(fn, 100, getCompareObjectForDataParams) : void 0,
3470
+ fullLazyLoad: 1,
3471
+ data: 1,
3472
+ pivotBy: 1,
3473
+ primaryKey: 1,
3474
+ livePagination: 1,
3475
+ lazyLoadBatchSize: (lazyLoadBatchSize) => lazyLoadBatchSize != null ? lazyLoadBatchSize : -1,
3476
+ aggregationReducers: 1,
3477
+ collapseGroupRowsOnDataFunctionChange: (collapseGroupRowsOnDataFunctionChange) => collapseGroupRowsOnDataFunctionChange != null ? collapseGroupRowsOnDataFunctionChange : true,
3478
+ loading: (loading) => loading != null ? loading : false,
3479
+ sortInfo: (sortInfo) => normalizeSortInfo(sortInfo, setupState.propsCache.get("sortInfo")),
3480
+ groupBy: (groupBy) => groupBy != null ? groupBy : [],
3481
+ groupRowsState: (groupRowsState) => {
3482
+ return groupRowsState || new GroupRowsState({
3483
+ expandedRows: true,
3484
+ collapsedRows: []
3485
+ });
3132
3486
  }
3133
- currentGroupKeys.length = 0;
3134
- }
3135
- if (reducers) {
3136
- deepMap.visitDepthFirst((deepMapValue, _keys, _indexInGroup, next) => {
3137
- completeReducers(reducers, deepMapValue.reducerResults, deepMapValue.items);
3138
- if (pivot) {
3139
- deepMapValue.pivotDeepMap.visitDepthFirst(({ items, reducerResults: pivotReducerResults }, _keys2, _indexInGroup2, next2) => {
3140
- completeReducers(reducers, pivotReducerResults, items);
3141
- next2 == null ? void 0 : next2();
3142
- });
3143
- }
3144
- next == null ? void 0 : next();
3145
- });
3146
- }
3147
- if (reducers) {
3148
- completeReducers(reducers, globalReducerResults, data);
3149
- }
3487
+ };
3488
+ };
3489
+ function getLivePaginationCursorValue(livePaginationCursorProp, state) {
3490
+ const livePaginationCursor = typeof livePaginationCursorProp === "function" ? livePaginationCursorProp({
3491
+ array: state.originalDataArray,
3492
+ length: state.originalDataArray.length,
3493
+ lastItem: state.originalDataArray[state.originalDataArray.length - 1]
3494
+ }) : livePaginationCursorProp;
3495
+ return livePaginationCursor;
3496
+ }
3497
+ function mapPropsToState2(params) {
3498
+ const { props, state, oldState } = params;
3499
+ const controlledSort = isControlledValue(props.sortInfo);
3150
3500
  const result = {
3151
- deepMap,
3152
- groupParams,
3153
- initialData: data,
3154
- reducerResults: globalReducerResults
3501
+ controlledSort,
3502
+ multiSort: Array.isArray(controlledSort ? props.sortInfo : props.defaultSortInfo)
3155
3503
  };
3156
- if (pivot) {
3157
- result.topLevelPivotColumns = topLevelPivotColumns;
3158
- result.pivot = pivot;
3504
+ if (props.livePagination) {
3505
+ const dataArrayChanged = !oldState || oldState.originalDataArray !== state.originalDataArray;
3506
+ const livePaginationCursor = typeof props.livePaginationCursor === "function" ? dataArrayChanged ? getLivePaginationCursorValue(props.livePaginationCursor, state) : state.livePaginationCursor : props.livePaginationCursor;
3507
+ result.livePaginationCursor = livePaginationCursor;
3159
3508
  }
3160
3509
  return result;
3161
3510
  }
3162
- function flatten(groupResult) {
3163
- const { groupParams, deepMap } = groupResult;
3164
- const groupByLength = groupParams.groupBy.length;
3165
- const result = [];
3166
- deepMap.topDownKeys().reduce((acc, key) => {
3167
- if (key.length === groupByLength) {
3168
- const items = deepMap.get(key).items;
3169
- acc.push(...items);
3511
+ var debugFullLazyLoad = dbg("DataSource:fullLazyLoad");
3512
+ function onPropChange(params, props, actions) {
3513
+ const { name, newValue } = params;
3514
+ if (name === "data" && typeof newValue === "function" && !props.groupRowsState) {
3515
+ if (props.fullLazyLoad) {
3516
+ debugFullLazyLoad(`"data" function prop has changed`);
3517
+ }
3518
+ if (props.collapseGroupRowsOnDataFunctionChange !== false) {
3519
+ actions.groupRowsState = new GroupRowsState({
3520
+ collapsedRows: true,
3521
+ expandedRows: []
3522
+ });
3170
3523
  }
3171
- return acc;
3172
- }, result);
3173
- return result;
3174
- }
3175
- function getEnhancedGroupData(options, deepMapValue) {
3176
- const { groupBy, groupKeys, collapsed, parents, reducers } = options;
3177
- const groupNesting = groupKeys.length;
3178
- const { items: groupItems, reducerResults, pivotDeepMap } = deepMapValue;
3179
- let data = null;
3180
- if (Object.keys(reducerResults).length > 0) {
3181
- data = {};
3182
- for (let key in reducers)
3183
- if (reducers.hasOwnProperty(key)) {
3184
- const reducer = reducers[key];
3185
- const field = reducer.field;
3186
- if (field) {
3187
- data[field] = reducerResults[key];
3188
- }
3189
- }
3190
3524
  }
3191
- const enhancedGroupData = {
3192
- data,
3193
- groupCount: groupItems.length,
3194
- groupData: groupItems,
3195
- groupKeys,
3196
- id: groupKeys,
3197
- collapsed,
3198
- parents,
3199
- collapsedChildrenCount: 0,
3200
- collapsedGroupsCount: 0,
3201
- indexInParentGroups: options.indexInParentGroups,
3202
- indexInGroup: options.indexInGroup,
3203
- indexInAll: options.indexInAll,
3204
- value: groupKeys[groupKeys.length - 1],
3205
- groupBy: groupBy.slice(0, groupNesting),
3206
- isGroupRow: true,
3207
- pivotValuesMap: pivotDeepMap,
3208
- groupNesting,
3209
- reducerResults
3210
- };
3211
- return enhancedGroupData;
3212
3525
  }
3213
- function completeReducers(reducers, reducerResults, items) {
3214
- if (reducers) {
3215
- for (let key in reducers)
3216
- if (reducers.hasOwnProperty(key)) {
3217
- const reducer = reducers[key];
3218
- if (reducer.done) {
3219
- reducerResults[key] = reducer.done(reducerResults[key], items);
3220
- }
3526
+ var debugDataParams = dbg("DataSource:dataParams");
3527
+ function getInterceptActions() {
3528
+ return {
3529
+ sortInfo: (sortInfo, { actions, state }) => {
3530
+ const dataParams = buildDataSourceDataParams(state, {
3531
+ sortInfo,
3532
+ livePaginationCursor: null
3533
+ });
3534
+ actions.dataParams = dataParams;
3535
+ if (state.livePagination) {
3536
+ requestAnimationFrame(() => {
3537
+ actions.livePaginationCursor = null;
3538
+ });
3221
3539
  }
3222
- }
3223
- return reducerResults;
3224
- }
3225
- function enhancedFlatten(param) {
3226
- const {
3227
- groupResult,
3228
- toPrimaryKey,
3229
- groupRowsState,
3230
- generateGroupRows,
3231
- reducers = {}
3232
- } = param;
3233
- const { groupParams, deepMap, pivot } = groupResult;
3234
- const { groupBy } = groupParams;
3235
- const groupByStrings = groupBy.map((g) => g.field);
3236
- const result = [];
3237
- const parents = [];
3238
- const indexInParentGroups = [];
3239
- deepMap.visitDepthFirst((deepMapValue, groupKeys, indexInGroup, next) => {
3240
- var _a;
3241
- const items = deepMapValue.items;
3242
- const groupNesting = groupKeys.length;
3243
- const collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
3244
- const enhancedGroupData = getEnhancedGroupData({
3245
- groupBy: groupByStrings,
3246
- parents: Array.from(parents),
3247
- reducers,
3248
- indexInGroup,
3249
- indexInParentGroups: Array.from(indexInParentGroups),
3250
- indexInAll: result.length,
3251
- groupKeys,
3252
- collapsed
3253
- }, deepMapValue);
3254
- const include = generateGroupRows || collapsed;
3255
- if (include) {
3256
- result.push(enhancedGroupData);
3257
- }
3258
- if (collapsed) {
3259
- parents.forEach((parent) => {
3260
- parent.collapsedChildrenCount += enhancedGroupData.groupCount;
3261
- parent.collapsedGroupsCount += 1;
3540
+ },
3541
+ groupBy: (groupBy, { actions, state }) => {
3542
+ const dataParams = buildDataSourceDataParams(state, {
3543
+ groupBy,
3544
+ livePaginationCursor: null
3262
3545
  });
3263
- }
3264
- indexInParentGroups.push(indexInGroup);
3265
- parents.push(enhancedGroupData);
3266
- if (!collapsed) {
3267
- if (!next) {
3268
- if (!pivot) {
3269
- const startIndex = result.length;
3270
- result.push(...items.map((item, index) => {
3271
- return {
3272
- id: toPrimaryKey(item),
3273
- data: item,
3274
- isGroupRow: false,
3275
- collapsed: false,
3276
- groupKeys,
3277
- parents: Array.from(parents),
3278
- indexInParentGroups: [...indexInParentGroups, index],
3279
- indexInGroup: index,
3280
- indexInAll: startIndex + index,
3281
- groupBy: groupByStrings,
3282
- groupNesting,
3283
- groupCount: enhancedGroupData.groupCount
3284
- };
3285
- }));
3286
- }
3287
- } else {
3288
- next();
3546
+ actions.dataParams = dataParams;
3547
+ if (state.livePagination) {
3548
+ requestAnimationFrame(() => {
3549
+ actions.livePaginationCursor = null;
3550
+ });
3551
+ }
3552
+ },
3553
+ pivotBy: (pivotBy, { actions, state }) => {
3554
+ const dataParams = buildDataSourceDataParams(state, {
3555
+ pivotBy,
3556
+ livePaginationCursor: null
3557
+ });
3558
+ actions.dataParams = dataParams;
3559
+ if (state.livePagination) {
3560
+ requestAnimationFrame(() => {
3561
+ actions.livePaginationCursor = null;
3562
+ });
3563
+ }
3564
+ },
3565
+ cursorId: (cursorId, { actions, state }) => {
3566
+ const dataParams = buildDataSourceDataParams(state, {
3567
+ cursorId
3568
+ });
3569
+ actions.dataParams = dataParams;
3570
+ },
3571
+ livePaginationCursor: (livePaginationCursor, { actions, state }) => {
3572
+ const dataParams = buildDataSourceDataParams(state, {
3573
+ livePaginationCursor
3574
+ });
3575
+ actions.dataParams = dataParams;
3576
+ },
3577
+ dataParams: (dataParams, { state }) => {
3578
+ if (shallowEqualObjects(dataParams, state.dataParams, new Set([
3579
+ "changes",
3580
+ "originalDataArray"
3581
+ ]))) {
3582
+ return false;
3289
3583
  }
3584
+ debugDataParams("onDataParamsChange triggered because the following values have changed", dataParams == null ? void 0 : dataParams.changes);
3585
+ return true;
3290
3586
  }
3291
- parents.pop();
3292
- indexInParentGroups.pop();
3293
- });
3294
- return {
3295
- data: result
3296
3587
  };
3297
3588
  }
3298
3589
 
3299
3590
  // src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts
3300
3591
  function prepareColumn(column) {
3301
3592
  const { pivotByAtIndex: pivotByForColumn } = column;
3302
- if (pivotByForColumn.column) {
3593
+ if (pivotByForColumn == null ? void 0 : pivotByForColumn.column) {
3303
3594
  if (typeof pivotByForColumn.column === "function") {
3304
3595
  Object.assign(column, pivotByForColumn.column({ column }));
3305
3596
  } else {
@@ -3310,7 +3601,7 @@ function prepareColumn(column) {
3310
3601
  }
3311
3602
  function prepareColumnGroup(columnGroup) {
3312
3603
  const { pivotByAtIndex: pivotByForColumnGroup } = columnGroup;
3313
- if (pivotByForColumnGroup.columnGroup) {
3604
+ if (pivotByForColumnGroup == null ? void 0 : pivotByForColumnGroup.columnGroup) {
3314
3605
  if (typeof pivotByForColumnGroup.columnGroup === "function") {
3315
3606
  Object.assign(columnGroup, pivotByForColumnGroup.columnGroup({ columnGroup }));
3316
3607
  } else {
@@ -3339,6 +3630,9 @@ function getPivotColumnsAndColumnGroups({
3339
3630
  valueGetter: (params) => {
3340
3631
  var _a;
3341
3632
  const { rowInfo } = params;
3633
+ if (!rowInfo.data) {
3634
+ return "Loading ... TODO replace this with a loading indicator";
3635
+ }
3342
3636
  return rowInfo.groupKeys ? rowInfo.groupKeys[((_a = rowInfo.groupKeys) == null ? void 0 : _a.length) - 1] : null;
3343
3637
  }
3344
3638
  }
@@ -3370,7 +3664,7 @@ function getPivotColumnsAndColumnGroups({
3370
3664
  }));
3371
3665
  }
3372
3666
  aggregationReducers.forEach((reducer, index) => {
3373
- const header = isSingleAggregationColumn ? keys[keys.length - 1] : reducer.id;
3667
+ const header = isSingleAggregationColumn ? keys[keys.length - 1] : reducer.name || reducer.id;
3374
3668
  const computedPivotColumn = prepareColumn({
3375
3669
  pivotBy,
3376
3670
  pivotColumn: true,
@@ -3389,7 +3683,7 @@ function getPivotColumnsAndColumnGroups({
3389
3683
  return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
3390
3684
  }
3391
3685
  });
3392
- const columnId = `${keys.join("/")}-${reducer.id}`;
3686
+ const columnId = `${reducer.id}:${keys.join("/")}`;
3393
3687
  columns.set(columnId, computedPivotColumn);
3394
3688
  });
3395
3689
  } else {
@@ -3422,7 +3716,7 @@ function getPivotColumnsAndColumnGroups({
3422
3716
  }));
3423
3717
  }
3424
3718
  aggregationReducers.forEach((reducer, index) => {
3425
- const header = isSingleAggregationColumn ? `${keys[keys.length - 1]} total ` : `${reducer.id} total`;
3719
+ const header = isSingleAggregationColumn ? `${keys[keys.length - 1]} total ` : `${reducer.name || reducer.id} total`;
3426
3720
  const computedPivotColumn = prepareColumn({
3427
3721
  columnGroup: columnGroupId,
3428
3722
  header,
@@ -3441,7 +3735,7 @@ function getPivotColumnsAndColumnGroups({
3441
3735
  return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
3442
3736
  }
3443
3737
  });
3444
- columns.set(`total:${keys.join("/")}-${reducer.id}`, computedPivotColumn);
3738
+ columns.set(`total:${reducer.id}:${keys.join("/")}`, computedPivotColumn);
3445
3739
  });
3446
3740
  }
3447
3741
  }
@@ -3450,15 +3744,22 @@ function getPivotColumnsAndColumnGroups({
3450
3744
  }
3451
3745
  });
3452
3746
  if (columns.size === 1) {
3453
- columns.set("single", {
3454
- header: "Reduced",
3455
- pivotBy,
3456
- pivotColumn: true,
3457
- valueGetter: ({ rowInfo }) => {
3458
- var _a;
3459
- const key = Object.keys(rowInfo.reducerResults || {})[0];
3460
- return (_a = rowInfo.reducerResults) == null ? void 0 : _a[key];
3461
- }
3747
+ aggregationReducers.forEach((reducer, index) => {
3748
+ columns.set(`total:${reducer.id}`, prepareColumn({
3749
+ header: `${reducer.name || reducer.id} total`,
3750
+ pivotBy,
3751
+ pivotColumn: true,
3752
+ pivotTotalColumn: true,
3753
+ pivotAggregator: reducer,
3754
+ pivotAggregatorIndex: index,
3755
+ pivotGroupKeys: [],
3756
+ pivotGroupKey: "",
3757
+ pivotIndex: -1,
3758
+ valueGetter: ({ rowInfo }) => {
3759
+ var _a;
3760
+ return (_a = rowInfo.reducerResults) == null ? void 0 : _a[reducer.id];
3761
+ }
3762
+ }));
3462
3763
  });
3463
3764
  }
3464
3765
  const result = {
@@ -3495,10 +3796,11 @@ function concludeReducer(params) {
3495
3796
  const { state, previousState } = params;
3496
3797
  const sortInfo = state.sortInfo;
3497
3798
  const shouldSort = !!(sortInfo == null ? void 0 : sortInfo.length) && !state.controlledSort;
3498
- const sortDepsChanged = haveDepsChanged(previousState, state, [
3499
- "originalDataArray",
3500
- "sortInfo"
3799
+ const originalDataArrayChanged = haveDepsChanged(previousState, state, [
3800
+ "originalDataArray"
3501
3801
  ]);
3802
+ const sortInfoChanged = haveDepsChanged(previousState, state, ["sortInfo"]);
3803
+ const sortDepsChanged = originalDataArrayChanged || sortInfoChanged;
3502
3804
  const shouldSortAgain = shouldSort && (sortDepsChanged || !state.lastSortDataArray);
3503
3805
  const groupBy = state.groupBy;
3504
3806
  const pivotBy = state.pivotBy;
@@ -3506,6 +3808,7 @@ function concludeReducer(params) {
3506
3808
  const groupsDepsChanged = haveDepsChanged(previousState, state, [
3507
3809
  "generateGroupRows",
3508
3810
  "originalDataArray",
3811
+ "originalLazyGroupData",
3509
3812
  "groupBy",
3510
3813
  "groupRowsState",
3511
3814
  "pivotBy",
@@ -3530,7 +3833,12 @@ function concludeReducer(params) {
3530
3833
  };
3531
3834
  if (shouldGroup) {
3532
3835
  if (shouldGroupAgain) {
3533
- const groupResult = group({
3836
+ const groupResult = state.fullLazyLoad ? lazyGroup({
3837
+ groupBy,
3838
+ pivot: pivotBy,
3839
+ mappings: state.pivotMappings,
3840
+ reducers: state.aggregationReducers
3841
+ }, state.originalLazyGroupData) : group({
3534
3842
  groupBy,
3535
3843
  pivot: pivotBy,
3536
3844
  reducers: state.aggregationReducers
@@ -3598,6 +3906,7 @@ var DataSourceRoot = getComponentStateRoot({
3598
3906
  forwardProps: forwardProps3,
3599
3907
  concludeReducer,
3600
3908
  mapPropsToState: mapPropsToState2,
3909
+ onPropChange,
3601
3910
  interceptActions: getInterceptActions()
3602
3911
  });
3603
3912
  function DataSourceCmp({ children }) {
@@ -3629,16 +3938,22 @@ function DataSource(props) {
3629
3938
  function useToggleGroupRow() {
3630
3939
  const { getState: getDataSourceState, componentActions: dataSourceActions } = useDataSourceContextValue();
3631
3940
  const toggleGroupRow = useCallback4((groupKeys) => {
3632
- const newState = new GroupRowsState(getDataSourceState().groupRowsState);
3941
+ const state = getDataSourceState();
3942
+ const newState = new GroupRowsState(state.groupRowsState);
3633
3943
  newState.toggleGroupRow(groupKeys);
3634
3944
  dataSourceActions.groupRowsState = newState;
3945
+ if (state.fullLazyLoad && newState.isGroupRowExpanded(groupKeys)) {
3946
+ loadData(state.data, state, dataSourceActions, {
3947
+ groupKeys
3948
+ });
3949
+ }
3635
3950
  }, []);
3636
3951
  return toggleGroupRow;
3637
3952
  }
3638
3953
 
3639
3954
  // src/components/InfiniteTable/hooks/useColumnsWhen.ts
3640
3955
  function useGroupByMap(groupBy) {
3641
- const groupByMap = useMemo5(() => {
3956
+ const groupByMap = useMemo4(() => {
3642
3957
  return groupBy.reduce((acc, groupBy2, index) => {
3643
3958
  acc.set(groupBy2.field, {
3644
3959
  groupBy: groupBy2,
@@ -3826,7 +4141,7 @@ function useHideEmptyGroupColumns(groupRowsMap) {
3826
4141
  const currentState = getComponentState();
3827
4142
  const { computedColumns } = currentState;
3828
4143
  let updated = false;
3829
- const columnVisibility = new Map(currentState.columnVisibility);
4144
+ const columnVisibility = __spreadValues({}, currentState.columnVisibility);
3830
4145
  const cols = computedColumns;
3831
4146
  groupBy.forEach(({ field, column: groupColumn }, index) => {
3832
4147
  const colId = (groupColumn == null ? void 0 : groupColumn.id) || `group-by-${field}`;
@@ -3837,9 +4152,9 @@ function useHideEmptyGroupColumns(groupRowsMap) {
3837
4152
  const shouldBeHidden = index > expandedGroupsLevel && hideEmptyGroupColumns;
3838
4153
  updated = true;
3839
4154
  if (shouldBeHidden) {
3840
- columnVisibility.set(colId, false);
4155
+ columnVisibility[colId] = false;
3841
4156
  } else {
3842
- columnVisibility.delete(colId);
4157
+ delete columnVisibility[colId];
3843
4158
  }
3844
4159
  });
3845
4160
  if (updated) {
@@ -3902,7 +4217,8 @@ function useComputed() {
3902
4217
  const { componentActions, componentState } = useComponentState();
3903
4218
  const {
3904
4219
  componentActions: dataSourceActions,
3905
- componentState: dataSourceState
4220
+ componentState: dataSourceState,
4221
+ getState: getDataSourceState
3906
4222
  } = useDataSourceContextValue();
3907
4223
  const {
3908
4224
  columnOrder,
@@ -3935,7 +4251,7 @@ function useComputed() {
3935
4251
  var _a2;
3936
4252
  const newSortInfo = multiSort ? sortInfo : (_a2 = sortInfo[0]) != null ? _a2 : null;
3937
4253
  dataSourceActions.sortInfo = newSortInfo;
3938
- }, []);
4254
+ }, [getDataSourceState]);
3939
4255
  const columns = componentState.computedColumns;
3940
4256
  const {
3941
4257
  computedColumnOrder,
@@ -4189,7 +4505,7 @@ var InfiniteTableCell = memo3(InfiniteTableCellFn);
4189
4505
  var import_binary_search = __toModule(require_binary_search());
4190
4506
  import {
4191
4507
  useCallback as useCallback6,
4192
- useMemo as useMemo6,
4508
+ useMemo as useMemo5,
4193
4509
  useRef as useRef7,
4194
4510
  useState as useState6
4195
4511
  } from "react";
@@ -4236,8 +4552,8 @@ var useColumnPointerEvents = ({
4236
4552
  const dragging = draggingDiff != null;
4237
4553
  const { componentActions, computed } = useInfiniteTable();
4238
4554
  const { computedColumnOrder } = computed;
4239
- const column = useMemo6(() => columns.get(columnId), [columnId, columns]);
4240
- const { columnIndex, columnWidth, columnsArray } = useMemo6(() => {
4555
+ const column = useMemo5(() => columns.get(columnId), [columnId, columns]);
4556
+ const { columnIndex, columnWidth, columnsArray } = useMemo5(() => {
4241
4557
  const columnsArray2 = Array.from(columns.values());
4242
4558
  return {
4243
4559
  columnsArray: columnsArray2,
@@ -4560,10 +4876,10 @@ import {
4560
4876
  createElement as createElement12,
4561
4877
  memo as memo4
4562
4878
  } from "react";
4563
- import { useLayoutEffect as useLayoutEffect4, useState as useState8 } from "react";
4879
+ import { useLayoutEffect as useLayoutEffect3, useState as useState8 } from "react";
4564
4880
  function AvoidReactDiffFn(props) {
4565
4881
  const [children, setChildren] = useState8(props.updater.get());
4566
- useLayoutEffect4(() => {
4882
+ useLayoutEffect3(() => {
4567
4883
  const remove = props.updater.onChange((children2) => {
4568
4884
  setChildren(children2);
4569
4885
  });
@@ -4574,7 +4890,7 @@ function AvoidReactDiffFn(props) {
4574
4890
  var AvoidReactDiff = memo4(AvoidReactDiffFn);
4575
4891
 
4576
4892
  // src/components/RawList/useVirtualRenderer.ts
4577
- import { useMemo as useMemo7 } from "react";
4893
+ import { useMemo as useMemo6 } from "react";
4578
4894
 
4579
4895
  // src/components/RawList/ReactVirtualRenderer.tsx
4580
4896
  import {
@@ -4890,7 +5206,7 @@ function createRenderer(brain) {
4890
5206
  function useVirtualRenderer({
4891
5207
  brain
4892
5208
  }) {
4893
- return useMemo7(() => {
5209
+ return useMemo6(() => {
4894
5210
  return createRenderer(brain);
4895
5211
  }, [brain]);
4896
5212
  }
@@ -4982,7 +5298,7 @@ var InfiniteTableHeader = memo6(InfiniteTableHeaderFn);
4982
5298
  import {
4983
5299
  createElement as createElement18,
4984
5300
  memo as memo7,
4985
- useMemo as useMemo8,
5301
+ useMemo as useMemo7,
4986
5302
  useRef as useRef10
4987
5303
  } from "react";
4988
5304
 
@@ -5196,7 +5512,7 @@ function InfiniteTableHeaderUnvirtualizedFn(props) {
5196
5512
  } = useInfiniteTable();
5197
5513
  const domRef = useRef10(null);
5198
5514
  const hasColumnGroups = computedColumnGroups.size > 0;
5199
- const columnHeaderGroups = useMemo8(() => {
5515
+ const columnHeaderGroups = useMemo7(() => {
5200
5516
  return hasColumnGroups ? renderColumnHeaderGroups({
5201
5517
  columnGroups: computedColumnGroups,
5202
5518
  columnGroupsDepthsMap,
@@ -5281,6 +5597,9 @@ function TableHeaderWrapper(props) {
5281
5597
  const hasPinnedStart = computedPinnedStartColumns.length > 0;
5282
5598
  const hasPinnedEnd = computedPinnedEndColumns.length > 0;
5283
5599
  const height = columnGroupsMaxDepth ? columnGroupsMaxDepth * headerHeight : headerHeight;
5600
+ const unvirtualizedStyle = !virtualizeHeader && computedPinnedStartColumnsWidth ? {
5601
+ left: computedPinnedStartWidth
5602
+ } : void 0;
5284
5603
  const header = virtualizeHeader ? /* @__PURE__ */ createElement19(InfiniteTableHeader, {
5285
5604
  columns: computedUnpinnedColumns,
5286
5605
  repaintId: virtualizeHeader ? repaintId : void 0,
@@ -5295,6 +5614,7 @@ function TableHeaderWrapper(props) {
5295
5614
  availableWidth: computedUnpinnedColumnsWidth,
5296
5615
  totalWidth: computedUnpinnedColumnsWidth
5297
5616
  }) : /* @__PURE__ */ createElement19(InfiniteTableHeaderUnvirtualized, {
5617
+ style: unvirtualizedStyle,
5298
5618
  brain,
5299
5619
  scrollable: true,
5300
5620
  pinning: false,
@@ -5603,6 +5923,9 @@ function InfiniteTableColumnCellFn(props) {
5603
5923
  }
5604
5924
  const { data, isGroupRow, groupBy } = rowInfo;
5605
5925
  const groupRowInfo = null;
5926
+ if (rowInfo.indexInAll === 0 && column.groupByField && column.groupByField === "stack") {
5927
+ debugger;
5928
+ }
5606
5929
  let value = isGroupRow && groupBy && column.groupByField ? rowInfo.value : isColumnWithField(column) ? data == null ? void 0 : data[column.field] : null;
5607
5930
  if (column.valueGetter) {
5608
5931
  value = column.valueGetter(isGroupRow ? {
@@ -6001,7 +6324,6 @@ var PinnedRowsClsVariants = { pinnedStart: "_1yeub2ve", pinnedEnd: "_1yeub2vf",
6001
6324
  var PinnedRowsContainerClsVariants = (0, import_createRuntimeFn5.createRuntimeFn)({ defaultClassName: "", variantClassNames: { pinned: { start: "_1yeub2vh", end: "_1yeub2vi", false: "_1yeub2vj" } }, defaultVariants: {}, compoundVariants: [] });
6002
6325
 
6003
6326
  // src/components/InfiniteTable/hooks/useOnContainerScroll.ts
6004
- var DELAY = 200;
6005
6327
  var TableClassName = internalProps.rootClassName;
6006
6328
  var TableClassName__Scrolling = `${TableClassName}--scrolling`;
6007
6329
  var SCROLL_BOTTOM_OFFSET = 1;
@@ -6012,15 +6334,25 @@ var useOnContainerScroll = ({
6012
6334
  }) => {
6013
6335
  const {
6014
6336
  componentState: {
6337
+ scrollStopDelay,
6015
6338
  scrollerDOMRef,
6016
6339
  domRef,
6017
6340
  scrollToBottomOffset,
6018
6341
  onScrollToBottom,
6019
6342
  onScrollToTop,
6343
+ onScrollStop: onScrollStopFromProps,
6020
6344
  bodySize
6021
6345
  }
6022
6346
  } = useInfiniteTable();
6023
- const { componentActions: dataSourceActions, getState: getDataSourceState } = useDataSourceContextValue();
6347
+ const {
6348
+ componentActions: dataSourceActions,
6349
+ getState: getDataSourceState,
6350
+ componentState: { notifyScrollStop }
6351
+ } = useDataSourceContextValue();
6352
+ const onScrollStop = useCallback13((param) => {
6353
+ onScrollStopFromProps == null ? void 0 : onScrollStopFromProps(param);
6354
+ notifyScrollStop(param);
6355
+ }, [onScrollStopFromProps, notifyScrollStop]);
6024
6356
  const timeoutIdRef = useRef15(0);
6025
6357
  const scrollingRef = useRef15(false);
6026
6358
  const scrollTopMaxRef = useRef15(0);
@@ -6039,9 +6371,17 @@ var useOnContainerScroll = ({
6039
6371
  timeoutIdRef.current = setTimeout(() => {
6040
6372
  setScrolling(false);
6041
6373
  timeoutIdRef.current = 0;
6042
- }, DELAY);
6374
+ }, scrollStopDelay);
6043
6375
  }
6044
6376
  if (prevScrolling !== scrolling) {
6377
+ if (!scrolling) {
6378
+ const range = verticalVirtualBrain.getRenderRange();
6379
+ onScrollStop({
6380
+ scrollTop: scrollPositionRef.current.scrollTop,
6381
+ firstVisibleRowIndex: range.renderStartIndex,
6382
+ lastVisibleRowIndex: range.renderEndIndex
6383
+ });
6384
+ }
6045
6385
  const classList = (_a = domRef.current) == null ? void 0 : _a.classList;
6046
6386
  if (!classList) {
6047
6387
  return;
@@ -6052,7 +6392,7 @@ var useOnContainerScroll = ({
6052
6392
  classList.remove(InfiniteClsScrolling, TableClassName__Scrolling);
6053
6393
  }
6054
6394
  }
6055
- }, []);
6395
+ }, [scrollStopDelay, onScrollStop]);
6056
6396
  const onContainerScroll = useCallback13((scrollInfo) => {
6057
6397
  verticalVirtualBrain.setScrollPosition(scrollInfo);
6058
6398
  horizontalVirtualBrain.setScrollPosition(scrollInfo);
@@ -6082,7 +6422,7 @@ var useOnContainerScroll = ({
6082
6422
  if (isScrollBottom) {
6083
6423
  onScrollToBottom == null ? void 0 : onScrollToBottom();
6084
6424
  if (getDataSourceState().livePagination) {
6085
- dataSourceActions.scrollBottomId = Date.now();
6425
+ dataSourceActions.cursorId = Date.now();
6086
6426
  }
6087
6427
  }
6088
6428
  }, [onContainerScroll, scrollToBottomOffset, onScrollToBottom, onScrollToTop]);
@@ -6095,7 +6435,7 @@ var useOnContainerScroll = ({
6095
6435
  // src/components/InfiniteTable/hooks/usePinnedRendering.tsx
6096
6436
  import {
6097
6437
  createElement as createElement29,
6098
- useMemo as useMemo9
6438
+ useMemo as useMemo8
6099
6439
  } from "react";
6100
6440
  import { useCallback as useCallback15 } from "react";
6101
6441
 
@@ -6201,7 +6541,7 @@ function PinnedRowsContainer(props) {
6201
6541
  brain,
6202
6542
  renderRow
6203
6543
  } = props;
6204
- const style = useMemo9(() => {
6544
+ const style = useMemo8(() => {
6205
6545
  const result = pinning === "end" ? {
6206
6546
  width: rowWidth,
6207
6547
  height,
@@ -6374,6 +6714,15 @@ function usePinnedStartRendering(params) {
6374
6714
  // src/components/InfiniteTable/hooks/useYourBrain.ts
6375
6715
  import { useEffect as useEffect21 } from "react";
6376
6716
 
6717
+ // src/components/hooks/useOnce.ts
6718
+ import { useMemo as useMemo9 } from "react";
6719
+ function useOnce(fn) {
6720
+ const onceFn = useMemo9(() => {
6721
+ return once(fn);
6722
+ }, []);
6723
+ return onceFn();
6724
+ }
6725
+
6377
6726
  // src/components/VirtualBrain/index.ts
6378
6727
  var import_binary_search2 = __toModule(require_binary_search());
6379
6728
  var initialScrollPosition2 = {
@@ -7269,7 +7618,7 @@ var useLicense = (licenseKey = "") => {
7269
7618
  const valid = useMemo11(() => {
7270
7619
  let valid2 = isValidLicense(licenseKey, {
7271
7620
  publishedAt: 1624970570587,
7272
- version: "0.1.1"
7621
+ version: "0.2.0"
7273
7622
  });
7274
7623
  if (!licenseKey && !valid2 && isInsideSandbox) {
7275
7624
  return true;
@@ -7283,7 +7632,7 @@ var useLicense = (licenseKey = "") => {
7283
7632
  import {
7284
7633
  createElement as createElement31,
7285
7634
  useCallback as useCallback19,
7286
- useLayoutEffect as useLayoutEffect5
7635
+ useLayoutEffect as useLayoutEffect4
7287
7636
  } from "react";
7288
7637
  import { useRef as useRef19 } from "react";
7289
7638
  var error = err("CSSVariableWatch");
@@ -7306,7 +7655,7 @@ var useCSSVariableWatch = (params) => {
7306
7655
  }
7307
7656
  }, [params.onChange]);
7308
7657
  useResizeObserver(params.ref, onResize, { earlyAttach: true });
7309
- useLayoutEffect5(() => {
7658
+ useLayoutEffect4(() => {
7310
7659
  const value = params.ref.current.getBoundingClientRect().height;
7311
7660
  if (value) {
7312
7661
  lastValueRef.current = value;
@@ -7508,7 +7857,7 @@ var InfiniteTableComponent = memo13(function InfiniteTableComponent2() {
7508
7857
  const licenseValid = useLicense(licenseKey);
7509
7858
  const domProps = useDOMProps(componentState.domProps);
7510
7859
  const LoadMaskCmp = (_a = components == null ? void 0 : components.LoadMask) != null ? _a : LoadMask;
7511
- useLayoutEffect6(() => {
7860
+ useLayoutEffect5(() => {
7512
7861
  const dataSourceState = getDataSourceState();
7513
7862
  const { onScrollbarsChange } = getInfiniteTableState();
7514
7863
  const { notifyScrollbarsChange } = dataSourceState;
@@ -7614,5 +7963,6 @@ export {
7614
7963
  interceptMap,
7615
7964
  multisort,
7616
7965
  useComponentState,
7617
- useDataSource
7966
+ useDataSource,
7967
+ useEffectWithChanges
7618
7968
  };