@infinite-table/infinite-react 2.0.1 → 2.0.3
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 +12 -4
- package/index.dev.js +36 -11
- package/index.dev.mjs +36 -11
- package/index.js +3 -3
- package/index.mjs +3 -3
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1375,14 +1375,17 @@ declare type RenderRange = {
|
|
|
1375
1375
|
declare type DataSourceMutation<T> = {
|
|
1376
1376
|
type: 'delete';
|
|
1377
1377
|
primaryKey: any;
|
|
1378
|
+
originalData: T;
|
|
1378
1379
|
} | {
|
|
1379
1380
|
type: 'update';
|
|
1380
1381
|
primaryKey: any;
|
|
1381
1382
|
data: Partial<T>;
|
|
1383
|
+
originalData: T;
|
|
1382
1384
|
} | {
|
|
1383
1385
|
type: 'insert';
|
|
1384
1386
|
primaryKey: any;
|
|
1385
1387
|
position: 'before' | 'after';
|
|
1388
|
+
originalData: null;
|
|
1386
1389
|
data: T;
|
|
1387
1390
|
};
|
|
1388
1391
|
declare class DataSourceCache<DataType, PrimaryKeyType = string> {
|
|
@@ -1393,9 +1396,9 @@ declare class DataSourceCache<DataType, PrimaryKeyType = string> {
|
|
|
1393
1396
|
light?: boolean;
|
|
1394
1397
|
}): DataSourceCache<DataType, PrimaryKeyType>;
|
|
1395
1398
|
getAffectedFields: () => true | Set<keyof DataType>;
|
|
1396
|
-
delete: (primaryKey: PrimaryKeyType) => void;
|
|
1399
|
+
delete: (primaryKey: PrimaryKeyType, originalData: DataType) => void;
|
|
1397
1400
|
insert: (primaryKey: PrimaryKeyType, data: DataType, position: 'before' | 'after') => void;
|
|
1398
|
-
update: (primaryKey: PrimaryKeyType, data: Partial<DataType
|
|
1401
|
+
update: (primaryKey: PrimaryKeyType, data: Partial<DataType>, originalData: DataType) => void;
|
|
1399
1402
|
clear: () => void;
|
|
1400
1403
|
isEmpty: () => boolean;
|
|
1401
1404
|
removeInfo: (primaryKey: PrimaryKeyType) => void;
|
|
@@ -1537,7 +1540,7 @@ declare type DataSourceRawReducer<T, RESULT_TYPE> = {
|
|
|
1537
1540
|
declare type DataSourceAggregationReducer<T, AggregationResultType> = {
|
|
1538
1541
|
name?: string;
|
|
1539
1542
|
field?: keyof T;
|
|
1540
|
-
initialValue?: AggregationResultType;
|
|
1543
|
+
initialValue?: AggregationResultType | (() => any);
|
|
1541
1544
|
getter?: (data: T) => any;
|
|
1542
1545
|
reducer: string | ((accumulator: any, value: any, data: T, index: number, groupKeys: any[] | undefined) => AggregationResultType | any);
|
|
1543
1546
|
done?: (accumulatedValue: AggregationResultType | any, array: T[]) => AggregationResultType;
|
|
@@ -1667,6 +1670,9 @@ declare type DataSourceRowInfoReducer<T> = DataSourceRawReducer<InfiniteTableRow
|
|
|
1667
1670
|
declare type DataSourceProps<T> = {
|
|
1668
1671
|
children: React$1.ReactNode | ((contextData: DataSourceState<T>) => React$1.ReactNode);
|
|
1669
1672
|
primaryKey: keyof T | ((data: T) => string);
|
|
1673
|
+
/**
|
|
1674
|
+
* @deprecated for now
|
|
1675
|
+
*/
|
|
1670
1676
|
fields?: (keyof T)[];
|
|
1671
1677
|
refetchKey?: number | string | object;
|
|
1672
1678
|
rowInfoReducers?: DataSourcePropRowInfoReducers<T>;
|
|
@@ -1704,7 +1710,8 @@ declare type DataSourceProps<T> = {
|
|
|
1704
1710
|
onSortInfoChange?: ((sortInfo: DataSourceSingleSortInfo<T> | null) => void) | ((sortInfo: DataSourceSingleSortInfo<T>[]) => void);
|
|
1705
1711
|
onDataParamsChange?: (dataParamsChange: DataSourceDataParams<T>) => void;
|
|
1706
1712
|
onDataArrayChange?: (dataArray: DataSourceState<T>['originalDataArray'], info: DataSourceState<T>['originalDataArrayChangedInfo']) => void;
|
|
1707
|
-
onDataMutations?: ({ dataArray, timestamp, mutations, }: {
|
|
1713
|
+
onDataMutations?: ({ dataArray, timestamp, mutations, primaryKeyField, }: {
|
|
1714
|
+
primaryKeyField: undefined | keyof T;
|
|
1708
1715
|
dataArray: DataSourceState<T>['originalDataArray'];
|
|
1709
1716
|
timestamp: number;
|
|
1710
1717
|
mutations: NonUndefined<DataSourceState<T>['originalDataArrayChangedInfo']['mutations']>;
|
|
@@ -1890,6 +1897,7 @@ declare type InfiniteTable_HasGrouping_RowInfoNormal<T> = {
|
|
|
1890
1897
|
declare type InfiniteTable_HasGrouping_RowInfoGroup<T> = {
|
|
1891
1898
|
dataSourceHasGrouping: true;
|
|
1892
1899
|
data: Partial<T> | null;
|
|
1900
|
+
reducerData?: Partial<Record<keyof T, any>>;
|
|
1893
1901
|
isGroupRow: true;
|
|
1894
1902
|
/**
|
|
1895
1903
|
* This array contains all the (uncollapsed, so visible) row infos under this group, at any level of nesting,
|
package/index.dev.js
CHANGED
|
@@ -8034,6 +8034,9 @@ function getRawValueForCell(column, rowInfo) {
|
|
|
8034
8034
|
let value = isGroupRow && groupBy && column.groupByForColumn && // if this is a multi-group column we're good
|
|
8035
8035
|
(Array.isArray(column.groupByForColumn) || // or it has to be a group column for the current group row
|
|
8036
8036
|
column.groupByForColumn === groupBy[groupBy.length - 1]) ? rowInfo.value : isColumnWithField(column) ? data == null ? void 0 : data[column.field] : null;
|
|
8037
|
+
if (column.field && rowInfo.isGroupRow && rowInfo.reducerData && rowInfo.reducerData[column.field] != null) {
|
|
8038
|
+
value = rowInfo.reducerData[column.field];
|
|
8039
|
+
}
|
|
8037
8040
|
if (column.valueGetter) {
|
|
8038
8041
|
if (!rowInfo.isGroupRow && rowInfo.data) {
|
|
8039
8042
|
value = column.valueGetter({ data: rowInfo.data, field: column.field });
|
|
@@ -10574,12 +10577,17 @@ function getEnhancedGroupData(options, deepMapValue) {
|
|
|
10574
10577
|
commonData
|
|
10575
10578
|
} = deepMapValue;
|
|
10576
10579
|
let data = commonData != null ? commonData : null;
|
|
10580
|
+
let reducerData;
|
|
10577
10581
|
if (Object.keys(reducerResults).length > 0) {
|
|
10578
10582
|
data = __spreadValues({}, commonData);
|
|
10583
|
+
reducerData = {};
|
|
10579
10584
|
for (const key in reducers)
|
|
10580
10585
|
if (reducers.hasOwnProperty(key)) {
|
|
10581
10586
|
const reducer = reducers[key];
|
|
10582
10587
|
const field = reducer.field;
|
|
10588
|
+
if (field) {
|
|
10589
|
+
reducerData[field] = reducerResults[key];
|
|
10590
|
+
}
|
|
10583
10591
|
if (field && data[field] == null) {
|
|
10584
10592
|
data[field] = reducerResults[key];
|
|
10585
10593
|
}
|
|
@@ -10604,6 +10612,7 @@ function getEnhancedGroupData(options, deepMapValue) {
|
|
|
10604
10612
|
}
|
|
10605
10613
|
const enhancedGroupData = {
|
|
10606
10614
|
data,
|
|
10615
|
+
reducerData,
|
|
10607
10616
|
groupCount: groupItems.length,
|
|
10608
10617
|
groupData: groupItems,
|
|
10609
10618
|
groupKeys,
|
|
@@ -10919,13 +10928,14 @@ var DataSourceCache = class {
|
|
|
10919
10928
|
}
|
|
10920
10929
|
return this.affectedFields;
|
|
10921
10930
|
};
|
|
10922
|
-
this.delete = (primaryKey) => {
|
|
10931
|
+
this.delete = (primaryKey, originalData) => {
|
|
10923
10932
|
this.allFieldsAffected = true;
|
|
10924
10933
|
const pk = `${primaryKey}`;
|
|
10925
10934
|
const value = this.primaryKeyToData.get(pk) || [];
|
|
10926
10935
|
value.push({
|
|
10927
10936
|
type: "delete",
|
|
10928
|
-
primaryKey
|
|
10937
|
+
primaryKey,
|
|
10938
|
+
originalData
|
|
10929
10939
|
});
|
|
10930
10940
|
this.primaryKeyToData.set(pk, value);
|
|
10931
10941
|
};
|
|
@@ -10937,11 +10947,12 @@ var DataSourceCache = class {
|
|
|
10937
10947
|
type: "insert",
|
|
10938
10948
|
primaryKey,
|
|
10939
10949
|
data,
|
|
10940
|
-
position: position2
|
|
10950
|
+
position: position2,
|
|
10951
|
+
originalData: null
|
|
10941
10952
|
});
|
|
10942
10953
|
this.primaryKeyToData.set(pk, value);
|
|
10943
10954
|
};
|
|
10944
|
-
this.update = (primaryKey, data) => {
|
|
10955
|
+
this.update = (primaryKey, data, originalData) => {
|
|
10945
10956
|
if (!this.allFieldsAffected) {
|
|
10946
10957
|
const keys = Object.keys(data);
|
|
10947
10958
|
keys.forEach((key) => this.affectedFields.add(key));
|
|
@@ -10951,7 +10962,8 @@ var DataSourceCache = class {
|
|
|
10951
10962
|
value.push({
|
|
10952
10963
|
type: "update",
|
|
10953
10964
|
primaryKey,
|
|
10954
|
-
data
|
|
10965
|
+
data,
|
|
10966
|
+
originalData
|
|
10955
10967
|
});
|
|
10956
10968
|
this.primaryKeyToData.set(`${primaryKey}`, value);
|
|
10957
10969
|
};
|
|
@@ -11022,13 +11034,20 @@ var DataSourceApiImpl = class {
|
|
|
11022
11034
|
operations.forEach((operation) => {
|
|
11023
11035
|
switch (operation.type) {
|
|
11024
11036
|
case "update":
|
|
11025
|
-
operation.array.forEach((
|
|
11026
|
-
|
|
11037
|
+
operation.array.forEach((data, index) => {
|
|
11038
|
+
const key = operation.primaryKeys[index];
|
|
11039
|
+
const rowInfo = this.getRowInfoByPrimaryKey(key);
|
|
11040
|
+
if (rowInfo && !rowInfo.isGroupRow) {
|
|
11041
|
+
cache.update(operation.primaryKeys[index], data, rowInfo.data);
|
|
11042
|
+
}
|
|
11027
11043
|
});
|
|
11028
11044
|
break;
|
|
11029
11045
|
case "delete":
|
|
11030
11046
|
operation.primaryKeys.forEach((key) => {
|
|
11031
|
-
|
|
11047
|
+
const rowInfo = this.getRowInfoByPrimaryKey(key);
|
|
11048
|
+
if (rowInfo && !rowInfo.isGroupRow) {
|
|
11049
|
+
cache.delete(key, rowInfo.data);
|
|
11050
|
+
}
|
|
11032
11051
|
});
|
|
11033
11052
|
break;
|
|
11034
11053
|
case "insert":
|
|
@@ -13967,6 +13986,7 @@ function DataSourceCmp({ children }) {
|
|
|
13967
13986
|
);
|
|
13968
13987
|
if (componentState.onDataMutations && componentState.originalDataArrayChangedInfo.mutations) {
|
|
13969
13988
|
componentState.onDataMutations({
|
|
13989
|
+
primaryKeyField: typeof componentState.primaryKey === "string" ? componentState.primaryKey : void 0,
|
|
13970
13990
|
dataArray: componentState.originalDataArray,
|
|
13971
13991
|
mutations: componentState.originalDataArrayChangedInfo.mutations,
|
|
13972
13992
|
timestamp: componentState.originalDataArrayChangedInfo.timestamp
|
|
@@ -14088,9 +14108,14 @@ var InfiniteTableApiImpl = class {
|
|
|
14088
14108
|
if (!params.column.field) {
|
|
14089
14109
|
return value;
|
|
14090
14110
|
}
|
|
14091
|
-
|
|
14111
|
+
const primaryKey = this.getDataSourceState().primaryKey;
|
|
14112
|
+
const newData = params.data && typeof primaryKey === "string" ? {
|
|
14113
|
+
[primaryKey]: params.data[primaryKey],
|
|
14092
14114
|
[params.column.field]: valueToPersist
|
|
14093
|
-
})
|
|
14115
|
+
} : __spreadProps(__spreadValues({}, params.data), {
|
|
14116
|
+
[params.column.field]: valueToPersist
|
|
14117
|
+
});
|
|
14118
|
+
return this.context.dataSourceApi.updateData(newData);
|
|
14094
14119
|
};
|
|
14095
14120
|
let response;
|
|
14096
14121
|
try {
|
|
@@ -16756,7 +16781,7 @@ var useLicense = (licenseKey = "") => {
|
|
|
16756
16781
|
const valid = (0, import_react49.useMemo)(() => {
|
|
16757
16782
|
let valid2 = isValidLicense(licenseKey, {
|
|
16758
16783
|
publishedAt: 1624970570587,
|
|
16759
|
-
version: "2.0.
|
|
16784
|
+
version: "2.0.3"
|
|
16760
16785
|
});
|
|
16761
16786
|
if (!licenseKey && !valid2 && isInsidePlayground) {
|
|
16762
16787
|
return true;
|
package/index.dev.mjs
CHANGED
|
@@ -8020,6 +8020,9 @@ function getRawValueForCell(column, rowInfo) {
|
|
|
8020
8020
|
let value = isGroupRow && groupBy && column.groupByForColumn && // if this is a multi-group column we're good
|
|
8021
8021
|
(Array.isArray(column.groupByForColumn) || // or it has to be a group column for the current group row
|
|
8022
8022
|
column.groupByForColumn === groupBy[groupBy.length - 1]) ? rowInfo.value : isColumnWithField(column) ? data == null ? void 0 : data[column.field] : null;
|
|
8023
|
+
if (column.field && rowInfo.isGroupRow && rowInfo.reducerData && rowInfo.reducerData[column.field] != null) {
|
|
8024
|
+
value = rowInfo.reducerData[column.field];
|
|
8025
|
+
}
|
|
8023
8026
|
if (column.valueGetter) {
|
|
8024
8027
|
if (!rowInfo.isGroupRow && rowInfo.data) {
|
|
8025
8028
|
value = column.valueGetter({ data: rowInfo.data, field: column.field });
|
|
@@ -10560,12 +10563,17 @@ function getEnhancedGroupData(options, deepMapValue) {
|
|
|
10560
10563
|
commonData
|
|
10561
10564
|
} = deepMapValue;
|
|
10562
10565
|
let data = commonData != null ? commonData : null;
|
|
10566
|
+
let reducerData;
|
|
10563
10567
|
if (Object.keys(reducerResults).length > 0) {
|
|
10564
10568
|
data = __spreadValues({}, commonData);
|
|
10569
|
+
reducerData = {};
|
|
10565
10570
|
for (const key in reducers)
|
|
10566
10571
|
if (reducers.hasOwnProperty(key)) {
|
|
10567
10572
|
const reducer = reducers[key];
|
|
10568
10573
|
const field = reducer.field;
|
|
10574
|
+
if (field) {
|
|
10575
|
+
reducerData[field] = reducerResults[key];
|
|
10576
|
+
}
|
|
10569
10577
|
if (field && data[field] == null) {
|
|
10570
10578
|
data[field] = reducerResults[key];
|
|
10571
10579
|
}
|
|
@@ -10590,6 +10598,7 @@ function getEnhancedGroupData(options, deepMapValue) {
|
|
|
10590
10598
|
}
|
|
10591
10599
|
const enhancedGroupData = {
|
|
10592
10600
|
data,
|
|
10601
|
+
reducerData,
|
|
10593
10602
|
groupCount: groupItems.length,
|
|
10594
10603
|
groupData: groupItems,
|
|
10595
10604
|
groupKeys,
|
|
@@ -10905,13 +10914,14 @@ var DataSourceCache = class {
|
|
|
10905
10914
|
}
|
|
10906
10915
|
return this.affectedFields;
|
|
10907
10916
|
};
|
|
10908
|
-
this.delete = (primaryKey) => {
|
|
10917
|
+
this.delete = (primaryKey, originalData) => {
|
|
10909
10918
|
this.allFieldsAffected = true;
|
|
10910
10919
|
const pk = `${primaryKey}`;
|
|
10911
10920
|
const value = this.primaryKeyToData.get(pk) || [];
|
|
10912
10921
|
value.push({
|
|
10913
10922
|
type: "delete",
|
|
10914
|
-
primaryKey
|
|
10923
|
+
primaryKey,
|
|
10924
|
+
originalData
|
|
10915
10925
|
});
|
|
10916
10926
|
this.primaryKeyToData.set(pk, value);
|
|
10917
10927
|
};
|
|
@@ -10923,11 +10933,12 @@ var DataSourceCache = class {
|
|
|
10923
10933
|
type: "insert",
|
|
10924
10934
|
primaryKey,
|
|
10925
10935
|
data,
|
|
10926
|
-
position: position2
|
|
10936
|
+
position: position2,
|
|
10937
|
+
originalData: null
|
|
10927
10938
|
});
|
|
10928
10939
|
this.primaryKeyToData.set(pk, value);
|
|
10929
10940
|
};
|
|
10930
|
-
this.update = (primaryKey, data) => {
|
|
10941
|
+
this.update = (primaryKey, data, originalData) => {
|
|
10931
10942
|
if (!this.allFieldsAffected) {
|
|
10932
10943
|
const keys = Object.keys(data);
|
|
10933
10944
|
keys.forEach((key) => this.affectedFields.add(key));
|
|
@@ -10937,7 +10948,8 @@ var DataSourceCache = class {
|
|
|
10937
10948
|
value.push({
|
|
10938
10949
|
type: "update",
|
|
10939
10950
|
primaryKey,
|
|
10940
|
-
data
|
|
10951
|
+
data,
|
|
10952
|
+
originalData
|
|
10941
10953
|
});
|
|
10942
10954
|
this.primaryKeyToData.set(`${primaryKey}`, value);
|
|
10943
10955
|
};
|
|
@@ -11008,13 +11020,20 @@ var DataSourceApiImpl = class {
|
|
|
11008
11020
|
operations.forEach((operation) => {
|
|
11009
11021
|
switch (operation.type) {
|
|
11010
11022
|
case "update":
|
|
11011
|
-
operation.array.forEach((
|
|
11012
|
-
|
|
11023
|
+
operation.array.forEach((data, index) => {
|
|
11024
|
+
const key = operation.primaryKeys[index];
|
|
11025
|
+
const rowInfo = this.getRowInfoByPrimaryKey(key);
|
|
11026
|
+
if (rowInfo && !rowInfo.isGroupRow) {
|
|
11027
|
+
cache.update(operation.primaryKeys[index], data, rowInfo.data);
|
|
11028
|
+
}
|
|
11013
11029
|
});
|
|
11014
11030
|
break;
|
|
11015
11031
|
case "delete":
|
|
11016
11032
|
operation.primaryKeys.forEach((key) => {
|
|
11017
|
-
|
|
11033
|
+
const rowInfo = this.getRowInfoByPrimaryKey(key);
|
|
11034
|
+
if (rowInfo && !rowInfo.isGroupRow) {
|
|
11035
|
+
cache.delete(key, rowInfo.data);
|
|
11036
|
+
}
|
|
11018
11037
|
});
|
|
11019
11038
|
break;
|
|
11020
11039
|
case "insert":
|
|
@@ -13953,6 +13972,7 @@ function DataSourceCmp({ children }) {
|
|
|
13953
13972
|
);
|
|
13954
13973
|
if (componentState.onDataMutations && componentState.originalDataArrayChangedInfo.mutations) {
|
|
13955
13974
|
componentState.onDataMutations({
|
|
13975
|
+
primaryKeyField: typeof componentState.primaryKey === "string" ? componentState.primaryKey : void 0,
|
|
13956
13976
|
dataArray: componentState.originalDataArray,
|
|
13957
13977
|
mutations: componentState.originalDataArrayChangedInfo.mutations,
|
|
13958
13978
|
timestamp: componentState.originalDataArrayChangedInfo.timestamp
|
|
@@ -14074,9 +14094,14 @@ var InfiniteTableApiImpl = class {
|
|
|
14074
14094
|
if (!params.column.field) {
|
|
14075
14095
|
return value;
|
|
14076
14096
|
}
|
|
14077
|
-
|
|
14097
|
+
const primaryKey = this.getDataSourceState().primaryKey;
|
|
14098
|
+
const newData = params.data && typeof primaryKey === "string" ? {
|
|
14099
|
+
[primaryKey]: params.data[primaryKey],
|
|
14078
14100
|
[params.column.field]: valueToPersist
|
|
14079
|
-
})
|
|
14101
|
+
} : __spreadProps(__spreadValues({}, params.data), {
|
|
14102
|
+
[params.column.field]: valueToPersist
|
|
14103
|
+
});
|
|
14104
|
+
return this.context.dataSourceApi.updateData(newData);
|
|
14080
14105
|
};
|
|
14081
14106
|
let response;
|
|
14082
14107
|
try {
|
|
@@ -16746,7 +16771,7 @@ var useLicense = (licenseKey = "") => {
|
|
|
16746
16771
|
const valid = useMemo11(() => {
|
|
16747
16772
|
let valid2 = isValidLicense(licenseKey, {
|
|
16748
16773
|
publishedAt: 1624970570587,
|
|
16749
|
-
version: "2.0.
|
|
16774
|
+
version: "2.0.3"
|
|
16750
16775
|
});
|
|
16751
16776
|
if (!licenseKey && !valid2 && isInsidePlayground) {
|
|
16752
16777
|
return true;
|