@infinite-table/infinite-react 3.2.0 → 3.2.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.
package/index.d.ts CHANGED
@@ -1629,6 +1629,7 @@ declare type InfiniteTableEventHandlerContext<T> = {
1629
1629
  actions: InfiniteTableActions<T>;
1630
1630
  cloneRowSelection: (rowSelection: RowSelectionState<T>) => RowSelectionState<T>;
1631
1631
  getDataSourceState: () => DataSourceState<T>;
1632
+ getDataSourceMasterContext: () => DataSourceMasterDetailContextValue | undefined;
1632
1633
  dataSourceActions: DataSourceComponentActions<T>;
1633
1634
  api: InfiniteTableApi<T>;
1634
1635
  dataSourceApi: DataSourceApi<T>;
@@ -1653,6 +1654,7 @@ interface InfiniteTableContextValue<T> {
1653
1654
  getComputed: () => InfiniteTableComputedValues<T>;
1654
1655
  getState: () => InfiniteTableState<T>;
1655
1656
  getDataSourceState: () => DataSourceState<T>;
1657
+ getDataSourceMasterContext: () => DataSourceMasterDetailContextValue | undefined;
1656
1658
  }
1657
1659
  interface InfiniteTablePublicContext<T> {
1658
1660
  api: InfiniteTableApi<T>;
@@ -1793,6 +1795,7 @@ declare class Indexer<DataType, PrimaryKeyType = string> {
1793
1795
 
1794
1796
  interface DataSourceDataParams<T> {
1795
1797
  originalDataArray: T[];
1798
+ masterRowInfo?: InfiniteTableRowInfo<any>;
1796
1799
  sortInfo?: DataSourceSortInfo<T>;
1797
1800
  groupBy?: DataSourcePropGroupBy<T>;
1798
1801
  pivotBy?: DataSourcePropPivotBy<T>;
@@ -1910,6 +1913,7 @@ declare type LazyRowInfoGroup<DataType> = {
1910
1913
  declare type LazyGroupDataDeepMap<DataType, KeyType = string> = DeepMap<KeyType, LazyRowInfoGroup<DataType>>;
1911
1914
  interface DataSourceSetupState<T> {
1912
1915
  indexer: Indexer<T, any>;
1916
+ getDataSourceMasterContextRef: React$1.MutableRefObject<() => DataSourceMasterDetailContextValue | undefined>;
1913
1917
  destroyedRef: React$1.MutableRefObject<boolean>;
1914
1918
  idToIndexMap: Map<any, number>;
1915
1919
  detailDataSourcesStateToRestore: Map<any, Partial<DataSourceStateRestoreForDetails<any>>>;
@@ -2178,12 +2182,14 @@ interface DataSourceContextValue<T> {
2178
2182
  api: DataSourceApi<T>;
2179
2183
  getState: () => DataSourceState<T>;
2180
2184
  assignState: (state: Partial<DataSourceState<T>>) => void;
2185
+ getDataSourceMasterContext: () => DataSourceMasterDetailContextValue | undefined;
2181
2186
  componentState: DataSourceState<T>;
2182
2187
  componentActions: DataSourceComponentActions<T>;
2183
2188
  }
2184
2189
  interface DataSourceMasterDetailContextValue {
2185
2190
  registerDetail: (detail: DataSourceContextValue<any>) => void;
2186
2191
  shouldRestoreState: boolean;
2192
+ masterRowInfo: InfiniteTableRowInfo<any>;
2187
2193
  }
2188
2194
  declare enum DataSourceActionType {
2189
2195
  INIT = "INIT"
package/index.dev.js CHANGED
@@ -1142,6 +1142,7 @@ function getDataSourceContext() {
1142
1142
  api: null,
1143
1143
  getState: () => null,
1144
1144
  assignState: () => null,
1145
+ getDataSourceMasterContext: () => void 0,
1145
1146
  componentState: null,
1146
1147
  componentActions: null
1147
1148
  });
@@ -8346,7 +8347,8 @@ function InfiniteTableColumnCellFn(props) {
8346
8347
  getState,
8347
8348
  actions: componentActions,
8348
8349
  computed,
8349
- api: imperativeApi
8350
+ api: imperativeApi,
8351
+ getDataSourceMasterContext
8350
8352
  } = useInfiniteTable();
8351
8353
  const {
8352
8354
  componentState: dataSourceState,
@@ -8359,6 +8361,7 @@ function InfiniteTableColumnCellFn(props) {
8359
8361
  const renderingContext = {
8360
8362
  getState,
8361
8363
  getDataSourceState,
8364
+ getDataSourceMasterContext,
8362
8365
  actions: componentActions,
8363
8366
  dataSourceActions,
8364
8367
  api: imperativeApi,
@@ -9255,7 +9258,8 @@ function InfiniteTableHeaderCell(props) {
9255
9258
  columnHeaderHeight,
9256
9259
  columnReorderDragColumnId,
9257
9260
  columnMenuVisibleForColumnId
9258
- }
9261
+ },
9262
+ getDataSourceMasterContext
9259
9263
  } = useInfiniteTable();
9260
9264
  const {
9261
9265
  api: dataSourceApi,
@@ -9287,6 +9291,7 @@ function InfiniteTableHeaderCell(props) {
9287
9291
  dataSourceApi,
9288
9292
  getComputed,
9289
9293
  getDataSourceState,
9294
+ getDataSourceMasterContext,
9290
9295
  getState
9291
9296
  });
9292
9297
  const computedSortable = columnApi.isSortable();
@@ -13553,7 +13558,7 @@ var DATA_CHANGES_COMPARE_FUNCTIONS = {
13553
13558
  return JSON.stringify(a) === JSON.stringify(b);
13554
13559
  }
13555
13560
  };
13556
- function buildDataSourceDataParams(componentState, overrides) {
13561
+ function buildDataSourceDataParams(componentState, overrides, masterContext) {
13557
13562
  var _a, _b;
13558
13563
  const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
13559
13564
  const dataSourceParams = {
@@ -13566,6 +13571,9 @@ function buildDataSourceDataParams(componentState, overrides) {
13566
13571
  filterValue: componentState.filterValue,
13567
13572
  aggregationReducers: componentState.aggregationReducers
13568
13573
  };
13574
+ if (masterContext) {
13575
+ dataSourceParams.masterRowInfo = masterContext.masterRowInfo;
13576
+ }
13569
13577
  if (dataSourceParams.groupBy) {
13570
13578
  dataSourceParams.groupRowsState = componentState.groupRowsState.getState();
13571
13579
  }
@@ -13612,8 +13620,12 @@ function buildDataSourceDataParams(componentState, overrides) {
13612
13620
  dataSourceParams.changes = changes;
13613
13621
  return dataSourceParams;
13614
13622
  }
13615
- function loadData(data, componentState, actions, overrides) {
13616
- const dataParams = buildDataSourceDataParams(componentState, overrides);
13623
+ function loadData(data, componentState, actions, overrides, masterContext) {
13624
+ const dataParams = buildDataSourceDataParams(
13625
+ componentState,
13626
+ overrides,
13627
+ masterContext
13628
+ );
13617
13629
  const append = dataParams.append;
13618
13630
  if (componentState.lazyLoad) {
13619
13631
  const lazyGroupData = componentState.originalLazyGroupData;
@@ -13793,6 +13805,15 @@ function computeFilterValueForRemote(filterValue, {
13793
13805
  }
13794
13806
  );
13795
13807
  }
13808
+ function getDetailReady(masterContext, getDataSourceState) {
13809
+ const isDetail = !!masterContext;
13810
+ const { stateReadyAsDetails } = getDataSourceState();
13811
+ const isDetailReady = isDetail ? masterContext.shouldRestoreState ? stateReadyAsDetails : true : true;
13812
+ return {
13813
+ isDetail,
13814
+ isDetailReady
13815
+ };
13816
+ }
13796
13817
  function useLoadData() {
13797
13818
  const {
13798
13819
  getComponentState,
@@ -13813,8 +13834,7 @@ function useLoadData() {
13813
13834
  livePagination,
13814
13835
  livePaginationCursor,
13815
13836
  filterTypes,
13816
- cursorId: stateCursorId,
13817
- stateReadyAsDetails
13837
+ cursorId: stateCursorId
13818
13838
  } = componentState;
13819
13839
  const [scrollbars, setScrollbars] = (0, import_react35.useState)({
13820
13840
  vertical: false,
@@ -13886,21 +13906,26 @@ function useLoadData() {
13886
13906
  };
13887
13907
  const initialRef = (0, import_react35.useRef)(true);
13888
13908
  useLazyLoadRange();
13889
- const masterContext = useMasterDetailContext();
13890
- const isDetail = !!masterContext;
13891
- const isDetailRef = (0, import_react35.useRef)(!!masterContext);
13892
- isDetailRef.current = isDetail;
13893
- const isDetailReady = isDetail ? masterContext.shouldRestoreState ? stateReadyAsDetails : true : true;
13894
- const isDetailReadyRef = (0, import_react35.useRef)(isDetailReady);
13895
- isDetailReadyRef.current = isDetailReady;
13909
+ const getMasterContext = useLatest(useMasterDetailContext());
13896
13910
  useEffectWithChanges(
13897
13911
  () => {
13898
13912
  const componentState2 = getComponentState();
13899
- if (isDetailRef.current && !isDetailReadyRef.current) {
13913
+ const masterContext = getMasterContext();
13914
+ const { isDetail, isDetailReady } = getDetailReady(
13915
+ masterContext,
13916
+ getComponentState
13917
+ );
13918
+ if (isDetail && !isDetailReady) {
13900
13919
  return;
13901
13920
  }
13902
13921
  if (typeof componentState2.data !== "function") {
13903
- loadData(componentState2.data, componentState2, actions);
13922
+ loadData(
13923
+ componentState2.data,
13924
+ componentState2,
13925
+ actions,
13926
+ void 0,
13927
+ masterContext
13928
+ );
13904
13929
  }
13905
13930
  },
13906
13931
  { data }
@@ -13915,14 +13940,25 @@ function useLoadData() {
13915
13940
  return;
13916
13941
  }
13917
13942
  }
13918
- if (isDetailRef.current && !isDetailReadyRef.current) {
13943
+ const masterContext = getMasterContext();
13944
+ const { isDetail, isDetailReady } = getDetailReady(
13945
+ masterContext,
13946
+ getComponentState
13947
+ );
13948
+ if (isDetail && !isDetailReady) {
13919
13949
  return;
13920
13950
  }
13921
13951
  const componentState2 = getComponentState();
13922
13952
  if (typeof componentState2.data === "function") {
13923
- loadData(componentState2.data, componentState2, actions, {
13924
- append: appendWhenLivePagination
13925
- });
13953
+ loadData(
13954
+ componentState2.data,
13955
+ componentState2,
13956
+ actions,
13957
+ {
13958
+ append: appendWhenLivePagination
13959
+ },
13960
+ masterContext
13961
+ );
13926
13962
  }
13927
13963
  },
13928
13964
  __spreadProps(__spreadValues({}, depsObject), { data })
@@ -13931,7 +13967,11 @@ function useLoadData() {
13931
13967
  const componentState2 = getComponentState();
13932
13968
  if (initialRef.current) {
13933
13969
  initialRef.current = false;
13934
- const dataParams = buildDataSourceDataParams(componentState2);
13970
+ const dataParams = buildDataSourceDataParams(
13971
+ componentState2,
13972
+ void 0,
13973
+ getMasterContext()
13974
+ );
13935
13975
  actions.dataParams = dataParams;
13936
13976
  }
13937
13977
  }, depsObject);
@@ -14224,6 +14264,7 @@ function initSetupState() {
14224
14264
  current: false
14225
14265
  },
14226
14266
  idToIndexMap: /* @__PURE__ */ new Map(),
14267
+ getDataSourceMasterContextRef: { current: () => void 0 },
14227
14268
  // TODO: cleanup cache on unmount
14228
14269
  cache: void 0,
14229
14270
  detailDataSourcesStateToRestore: /* @__PURE__ */ new Map(),
@@ -14491,10 +14532,15 @@ function getMappedCallbacks() {
14491
14532
  function getInterceptActions() {
14492
14533
  return {
14493
14534
  sortInfo: (sortInfo, { actions, state }) => {
14494
- const dataParams = buildDataSourceDataParams(state, {
14495
- sortInfo,
14496
- livePaginationCursor: null
14497
- });
14535
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14536
+ const dataParams = buildDataSourceDataParams(
14537
+ state,
14538
+ {
14539
+ sortInfo,
14540
+ livePaginationCursor: null
14541
+ },
14542
+ getDataSourceMasterContext()
14543
+ );
14498
14544
  actions.dataParams = dataParams;
14499
14545
  if (state.livePagination) {
14500
14546
  raf(() => {
@@ -14503,10 +14549,15 @@ function getInterceptActions() {
14503
14549
  }
14504
14550
  },
14505
14551
  groupBy: (groupBy, { actions, state }) => {
14506
- const dataParams = buildDataSourceDataParams(state, {
14507
- groupBy,
14508
- livePaginationCursor: null
14509
- });
14552
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14553
+ const dataParams = buildDataSourceDataParams(
14554
+ state,
14555
+ {
14556
+ groupBy,
14557
+ livePaginationCursor: null
14558
+ },
14559
+ getDataSourceMasterContext()
14560
+ );
14510
14561
  actions.dataParams = dataParams;
14511
14562
  if (state.livePagination) {
14512
14563
  raf(() => {
@@ -14515,10 +14566,15 @@ function getInterceptActions() {
14515
14566
  }
14516
14567
  },
14517
14568
  pivotBy: (pivotBy, { actions, state }) => {
14518
- const dataParams = buildDataSourceDataParams(state, {
14519
- pivotBy,
14520
- livePaginationCursor: null
14521
- });
14569
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14570
+ const dataParams = buildDataSourceDataParams(
14571
+ state,
14572
+ {
14573
+ pivotBy,
14574
+ livePaginationCursor: null
14575
+ },
14576
+ getDataSourceMasterContext()
14577
+ );
14522
14578
  actions.dataParams = dataParams;
14523
14579
  if (state.livePagination) {
14524
14580
  raf(() => {
@@ -14527,10 +14583,15 @@ function getInterceptActions() {
14527
14583
  }
14528
14584
  },
14529
14585
  filterValue: (filterValue, { actions, state }) => {
14530
- const dataParams = buildDataSourceDataParams(state, {
14531
- filterValue,
14532
- livePaginationCursor: null
14533
- });
14586
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14587
+ const dataParams = buildDataSourceDataParams(
14588
+ state,
14589
+ {
14590
+ filterValue,
14591
+ livePaginationCursor: null
14592
+ },
14593
+ getDataSourceMasterContext()
14594
+ );
14534
14595
  actions.dataParams = dataParams;
14535
14596
  if (state.livePagination) {
14536
14597
  raf(() => {
@@ -14539,15 +14600,25 @@ function getInterceptActions() {
14539
14600
  }
14540
14601
  },
14541
14602
  cursorId: (cursorId, { actions, state }) => {
14542
- const dataParams = buildDataSourceDataParams(state, {
14543
- __cursorId: cursorId
14544
- });
14603
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14604
+ const dataParams = buildDataSourceDataParams(
14605
+ state,
14606
+ {
14607
+ __cursorId: cursorId
14608
+ },
14609
+ getDataSourceMasterContext()
14610
+ );
14545
14611
  actions.dataParams = dataParams;
14546
14612
  },
14547
14613
  livePaginationCursor: (livePaginationCursor, { actions, state }) => {
14548
- const dataParams = buildDataSourceDataParams(state, {
14549
- livePaginationCursor
14550
- });
14614
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14615
+ const dataParams = buildDataSourceDataParams(
14616
+ state,
14617
+ {
14618
+ livePaginationCursor
14619
+ },
14620
+ getDataSourceMasterContext()
14621
+ );
14551
14622
  actions.dataParams = dataParams;
14552
14623
  },
14553
14624
  dataParams: (dataParams, { state }) => {
@@ -14556,7 +14627,8 @@ function getInterceptActions() {
14556
14627
  state.dataParams,
14557
14628
  /* @__PURE__ */ new Set([
14558
14629
  "changes",
14559
- "originalDataArray"
14630
+ "originalDataArray",
14631
+ "masterRowInfo"
14560
14632
  ])
14561
14633
  )) {
14562
14634
  return false;
@@ -14754,7 +14826,9 @@ function DataSourceCmp({
14754
14826
  }) {
14755
14827
  const DataSourceContext = getDataSourceContext();
14756
14828
  const masterContext = useMasterDetailContext();
14829
+ const getDataSourceMasterContext = useLatest(masterContext);
14757
14830
  const { componentState, componentActions, assignState } = useComponentState();
14831
+ componentState.getDataSourceMasterContextRef.current = getDataSourceMasterContext;
14758
14832
  const getState = useLatest(componentState);
14759
14833
  const [api] = React51.useState(() => {
14760
14834
  return getDataSourceApi({ getState, actions: componentActions });
@@ -14762,6 +14836,7 @@ function DataSourceCmp({
14762
14836
  const contextValue = {
14763
14837
  componentState,
14764
14838
  componentActions,
14839
+ getDataSourceMasterContext,
14765
14840
  getState,
14766
14841
  assignState,
14767
14842
  api
@@ -15657,9 +15732,15 @@ var InfiniteTableApiImpl = class {
15657
15732
  const currentData = state.originalLazyGroupData.get(dataKeys);
15658
15733
  if (newState.isGroupRowExpanded(groupKeys)) {
15659
15734
  if (!(currentData == null ? void 0 : currentData.cache)) {
15660
- loadData(state.data, state, this.dataSourceActions, {
15661
- groupKeys
15662
- });
15735
+ loadData(
15736
+ state.data,
15737
+ state,
15738
+ this.dataSourceActions,
15739
+ {
15740
+ groupKeys
15741
+ },
15742
+ this.context.getDataSourceMasterContext()
15743
+ );
15663
15744
  }
15664
15745
  } else {
15665
15746
  if (!(currentData == null ? void 0 : currentData.cache)) {
@@ -16493,6 +16574,7 @@ function useRegisterDetail(props) {
16493
16574
  shouldRestoreState
16494
16575
  };
16495
16576
  }, [rowInfo.id, currentRowCache]);
16577
+ masterDetailContextValue.masterRowInfo = rowInfo;
16496
16578
  return { masterDetailContextValue, currentRowCache };
16497
16579
  }
16498
16580
 
@@ -17352,7 +17434,7 @@ var forwardProps4 = (setupState) => {
17352
17434
  showHoverRows: (showHoverRows) => showHoverRows != null ? showHoverRows : true,
17353
17435
  virtualizeColumns: (virtualizeColumns) => virtualizeColumns != null ? virtualizeColumns : true,
17354
17436
  rowHeight: (rowHeight) => typeof rowHeight === "number" || typeof rowHeight === "function" ? rowHeight : 0,
17355
- rowDetailHeight: (rowHeight) => typeof rowHeight === "number" || typeof rowHeight === "function" ? rowHeight : 0,
17437
+ rowDetailHeight: (rowDetailHeight) => typeof rowDetailHeight === "number" || typeof rowDetailHeight === "function" ? rowDetailHeight : 300,
17356
17438
  columnHeaderHeight: (columnHeaderHeight) => typeof columnHeaderHeight === "number" ? columnHeaderHeight : 30,
17357
17439
  columns: (columns) => toMap(columns, setupState.propsCache.get("columns")),
17358
17440
  columnVisibility: (columnVisibility) => columnVisibility != null ? columnVisibility : {},
@@ -17566,7 +17648,11 @@ function getColumnVisibilityForHideEmptyGroupColumns(params) {
17566
17648
  // src/components/InfiniteTable/hooks/useToggleGroupRow.ts
17567
17649
  var import_react46 = require("react");
17568
17650
  function useToggleGroupRow() {
17569
- const { getState: getDataSourceState, componentActions: dataSourceActions } = useDataSourceContextValue();
17651
+ const {
17652
+ getState: getDataSourceState,
17653
+ componentActions: dataSourceActions,
17654
+ getDataSourceMasterContext
17655
+ } = useDataSourceContextValue();
17570
17656
  const toggleGroupRow = (0, import_react46.useCallback)((groupKeys) => {
17571
17657
  const state = getDataSourceState();
17572
17658
  const newState = new GroupRowsState(state.groupRowsState);
@@ -17577,9 +17663,15 @@ function useToggleGroupRow() {
17577
17663
  const currentData = state.originalLazyGroupData.get(dataKeys);
17578
17664
  if (newState.isGroupRowExpanded(groupKeys)) {
17579
17665
  if (!(currentData == null ? void 0 : currentData.cache)) {
17580
- loadData(state.data, state, dataSourceActions, {
17581
- groupKeys
17582
- });
17666
+ loadData(
17667
+ state.data,
17668
+ state,
17669
+ dataSourceActions,
17670
+ {
17671
+ groupKeys
17672
+ },
17673
+ getDataSourceMasterContext()
17674
+ );
17583
17675
  }
17584
17676
  } else {
17585
17677
  if (!(currentData == null ? void 0 : currentData.cache)) {
@@ -18638,7 +18730,7 @@ var useLicense = (licenseKey = "") => {
18638
18730
  const valid = (0, import_react53.useMemo)(() => {
18639
18731
  let valid2 = isValidLicense(licenseKey, {
18640
18732
  publishedAt: 1624970570587,
18641
- version: "3.2.0"
18733
+ version: "3.2.2"
18642
18734
  });
18643
18735
  if (!licenseKey && !valid2 && isInsidePlayground) {
18644
18736
  return true;
@@ -19443,7 +19535,8 @@ function useEventHandlersContext() {
19443
19535
  getState,
19444
19536
  actions,
19445
19537
  api,
19446
- getComputed
19538
+ getComputed,
19539
+ getDataSourceMasterContext
19447
19540
  } = useInfiniteTable();
19448
19541
  const {
19449
19542
  getState: getDataSourceState,
@@ -19453,6 +19546,7 @@ function useEventHandlersContext() {
19453
19546
  const context = (0, import_react56.useMemo)(() => {
19454
19547
  const context2 = {
19455
19548
  getComputed,
19549
+ getDataSourceMasterContext,
19456
19550
  dataSourceApi,
19457
19551
  api,
19458
19552
  getState,
@@ -21413,11 +21507,12 @@ function FocusDetect() {
21413
21507
  dataSourceApi,
21414
21508
  dataSourceActions
21415
21509
  } = useInfiniteTable();
21416
- const { getState: getDataSourceState } = useDataSourceContextValue();
21510
+ const { getState: getDataSourceState, getDataSourceMasterContext } = useDataSourceContextValue();
21417
21511
  const { focusDetectDOMRef } = getState();
21418
21512
  const onFocus = (0, import_react62.useCallback)(() => __async(this, null, function* () {
21419
21513
  const context = {
21420
21514
  getDataSourceState,
21515
+ getDataSourceMasterContext,
21421
21516
  getComputed,
21422
21517
  actions,
21423
21518
  dataSourceActions,
@@ -22276,6 +22371,7 @@ function InfiniteTableContextProvider() {
22276
22371
  const {
22277
22372
  getState: getDataSourceState,
22278
22373
  componentActions: dataSourceActions,
22374
+ getDataSourceMasterContext,
22279
22375
  api: dataSourceApi
22280
22376
  } = useDataSourceContextValue();
22281
22377
  const [imperativeApi] = React66.useState(() => {
@@ -22283,6 +22379,7 @@ function InfiniteTableContextProvider() {
22283
22379
  getComputed,
22284
22380
  getState,
22285
22381
  getDataSourceState,
22382
+ getDataSourceMasterContext,
22286
22383
  dataSourceApi,
22287
22384
  actions: componentActions,
22288
22385
  dataSourceActions
@@ -22293,6 +22390,7 @@ function InfiniteTableContextProvider() {
22293
22390
  state: componentState,
22294
22391
  computed,
22295
22392
  dataSourceActions,
22393
+ getDataSourceMasterContext,
22296
22394
  getDataSourceState,
22297
22395
  getComputed,
22298
22396
  getState,