@infinite-table/infinite-react 11.0.0 → 11.0.1

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
@@ -2083,6 +2083,43 @@ declare class ScrollListener {
2083
2083
  destroy: () => void;
2084
2084
  }
2085
2085
 
2086
+ /**
2087
+ * The filter values typed in the header that wait `filterDelay` before they
2088
+ * are applied, one per column (the last one typed).
2089
+ *
2090
+ * A pending value is dropped when the column's filter is written by
2091
+ * something else in the meantime, so it doesn't overwrite that write when
2092
+ * it fires:
2093
+ * - the table API writes it (setColumnFilter, clearColumnFilter, ...): the
2094
+ * API calls `cancel`;
2095
+ * - the DataSource's filterValue changes in another way (a controlled
2096
+ * `filterValue`, a restored state): when it fires, the pending value
2097
+ * checks that the column's filter is the one it was typed over (by
2098
+ * value - a filterValue built again with the same filters doesn't drop
2099
+ * it), or the one this column applied last (a controlled filterValue
2100
+ * gets it back after the apply).
2101
+ *
2102
+ * The filter editors of a column listen with `onCancel`, to show the
2103
+ * column's filter again instead of the dropped value.
2104
+ */
2105
+ declare class PendingColumnFilters {
2106
+ private pending;
2107
+ /** the value applied last, until the DataSource has it */
2108
+ private applied;
2109
+ private cancelListeners;
2110
+ schedule(columnId: string, value: unknown, options: {
2111
+ delay: number;
2112
+ /** the column's filter value item in the DataSource, now */
2113
+ getFilterValueItem: () => DataSourceFilterValueItem<any> | null;
2114
+ apply: (value: unknown) => void;
2115
+ }): void;
2116
+ /** drops the value waiting for the column, if any */
2117
+ cancel(columnId: string): void;
2118
+ onCancel(columnId: string, fn: () => void): () => void;
2119
+ private isLastApplied;
2120
+ private notifyCancel;
2121
+ }
2122
+
2086
2123
  declare const DS_ERROR_CODES: Record<"DS001", DebugWarningPayload>;
2087
2124
  declare const INFINITE_ERROR_CODES: Record<"CSS001_CSS", DebugWarningPayload>;
2088
2125
  declare const ERROR_CODES: {
@@ -2236,6 +2273,8 @@ interface InfiniteTableSetupState<T> {
2236
2273
  target: HTMLElement | EventTarget;
2237
2274
  column: InfiniteTableComputedColumn<T>;
2238
2275
  }>;
2276
+ /** the filter values typed in the header, waiting for `filterDelay` */
2277
+ pendingColumnFilters: PendingColumnFilters;
2239
2278
  cellContextMenu: SubscriptionCallback<CellContextMenuLocationWithEvent>;
2240
2279
  contextMenu: SubscriptionCallback<ContextMenuLocationWithEvent>;
2241
2280
  cellContextMenuVisibleFor: CellContextMenuLocation | null;
package/index.dev.js CHANGED
@@ -4004,6 +4004,14 @@ function useInfiniteColumnFilterEditor() {
4004
4004
  const [theValue, setTheValue] = (0, import_react13.useState)(
4005
4005
  columnFilterValue?.filter.value ?? ""
4006
4006
  );
4007
+ const [droppedCount, setDroppedCount] = (0, import_react13.useState)(0);
4008
+ (0, import_react13.useEffect)(
4009
+ () => context.getState().pendingColumnFilters.onCancel(
4010
+ column.id,
4011
+ () => setDroppedCount((count) => count + 1)
4012
+ ),
4013
+ [column.id]
4014
+ );
4007
4015
  const onInputChange = React18.useCallback(
4008
4016
  (filterValue) => {
4009
4017
  setTheValue(filterValue);
@@ -4030,7 +4038,7 @@ function useInfiniteColumnFilterEditor() {
4030
4038
  }
4031
4039
  }
4032
4040
  }
4033
- }, [columnFilterValue?.filter.value]);
4041
+ }, [columnFilterValue?.filter.value, droppedCount]);
4034
4042
  const operator = filterContextValue.operator;
