@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.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: 1796056580800,
29730
+ version: "11.0.2"
29605
29731
  });
29606
29732
  if (result === "invalid" && !licenseKey) {
29607
29733
  return "missing";
@@ -33112,7 +33238,7 @@ var DevToolsOverlay = createRuntimeFn({ defaultClassName: "_143ofgf0", variantCl
33112
33238
  var DevToolsOverlayBg = "_143ofgf5";
33113
33239
  var DevToolsOverlayText = "_143ofgf3";
33114
33240
 
33115
- // src/components/InfiniteTable/hooks/useDebugMode.ts
33241
+ // src/components/InfiniteTable/utils/devToolsConnection.ts
33116
33242
  var cssFileLoadedVarName = stripVar(ThemeVars.loaded);
33117
33243
  var messageBase = {
33118
33244
  source: "infinite-table-page",
@@ -33247,37 +33373,6 @@ var setupHook = once(() => {
33247
33373
  });
33248
33374
  return hookFn;
33249
33375
  });
33250
- function useDebugMode() {
33251
- const { getState, getDataSourceState, dataSourceActions } = useInfiniteTableSelector((ctx) => {
33252
- return {
33253
- getState: ctx.getState,
33254
- getDataSourceState: ctx.getDataSourceState,
33255
- dataSourceActions: ctx.dataSourceActions
33256
- };
33257
- });
33258
- const state = getState();
33259
- const { domRef, debugId } = state;
33260
- if (debugId) {
33261
- if (domRef.current) {
33262
- const value = getComputedStyle(domRef.current).getPropertyValue(
33263
- cssFileLoadedVarName
33264
- );
33265
- if (value !== `${CSS_LOADED_VALUE}`) {
33266
- logDevToolsWarning({
33267
- debugId,
33268
- key: "CSS001_CSS"
33269
- });
33270
- }
33271
- }
33272
- }
33273
- useEffect38(() => {
33274
- const dataSourceState = getDataSourceState();
33275
- if (dataSourceState.debugId !== debugId) {
33276
- dataSourceActions.debugId = debugId;
33277
- }
33278
- }, [debugId]);
33279
- return useDevTools();
33280
- }
33281
33376
  var HOOK_FN_SETUP_CALLBACK = buildSubscriptionCallback();
33282
33377
  var DEVTOOLS_MESSAGES = {
33283
33378
  revertAll: (payload) => {
@@ -33500,6 +33595,57 @@ function listenForDevTools() {
33500
33595
  }
33501
33596
  }
33502
33597
  listenForDevTools();
33598
+ function warnIfDevToolsCssNotLoaded(debugId, domNode) {
33599
+ if (!domNode) {
33600
+ return;
33601
+ }
33602
+ const value = getComputedStyle(domNode).getPropertyValue(cssFileLoadedVarName);
33603
+ if (value !== `${CSS_LOADED_VALUE}`) {
33604
+ logDevToolsWarning({
33605
+ debugId,
33606
+ key: "CSS001_CSS"
33607
+ });
33608
+ }
33609
+ }
33610
+ function getDevToolsHookFn() {
33611
+ return HOOK_FN_SETUP_CALLBACK.get();
33612
+ }
33613
+ function onDevToolsHookFn(fn) {
33614
+ return HOOK_FN_SETUP_CALLBACK.onChange((hookFn) => {
33615
+ if (hookFn) {
33616
+ fn(hookFn);
33617
+ }
33618
+ });
33619
+ }
33620
+ function disconnectFromDevTools(debugId) {
33621
+ const devtoolsHookFn = globalThis.__INFINITE_TABLE_DEVTOOLS_HOOK__;
33622
+ if (devtoolsHookFn) {
33623
+ devtoolsHookFn(debugId, null);
33624
+ }
33625
+ }
33626
+
33627
+ // src/components/InfiniteTable/hooks/useDebugMode.ts
33628
+ function useDebugMode() {
33629
+ const { getState, getDataSourceState, dataSourceActions } = useInfiniteTableSelector((ctx) => {
33630
+ return {
33631
+ getState: ctx.getState,
33632
+ getDataSourceState: ctx.getDataSourceState,
33633
+ dataSourceActions: ctx.dataSourceActions
33634
+ };
33635
+ });
33636
+ const state = getState();
33637
+ const { domRef, debugId } = state;
33638
+ if (debugId) {
33639
+ warnIfDevToolsCssNotLoaded(debugId, domRef.current);
33640
+ }
33641
+ useEffect38(() => {
33642
+ const dataSourceState = getDataSourceState();
33643
+ if (dataSourceState.debugId !== debugId) {
33644
+ dataSourceActions.debugId = debugId;
33645
+ }
33646
+ }, [debugId]);
33647
+ return useDevTools();
33648
+ }
33503
33649
  function useDevTools() {
33504
33650
  const {
33505
33651
  getState,
@@ -33540,24 +33686,19 @@ function useDevTools() {
33540
33686
  dataSourceApi
33541
33687
  });
33542
33688
  };
33543
- const hookFn = HOOK_FN_SETUP_CALLBACK.get();
33689
+ const hookFn = getDevToolsHookFn();
33544
33690
  if (hookFn) {
33545
33691
  withHookFn(hookFn);
33546
33692
  return;
33547
33693
  }
33548
- return HOOK_FN_SETUP_CALLBACK.onChange((hookFn2) => {
33549
- if (!hookFn2) {
33550
- return;
33551
- }
33552
- withHookFn(hookFn2);
33553
- });
33694
+ return onDevToolsHookFn(withHookFn);
33554
33695
  }, []);
33555
33696
  useEffect38(() => {
33556
33697
  const debugId2 = debugIdRef.current;
33557
33698
  if (!debugId2) {
33558
33699
  return;
33559
33700
  }
33560
- const hookFn = HOOK_FN_SETUP_CALLBACK.get();
33701
+ const hookFn = getDevToolsHookFn();
33561
33702
  if (hookFn) {
33562
33703
  hookFn(debugId2, {
33563
33704
  getState,
@@ -33575,10 +33716,7 @@ function useDevTools() {
33575
33716
  return;
33576
33717
  }
33577
33718
  return () => {
33578
- const devtoolsHookFn = globalThis.__INFINITE_TABLE_DEVTOOLS_HOOK__;
33579
- if (devtoolsHookFn) {
33580
- devtoolsHookFn(debugId, null);
33581
- }
33719
+ disconnectFromDevTools(debugId);
33582
33720
  };
33583
33721
  }, [debugId]);
33584
33722
  return debugId;