@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.dev.mjs CHANGED
@@ -1102,6 +1102,7 @@ function getDataSourceContext() {
1102
1102
  api: null,
1103
1103
  getState: () => null,
1104
1104
  assignState: () => null,
1105
+ getDataSourceMasterContext: () => void 0,
1105
1106
  componentState: null,
1106
1107
  componentActions: null
1107
1108
  });
@@ -8319,7 +8320,8 @@ function InfiniteTableColumnCellFn(props) {
8319
8320
  getState,
8320
8321
  actions: componentActions,
8321
8322
  computed,
8322
- api: imperativeApi
8323
+ api: imperativeApi,
8324
+ getDataSourceMasterContext
8323
8325
  } = useInfiniteTable();
8324
8326
  const {
8325
8327
  componentState: dataSourceState,
@@ -8332,6 +8334,7 @@ function InfiniteTableColumnCellFn(props) {
8332
8334
  const renderingContext = {
8333
8335
  getState,
8334
8336
  getDataSourceState,
8337
+ getDataSourceMasterContext,
8335
8338
  actions: componentActions,
8336
8339
  dataSourceActions,
8337
8340
  api: imperativeApi,
@@ -9228,7 +9231,8 @@ function InfiniteTableHeaderCell(props) {
9228
9231
  columnHeaderHeight,
9229
9232
  columnReorderDragColumnId,
9230
9233
  columnMenuVisibleForColumnId
9231
- }
9234
+ },
9235
+ getDataSourceMasterContext
9232
9236
  } = useInfiniteTable();
9233
9237
  const {
9234
9238
  api: dataSourceApi,
@@ -9260,6 +9264,7 @@ function InfiniteTableHeaderCell(props) {
9260
9264
  dataSourceApi,
9261
9265
  getComputed,
9262
9266
  getDataSourceState,
9267
+ getDataSourceMasterContext,
9263
9268
  getState
9264
9269
  });
9265
9270
  const computedSortable = columnApi.isSortable();
@@ -13526,7 +13531,7 @@ var DATA_CHANGES_COMPARE_FUNCTIONS = {
13526
13531
  return JSON.stringify(a) === JSON.stringify(b);
13527
13532
  }
13528
13533
  };
