@infinite-table/infinite-react 5.0.0-canary.1 → 5.0.0-canary.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
@@ -1903,6 +1903,10 @@ declare type DataSourceMutation<T> = {
1903
1903
  originalData: null;
1904
1904
  data: T;
1905
1905
  metadata: any;
1906
+ } | {
1907
+ type: 'clear-all';
1908
+ primaryKey: undefined;
1909
+ metadata: any;
1906
1910
  };
1907
1911
  declare class DataSourceCache<DataType, PrimaryKeyType = string> {
1908
1912
  private affectedFields;
@@ -1915,11 +1919,15 @@ declare class DataSourceCache<DataType, PrimaryKeyType = string> {
1915
1919
  delete: (primaryKey: PrimaryKeyType, originalData: DataType, metadata: any) => void;
1916
1920
  insert: (primaryKey: PrimaryKeyType, data: DataType, position: 'before' | 'after', metadata: any) => void;
1917
1921
  update: (primaryKey: PrimaryKeyType, data: Partial<DataType>, originalData: DataType, metadata: any) => void;
1922
+ resetDataSource: (metadata: any) => void;
1923
+ shouldResetDataSource: () => boolean;
1918
1924
  clear: () => void;
1919
1925
  isEmpty: () => boolean;
1920
1926
  removeInfo: (primaryKey: PrimaryKeyType) => void;
1921
1927
  getMutationsForPrimaryKey: (primaryKey: PrimaryKeyType) => DataSourceMutation<DataType>[] | undefined;
1928
+ getMutationsCount: () => number;
1922
1929
  getMutations: () => Map<PrimaryKeyType, DataSourceMutation<DataType>[]>;
1930
+ getMutationsArray: () => DataSourceMutation<DataType>[];
1923
1931
  }
1924
1932
 
1925
1933
  declare type BooleanDeepCollectionStateKeys<KeyType> = true | KeyType[][];
@@ -2215,10 +2223,13 @@ interface DataSourceApi<T> {
2215
2223
  getPrimaryKeyByIndex(id: any): any;
2216
2224
  updateData(data: Partial<T>, options?: DataSourceCRUDParam): Promise<any>;
2217
2225
  updateDataArray(data: Partial<T>[], options?: DataSourceCRUDParam): Promise<any>;
2226
+ flush(): Promise<any>;
2218
2227
  removeDataByPrimaryKey(id: any, options?: DataSourceCRUDParam): Promise<any>;
2219
2228
  removeDataArrayByPrimaryKeys(id: any[], options?: DataSourceCRUDParam): Promise<any>;
2220
2229
  removeData(data: Partial<T>, options?: DataSourceCRUDParam): Promise<any>;
2221
2230
  removeDataArray(data: Partial<T>[], options?: DataSourceCRUDParam): Promise<any>;
2231
+ clearAllData(options?: DataSourceCRUDParam): Promise<any>;
2232
+ replaceAllData(data: T[], options?: DataSourceCRUDParam): Promise<any>;
2222
2233
  addData(data: T, options?: DataSourceCRUDParam): Promise<any>;
2223
2234
  addDataArray(data: T[], options?: DataSourceCRUDParam): Promise<any>;
2224
2235
  insertData(data: T, options: DataSourceInsertParam): Promise<any>;
package/index.dev.js CHANGED
@@ -8827,6 +8827,7 @@ function InfiniteTableColumnCellFn(props) {
8827
8827
  if (inEdit) {
8828
8828
  return null;
8829
8829
  }
8830
+ renderParamRef.current = renderParam;
8830
8831
  if (renderFunctions.renderGroupIcon) {
8831
8832
  renderParam.renderBag.groupIcon = /* @__PURE__ */ React36.createElement(
8832
8833
  RenderCellHookComponent,
@@ -9040,6 +9041,7 @@ function InfiniteTableColumnCellFn(props) {
9040
9041
  bottom: bottomSelectionBorder
9041
9042
  } : null;
9042
9043
  const afterChildren = editor;
9044
+ const theChildren = renderChildren();
9043
9045
  const cellProps = {
9044
9046
  domRef,
9045
9047
  cellType: "body",
@@ -9078,7 +9080,7 @@ function InfiniteTableColumnCellFn(props) {
9078
9080
  colClassName,
9079
9081
  rowComputedClassName
9080
9082
  ),
9081
- renderChildren
9083
+ renderChildren: (0, import_react25.useCallback)(() => theChildren, [renderChildren])
9082
9084
  };
9083
9085
  const ContextProvider = InfiniteTableColumnCellContext.Provider;
9084
9086
  return (
@@ -10870,7 +10872,7 @@ function lazyGroup(groupParams, rootData) {
10870
10872
  rootData.visitDepthFirst(
10871
10873
  (lazyGroupRowInfo, keys, _index, next) => {
10872
10874
  const [_rootKey, ...currentGroupKeys] = keys;
10873
- const dataArray = lazyGroupRowInfo.children;
10875
+ let dataArray = lazyGroupRowInfo.children;
10874
10876
  const current = deepMap.get(currentGroupKeys);
10875
10877
  if (current) {
10876
10878
  current.cache = lazyGroupRowInfo.cache;
@@ -10893,10 +10895,11 @@ function lazyGroup(groupParams, rootData) {
10893
10895
  );
10894
10896
  }
10895
10897
  }
10896
- indexer.indexArray(dataArray, {
10898
+ const res = indexer.indexArray(dataArray, {
10897
10899
  toPrimaryKey,
10898
10900
  cache
10899
10901
  });
10902
+ dataArray = res;
10900
10903
  }
10901
10904
  return next == null ? void 0 : next();
10902
10905
  }
@@ -12889,11 +12892,15 @@ var Indexer = class {
12889
12892
  };
12890
12893
  this.indexArray = (arr, options) => {
12891
12894
  const { cache, toPrimaryKey } = options;
12895
+ if (cache && cache.shouldResetDataSource()) {
12896
+ this.clear();
12897
+ arr = [];
12898
+ }
12892
12899
  if (cache && !cache.isEmpty()) {
12893
12900
  arr = arr.concat();
12894
12901
  }
12895
12902
  if (!arr.length && cache) {
12896
- const cacheInfo = [...cache.getMutations().values()].flatMap((x) => x);
12903
+ const cacheInfo = cache.getMutationsArray();
12897
12904
  if (cacheInfo && cacheInfo.length) {
12898
12905
  for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
12899
12906
  const info = cacheInfo[cacheIndex];
@@ -13206,6 +13213,7 @@ function getPivotColumnsAndColumnGroups({
13206
13213
  }
13207
13214
 
13208
13215
  // src/components/DataSource/DataSourceCache.ts
13216
+ var CLEAR_SYMBOL = Symbol("CLEAR");
13209
13217
  var DataSourceCache = class {
13210
13218
  constructor() {
13211
13219
  this.affectedFields = /* @__PURE__ */ new Set();
@@ -13259,6 +13267,21 @@ var DataSourceCache = class {
13259
13267
  });
13260
13268
  this.primaryKeyToData.set(primaryKey, value);
13261
13269
  };
13270
+ this.resetDataSource = (metadata) => {
13271
+ this.clear();
13272
+ this.allFieldsAffected = true;
13273
+ const pk = CLEAR_SYMBOL;
13274
+ const value = this.primaryKeyToData.get(pk) || [];
13275
+ value.push({
13276
+ type: "clear-all",
13277
+ primaryKey: void 0,
13278
+ metadata
13279
+ });
13280
+ this.primaryKeyToData.set(pk, value);
13281
+ };
13282
+ this.shouldResetDataSource = () => {
13283
+ return this.primaryKeyToData.has(CLEAR_SYMBOL);
13284
+ };
13262
13285
  this.clear = () => {
13263
13286
  this.allFieldsAffected = false;
13264
13287
  this.affectedFields.clear();
@@ -13274,9 +13297,15 @@ var DataSourceCache = class {
13274
13297
  const data = this.primaryKeyToData.get(primaryKey);
13275
13298
  return data;
13276
13299
  };
13300
+ this.getMutationsCount = () => {
13301
+ return this.primaryKeyToData.size;
13302
+ };
13277
13303
  this.getMutations = () => {
13278
13304
  return new Map(this.primaryKeyToData);
13279
13305
  };
13306
+ this.getMutationsArray = () => {
13307
+ return Array.from(this.primaryKeyToData.values()).flat();
13308
+ };
13280
13309
  }
13281
13310
  static clone(cache, { light = false } = {}) {
13282
13311
  const clone = new DataSourceCache();
@@ -13538,6 +13567,32 @@ var DataSourceApiImpl = class {
13538
13567
  const { indexer } = this.getState();
13539
13568
  return (_a = indexer.getDataForPrimaryKey(id)) != null ? _a : null;
13540
13569
  };
13570
+ /**
13571
+ * Replaces all data in the DataSource with the provided data.
13572
+ * @param data - The new data to replace the existing data with.
13573
+ * @param options - Additional options for the operation.
13574
+ * @param options.flush - If true, the mutations will be flushed immediately.
13575
+ * @param options.metadata - Additional metadata for the operation.
13576
+ * @returns A promise that resolves when the operation is complete.
13577
+ */
13578
+ this.replaceAllData = (data, options) => {
13579
+ this.batchOperation({
13580
+ type: "replace-all",
13581
+ array: data,
13582
+ metadata: options == null ? void 0 : options.metadata
13583
+ });
13584
+ return this.addDataArray(data, options);
13585
+ };
13586
+ /**
13587
+ * Clears all data in the DataSource.
13588
+ * @param options - Additional options for the operation.
13589
+ * @param options.flush - If true, the mutations will be flushed immediately.
13590
+ * @param options.metadata - Additional metadata for the operation.
13591
+ * @returns A promise that resolves when the operation is complete.
13592
+ */
13593
+ this.clearAllData = (options) => {
13594
+ return this.replaceAllData([], options);
13595
+ };
13541
13596
  this.updateData = (data, options) => {
13542
13597
  return this.updateDataArray([data], options);
13543
13598
  };
@@ -13733,12 +13788,12 @@ var DataSourceApiImpl = class {
13733
13788
  }, delay);
13734
13789
  }
13735
13790
  }
13791
+ if (operation.type === "replace-all") {
13792
+ this.pendingOperations.length = 0;
13793
+ }
13736
13794
  this.pendingOperations.push(operation);
13737
13795
  return this.pendingPromise;
13738
13796
  }
13739
- batchOperations(operations) {
13740
- this.pendingOperations.push(...operations);
13741
- }
13742
13797
  commitOperations(operations) {
13743
13798
  if (!operations.length) {
13744
13799
  return;
@@ -13778,14 +13833,21 @@ var DataSourceApiImpl = class {
13778
13833
  position2 = "after";
13779
13834
  });
13780
13835
  break;
13836
+ case "replace-all":
13837
+ cache.resetDataSource(operation.metadata);
13838
+ break;
13781
13839
  }
13782
13840
  });
13783
13841
  this.actions.cache = cache;
13784
13842
  }
13843
+ flush() {
13844
+ return this.commit();
13845
+ }
13785
13846
  commit() {
13786
13847
  this.commitOperations(this.pendingOperations);
13787
13848
  this.pendingOperations.length = 0;
13788
- if (this.pendingPromise && this.resolvePendingPromise) {
13849
+ const pendingPromise = this.pendingPromise;
13850
+ if (pendingPromise && this.resolvePendingPromise) {
13789
13851
  const resolve = this.resolvePendingPromise;
13790
13852
  requestAnimationFrame(() => {
13791
13853
  resolve(true);
@@ -13793,6 +13855,7 @@ var DataSourceApiImpl = class {
13793
13855
  this.pendingPromise = null;
13794
13856
  this.resolvePendingPromise = null;
13795
13857
  }
13858
+ return pendingPromise || Promise.resolve(true);
13796
13859
  }
13797
13860
  };
13798
13861
  function getCacheAffectedParts(state) {
@@ -19765,7 +19828,7 @@ var useLicense = (licenseKey = "") => {
19765
19828
  }
19766
19829
  let valid2 = isValidLicense(licenseKey, {
19767
19830
  publishedAt: 1624970570587,
19768
- version: "5.0.0-canary.1"
19831
+ version: "5.0.0-canary.2"
19769
19832
  });
19770
19833
  if (!licenseKey && !valid2 && isInsidePlayground) {
19771
19834
  return true;
package/index.dev.mjs CHANGED
@@ -8789,6 +8789,7 @@ function InfiniteTableColumnCellFn(props) {
8789
8789
  if (inEdit) {
8790
8790
  return null;
8791
8791
  }
8792
+ renderParamRef.current = renderParam;
8792
8793
  if (renderFunctions.renderGroupIcon) {
8793
8794
  renderParam.renderBag.groupIcon = /* @__PURE__ */ React36.createElement(
8794
8795
  RenderCellHookComponent,
@@ -9002,6 +9003,7 @@ function InfiniteTableColumnCellFn(props) {
9002
9003
  bottom: bottomSelectionBorder
9003
9004
  } : null;
9004
9005
  const afterChildren = editor;
9006
+ const theChildren = renderChildren();
9005
9007
  const cellProps = {
9006
9008
  domRef,
9007
9009
  cellType: "body",
@@ -9040,7 +9042,7 @@ function InfiniteTableColumnCellFn(props) {
9040
9042
  colClassName,
9041
9043
  rowComputedClassName
9042
9044
  ),
9043
- renderChildren
9045
+ renderChildren: useCallback12(() => theChildren, [renderChildren])
9044
9046
  };
9045
9047
  const ContextProvider = InfiniteTableColumnCellContext.Provider;
9046
9048
  return (
@@ -10832,7 +10834,7 @@ function lazyGroup(groupParams, rootData) {
10832
10834
  rootData.visitDepthFirst(
10833
10835
  (lazyGroupRowInfo, keys, _index, next) => {
10834
10836
  const [_rootKey, ...currentGroupKeys] = keys;
10835
- const dataArray = lazyGroupRowInfo.children;
10837
+ let dataArray = lazyGroupRowInfo.children;
10836
10838
  const current = deepMap.get(currentGroupKeys);
10837
10839
  if (current) {
10838
10840
  current.cache = lazyGroupRowInfo.cache;
@@ -10855,10 +10857,11 @@ function lazyGroup(groupParams, rootData) {
10855
10857
  );
10856
10858
  }
10857
10859
  }
10858
- indexer.indexArray(dataArray, {
10860
+ const res = indexer.indexArray(dataArray, {
10859
10861
  toPrimaryKey,
10860
10862
  cache
10861
10863
  });
10864
+ dataArray = res;
10862
10865
  }
10863
10866
  return next == null ? void 0 : next();
10864
10867
  }
@@ -12851,11 +12854,15 @@ var Indexer = class {
12851
12854
  };
12852
12855
  this.indexArray = (arr, options) => {
12853
12856
  const { cache, toPrimaryKey } = options;
12857
+ if (cache && cache.shouldResetDataSource()) {
12858
+ this.clear();
12859
+ arr = [];
12860
+ }
12854
12861
  if (cache && !cache.isEmpty()) {
12855
12862
  arr = arr.concat();
12856
12863
  }
12857
12864
  if (!arr.length && cache) {
12858
- const cacheInfo = [...cache.getMutations().values()].flatMap((x) => x);
12865
+ const cacheInfo = cache.getMutationsArray();
12859
12866
  if (cacheInfo && cacheInfo.length) {
12860
12867
  for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
12861
12868
  const info = cacheInfo[cacheIndex];
@@ -13168,6 +13175,7 @@ function getPivotColumnsAndColumnGroups({
13168
13175
  }
13169
13176
 
13170
13177
  // src/components/DataSource/DataSourceCache.ts
13178
+ var CLEAR_SYMBOL = Symbol("CLEAR");
13171
13179
  var DataSourceCache = class {
13172
13180
  constructor() {
13173
13181
  this.affectedFields = /* @__PURE__ */ new Set();
@@ -13221,6 +13229,21 @@ var DataSourceCache = class {
13221
13229
  });
13222
13230
  this.primaryKeyToData.set(primaryKey, value);
13223
13231
  };
13232
+ this.resetDataSource = (metadata) => {
13233
+ this.clear();
13234
+ this.allFieldsAffected = true;
13235
+ const pk = CLEAR_SYMBOL;
13236
+ const value = this.primaryKeyToData.get(pk) || [];
13237
+ value.push({
13238
+ type: "clear-all",
13239
+ primaryKey: void 0,
13240
+ metadata
13241
+ });
13242
+ this.primaryKeyToData.set(pk, value);
13243
+ };
13244
+ this.shouldResetDataSource = () => {
13245
+ return this.primaryKeyToData.has(CLEAR_SYMBOL);
13246
+ };
13224
13247
  this.clear = () => {
13225
13248
  this.allFieldsAffected = false;
13226
13249
  this.affectedFields.clear();
@@ -13236,9 +13259,15 @@ var DataSourceCache = class {
13236
13259
  const data = this.primaryKeyToData.get(primaryKey);
13237
13260
  return data;
13238
13261
  };
13262
+ this.getMutationsCount = () => {
13263
+ return this.primaryKeyToData.size;
13264
+ };
13239
13265
  this.getMutations = () => {
13240
13266
  return new Map(this.primaryKeyToData);
13241
13267
  };
13268
+ this.getMutationsArray = () => {
13269
+ return Array.from(this.primaryKeyToData.values()).flat();
13270
+ };
13242
13271
  }
13243
13272
  static clone(cache, { light = false } = {}) {
13244
13273
  const clone = new DataSourceCache();
@@ -13500,6 +13529,32 @@ var DataSourceApiImpl = class {
13500
13529
  const { indexer } = this.getState();
13501
13530
  return (_a = indexer.getDataForPrimaryKey(id)) != null ? _a : null;
13502
13531
  };
13532
+ /**
13533
+ * Replaces all data in the DataSource with the provided data.
13534
+ * @param data - The new data to replace the existing data with.
13535
+ * @param options - Additional options for the operation.
13536
+ * @param options.flush - If true, the mutations will be flushed immediately.
13537
+ * @param options.metadata - Additional metadata for the operation.
13538
+ * @returns A promise that resolves when the operation is complete.
13539
+ */
13540
+ this.replaceAllData = (data, options) => {
13541
+ this.batchOperation({
13542
+ type: "replace-all",
13543
+ array: data,
13544
+ metadata: options == null ? void 0 : options.metadata
13545
+ });
13546
+ return this.addDataArray(data, options);
13547
+ };
13548
+ /**
13549
+ * Clears all data in the DataSource.
13550
+ * @param options - Additional options for the operation.
13551
+ * @param options.flush - If true, the mutations will be flushed immediately.
13552
+ * @param options.metadata - Additional metadata for the operation.
13553
+ * @returns A promise that resolves when the operation is complete.
13554
+ */
13555
+ this.clearAllData = (options) => {
13556
+ return this.replaceAllData([], options);
13557
+ };
13503
13558
  this.updateData = (data, options) => {
13504
13559
  return this.updateDataArray([data], options);
13505
13560
  };
@@ -13695,12 +13750,12 @@ var DataSourceApiImpl = class {
13695
13750
  }, delay);
13696
13751
  }
13697
13752
  }
13753
+ if (operation.type === "replace-all") {
13754
+ this.pendingOperations.length = 0;
13755
+ }
13698
13756
  this.pendingOperations.push(operation);
13699
13757
  return this.pendingPromise;
13700
13758
  }
13701
- batchOperations(operations) {
13702
- this.pendingOperations.push(...operations);
13703
- }
13704
13759
  commitOperations(operations) {
13705
13760
  if (!operations.length) {
13706
13761
  return;
@@ -13740,14 +13795,21 @@ var DataSourceApiImpl = class {
13740
13795
  position2 = "after";
13741
13796
  });
13742
13797
  break;
13798
+ case "replace-all":
13799
+ cache.resetDataSource(operation.metadata);
13800
+ break;
13743
13801
  }
13744
13802
  });
13745
13803
  this.actions.cache = cache;
13746
13804
  }
13805
+ flush() {
13806
+ return this.commit();
13807
+ }
13747
13808
  commit() {
13748
13809
  this.commitOperations(this.pendingOperations);
13749
13810
  this.pendingOperations.length = 0;
13750
- if (this.pendingPromise && this.resolvePendingPromise) {
13811
+ const pendingPromise = this.pendingPromise;
13812
+ if (pendingPromise && this.resolvePendingPromise) {
13751
13813
  const resolve = this.resolvePendingPromise;
13752
13814
  requestAnimationFrame(() => {
13753
13815
  resolve(true);
@@ -13755,6 +13817,7 @@ var DataSourceApiImpl = class {
13755
13817
  this.pendingPromise = null;
13756
13818
  this.resolvePendingPromise = null;
13757
13819
  }
13820
+ return pendingPromise || Promise.resolve(true);
13758
13821
  }
13759
13822
  };
13760
13823
  function getCacheAffectedParts(state) {
@@ -19736,7 +19799,7 @@ var useLicense = (licenseKey = "") => {
19736
19799
  }
19737
19800
  let valid2 = isValidLicense(licenseKey, {
19738
19801
  publishedAt: 1624970570587,
19739
- version: "5.0.0-canary.1"
19802
+ version: "5.0.0-canary.2"
19740
19803
  });
19741
19804
  if (!licenseKey && !valid2 && isInsidePlayground) {
19742
19805
  return true;
package/index.js CHANGED
@@ -8827,6 +8827,7 @@ function InfiniteTableColumnCellFn(props) {
8827
8827
  if (inEdit) {
8828
8828
  return null;
8829
8829
  }
8830
+ renderParamRef.current = renderParam;
8830
8831
  if (renderFunctions.renderGroupIcon) {
8831
8832
  renderParam.renderBag.groupIcon = /* @__PURE__ */ React36.createElement(
8832
8833
  RenderCellHookComponent,
@@ -9040,6 +9041,7 @@ function InfiniteTableColumnCellFn(props) {
9040
9041
  bottom: bottomSelectionBorder
9041
9042
  } : null;
9042
9043
  const afterChildren = editor;
9044
+ const theChildren = renderChildren();
9043
9045
  const cellProps = {
9044
9046
  domRef,
9045
9047
  cellType: "body",
@@ -9078,7 +9080,7 @@ function InfiniteTableColumnCellFn(props) {
9078
9080
  colClassName,
9079
9081
  rowComputedClassName
9080
9082
  ),
9081
- renderChildren
9083
+ renderChildren: (0, import_react25.useCallback)(() => theChildren, [renderChildren])
9082
9084
  };
9083
9085
  const ContextProvider = InfiniteTableColumnCellContext.Provider;
9084
9086
  return (
@@ -10870,7 +10872,7 @@ function lazyGroup(groupParams, rootData) {
10870
10872
  rootData.visitDepthFirst(
10871
10873
  (lazyGroupRowInfo, keys, _index, next) => {
10872
10874
  const [_rootKey, ...currentGroupKeys] = keys;
10873
- const dataArray = lazyGroupRowInfo.children;
10875
+ let dataArray = lazyGroupRowInfo.children;
10874
10876
  const current = deepMap.get(currentGroupKeys);
10875
10877
  if (current) {
10876
10878
  current.cache = lazyGroupRowInfo.cache;
@@ -10893,10 +10895,11 @@ function lazyGroup(groupParams, rootData) {
10893
10895
  );
10894
10896
  }
10895
10897
  }
10896
- indexer.indexArray(dataArray, {
10898
+ const res = indexer.indexArray(dataArray, {
10897
10899
  toPrimaryKey,
10898
10900
  cache
10899
10901
  });
10902
+ dataArray = res;
10900
10903
  }
10901
10904
  return next == null ? void 0 : next();
10902
10905
  }
@@ -12889,11 +12892,15 @@ var Indexer = class {
12889
12892
  };
12890
12893
  this.indexArray = (arr, options) => {
12891
12894
  const { cache, toPrimaryKey } = options;
12895
+ if (cache && cache.shouldResetDataSource()) {
12896
+ this.clear();
12897
+ arr = [];
12898
+ }
12892
12899
  if (cache && !cache.isEmpty()) {
12893
12900
  arr = arr.concat();
12894
12901
  }
12895
12902
  if (!arr.length && cache) {
12896
- const cacheInfo = [...cache.getMutations().values()].flatMap((x) => x);
12903
+ const cacheInfo = cache.getMutationsArray();
12897
12904
  if (cacheInfo && cacheInfo.length) {
12898
12905
  for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
12899
12906
  const info = cacheInfo[cacheIndex];
@@ -13206,6 +13213,7 @@ function getPivotColumnsAndColumnGroups({
13206
13213
  }
13207
13214
 
13208
13215
  // src/components/DataSource/DataSourceCache.ts
13216
+ var CLEAR_SYMBOL = Symbol("CLEAR");
13209
13217
  var DataSourceCache = class {
13210
13218
  constructor() {
13211
13219
  this.affectedFields = /* @__PURE__ */ new Set();
@@ -13259,6 +13267,21 @@ var DataSourceCache = class {
13259
13267
  });
13260
13268
  this.primaryKeyToData.set(primaryKey, value);
13261
13269
  };
13270
+ this.resetDataSource = (metadata) => {
13271
+ this.clear();
13272
+ this.allFieldsAffected = true;
13273
+ const pk = CLEAR_SYMBOL;
13274
+ const value = this.primaryKeyToData.get(pk) || [];
13275
+ value.push({
13276
+ type: "clear-all",
13277
+ primaryKey: void 0,
13278
+ metadata
13279
+ });
13280
+ this.primaryKeyToData.set(pk, value);
13281
+ };
13282
+ this.shouldResetDataSource = () => {
13283
+ return this.primaryKeyToData.has(CLEAR_SYMBOL);
13284
+ };
13262
13285
  this.clear = () => {
13263
13286
  this.allFieldsAffected = false;
13264
13287
  this.affectedFields.clear();
@@ -13274,9 +13297,15 @@ var DataSourceCache = class {
13274
13297
  const data = this.primaryKeyToData.get(primaryKey);
13275
13298
  return data;
13276
13299
  };
13300
+ this.getMutationsCount = () => {
13301
+ return this.primaryKeyToData.size;
13302
+ };
13277
13303
  this.getMutations = () => {
13278
13304
  return new Map(this.primaryKeyToData);
13279
13305
  };
13306
+ this.getMutationsArray = () => {
13307
+ return Array.from(this.primaryKeyToData.values()).flat();
13308
+ };
13280
13309
  }
13281
13310
  static clone(cache, { light = false } = {}) {
13282
13311
  const clone = new DataSourceCache();
@@ -13538,6 +13567,32 @@ var DataSourceApiImpl = class {
13538
13567
  const { indexer } = this.getState();
13539
13568
  return (_a = indexer.getDataForPrimaryKey(id)) != null ? _a : null;
13540
13569
  };
13570
+ /**
13571
+ * Replaces all data in the DataSource with the provided data.
13572
+ * @param data - The new data to replace the existing data with.
13573
+ * @param options - Additional options for the operation.
13574
+ * @param options.flush - If true, the mutations will be flushed immediately.
13575
+ * @param options.metadata - Additional metadata for the operation.
13576
+ * @returns A promise that resolves when the operation is complete.
13577
+ */
13578
+ this.replaceAllData = (data, options) => {
13579
+ this.batchOperation({
13580
+ type: "replace-all",
13581
+ array: data,
13582
+ metadata: options == null ? void 0 : options.metadata
13583
+ });
13584
+ return this.addDataArray(data, options);
13585
+ };
13586
+ /**
13587
+ * Clears all data in the DataSource.
13588
+ * @param options - Additional options for the operation.
13589
+ * @param options.flush - If true, the mutations will be flushed immediately.
13590
+ * @param options.metadata - Additional metadata for the operation.
13591
+ * @returns A promise that resolves when the operation is complete.
13592
+ */
13593
+ this.clearAllData = (options) => {
13594
+ return this.replaceAllData([], options);
13595
+ };
13541
13596
  this.updateData = (data, options) => {
13542
13597
  return this.updateDataArray([data], options);
13543
13598
  };
@@ -13733,12 +13788,12 @@ var DataSourceApiImpl = class {
13733
13788
  }, delay);
13734
13789
  }
13735
13790
  }
13791
+ if (operation.type === "replace-all") {
13792
+ this.pendingOperations.length = 0;
13793
+ }
13736
13794
  this.pendingOperations.push(operation);
13737
13795
  return this.pendingPromise;
13738
13796
  }
13739
- batchOperations(operations) {
13740
- this.pendingOperations.push(...operations);
13741
- }
13742
13797
  commitOperations(operations) {
13743
13798
  if (!operations.length) {
13744
13799
  return;
@@ -13778,14 +13833,21 @@ var DataSourceApiImpl = class {
13778
13833
  position2 = "after";
13779
13834
  });
13780
13835
  break;
13836
+ case "replace-all":
13837
+ cache.resetDataSource(operation.metadata);
13838
+ break;
13781
13839
  }
13782
13840
  });
13783
13841
  this.actions.cache = cache;
13784
13842
  }
13843
+ flush() {
13844
+ return this.commit();
13845
+ }
13785
13846
  commit() {
13786
13847
  this.commitOperations(this.pendingOperations);
13787
13848
  this.pendingOperations.length = 0;
13788
- if (this.pendingPromise && this.resolvePendingPromise) {
13849
+ const pendingPromise = this.pendingPromise;
13850
+ if (pendingPromise && this.resolvePendingPromise) {
13789
13851
  const resolve = this.resolvePendingPromise;
13790
13852
  requestAnimationFrame(() => {
13791
13853
  resolve(true);
@@ -13793,6 +13855,7 @@ var DataSourceApiImpl = class {
13793
13855
  this.pendingPromise = null;
13794
13856
  this.resolvePendingPromise = null;
13795
13857
  }
13858
+ return pendingPromise || Promise.resolve(true);
13796
13859
  }
13797
13860
  };
13798
13861
  function getCacheAffectedParts(state) {
@@ -19765,7 +19828,7 @@ var useLicense = (licenseKey = "") => {
19765
19828
  }
19766
19829
  let valid2 = isValidLicense(licenseKey, {
19767
19830
  publishedAt: 1624970570587,
19768
- version: "5.0.0-canary.1"
19831
+ version: "5.0.0-canary.2"
19769
19832
  });
19770
19833
  if (!licenseKey && !valid2 && isInsidePlayground) {
19771
19834
  return true;
package/index.mjs CHANGED
@@ -8789,6 +8789,7 @@ function InfiniteTableColumnCellFn(props) {
8789
8789
  if (inEdit) {
8790
8790
  return null;
8791
8791
  }
8792
+ renderParamRef.current = renderParam;
8792
8793
  if (renderFunctions.renderGroupIcon) {
8793
8794
  renderParam.renderBag.groupIcon = /* @__PURE__ */ React36.createElement(
8794
8795
  RenderCellHookComponent,
@@ -9002,6 +9003,7 @@ function InfiniteTableColumnCellFn(props) {
9002
9003
  bottom: bottomSelectionBorder
9003
9004
  } : null;
9004
9005
  const afterChildren = editor;
9006
+ const theChildren = renderChildren();
9005
9007
  const cellProps = {
9006
9008
  domRef,
9007
9009
  cellType: "body",
@@ -9040,7 +9042,7 @@ function InfiniteTableColumnCellFn(props) {
9040
9042
  colClassName,
9041
9043
  rowComputedClassName
9042
9044
  ),
9043
- renderChildren
9045
+ renderChildren: useCallback12(() => theChildren, [renderChildren])
9044
9046
  };
9045
9047
  const ContextProvider = InfiniteTableColumnCellContext.Provider;
9046
9048
  return (
@@ -10832,7 +10834,7 @@ function lazyGroup(groupParams, rootData) {
10832
10834
  rootData.visitDepthFirst(
10833
10835
  (lazyGroupRowInfo, keys, _index, next) => {
10834
10836
  const [_rootKey, ...currentGroupKeys] = keys;
10835
- const dataArray = lazyGroupRowInfo.children;
10837
+ let dataArray = lazyGroupRowInfo.children;
10836
10838
  const current = deepMap.get(currentGroupKeys);
10837
10839
  if (current) {
10838
10840
  current.cache = lazyGroupRowInfo.cache;
@@ -10855,10 +10857,11 @@ function lazyGroup(groupParams, rootData) {
10855
10857
  );
10856
10858
  }
10857
10859
  }
10858
- indexer.indexArray(dataArray, {
10860
+ const res = indexer.indexArray(dataArray, {
10859
10861
  toPrimaryKey,
10860
10862
  cache
10861
10863
  });
10864
+ dataArray = res;
10862
10865
  }
10863
10866
  return next == null ? void 0 : next();
10864
10867
  }
@@ -12851,11 +12854,15 @@ var Indexer = class {
12851
12854
  };
12852
12855
  this.indexArray = (arr, options) => {
12853
12856
  const { cache, toPrimaryKey } = options;
12857
+ if (cache && cache.shouldResetDataSource()) {
12858
+ this.clear();
12859
+ arr = [];
12860
+ }
12854
12861
  if (cache && !cache.isEmpty()) {
12855
12862
  arr = arr.concat();
12856
12863
  }
12857
12864
  if (!arr.length && cache) {
12858
- const cacheInfo = [...cache.getMutations().values()].flatMap((x) => x);
12865
+ const cacheInfo = cache.getMutationsArray();
12859
12866
  if (cacheInfo && cacheInfo.length) {
12860
12867
  for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
12861
12868
  const info = cacheInfo[cacheIndex];
@@ -13168,6 +13175,7 @@ function getPivotColumnsAndColumnGroups({
13168
13175
  }
13169
13176
 
13170
13177
  // src/components/DataSource/DataSourceCache.ts
13178
+ var CLEAR_SYMBOL = Symbol("CLEAR");
13171
13179
  var DataSourceCache = class {
13172
13180
  constructor() {
13173
13181
  this.affectedFields = /* @__PURE__ */ new Set();
@@ -13221,6 +13229,21 @@ var DataSourceCache = class {
13221
13229
  });
13222
13230
  this.primaryKeyToData.set(primaryKey, value);
13223
13231
  };
13232
+ this.resetDataSource = (metadata) => {
13233
+ this.clear();
13234
+ this.allFieldsAffected = true;
13235
+ const pk = CLEAR_SYMBOL;
13236
+ const value = this.primaryKeyToData.get(pk) || [];
13237
+ value.push({
13238
+ type: "clear-all",
13239
+ primaryKey: void 0,
13240
+ metadata
13241
+ });
13242
+ this.primaryKeyToData.set(pk, value);
13243
+ };
13244
+ this.shouldResetDataSource = () => {
13245
+ return this.primaryKeyToData.has(CLEAR_SYMBOL);
13246
+ };
13224
13247
  this.clear = () => {
13225
13248
  this.allFieldsAffected = false;
13226
13249
  this.affectedFields.clear();
@@ -13236,9 +13259,15 @@ var DataSourceCache = class {
13236
13259
  const data = this.primaryKeyToData.get(primaryKey);
13237
13260
  return data;
13238
13261
  };
13262
+ this.getMutationsCount = () => {
13263
+ return this.primaryKeyToData.size;
13264
+ };
13239
13265
  this.getMutations = () => {
13240
13266
  return new Map(this.primaryKeyToData);
13241
13267
  };
13268
+ this.getMutationsArray = () => {
13269
+ return Array.from(this.primaryKeyToData.values()).flat();
13270
+ };
13242
13271
  }
13243
13272
  static clone(cache, { light = false } = {}) {
13244
13273
  const clone = new DataSourceCache();
@@ -13500,6 +13529,32 @@ var DataSourceApiImpl = class {
13500
13529
  const { indexer } = this.getState();
13501
13530
  return (_a = indexer.getDataForPrimaryKey(id)) != null ? _a : null;
13502
13531
  };
13532
+ /**
13533
+ * Replaces all data in the DataSource with the provided data.
13534
+ * @param data - The new data to replace the existing data with.
13535
+ * @param options - Additional options for the operation.
13536
+ * @param options.flush - If true, the mutations will be flushed immediately.
13537
+ * @param options.metadata - Additional metadata for the operation.
13538
+ * @returns A promise that resolves when the operation is complete.
13539
+ */
13540
+ this.replaceAllData = (data, options) => {
13541
+ this.batchOperation({
13542
+ type: "replace-all",
13543
+ array: data,
13544
+ metadata: options == null ? void 0 : options.metadata
13545
+ });
13546
+ return this.addDataArray(data, options);
13547
+ };
13548
+ /**
13549
+ * Clears all data in the DataSource.
13550
+ * @param options - Additional options for the operation.
13551
+ * @param options.flush - If true, the mutations will be flushed immediately.
13552
+ * @param options.metadata - Additional metadata for the operation.
13553
+ * @returns A promise that resolves when the operation is complete.
13554
+ */
13555
+ this.clearAllData = (options) => {
13556
+ return this.replaceAllData([], options);
13557
+ };
13503
13558
  this.updateData = (data, options) => {
13504
13559
  return this.updateDataArray([data], options);
13505
13560
  };
@@ -13695,12 +13750,12 @@ var DataSourceApiImpl = class {
13695
13750
  }, delay);
13696
13751
  }
13697
13752
  }
13753
+ if (operation.type === "replace-all") {
13754
+ this.pendingOperations.length = 0;
13755
+ }
13698
13756
  this.pendingOperations.push(operation);
13699
13757
  return this.pendingPromise;
13700
13758
  }
13701
- batchOperations(operations) {
13702
- this.pendingOperations.push(...operations);
13703
- }
13704
13759
  commitOperations(operations) {
13705
13760
  if (!operations.length) {
13706
13761
  return;
@@ -13740,14 +13795,21 @@ var DataSourceApiImpl = class {
13740
13795
  position2 = "after";
13741
13796
  });
13742
13797
  break;
13798
+ case "replace-all":
13799
+ cache.resetDataSource(operation.metadata);
13800
+ break;
13743
13801
  }
13744
13802
  });
13745
13803
  this.actions.cache = cache;
13746
13804
  }
13805
+ flush() {
13806
+ return this.commit();
13807
+ }
13747
13808
  commit() {
13748
13809
  this.commitOperations(this.pendingOperations);
13749
13810
  this.pendingOperations.length = 0;
13750
- if (this.pendingPromise && this.resolvePendingPromise) {
13811
+ const pendingPromise = this.pendingPromise;
13812
+ if (pendingPromise && this.resolvePendingPromise) {
13751
13813
  const resolve = this.resolvePendingPromise;
13752
13814
  requestAnimationFrame(() => {
13753
13815
  resolve(true);
@@ -13755,6 +13817,7 @@ var DataSourceApiImpl = class {
13755
13817
  this.pendingPromise = null;
13756
13818
  this.resolvePendingPromise = null;
13757
13819
  }
13820
+ return pendingPromise || Promise.resolve(true);
13758
13821
  }
13759
13822
  };
13760
13823
  function getCacheAffectedParts(state) {
@@ -19736,7 +19799,7 @@ var useLicense = (licenseKey = "") => {
19736
19799
  }
19737
19800
  let valid2 = isValidLicense(licenseKey, {
19738
19801
  publishedAt: 1624970570587,
19739
- version: "5.0.0-canary.1"
19802
+ version: "5.0.0-canary.2"
19740
19803
  });
19741
19804
  if (!licenseKey && !valid2 && isInsidePlayground) {
19742
19805
  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": "5.0.0-canary.1",
28
+ "version": "5.0.0-canary.2",
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": 1726844089529
37
+ "publishedAt": 1726930737344
38
38
  }