@infinite-table/infinite-react 7.2.5-canary.1 → 7.2.5

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.js CHANGED
@@ -128,7 +128,8 @@ __export(index_exports, {
128
128
  useOverlayPortal: () => useOverlayPortal,
129
129
  usePrevious: () => usePrevious,
130
130
  useRowInfoReducers: () => useRowInfoReducers,
131
- useVisibleColumnSizes: () => useVisibleColumnSizes
131
+ useVisibleColumnSizes: () => useVisibleColumnSizes,
132
+ withSelectedLeafNodesOnly: () => withSelectedLeafNodesOnly
132
133
  });
133
134
  module.exports = __toCommonJS(index_exports);
134
135
 
@@ -1483,13 +1484,17 @@ function AvoidReactDiffFn(props) {
1483
1484
  cancelAnimationFrame(rafId.current);
1484
1485
  }
1485
1486
  rafId.current = requestAnimationFrame(() => {
1486
- (0, import_react_dom.flushSync)(() => {
1487
- setChildren(children2);
1487
+ queueMicrotask(() => {
1488
+ (0, import_react_dom.flushSync)(() => {
1489
+ setChildren(children2);
1490
+ });
1488
1491
  });
1489
1492
  });
1490
1493
  } else {
1491
- (0, import_react_dom.flushSync)(() => {
1492
- setChildren(children2);
1494
+ queueMicrotask(() => {
1495
+ (0, import_react_dom.flushSync)(() => {
1496
+ setChildren(children2);
1497
+ });
1493
1498
  });
1494
1499
  }
1495
1500
  }
@@ -9521,6 +9526,15 @@ var getHeaderWrapperNodes = (root) => {
9521
9526
  );
9522
9527
  };
9523
9528
 
9529
+ // src/utils/isTargetInput.ts
9530
+ function isTargetInput(target) {
9531
+ if (!target) {
9532
+ return false;
9533
+ }
9534
+ const tagName = target.tagName;
9535
+ return tagName === "INPUT" || tagName === "BUTTON";
9536
+ }
9537
+
9524
9538
  // src/components/InfiniteTable/hooks/useColumnPointerEvents.ts
9525
9539
  var baseZIndexForCells2 = stripVar(InternalVars.baseZIndexForCells);
9526
9540
  var equalPinning = (pinning1, pinning2) => {
@@ -9563,8 +9577,7 @@ var useColumnPointerEvents = ({
9563
9577
  }, []);
9564
9578
  const onPointerDown = (0, import_react21.useCallback)(
9565
9579
  (e) => {
9566
- const tagName = e.target?.tagName;
9567
- if (tagName === "INPUT" || tagName === "BUTTON") {
9580
+ if (isTargetInput(e.target)) {
9568
9581
  return;
9569
9582
  }
9570
9583
  const { brain, draggableColumnsRestrictTo } = getState();
@@ -17070,52 +17083,103 @@ var TreeSelectionState = class _TreeSelectionState {
17070
17083
  this.defaultSelection = false;
17071
17084
  this.selectionMap = new DeepMap();
17072
17085
  this.cache = new DeepMap();
17073
- const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? (
17086
+ this.correctnessChecks = false;
17087
+ const isTreeSelectionStateInstance = state instanceof Object.getPrototypeOf(this).constructor;
17088
+ const stateObject = isTreeSelectionStateInstance ? (
17074
17089
  //@ts-ignore
17075
17090
  state.getState()
17076
17091
  ) : state;
17077
- this.setConfigFn(getConfig);
17092
+ this.setConfig(
17093
+ getConfig || (isTreeSelectionStateInstance ? state.config : {
17094
+ treePaths: new DeepMap()
17095
+ })
17096
+ );
17097
+ this.disableCorrectnessChecks();
17078
17098
  this.update(stateObject);
17099
+ this.enableCorrectnessChecks();
17079
17100
  }
17080
- getTreeDeepMap() {
17081
- return this.getConfig().treeDeepMap;
17101
+ getTreePaths(treePaths) {
17102
+ if (treePaths) {
17103
+ if (Array.isArray(treePaths)) {
17104
+ return new DeepMap(treePaths.map((path) => [path, true]));
17105
+ }
17106
+ return treePaths;
17107
+ }
17108
+ return this.config.treePaths;
17109
+ }
17110
+ withTreePaths(fn, treePaths) {
17111
+ const initialTreePaths = this.config.treePaths;
17112
+ treePaths = this.getTreePaths(treePaths);
17113
+ const treePathsDifferent = treePaths !== initialTreePaths;
17114
+ if (treePathsDifferent) {
17115
+ this.xcache();
17116
+ }
17117
+ this.config.treePaths = treePaths;
17118
+ const result = fn(treePaths);
17119
+ this.config.treePaths = initialTreePaths;
17120
+ if (treePathsDifferent) {
17121
+ this.xcache();
17122
+ }
17123
+ return result;
17124
+ }
17125
+ getLeafNodePaths(rootNodePath = [], treePaths) {
17126
+ return this.withTreePaths((paths) => {
17127
+ return paths.getKeysForLeafNodesStartingWith(rootNodePath);
17128
+ }, treePaths);
17129
+ }
17130
+ forEachLeafNodePath(fn, rootNodePath = [], treePaths) {
17131
+ const selectedObj = { selected: false };
17132
+ this.withTreePaths((paths) => {
17133
+ paths.getLeafNodesStartingWith(rootNodePath, (pair) => {
17134
+ selectedObj.selected = this.isNodeSelected(pair.keys) === true;
17135
+ fn(pair.keys, selectedObj);
17136
+ });
17137
+ }, treePaths);
17082
17138
  }
17083
17139
  getSelectedLeafNodePaths(rootNodePath = [], treePaths) {
17084
- treePaths = treePaths || this.getConfig().treePaths;
17085
17140
  const selectedLeafPaths = [];
17086
- treePaths.getLeafNodesStartingWith(rootNodePath, (pair) => {
17087
- if (this.isNodeSelected(pair.keys)) {
17088
- selectedLeafPaths.push(pair.keys);
17089
- }
17090
- });
17141
+ this.withTreePaths((paths) => {
17142
+ paths.getLeafNodesStartingWith(rootNodePath, (pair) => {
17143
+ if (this.isNodeSelected(pair.keys)) {
17144
+ selectedLeafPaths.push(pair.keys);
17145
+ }
17146
+ });
17147
+ }, treePaths);
17091
17148
  return selectedLeafPaths;
17092
17149
  }
17093
17150
  getDeselectedLeafNodePaths(rootNodePath = [], treePaths) {
17094
- treePaths = treePaths || this.getConfig().treePaths;
17095
17151
  const deselectedLeafPaths = [];
17096
- treePaths.getLeafNodesStartingWith(rootNodePath, (pair) => {
17097
- if (!this.isNodeSelected(pair.keys)) {
17098
- deselectedLeafPaths.push(pair.keys);
17099
- }
17100
- });
17152
+ this.withTreePaths((paths) => {
17153
+ paths.getLeafNodesStartingWith(rootNodePath, (pair) => {
17154
+ if (!this.isNodeSelected(pair.keys)) {
17155
+ deselectedLeafPaths.push(pair.keys);
17156
+ }
17157
+ });
17158
+ }, treePaths);
17101
17159
  return deselectedLeafPaths;
17102
17160
  }
17103
17161
  isLeafNode(nodePath) {
17104
- return !this.getTreeDeepMap().has(nodePath);
17162
+ const { treePaths } = this.config;
17163
+ if (!treePaths.has(nodePath)) {
17164
+ return null;
17165
+ }
17166
+ const keys = treePaths.getKeysForLeafNodesStartingWith(nodePath);
17167
+ if (keys.length === 1) {
17168
+ return true;
17169
+ }
17170
+ return false;
17105
17171
  }
17106
17172
  getLeafNodesCount(nodePath) {
17107
- const treeDeepMap = this.getTreeDeepMap();
17108
- const deepMapValue = treeDeepMap.get(nodePath);
17109
- if (!deepMapValue) {
17110
- return 1;
17111
- }
17112
- return deepMapValue.items.length;
17173
+ return this.config.treePaths.getKeysForLeafNodesStartingWith(nodePath).length;
17113
17174
  }
17114
17175
  static from(treeSelectionState, getConfig) {
17115
17176
  return new _TreeSelectionState(treeSelectionState, getConfig);
17116
17177
  }
17117
- setConfigFn(getConfig) {
17118
- this.getConfig = getConfig;
17178
+ setConfig(getConfig) {
17179
+ const config = typeof getConfig === "function" ? getConfig() : getConfig;
17180
+ this.config = {
17181
+ treePaths: Array.isArray(config.treePaths) ? new DeepMap(config.treePaths.map((path) => [path, true])) : config.treePaths
17182
+ };
17119
17183
  this.xcache();
17120
17184
  }
17121
17185
  xcache() {
@@ -17136,6 +17200,9 @@ var TreeSelectionState = class _TreeSelectionState {
17136
17200
  this.xcache();
17137
17201
  }
17138
17202
  setSelectionForPath(nodePath, selected) {
17203
+ if (!this.isPathAvailable(nodePath)) {
17204
+ return;
17205
+ }
17139
17206
  this.selectionMap.set(nodePath, selected);
17140
17207
  }
17141
17208
  getState() {
@@ -17168,6 +17235,19 @@ var TreeSelectionState = class _TreeSelectionState {
17168
17235
  selectedPaths: []
17169
17236
  });
17170
17237
  }
17238
+ enableCorrectnessChecks() {
17239
+ this.correctnessChecks = true;
17240
+ }
17241
+ disableCorrectnessChecks() {
17242
+ this.correctnessChecks = false;
17243
+ }
17244
+ isPathAvailable(nodePath) {
17245
+ if (!this.correctnessChecks) {
17246
+ return true;
17247
+ }
17248
+ const { treePaths } = this.config;
17249
+ return treePaths.has(nodePath);
17250
+ }
17171
17251
  isNodeSelected(nodePath) {
17172
17252
  return this.isPathSelected(nodePath);
17173
17253
  }
@@ -17183,7 +17263,7 @@ var TreeSelectionState = class _TreeSelectionState {
17183
17263
  if (cachedResult) {
17184
17264
  return cachedResult;
17185
17265
  }
17186
- if (this.isLeafNode(nodePath)) {
17266
+ if (this.isLeafNode(nodePath) !== false) {
17187
17267
  const selected = this.isSelfSelected(nodePath);
17188
17268
  if (selected !== null) {
17189
17269
  return this.cacheIt(nodePath, {
@@ -17197,9 +17277,12 @@ var TreeSelectionState = class _TreeSelectionState {
17197
17277
  const leafCount = this.getLeafNodesCount(nodePath);
17198
17278
  let currentSelectionState = this.isSelfSelected(nodePath);
17199
17279
  const { selectionMap } = this;
17200
- const childPaths = selectionMap.getKeysOfFirstChildOnEachBranchStartingWith(nodePath, {
17280
+ let childPaths = selectionMap.getKeysOfFirstChildOnEachBranchStartingWith(nodePath, {
17201
17281
  excludeSelf: true
17202
17282
  }).sort(shortestToLongest);
17283
+ if (this.correctnessChecks) {
17284
+ childPaths = childPaths.filter((path) => this.isPathAvailable(path));
17285
+ }
17203
17286
  if (!childPaths.length) {
17204
17287
  if (currentSelectionState !== null) {
17205
17288
  const res2 = leafCount ? currentSelectionState : (
@@ -17273,6 +17356,9 @@ var TreeSelectionState = class _TreeSelectionState {
17273
17356
  });
17274
17357
  }
17275
17358
  isPathSelected(nodePath) {
17359
+ if (!this.isPathAvailable(nodePath)) {
17360
+ return false;
17361
+ }
17276
17362
  return this.getSelectionStateForNode(nodePath, true).selected;
17277
17363
  }
17278
17364
  getNodeBooleanSelectionStateFromParent(initialNodePath) {
@@ -17294,6 +17380,7 @@ var TreeSelectionState = class _TreeSelectionState {
17294
17380
  if (!nodePath.length) {
17295
17381
  return;
17296
17382
  }
17383
+ this.xcache();
17297
17384
  const keys = this.selectionMap.getKeysStartingWith(nodePath);
17298
17385
  keys.forEach((nodePath2) => {
17299
17386
  this.selectionMap.delete(nodePath2);
@@ -17333,7 +17420,7 @@ var TreeSelectionState = class _TreeSelectionState {
17333
17420
  };
17334
17421
  }
17335
17422
  destroy() {
17336
- this.getConfig = null;
17423
+ this.config = void 0;
17337
17424
  this.xcache();
17338
17425
  this.selectionMap.clear();
17339
17426
  }
@@ -17350,8 +17437,7 @@ function treeSelectionStateConfigGetter(stateOrStateGetter) {
17350
17437
  return () => {
17351
17438
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
17352
17439
  return {
17353
- treePaths: state.treePaths,
17354
- treeDeepMap: state.treeDeepMap
17440
+ treePaths: state.treePaths
17355
17441
  };
17356
17442
  };
17357
17443
  }
@@ -17377,7 +17463,10 @@ var TreeApiImpl = class {
17377
17463
  treeSelectionStateConfigGetter(this.getState)
17378
17464
  );
17379
17465
  treeSelectionState.setNodeSelection(nodePath, selected);
17380
- this.getState().lastSelectionUpdatedNodePathRef.current = nodePath;
17466
+ this.getState().lastSelectionUpdatedNodePathRef.current = {
17467
+ nodePath,
17468
+ selected
17469
+ };
17381
17470
  this.actions.treeSelection = treeSelectionState;
17382
17471
  };
17383
17472
  this.getCallbackParam = (_nodePath) => {
@@ -17535,8 +17624,7 @@ var TreeApiImpl = class {
17535
17624
  }
17536
17625
  }
17537
17626
  getNodeDataByPath(nodePath) {
17538
- const { treeDeepMap } = this.getState();
17539
- if (!treeDeepMap || !nodePath.length) {
17627
+ if (!nodePath.length) {
17540
17628
  return null;
17541
17629
  }
17542
17630
  const rowInfo = this.getRowInfoByPath(nodePath);
@@ -19019,6 +19107,14 @@ function concludeReducer(params) {
19019
19107
  const shouldTreeAgain = shouldTree && (treeDepsChanged || cacheAffectedParts.tree || !state.lastTreeDataArray) || treeSelectionDepsChanged || rowDisabledStateDepsChanged || rowInfoReducersChanged;
19020
19108
  const now = Date.now();
19021
19109
  let dataArray = state.originalDataArray;
19110
+ if (shouldTree && shouldTreeAgain) {
19111
+ const treeParams = {
19112
+ isLeafNode,
19113
+ getNodeChildren,
19114
+ toKey: toPrimaryKey
19115
+ };
19116
+ state.unfilteredTreePaths = tree(treeParams, dataArray).treePaths;
19117
+ }
19022
19118
  if (!shouldFilter) {
19023
19119
  state.unfilteredCount = dataArray.length;
19024
19120
  }
@@ -20317,6 +20413,7 @@ var cleanupDataSource = (state) => {
20317
20413
  };
20318
20414
  state.treeExpandState?.destroy();
20319
20415
  state.treePaths?.clear();
20416
+ state.unfilteredTreePaths?.clear();
20320
20417
  state.waitForNodePathPromises.clear();
20321
20418
  state.pathToIndexMap?.clear();
20322
20419
  state.rowDisabledState?.destroy();
@@ -20476,7 +20573,7 @@ function getTreeSelectionState(currentTreeSelection, selectionMode, state) {
20476
20573
  }
20477
20574
  const config = treeSelectionStateConfigGetter(state);
20478
20575
  if (currentTreeSelection instanceof TreeSelectionState) {
20479
- currentTreeSelection.setConfigFn(config);
20576
+ currentTreeSelection.setConfig(config);
20480
20577
  return currentTreeSelection;
20481
20578
  }
20482
20579
  if (currentTreeSelection === null || currentTreeSelection === void 0 || typeof currentTreeSelection != "object") {
@@ -20485,7 +20582,7 @@ function getTreeSelectionState(currentTreeSelection, selectionMode, state) {
20485
20582
  const treeSelectionStateObject = currentTreeSelection ?? treeSelectionStateDefaultObject;
20486
20583
  let instance = weakMap.get(treeSelectionStateObject);
20487
20584
  if (instance) {
20488
- instance.setConfigFn(config);
20585
+ instance.setConfig(config);
20489
20586
  }
20490
20587
  instance = instance ?? new TreeSelectionState(treeSelectionStateObject, config);
20491
20588
  weakMap.set(treeSelectionStateObject, instance);
@@ -20747,8 +20844,10 @@ function getMappedCallbacks() {
20747
20844
  treeSelection2.getState(),
20748
20845
  {
20749
20846
  treeSelectionState: treeSelection2,
20847
+ prevTreeSelectionState: state.treeSelectionState,
20750
20848
  selectionMode: "multi-row",
20751
- lastUpdatedNodePath: state.lastSelectionUpdatedNodePathRef.current,
20849
+ lastUpdatedNodeInfo: state.lastSelectionUpdatedNodePathRef.current,
20850
+ unfilteredTreePaths: state.unfilteredTreePaths,
20752
20851
  dataSourceApi,
20753
20852
  treeApi
20754
20853
  }
@@ -25726,7 +25825,7 @@ var useLicense = (licenseKey = "") => {
25726
25825
  }
25727
25826
  let valid2 = isValidLicense(licenseKey, {
25728
25827
  publishedAt: 1624970570587,
25729
- version: "7.2.5-canary.1"
25828
+ version: "7.2.5"
25730
25829
  });
25731
25830
  if (!licenseKey && !valid2 && isInsidePlayground) {
25732
25831
  return true;
@@ -25828,6 +25927,9 @@ function onCellClick(context, event) {
25828
25927
  context.getState().onCellClick?.(context, event);
25829
25928
  }
25830
25929
  function onCellDoubleClick(context, event) {
25930
+ if (isTargetInput(event.target)) {
25931
+ return;
25932
+ }
25831
25933
  const { onCellDoubleClick: onCellDoubleClick2 } = context.getState();
25832
25934
  let dblClickResult = {
25833
25935
  preventEdit: false
@@ -30182,6 +30284,36 @@ var React78 = __toESM(require("react"));
30182
30284
  function TreeGrid(props) {
30183
30285
  return /* @__PURE__ */ React78.createElement(InfiniteTable, { ...props });
30184
30286
  }
30287
+ var withSelectedLeafNodesOnly = (callback) => {
30288
+ const onTreeSelectionChange = (_, {
30289
+ unfilteredTreePaths,
30290
+ treeSelectionState,
30291
+ prevTreeSelectionState,
30292
+ lastUpdatedNodeInfo
30293
+ }) => {
30294
+ const newTreeSelection = new TreeSelectionState(prevTreeSelectionState, {
30295
+ treePaths: unfilteredTreePaths
30296
+ });
30297
+ treeSelectionState.forEachLeafNodePath((nodePath, { selected }) => {
30298
+ newTreeSelection.setNodeSelection(nodePath, selected);
30299
+ });
30300
+ if (lastUpdatedNodeInfo) {
30301
+ treeSelectionState.forEachLeafNodePath((nodePath) => {
30302
+ newTreeSelection.setNodeSelection(
30303
+ nodePath,
30304
+ lastUpdatedNodeInfo.selected
30305
+ );
30306
+ }, lastUpdatedNodeInfo.nodePath);
30307
+ }
30308
+ const selectedPaths = newTreeSelection.getSelectedLeafNodePaths();
30309
+ const treeSelectionObject = {
30310
+ defaultSelection: false,
30311
+ selectedPaths
30312
+ };
30313
+ callback(treeSelectionObject);
30314
+ };
30315
+ return onTreeSelectionChange;
30316
+ };
30185
30317
 
30186
30318
  // src/components/DataSource/DataLoader/DataQuery.ts
30187
30319
  var DataQuery = class {
@@ -30941,6 +31073,7 @@ var components = {
30941
31073
  useOverlayPortal,
30942
31074
  usePrevious,
30943
31075
  useRowInfoReducers,
30944
- useVisibleColumnSizes
31076
+ useVisibleColumnSizes,
31077
+ withSelectedLeafNodesOnly
30945
31078
  });
30946
31079
  //!collapsed || lazyLoad;