13529
- function buildDataSourceDataParams(componentState, overrides) {
13534
+ function buildDataSourceDataParams(componentState, overrides, masterContext) {
13530
13535
  var _a, _b;
13531
13536
  const sortInfo = componentState.multiSort ? componentState.sortInfo : (_b = (_a = componentState.sortInfo) == null ? void 0 : _a[0]) != null ? _b : null;
13532
13537
  const dataSourceParams = {
@@ -13539,6 +13544,9 @@ function buildDataSourceDataParams(componentState, overrides) {
13539
13544
  filterValue: componentState.filterValue,
13540
13545
  aggregationReducers: componentState.aggregationReducers
13541
13546
  };
13547
+ if (masterContext) {
13548
+ dataSourceParams.masterRowInfo = masterContext.masterRowInfo;
13549
+ }
13542
13550
  if (dataSourceParams.groupBy) {
13543
13551
  dataSourceParams.groupRowsState = componentState.groupRowsState.getState();
13544
13552
  }
@@ -13585,8 +13593,12 @@ function buildDataSourceDataParams(componentState, overrides) {
13585
13593
  dataSourceParams.changes = changes;
13586
13594
  return dataSourceParams;
13587
13595
  }
13588
- function loadData(data, componentState, actions, overrides) {
13589
- const dataParams = buildDataSourceDataParams(componentState, overrides);
13596
+ function loadData(data, componentState, actions, overrides, masterContext) {
13597
+ const dataParams = buildDataSourceDataParams(
13598
+ componentState,
13599
+ overrides,
13600
+ masterContext
13601
+ );
13590
13602
  const append = dataParams.append;
13591
13603
  if (componentState.lazyLoad) {
13592
13604
  const lazyGroupData = componentState.originalLazyGroupData;
@@ -13766,6 +13778,15 @@ function computeFilterValueForRemote(filterValue, {
13766
13778
  }
13767
13779
  );
13768
13780
  }
13781
+ function getDetailReady(masterContext, getDataSourceState) {
13782
+ const isDetail = !!masterContext;
13783
+ const { stateReadyAsDetails } = getDataSourceState();
13784
+ const isDetailReady = isDetail ? masterContext.shouldRestoreState ? stateReadyAsDetails : true : true;
13785
+ return {
13786
+ isDetail,
13787
+ isDetailReady
13788
+ };
13789
+ }
13769
13790
  function useLoadData() {
13770
13791
  const {
13771
13792
  getComponentState,
@@ -13786,8 +13807,7 @@ function useLoadData() {
13786
13807
  livePagination,
13787
13808
  livePaginationCursor,
13788
13809
  filterTypes,
13789
- cursorId: stateCursorId,
13790
- stateReadyAsDetails
13810
+ cursorId: stateCursorId
13791
13811
  } = componentState;
13792
13812
  const [scrollbars, setScrollbars] = useState13({
13793
13813
  vertical: false,
@@ -13859,21 +13879,26 @@ function useLoadData() {
13859
13879
  };
13860
13880
  const initialRef = useRef21(true);
13861
13881
  useLazyLoadRange();
13862
- const masterContext = useMasterDetailContext();
13863
- const isDetail = !!masterContext;
13864
- const isDetailRef = useRef21(!!masterContext);
13865
- isDetailRef.current = isDetail;
13866
- const isDetailReady = isDetail ? masterContext.shouldRestoreState ? stateReadyAsDetails : true : true;
13867
- const isDetailReadyRef = useRef21(isDetailReady);
13868
- isDetailReadyRef.current = isDetailReady;
13882
+ const getMasterContext = useLatest(useMasterDetailContext());
13869
13883
  useEffectWithChanges(
13870
13884
  () => {
13871
13885
  const componentState2 = getComponentState();
13872
- if (isDetailRef.current && !isDetailReadyRef.current) {
13886
+ const masterContext = getMasterContext();
13887
+ const { isDetail, isDetailReady } = getDetailReady(
13888
+ masterContext,
13889
+ getComponentState
13890
+ );
13891
+ if (isDetail && !isDetailReady) {
13873
13892
  return;
13874
13893
  }
13875
13894
  if (typeof componentState2.data !== "function") {
13876
- loadData(componentState2.data, componentState2, actions);
13895
+ loadData(
13896
+ componentState2.data,
13897
+ componentState2,
13898
+ actions,
13899
+ void 0,
13900
+ masterContext
13901
+ );
13877
13902
  }
13878
13903
  },
13879
13904
  { data }
@@ -13888,14 +13913,25 @@ function useLoadData() {
13888
13913
  return;
13889
13914
  }
13890
13915
  }
13891
- if (isDetailRef.current && !isDetailReadyRef.current) {
13916
+ const masterContext = getMasterContext();
13917
+ const { isDetail, isDetailReady } = getDetailReady(
13918
+ masterContext,
13919
+ getComponentState
13920
+ );
13921
+ if (isDetail && !isDetailReady) {
13892
13922
  return;
13893
13923
  }
13894
13924
  const componentState2 = getComponentState();
13895
13925
  if (typeof componentState2.data === "function") {
13896
- loadData(componentState2.data, componentState2, actions, {
13897
- append: appendWhenLivePagination
13898
- });
13926
+ loadData(
13927
+ componentState2.data,
13928
+ componentState2,
13929
+ actions,
13930
+ {
13931
+ append: appendWhenLivePagination
13932
+ },
13933
+ masterContext
13934
+ );
13899
13935
  }
13900
13936
  },
13901
13937
  __spreadProps(__spreadValues({}, depsObject), { data })
@@ -13904,7 +13940,11 @@ function useLoadData() {
13904
13940
  const componentState2 = getComponentState();
13905
13941
  if (initialRef.current) {
13906
13942
  initialRef.current = false;
13907
- const dataParams = buildDataSourceDataParams(componentState2);
13943
+ const dataParams = buildDataSourceDataParams(
13944
+ componentState2,
13945
+ void 0,
13946
+ getMasterContext()
13947
+ );
13908
13948
  actions.dataParams = dataParams;
13909
13949
  }
13910
13950
  }, depsObject);
@@ -14197,6 +14237,7 @@ function initSetupState() {
14197
14237
  current: false
14198
14238
  },
14199
14239
  idToIndexMap: /* @__PURE__ */ new Map(),
14240
+ getDataSourceMasterContextRef: { current: () => void 0 },
14200
14241
  // TODO: cleanup cache on unmount
14201
14242
  cache: void 0,
14202
14243
  detailDataSourcesStateToRestore: /* @__PURE__ */ new Map(),
@@ -14464,10 +14505,15 @@ function getMappedCallbacks() {
14464
14505
  function getInterceptActions() {
14465
14506
  return {
14466
14507
  sortInfo: (sortInfo, { actions, state }) => {
14467
- const dataParams = buildDataSourceDataParams(state, {
14468
- sortInfo,
14469
- livePaginationCursor: null
14470
- });
14508
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14509
+ const dataParams = buildDataSourceDataParams(
14510
+ state,
14511
+ {
14512
+ sortInfo,
14513
+ livePaginationCursor: null
14514
+ },
14515
+ getDataSourceMasterContext()
14516
+ );
14471
14517
  actions.dataParams = dataParams;
14472
14518
  if (state.livePagination) {
14473
14519
  raf(() => {
@@ -14476,10 +14522,15 @@ function getInterceptActions() {
14476
14522
  }
14477
14523
  },
14478
14524
  groupBy: (groupBy, { actions, state }) => {
14479
- const dataParams = buildDataSourceDataParams(state, {
14480
- groupBy,
14481
- livePaginationCursor: null
14482
- });
14525
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14526
+ const dataParams = buildDataSourceDataParams(
14527
+ state,
14528
+ {
14529
+ groupBy,
14530
+ livePaginationCursor: null
14531
+ },
14532
+ getDataSourceMasterContext()
14533
+ );
14483
14534
  actions.dataParams = dataParams;
14484
14535
  if (state.livePagination) {
14485
14536
  raf(() => {
@@ -14488,10 +14539,15 @@ function getInterceptActions() {
14488
14539
  }
14489
14540
  },
14490
14541
  pivotBy: (pivotBy, { actions, state }) => {
14491
- const dataParams = buildDataSourceDataParams(state, {
14492
- pivotBy,
14493
- livePaginationCursor: null
14494
- });
14542
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14543
+ const dataParams = buildDataSourceDataParams(
14544
+ state,
14545
+ {
14546
+ pivotBy,
14547
+ livePaginationCursor: null
14548
+ },
14549
+ getDataSourceMasterContext()
14550
+ );
14495
14551
  actions.dataParams = dataParams;
14496
14552
  if (state.livePagination) {
14497
14553
  raf(() => {
@@ -14500,10 +14556,15 @@ function getInterceptActions() {
14500
14556
  }
14501
14557
  },
14502
14558
  filterValue: (filterValue, { actions, state }) => {
14503
- const dataParams = buildDataSourceDataParams(state, {
14504
- filterValue,
14505
- livePaginationCursor: null
14506
- });
14559
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14560
+ const dataParams = buildDataSourceDataParams(
14561
+ state,
14562
+ {
14563
+ filterValue,
14564
+ livePaginationCursor: null
14565
+ },
14566
+ getDataSourceMasterContext()
14567
+ );
14507
14568
  actions.dataParams = dataParams;
14508
14569
  if (state.livePagination) {
14509
14570
  raf(() => {
@@ -14512,15 +14573,25 @@ function getInterceptActions() {
14512
14573
  }
14513
14574
  },
14514
14575
  cursorId: (cursorId, { actions, state }) => {
14515
- const dataParams = buildDataSourceDataParams(state, {
14516
- __cursorId: cursorId
14517
- });
14576
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14577
+ const dataParams = buildDataSourceDataParams(
14578
+ state,
14579
+ {
14580
+ __cursorId: cursorId
14581
+ },
14582
+ getDataSourceMasterContext()
14583
+ );
14518
14584
  actions.dataParams = dataParams;
14519
14585
  },
14520
14586
  livePaginationCursor: (livePaginationCursor, { actions, state }) => {
14521
- const dataParams = buildDataSourceDataParams(state, {
14522
- livePaginationCursor
14523
- });
14587
+ const getDataSourceMasterContext = state.getDataSourceMasterContextRef.current;
14588
+ const dataParams = buildDataSourceDataParams(
14589
+ state,
14590
+ {
14591
+ livePaginationCursor
14592
+ },
14593
+ getDataSourceMasterContext()
14594
+ );
14524
14595
  actions.dataParams = dataParams;
14525
14596
  },
14526
14597
  dataParams: (dataParams, { state }) => {
@@ -14529,7 +14600,8 @@ function getInterceptActions() {
14529
14600
  state.dataParams,
14530
14601
  /* @__PURE__ */ new Set([
14531
14602
  "changes",
14532
- "originalDataArray"
14603
+ "originalDataArray",
14604
+ "masterRowInfo"
14533
14605
  ])
14534
14606
  )) {
14535
14607
  return false;
@@ -14727,7 +14799,9 @@ function DataSourceCmp({
14727
14799
  }) {
14728
14800
  const DataSourceContext = getDataSourceContext();
14729
14801
  const masterContext = useMasterDetailContext();
14802
+ const getDataSourceMasterContext = useLatest(masterContext);
14730
14803
  const { componentState, componentActions, assignState } = useComponentState();
14804
+ componentState.getDataSourceMasterContextRef.current = getDataSourceMasterContext;
14731
14805
  const getState = useLatest(componentState);
14732
14806
  const [api] = React51.useState(() => {
14733
14807
  return getDataSourceApi({ getState, actions: componentActions });
@@ -14735,6 +14809,7 @@ function DataSourceCmp({
14735
14809
  const contextValue = {
14736
14810
  componentState,
14737
14811
  componentActions,
14812
+ getDataSourceMasterContext,
14738
14813
  getState,
14739
14814
  assignState,
14740
14815
  api
@@ -15630,9 +15705,15 @@ var InfiniteTableApiImpl = class {
15630
15705
  const currentData = state.originalLazyGroupData.get(dataKeys);
15631
15706
  if (newState.isGroupRowExpanded(groupKeys)) {
15632
15707
  if (!(currentData == null ? void 0 : currentData.cache)) {
15633
- loadData(state.data, state, this.dataSourceActions, {
15634
- groupKeys
15635
- });
15708
+ loadData(
15709
+ state.data,
15710
+ state,
15711
+ this.dataSourceActions,
15712
+ {
15713
+ groupKeys
15714
+ },
15715
+ this.context.getDataSourceMasterContext()
15716
+ );
15636
15717
  }
15637
15718
  } else {
15638
15719
  if (!(currentData == null ? void 0 : currentData.cache)) {
@@ -16470,6 +16551,7 @@ function useRegisterDetail(props) {
16470
16551
  shouldRestoreState
16471
16552
  };
16472
16553
  }, [rowInfo.id, currentRowCache]);
16554
+ masterDetailContextValue.masterRowInfo = rowInfo;
16473
16555
  return { masterDetailContextValue, currentRowCache };
16474
16556
  }
16475
16557
 
@@ -17329,7 +17411,7 @@ var forwardProps4 = (setupState) => {
17329
17411
  showHoverRows: (showHoverRows) => showHoverRows != null ? showHoverRows : true,
17330
17412
  virtualizeColumns: (virtualizeColumns) => virtualizeColumns != null ? virtualizeColumns : true,
17331
17413
  rowHeight: (rowHeight) => typeof rowHeight === "number" || typeof rowHeight === "function" ? rowHeight : 0,
17332
- rowDetailHeight: (rowHeight) => typeof rowHeight === "number" || typeof rowHeight === "function" ? rowHeight : 0,
17414
+ rowDetailHeight: (rowDetailHeight) => typeof rowDetailHeight === "number" || typeof rowDetailHeight === "function" ? rowDetailHeight : 300,
17333
17415
  columnHeaderHeight: (columnHeaderHeight) => typeof columnHeaderHeight === "number" ? columnHeaderHeight : 30,
17334
17416
  columns: (columns) => toMap(columns, setupState.propsCache.get("columns")),
17335
17417
  columnVisibility: (columnVisibility) => columnVisibility != null ? columnVisibility : {},
@@ -17543,7 +17625,11 @@ function getColumnVisibilityForHideEmptyGroupColumns(params) {
17543
17625
  // src/components/InfiniteTable/hooks/useToggleGroupRow.ts
17544
17626
  import { useCallback as useCallback21 } from "react";
17545
17627
  function useToggleGroupRow() {
17546
- const { getState: getDataSourceState, componentActions: dataSourceActions } = useDataSourceContextValue();
17628
+ const {
17629
+ getState: getDataSourceState,
17630
+ componentActions: dataSourceActions,
17631
+ getDataSourceMasterContext
17632
+ } = useDataSourceContextValue();
17547
17633
  const toggleGroupRow = useCallback21((groupKeys) => {
17548
17634
  const state = getDataSourceState();
17549
17635
  const newState = new GroupRowsState(state.groupRowsState);
@@ -17554,9 +17640,15 @@ function useToggleGroupRow() {
17554
17640
  const currentData = state.originalLazyGroupData.get(dataKeys);
17555
17641
  if (newState.isGroupRowExpanded(groupKeys)) {
17556
17642
  if (!(currentData == null ? void 0 : currentData.cache)) {
17557
- loadData(state.data, state, dataSourceActions, {
17558
- groupKeys
17559
- });
17643
+ loadData(
17644
+ state.data,
17645
+ state,
17646
+ dataSourceActions,
17647
+ {
17648
+ groupKeys
17649
+ },
17650
+ getDataSourceMasterContext()
17651
+ );
17560
17652
  }
17561
17653
  } else {
17562
17654
  if (!(currentData == null ? void 0 : currentData.cache)) {
@@ -18615,7 +18707,7 @@ var useLicense = (licenseKey = "") => {
18615
18707
  const valid = useMemo14(() => {
18616
18708
  let valid2 = isValidLicense(licenseKey, {
18617
18709
  publishedAt: 1624970570587,
18618
- version: "3.2.0"
18710
+ version: "3.2.2"
18619
18711
  });
18620
18712
  if (!licenseKey && !valid2 && isInsidePlayground) {
18621
18713
  return true;
@@ -19420,7 +19512,8 @@ function useEventHandlersContext() {
19420
19512
  getState,
19421
19513
  actions,
19422
19514
  api,
19423
- getComputed
19515
+ getComputed,
19516
+ getDataSourceMasterContext
19424
19517
  } = useInfiniteTable();
19425
19518
  const {
19426
19519
  getState: getDataSourceState,
@@ -19430,6 +19523,7 @@ function useEventHandlersContext() {
19430
19523
  const context = useMemo15(() => {
19431
19524
  const context2 = {
19432
19525
  getComputed,
19526
+ getDataSourceMasterContext,
19433
19527
  dataSourceApi,
19434
19528
  api,
19435
19529
  getState,
@@ -21400,11 +21494,12 @@ function FocusDetect() {
21400
21494
  dataSourceApi,
21401
21495
  dataSourceActions
21402
21496
  } = useInfiniteTable();
21403
- const { getState: getDataSourceState } = useDataSourceContextValue();
21497
+ const { getState: getDataSourceState, getDataSourceMasterContext } = useDataSourceContextValue();
21404
21498
  const { focusDetectDOMRef } = getState();
21405
21499
  const onFocus = useCallback26(() => __async(this, null, function* () {
21406
21500
  const context = {
21407
21501
  getDataSourceState,
21502
+ getDataSourceMasterContext,
21408
21503
  getComputed,
21409
21504
  actions,
21410
21505
  dataSourceActions,
@@ -22263,6 +22358,7 @@ function InfiniteTableContextProvider() {
22263
22358
  const {
22264
22359
  getState: getDataSourceState,
22265
22360
  componentActions: dataSourceActions,
22361
+ getDataSourceMasterContext,
22266
22362
  api: dataSourceApi
22267
22363
  } = useDataSourceContextValue();
22268
22364
  const [imperativeApi] = React66.useState(() => {
@@ -22270,6 +22366,7 @@ function InfiniteTableContextProvider() {
22270
22366
  getComputed,
22271
22367
  getState,
22272
22368
  getDataSourceState,
22369
+ getDataSourceMasterContext,
22273
22370
  dataSourceApi,
22274
22371
  actions: componentActions,
22275
22372
  dataSourceActions
@@ -22280,6 +22377,7 @@ function InfiniteTableContextProvider() {
22280
22377
  state: componentState,
22281
22378
  computed,
22282
22379
  dataSourceActions,
22380
+ getDataSourceMasterContext,
22283
22381
  getDataSourceState,
22284
22382
  getComputed,
22285
22383
  getState,