@infinite-table/infinite-react 1.3.21 → 1.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.dev.js CHANGED
@@ -5281,7 +5281,10 @@ function getColumnApiForColumn(colOrColId, param) {
5281
5281
  toggleSort(params = {
5282
5282
  multiSortBehavior: "replace"
5283
5283
  }) {
5284
- column.toggleSort(params);
5284
+ return api.toggleSortingForColumn(column.id, params);
5285
+ },
5286
+ getSortDir() {
5287
+ return api.getSortingForColumn(column.id);
5285
5288
  },
5286
5289
  setFilter(value) {
5287
5290
  return api.setColumnFilter(column.id, value);
@@ -5289,6 +5292,9 @@ function getColumnApiForColumn(colOrColId, param) {
5289
5292
  clearFilter() {
5290
5293
  return api.clearColumnFilter(column.id);
5291
5294
  },
5295
+ getSortInfo() {
5296
+ return api.getSortInfoForColumn(column.id);
5297
+ },
5292
5298
  setSort(sort) {
5293
5299
  if (!sort) {
5294
5300
  api.setSortInfoForColumn(column.id, null);
@@ -6525,7 +6531,7 @@ var useColumnPointerEvents = ({
6525
6531
  target2.removeEventListener("pointerup", onPointerUp);
6526
6532
  setProxyPosition(null);
6527
6533
  if (!didDragAtLeastOnce && dragColumn.computedSortable) {
6528
- dragColumn.toggleSort({
6534
+ api.toggleSortingForColumn(dragColumn.id, {
6529
6535
  multiSortBehavior: multiSortBehavior === "replace" && (e2.ctrlKey || e2.metaKey) ? "append" : multiSortBehavior
6530
6536
  });
6531
6537
  }
@@ -10628,6 +10634,15 @@ var DataSourceApiImpl = class {
10628
10634
  }
10629
10635
  return result;
10630
10636
  }
10637
+ setSortInfo(sortInfo) {
10638
+ const multiSort = this.getState().multiSort;
10639
+ if (Array.isArray(sortInfo)) {
10640
+ this.actions.sortInfo = sortInfo.length ? multiSort ? sortInfo : sortInfo[0] : null;
10641
+ return;
10642
+ }
10643
+ this.actions.sortInfo = sortInfo;
10644
+ return;
10645
+ }
10631
10646
  };
10632
10647
  function getCacheAffectedParts(state) {
10633
10648
  const cache = state.cache;
@@ -11079,7 +11094,7 @@ function getPivotColumnsAndColumnGroups({
11079
11094
  columnGroups.set(
11080
11095
  parentColumnGroupId,
11081
11096
  prepareColumnGroup({
11082
- header: pivotGroupKey,
11097
+ header: `${pivotGroupKey}`,
11083
11098
  columnGroup: columnGroupId,
11084
11099
  pivotBy,
11085
11100
  pivotGroupKeys: keys,
@@ -11090,7 +11105,7 @@ function getPivotColumnsAndColumnGroups({
11090
11105
  );
11091
11106
  }
11092
11107
  aggregationReducers.forEach((reducer, index) => {
11093
- const header = isSingleAggregationColumn ? keys[keys.length - 1] : reducer.name || reducer.id;
11108
+ const header = isSingleAggregationColumn ? `${keys[keys.length - 1]}` : reducer.name || reducer.id;
11094
11109
  const computedPivotColumn = prepareColumn({
11095
11110
  pivotBy,
11096
11111
  pivotColumn: true,
@@ -11122,7 +11137,7 @@ function getPivotColumnsAndColumnGroups({
11122
11137
  colGroupId,
11123
11138
  prepareColumnGroup({
11124
11139
  columnGroup: parentKeys.length ? parentKeys.join("/") : void 0,
11125
- header: keys[keys.length - 1],
11140
+ header: `${keys[keys.length - 1]}`,
11126
11141
  pivotBy,
11127
11142
  pivotGroupKeys: keys,
11128
11143
  pivotIndex: keys.length - 1,
@@ -13486,7 +13501,29 @@ function realignColumnContextMenu(param) {
13486
13501
  return colId;
13487
13502
  }
13488
13503
 
13504
+ // src/components/InfiniteTable/types/Utility.ts
13505
+ function notNullable(value) {
13506
+ if (value === null || value === void 0)
13507
+ return false;
13508
+ const testDummyForCompileError = value;
13509
+ return true;
13510
+ }
13511
+
13489
13512
  // src/components/InfiniteTable/api/getImperativeApi.ts
13513
+ function isSortInfoForColumn(sortInfo, col) {
13514
+ if (sortInfo.id) {
13515
+ if (sortInfo.id === col.id) {
13516
+ return true;
13517
+ }
13518
+ return false;
13519
+ }
13520
+ if (sortInfo.field) {
13521
+ if (sortInfo.field === col.field) {
13522
+ return true;
13523
+ }
13524
+ }
13525
+ return false;
13526
+ }
13490
13527
  var InfiniteTableApiImpl = class {
13491
13528
  constructor(context) {
13492
13529
  this.persistEdit = (arg) => __async(this, null, function* () {
@@ -13785,6 +13822,9 @@ var InfiniteTableApiImpl = class {
13785
13822
  get dataSourceActions() {
13786
13823
  return this.context.dataSourceActions;
13787
13824
  }
13825
+ get dataSourceApi() {
13826
+ return this.context.dataSourceApi;
13827
+ }
13788
13828
  focus() {
13789
13829
  var _a;
13790
13830
  (_a = this.getState().scrollerDOMRef.current) == null ? void 0 : _a.focus();
@@ -13805,10 +13845,16 @@ var InfiniteTableApiImpl = class {
13805
13845
  callback == null ? void 0 : callback();
13806
13846
  }
13807
13847
  setTimeout(() => {
13848
+ if (this.isDestroyed()) {
13849
+ return;
13850
+ }
13808
13851
  realignColumnContextMenu(param);
13809
13852
  callback == null ? void 0 : callback();
13810
13853
  }, delay);
13811
13854
  }
13855
+ isDestroyed() {
13856
+ return !this.getState().domRef.current;
13857
+ }
13812
13858
  getColumnOrder() {
13813
13859
  return this.getComputed().computedColumnOrder;
13814
13860
  }
@@ -13914,29 +13960,121 @@ var InfiniteTableApiImpl = class {
13914
13960
  }
13915
13961
  }
13916
13962
  }
13917
- setSortingForColumn(columnId, dir, options) {
13963
+ toggleSortingForColumn(columnId, options) {
13918
13964
  const col = this.getComputed().computedColumnsMap.get(columnId);
13919
13965
  if (!col) {
13920
13966
  return;
13921
13967
  }
13968
+ let dir = this.getSortingForColumn(columnId);
13969
+ if (dir === null) {
13970
+ dir = 1;
13971
+ } else {
13972
+ dir = dir === 1 ? -1 : null;
13973
+ }
13974
+ this.setSortingForColumn(columnId, dir, options);
13975
+ }
13976
+ setSortingForColumn(columnId, dir, options) {
13977
+ const c = this.getComputed().computedColumnsMap.get(columnId);
13978
+ if (!c) {
13979
+ return;
13980
+ }
13981
+ const currentSorting = this.getSortingForColumn(columnId);
13982
+ if (currentSorting === dir) {
13983
+ if (this.getDataSourceState().multiSort === false) {
13984
+ return;
13985
+ }
13986
+ }
13922
13987
  if (dir === null) {
13923
13988
  this.setSortInfoForColumn(columnId, null, options);
13924
13989
  return;
13925
13990
  }
13926
- const sortInfo = {
13927
- dir
13991
+ const groupByForColumn = c.groupByForColumn;
13992
+ let field = c.field;
13993
+ const groupByForCol = groupByForColumn ? Array.isArray(groupByForColumn) ? groupByForColumn : [groupByForColumn] : [];
13994
+ const fieldArr = groupByForCol.map((c2) => {
13995
+ var _a;
13996
+ return c2.valueGetter ? (item) => c2.valueGetter({ data: item, field: c2.field }) : c2.field ? c2.field : (_a = c2.groupField) != null ? _a : void 0;
13997
+ }).filter(notNullable);
13998
+ if (fieldArr.length) {
13999
+ field = fieldArr;
14000
+ }
14001
+ const computedSortType = c.computedSortType;
14002
+ const newColumnSortInfo = {
14003
+ dir,
14004
+ id: c.id,
14005
+ field,
14006
+ type: computedSortType
13928
14007
  };
13929
- const field = col.groupByForColumn ? col.groupByForColumn : col.field;
13930
- if (field) {
13931
- sortInfo.field = field;
14008
+ if (c.valueGetter) {
14009
+ newColumnSortInfo.valueGetter = (data) => c.valueGetter({ data, field: c.field });
14010
+ }
14011
+ this.setSortInfoForColumn(columnId, newColumnSortInfo, options);
14012
+ }
14013
+ setSortInfoForColumn(columnId, columnSortInfo, options) {
14014
+ var _a, _b, _c;
14015
+ const dataSourceState = this.getDataSourceState();
14016
+ const col = this.getComputed().computedColumnsMap.get(columnId);
14017
+ if (!col) {
14018
+ return;
14019
+ }
14020
+ if (!dataSourceState.multiSort) {
14021
+ this.dataSourceApi.setSortInfo(columnSortInfo ? [columnSortInfo] : null);
14022
+ return;
14023
+ }
14024
+ const colField = col.field;
14025
+ const colInfo = {
14026
+ id: columnId,
14027
+ field: colField
14028
+ };
14029
+ let newSortInfo = (_b = (_a = dataSourceState.sortInfo) == null ? void 0 : _a.slice()) != null ? _b : [];
14030
+ if (columnSortInfo === null) {
14031
+ newSortInfo = newSortInfo.filter(
14032
+ (sortInfo) => !isSortInfoForColumn(sortInfo, colInfo)
14033
+ );
14034
+ this.dataSourceApi.setSortInfo(newSortInfo);
14035
+ return;
14036
+ }
14037
+ let matched = false;
14038
+ const multiSortBehavior = (_c = options == null ? void 0 : options.multiSortBehavior) != null ? _c : this.getState().multiSortBehavior;
14039
+ if (multiSortBehavior === "replace") {
14040
+ this.dataSourceApi.setSortInfo([columnSortInfo]);
14041
+ return;
14042
+ }
14043
+ newSortInfo = newSortInfo.map((sortInfo) => {
14044
+ if (matched) {
14045
+ return sortInfo;
14046
+ }
14047
+ if (isSortInfoForColumn(sortInfo, colInfo)) {
14048
+ matched = true;
14049
+ return columnSortInfo;
14050
+ }
14051
+ return sortInfo;
14052
+ });
14053
+ if (!matched) {
14054
+ newSortInfo.push(columnSortInfo);
14055
+ }
14056
+ this.dataSourceApi.setSortInfo(newSortInfo);
14057
+ }
14058
+ getSortTypeForColumn(columnId) {
14059
+ const col = this.getComputed().computedColumnsMap.get(columnId);
14060
+ if (!col) {
14061
+ return null;
13932
14062
  }
13933
- if (col.computedSortType) {
13934
- sortInfo.type = col.computedSortType;
14063
+ return col.computedSortType;
14064
+ }
14065
+ getSortInfoForColumn(columnId) {
14066
+ const col = this.getComputed().computedColumnsMap.get(columnId);
14067
+ if (!col) {
14068
+ return null;
13935
14069
  }
13936
- if (col.valueGetter) {
13937
- sortInfo.valueGetter = (data) => col.valueGetter({ data, field: col.field });
14070
+ return col.computedSortInfo;
14071
+ }
14072
+ getSortingForColumn(columnId) {
14073
+ const sortInfo = this.getSortInfoForColumn(columnId);
14074
+ if (!sortInfo) {
14075
+ return null;
13938
14076
  }
13939
- this.setSortInfoForColumn(columnId, sortInfo, options);
14077
+ return sortInfo.dir;
13940
14078
  }
13941
14079
  setPinningForColumn(columnId, pinning) {
13942
14080
  const columnPinning = __spreadValues({}, this.getState().columnPinning);
@@ -14057,69 +14195,6 @@ var InfiniteTableApiImpl = class {
14057
14195
  this.dataSourceActions.filterValue = newFilterValue;
14058
14196
  }
14059
14197
  }
14060
- setSortInfoForColumn(columnId, columnSortInfo, options) {
14061
- var _a, _b, _c;
14062
- const dataSourceState = this.getDataSourceState();
14063
- const col = this.getComputed().computedColumnsMap.get(columnId);
14064
- if (!col) {
14065
- return;
14066
- }
14067
- if (!dataSourceState.multiSort) {
14068
- this.dataSourceActions.sortInfo = columnSortInfo ? [columnSortInfo] : null;
14069
- return;
14070
- }
14071
- const colField = col.field;
14072
- let newSortInfo = (_b = (_a = dataSourceState.sortInfo) == null ? void 0 : _a.slice()) != null ? _b : [];
14073
- if (columnSortInfo === null) {
14074
- newSortInfo = newSortInfo.filter((sortInfo) => {
14075
- if (sortInfo.id) {
14076
- if (sortInfo.id === columnId) {
14077
- return false;
14078
- }
14079
- return true;
14080
- }
14081
- if (sortInfo.field) {
14082
- if (sortInfo.field === colField) {
14083
- return false;
14084
- }
14085
- return true;
14086
- }
14087
- return true;
14088
- });
14089
- this.dataSourceActions.sortInfo = newSortInfo.length ? newSortInfo : null;
14090
- return;
14091
- }
14092
- let matched = false;
14093
- const multiSortBehavior = (_c = options == null ? void 0 : options.multiSortBehavior) != null ? _c : this.getState().multiSortBehavior;
14094
- if (multiSortBehavior === "replace") {
14095
- this.dataSourceActions.sortInfo = [columnSortInfo];
14096
- } else {
14097
- newSortInfo = newSortInfo.map((sortInfo) => {
14098
- if (matched) {
14099
- return sortInfo;
14100
- }
14101
- if (sortInfo.id) {
14102
- if (sortInfo.id === columnId) {
14103
- matched = true;
14104
- return columnSortInfo;
14105
- }
14106
- return sortInfo;
14107
- }
14108
- if (sortInfo.field) {
14109
- if (sortInfo.field === colField) {
14110
- matched = true;
14111
- return columnSortInfo;
14112
- }
14113
- return sortInfo;
14114
- }
14115
- return sortInfo;
14116
- });
14117
- if (!matched) {
14118
- newSortInfo.push(columnSortInfo);
14119
- }
14120
- this.dataSourceActions.sortInfo = newSortInfo.length ? newSortInfo : null;
14121
- }
14122
- }
14123
14198
  setVisibilityForColumn(columnId, visible) {
14124
14199
  const columnVisibility = __spreadValues({}, this.getState().columnVisibility);
14125
14200
  if (visible) {
@@ -15634,17 +15709,9 @@ function getColumnsWhenGrouping(params) {
15634
15709
  };
15635
15710
  }
15636
15711
 
15637
- // src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts
15712
+ // src/components/InfiniteTable/hooks/useComputedColumns.ts
15638
15713
  var import_react46 = require("react");
15639
15714
 
15640
- // src/components/InfiniteTable/types/Utility.ts
15641
- function notNullable(value) {
15642
- if (value === null || value === void 0)
15643
- return false;
15644
- const testDummyForCompileError = value;
15645
- return true;
15646
- }
15647
-
15648
15715
  // src/components/InfiniteTable/utils/adjustColumnOrderForPinning.ts
15649
15716
  var order = ["start", void 0, "end"];
15650
15717
  var adjustColumnOrderForPinning = (columnOrder, columnPinning) => {
@@ -15691,7 +15758,7 @@ function getColumnComputedType(column, columnTypes) {
15691
15758
  );
15692
15759
  }
15693
15760
 
15694
- // src/components/InfiniteTable/utils/getComputedVisibleColumns.ts
15761
+ // src/components/InfiniteTable/utils/getComputedColumns.ts
15695
15762
  var logError = err("getComputedVisibleColumns");
15696
15763
  var isColumnVisible = (columnVisibility, _columnVisibilityAssumeVisible, colId) => {
15697
15764
  return columnVisibility[colId] !== false;
@@ -15735,7 +15802,7 @@ function isGroupColumnSortable(column, fieldsToColumns) {
15735
15802
  return acc && !!colSortable;
15736
15803
  }, true);
15737
15804
  }
15738
- var getComputedVisibleColumns = ({
15805
+ var getComputedColumns = ({
15739
15806
  columns,
15740
15807
  bodySize,
15741
15808
  columnMinWidth,
@@ -15750,7 +15817,6 @@ var getComputedVisibleColumns = ({
15750
15817
  filterValue,
15751
15818
  sortable,
15752
15819
  sortInfo,
15753
- setSortInfo,
15754
15820
  multiSort,
15755
15821
  filterTypes = defaultFilterTypes,
15756
15822
  viewportReservedWidth,
@@ -16040,67 +16106,6 @@ var getComputedVisibleColumns = ({
16040
16106
  computedLastInCategory,
16041
16107
  computedFirst: theComputedVisibleIndex === 0,
16042
16108
  computedLast,
16043
- toggleSort: ({
16044
- multiSortBehavior
16045
- } = {
16046
- multiSortBehavior: "replace"
16047
- }) => {
16048
- const currentSortInfo = computedSortInfo;
16049
- let newColumnSortInfo;
16050
- const groupByForColumn = result2.groupByForColumn;
16051
- let field2 = c.field;
16052
- const groupByForCol = groupByForColumn ? Array.isArray(groupByForColumn) ? groupByForColumn : [groupByForColumn] : [];
16053
- const fieldArr = groupByForCol.map((c2) => {
16054
- return c2.valueGetter ? (item) => c2.valueGetter({ data: item, field: c2.field }) : c2.field ? c2.field : void 0;
16055
- }).filter(notNullable);
16056
- if (fieldArr.length) {
16057
- field2 = fieldArr;
16058
- }
16059
- if (!currentSortInfo) {
16060
- newColumnSortInfo = {
16061
- dir: 1,
16062
- id,
16063
- field: field2,
16064
- type: computedSortType
16065
- };
16066
- } else {
16067
- if (computedSortedDesc) {
16068
- newColumnSortInfo = null;
16069
- } else {
16070
- newColumnSortInfo = __spreadProps(__spreadValues({}, computedSortInfo), {
16071
- dir: -1
16072
- });
16073
- }
16074
- }
16075
- if (field2 && newColumnSortInfo && !newColumnSortInfo.field) {
16076
- newColumnSortInfo.field = field2;
16077
- }
16078
- if (c.valueGetter && newColumnSortInfo && !newColumnSortInfo.valueGetter) {
16079
- newColumnSortInfo.valueGetter = (data) => c.valueGetter({ data, field: c.field });
16080
- }
16081
- let finalSortInfo = sortInfo ? [...sortInfo] : [];
16082
- if (multiSort) {
16083
- if (multiSortBehavior === "append") {
16084
- if (computedSortIndex === -1) {
16085
- if (newColumnSortInfo) {
16086
- finalSortInfo.push(newColumnSortInfo);
16087
- }
16088
- } else {
16089
- finalSortInfo = finalSortInfo.map((info, index) => {
16090
- if (index === computedSortIndex) {
16091
- return newColumnSortInfo;
16092
- }
16093
- return info;
16094
- }).filter((x) => x != null);
16095
- }
16096
- } else {
16097
- finalSortInfo = newColumnSortInfo ? [newColumnSortInfo] : [];
16098
- }
16099
- } else {
16100
- finalSortInfo = newColumnSortInfo ? [newColumnSortInfo] : [];
16101
- }
16102
- setSortInfo(finalSortInfo);
16103
- },
16104
16109
  id,
16105
16110
  header: (_B = (_A = (_z = c.header) != null ? _z : colType.header) != null ? _A : c.name) != null ? _B : c.field
16106
16111
  });
@@ -16191,8 +16196,8 @@ var useRerenderOnKeyChange = (map2) => {
16191
16196
  return renderId;
16192
16197
  };
16193
16198
 
16194
- // src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts
16195
- var useComputedVisibleColumns = ({
16199
+ // src/components/InfiniteTable/hooks/useComputedColumns.ts
16200
+ var useComputedColumns = ({
16196
16201
  columns,
16197
16202
  bodySize,
16198
16203
  columnMinWidth,
@@ -16205,7 +16210,6 @@ var useComputedVisibleColumns = ({
16205
16210
  draggableColumns,
16206
16211
  sortInfo,
16207
16212
  multiSort,
16208
- setSortInfo,
16209
16213
  filterValue,
16210
16214
  filterTypes,
16211
16215
  columnOrder,
@@ -16244,7 +16248,7 @@ var useComputedVisibleColumns = ({
16244
16248
  computedColumnsMapInInitialOrder,
16245
16249
  fieldsToColumn
16246
16250
  } = (0, import_react46.useMemo)(() => {
16247
- return getComputedVisibleColumns({
16251
+ return getComputedColumns({
16248
16252
  columns,
16249
16253
  scrollbarWidth: scrollbarWidth2,
16250
16254
  bodySize,
@@ -16260,7 +16264,6 @@ var useComputedVisibleColumns = ({
16260
16264
  filterTypes,
16261
16265
  sortable,
16262
16266
  sortInfo,
16263
- setSortInfo,
16264
16267
  multiSort,
16265
16268
  pinnedEndMaxWidth,
16266
16269
  pinnedStartMaxWidth,
@@ -16285,7 +16288,6 @@ var useComputedVisibleColumns = ({
16285
16288
  scrollbarWidth2,
16286
16289
  sortable,
16287
16290
  sortInfo,
16288
- setSortInfo,
16289
16291
  multiSort,
16290
16292
  filterValue,
16291
16293
  filterTypes,
@@ -16401,14 +16403,6 @@ function useComputed() {
16401
16403
  const { multiSort, filterValue, filterTypes } = dataSourceState;
16402
16404
  useColumnGroups();
16403
16405
  const { toggleGroupRow } = useColumnsWhen();
16404
- const setSortInfo = (0, import_react48.useCallback)(
16405
- (sortInfo) => {
16406
- var _a2;
16407
- const newSortInfo = getDataSourceState().multiSort ? sortInfo : (_a2 = sortInfo[0]) != null ? _a2 : null;
16408
- dataSourceActions.sortInfo = newSortInfo;
16409
- },
16410
- [getDataSourceState]
16411
- );
16412
16406
  const columns = componentState.computedColumns;
16413
16407
  const {
16414
16408
  computedColumnOrder,
@@ -16429,7 +16423,7 @@ function useComputed() {
16429
16423
  computedColumnsMap,
16430
16424
  computedColumnsMapInInitialOrder,
16431
16425
  fieldsToColumn
16432
- } = useComputedVisibleColumns({
16426
+ } = useComputedColumns({
16433
16427
  columns,
16434
16428
  // scrollbarWidth: scrollbars.vertical ? getScrollbarWidth() : 0,
16435
16429
  // #scrollbarverticaltag
@@ -16453,7 +16447,6 @@ function useComputed() {
16453
16447
  draggableColumns: componentState.draggableColumns,
16454
16448
  sortInfo: (_a = dataSourceState.sortInfo) != null ? _a : void 0,
16455
16449
  multiSort,
16456
- setSortInfo,
16457
16450
  columnOrder,
16458
16451
  columnVisibility,
16459
16452
  columnVisibilityAssumeVisible: true,
@@ -16680,7 +16673,7 @@ var useLicense = (licenseKey = "") => {
16680
16673
  const valid = (0, import_react49.useMemo)(() => {
16681
16674
  let valid2 = isValidLicense(licenseKey, {
16682
16675
  publishedAt: 1624970570587,
16683
- version: "1.3.21"
16676
+ version: "1.3.23"
16684
16677
  });
16685
16678
  if (!licenseKey && !valid2 && isInsidePlayground) {
16686
16679
  return true;