@infinite-table/infinite-react 6.0.14 → 6.0.16

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.mjs CHANGED
@@ -2631,15 +2631,22 @@ var MatrixBrain = class extends Logger {
2631
2631
  if (size <= 0) {
2632
2632
  return 0;
2633
2633
  }
2634
+ const fixedStart = direction === "horizontal" ? this.fixedColsStart : this.fixedRowsStart;
2635
+ const fixedEnd = direction === "horizontal" ? this.fixedColsEnd : this.fixedRowsEnd;
2634
2636
  if (typeof itemSize === "function") {
2635
2637
  const sizes = [];
2636
- for (let i = 0; i < count; i++) {
2638
+ let start = 0;
2639
+ let end = count;
2640
+ start += fixedStart;
2641
+ end -= fixedEnd;
2642
+ for (let i = start; i < end; i++) {
2637
2643
  sizes.push(this.getItemSize(i, direction));
2638
2644
  }
2639
2645
  renderCount = getGreatestCountVisibleInSize(size, sizes);
2640
2646
  } else {
2641
2647
  renderCount = (itemSize ? Math.ceil(size / itemSize) : 0) + 1;
2642
2648
  }
2649
+ renderCount += fixedStart + fixedEnd;
2643
2650
  renderCount = Math.min(count, renderCount);
2644
2651
  return renderCount;
2645
2652
  }
@@ -4633,7 +4640,7 @@ var ActiveRowIndicatorFn = (props) => {
4633
4640
  setInfiniteVarsOnNode(
4634
4641
  {
4635
4642
  scrollTopForActiveRow: `${-scrollPosition.scrollTop}px`,
4636
- scrollLeftForActiveRowWhenHorizontalLayout: `${-scrollPosition.scrollLeft}px`
4643
+ scrollLeftForActiveRowWhenHorizontalLayout: brain.isHorizontalLayoutBrain ? `${-scrollPosition.scrollLeft}px` : "0px"
4637
4644
  },
4638
4645
  domRef.current
4639
4646
  );
@@ -5372,7 +5379,7 @@ var Icon = (props) => {
5372
5379
  // src/components/InfiniteTable/components/icons/IncludesOperatorIcon.tsx
5373
5380
  import * as React17 from "react";
5374
5381
  var IncludesOperatorIcon = (props) => {
5375
- return /* @__PURE__ */ React17.createElement(Icon, { ...props }, /* @__PURE__ */ React17.createElement("path", { d: "M5,4V7H10.5V19H13.5V7H19V4H5Z" }));
5382
+ return /* @__PURE__ */ React17.createElement(Icon, { ...props }, /* @__PURE__ */ React17.createElement("path", { d: "M11.14 4L6.43 16H8.36L9.32 13.43H14.67L15.64 16H17.57L12.86 4M12 6.29L14.03 11.71H9.96M20" }), /* @__PURE__ */ React17.createElement("path", { d: "M4 18V15H2V20H22V18Z" }), /* @__PURE__ */ React17.createElement("path", { d: "M20 14V18H2V20H22V14Z" }));
5376
5383
  };
5377
5384
 
5378
5385
  // src/components/InfiniteTable/components/icons/EndsWithOperatorIcon.tsx
@@ -13929,6 +13936,19 @@ var Indexer = class {
13929
13936
  item = { ...item, ...info.data };
13930
13937
  arr2[i] = item;
13931
13938
  }
13939
+ if (info.type === "update-children" && !deleted) {
13940
+ const children = info.children(
13941
+ item[nodesKey],
13942
+ item
13943
+ );
13944
+ item = { ...item };
13945
+ if (children !== void 0) {
13946
+ item[nodesKey] = children;
13947
+ } else {
13948
+ delete item[nodesKey];
13949
+ }
13950
+ arr2[i] = item;
13951
+ }
13932
13952
  if (info.type === "insert") {
13933
13953
  if (info.position === "before") {
13934
13954
  arr2.splice(i, 0, info.data);
@@ -14228,7 +14248,7 @@ function getPivotColumnsAndColumnGroups({
14228
14248
  // src/components/DataSource/DataSourceCache.ts
14229
14249
  var CLEAR_SYMBOL = Symbol("CLEAR");
14230
14250
  var DataSourceCache = class {
14231
- constructor() {
14251
+ constructor(options) {
14232
14252
  this.affectedFields = /* @__PURE__ */ new Set();
14233
14253
  this.allFieldsAffected = false;
14234
14254
  this.primaryKeyToData = /* @__PURE__ */ new Map();
@@ -14291,8 +14311,12 @@ var DataSourceCache = class {
14291
14311
  };
14292
14312
  this.update = (primaryKey, data, originalData, metadata) => {
14293
14313
  if (!this.allFieldsAffected) {
14294
- const keys = Object.keys(data);
14295
- keys.forEach((key) => this.affectedFields.add(key));
14314
+ if (this.nodesKey && Array.isArray(data[this.nodesKey])) {
14315
+ this.allFieldsAffected = true;
14316
+ } else {
14317
+ const keys = Object.keys(data);
14318
+ keys.forEach((key) => this.affectedFields.add(key));
14319
+ }
14296
14320
  }
14297
14321
  const pk = primaryKey;
14298
14322
  const value = this.primaryKeyToData.get(pk) || [];
@@ -14307,8 +14331,12 @@ var DataSourceCache = class {
14307
14331
  };
14308
14332
  this.updateNodePath = (nodePath, data, originalData, metadata) => {
14309
14333
  if (!this.allFieldsAffected) {
14310
- const keys = Object.keys(data);
14311
- keys.forEach((key) => this.affectedFields.add(key));
14334
+ if (this.nodesKey && Array.isArray(data[this.nodesKey])) {
14335
+ this.allFieldsAffected = true;
14336
+ } else {
14337
+ const keys = Object.keys(data);
14338
+ keys.forEach((key) => this.affectedFields.add(key));
14339
+ }
14312
14340
  }
14313
14341
  const value = this.nodePathToData.get(nodePath) || [];
14314
14342
  value.push({
@@ -14320,6 +14348,18 @@ var DataSourceCache = class {
14320
14348
  });
14321
14349
  this.nodePathToData.set(nodePath, value);
14322
14350
  };
14351
+ this.updateChildren = (nodePath, children, originalData, metadata) => {
14352
+ this.allFieldsAffected = true;
14353
+ const value = this.nodePathToData.get(nodePath) || [];
14354
+ value.push({
14355
+ type: "update-children",
14356
+ nodePath,
14357
+ children,
14358
+ originalData,
14359
+ metadata
14360
+ });
14361
+ this.nodePathToData.set(nodePath, value);
14362
+ };
14323
14363
  this.resetDataSource = (metadata) => {
14324
14364
  this.clear();
14325
14365
  this.allFieldsAffected = true;
@@ -14372,9 +14412,12 @@ var DataSourceCache = class {
14372
14412
  this.getTreeMutationsArray = () => {
14373
14413
  return Array.from(this.nodePathToData.values()).flat();
14374
14414
  };
14415
+ this.nodesKey = options.nodesKey;
14375
14416
  }
14376
14417
  static clone(cache, { light = false } = {}) {
14377
- const clone = new DataSourceCache();
14418
+ const clone = new DataSourceCache({
14419
+ nodesKey: cache.nodesKey
14420
+ });
14378
14421
  clone.allFieldsAffected = cache.allFieldsAffected;
14379
14422
  clone.affectedFields = new Set(cache.affectedFields);
14380
14423
  clone.primaryKeyToData = light ? cache.primaryKeyToData : new Map(
@@ -15250,6 +15293,7 @@ var RowDisabledState = class extends BooleanCollectionState {
15250
15293
  };
15251
15294
 
15252
15295
  // src/components/DataSource/getDataSourceApi.ts
15296
+ var DEFAULT_NODE_PATH_WAIT_TIMEOUT = 1e3;
15253
15297
  function getDataSourceApi(param) {
15254
15298
  return new DataSourceApiImpl(param);
15255
15299
  }
@@ -15313,15 +15357,20 @@ var DataSourceApiImpl = class {
15313
15357
  const { indexer } = this.getState();
15314
15358
  return indexer.getDataForPrimaryKey(id) ?? null;
15315
15359
  };
15360
+ this.isNodePathAvailable = (nodePath) => {
15361
+ return this.getState().indexer.getDataForNodePath(nodePath) !== void 0;
15362
+ };
15316
15363
  this.getDataByNodePath = (nodePath) => {
15317
15364
  const { indexer } = this.getState();
15318
15365
  const data = indexer.getDataForNodePath(nodePath);
15319
15366
  if (!data) {
15320
- console.warn(
15321
- `getDataByNodePath: no data found for nodePath: "${nodePath.join(
15322
- " / "
15323
- )}"`
15324
- );
15367
+ if (false) {
15368
+ console.warn(
15369
+ `getDataByNodePath: no data found for nodePath: "${nodePath.join(
15370
+ " / "
15371
+ )}"`
15372
+ );
15373
+ }
15325
15374
  return null;
15326
15375
  }
15327
15376
  return data;
@@ -15381,25 +15430,84 @@ var DataSourceApiImpl = class {
15381
15430
  }
15382
15431
  return result;
15383
15432
  };
15433
+ this.withWaitForNode = (nodePath, fn, options) => {
15434
+ const waitForNode = options?.waitForNode ?? true;
15435
+ if (waitForNode === true || typeof waitForNode === "number") {
15436
+ let timeout = waitForNode === true ? DEFAULT_NODE_PATH_WAIT_TIMEOUT : waitForNode;
15437
+ if (!isNaN(timeout)) {
15438
+ timeout = DEFAULT_NODE_PATH_WAIT_TIMEOUT;
15439
+ }
15440
+ return this.waitForNodePath(nodePath, { timeout }).then((okay) => {
15441
+ if (!okay) {
15442
+ const error2 = `Cannot find node path "${nodePath.join(
15443
+ "/"
15444
+ )}" (we waited for it ${timeout}ms)`;
15445
+ console.error(error2);
15446
+ return fn({
15447
+ error: error2,
15448
+ resolved: false
15449
+ });
15450
+ }
15451
+ return fn({
15452
+ resolved: true
15453
+ });
15454
+ });
15455
+ }
15456
+ const result = fn({
15457
+ resolved: void 0
15458
+ });
15459
+ return result instanceof Promise ? result : Promise.resolve(result);
15460
+ };
15384
15461
  this.updateChildrenByNodePath = (childrenOrFn, nodePath, options) => {
15385
- const data = this.getDataByNodePath(nodePath);
15386
- if (data == null) {
15387
- return Promise.resolve(null);
15388
- }
15389
- const nodesKey = this.getState().nodesKey;
15390
- const dataChildren = data[nodesKey];
15391
- const children = typeof childrenOrFn === "function" ? childrenOrFn(dataChildren, data) : childrenOrFn;
15392
- return this.updateDataByNodePath(
15393
- {
15394
- ...data,
15395
- [nodesKey]: children
15396
- },
15462
+ return this.withWaitForNode(
15397
15463
  nodePath,
15464
+ ({ error: error2 }) => {
15465
+ if (error2) {
15466
+ return false;
15467
+ }
15468
+ return this.updateChildrenByNodePath_Internal(
15469
+ childrenOrFn,
15470
+ nodePath,
15471
+ options
15472
+ );
15473
+ },
15474
+ options
15475
+ );
15476
+ };
15477
+ this.updateChildrenByNodePath_Internal = (childrenOrFn, nodePath, options) => {
15478
+ const children = typeof childrenOrFn === "function" ? childrenOrFn : () => childrenOrFn;
15479
+ return this.updateDataArrayByNodePath_Internal(
15480
+ [
15481
+ {
15482
+ nodePath,
15483
+ children
15484
+ }
15485
+ ],
15398
15486
  options
15399
15487
  );
15400
15488
  };
15401
15489
  this.updateDataByNodePath = (data, nodePath, options) => {
15402
- return this.updateDataArrayByNodePath(
15490
+ if (!this.isNodePathAvailable(nodePath)) {
15491
+ return this.withWaitForNode(
15492
+ nodePath,
15493
+ ({ error: error2 }) => {
15494
+ if (error2) {
15495
+ return false;
15496
+ }
15497
+ return this.updateDataArrayByNodePath_Internal(
15498
+ [
15499
+ {
15500
+ data,
15501
+ nodePath
15502
+ }
15503
+ ],
15504
+ options
15505
+ );
15506
+ },
15507
+ options
15508
+ );
15509
+ }
15510
+ return this.updateDataArrayByNodePath_Internal(
15403
15511
  [
15404
15512
  {
15405
15513
  data,
@@ -15410,10 +15518,31 @@ var DataSourceApiImpl = class {
15410
15518
  );
15411
15519
  };
15412
15520
  this.updateDataArrayByNodePath = (updateInfo, options) => {
15521
+ if (options && typeof options.waitForNode !== "undefined" && !options.waitForNode) {
15522
+ return this.updateDataArrayByNodePath_Internal(updateInfo, options);
15523
+ }
15524
+ const allNodePaths = updateInfo.map((info) => info.nodePath);
15525
+ const promiseWithAll = Promise.allSettled(
15526
+ allNodePaths.map((nodePath) => {
15527
+ return this.withWaitForNode(nodePath, ({ error: error2 }) => !error2, options);
15528
+ })
15529
+ );
15530
+ return promiseWithAll.then((allGood) => {
15531
+ if (!allGood.every(Boolean)) {
15532
+ return false;
15533
+ }
15534
+ return this.updateDataArrayByNodePath_Internal(updateInfo, options);
15535
+ });
15536
+ };
15537
+ this.updateDataArrayByNodePath_Internal = (updateInfo, options) => {
15413
15538
  const data = [];
15414
15539
  const nodePaths = [];
15415
15540
  updateInfo.forEach((info) => {
15416
- data.push(info.data);
15541
+ if (info.data) {
15542
+ data.push(info.data);
15543
+ } else if (info.children) {
15544
+ data.push(info.children);
15545
+ }
15417
15546
  nodePaths.push(info.nodePath);
15418
15547
  });
15419
15548
  const result = this.batchOperation({
@@ -15443,67 +15572,39 @@ var DataSourceApiImpl = class {
15443
15572
  return result;
15444
15573
  };
15445
15574
  this.removeDataByNodePath = (nodePath, options) => {
15446
- const result = this.batchOperation({
15447
- type: "delete",
15448
- nodePaths: [nodePath],
15449
- metadata: options?.metadata
15450
- });
15451
- if (options?.flush) {
15452
- this.commit();
15453
- }
15454
- return result;
15575
+ return this.batchDeleteNodePaths([nodePath], options);
15455
15576
  };
15456
15577
  this.removeData = (data, options) => {
15457
15578
  const isTree = this.getState().isTree;
15458
- let primaryKeys = !isTree ? [this.toPrimaryKey(data)] : void 0;
15459
- const nodePath = isTree ? this.getNodePathById(this.toPrimaryKey(data)) : null;
15460
- let nodePaths = isTree && nodePath ? [nodePath] : void 0;
15461
- const result = primaryKeys ? this.batchOperation({
15462
- type: "delete",
15463
- primaryKeys,
15464
- metadata: options?.metadata
15465
- }) : this.batchOperation({
15466
- type: "delete",
15467
- nodePaths: nodePaths || [],
15468
- metadata: options?.metadata
15469
- });
15470
- if (options?.flush) {
15471
- this.commit();
15579
+ if (isTree) {
15580
+ const nodePath = this.getNodePathById(this.toPrimaryKey(data));
15581
+ return this.removeDataByNodePath(nodePath, options);
15472
15582
  }
15473
- return result;
15583
+ return this.batchDeletePrimaryKeys([this.toPrimaryKey(data)], options);
15474
15584
  };
15475
15585
  this.removeDataArrayByPrimaryKeys = (ids, options) => {
15476
15586
  const isTree = this.getState().isTree;
15477
- const nodePaths = isTree ? ids.map((id) => {
15478
- return this.getNodePathById(id) || [];
15479
- }) : null;
15480
- const result = isTree ? this.batchOperation({
15587
+ if (isTree) {
15588
+ const nodePaths = ids.map((id) => this.getNodePathById(id) || []);
15589
+ return this.batchDeleteNodePaths(nodePaths, options);
15590
+ }
15591
+ return this.batchDeletePrimaryKeys(ids, options);
15592
+ };
15593
+ this.batchDeleteNodePaths = (nodePaths, options) => {
15594
+ const result = this.batchOperation({
15481
15595
  type: "delete",
15482
15596
  nodePaths: nodePaths || [],
15483
15597
  metadata: options?.metadata
15484
- }) : this.batchOperation({
15485
- type: "delete",
15486
- primaryKeys: ids,
15487
- metadata: options?.metadata
15488
15598
  });
15489
15599
  if (options?.flush) {
15490
15600
  this.commit();
15491
15601
  }
15492
15602
  return result;
15493
15603
  };
15494
- this.removeDataArray = (data, options) => {
15495
- const isTree = this.getState().isTree;
15496
- const nodePaths = isTree ? data.map((d) => {
15497
- return this.getNodePathById(this.toPrimaryKey(d)) || [];
15498
- }) : null;
15499
- const primaryKeys = !isTree ? data.map(this.toPrimaryKey) : void 0;
15500
- const result = isTree ? this.batchOperation({
15501
- type: "delete",
15502
- nodePaths: nodePaths || [],
15503
- metadata: options?.metadata
15504
- }) : this.batchOperation({
15604
+ this.batchDeletePrimaryKeys = (primaryKeys, options) => {
15605
+ const result = this.batchOperation({
15505
15606
  type: "delete",
15506
- primaryKeys: primaryKeys || [],
15607
+ primaryKeys,
15507
15608
  metadata: options?.metadata
15508
15609
  });
15509
15610
  if (options?.flush) {
@@ -15511,6 +15612,17 @@ var DataSourceApiImpl = class {
15511
15612
  }
15512
15613
  return result;
15513
15614
  };
15615
+ this.removeDataArray = (data, options) => {
15616
+ const isTree = this.getState().isTree;
15617
+ if (isTree) {
15618
+ const nodePaths = data.map((d) => {
15619
+ return this.getNodePathById(this.toPrimaryKey(d)) || [];
15620
+ });
15621
+ return this.batchDeleteNodePaths(nodePaths, options);
15622
+ }
15623
+ const primaryKeys = data.map(this.toPrimaryKey);
15624
+ return this.batchDeletePrimaryKeys(primaryKeys, options);
15625
+ };
15514
15626
  this.addData = (data, options) => {
15515
15627
  return this.addDataArray([data], options);
15516
15628
  };
@@ -15524,9 +15636,33 @@ var DataSourceApiImpl = class {
15524
15636
  return this.insertDataArray([data], options);
15525
15637
  };
15526
15638
  this.insertDataArray = (data, options) => {
15639
+ const isTree = this.getState().isTree;
15527
15640
  let position2 = "before";
15528
15641
  let primaryKey = void 0;
15529
15642
  let nodePath = options.nodePath;
15643
+ if (isTree && nodePath?.length) {
15644
+ return this.withWaitForNode(
15645
+ nodePath,
15646
+ ({ error: error2 }) => {
15647
+ if (error2) {
15648
+ return false;
15649
+ }
15650
+ if (options.position === "before" || options.position === "after") {
15651
+ return this.batchTreeInsert(
15652
+ data,
15653
+ options.position,
15654
+ nodePath,
15655
+ options
15656
+ );
15657
+ }
15658
+ const newChildren = (childrenOfNode) => {
15659
+ return options.position === "start" ? [...data, ...childrenOfNode || []] : [...childrenOfNode || [], ...data];
15660
+ };
15661
+ return this.updateChildrenByNodePath(newChildren, nodePath, options);
15662
+ },
15663
+ options
15664
+ );
15665
+ }
15530
15666
  if (options.position === "before" || options.position === "after") {
15531
15667
  position2 = options.position;
15532
15668
  primaryKey = options.primaryKey;
@@ -15534,13 +15670,20 @@ var DataSourceApiImpl = class {
15534
15670
  const arr = this.getOriginalDataArray();
15535
15671
  if (options.position === "start") {
15536
15672
  position2 = "before";
15537
- primaryKey = !arr.length ? void 0 : this.toPrimaryKey(arr[0]);
15673
+ if (!arr.length) {
15674
+ primaryKey = void 0;
15675
+ } else {
15676
+ primaryKey = this.toPrimaryKey(arr[0]);
15677
+ }
15538
15678
  } else {
15539
15679
  position2 = "after";
15540
- primaryKey = !arr.length ? void 0 : this.toPrimaryKey(arr[arr.length - 1]);
15680
+ if (!arr.length) {
15681
+ primaryKey = void 0;
15682
+ } else {
15683
+ primaryKey = this.toPrimaryKey(arr[arr.length - 1]);
15684
+ }
15541
15685
  }
15542
15686
  }
15543
- const isTree = this.getState().isTree;
15544
15687
  const result = isTree ? this.batchOperation({
15545
15688
  type: "insert",
15546
15689
  array: data,
@@ -15560,6 +15703,41 @@ var DataSourceApiImpl = class {
15560
15703
  }
15561
15704
  return result;
15562
15705
  };
15706
+ this.batchTreeInsert = (data, position2, nodePath, options) => {
15707
+ if (nodePath.length && !this.isNodePathAvailable(nodePath)) {
15708
+ return this.withWaitForNode(
15709
+ nodePath,
15710
+ ({ error: error2 }) => {
15711
+ if (error2) {
15712
+ return false;
15713
+ }
15714
+ const result2 = this.batchOperation({
15715
+ type: "insert",
15716
+ array: data,
15717
+ position: position2,
15718
+ metadata: options?.metadata,
15719
+ nodePath
15720
+ });
15721
+ if (options?.flush) {
15722
+ this.commit();
15723
+ }
15724
+ return result2;
15725
+ },
15726
+ options
15727
+ );
15728
+ }
15729
+ const result = this.batchOperation({
15730
+ type: "insert",
15731
+ array: data,
15732
+ position: position2,
15733
+ metadata: options?.metadata,
15734
+ nodePath
15735
+ });
15736
+ if (options?.flush) {
15737
+ this.commit();
15738
+ }
15739
+ return result;
15740
+ };
15563
15741
  this.setSortInfo = (sortInfo) => {
15564
15742
  const multiSort = this.getState().multiSort;
15565
15743
  if (Array.isArray(sortInfo)) {
@@ -15636,6 +15814,9 @@ var DataSourceApiImpl = class {
15636
15814
  this.actions = param.actions;
15637
15815
  this.treeApi = new TreeApiImpl({ ...param, dataSourceApi: this });
15638
15816
  }
15817
+ getPendingOperationPromise() {
15818
+ return this.pendingPromise;
15819
+ }
15639
15820
  batchOperation(operation) {
15640
15821
  if (!this.pendingPromise) {
15641
15822
  this.pendingPromise = new Promise((resolve) => {
@@ -15665,7 +15846,8 @@ var DataSourceApiImpl = class {
15665
15846
  return;
15666
15847
  }
15667
15848
  const currentCache = this.getState().cache;
15668
- let cache = currentCache ? DataSourceCache.clone(currentCache, { light: true }) : new DataSourceCache();
15849
+ const { isTree, nodesKey } = this.getState();
15850
+ let cache = currentCache ? DataSourceCache.clone(currentCache, { light: true }) : new DataSourceCache({ nodesKey: isTree ? nodesKey : void 0 });
15669
15851
  operations.forEach((operation) => {
15670
15852
  switch (operation.type) {
15671
15853
  case "update":
@@ -15686,12 +15868,21 @@ var DataSourceApiImpl = class {
15686
15868
  operation.nodePaths[index]
15687
15869
  );
15688
15870
  if (originalData) {
15689
- cache.updateNodePath(
15690
- operation.nodePaths[index],
15691
- data,
15692
- originalData,
15693
- operation.metadata
15694
- );
15871
+ if (typeof data === "function") {
15872
+ cache.updateChildren(
15873
+ operation.nodePaths[index],
15874
+ data,
15875
+ originalData,
15876
+ operation.metadata
15877
+ );
15878
+ } else {
15879
+ cache.updateNodePath(
15880
+ operation.nodePaths[index],
15881
+ data,
15882
+ originalData,
15883
+ operation.metadata
15884
+ );
15885
+ }
15695
15886
  }
15696
15887
  }
15697
15888
  });
@@ -15724,7 +15915,7 @@ var DataSourceApiImpl = class {
15724
15915
  if (nodePath) {
15725
15916
  operation.array.forEach((data) => {
15726
15917
  cache.insertNodePath(
15727
- nodePath,
15918
+ [...nodePath],
15728
15919
  data,
15729
15920
  position2,
15730
15921
  operation.metadata
@@ -15752,6 +15943,41 @@ var DataSourceApiImpl = class {
15752
15943
  flush() {
15753
15944
  return this.commit();
15754
15945
  }
15946
+ waitForNodePath(nodePath, options) {
15947
+ const state = this.getState();
15948
+ if (this.isNodePathAvailable(nodePath)) {
15949
+ return Promise.resolve(true);
15950
+ }
15951
+ const timeout = options?.timeout ?? DEFAULT_NODE_PATH_WAIT_TIMEOUT;
15952
+ const result = state.waitForNodePathPromises.get(nodePath);
15953
+ if (result) {
15954
+ return result.promise;
15955
+ }
15956
+ const timestamp = Date.now();
15957
+ let resolve = () => {
15958
+ };
15959
+ const promise = new Promise((res) => {
15960
+ let resolved;
15961
+ let timeoutId;
15962
+ resolve = (value) => {
15963
+ clearTimeout(timeoutId);
15964
+ resolved = value;
15965
+ state.waitForNodePathPromises.delete(nodePath);
15966
+ res(value);
15967
+ };
15968
+ timeoutId = setTimeout(() => {
15969
+ if (resolved === void 0) {
15970
+ resolve(false);
15971
+ }
15972
+ }, timeout);
15973
+ });
15974
+ state.waitForNodePathPromises.set(nodePath, {
15975
+ timestamp,
15976
+ promise,
15977
+ resolve
15978
+ });
15979
+ return promise;
15980
+ }
15755
15981
  commit() {
15756
15982
  this.commitOperations(this.pendingOperations);
15757
15983
  this.pendingOperations.length = 0;
@@ -16070,6 +16296,7 @@ function concludeReducer(params) {
16070
16296
  }
16071
16297
  const toPrimaryKey = state.toPrimaryKey;
16072
16298
  const nodesKey = state.nodesKey;
16299
+ const isTree = state.isTree;
16073
16300
  const getNodeChildren = nodesKey ? (node) => {
16074
16301
  return node[nodesKey];
16075
16302
  } : void 0;
@@ -16094,6 +16321,16 @@ function concludeReducer(params) {
16094
16321
  nodesKey
16095
16322
  }
16096
16323
  );
16324
+ if (isTree) {
16325
+ state.waitForNodePathPromises.visit(({ value }, keys) => {
16326
+ if (!value) {
16327
+ return;
16328
+ }
16329
+ if (state.indexer.getDataForNodePath(keys) !== void 0) {
16330
+ value.resolve(true);
16331
+ }
16332
+ });
16333
+ }
16097
16334
  }
16098
16335
  }
16099
16336
  if (cache) {
@@ -16115,7 +16352,6 @@ function concludeReducer(params) {
16115
16352
  const shouldSortAgain = shouldSort && (sortDepsChanged || !state.lastSortDataArray || cacheAffectedParts.sortInfo);
16116
16353
  const groupBy = state.groupBy;
16117
16354
  const pivotBy = state.pivotBy;
16118
- const isTree = state.isTree;
16119
16355
  const shouldGroup = !isTree && (groupBy.length > 0 || !!pivotBy);
16120
16356
  const shouldTree = isTree;
16121
16357
  const rowDisabledStateDepsChanged = haveDepsChanged(previousState, state, [
@@ -17198,6 +17434,7 @@ function initSetupState() {
17198
17434
  idToIndexMap: /* @__PURE__ */ new Map(),
17199
17435
  idToPathMap: /* @__PURE__ */ new Map(),
17200
17436
  pathToIndexMap: new DeepMap(),
17437
+ waitForNodePathPromises: new DeepMap(),
17201
17438
  getDataSourceMasterContextRef: { current: () => void 0 },
17202
17439
  // TODO: cleanup cache on unmount
17203
17440
  cache: void 0,
@@ -17270,6 +17507,7 @@ var cleanupDataSource = (state) => {
17270
17507
  };
17271
17508
  state.treeExpandState?.destroy();
17272
17509
  state.treePaths?.clear();
17510
+ state.waitForNodePathPromises.clear();
17273
17511
  state.pathToIndexMap?.clear();
17274
17512
  state.rowDisabledState?.destroy();
17275
17513
  state.groupRowsState?.destroy();
@@ -22226,7 +22464,7 @@ var useLicense = (licenseKey = "") => {
22226
22464
  }
22227
22465
  let valid2 = isValidLicense(licenseKey, {
22228
22466
  publishedAt: 1624970570587,
22229
- version: "6.0.14"
22467
+ version: "6.0.16"
22230
22468
  });
22231
22469
  if (!licenseKey && !valid2 && isInsidePlayground) {
22232
22470
  return true;
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "bugs": {
26
26
  "url": "https://github.com/infinite-table/infinite-react/issues"
27
27
  },
28
- "version": "6.0.14",
28
+ "version": "6.0.16",
29
29
  "main": "index.js",
30
30
  "module": "index.mjs",
31
31
  "typings": "index.d.ts",
@@ -34,5 +34,5 @@
34
34
  },
35
35
  "license": "Commercial & Open Source",
36
36
  "//": "will be updated at build time",
37
- "publishedAt": 1731510719445
37
+ "publishedAt": 1732547734552
38
38
  }