@infinite-table/infinite-react 0.1.1 → 0.1.2

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.
Files changed (4) hide show
  1. package/index.d.ts +23 -12
  2. package/index.esm.js +79 -37
  3. package/index.js +79 -37
  4. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -158,7 +158,7 @@ declare module "components/hooks/useComponentState" {
158
158
  type ComponentStateRootConfig<T_PROPS, COMPONENT_MAPPED_STATE, COMPONENT_SETUP_STATE = {}, COMPONENT_DERIVED_STATE = {}, T_ACTIONS = {}, T_PARENT_STATE = {}> = {
159
159
  debugName?: string;
160
160
  initSetupState?: () => COMPONENT_SETUP_STATE;
161
- forwardProps?: () => ForwardPropsToStateFnResult<T_PROPS, COMPONENT_MAPPED_STATE>;
161
+ forwardProps?: (setupState: COMPONENT_SETUP_STATE) => ForwardPropsToStateFnResult<T_PROPS, COMPONENT_MAPPED_STATE>;
162
162
  allowedControlledPropOverrides?: Record<keyof T_PROPS, true>;
163
163
  interceptActions?: ComponentInterceptedActions<COMPONENT_MAPPED_STATE & COMPONENT_DERIVED_STATE & COMPONENT_SETUP_STATE>;
164
164
  mapPropsToState?: (params: {
@@ -212,7 +212,9 @@ declare module "components/DataSource/types" {
212
212
  groupBy?: DataSourcePropGroupBy<T>;
213
213
  pivotBy?: DataSourcePropPivotBy<T>;
214
214
  livePaginationCursor?: DataSourceLivePaginationCursorValue;
215
+ changes?: DataSourceDataParamsChanges<T>;
215
216
  }
217
+ export type DataSourceDataParamsChanges<T> = Record<keyof Omit<DataSourceDataParams<T>, 'originalDataArray' | 'changes'>, true>;
216
218
  export type DataSourceSingleSortInfo<T> = MultisortInfo<T> & {
217
219
  field?: keyof T;
218
220
  id?: string;
@@ -235,7 +237,6 @@ declare module "components/DataSource/types" {
235
237
  export interface DataSourceMappedState<T> {
236
238
  aggregationReducers?: DataSourceProps<T>['aggregationReducers'];
237
239
  livePagination: DataSourceProps<T>['livePagination'];
238
- livePaginationCursor: DataSourceProps<T>['livePaginationCursor'];
239
240
  onDataParamsChange: DataSourceProps<T>['onDataParamsChange'];
240
241
  data: DataSourceProps<T>['data'];
241
242
  primaryKey: DataSourceProps<T>['primaryKey'];
@@ -253,6 +254,7 @@ declare module "components/DataSource/types" {
253
254
  done?: (accumulatedValue: AggregationResultType | any, array: T[]) => AggregationResultType;
254
255
  };
255
256
  export interface DataSourceSetupState<T> {
257
+ propsCache: Map<keyof DataSourceProps<T>, WeakMap<any, any>>;
256
258
  showSeparatePivotColumnForSingleAggregation: boolean;
257
259
  dataParams?: DataSourceDataParams<T>;
258
260
  notifyScrollbarsChange: SubscriptionCallback<Scrollbars>;
@@ -298,14 +300,23 @@ declare module "components/DataSource/types" {
298
300
  onSortInfoChange?: ((sortInfo: DataSourceSingleSortInfo<T> | null) => void) | ((sortInfo: DataSourceSingleSortInfo<T>[]) => void);
299
301
  onDataParamsChange?: (dataParamsChange: DataSourceDataParams<T>) => void;
300
302
  livePagination?: boolean;
301
- livePaginationCursor?: DataSourceLivePaginationCursorValue;
303
+ livePaginationCursor?: DataSourcePropLivePaginationCursor<T>;
304
+ onLivePaginationCursorChange?: (livePaginationCursor: DataSourceLivePaginationCursorValue) => void;
302
305
  }
303
- export type DataSourceLivePaginationCursorValue = string | number;
306
+ export type DataSourcePropLivePaginationCursor<T> = DataSourceLivePaginationCursorValue | DataSourceLivePaginationCursorFn<T>;
307
+ export type DataSourceLivePaginationCursorFn<T> = (params: DataSourceLivePaginationCursorParams<T>) => DataSourceLivePaginationCursorValue;
308
+ export type DataSourceLivePaginationCursorParams<T> = {
309
+ array: T[];
310
+ lastItem: T | Partial<T> | null;
311
+ length: number;
312
+ };
313
+ export type DataSourceLivePaginationCursorValue = string | number | null;
304
314
  export interface DataSourceState<T> extends DataSourceSetupState<T>, DataSourceDerivedState<T>, DataSourceMappedState<T> {
305
315
  }
306
316
  export interface DataSourceDerivedState<_T> {
307
317
  multiSort: boolean;
308
318
  controlledSort: boolean;
319
+ livePaginationCursor?: DataSourceLivePaginationCursorValue;
309
320
  }
310
321
  export type DataSourceComponentActions<T> = ComponentStateActions<DataSourceState<T>>;
311
322
  export interface DataSourceContextValue<T> {
@@ -341,14 +352,14 @@ declare module "components/hooks/useEffectWithChanges" {
341
352
  export function useEffectWithObject(fn: EffectCallback, deps: Record<string, any>): void;
342
353
  }
343
354
  declare module "components/DataSource/privateHooks/useLoadData" {
344
- import { DataSourceDataParams, DataSourceState } from "components/DataSource/types";
345
- export function buildDataSourceDataParams<T>(componentState: DataSourceState<T>): DataSourceDataParams<T>;
355
+ import { DataSourceDataParams, DataSourceState, DataSourceDataParamsChanges } from "components/DataSource/types";
356
+ export function buildDataSourceDataParams<T>(componentState: DataSourceState<T>, changes?: DataSourceDataParamsChanges<T>): DataSourceDataParams<T>;
346
357
  export function useLoadData<T>(): void;
347
358
  export function useLivePagination<T>(): void;
348
359
  }
349
360
  declare module "components/DataSource/state/normalizeSortInfo" {
350
361
  import { DataSourceSingleSortInfo, DataSourceSortInfo } from "components/DataSource/types";
351
- export const normalizeSortInfo: <T>(sortInfo?: DataSourceSortInfo<T> | undefined) => DataSourceSingleSortInfo<T>[];
362
+ export const normalizeSortInfo: <T>(initialSortInfo?: DataSourceSortInfo<T> | undefined, weakMap?: WeakMap<any, any> | undefined) => DataSourceSingleSortInfo<T>[];
352
363
  }
353
364
  declare module "components/utils/buildSubscriptionCallback" {
354
365
  import { SubscriptionCallback } from "components/types/SubscriptionCallback";
@@ -366,18 +377,17 @@ declare module "components/DataSource/state/getInitialState" {
366
377
  import { ComponentInterceptedActions, ForwardPropsToStateFnResult } from "components/hooks/useComponentState";
367
378
  import { DataSourceDataParams } from "components/DataSource/index";
368
379
  export function initSetupState<T>(): DataSourceSetupState<T>;
369
- export const forwardProps: <T>() => Partial<{
380
+ export const forwardProps: <T>(setupState: DataSourceSetupState<T>) => Partial<{
370
381
  data: 1 | ((value: import("components/DataSource").DataSourceData<T>) => import("components/DataSource").DataSourceData<T>);
371
382
  loading: 1 | ((value: boolean | undefined) => boolean);
383
+ sortInfo: 1 | ((value: import("components/DataSource").DataSourceSortInfo<T> | undefined) => import("components/DataSource").DataSourceSingleSortInfo<T>[] | null);
384
+ groupBy: 1 | ((value: import("components/DataSource").DataSourcePropGroupBy<T> | undefined) => import("components/DataSource").DataSourcePropGroupBy<T>);
385
+ pivotBy: 1 | ((value: import("components/DataSource").DataSourcePropPivotBy<T> | undefined) => import("components/DataSource").DataSourcePropPivotBy<T> | undefined);
372
386
  aggregationReducers: 1 | ((value: import("components/DataSource").DataSourcePropAggregationReducers<T> | undefined) => import("components/DataSource").DataSourcePropAggregationReducers<T> | undefined);
373
387
  livePagination: 1 | ((value: boolean | undefined) => boolean | undefined);
374
- livePaginationCursor: 1 | ((value: import("components/DataSource").DataSourceLivePaginationCursorValue | undefined) => import("components/DataSource").DataSourceLivePaginationCursorValue | undefined);
375
388
  onDataParamsChange: 1 | ((value: ((dataParamsChange: DataSourceDataParams<T>) => void) | undefined) => ((dataParamsChange: DataSourceDataParams<T>) => void) | undefined);
376
389
  primaryKey: 1 | ((value: keyof T) => keyof T);
377
- groupBy: 1 | ((value: import("components/DataSource").DataSourcePropGroupBy<T> | undefined) => import("components/DataSource").DataSourcePropGroupBy<T>);
378
390
  groupRowsState: 1 | ((value: GroupRowsState<any> | undefined) => GroupRowsState<any>);
379
- pivotBy: 1 | ((value: import("components/DataSource").DataSourcePropPivotBy<T> | undefined) => import("components/DataSource").DataSourcePropPivotBy<T> | undefined);
380
- sortInfo: 1 | ((value: import("components/DataSource").DataSourceSortInfo<T> | undefined) => import("components/DataSource").DataSourceSingleSortInfo<T>[] | null);
381
391
  }>;
382
392
  export function mapPropsToState<T extends any>(params: {
383
393
  props: DataSourceProps<T>;
@@ -3118,4 +3128,5 @@ declare module "@infinite-table/infinite-react" {
3118
3128
  export { group, flatten } from "utils/groupAndPivot/index";
3119
3129
  export { useComponentState, getComponentStateRoot, } from "components/hooks/useComponentState";
3120
3130
  export { interceptMap } from "components/hooks/useInterceptedMap";
3131
+ export { useEffectWithChanges } from "components/hooks/useEffectWithChanges";
3121
3132
  }
package/index.esm.js CHANGED
@@ -193,11 +193,11 @@ var require_common = __commonJS({
193
193
  let enableOverride = null;
194
194
  let namespacesCache;
195
195
  let enabledCache;
196
- function debug6(...args) {
197
- if (!debug6.enabled) {
196
+ function debug7(...args) {
197
+ if (!debug7.enabled) {
198
198
  return;
199
199
  }
200
- const self = debug6;
200
+ const self = debug7;
201
201
  const curr = Number(new Date());
202
202
  const ms = curr - (prevTime || curr);
203
203
  self.diff = ms;
@@ -227,12 +227,12 @@ var require_common = __commonJS({
227
227
  const logFn = self.log || createDebug.log;
228
228
  logFn.apply(self, args);
229
229
  }
230
- debug6.namespace = namespace;
231
- debug6.useColors = createDebug.useColors();
232
- debug6.color = createDebug.selectColor(namespace);
233
- debug6.extend = extend;
234
- debug6.destroy = createDebug.destroy;
235
- Object.defineProperty(debug6, "enabled", {
230
+ debug7.namespace = namespace;
231
+ debug7.useColors = createDebug.useColors();
232
+ debug7.color = createDebug.selectColor(namespace);
233
+ debug7.extend = extend;
234
+ debug7.destroy = createDebug.destroy;
235
+ Object.defineProperty(debug7, "enabled", {
236
236
  enumerable: true,
237
237
  configurable: false,
238
238
  get: () => {
@@ -250,9 +250,9 @@ var require_common = __commonJS({
250
250
  }
251
251
  });
252
252
  if (typeof createDebug.init === "function") {
253
- createDebug.init(debug6);
253
+ createDebug.init(debug7);
254
254
  }
255
- return debug6;
255
+ return debug7;
256
256
  }
257
257
  function extend(namespace, delimiter) {
258
258
  const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
@@ -1798,12 +1798,14 @@ function forwardProps2(propsToForward, props) {
1798
1798
  function getComponentStateRoot(config) {
1799
1799
  return memo(function ComponentStateRoot(props) {
1800
1800
  var _a, _b;
1801
+ const [initialSetupState] = useState2(() => {
1802
+ return config.initSetupState ? config.initSetupState() : {};
1803
+ });
1801
1804
  const propsToStateSetRef = useRef4(new Set());
1802
- const propsToForward = useMemo3(() => config.forwardProps ? config.forwardProps() : {}, []);
1805
+ const propsToForward = useMemo3(() => config.forwardProps ? config.forwardProps(initialSetupState) : {}, [initialSetupState]);
1803
1806
  const parentState = (_b = (_a = config.getParentState) == null ? void 0 : _a.call(config)) != null ? _b : null;
1804
1807
  const getParentState = useLatest(parentState);
1805
1808
  const [wholeState] = useState2(() => {
1806
- const initialSetupState = config.initSetupState ? config.initSetupState() : {};
1807
1809
  let mappedState = {};
1808
1810
  if (propsToForward) {
1809
1811
  mappedState = forwardProps2(propsToForward, props);
@@ -2404,7 +2406,16 @@ function useEffectWithChanges(fn, deps) {
2404
2406
  }
2405
2407
 
2406
2408
  // src/components/DataSource/privateHooks/useLoadData.ts
2407
- function buildDataSourceDataParams(componentState) {
2409
+ var debug3 = dbg("DataSource:useLoadData");
2410
+ function anonimizeValues(arg) {
2411
+ const result = {};
2412
+ for (var k in arg)
2413
+ if (arg.hasOwnProperty(k)) {
2414
+ result[k] = true;
2415
+ }
2416
+ return result;
2417
+ }
2418
+ function buildDataSourceDataParams(componentState, changes) {
2408
2419
  var _a, _b;
2409
2420
  const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
2410
2421
  const dataSourceParams = {
@@ -2416,14 +2427,17 @@ function buildDataSourceDataParams(componentState) {
2416
2427
  if (componentState.livePagination !== void 0) {
2417
2428
  dataSourceParams.livePaginationCursor = componentState.livePaginationCursor;
2418
2429
  }
2430
+ if (changes !== void 0) {
2431
+ dataSourceParams.changes = changes;
2432
+ }
2419
2433
  return dataSourceParams;
2420
2434
  }
2421
- function notifyDataParamsChanged(componentState, actions) {
2435
+ function notifyDataParamsChanged(componentState, actions, changes) {
2422
2436
  var _a;
2423
2437
  if (typeof componentState.data === "function") {
2424
2438
  loadData(componentState.data, componentState, actions);
2425
2439
  }
2426
- const dataParams = buildDataSourceDataParams(componentState);
2440
+ const dataParams = buildDataSourceDataParams(componentState, changes);
2427
2441
  (_a = componentState.onDataParamsChange) == null ? void 0 : _a.call(componentState, dataParams);
2428
2442
  }
2429
2443
  function loadData(data, componentState, actions) {
@@ -2515,20 +2529,32 @@ function useLivePagination() {
2515
2529
  sortInfo,
2516
2530
  groupBy,
2517
2531
  pivotBy,
2518
- cursorId
2532
+ livePaginationCursor: cursorId
2519
2533
  };
2520
- useEffectWithChanges(() => {
2534
+ useEffectWithChanges((changes, prevValues) => {
2521
2535
  if (cursorId === void 0) {
2522
2536
  return;
2523
2537
  }
2524
- notifyDataParamsChanged(getComponentState(), actions);
2538
+ debug3("onDataParamsChange triggered because the following values have changed", changes, "old values", prevValues);
2539
+ notifyDataParamsChanged(getComponentState(), actions, anonimizeValues(changes));
2525
2540
  }, depsObject);
2526
2541
  }
2527
2542
 
2528
2543
  // src/components/DataSource/state/normalizeSortInfo.ts
2529
- var normalizeSortInfo = (sortInfo) => {
2530
- sortInfo = sortInfo != null ? sortInfo : [];
2531
- return Array.isArray(sortInfo) ? sortInfo : [sortInfo];
2544
+ var EMPTY_ARRAY = Object.freeze([]);
2545
+ var normalizeSortInfo = (initialSortInfo, weakMap) => {
2546
+ const sortInfo = initialSortInfo != null ? initialSortInfo : EMPTY_ARRAY;
2547
+ const result = Array.isArray(sortInfo) ? sortInfo : [sortInfo];
2548
+ if (weakMap && weakMap.has(sortInfo)) {
2549
+ const prevResult = weakMap.get(sortInfo);
2550
+ if (prevResult && prevResult.length === result.length) {
2551
+ return prevResult;
2552
+ }
2553
+ }
2554
+ if (weakMap && sortInfo) {
2555
+ weakMap.set(sortInfo, result);
2556
+ }
2557
+ return result;
2532
2558
  };
2533
2559
 
2534
2560
  // src/components/hooks/useOnce.ts
@@ -2978,6 +3004,9 @@ function initSetupState2() {
2978
3004
  originalDataArray,
2979
3005
  scrollBottomId: Symbol("scrollBottomId"),
2980
3006
  showSeparatePivotColumnForSingleAggregation: false,
3007
+ propsCache: new Map([
3008
+ ["sortInfo", new WeakMap()]
3009
+ ]),
2981
3010
  pivotColumns: void 0,
2982
3011
  pivotColumnGroups: void 0,
2983
3012
  dataArray,
@@ -2998,17 +3027,16 @@ function getCompareObject(dataParams) {
2998
3027
  delete obj.originalDataArray;
2999
3028
  return obj;
3000
3029
  }
3001
- var forwardProps3 = () => {
3030
+ var forwardProps3 = (setupState) => {
3002
3031
  return {
3003
3032
  onDataParamsChange: (fn) => fn ? discardCallsWithEqualArg(fn, 100, getCompareObject) : void 0,
3004
3033
  data: 1,
3005
3034
  pivotBy: 1,
3006
3035
  primaryKey: 1,
3007
3036
  livePagination: 1,
3008
- livePaginationCursor: 1,
3009
3037
  aggregationReducers: 1,
3010
3038
  loading: (loading) => loading != null ? loading : false,
3011
- sortInfo: (sortInfo) => normalizeSortInfo(sortInfo),
3039
+ sortInfo: (sortInfo) => normalizeSortInfo(sortInfo, setupState.propsCache.get("sortInfo")),
3012
3040
  groupBy: (groupBy) => groupBy != null ? groupBy : [],
3013
3041
  groupRowsState: (groupRowsState) => {
3014
3042
  return groupRowsState || new GroupRowsState({
@@ -3019,12 +3047,21 @@ var forwardProps3 = () => {
3019
3047
  };
3020
3048
  };
3021
3049
  function mapPropsToState2(params) {
3022
- const { props } = params;
3050
+ const { props, state } = params;
3023
3051
  const controlledSort = isControlledValue(props.sortInfo);
3024
- return {
3052
+ const result = {
3025
3053
  controlledSort,
3026
3054
  multiSort: Array.isArray(controlledSort ? props.sortInfo : props.defaultSortInfo)
3027
3055
  };
3056
+ if (props.livePagination) {
3057
+ const livePaginationCursor = typeof props.livePaginationCursor === "function" ? props.livePaginationCursor({
3058
+ array: state.originalDataArray,
3059
+ length: state.originalDataArray.length,
3060
+ lastItem: state.originalDataArray[state.originalDataArray.length - 1]
3061
+ }) : props.livePaginationCursor;
3062
+ result.livePaginationCursor = livePaginationCursor;
3063
+ }
3064
+ return result;
3028
3065
  }
3029
3066
  function getInterceptActions() {
3030
3067
  return {
@@ -3902,7 +3939,8 @@ function useComputed() {
3902
3939
  const { componentActions, componentState } = useComponentState();
3903
3940
  const {
3904
3941
  componentActions: dataSourceActions,
3905
- componentState: dataSourceState
3942
+ componentState: dataSourceState,
3943
+ getState: getDataSourceState
3906
3944
  } = useDataSourceContextValue();
3907
3945
  const {
3908
3946
  columnOrder,
@@ -3935,7 +3973,10 @@ function useComputed() {
3935
3973
  var _a2;
3936
3974
  const newSortInfo = multiSort ? sortInfo : (_a2 = sortInfo[0]) != null ? _a2 : null;
3937
3975
  dataSourceActions.sortInfo = newSortInfo;
3938
- }, []);
3976
+ if (getDataSourceState().livePagination) {
3977
+ dataSourceActions.livePaginationCursor = null;
3978
+ }
3979
+ }, [getDataSourceState]);
3939
3980
  const columns = componentState.computedColumns;
3940
3981
  const {
3941
3982
  computedColumnOrder,
@@ -4928,7 +4969,7 @@ function RawListFn(props) {
4928
4969
  var RawList = memo5(RawListFn);
4929
4970
 
4930
4971
  // src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx
4931
- var debug3 = dbg("Header");
4972
+ var debug4 = dbg("Header");
4932
4973
  var { rootClassName: rootClassName4 } = internalProps;
4933
4974
  var TableHeaderClassName = `${rootClassName4}Header`;
4934
4975
  function InfiniteTableHeaderFn(props) {
@@ -4942,7 +4983,7 @@ function InfiniteTableHeaderFn(props) {
4942
4983
  const column = columns[columnIndex];
4943
4984
  if (!column) {
4944
4985
  if (true) {
4945
- debug3("Cannot find column to render at ", columnIndex);
4986
+ debug4("Cannot find column to render at ", columnIndex);
4946
4987
  }
4947
4988
  return null;
4948
4989
  }
@@ -5459,7 +5500,7 @@ var scrollTransformTargetCls = "mlx2t3";
5459
5500
  var UPDATE_SCROLL2 = (node, scrollPosition) => {
5460
5501
  node.style.transform = `translate3d(${-scrollPosition.scrollLeft}px, ${-scrollPosition.scrollTop}px, 0px)`;
5461
5502
  };
5462
- var debug4 = dbg("VirtuaList");
5503
+ var debug5 = dbg("VirtuaList");
5463
5504
  var rootClassName7 = "InfiniteList";
5464
5505
  var VirtualList = (props) => {
5465
5506
  const _a = props, {
@@ -5499,7 +5540,7 @@ var VirtualList = (props) => {
5499
5540
  const removeOnRenderCount = virtualBrain.onRenderCountChange((renderCount) => {
5500
5541
  renderCountRef.current = renderCount;
5501
5542
  if (true) {
5502
- debug4.extend(mainAxis)(`Render count change ${renderCount}`);
5543
+ debug5.extend(mainAxis)(`Render count change ${renderCount}`);
5503
5544
  }
5504
5545
  rerender();
5505
5546
  });
@@ -7269,7 +7310,7 @@ var useLicense = (licenseKey = "") => {
7269
7310
  const valid = useMemo11(() => {
7270
7311
  let valid2 = isValidLicense(licenseKey, {
7271
7312
  publishedAt: 1624970570587,
7272
- version: "0.1.1"
7313
+ version: "0.1.2"
7273
7314
  });
7274
7315
  if (!licenseKey && !valid2 && isInsideSandbox) {
7275
7316
  return true;
@@ -7287,7 +7328,7 @@ import {
7287
7328
  } from "react";
7288
7329
  import { useRef as useRef19 } from "react";
7289
7330
  var error = err("CSSVariableWatch");
7290
- var debug5 = dbg("CSSVariableWatch");
7331
+ var debug6 = dbg("CSSVariableWatch");
7291
7332
  var WRAPPER_STYLE = {
7292
7333
  position: "absolute",
7293
7334
  pointerEvents: "none",
@@ -7310,7 +7351,7 @@ var useCSSVariableWatch = (params) => {
7310
7351
  const value = params.ref.current.getBoundingClientRect().height;
7311
7352
  if (value) {
7312
7353
  lastValueRef.current = value;
7313
- debug5(`Variable ${params.varName} found and equals ${value}.`);
7354
+ debug6(`Variable ${params.varName} found and equals ${value}.`);
7314
7355
  params.onChange(value);
7315
7356
  } else {
7316
7357
  error(`Specified variable ${params.varName} not found or does not have a numeric value.`);
@@ -7614,5 +7655,6 @@ export {
7614
7655
  interceptMap,
7615
7656
  multisort,
7616
7657
  useComponentState,
7617
- useDataSource
7658
+ useDataSource,
7659
+ useEffectWithChanges
7618
7660
  };
package/index.js CHANGED
@@ -198,11 +198,11 @@ var require_common = __commonJS({
198
198
  let enableOverride = null;
199
199
  let namespacesCache;
200
200
  let enabledCache;
201
- function debug6(...args) {
202
- if (!debug6.enabled) {
201
+ function debug7(...args) {
202
+ if (!debug7.enabled) {
203
203
  return;
204
204
  }
205
- const self = debug6;
205
+ const self = debug7;
206
206
  const curr = Number(new Date());
207
207
  const ms = curr - (prevTime || curr);
208
208
  self.diff = ms;
@@ -232,12 +232,12 @@ var require_common = __commonJS({
232
232
  const logFn = self.log || createDebug.log;
233
233
  logFn.apply(self, args);
234
234
  }
235
- debug6.namespace = namespace;
236
- debug6.useColors = createDebug.useColors();
237
- debug6.color = createDebug.selectColor(namespace);
238
- debug6.extend = extend;
239
- debug6.destroy = createDebug.destroy;
240
- Object.defineProperty(debug6, "enabled", {
235
+ debug7.namespace = namespace;
236
+ debug7.useColors = createDebug.useColors();
237
+ debug7.color = createDebug.selectColor(namespace);
238
+ debug7.extend = extend;
239
+ debug7.destroy = createDebug.destroy;
240
+ Object.defineProperty(debug7, "enabled", {
241
241
  enumerable: true,
242
242
  configurable: false,
243
243
  get: () => {
@@ -255,9 +255,9 @@ var require_common = __commonJS({
255
255
  }
256
256
  });
257
257
  if (typeof createDebug.init === "function") {
258
- createDebug.init(debug6);
258
+ createDebug.init(debug7);
259
259
  }
260
- return debug6;
260
+ return debug7;
261
261
  }
262
262
  function extend(namespace, delimiter) {
263
263
  const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
@@ -635,7 +635,8 @@ __export(exports, {
635
635
  interceptMap: () => interceptMap,
636
636
  multisort: () => multisort,
637
637
  useComponentState: () => useComponentState,
638
- useDataSource: () => useDataSource
638
+ useDataSource: () => useDataSource,
639
+ useEffectWithChanges: () => useEffectWithChanges
639
640
  });
640
641
 
641
642
  // src/components/InfiniteTable/index.tsx
@@ -1795,12 +1796,14 @@ function forwardProps2(propsToForward, props) {
1795
1796
  function getComponentStateRoot(config) {
1796
1797
  return React2.memo(function ComponentStateRoot(props) {
1797
1798
  var _a, _b;
1799
+ const [initialSetupState] = (0, import_react11.useState)(() => {
1800
+ return config.initSetupState ? config.initSetupState() : {};
1801
+ });
1798
1802
  const propsToStateSetRef = (0, import_react11.useRef)(new Set());
1799
- const propsToForward = (0, import_react11.useMemo)(() => config.forwardProps ? config.forwardProps() : {}, []);
1803
+ const propsToForward = (0, import_react11.useMemo)(() => config.forwardProps ? config.forwardProps(initialSetupState) : {}, [initialSetupState]);
1800
1804
  const parentState = (_b = (_a = config.getParentState) == null ? void 0 : _a.call(config)) != null ? _b : null;
1801
1805
  const getParentState = useLatest(parentState);
1802
1806
  const [wholeState] = (0, import_react11.useState)(() => {
1803
- const initialSetupState = config.initSetupState ? config.initSetupState() : {};
1804
1807
  let mappedState = {};
1805
1808
  if (propsToForward) {
1806
1809
  mappedState = forwardProps2(propsToForward, props);
@@ -2387,7 +2390,16 @@ function useEffectWithChanges(fn, deps) {
2387
2390
  }
2388
2391
 
2389
2392
  // src/components/DataSource/privateHooks/useLoadData.ts
2390
- function buildDataSourceDataParams(componentState) {
2393
+ var debug3 = dbg("DataSource:useLoadData");
2394
+ function anonimizeValues(arg) {
2395
+ const result = {};
2396
+ for (var k in arg)
2397
+ if (arg.hasOwnProperty(k)) {
2398
+ result[k] = true;
2399
+ }
2400
+ return result;
2401
+ }
2402
+ function buildDataSourceDataParams(componentState, changes) {
2391
2403
  var _a, _b;
2392
2404
  const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
2393
2405
  const dataSourceParams = {
@@ -2399,14 +2411,17 @@ function buildDataSourceDataParams(componentState) {
2399
2411
  if (componentState.livePagination !== void 0) {
2400
2412
  dataSourceParams.livePaginationCursor = componentState.livePaginationCursor;
2401
2413
  }
2414
+ if (changes !== void 0) {
2415
+ dataSourceParams.changes = changes;
2416
+ }
2402
2417
  return dataSourceParams;
2403
2418
  }
2404
- function notifyDataParamsChanged(componentState, actions) {
2419
+ function notifyDataParamsChanged(componentState, actions, changes) {
2405
2420
  var _a;
2406
2421
  if (typeof componentState.data === "function") {
2407
2422
  loadData(componentState.data, componentState, actions);
2408
2423
  }
2409
- const dataParams = buildDataSourceDataParams(componentState);
2424
+ const dataParams = buildDataSourceDataParams(componentState, changes);
2410
2425
  (_a = componentState.onDataParamsChange) == null ? void 0 : _a.call(componentState, dataParams);
2411
2426
  }
2412
2427
  function loadData(data, componentState, actions) {
@@ -2498,20 +2513,32 @@ function useLivePagination() {
2498
2513
  sortInfo,
2499
2514
  groupBy,
2500
2515
  pivotBy,
2501
- cursorId
2516
+ livePaginationCursor: cursorId
2502
2517
  };
2503
- useEffectWithChanges(() => {
2518
+ useEffectWithChanges((changes, prevValues) => {
2504
2519
  if (cursorId === void 0) {
2505
2520
  return;
2506
2521
  }
2507
- notifyDataParamsChanged(getComponentState(), actions);
2522
+ debug3("onDataParamsChange triggered because the following values have changed", changes, "old values", prevValues);
2523
+ notifyDataParamsChanged(getComponentState(), actions, anonimizeValues(changes));
2508
2524
  }, depsObject);
2509
2525
  }
2510
2526
 
2511
2527
  // src/components/DataSource/state/normalizeSortInfo.ts
2512
- var normalizeSortInfo = (sortInfo) => {
2513
- sortInfo = sortInfo != null ? sortInfo : [];
2514
- return Array.isArray(sortInfo) ? sortInfo : [sortInfo];
2528
+ var EMPTY_ARRAY = Object.freeze([]);
2529
+ var normalizeSortInfo = (initialSortInfo, weakMap) => {
2530
+ const sortInfo = initialSortInfo != null ? initialSortInfo : EMPTY_ARRAY;
2531
+ const result = Array.isArray(sortInfo) ? sortInfo : [sortInfo];
2532
+ if (weakMap && weakMap.has(sortInfo)) {
2533
+ const prevResult = weakMap.get(sortInfo);
2534
+ if (prevResult && prevResult.length === result.length) {
2535
+ return prevResult;
2536
+ }
2537
+ }
2538
+ if (weakMap && sortInfo) {
2539
+ weakMap.set(sortInfo, result);
2540
+ }
2541
+ return result;
2515
2542
  };
2516
2543
 
2517
2544
  // src/components/hooks/useOnce.ts
@@ -2961,6 +2988,9 @@ function initSetupState2() {
2961
2988
  originalDataArray,
2962
2989
  scrollBottomId: Symbol("scrollBottomId"),
2963
2990
  showSeparatePivotColumnForSingleAggregation: false,
2991
+ propsCache: new Map([
2992
+ ["sortInfo", new WeakMap()]
2993
+ ]),
2964
2994
  pivotColumns: void 0,
2965
2995
  pivotColumnGroups: void 0,
2966
2996
  dataArray,
@@ -2981,17 +3011,16 @@ function getCompareObject(dataParams) {
2981
3011
  delete obj.originalDataArray;
2982
3012
  return obj;
2983
3013
  }
2984
- var forwardProps3 = () => {
3014
+ var forwardProps3 = (setupState) => {
2985
3015
  return {
2986
3016
  onDataParamsChange: (fn) => fn ? discardCallsWithEqualArg(fn, 100, getCompareObject) : void 0,
2987
3017
  data: 1,
2988
3018
  pivotBy: 1,
2989
3019
  primaryKey: 1,
2990
3020
  livePagination: 1,
2991
- livePaginationCursor: 1,
2992
3021
  aggregationReducers: 1,
2993
3022
  loading: (loading) => loading != null ? loading : false,
2994
- sortInfo: (sortInfo) => normalizeSortInfo(sortInfo),
3023
+ sortInfo: (sortInfo) => normalizeSortInfo(sortInfo, setupState.propsCache.get("sortInfo")),
2995
3024
  groupBy: (groupBy) => groupBy != null ? groupBy : [],
2996
3025
  groupRowsState: (groupRowsState) => {
2997
3026
  return groupRowsState || new GroupRowsState({
@@ -3002,12 +3031,21 @@ var forwardProps3 = () => {
3002
3031
  };
3003
3032
  };
3004
3033
  function mapPropsToState2(params) {
3005
- const { props } = params;
3034
+ const { props, state } = params;
3006
3035
  const controlledSort = isControlledValue(props.sortInfo);
3007
- return {
3036
+ const result = {
3008
3037
  controlledSort,
3009
3038
  multiSort: Array.isArray(controlledSort ? props.sortInfo : props.defaultSortInfo)
3010
3039
  };
3040
+ if (props.livePagination) {
3041
+ const livePaginationCursor = typeof props.livePaginationCursor === "function" ? props.livePaginationCursor({
3042
+ array: state.originalDataArray,
3043
+ length: state.originalDataArray.length,
3044
+ lastItem: state.originalDataArray[state.originalDataArray.length - 1]
3045
+ }) : props.livePaginationCursor;
3046
+ result.livePaginationCursor = livePaginationCursor;
3047
+ }
3048
+ return result;
3011
3049
  }
3012
3050
  function getInterceptActions() {
3013
3051
  return {
@@ -3885,7 +3923,8 @@ function useComputed() {
3885
3923
  const { componentActions, componentState } = useComponentState();
3886
3924
  const {
3887
3925
  componentActions: dataSourceActions,
3888
- componentState: dataSourceState
3926
+ componentState: dataSourceState,
3927
+ getState: getDataSourceState
3889
3928
  } = useDataSourceContextValue();
3890
3929
  const {
3891
3930
  columnOrder,
@@ -3918,7 +3957,10 @@ function useComputed() {
3918
3957
  var _a2;
3919
3958
  const newSortInfo = multiSort ? sortInfo : (_a2 = sortInfo[0]) != null ? _a2 : null;
3920
3959
  dataSourceActions.sortInfo = newSortInfo;
3921
- }, []);
3960
+ if (getDataSourceState().livePagination) {
3961
+ dataSourceActions.livePaginationCursor = null;
3962
+ }
3963
+ }, [getDataSourceState]);
3922
3964
  const columns = componentState.computedColumns;
3923
3965
  const {
3924
3966
  computedColumnOrder,
@@ -4878,7 +4920,7 @@ function RawListFn(props) {
4878
4920
  var RawList = React16.memo(RawListFn);
4879
4921
 
4880
4922
  // src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx
4881
- var debug3 = dbg("Header");
4923
+ var debug4 = dbg("Header");
4882
4924
  var { rootClassName: rootClassName4 } = internalProps;
4883
4925
  var TableHeaderClassName = `${rootClassName4}Header`;
4884
4926
  function InfiniteTableHeaderFn(props) {
@@ -4892,7 +4934,7 @@ function InfiniteTableHeaderFn(props) {
4892
4934
  const column = columns[columnIndex];
4893
4935
  if (!column) {
4894
4936
  if (true) {
4895
- debug3("Cannot find column to render at ", columnIndex);
4937
+ debug4("Cannot find column to render at ", columnIndex);
4896
4938
  }
4897
4939
  return null;
4898
4940
  }
@@ -5386,7 +5428,7 @@ var scrollTransformTargetCls = "mlx2t3";
5386
5428
  var UPDATE_SCROLL2 = (node, scrollPosition) => {
5387
5429
  node.style.transform = `translate3d(${-scrollPosition.scrollLeft}px, ${-scrollPosition.scrollTop}px, 0px)`;
5388
5430
  };
5389
- var debug4 = dbg("VirtuaList");
5431
+ var debug5 = dbg("VirtuaList");
5390
5432
  var rootClassName7 = "InfiniteList";
5391
5433
  var VirtualList = (props) => {
5392
5434
  const _a = props, {
@@ -5426,7 +5468,7 @@ var VirtualList = (props) => {
5426
5468
  const removeOnRenderCount = virtualBrain.onRenderCountChange((renderCount) => {
5427
5469
  renderCountRef.current = renderCount;
5428
5470
  if (true) {
5429
- debug4.extend(mainAxis)(`Render count change ${renderCount}`);
5471
+ debug5.extend(mainAxis)(`Render count change ${renderCount}`);
5430
5472
  }
5431
5473
  rerender();
5432
5474
  });
@@ -7173,7 +7215,7 @@ var useLicense = (licenseKey = "") => {
7173
7215
  const valid = (0, import_react43.useMemo)(() => {
7174
7216
  let valid2 = isValidLicense(licenseKey, {
7175
7217
  publishedAt: 1624970570587,
7176
- version: "0.1.1"
7218
+ version: "0.1.2"
7177
7219
  });
7178
7220
  if (!licenseKey && !valid2 && isInsideSandbox) {
7179
7221
  return true;
@@ -7187,7 +7229,7 @@ var useLicense = (licenseKey = "") => {
7187
7229
  var React33 = __toModule(require("react"));
7188
7230
  var import_react44 = __toModule(require("react"));
7189
7231
  var error = err("CSSVariableWatch");
7190
- var debug5 = dbg("CSSVariableWatch");
7232
+ var debug6 = dbg("CSSVariableWatch");
7191
7233
  var WRAPPER_STYLE = {
7192
7234
  position: "absolute",
7193
7235
  pointerEvents: "none",
@@ -7210,7 +7252,7 @@ var useCSSVariableWatch = (params) => {
7210
7252
  const value = params.ref.current.getBoundingClientRect().height;
7211
7253
  if (value) {
7212
7254
  lastValueRef.current = value;
7213
- debug5(`Variable ${params.varName} found and equals ${value}.`);
7255
+ debug6(`Variable ${params.varName} found and equals ${value}.`);
7214
7256
  params.onChange(value);
7215
7257
  } else {
7216
7258
  error(`Specified variable ${params.varName} not found or does not have a numeric value.`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infinite-table/infinite-react",
3
3
  "description": "Infinite Table for React",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
7
7
  "typings": "index.d.ts",
@@ -14,5 +14,5 @@
14
14
  },
15
15
  "license": "Commercial & Open Source",
16
16
  "//": "will be updated at build time",
17
- "publishedAt": 1642076142630
17
+ "publishedAt": 1642424005983
18
18
  }