@infinite-table/infinite-react 2.0.2 → 2.0.4

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
@@ -1375,15 +1375,21 @@ declare type RenderRange = {
1375
1375
  declare type DataSourceMutation<T> = {
1376
1376
  type: 'delete';
1377
1377
  primaryKey: any;
1378
+ originalData: T;
1379
+ metadata: any;
1378
1380
  } | {
1379
1381
  type: 'update';
1380
1382
  primaryKey: any;
1381
1383
  data: Partial<T>;
1384
+ originalData: T;
1385
+ metadata: any;
1382
1386
  } | {
1383
1387
  type: 'insert';
1384
1388
  primaryKey: any;
1385
1389
  position: 'before' | 'after';
1390
+ originalData: null;
1386
1391
  data: T;
1392
+ metadata: any;
1387
1393
  };
1388
1394
  declare class DataSourceCache<DataType, PrimaryKeyType = string> {
1389
1395
  private affectedFields;
@@ -1393,9 +1399,9 @@ declare class DataSourceCache<DataType, PrimaryKeyType = string> {
1393
1399
  light?: boolean;
1394
1400
  }): DataSourceCache<DataType, PrimaryKeyType>;
1395
1401
  getAffectedFields: () => true | Set<keyof DataType>;
1396
- delete: (primaryKey: PrimaryKeyType) => void;
1397
- insert: (primaryKey: PrimaryKeyType, data: DataType, position: 'before' | 'after') => void;
1398
- update: (primaryKey: PrimaryKeyType, data: Partial<DataType>) => void;
1402
+ delete: (primaryKey: PrimaryKeyType, originalData: DataType, metadata: any) => void;
1403
+ insert: (primaryKey: PrimaryKeyType, data: DataType, position: 'before' | 'after', metadata: any) => void;
1404
+ update: (primaryKey: PrimaryKeyType, data: Partial<DataType>, originalData: DataType, metadata: any) => void;
1399
1405
  clear: () => void;
1400
1406
  isEmpty: () => boolean;
1401
1407
  removeInfo: (primaryKey: PrimaryKeyType) => void;
@@ -1636,6 +1642,7 @@ declare type DataSourcePropIsRowSelected<T> = (rowInfo: InfiniteTableRowInfo<T>,
1636
1642
  declare type DataSourcePropSortFn<T> = (sortInfo: MultisortInfoAllowMultipleFields<T>[], array: T[], get?: (item: any) => T) => T[];
1637
1643
  declare type DataSourceCRUDParam = {
1638
1644
  flush?: boolean;
1645
+ metadata?: any;
1639
1646
  };
1640
1647
  declare type DataSourceInsertParam = DataSourceCRUDParam & ({
1641
1648
  position: 'before' | 'after';
@@ -1667,6 +1674,9 @@ declare type DataSourceRowInfoReducer<T> = DataSourceRawReducer<InfiniteTableRow
1667
1674
  declare type DataSourceProps<T> = {
1668
1675
  children: React$1.ReactNode | ((contextData: DataSourceState<T>) => React$1.ReactNode);
1669
1676
  primaryKey: keyof T | ((data: T) => string);
1677
+ /**
1678
+ * @deprecated for now
1679
+ */
1670
1680
  fields?: (keyof T)[];
1671
1681
  refetchKey?: number | string | object;
1672
1682
  rowInfoReducers?: DataSourcePropRowInfoReducers<T>;
@@ -1704,7 +1714,8 @@ declare type DataSourceProps<T> = {
1704
1714
  onSortInfoChange?: ((sortInfo: DataSourceSingleSortInfo<T> | null) => void) | ((sortInfo: DataSourceSingleSortInfo<T>[]) => void);
1705
1715
  onDataParamsChange?: (dataParamsChange: DataSourceDataParams<T>) => void;
1706
1716
  onDataArrayChange?: (dataArray: DataSourceState<T>['originalDataArray'], info: DataSourceState<T>['originalDataArrayChangedInfo']) => void;
1707
- onDataMutations?: ({ dataArray, timestamp, mutations, }: {
1717
+ onDataMutations?: ({ dataArray, timestamp, mutations, primaryKeyField, }: {
1718
+ primaryKeyField: undefined | keyof T;
1708
1719
  dataArray: DataSourceState<T>['originalDataArray'];
1709
1720
  timestamp: number;
1710
1721
  mutations: NonUndefined<DataSourceState<T>['originalDataArrayChangedInfo']['mutations']>;
package/index.dev.js CHANGED
@@ -10928,17 +10928,19 @@ var DataSourceCache = class {
10928
10928
  }
10929
10929
  return this.affectedFields;
10930
10930
  };
10931
- this.delete = (primaryKey) => {
10931
+ this.delete = (primaryKey, originalData, metadata) => {
10932
10932
  this.allFieldsAffected = true;
10933
10933
  const pk = `${primaryKey}`;
10934
10934
  const value = this.primaryKeyToData.get(pk) || [];
10935
10935
  value.push({
10936
10936
  type: "delete",
10937
- primaryKey
10937
+ primaryKey,
10938
+ originalData,
10939
+ metadata
10938
10940
  });
10939
10941
  this.primaryKeyToData.set(pk, value);
10940
10942
  };
10941
- this.insert = (primaryKey, data, position2) => {
10943
+ this.insert = (primaryKey, data, position2, metadata) => {
10942
10944
  const pk = `${primaryKey}`;
10943
10945
  const value = this.primaryKeyToData.get(pk) || [];
10944
10946
  this.allFieldsAffected = true;
@@ -10946,11 +10948,13 @@ var DataSourceCache = class {
10946
10948
  type: "insert",
10947
10949
  primaryKey,
10948
10950
  data,
10949
- position: position2
10951
+ position: position2,
10952
+ originalData: null,
10953
+ metadata
10950
10954
  });
10951
10955
  this.primaryKeyToData.set(pk, value);
10952
10956
  };
10953
- this.update = (primaryKey, data) => {
10957
+ this.update = (primaryKey, data, originalData, metadata) => {
10954
10958
  if (!this.allFieldsAffected) {
10955
10959
  const keys = Object.keys(data);
10956
10960
  keys.forEach((key) => this.affectedFields.add(key));
@@ -10960,7 +10964,9 @@ var DataSourceCache = class {
10960
10964
  value.push({
10961
10965
  type: "update",
10962
10966
  primaryKey,
10963
- data
10967
+ data,
10968
+ originalData,
10969
+ metadata
10964
10970
  });
10965
10971
  this.primaryKeyToData.set(`${primaryKey}`, value);
10966
10972
  };
@@ -11031,20 +11037,32 @@ var DataSourceApiImpl = class {
11031
11037
  operations.forEach((operation) => {
11032
11038
  switch (operation.type) {
11033
11039
  case "update":
11034
- operation.array.forEach((d, index) => {
11035
- cache.update(operation.primaryKeys[index], d);
11040
+ operation.array.forEach((data, index) => {
11041
+ const key = operation.primaryKeys[index];
11042
+ const rowInfo = this.getRowInfoByPrimaryKey(key);
11043
+ if (rowInfo && !rowInfo.isGroupRow) {
11044
+ cache.update(
11045
+ operation.primaryKeys[index],
11046
+ data,
11047
+ rowInfo.data,
11048
+ operation.metadata
11049
+ );
11050
+ }
11036
11051
  });
11037
11052
  break;
11038
11053
  case "delete":
11039
11054
  operation.primaryKeys.forEach((key) => {
11040
- cache.delete(key);
11055
+ const rowInfo = this.getRowInfoByPrimaryKey(key);
11056
+ if (rowInfo && !rowInfo.isGroupRow) {
11057
+ cache.delete(key, rowInfo.data, operation.metadata);
11058
+ }
11041
11059
  });
11042
11060
  break;
11043
11061
  case "insert":
11044
11062
  let pk = operation.primaryKey;
11045
11063
  let position2 = operation.position;
11046
11064
  operation.array.forEach((data) => {
11047
- cache.insert(pk, data, position2);
11065
+ cache.insert(pk, data, position2, operation.metadata);
11048
11066
  pk = this.toPrimaryKey(data);
11049
11067
  position2 = "after";
11050
11068
  });
@@ -11102,7 +11120,8 @@ var DataSourceApiImpl = class {
11102
11120
  array: data,
11103
11121
  primaryKeys: data.map((d) => {
11104
11122
  return this.toPrimaryKey(d);
11105
- })
11123
+ }),
11124
+ metadata: options == null ? void 0 : options.metadata
11106
11125
  });
11107
11126
  if (options == null ? void 0 : options.flush) {
11108
11127
  this.commit();
@@ -11112,7 +11131,8 @@ var DataSourceApiImpl = class {
11112
11131
  removeDataByPrimaryKey(id, options) {
11113
11132
  const result = this.batchOperation({
11114
11133
  type: "delete",
11115
- primaryKeys: [id]
11134
+ primaryKeys: [id],
11135
+ metadata: options == null ? void 0 : options.metadata
11116
11136
  });
11117
11137
  if (options == null ? void 0 : options.flush) {
11118
11138
  this.commit();
@@ -11122,7 +11142,8 @@ var DataSourceApiImpl = class {
11122
11142
  removeData(data, options) {
11123
11143
  const result = this.batchOperation({
11124
11144
  type: "delete",
11125
- primaryKeys: [this.toPrimaryKey(data)]
11145
+ primaryKeys: [this.toPrimaryKey(data)],
11146
+ metadata: options == null ? void 0 : options.metadata
11126
11147
  });
11127
11148
  if (options == null ? void 0 : options.flush) {
11128
11149
  this.commit();
@@ -11132,7 +11153,8 @@ var DataSourceApiImpl = class {
11132
11153
  removeDataArrayByPrimaryKeys(ids, options) {
11133
11154
  const result = this.batchOperation({
11134
11155
  type: "delete",
11135
- primaryKeys: ids
11156
+ primaryKeys: ids,
11157
+ metadata: options == null ? void 0 : options.metadata
11136
11158
  });
11137
11159
  if (options == null ? void 0 : options.flush) {
11138
11160
  this.commit();
@@ -11142,7 +11164,8 @@ var DataSourceApiImpl = class {
11142
11164
  removeDataArray(data, options) {
11143
11165
  const result = this.batchOperation({
11144
11166
  type: "delete",
11145
- primaryKeys: data.map(this.toPrimaryKey)
11167
+ primaryKeys: data.map(this.toPrimaryKey),
11168
+ metadata: options == null ? void 0 : options.metadata
11146
11169
  });
11147
11170
  if (options == null ? void 0 : options.flush) {
11148
11171
  this.commit();
@@ -11180,6 +11203,7 @@ var DataSourceApiImpl = class {
11180
11203
  type: "insert",
11181
11204
  array: data,
11182
11205
  position: position2,
11206
+ metadata: options == null ? void 0 : options.metadata,
11183
11207
  primaryKey
11184
11208
  });
11185
11209
  if (options == null ? void 0 : options.flush) {
@@ -11566,6 +11590,17 @@ function getPivotColumnsAndColumnGroups({
11566
11590
  ).map((key) => {
11567
11591
  return __spreadProps(__spreadValues({}, reducers[key]), { id: key });
11568
11592
  });
11593
+ if (!aggregationReducers.length) {
11594
+ showSeparatePivotColumnForSingleAggregation = true;
11595
+ pivotGrandTotalColumnPosition = false;
11596
+ pivotTotalColumnPosition = false;
11597
+ aggregationReducers.push({
11598
+ id: "__empty-aggregation-reducer__",
11599
+ name: "-",
11600
+ initialValue: null,
11601
+ reducer: () => null
11602
+ });
11603
+ }
11569
11604
  const columns = /* @__PURE__ */ new Map([
11570
11605
  // [
11571
11606
  // 'labels',
@@ -13976,6 +14011,7 @@ function DataSourceCmp({ children }) {
13976
14011
  );
13977
14012
  if (componentState.onDataMutations && componentState.originalDataArrayChangedInfo.mutations) {
13978
14013
  componentState.onDataMutations({
14014
+ primaryKeyField: typeof componentState.primaryKey === "string" ? componentState.primaryKey : void 0,
13979
14015
  dataArray: componentState.originalDataArray,
13980
14016
  mutations: componentState.originalDataArrayChangedInfo.mutations,
13981
14017
  timestamp: componentState.originalDataArrayChangedInfo.timestamp
@@ -14093,13 +14129,19 @@ var InfiniteTableApiImpl = class {
14093
14129
  valueToPersist = yield column.getValueToPersist(params);
14094
14130
  }
14095
14131
  params.value = valueToPersist;
14132
+ editingCell.value = valueToPersist;
14096
14133
  const persistEdit = (_b = this.getState().persistEdit) != null ? _b : () => {
14097
14134
  if (!params.column.field) {
14098
14135
  return value;
14099
14136
  }
14100
- return this.context.dataSourceApi.updateData(__spreadProps(__spreadValues({}, params.data), {
14137
+ const primaryKey = this.getDataSourceState().primaryKey;
14138
+ const newData = params.data && typeof primaryKey === "string" ? {
14139
+ [primaryKey]: params.data[primaryKey],
14101
14140
  [params.column.field]: valueToPersist
14102
- }));
14141
+ } : __spreadProps(__spreadValues({}, params.data), {
14142
+ [params.column.field]: valueToPersist
14143
+ });
14144
+ return this.context.dataSourceApi.updateData(newData);
14103
14145
  };
14104
14146
  let response;
14105
14147
  try {
@@ -16765,7 +16807,7 @@ var useLicense = (licenseKey = "") => {
16765
16807
  const valid = (0, import_react49.useMemo)(() => {
16766
16808
  let valid2 = isValidLicense(licenseKey, {
16767
16809
  publishedAt: 1624970570587,
16768
- version: "2.0.2"
16810
+ version: "2.0.4"
16769
16811
  });
16770
16812
  if (!licenseKey && !valid2 && isInsidePlayground) {
16771
16813
  return true;
package/index.dev.mjs CHANGED
@@ -10914,17 +10914,19 @@ var DataSourceCache = class {
10914
10914
  }
10915
10915
  return this.affectedFields;
10916
10916
  };
10917
- this.delete = (primaryKey) => {
10917
+ this.delete = (primaryKey, originalData, metadata) => {
10918
10918
  this.allFieldsAffected = true;
10919
10919
  const pk = `${primaryKey}`;
10920
10920
  const value = this.primaryKeyToData.get(pk) || [];
10921
10921
  value.push({
10922
10922
  type: "delete",
10923
- primaryKey
10923
+ primaryKey,
10924
+ originalData,
10925
+ metadata
10924
10926
  });
10925
10927
  this.primaryKeyToData.set(pk, value);
10926
10928
  };
10927
- this.insert = (primaryKey, data, position2) => {
10929
+ this.insert = (primaryKey, data, position2, metadata) => {
10928
10930
  const pk = `${primaryKey}`;
10929
10931
  const value = this.primaryKeyToData.get(pk) || [];
10930
10932
  this.allFieldsAffected = true;
@@ -10932,11 +10934,13 @@ var DataSourceCache = class {
10932
10934
  type: "insert",
10933
10935
  primaryKey,
10934
10936
  data,
10935
- position: position2
10937
+ position: position2,
10938
+ originalData: null,
10939
+ metadata
10936
10940
  });
10937
10941
  this.primaryKeyToData.set(pk, value);
10938
10942
  };
10939
- this.update = (primaryKey, data) => {
10943
+ this.update = (primaryKey, data, originalData, metadata) => {
10940
10944
  if (!this.allFieldsAffected) {
10941
10945
  const keys = Object.keys(data);
10942
10946
  keys.forEach((key) => this.affectedFields.add(key));
@@ -10946,7 +10950,9 @@ var DataSourceCache = class {
10946
10950
  value.push({
10947
10951
  type: "update",
10948
10952
  primaryKey,
10949
- data
10953
+ data,
10954
+ originalData,
10955
+ metadata
10950
10956
  });
10951
10957
  this.primaryKeyToData.set(`${primaryKey}`, value);
10952
10958
  };
@@ -11017,20 +11023,32 @@ var DataSourceApiImpl = class {
11017
11023
  operations.forEach((operation) => {
11018
11024
  switch (operation.type) {
11019
11025
  case "update":
11020
- operation.array.forEach((d, index) => {
11021
- cache.update(operation.primaryKeys[index], d);
11026
+ operation.array.forEach((data, index) => {
11027
+ const key = operation.primaryKeys[index];
11028
+ const rowInfo = this.getRowInfoByPrimaryKey(key);
11029
+ if (rowInfo && !rowInfo.isGroupRow) {
11030
+ cache.update(
11031
+ operation.primaryKeys[index],
11032
+ data,
11033
+ rowInfo.data,
11034
+ operation.metadata
11035
+ );
11036
+ }
11022
11037
  });
11023
11038
  break;
11024
11039
  case "delete":
11025
11040
  operation.primaryKeys.forEach((key) => {
11026
- cache.delete(key);
11041
+ const rowInfo = this.getRowInfoByPrimaryKey(key);
11042
+ if (rowInfo && !rowInfo.isGroupRow) {
11043
+ cache.delete(key, rowInfo.data, operation.metadata);
11044
+ }
11027
11045
  });
11028
11046
  break;
11029
11047
  case "insert":
11030
11048
  let pk = operation.primaryKey;
11031
11049
  let position2 = operation.position;
11032
11050
  operation.array.forEach((data) => {
11033
- cache.insert(pk, data, position2);
11051
+ cache.insert(pk, data, position2, operation.metadata);
11034
11052
  pk = this.toPrimaryKey(data);
11035
11053
  position2 = "after";
11036
11054
  });
@@ -11088,7 +11106,8 @@ var DataSourceApiImpl = class {
11088
11106
  array: data,
11089
11107
  primaryKeys: data.map((d) => {
11090
11108
  return this.toPrimaryKey(d);
11091
- })
11109
+ }),
11110
+ metadata: options == null ? void 0 : options.metadata
11092
11111
  });
11093
11112
  if (options == null ? void 0 : options.flush) {
11094
11113
  this.commit();
@@ -11098,7 +11117,8 @@ var DataSourceApiImpl = class {
11098
11117
  removeDataByPrimaryKey(id, options) {
11099
11118
  const result = this.batchOperation({
11100
11119
  type: "delete",
11101
- primaryKeys: [id]
11120
+ primaryKeys: [id],
11121
+ metadata: options == null ? void 0 : options.metadata
11102
11122
  });
11103
11123
  if (options == null ? void 0 : options.flush) {
11104
11124
  this.commit();
@@ -11108,7 +11128,8 @@ var DataSourceApiImpl = class {
11108
11128
  removeData(data, options) {
11109
11129
  const result = this.batchOperation({
11110
11130
  type: "delete",
11111
- primaryKeys: [this.toPrimaryKey(data)]
11131
+ primaryKeys: [this.toPrimaryKey(data)],
11132
+ metadata: options == null ? void 0 : options.metadata
11112
11133
  });
11113
11134
  if (options == null ? void 0 : options.flush) {
11114
11135
  this.commit();
@@ -11118,7 +11139,8 @@ var DataSourceApiImpl = class {
11118
11139
  removeDataArrayByPrimaryKeys(ids, options) {
11119
11140
  const result = this.batchOperation({
11120
11141
  type: "delete",
11121
- primaryKeys: ids
11142
+ primaryKeys: ids,
11143
+ metadata: options == null ? void 0 : options.metadata
11122
11144
  });
11123
11145
  if (options == null ? void 0 : options.flush) {
11124
11146
  this.commit();
@@ -11128,7 +11150,8 @@ var DataSourceApiImpl = class {
11128
11150
  removeDataArray(data, options) {
11129
11151
  const result = this.batchOperation({
11130
11152
  type: "delete",
11131
- primaryKeys: data.map(this.toPrimaryKey)
11153
+ primaryKeys: data.map(this.toPrimaryKey),
11154
+ metadata: options == null ? void 0 : options.metadata
11132
11155
  });
11133
11156
  if (options == null ? void 0 : options.flush) {
11134
11157
  this.commit();
@@ -11166,6 +11189,7 @@ var DataSourceApiImpl = class {
11166
11189
  type: "insert",
11167
11190
  array: data,
11168
11191
  position: position2,
11192
+ metadata: options == null ? void 0 : options.metadata,
11169
11193
  primaryKey
11170
11194
  });
11171
11195
  if (options == null ? void 0 : options.flush) {
@@ -11552,6 +11576,17 @@ function getPivotColumnsAndColumnGroups({
11552
11576
  ).map((key) => {
11553
11577
  return __spreadProps(__spreadValues({}, reducers[key]), { id: key });
11554
11578
  });
11579
+ if (!aggregationReducers.length) {
11580
+ showSeparatePivotColumnForSingleAggregation = true;
11581
+ pivotGrandTotalColumnPosition = false;
11582
+ pivotTotalColumnPosition = false;
11583
+ aggregationReducers.push({
11584
+ id: "__empty-aggregation-reducer__",
11585
+ name: "-",
11586
+ initialValue: null,
11587
+ reducer: () => null
11588
+ });
11589
+ }
11555
11590
  const columns = /* @__PURE__ */ new Map([
11556
11591
  // [
11557
11592
  // 'labels',
@@ -13962,6 +13997,7 @@ function DataSourceCmp({ children }) {
13962
13997
  );
13963
13998
  if (componentState.onDataMutations && componentState.originalDataArrayChangedInfo.mutations) {
13964
13999
  componentState.onDataMutations({
14000
+ primaryKeyField: typeof componentState.primaryKey === "string" ? componentState.primaryKey : void 0,
13965
14001
  dataArray: componentState.originalDataArray,
13966
14002
  mutations: componentState.originalDataArrayChangedInfo.mutations,
13967
14003
  timestamp: componentState.originalDataArrayChangedInfo.timestamp
@@ -14079,13 +14115,19 @@ var InfiniteTableApiImpl = class {
14079
14115
  valueToPersist = yield column.getValueToPersist(params);
14080
14116
  }
14081
14117
  params.value = valueToPersist;
14118
+ editingCell.value = valueToPersist;
14082
14119
  const persistEdit = (_b = this.getState().persistEdit) != null ? _b : () => {
14083
14120
  if (!params.column.field) {
14084
14121
  return value;
14085
14122
  }
14086
- return this.context.dataSourceApi.updateData(__spreadProps(__spreadValues({}, params.data), {
14123
+ const primaryKey = this.getDataSourceState().primaryKey;
14124
+ const newData = params.data && typeof primaryKey === "string" ? {
14125
+ [primaryKey]: params.data[primaryKey],
14087
14126
  [params.column.field]: valueToPersist
14088
- }));
14127
+ } : __spreadProps(__spreadValues({}, params.data), {
14128
+ [params.column.field]: valueToPersist
14129
+ });
14130
+ return this.context.dataSourceApi.updateData(newData);
14089
14131
  };
14090
14132
  let response;
14091
14133
  try {
@@ -16755,7 +16797,7 @@ var useLicense = (licenseKey = "") => {
16755
16797
  const valid = useMemo11(() => {
16756
16798
  let valid2 = isValidLicense(licenseKey, {
16757
16799
  publishedAt: 1624970570587,
16758
- version: "2.0.2"
16800
+ version: "2.0.4"
16759
16801
  });
16760
16802
  if (!licenseKey && !valid2 && isInsidePlayground) {
16761
16803
  return true;