@infinite-table/infinite-react 11.0.0 → 11.0.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
@@ -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: 1796056580800,
29787
+ version: "11.0.2"
29662
29788
  });
29663
29789
  if (result === "invalid" && !licenseKey) {
29664
29790
  return "missing";
@@ -33159,7 +33285,7 @@ var DevToolsOverlay = createRuntimeFn({ defaultClassName: "_143ofgf0", variantCl
33159
33285
  var DevToolsOverlayBg = "_143ofgf5";
33160
33286
  var DevToolsOverlayText = "_143ofgf3";
33161
33287
 
33162
- // src/components/InfiniteTable/hooks/useDebugMode.ts
33288
+ // src/components/InfiniteTable/utils/devToolsConnection.ts
33163
33289
  var cssFileLoadedVarName = stripVar(ThemeVars.loaded);
33164
33290
  var messageBase = {
33165
33291
  source: "infinite-table-page",
@@ -33294,37 +33420,6 @@ var setupHook = once(() => {
33294
33420
  });
33295
33421
  return hookFn;
33296
33422
  });
33297
- function useDebugMode() {
33298
- const { getState, getDataSourceState, dataSourceActions } = useInfiniteTableSelector((ctx) => {
33299
- return {
33300
- getState: ctx.getState,
33301
- getDataSourceState: ctx.getDataSourceState,
33302
- dataSourceActions: ctx.dataSourceActions
33303
- };
33304
- });
33305
- const state = getState();
33306
- const { domRef, debugId } = state;
33307
- if (debugId) {
33308
- if (domRef.current) {
33309
- const value = getComputedStyle(domRef.current).getPropertyValue(
33310
- cssFileLoadedVarName
33311
- );
33312
- if (value !== `${CSS_LOADED_VALUE}`) {
33313
- logDevToolsWarning({
33314
- debugId,
33315
- key: "CSS001_CSS"
33316
- });
33317
- }
33318
- }
33319
- }
33320
- (0, import_react68.useEffect)(() => {
33321
- const dataSourceState = getDataSourceState();
33322
- if (dataSourceState.debugId !== debugId) {
33323
- dataSourceActions.debugId = debugId;
33324
- }
33325
- }, [debugId]);
33326
- return useDevTools();
33327
- }
33328
33423
  var HOOK_FN_SETUP_CALLBACK = buildSubscriptionCallback();
33329
33424
  var DEVTOOLS_MESSAGES = {
33330
33425
  revertAll: (payload) => {
@@ -33547,6 +33642,57 @@ function listenForDevTools() {
33547
33642
  }
33548
33643
  }
33549
33644
  listenForDevTools();
33645
+ function warnIfDevToolsCssNotLoaded(debugId, domNode) {
33646
+ if (!domNode) {
33647
+ return;
33648
+ }
33649
+ const value = getComputedStyle(domNode).getPropertyValue(cssFileLoadedVarName);
33650
+ if (value !== `${CSS_LOADED_VALUE}`) {
33651
+ logDevToolsWarning({
33652
+ debugId,
33653
+ key: "CSS001_CSS"
33654
+ });
33655
+ }
33656
+ }
33657
+ function getDevToolsHookFn() {
33658
+ return HOOK_FN_SETUP_CALLBACK.get();
33659
+ }
33660
+ function onDevToolsHookFn(fn) {
33661
+ return HOOK_FN_SETUP_CALLBACK.onChange((hookFn) => {
33662
+ if (hookFn) {
33663
+ fn(hookFn);
33664
+ }
33665
+ });
33666
+ }
33667
+ function disconnectFromDevTools(debugId) {
33668
+ const devtoolsHookFn = globalThis.__INFINITE_TABLE_DEVTOOLS_HOOK__;
33669
+ if (devtoolsHookFn) {
33670
+ devtoolsHookFn(debugId, null);
33671
+ }
33672
+ }
33673
+
33674
+ // src/components/InfiniteTable/hooks/useDebugMode.ts
33675
+ function useDebugMode() {
33676
+ const { getState, getDataSourceState, dataSourceActions } = useInfiniteTableSelector((ctx) => {
33677
+ return {
33678
+ getState: ctx.getState,
33679
+ getDataSourceState: ctx.getDataSourceState,
33680
+ dataSourceActions: ctx.dataSourceActions
33681
+ };
33682
+ });
33683
+ const state = getState();
33684
+ const { domRef, debugId } = state;
33685
+ if (debugId) {
33686
+ warnIfDevToolsCssNotLoaded(debugId, domRef.current);
33687
+ }
33688
+ (0, import_react68.useEffect)(() => {
33689
+ const dataSourceState = getDataSourceState();
33690
+ if (dataSourceState.debugId !== debugId) {
33691
+ dataSourceActions.debugId = debugId;
33692
+ }
33693
+ }, [debugId]);
33694
+ return useDevTools();
33695
+ }
33550
33696
  function useDevTools() {
33551
33697
  const {
33552
33698
  getState,
@@ -33587,24 +33733,19 @@ function useDevTools() {
33587
33733
  dataSourceApi
33588
33734
  });
33589
33735
  };
33590
- const hookFn = HOOK_FN_SETUP_CALLBACK.get();
33736
+ const hookFn = getDevToolsHookFn();
33591
33737
  if (hookFn) {
33592
33738
  withHookFn(hookFn);
33593
33739
  return;
33594
33740
  }
33595
- return HOOK_FN_SETUP_CALLBACK.onChange((hookFn2) => {
33596
- if (!hookFn2) {
33597
- return;
33598
- }
33599
- withHookFn(hookFn2);
33600
- });
33741
+ return onDevToolsHookFn(withHookFn);
33601
33742
  }, []);
33602
33743
  (0, import_react68.useEffect)(() => {
33603
33744
  const debugId2 = debugIdRef.current;
33604
33745
  if (!debugId2) {
33605
33746
  return;
33606
33747
  }
33607
- const hookFn = HOOK_FN_SETUP_CALLBACK.get();
33748
+ const hookFn = getDevToolsHookFn();
33608
33749
  if (hookFn) {
33609
33750
  hookFn(debugId2, {
33610
33751
  getState,
@@ -33622,10 +33763,7 @@ function useDevTools() {
33622
33763
  return;
33623
33764
  }
33624
33765
  return () => {
33625
- const devtoolsHookFn = globalThis.__INFINITE_TABLE_DEVTOOLS_HOOK__;
33626
- if (devtoolsHookFn) {
33627
- devtoolsHookFn(debugId, null);
33628
- }
33766
+ disconnectFromDevTools(debugId);
33629
33767
  };
33630
33768
  }, [debugId]);
33631
33769
  return debugId;