4035
4043
  const operatorName = operator?.name;
4036
4044
  return {
@@ -12372,6 +12380,116 @@ function useColumnResizeHandle(column, opts) {
12372
12380
  return resizeHandle;
12373
12381
  }
12374
12382
 
12383
+ // src/components/InfiniteTable/utils/pendingColumnFilters.ts
12384
+ function getColumnFilterValueItem(filterValue, column) {
12385
+ if (!filterValue || !column) {
12386
+ return null;
12387
+ }
12388
+ const fieldKey = column.field || column.groupByForColumn;
12389
+ let byId = null;
12390
+ let byField = null;
12391
+ for (const item of filterValue) {
12392
+ if (item.id === column.id || item.field === column.id) {
12393
+ byId = item;
12394
+ }
12395
+ if (fieldKey && (item.id === fieldKey || item.field === fieldKey)) {
12396
+ byField = item;
12397
+ }
12398
+ }
12399
+ return byId || byField;
12400
+ }
12401
+ function sameFilter(a, b) {
12402
+ if (!a || !b) {
12403
+ return a === b;
12404
+ }
12405
+ return a.filter.type === b.filter.type && a.filter.operator === b.filter.operator && a.filter.value === b.filter.value && !!a.disabled === !!b.disabled;
12406
+ }
12407
+ var PendingColumnFilters = class {
12408
+ constructor() {
12409
+ this.pending = /* @__PURE__ */ new Map();
12410
+ /** the value applied last, until the DataSource has it */
12411
+ this.applied = /* @__PURE__ */ new Map();
12412
+ this.cancelListeners = /* @__PURE__ */ new Map();
12413
+ }
12414
+ schedule(columnId, value, options) {
12415
+ const typedOver = options.getFilterValueItem();
12416
+ if (this.isLastApplied(columnId, typedOver)) {
12417
+ this.applied.delete(columnId);
12418
+ }
12419
+ const previous = this.pending.get(columnId);
12420
+ if (previous) {
12421
+ clearTimeout(previous.timeout);
12422
+ }
12423
+ const timeout = setTimeout(() => {
12424
+ this.pending.delete(columnId);
12425
+ const current = options.getFilterValueItem();
12426
+ if (!sameFilter(current, typedOver) && !this.isLastApplied(columnId, current)) {
12427
+ this.applied.delete(columnId);
12428
+ this.notifyCancel(columnId);
12429
+ return;
12430
+ }
12431
+ options.apply(value);
12432
+ const applied = options.getFilterValueItem();
12433
+ if (applied && applied.filter.value === value) {
12434
+ this.applied.delete(columnId);
12435
+ } else {
12436
+ this.applied.set(columnId, value);
12437
+ }
12438
+ }, options.delay);
12439
+ this.pending.set(columnId, { timeout, typedOver });
12440
+ }
12441
+ /** drops the value waiting for the column, if any */
12442
+ cancel(columnId) {
12443
+ const pending = this.pending.get(columnId);
12444
+ if (!pending) {
12445
+ return;
12446
+ }
12447
+ clearTimeout(pending.timeout);
12448
+ this.pending.delete(columnId);
12449
+ this.notifyCancel(columnId);
12450
+ }
12451
+ onCancel(columnId, fn) {
12452
+ let listeners = this.cancelListeners.get(columnId);
12453
+ if (!listeners) {
12454
+ listeners = /* @__PURE__ */ new Set();
12455
+ this.cancelListeners.set(columnId, listeners);
12456
+ }
12457
+ listeners.add(fn);
12458
+ return () => {
12459
+ listeners.delete(fn);
12460
+ if (!listeners.size && this.cancelListeners.get(columnId) === listeners) {
12461
+ this.cancelListeners.delete(columnId);
12462
+ }
12463
+ };
12464
+ }
12465
+ isLastApplied(columnId, item) {
12466
+ return !!item && this.applied.has(columnId) && item.filter.value === this.applied.get(columnId);
12467
+ }
12468
+ notifyCancel(columnId) {
12469
+ this.cancelListeners.get(columnId)?.forEach((fn) => fn());
12470
+ }
12471
+ };
12472
+ function createColumnFilterChangeHandler(params) {
12473
+ const { columnId, filterDelay, api } = params;
12474
+ const apply = (filterValue) => {
12475
+ api.setColumnFilter(columnId, filterValue);
12476
+ };
12477
+ if (!(filterDelay > 0)) {
12478
+ return apply;
12479
+ }
12480
+ const getFilterValueItem = () => getColumnFilterValueItem(
12481
+ params.getDataSourceState().filterValue,
12482
+ params.getComputed().computedColumnsMap.get(columnId)
12483
+ );
12484
+ return (filterValue) => {
12485
+ params.getState().pendingColumnFilters.schedule(columnId, filterValue, {
12486
+ delay: filterDelay,
12487
+ getFilterValueItem,
12488
+ apply
12489
+ });
12490
+ };
12491
+ }
12492
+
12375
12493
  // src/components/InfiniteTable/components/draggable/DragList.tsx
12376
12494
  var React31 = __toESM(require("react"));
12377
12495
  var import_react24 = require("react");
@@ -18976,15 +19094,17 @@ function InfiniteTableHeaderCellFn(props) {
18976
19094
  verticalAlign,
18977
19095
  align: align2
18978
19096
  };
18979
- const debouncedOnFilterValueChange = React49.useMemo(() => {
18980
- const fn = (filterValue) => {
18981
- api.setColumnFilter(column.id, filterValue);
18982
- };
18983
- if (filterDelay > 0) {
18984
- return debounce(fn, { wait: filterDelay });
18985
- }
18986
- return fn;
18987
- }, [filterDelay, column.id]);
19097
+ const debouncedOnFilterValueChange = React49.useMemo(
19098
+ () => createColumnFilterChangeHandler({
19099
+ columnId: column.id,
19100
+ filterDelay,
19101
+ api,
19102
+ getState,
19103
+ getComputed,
19104
+ getDataSourceState
19105
+ }),
19106
+ [filterDelay, column.id]
19107
+ );
18988
19108
  const filterTypeKey = column.computedFilterType;
18989
19109
  const filterType = filterTypes[filterTypeKey];
18990
19110
  const operatorName = column.computedFilterable ? column.computedFilterValue?.filter.operator ?? filterType?.defaultOperator : void 0;
@@ -21765,6 +21885,7 @@ var InfiniteTableApiImpl = class {
21765
21885
  this.actions.columnPinning = columnPinning;
21766
21886
  }
21767
21887
  setColumnFilter(columnId, filterValue) {
21888
+ this.getState().pendingColumnFilters.cancel(columnId);
21768
21889
  const col = this.getComputed().computedColumnsMap.get(columnId);
21769
21890
  if (!col) {
21770
21891
  return;
@@ -21802,6 +21923,7 @@ var InfiniteTableApiImpl = class {
21802
21923
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21803
21924
  }
21804
21925
  setColumnFilterOperator(columnId, newOperator) {
21926
+ this.getState().pendingColumnFilters.cancel(columnId);
21805
21927
  const col = this.getComputed().computedColumnsMap.get(columnId);
21806
21928
  if (!col) {
21807
21929
  return;
@@ -21845,6 +21967,7 @@ var InfiniteTableApiImpl = class {
21845
21967
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21846
21968
  }
21847
21969
  setFilterValueForColumn(columnId, filterValue) {
21970
+ this.getState().pendingColumnFilters.cancel(columnId);
21848
21971
  const column = this.getComputed().computedColumnsMap.get(columnId);
21849
21972
  if (!column) {
21850
21973
  return;
@@ -21865,6 +21988,7 @@ var InfiniteTableApiImpl = class {
21865
21988
  this.dataSourceActions.filterValue = newFilterValue;
21866
21989
  }
21867
21990
  removeColumnFilter(columnId) {
21991
+ this.getState().pendingColumnFilters.cancel(columnId);
21868
21992
  const column = this.getComputed().computedColumnsMap.get(columnId);
21869
21993
  if (!column) {
21870
21994
  return;
@@ -21884,6 +22008,7 @@ var InfiniteTableApiImpl = class {
21884
22008
  }
21885
22009
  }
21886
22010
  clearColumnFilter(columnId) {
22011
+ this.getState().pendingColumnFilters.cancel(columnId);
21887
22012
  const column = this.getComputed().computedColumnsMap.get(columnId);
21888
22013
  if (!column) {
21889
22014
  return;
@@ -27846,6 +27971,7 @@ function initSetupState2({
27846
27971
  cellContextMenu: buildSubscriptionCallback(),
27847
27972
  contextMenu: buildSubscriptionCallback(),
27848
27973
  onFilterOperatorMenuClick: buildSubscriptionCallback(),
27974
+ pendingColumnFilters: new PendingColumnFilters(),
27849
27975
  flashingDurationCSSVarValue: null,
27850
27976
  onFlashingDurationCSSVarChange: buildSubscriptionCallback(),
27851
27977
  onRowHeightCSSVarChange: buildSubscriptionCallback(),
@@ -29657,8 +29783,8 @@ function getLicenseStatus(licenseKey = "", options) {
29657
29783
  return "valid";
29658
29784
  }
29659
29785
  const result = checkLicense(licenseKey, {
29660
- publishedAt: 1795695384921,
29661
- version: "11.0.0"
29786
+ publishedAt: 1795784312033,
29787
+ version: "11.0.1"
29662
29788
  });
29663
29789
  if (result === "invalid" && !licenseKey) {
29664
29790
  return "missing";
package/index.dev.mjs CHANGED
@@ -3929,6 +3929,14 @@ function useInfiniteColumnFilterEditor() {
3929
3929
  const [theValue, setTheValue] = useState4(
3930
3930
  columnFilterValue?.filter.value ?? ""
3931
3931
  );
3932
+ const [droppedCount, setDroppedCount] = useState4(0);
3933
+ useEffect5(
3934
+ () => context.getState().pendingColumnFilters.onCancel(
3935
+ column.id,
3936
+ () => setDroppedCount((count) => count + 1)
3937
+ ),
3938
+ [column.id]
3939
+ );
3932
3940
  const onInputChange = React18.useCallback(
3933
3941
  (filterValue) => {
3934
3942
  setTheValue(filterValue);
@@ -3955,7 +3963,7 @@ function useInfiniteColumnFilterEditor() {
3955
3963
  }
3956
3964
  }
3957
3965
  }
3958
- }, [columnFilterValue?.filter.value]);
3966
+ }, [columnFilterValue?.filter.value, droppedCount]);
3959
3967
  const operator = filterContextValue.operator;
3960
3968
  const operatorName = operator?.name;
3961
3969
  return {
@@ -12304,6 +12312,116 @@ function useColumnResizeHandle(column, opts) {
12304
12312
  return resizeHandle;
12305
12313
  }
12306
12314
 
12315
+ // src/components/InfiniteTable/utils/pendingColumnFilters.ts
12316
+ function getColumnFilterValueItem(filterValue, column) {
12317
+ if (!filterValue || !column) {
12318
+ return null;
12319
+ }
12320
+ const fieldKey = column.field || column.groupByForColumn;
12321
+ let byId = null;
12322
+ let byField = null;
12323
+ for (const item of filterValue) {
12324
+ if (item.id === column.id || item.field === column.id) {
12325
+ byId = item;
12326
+ }
12327
+ if (fieldKey && (item.id === fieldKey || item.field === fieldKey)) {
12328
+ byField = item;
12329
+ }
12330
+ }
12331
+ return byId || byField;
12332
+ }
12333
+ function sameFilter(a, b) {
12334
+ if (!a || !b) {
12335
+ return a === b;
12336
+ }
12337
+ return a.filter.type === b.filter.type && a.filter.operator === b.filter.operator && a.filter.value === b.filter.value && !!a.disabled === !!b.disabled;
12338
+ }
12339
+ var PendingColumnFilters = class {
12340
+ constructor() {
12341
+ this.pending = /* @__PURE__ */ new Map();
12342
+ /** the value applied last, until the DataSource has it */
12343
+ this.applied = /* @__PURE__ */ new Map();
12344
+ this.cancelListeners = /* @__PURE__ */ new Map();
12345
+ }
12346
+ schedule(columnId, value, options) {
12347
+ const typedOver = options.getFilterValueItem();
12348
+ if (this.isLastApplied(columnId, typedOver)) {
12349
+ this.applied.delete(columnId);
12350
+ }
12351
+ const previous = this.pending.get(columnId);
12352
+ if (previous) {
12353
+ clearTimeout(previous.timeout);
12354
+ }
12355
+ const timeout = setTimeout(() => {
12356
+ this.pending.delete(columnId);
12357
+ const current = options.getFilterValueItem();
12358
+ if (!sameFilter(current, typedOver) && !this.isLastApplied(columnId, current)) {
12359
+ this.applied.delete(columnId);
12360
+ this.notifyCancel(columnId);
12361
+ return;
12362
+ }
12363
+ options.apply(value);
12364
+ const applied = options.getFilterValueItem();
12365
+ if (applied && applied.filter.value === value) {
12366
+ this.applied.delete(columnId);
12367
+ } else {
12368
+ this.applied.set(columnId, value);
12369
+ }
12370
+ }, options.delay);
12371
+ this.pending.set(columnId, { timeout, typedOver });
12372
+ }
12373
+ /** drops the value waiting for the column, if any */
12374
+ cancel(columnId) {
12375
+ const pending = this.pending.get(columnId);
12376
+ if (!pending) {
12377
+ return;
12378
+ }
12379
+ clearTimeout(pending.timeout);
12380
+ this.pending.delete(columnId);
12381
+ this.notifyCancel(columnId);
12382
+ }
12383
+ onCancel(columnId, fn) {
12384
+ let listeners = this.cancelListeners.get(columnId);
12385
+ if (!listeners) {
12386
+ listeners = /* @__PURE__ */ new Set();
12387
+ this.cancelListeners.set(columnId, listeners);
12388
+ }
12389
+ listeners.add(fn);
12390
+ return () => {
12391
+ listeners.delete(fn);
12392
+ if (!listeners.size && this.cancelListeners.get(columnId) === listeners) {
12393
+ this.cancelListeners.delete(columnId);
12394
+ }
12395
+ };
12396
+ }
12397
+ isLastApplied(columnId, item) {
12398
+ return !!item && this.applied.has(columnId) && item.filter.value === this.applied.get(columnId);
12399
+ }
12400
+ notifyCancel(columnId) {
12401
+ this.cancelListeners.get(columnId)?.forEach((fn) => fn());
12402
+ }
12403
+ };
12404
+ function createColumnFilterChangeHandler(params) {
12405
+ const { columnId, filterDelay, api } = params;
12406
+ const apply = (filterValue) => {
12407
+ api.setColumnFilter(columnId, filterValue);
12408
+ };
12409
+ if (!(filterDelay > 0)) {
12410
+ return apply;
12411
+ }
12412
+ const getFilterValueItem = () => getColumnFilterValueItem(
12413
+ params.getDataSourceState().filterValue,
12414
+ params.getComputed().computedColumnsMap.get(columnId)
12415
+ );
12416
+ return (filterValue) => {
12417
+ params.getState().pendingColumnFilters.schedule(columnId, filterValue, {
12418
+ delay: filterDelay,
12419
+ getFilterValueItem,
12420
+ apply
12421
+ });
12422
+ };
12423
+ }
12424
+
12307
12425
  // src/components/InfiniteTable/components/draggable/DragList.tsx
12308
12426
  import * as React31 from "react";
12309
12427
  import { useCallback as useCallback17, useEffect as useEffect11, useState as useState12 } from "react";
@@ -18914,15 +19032,17 @@ function InfiniteTableHeaderCellFn(props) {
18914
19032
  verticalAlign,
18915
19033
  align: align2
18916
19034
  };
18917
- const debouncedOnFilterValueChange = React49.useMemo(() => {
18918
- const fn = (filterValue) => {
18919
- api.setColumnFilter(column.id, filterValue);
18920
- };
18921
- if (filterDelay > 0) {
18922
- return debounce(fn, { wait: filterDelay });
18923
- }
18924
- return fn;
18925
- }, [filterDelay, column.id]);
19035
+ const debouncedOnFilterValueChange = React49.useMemo(
19036
+ () => createColumnFilterChangeHandler({
19037
+ columnId: column.id,
19038
+ filterDelay,
19039
+ api,
19040
+ getState,
19041
+ getComputed,
19042
+ getDataSourceState
19043
+ }),
19044
+ [filterDelay, column.id]
19045
+ );
18926
19046
  const filterTypeKey = column.computedFilterType;
18927
19047
  const filterType = filterTypes[filterTypeKey];
18928
19048
  const operatorName = column.computedFilterable ? column.computedFilterValue?.filter.operator ?? filterType?.defaultOperator : void 0;
@@ -21703,6 +21823,7 @@ var InfiniteTableApiImpl = class {
21703
21823
  this.actions.columnPinning = columnPinning;
21704
21824
  }
21705
21825
  setColumnFilter(columnId, filterValue) {
21826
+ this.getState().pendingColumnFilters.cancel(columnId);
21706
21827
  const col = this.getComputed().computedColumnsMap.get(columnId);
21707
21828
  if (!col) {
21708
21829
  return;
@@ -21740,6 +21861,7 @@ var InfiniteTableApiImpl = class {
21740
21861
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21741
21862
  }
21742
21863
  setColumnFilterOperator(columnId, newOperator) {
21864
+ this.getState().pendingColumnFilters.cancel(columnId);
21743
21865
  const col = this.getComputed().computedColumnsMap.get(columnId);
21744
21866
  if (!col) {
21745
21867
  return;
@@ -21783,6 +21905,7 @@ var InfiniteTableApiImpl = class {
21783
21905
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21784
21906
  }
21785
21907
  setFilterValueForColumn(columnId, filterValue) {
21908
+ this.getState().pendingColumnFilters.cancel(columnId);
21786
21909
  const column = this.getComputed().computedColumnsMap.get(columnId);
21787
21910
  if (!column) {
21788
21911
  return;
@@ -21803,6 +21926,7 @@ var InfiniteTableApiImpl = class {
21803
21926
  this.dataSourceActions.filterValue = newFilterValue;
21804
21927
  }
21805
21928
  removeColumnFilter(columnId) {
21929
+ this.getState().pendingColumnFilters.cancel(columnId);
21806
21930
  const column = this.getComputed().computedColumnsMap.get(columnId);
21807
21931
  if (!column) {
21808
21932
  return;
@@ -21822,6 +21946,7 @@ var InfiniteTableApiImpl = class {
21822
21946
  }
21823
21947
  }
21824
21948
  clearColumnFilter(columnId) {
21949
+ this.getState().pendingColumnFilters.cancel(columnId);
21825
21950
  const column = this.getComputed().computedColumnsMap.get(columnId);
21826
21951
  if (!column) {
21827
21952
  return;
@@ -27789,6 +27914,7 @@ function initSetupState2({
27789
27914
  cellContextMenu: buildSubscriptionCallback(),
27790
27915
  contextMenu: buildSubscriptionCallback(),
27791
27916
  onFilterOperatorMenuClick: buildSubscriptionCallback(),
27917
+ pendingColumnFilters: new PendingColumnFilters(),
27792
27918
  flashingDurationCSSVarValue: null,
27793
27919
  onFlashingDurationCSSVarChange: buildSubscriptionCallback(),
27794
27920
  onRowHeightCSSVarChange: buildSubscriptionCallback(),
@@ -29600,8 +29726,8 @@ function getLicenseStatus(licenseKey = "", options) {
29600
29726
  return "valid";
29601
29727
  }
29602
29728
  const result = checkLicense(licenseKey, {
29603
- publishedAt: 1795695384921,
29604
- version: "11.0.0"
29729
+ publishedAt: 1795784312033,
29730
+ version: "11.0.1"
29605
29731
  });
29606
29732
  if (result === "invalid" && !licenseKey) {
29607
29733
  return "missing";