@infinite-table/infinite-react 10.2.1 → 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.dev.mjs CHANGED
@@ -1900,6 +1900,62 @@ function computePropsDiff(params) {
1900
1900
  rawUpdatedPropsCount
1901
1901
  };
1902
1902
  }
1903
+ function applyPropsDiff(params) {
1904
+ const {
1905
+ currentProps,
1906
+ prevProps,
1907
+ state,
1908
+ propsToForward,
1909
+ propsToStateSet,
1910
+ dispatch,
1911
+ actions,
1912
+ onPropChange: onPropChange2,
1913
+ onPropsChange,
1914
+ beforeDispatch
1915
+ } = params;
1916
+ const diff = computePropsDiff({
1917
+ currentProps,
1918
+ prevProps,
1919
+ state,
1920
+ propsToForward,
1921
+ propsToStateSet
1922
+ });
1923
+ const {
1924
+ newMappedState,
1925
+ newMappedStateCount,
1926
+ updatedPropsToState,
1927
+ updatedPropsToStateCount,
1928
+ rawUpdatedProps,
1929
+ rawUpdatedPropsCount
1930
+ } = diff;
1931
+ if (updatedPropsToStateCount === 0 && newMappedStateCount === 0) {
1932
+ return false;
1933
+ }
1934
+ beforeDispatch?.(diff);
1935
+ dispatch({
1936
+ payload: {
1937
+ mappedState: newMappedStateCount ? newMappedState : null,
1938
+ updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
1939
+ }
1940
+ });
1941
+ if (onPropChange2) {
1942
+ for (const prop in rawUpdatedProps) {
1943
+ if (rawUpdatedProps.hasOwnProperty(prop)) {
1944
+ const { newValue, oldValue } = rawUpdatedProps[prop];
1945
+ onPropChange2(
1946
+ { name: prop, newValue, oldValue },
1947
+ currentProps,
1948
+ actions,
1949
+ state
1950
+ );
1951
+ }
1952
+ }
1953
+ }
1954
+ if (onPropsChange && rawUpdatedPropsCount) {
1955
+ onPropsChange(rawUpdatedProps, currentProps, actions, state);
1956
+ }
1957
+ return true;
1958
+ }
1903
1959
 
1904
1960
  // src/components/hooks/useComponentState/index.tsx
1905
1961
  var ComponentContext;
@@ -1995,79 +2051,56 @@ function buildManagedComponent(config) {
1995
2051
  const effectFn = config.layoutEffect ? useLayoutEffect4 : useEffect3;
1996
2052
  effectFn(() => {
1997
2053
  const currentProps = props;
1998
- const {
1999
- newMappedState,
2000
- newMappedStateCount,
2001
- updatedPropsToState,
2002
- updatedPropsToStateCount,
2003
- rawUpdatedProps,
2004
- rawUpdatedPropsCount
2005
- } = computePropsDiff({
2054
+ const dispatched = applyPropsDiff({
2006
2055
  currentProps,
2007
2056
  prevProps,
2008
2057
  state,
2009
2058
  propsToForward,
2010
- propsToStateSet: propsToStateSetRef.current
2011
- });
2012
- if (updatedPropsToStateCount > 0 || newMappedStateCount > 0) {
2013
- const debugId = state.debugId;
2014
- const marker = debugId ? getMarker(debugId).track.ComponentState.label.PropUpdate.start() : void 0;
2015
- const debugChannelName = config.debugName ? typeof config.debugName === "function" ? `${config.debugName(currentProps)}:rerender` : `${config.debugName}:rerender` : "rerender";
2016
- const logger2 = dbg(debugChannelName);
2017
- logger2(
2018
- "Triggered by new values for the following props",
2019
- ...[
2020
- ...Object.keys(newMappedState ?? {}),
2021
- ...Object.keys(updatedPropsToState ?? {})
2022
- ]
2023
- );
2024
- if (marker) {
2025
- marker.end({
2026
- label: debugChannelName,
2027
- details: [
2028
- newMappedStateCount > 0 ? {
2029
- name: "Updated properties",
2030
- value: Object.keys(newMappedState).join(", ")
2031
- } : void 0,
2032
- updatedPropsToStateCount > 0 ? {
2033
- name: "Updated props",
2034
- value: Object.keys(updatedPropsToState).join(", ")
2035
- } : void 0,
2036
- updatedPropsToStateCount > 0 || updatedPropsToState ? {
2037
- name: "Details",
2038
- value: "The time for this marker is not accurate. The marker is only displayed so you can easily identify the props that triggered the rerender."
2039
- } : void 0
2040
- ].filter(notNullable)
2041
- });
2042
- }
2043
- const action = {
2044
- payload: {
2045
- mappedState: newMappedStateCount ? newMappedState : null,
2046
- updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
2047
- }
2048
- };
2049
- skipTriggerParentStateChangeRef.current = true;
2050
- dispatch(action);
2051
- if (config.onPropChange) {
2052
- for (var prop in rawUpdatedProps)
2053
- if (rawUpdatedProps.hasOwnProperty(prop)) {
2054
- const { newValue, oldValue } = rawUpdatedProps[prop];
2055
- config.onPropChange(
2056
- { name: prop, newValue, oldValue },
2057
- props,
2058
- actions,
2059
- state
2060
- );
2061
- }
2062
- }
2063
- if (config.onPropsChange && rawUpdatedPropsCount) {
2064
- config.onPropsChange(
2065
- rawUpdatedProps,
2066
- props,
2067
- actions,
2068
- state
2059
+ propsToStateSet: propsToStateSetRef.current,
2060
+ dispatch,
2061
+ actions,
2062
+ onPropChange: config.onPropChange,
2063
+ onPropsChange: config.onPropsChange,
2064
+ beforeDispatch: ({
2065
+ newMappedState,
2066
+ newMappedStateCount,
2067
+ updatedPropsToState,
2068
+ updatedPropsToStateCount
2069
+ }) => {
2070
+ const debugId = state.debugId;
2071
+ const marker = debugId ? getMarker(debugId).track.ComponentState.label.PropUpdate.start() : void 0;
2072
+ const debugChannelName = config.debugName ? typeof config.debugName === "function" ? `${config.debugName(currentProps)}:rerender` : `${config.debugName}:rerender` : "rerender";
2073
+ const logger2 = dbg(debugChannelName);
2074
+ logger2(
2075
+ "Triggered by new values for the following props",
2076
+ ...[
2077
+ ...Object.keys(newMappedState ?? {}),
2078
+ ...Object.keys(updatedPropsToState ?? {})
2079
+ ]
2069
2080
  );
2081
+ if (marker) {
2082
+ marker.end({
2083
+ label: debugChannelName,
2084
+ details: [
2085
+ newMappedStateCount > 0 ? {
2086
+ name: "Updated properties",
2087
+ value: Object.keys(newMappedState).join(", ")
2088
+ } : void 0,
2089
+ updatedPropsToStateCount > 0 ? {
2090
+ name: "Updated props",
2091
+ value: Object.keys(updatedPropsToState).join(", ")
2092
+ } : void 0,
2093
+ updatedPropsToStateCount > 0 || updatedPropsToState ? {
2094
+ name: "Details",
2095
+ value: "The time for this marker is not accurate. The marker is only displayed so you can easily identify the props that triggered the rerender."
2096
+ } : void 0
2097
+ ].filter(notNullable)
2098
+ });
2099
+ }
2070
2100
  }
2101
+ });
2102
+ if (dispatched) {
2103
+ skipTriggerParentStateChangeRef.current = true;
2071
2104
  }
2072
2105
  });
2073
2106
  effectFn(() => {
@@ -2451,7 +2484,7 @@ var HeaderFilterOperatorCls = "_12zfob12q _16lm1iw1p _16lm1iw2h _16lm1iw2j _16lm
2451
2484
  var HeaderFilterOperatorIconRecipe = createRuntimeFn({ defaultClassName: "_12zfob12r _16lm1iw1 _16lm1iw23", variantClassNames: { disabled: { true: "_12zfob12s", false: "_12zfob12t" } }, defaultVariants: {}, compoundVariants: [] });
2452
2485
  var HeaderFilterRecipe = createRuntimeFn({ defaultClassName: "_12zfob12n _16lm1iw1p _16lm1iw2h _16lm1iw2k _16lm1iw1", variantClassNames: { active: { true: "_12zfob12o", false: "_12zfob12p" } }, defaultVariants: {}, compoundVariants: [] });
2453
2486
  var HeaderGroupCls = "_12zfob12m _16lm1iw1p _16lm1iw2h _16lm1iw2j";
2454
- var HeaderMenuIconCls = createRuntimeFn({ defaultClassName: "_12zfob127 _16lm1iw1 _16lm1iw1p _16lm1iw2f _16lm1iw32 _16lm1iw39", variantClassNames: { menuVisible: { true: "_12zfob128" }, reserveSpaceWhenHidden: { true: "_12zfob129", false: "_12zfob12a" } }, defaultVariants: {}, compoundVariants: [[{ menuVisible: true, reserveSpaceWhenHidden: false }, "_12zfob12b"]] });
2487
+ var HeaderMenuIconCls = createRuntimeFn({ defaultClassName: "_12zfob127 _16lm1iw1 _16lm1iw39", variantClassNames: { menuVisible: { true: "_12zfob128" }, reserveSpaceWhenHidden: { true: "_12zfob129", false: "_12zfob12a" } }, defaultVariants: {}, compoundVariants: [[{ menuVisible: true, reserveSpaceWhenHidden: false }, "_12zfob12b"]] });
2455
2488
  var HeaderScrollbarPlaceholderCls = "_12zfob1b _16lm1iw2";
2456
2489
  var HeaderSortIconCls = "_16lm1iw1";
2457
2490
  var HeaderSortIconIndexCls = "_12zfob16";
@@ -3698,8 +3731,7 @@ function getColumnApiForColumn(colOrColId, param) {
3698
3731
  }
3699
3732
 
3700
3733
  // src/components/InfiniteTable/components/InfiniteTableHeader/getColumnLabel.ts
3701
- function getColumnLabel(colIdOrCol, context, renderLocation) {
3702
- const col = typeof colIdOrCol === "string" ? context.getComputed().computedColumnsMap.get(colIdOrCol) : colIdOrCol;
3734
+ function getColumnLabelHeaderParam(col, context, renderLocation) {
3703
3735
  const {
3704
3736
  api,
3705
3737
  getComputed,
@@ -3711,35 +3743,47 @@ function getColumnLabel(colIdOrCol, context, renderLocation) {
3711
3743
  const dataSourceState = getDataSourceState();
3712
3744
  const { allRowsSelected, someRowsSelected, selectionMode } = dataSourceState;
3713
3745
  const computed = getComputed();
3714
- let label = col.header && typeof col.header !== "function" ? col.header : col.name || col.id || "";
3715
- if (typeof col.header === "function") {
3716
- const columnApi = getColumnApiForColumn(col.id, {
3717
- ...context,
3718
- actions,
3719
- dataSourceActions,
3720
- dataSourceApi
3721
- });
3722
- label = col.header({
3723
- horizontalLayoutPageIndex: null,
3724
- column: col,
3725
- columnApi,
3726
- dataSourceApi,
3727
- renderLocation,
3728
- dragging: false,
3729
- columnsMap: computed.computedColumnsMap,
3730
- columnSortInfo: col.computedSortInfo,
3731
- columnFilterValue: col.computedFilterValue,
3732
- filtered: col.computedFiltered,
3733
- allRowsSelected,
3734
- someRowsSelected,
3735
- selectionMode,
3736
- api,
3737
- renderBag: {
3738
- header: label
3739
- }
3740
- }) ?? null;
3746
+ const columnApi = getColumnApiForColumn(col.id, {
3747
+ ...context,
3748
+ actions,
3749
+ dataSourceActions,
3750
+ dataSourceApi
3751
+ });
3752
+ return {
3753
+ horizontalLayoutPageIndex: null,
3754
+ column: col,
3755
+ columnApi,
3756
+ dataSourceApi,
3757
+ renderLocation,
3758
+ dragging: false,
3759
+ columnsMap: computed.computedColumnsMap,
3760
+ columnSortInfo: col.computedSortInfo,
3761
+ columnFilterValue: col.computedFilterValue,
3762
+ filtered: col.computedFiltered,
3763
+ allRowsSelected,
3764
+ someRowsSelected,
3765
+ selectionMode,
3766
+ api,
3767
+ renderBag: {
3768
+ header: col.name || col.id || ""
3769
+ }
3770
+ };
3771
+ }
3772
+ function getColumnLabel(colIdOrCol, context, renderLocation, bind) {
3773
+ const col = typeof colIdOrCol === "string" ? context.getComputed().computedColumnsMap.get(colIdOrCol) : colIdOrCol;
3774
+ const header = col.header;
3775
+ if (typeof header === "function") {
3776
+ const param = getColumnLabelHeaderParam(col, context, renderLocation);
3777
+ const label = header(param) ?? null;
3778
+ return bind ? bind(label, param) : label;
3741
3779
  }
3742
- return label;
3780
+ if (header) {
3781
+ return bind ? bind(
3782
+ header,
3783
+ getColumnLabelHeaderParam(col, context, renderLocation)
3784
+ ) : header;
3785
+ }
3786
+ return col.name || col.id || "";
3743
3787
  }
3744
3788
 
3745
3789
  // src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilterContext.ts
@@ -3885,6 +3929,14 @@ function useInfiniteColumnFilterEditor() {
3885
3929
  const [theValue, setTheValue] = useState4(
3886
3930
  columnFilterValue?.filter.value ?? ""
3887
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
+ );
3888
3940
  const onInputChange = React18.useCallback(
3889
3941
  (filterValue) => {
3890
3942
  setTheValue(filterValue);
@@ -3911,7 +3963,7 @@ function useInfiniteColumnFilterEditor() {
3911
3963
  }
3912
3964
  }
3913
3965
  }
3914
- }, [columnFilterValue?.filter.value]);
3966
+ }, [columnFilterValue?.filter.value, droppedCount]);
3915
3967
  const operator = filterContextValue.operator;
3916
3968
  const operatorName = operator?.name;
3917
3969
  return {
@@ -11786,9 +11838,10 @@ import * as React28 from "react";
11786
11838
  import { useEffect as useEffect10, useState as useState9 } from "react";
11787
11839
 
11788
11840
  // src/components/InfiniteTable/components/icons/SortIcon/SortIcon.css.ts
11789
- var SortIconCls = "_1b8djff0 _16lm1iw1p _16lm1iw2f _16lm1iw1 _16lm1iw32";
11790
- var SortIconDirectionCls = { asc: "_1b8djff1", desc: "_1b8djff2", none: "_1b8djff3" };
11791
- var SortIconLineCls = "_1b8djff4";
11841
+ var SortIconCls = "_1b8djff1 _16lm1iw1";
11842
+ var SortIconDirectionCls = { asc: "_1b8djff2", desc: "_1b8djff3", none: "_1b8djff4" };
11843
+ var SortIconLineCls = "_1b8djff5";
11844
+ var SortIconLineWidthVarName = "--_1b8djff0";
11792
11845
 
11793
11846
  // src/components/InfiniteTable/components/icons/SortIcon/shared.ts
11794
11847
  var defaultLineStyle3 = {
@@ -11858,7 +11911,11 @@ function SortIcon(props) {
11858
11911
  "div",
11859
11912
  {
11860
11913
  "data-name": "sort-icon",
11861
- style: { ...style2, width: size },
11914
+ style: {
11915
+ ...style2,
11916
+ width: size,
11917
+ [SortIconLineWidthVarName]: `${lineWidth}px`
11918
+ },
11862
11919
  className: join(
11863
11920
  className,
11864
11921
  InfiniteIconClassName,
@@ -12255,6 +12312,116 @@ function useColumnResizeHandle(column, opts) {
12255
12312
  return resizeHandle;
12256
12313
  }
12257
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
+
12258
12425
  // src/components/InfiniteTable/components/draggable/DragList.tsx
12259
12426
  import * as React31 from "react";
12260
12427
  import { useCallback as useCallback17, useEffect as useEffect11, useState as useState12 } from "react";
@@ -18865,15 +19032,17 @@ function InfiniteTableHeaderCellFn(props) {
18865
19032
  verticalAlign,
18866
19033
  align: align2
18867
19034
  };
18868
- const debouncedOnFilterValueChange = React49.useMemo(() => {
18869
- const fn = (filterValue) => {
18870
- api.setColumnFilter(column.id, filterValue);
18871
- };
18872
- if (filterDelay > 0) {
18873
- return debounce(fn, { wait: filterDelay });
18874
- }
18875
- return fn;
18876
- }, [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
+ );
18877
19046
  const filterTypeKey = column.computedFilterType;
18878
19047
  const filterType = filterTypes[filterTypeKey];
18879
19048
  const operatorName = column.computedFilterable ? column.computedFilterValue?.filter.operator ?? filterType?.defaultOperator : void 0;
@@ -21654,6 +21823,7 @@ var InfiniteTableApiImpl = class {
21654
21823
  this.actions.columnPinning = columnPinning;
21655
21824
  }
21656
21825
  setColumnFilter(columnId, filterValue) {
21826
+ this.getState().pendingColumnFilters.cancel(columnId);
21657
21827
  const col = this.getComputed().computedColumnsMap.get(columnId);
21658
21828
  if (!col) {
21659
21829
  return;
@@ -21691,6 +21861,7 @@ var InfiniteTableApiImpl = class {
21691
21861
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21692
21862
  }
21693
21863
  setColumnFilterOperator(columnId, newOperator) {
21864
+ this.getState().pendingColumnFilters.cancel(columnId);
21694
21865
  const col = this.getComputed().computedColumnsMap.get(columnId);
21695
21866
  if (!col) {
21696
21867
  return;
@@ -21734,6 +21905,7 @@ var InfiniteTableApiImpl = class {
21734
21905
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21735
21906
  }
21736
21907
  setFilterValueForColumn(columnId, filterValue) {
21908
+ this.getState().pendingColumnFilters.cancel(columnId);
21737
21909
  const column = this.getComputed().computedColumnsMap.get(columnId);
21738
21910
  if (!column) {
21739
21911
  return;
@@ -21754,6 +21926,7 @@ var InfiniteTableApiImpl = class {
21754
21926
  this.dataSourceActions.filterValue = newFilterValue;
21755
21927
  }
21756
21928
  removeColumnFilter(columnId) {
21929
+ this.getState().pendingColumnFilters.cancel(columnId);
21757
21930
  const column = this.getComputed().computedColumnsMap.get(columnId);
21758
21931
  if (!column) {
21759
21932
  return;
@@ -21773,6 +21946,7 @@ var InfiniteTableApiImpl = class {
21773
21946
  }
21774
21947
  }
21775
21948
  clearColumnFilter(columnId) {
21949
+ this.getState().pendingColumnFilters.cancel(columnId);
21776
21950
  const column = this.getComputed().computedColumnsMap.get(columnId);
21777
21951
  if (!column) {
21778
21952
  return;
@@ -23111,6 +23285,9 @@ function deepEqual(a, b) {
23111
23285
  if (a === b) return true;
23112
23286
  if (a == null || b == null) return a === b;
23113
23287
  if (typeof a !== typeof b) return false;
23288
+ if (a instanceof Date || b instanceof Date) {
23289
+ return a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
23290
+ }
23114
23291
  if (Array.isArray(a) && Array.isArray(b)) {
23115
23292
  if (a.length !== b.length) return false;
23116
23293
  for (let i = 0, len = a.length; i < len; i++) {
@@ -27737,6 +27914,7 @@ function initSetupState2({
27737
27914
  cellContextMenu: buildSubscriptionCallback(),
27738
27915
  contextMenu: buildSubscriptionCallback(),
27739
27916
  onFilterOperatorMenuClick: buildSubscriptionCallback(),
27917
+ pendingColumnFilters: new PendingColumnFilters(),
27740
27918
  flashingDurationCSSVarValue: null,
27741
27919
  onFlashingDurationCSSVarChange: buildSubscriptionCallback(),
27742
27920
  onRowHeightCSSVarChange: buildSubscriptionCallback(),
@@ -29548,8 +29726,8 @@ function getLicenseStatus(licenseKey = "", options) {
29548
29726
  return "valid";
29549
29727
  }
29550
29728
  const result = checkLicense(licenseKey, {
29551
- publishedAt: 1795523603652,
29552
- version: "10.2.1"
29729
+ publishedAt: 1795784312033,
29730
+ version: "11.0.1"
29553
29731
  });
29554
29732
  if (result === "invalid" && !licenseKey) {
29555
29733
  return "missing";
@@ -30858,6 +31036,14 @@ import {
30858
31036
  useState as useState23
30859
31037
  } from "react";
30860
31038
 
31039
+ // src/components/Menu/MenuContext.ts
31040
+ import { createContext as createContext11, useContext as useContext12 } from "react";
31041
+ var MenuContext = createContext11(null);
31042
+ function useMenuContext() {
31043
+ const contextValue = useContext12(MenuContext);
31044
+ return contextValue;
31045
+ }
31046
+
30861
31047
  // src/components/Menu/menuDomUtils.ts
30862
31048
  function getMenuItemRect(menuId, itemKey) {
30863
31049
  const cells = getMenuItemNodes(menuId, itemKey);
@@ -30899,6 +31085,180 @@ function getFirstCheckBoxInsideMenuItem(menuId, itemKey) {
30899
31085
  return null;
30900
31086
  }
30901
31087
 
31088
+ // src/components/Menu/menuKeyboardNav.ts
31089
+ function hideMenuAndParents(getState) {
31090
+ const state = getState();
31091
+ state.onHideIntent?.(state);
31092
+ }
31093
+ function runMenuItemClick(event, item, context) {
31094
+ const { getState, setActiveItemKey, setKeyboardActiveItemKey, hideAll } = context;
31095
+ setKeyboardActiveItemKey(item.key);
31096
+ setActiveItemKey(item.key);
31097
+ if (item.originalMenuItem.onClick) {
31098
+ item.originalMenuItem.onClick(event);
31099
+ }
31100
+ const onActionParam = {
31101
+ key: item.key,
31102
+ item: item.originalMenuItem,
31103
+ hideMenu: hideAll
31104
+ };
31105
+ if (item.originalMenuItem.onAction) {
31106
+ item.originalMenuItem.onAction(onActionParam);
31107
+ }
31108
+ const { onAction } = getState();
31109
+ if (onAction) {
31110
+ onAction(onActionParam);
31111
+ }
31112
+ if (item.originalMenuItem.hideMenuOnAction) {
31113
+ hideAll();
31114
+ }
31115
+ }
31116
+ function handleMenuKeyDown(keyboardEvent, context) {
31117
+ const {
31118
+ getState,
31119
+ setActiveItemKey,
31120
+ setKeyboardActiveItemKey,
31121
+ destroy,
31122
+ getSubmenuApi,
31123
+ isMounted,
31124
+ onItemClick
31125
+ } = context;
31126
+ const { runtimeItems, runtimeSelectableItems, keyboardActiveItemKey } = getState();
31127
+ const keyboardActiveIndex = runtimeItems.findIndex(
31128
+ (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31129
+ );
31130
+ let newKeyboardActiveItemKey = keyboardActiveItemKey;
31131
+ const keyboardActiveItem = runtimeItems[keyboardActiveIndex];
31132
+ const validKeys3 = {
31133
+ ArrowUp: () => {
31134
+ const newActiveItem = runtimeItems.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31135
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31136
+ newKeyboardActiveItemKey = newActiveItem.key;
31137
+ }
31138
+ },
31139
+ ArrowDown: () => {
31140
+ const newActiveItem = runtimeItems.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31141
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31142
+ newKeyboardActiveItemKey = newActiveItem.key;
31143
+ }
31144
+ },
31145
+ Home: () => {
31146
+ validKeys3.PageUp();
31147
+ },
31148
+ End: () => {
31149
+ validKeys3.PageDown();
31150
+ },
31151
+ PageUp: () => {
31152
+ newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31153
+ },
31154
+ PageDown: () => {
31155
+ newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31156
+ },
31157
+ ArrowLeft: () => {
31158
+ setActiveItemKey(null);
31159
+ if (getState().parentMenuId) {
31160
+ destroy();
31161
+ }
31162
+ },
31163
+ ArrowRight: () => {
31164
+ if (!keyboardActiveItem) {
31165
+ return;
31166
+ }
31167
+ setActiveItemKey(keyboardActiveItem.key);
31168
+ raf(() => {
31169
+ const submenuApi = getSubmenuApi();
31170
+ if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31171
+ submenuApi.focus();
31172
+ }
31173
+ });
31174
+ },
31175
+ Enter: () => {
31176
+ if (!keyboardActiveItem) {
31177
+ return;
31178
+ }
31179
+ if (keyboardActiveItem.originalMenuItem?.menu) {
31180
+ if (getSubmenuApi()) {
31181
+ validKeys3.ArrowLeft();
31182
+ return;
31183
+ }
31184
+ setActiveItemKey(keyboardActiveItem.key);
31185
+ } else {
31186
+ onItemClick(keyboardEvent, keyboardActiveItem);
31187
+ }
31188
+ },
31189
+ " ": () => {
31190
+ if (!keyboardActiveItem) {
31191
+ return;
31192
+ }
31193
+ if (!keyboardActiveItem.originalMenuItem.menu) {
31194
+ onItemClick(keyboardEvent, keyboardActiveItem);
31195
+ }
31196
+ const checkbox = getFirstCheckBoxInsideMenuItem(
31197
+ getState().menuId,
31198
+ keyboardActiveItem.key
31199
+ );
31200
+ if (!checkbox) {
31201
+ return;
31202
+ }
31203
+ checkbox.click();
31204
+ },
31205
+ Escape: () => {
31206
+ validKeys3.ArrowLeft();
31207
+ const state = getState();
31208
+ if (!state.parentMenuId) {
31209
+ state.onHideIntent?.(state);
31210
+ }
31211
+ }
31212
+ };
31213
+ const fn = validKeys3[keyboardEvent.key];
31214
+ if (fn) {
31215
+ fn();
31216
+ keyboardEvent.preventDefault();
31217
+ }
31218
+ if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31219
+ setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31220
+ }
31221
+ }
31222
+ function createMenuFocus(context) {
31223
+ const {
31224
+ getState,
31225
+ setFocused,
31226
+ setKeyboardActiveItemKey,
31227
+ shouldSelectFirstItemOnFocus,
31228
+ hideAll
31229
+ } = context;
31230
+ const onMenuFocus = () => {
31231
+ setFocused(true);
31232
+ setTimeout(() => {
31233
+ const domNode = getState().domRef.current;
31234
+ if (shouldSelectFirstItemOnFocus() && domNode && domNode === document.activeElement && getState().keyboardActiveItemKey == null) {
31235
+ setKeyboardActiveItemKey(
31236
+ getState().runtimeSelectableItems[0]?.key ?? null
31237
+ );
31238
+ }
31239
+ });
31240
+ };
31241
+ const api = {
31242
+ hideMenu: hideAll,
31243
+ focus: () => {
31244
+ const domNode = getState().domRef.current;
31245
+ if (domNode) {
31246
+ domNode.focus();
31247
+ setTimeout(() => {
31248
+ const node = getState().domRef.current;
31249
+ if (node && node !== document.activeElement) {
31250
+ node.focus();
31251
+ }
31252
+ }, 10);
31253
+ onMenuFocus();
31254
+ }
31255
+ },
31256
+ getMenuId: () => getState().menuId,
31257
+ getParentMenuId: () => getState().parentMenuId
31258
+ };
31259
+ return { api, onMenuFocus };
31260
+ }
31261
+
30902
31262
  // src/utils/pageGeometry/Triangle.ts
30903
31263
  var Triangle = class extends ConvexPoly {
30904
31264
  // uncommenting this here breaks our tests - WHAT????
@@ -31115,40 +31475,38 @@ var MenuTriangleContext = class {
31115
31475
  }
31116
31476
  };
31117
31477
 
31118
- // src/components/Menu/MenuContext.ts
31119
- import { createContext as createContext11, useContext as useContext12 } from "react";
31120
- var MenuContext = createContext11(null);
31121
- function useMenuContext() {
31122
- const contextValue = useContext12(MenuContext);
31123
- return contextValue;
31478
+ // src/components/Menu/menuViewShared.ts
31479
+ function getActiveSubmenuItem(runtimeItems, activeItemKey) {
31480
+ const activeItem = runtimeItems.filter(
31481
+ (item) => item.type === "item" && activeItemKey === item.key
31482
+ )[0];
31483
+ return activeItem && activeItem.menu ? activeItem : null;
31124
31484
  }
31125
-
31126
- // src/components/hooks/useMounted.ts
31127
- import { useCallback as useCallback29, useEffect as useEffect31, useRef as useRef29 } from "react";
31128
- function useMounted() {
31129
- let mountedRef = useRef29(true);
31130
- useEffect31(() => {
31131
- mountedRef.current = true;
31132
- return () => {
31133
- mountedRef.current = false;
31134
- };
31135
- }, []);
31136
- const isMounted = useCallback29(() => mountedRef.current, []);
31137
- return isMounted;
31485
+ function getSubmenuOverlayParams(menuId, item, constrainTo) {
31486
+ const alignTo = getMenuItemRect(menuId, item.key);
31487
+ if (!alignTo) {
31488
+ return null;
31489
+ }
31490
+ return {
31491
+ id: `${menuId}-submenu`,
31492
+ alignTo,
31493
+ alignPosition: [
31494
+ ["TopLeft", "TopRight"],
31495
+ ["TopRight", "TopLeft"]
31496
+ ],
31497
+ constrainTo
31498
+ };
31138
31499
  }
31139
-
31140
- // src/components/Menu/Menu.tsx
31141
- function renderSubmenuForItem(item, config) {
31500
+ function getSubmenuProps(item, context) {
31142
31501
  const {
31143
31502
  parentMenuId,
31503
+ constrainTo,
31504
+ api,
31505
+ hideAll,
31144
31506
  setSubmenuApi,
31145
31507
  setActiveItemKey,
31146
- setKeyboardActiveItemKey,
31147
- constrainTo,
31148
- onHideIntent,
31149
- api
31150
- } = config;
31151
- const overlayId = `${parentMenuId}-submenu`;
31508
+ setKeyboardActiveItemKey
31509
+ } = context;
31152
31510
  let itemMenu = item.menu;
31153
31511
  if (!itemMenu) {
31154
31512
  return null;
@@ -31156,67 +31514,152 @@ function renderSubmenuForItem(item, config) {
31156
31514
  if (typeof itemMenu === "function") {
31157
31515
  itemMenu = itemMenu();
31158
31516
  }
31159
- return /* @__PURE__ */ React61.createElement(
31160
- Menu,
31161
- {
31162
- key: overlayId,
31163
- parentMenuItemKey: item.key,
31164
- parentMenuId,
31165
- constrainTo,
31166
- ...itemMenu,
31167
- autoFocus: false,
31168
- onShow: (state, api2) => {
31169
- itemMenu?.onShow?.(state, api2);
31170
- setSubmenuApi(api2);
31171
- },
31172
- onHideIntent: (state) => {
31173
- itemMenu?.onHideIntent?.(state);
31174
- onHideIntent(state);
31175
- },
31176
- onHide: (state) => {
31177
- if (state.focused) {
31178
- setActiveItemKey(null);
31179
- setKeyboardActiveItemKey(item.key);
31180
- api.focus();
31181
- }
31182
- }
31183
- }
31184
- );
31185
- }
31186
- function useSubmenus({
31187
- onItemActivate
31188
- }) {
31189
- const { getState } = useMenuContext();
31190
- const [{ onItemEnter, onItemLeave }] = useState23(() => {
31191
- return new MenuTriangleContext({
31192
- parentMenuId: getState().parentMenuId,
31193
- onItemActivate: (itemKey) => {
31194
- if (!itemKey) {
31195
- onItemActivate(null);
31196
- return;
31197
- }
31198
- const item = getState().runtimeItems.filter(
31199
- (item2) => item2.type === "item" && item2.key === itemKey
31200
- )[0];
31201
- onItemActivate(item);
31202
- },
31203
- itemHasSubMenu: (itemKey) => {
31204
- const item = getState().runtimeItems.filter(
31205
- (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31206
- )[0];
31207
- return !!item;
31517
+ const submenu = itemMenu;
31518
+ return {
31519
+ parentMenuItemKey: item.key,
31520
+ parentMenuId,
31521
+ constrainTo,
31522
+ ...submenu,
31523
+ autoFocus: false,
31524
+ onShow: (state, submenuApi) => {
31525
+ submenu?.onShow?.(state, submenuApi);
31526
+ setSubmenuApi(submenuApi);
31527
+ },
31528
+ onHideIntent: (state) => {
31529
+ submenu?.onHideIntent?.(state);
31530
+ hideAll();
31531
+ },
31532
+ onHide: (state) => {
31533
+ if (state.focused) {
31534
+ setActiveItemKey(null);
31535
+ setKeyboardActiveItemKey(item.key);
31536
+ api.focus();
31537
+ }
31538
+ }
31539
+ };
31540
+ }
31541
+ function createMenuTriangleHandlers(getState, onItemActivate) {
31542
+ return new MenuTriangleContext({
31543
+ parentMenuId: getState().parentMenuId,
31544
+ onItemActivate,
31545
+ itemHasSubMenu: (itemKey) => {
31546
+ const item = getState().runtimeItems.filter(
31547
+ (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31548
+ )[0];
31549
+ return !!item;
31550
+ },
31551
+ getMenuRectFor: (itemKey) => {
31552
+ const selector2 = `[data-submenu-for="${itemKey}"]`;
31553
+ const menuNode = document.querySelector(selector2);
31554
+ if (!menuNode) {
31555
+ return void 0;
31556
+ }
31557
+ return Rectangle.from(menuNode.getBoundingClientRect());
31558
+ }
31559
+ }).getHandlers();
31560
+ }
31561
+ function getMenuGridStyle(state, style2, toCssWidth = (width) => width) {
31562
+ const { columns, runtimeItems, wrapLabels } = state;
31563
+ const gridTemplateColumns = columns.map((col) => {
31564
+ return toCssWidth(
31565
+ col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto"
31566
+ );
31567
+ }).join(" ");
31568
+ const result = {
31569
+ ...style2,
31570
+ gridTemplateColumns,
31571
+ gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31572
+ };
31573
+ if (!wrapLabels) {
31574
+ result.whiteSpace = "nowrap";
31575
+ }
31576
+ return result;
31577
+ }
31578
+ function getMenuItemCells(item, columns, index, flags) {
31579
+ const { active, keyboardActive, pressed } = flags;
31580
+ const key = item.value.key;
31581
+ const className = join(
31582
+ MenuItemCls({
31583
+ active,
31584
+ disabled: !!item.disabled,
31585
+ keyboardActive,
31586
+ pressed: pressed || active
31587
+ }),
31588
+ item.className
31589
+ );
31590
+ const cells = [];
31591
+ let spanIndex = 0;
31592
+ columns.forEach((col, i) => {
31593
+ const target = item.value;
31594
+ const field = col.field || col.name;
31595
+ const start = i + 1;
31596
+ const end = start + item.span;
31597
+ if (start < spanIndex) {
31598
+ return;
31599
+ }
31600
+ spanIndex = end;
31601
+ cells.push({
31602
+ key: `${key}-${field}`,
31603
+ column: col,
31604
+ value: target[field],
31605
+ style: {
31606
+ ...col.style,
31607
+ ...item.style,
31608
+ gridColumnStart: start,
31609
+ gridColumnEnd: end
31208
31610
  },
31209
- getMenuRectFor: (itemKey) => {
31210
- const selector2 = `[data-submenu-for="${itemKey}"]`;
31211
- const menuNode = document.querySelector(selector2);
31212
- if (!menuNode) {
31213
- return void 0;
31214
- }
31215
- const rect = Rectangle.from(menuNode.getBoundingClientRect());
31216
- return rect;
31611
+ className,
31612
+ dataAttributes: {
31613
+ "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31614
+ "data-menu-col-name": `${col.name}`,
31615
+ "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31616
+ "data-menu-row-index": `${index}`,
31617
+ "data-menu-item-key": `${item.key}`
31217
31618
  }
31218
- }).getHandlers();
31619
+ });
31219
31620
  });
31621
+ return cells;
31622
+ }
31623
+
31624
+ // src/components/hooks/useMounted.ts
31625
+ import { useCallback as useCallback29, useEffect as useEffect31, useRef as useRef29 } from "react";
31626
+ function useMounted() {
31627
+ let mountedRef = useRef29(true);
31628
+ useEffect31(() => {
31629
+ mountedRef.current = true;
31630
+ return () => {
31631
+ mountedRef.current = false;
31632
+ };
31633
+ }, []);
31634
+ const isMounted = useCallback29(() => mountedRef.current, []);
31635
+ return isMounted;
31636
+ }
31637
+
31638
+ // src/components/Menu/Menu.tsx
31639
+ function renderSubmenuForItem(item, config) {
31640
+ const overlayId = `${config.parentMenuId}-submenu`;
31641
+ const submenuProps = getSubmenuProps(item, config);
31642
+ if (!submenuProps) {
31643
+ return null;
31644
+ }
31645
+ return /* @__PURE__ */ React61.createElement(Menu, { key: overlayId, ...submenuProps });
31646
+ }
31647
+ function useSubmenus({
31648
+ onItemActivate
31649
+ }) {
31650
+ const { getState } = useMenuContext();
31651
+ const [{ onItemEnter, onItemLeave }] = useState23(
31652
+ () => createMenuTriangleHandlers(getState, (itemKey) => {
31653
+ if (!itemKey) {
31654
+ onItemActivate(null);
31655
+ return;
31656
+ }
31657
+ const item = getState().runtimeItems.filter(
31658
+ (item2) => item2.type === "item" && item2.key === itemKey
31659
+ )[0];
31660
+ onItemActivate(item);
31661
+ })
31662
+ );
31220
31663
  return {
31221
31664
  onItemEnter: useCallback30(onItemEnter, []),
31222
31665
  onItemLeave: useCallback30(onItemLeave, [])
@@ -31225,6 +31668,7 @@ function useSubmenus({
31225
31668
  function MenuComponent(props) {
31226
31669
  const { domProps } = props;
31227
31670
  const {
31671
+ componentState,
31228
31672
  componentState: {
31229
31673
  columns,
31230
31674
  runtimeItems,
@@ -31233,8 +31677,6 @@ function MenuComponent(props) {
31233
31677
  keyboardActiveItemKey,
31234
31678
  constrainTo,
31235
31679
  destroyed,
31236
- onAction,
31237
- wrapLabels,
31238
31680
  onShow,
31239
31681
  onHide,
31240
31682
  autoFocus,
@@ -31252,62 +31694,56 @@ function MenuComponent(props) {
31252
31694
  }, []);
31253
31695
  const isMounted = useMounted();
31254
31696
  const [submenuApi, setSubmenuApi] = useState23(null);
31697
+ const shouldSelectFirstItemOnFocus = useRef30(true);
31698
+ const [{ api, onMenuFocus, hideAll }] = useState23(() => {
31699
+ const hideAll2 = () => hideMenuAndParents(getState);
31700
+ return {
31701
+ hideAll: hideAll2,
31702
+ ...createMenuFocus({
31703
+ getState,
31704
+ setFocused: (focused) => {
31705
+ componentActions.focused = focused;
31706
+ },
31707
+ setKeyboardActiveItemKey,
31708
+ shouldSelectFirstItemOnFocus: () => shouldSelectFirstItemOnFocus.current,
31709
+ hideAll: hideAll2
31710
+ })
31711
+ };
31712
+ });
31255
31713
  let renderedChildren = null;
31256
31714
  useLayoutEffect17(() => {
31257
31715
  const { runtimeItems: runtimeItems2 } = getState();
31258
- const activeItem = runtimeItems2.filter(
31259
- (item) => item.type === "item" && activeItemKey === item.key
31260
- )[0];
31261
- if (!activeItem || !activeItem.menu) {
31716
+ const activeItem = getActiveSubmenuItem(runtimeItems2, activeItemKey);
31717
+ if (!activeItem) {
31262
31718
  setSubmenuApi(null);
31263
31719
  clearAll();
31264
31720
  return;
31265
31721
  }
31266
- if (activeItem) {
31267
- const alignTo = getMenuItemRect(menuId, activeItem.key);
31268
- const menu = () => renderSubmenuForItem(activeItem, {
31269
- constrainTo,
31270
- setSubmenuApi,
31271
- setActiveItemKey,
31272
- setKeyboardActiveItemKey,
31273
- parentMenuId: menuId,
31274
- onHideIntent: hideAll,
31275
- api
31276
- });
31277
- if (alignTo) {
31278
- showOverlay(menu, {
31279
- id: `${menuId}-submenu`,
31280
- alignTo,
31281
- alignPosition: [
31282
- ["TopLeft", "TopRight"],
31283
- ["TopRight", "TopLeft"]
31284
- ],
31285
- constrainTo
31286
- });
31287
- }
31288
- return;
31722
+ const overlayParams = getSubmenuOverlayParams(
31723
+ menuId,
31724
+ activeItem,
31725
+ constrainTo
31726
+ );
31727
+ const menu = () => renderSubmenuForItem(activeItem, {
31728
+ constrainTo,
31729
+ setSubmenuApi,
31730
+ setActiveItemKey,
31731
+ setKeyboardActiveItemKey,
31732
+ parentMenuId: menuId,
31733
+ hideAll,
31734
+ api
31735
+ });
31736
+ if (overlayParams) {
31737
+ showOverlay(menu, overlayParams);
31289
31738
  }
31290
31739
  }, [activeItemKey]);
31291
31740
  const onItemClick = (event, item) => {
31292
- setKeyboardActiveItemKey(item.key);
31293
- setActiveItemKey(item.key);
31294
- if (item.originalMenuItem.onClick) {
31295
- item.originalMenuItem.onClick(event);
31296
- }
31297
- const onActionParam = {
31298
- key: item.key,
31299
- item: item.originalMenuItem,
31300
- hideMenu: hideAll
31301
- };
31302
- if (item.originalMenuItem.onAction) {
31303
- item.originalMenuItem.onAction(onActionParam);
31304
- }
31305
- if (onAction) {
31306
- onAction(onActionParam);
31307
- }
31308
- if (item.originalMenuItem.hideMenuOnAction) {
31309
- hideAll();
31310
- }
31741
+ runMenuItemClick(event, item, {
31742
+ getState,
31743
+ setActiveItemKey,
31744
+ setKeyboardActiveItemKey,
31745
+ hideAll
31746
+ });
31311
31747
  };
31312
31748
  const {
31313
31749
  showOverlay,
@@ -31345,158 +31781,27 @@ function MenuComponent(props) {
31345
31781
  onClick: onItemClick
31346
31782
  }
31347
31783
  ));
31348
- const gridTemplateColumns = columns.map((col) => {
31349
- return col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto";
31350
- }).join(" ");
31351
- const style2 = {
31352
- ...domProps.style,
31353
- gridTemplateColumns,
31354
- gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31355
- };
31356
- if (!wrapLabels) {
31357
- style2.whiteSpace = "nowrap";
31358
- }
31784
+ const style2 = getMenuGridStyle(
31785
+ componentState,
31786
+ domProps.style
31787
+ );
31359
31788
  function handleKeydown(keyboardEvent) {
31360
- const { runtimeItems: runtimeItems2, runtimeSelectableItems } = getState();
31361
- let keyboardActiveIndex = runtimeItems2.findIndex(
31362
- (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31363
- );
31364
- let newKeyboardActiveItemKey = keyboardActiveItemKey;
31365
- const keyboardActiveItem = runtimeItems2[keyboardActiveIndex];
31366
- const validKeys3 = {
31367
- ArrowUp: () => {
31368
- const newActiveItem = runtimeItems2.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31369
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31370
- newKeyboardActiveItemKey = newActiveItem.key;
31371
- }
31372
- },
31373
- ArrowDown: () => {
31374
- const newActiveItem = runtimeItems2.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31375
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31376
- newKeyboardActiveItemKey = newActiveItem.key;
31377
- }
31378
- },
31379
- Home: () => {
31380
- validKeys3.PageUp();
31381
- },
31382
- End: () => {
31383
- validKeys3.PageDown();
31384
- },
31385
- PageUp: () => {
31386
- newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31387
- },
31388
- PageDown: () => {
31389
- newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31390
- },
31391
- ArrowLeft: () => {
31392
- setActiveItemKey(null);
31393
- if (getState().parentMenuId) {
31394
- componentActions.destroyed = true;
31395
- }
31396
- },
31397
- ArrowRight: () => {
31398
- if (!keyboardActiveItem) {
31399
- return;
31400
- }
31401
- setActiveItemKey(keyboardActiveItem.key);
31402
- raf(() => {
31403
- if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31404
- submenuApi.focus();
31405
- }
31406
- });
31407
- },
31408
- Enter: () => {
31409
- if (!keyboardActiveItem) {
31410
- return;
31411
- }
31412
- if (keyboardActiveItem.originalMenuItem?.menu) {
31413
- if (keyboardActiveItem && keyboardActiveItem.originalMenuItem.menu && submenuApi) {
31414
- validKeys3.ArrowLeft();
31415
- return;
31416
- }
31417
- if (keyboardActiveItem) {
31418
- setActiveItemKey(keyboardActiveItem.key);
31419
- }
31420
- } else {
31421
- onItemClick(
31422
- keyboardEvent,
31423
- keyboardActiveItem
31424
- );
31425
- }
31426
- },
31427
- " ": () => {
31428
- if (!keyboardActiveItem) {
31429
- return;
31430
- }
31431
- if (!keyboardActiveItem.originalMenuItem.menu) {
31432
- onItemClick(
31433
- keyboardEvent,
31434
- keyboardActiveItem
31435
- );
31436
- }
31437
- const checkbox = getFirstCheckBoxInsideMenuItem(
31438
- menuId,
31439
- keyboardActiveItem.key
31440
- );
31441
- if (!checkbox) {
31442
- return;
31443
- }
31444
- checkbox.click();
31789
+ handleMenuKeyDown(keyboardEvent, {
31790
+ getState,
31791
+ setActiveItemKey,
31792
+ setKeyboardActiveItemKey,
31793
+ destroy: () => {
31794
+ componentActions.destroyed = true;
31445
31795
  },
31446
- Escape: () => {
31447
- validKeys3.ArrowLeft();
31448
- const state = getState();
31449
- if (!state.parentMenuId) {
31450
- state.onHideIntent?.(state);
31451
- }
31452
- }
31453
- };
31454
- const fn = validKeys3[keyboardEvent.key];
31455
- if (fn) {
31456
- fn();
31457
- keyboardEvent.preventDefault();
31458
- }
31459
- if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31460
- setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31461
- }
31796
+ // the submenu api of this render: the raf of ArrowRight reads it
31797
+ getSubmenuApi: () => submenuApi,
31798
+ isMounted,
31799
+ onItemClick
31800
+ });
31462
31801
  }
31463
31802
  function onMenuBlur() {
31464
31803
  componentActions.focused = false;
31465
31804
  }
31466
- const onMenuFocus = useCallback30(function() {
31467
- componentActions.focused = true;
31468
- setTimeout(() => {
31469
- if (shouldSelectFirstItemOnFocus.current && domRef.current && domRef.current === document.activeElement && getState().keyboardActiveItemKey == null) {
31470
- setKeyboardActiveItemKey(
31471
- getState().runtimeSelectableItems[0]?.key ?? null
31472
- );
31473
- }
31474
- });
31475
- }, []);
31476
- const shouldSelectFirstItemOnFocus = useRef30(true);
31477
- const hideAll = useCallback30(() => {
31478
- const state = getState();
31479
- state.onHideIntent?.(state);
31480
- }, [getState]);
31481
- const [api] = useState23(() => {
31482
- const result2 = {
31483
- hideMenu: hideAll,
31484
- focus: () => {
31485
- if (domRef.current) {
31486
- domRef.current.focus();
31487
- setTimeout(() => {
31488
- if (domRef.current && domRef.current !== document.activeElement) {
31489
- domRef.current.focus();
31490
- }
31491
- }, 10);
31492
- onMenuFocus();
31493
- }
31494
- },
31495
- getMenuId: () => getState().menuId,
31496
- getParentMenuId: () => getState().parentMenuId
31497
- };
31498
- return result2;
31499
- });
31500
31805
  const refCallback = useCallback30((node) => {
31501
31806
  if (node) {
31502
31807
  domRef.current = node;
@@ -31541,44 +31846,20 @@ function MenuComponent(props) {
31541
31846
  function RuntimeItemRenderer(props) {
31542
31847
  const [pressed, setPressed] = React61.useState(false);
31543
31848
  const { columns, item, index, active, keyboardActive } = props;
31544
- const key = item.type === "item" ? item.value.key : index;
31545
31849
  let content = null;
31546
31850
  if (item.type === "decoration") {
31547
31851
  content = /* @__PURE__ */ React61.createElement("div", { style: item.style }, item.value);
31548
31852
  } else {
31549
- let spanIndex = 0;
31550
- content = columns.map((col, i) => {
31551
- const target = item.value;
31552
- const field = col.field || col.name;
31553
- const start = i + 1;
31554
- const end = start + item.span;
31555
- if (start < spanIndex) {
31556
- return null;
31557
- }
31558
- spanIndex = end;
31559
- const style2 = {
31560
- ...col.style,
31561
- ...item.style,
31562
- gridColumnStart: start,
31563
- gridColumnEnd: end
31564
- };
31853
+ content = getMenuItemCells(item, columns, index, {
31854
+ active,
31855
+ keyboardActive,
31856
+ pressed
31857
+ }).map((cell) => {
31858
+ const col = cell.column;
31565
31859
  const domProps = {
31566
- style: style2,
31567
- //@ts-ignore
31568
- "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31569
- "data-menu-col-name": `${col.name}`,
31570
- "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31571
- "data-menu-row-index": `${index}`,
31572
- "data-menu-item-key": `${item.key}`,
31573
- className: join(
31574
- MenuItemCls({
31575
- active,
31576
- disabled: !!item.disabled,
31577
- keyboardActive,
31578
- pressed: pressed || props.active
31579
- }),
31580
- item.className
31581
- ),
31860
+ style: cell.style,
31861
+ ...cell.dataAttributes,
31862
+ className: cell.className,
31582
31863
  onPointerEnter: (event) => {
31583
31864
  if (!item.disabled) {
31584
31865
  props.onItemEnter?.(item, event);
@@ -31608,17 +31889,17 @@ function RuntimeItemRenderer(props) {
31608
31889
  return col.render ? /* @__PURE__ */ React61.createElement(
31609
31890
  RenderHookComponent,
31610
31891
  {
31611
- key: `${key}-${field}`,
31892
+ key: cell.key,
31612
31893
  render: col.render,
31613
31894
  renderParam: {
31614
- item: target,
31895
+ item: item.value,
31615
31896
  column: col,
31616
- value: target[field],
31897
+ value: cell.value,
31617
31898
  domProps
31618
31899
  }
31619
31900
  }
31620
- ) : /* @__PURE__ */ React61.createElement("div", { key: `${key}-${field}`, ...domProps }, target[field]);
31621
- }).filter(Boolean);
31901
+ ) : /* @__PURE__ */ React61.createElement("div", { key: cell.key, ...domProps }, cell.value);
31902
+ });
31622
31903
  }
31623
31904
  return /* @__PURE__ */ React61.createElement("div", { className: MenuRowCls }, content);
31624
31905
  }
@@ -31683,9 +31964,64 @@ Menu[propToIdentifyMenu] = true;
31683
31964
 
31684
31965
  // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
31685
31966
  import * as React63 from "react";
31686
- function defaultGetColumnMenuItems(_items, params) {
31687
- const { columnApi, column, getComputed, api, dataSourceApi, getState } = params;
31688
- const CheckBoxCmp = getState().components?.CheckBox || InfiniteCheckBox;
31967
+
31968
+ // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
31969
+ function getMenuItemsAndColumns(menuDefinition) {
31970
+ let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
31971
+ const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
31972
+ return {
31973
+ items,
31974
+ columns
31975
+ };
31976
+ }
31977
+ function getMenuVisibilityProps(onHideIntent) {
31978
+ const onRootMouseDown = (event) => {
31979
+ event.__insideMenu = true;
31980
+ };
31981
+ const onHide = (state) => {
31982
+ state.domRef.current?.parentNode?.removeEventListener(
31983
+ "mousedown",
31984
+ onRootMouseDown
31985
+ );
31986
+ };
31987
+ return {
31988
+ onShow: (state) => {
31989
+ state.domRef.current?.parentNode?.addEventListener(
31990
+ "mousedown",
31991
+ onRootMouseDown
31992
+ );
31993
+ },
31994
+ onHide,
31995
+ onHideIntent: (state) => {
31996
+ onHide(state);
31997
+ onHideIntent?.();
31998
+ }
31999
+ };
32000
+ }
32001
+ function getMenuDefaultProps(config) {
32002
+ const menuDefaultProps = {
32003
+ columns: [],
32004
+ items: [],
32005
+ autoFocus: true,
32006
+ ...getMenuVisibilityProps(config.onHideIntent)
32007
+ };
32008
+ return menuDefaultProps;
32009
+ }
32010
+ function getLazyMenuProps(menuDefinition, menuDefaultProps) {
32011
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32012
+ if (items && items.length) {
32013
+ return {
32014
+ ...menuDefaultProps,
32015
+ items: items || [],
32016
+ columns
32017
+ };
32018
+ }
32019
+ return null;
32020
+ }
32021
+
32022
+ // src/components/InfiniteTable/utils/menuItemsShared.ts
32023
+ function getDefaultColumnMenuItems(params, binder) {
32024
+ const { columnApi, column, getComputed, api, dataSourceApi } = params;
31689
32025
  const sortable = columnApi.isSortable();
31690
32026
  const sortItems = sortable ? [
31691
32027
  {
@@ -31766,25 +32102,22 @@ function defaultGetColumnMenuItems(_items, params) {
31766
32102
  const colItems = [];
31767
32103
  const computed = getComputed();
31768
32104
  computed.computedColumnsMapInInitialOrder.forEach((col, id) => {
31769
- const label = getColumnLabel(col, params, "column-menu");
32105
+ const label = binder.getColumnLabel(col);
31770
32106
  colItems.push({
31771
32107
  key: id,
31772
32108
  label,
31773
- check: /* @__PURE__ */ React63.createElement(
31774
- CheckBoxCmp,
31775
- {
31776
- key: col.id,
31777
- disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
31778
- checked: col.computedVisible,
31779
- onChange: (checked) => {
31780
- const visible = !!checked;
31781
- api.setVisibilityForColumn(col.id, visible);
31782
- requestAnimationFrame(() => {
31783
- api.realignColumnContextMenu();
31784
- });
31785
- }
32109
+ check: binder.renderCheckBox({
32110
+ key: col.id,
32111
+ disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
32112
+ checked: col.computedVisible,
32113
+ onChange: (checked) => {
32114
+ const visible = !!checked;
32115
+ api.setVisibilityForColumn(col.id, visible);
32116
+ requestAnimationFrame(() => {
32117
+ api.realignColumnContextMenu();
32118
+ });
31786
32119
  }
31787
- )
32120
+ })
31788
32121
  });
31789
32122
  });
31790
32123
  return {
@@ -31809,21 +32142,18 @@ function defaultGetColumnMenuItems(_items, params) {
31809
32142
  if (col.groupByForColumn) {
31810
32143
  return;
31811
32144
  }
31812
- const label = getColumnLabel(col, params, "column-menu");
32145
+ const label = binder.getColumnLabel(col);
31813
32146
  colItems.push({
31814
32147
  key: id,
31815
32148
  label,
31816
- check: /* @__PURE__ */ React63.createElement(
31817
- CheckBoxCmp,
31818
- {
31819
- key: col.id,
31820
- disabled: !col.computedGroupable,
31821
- checked: col.computedGroupedBy,
31822
- onChange: () => {
31823
- dataSourceApi.toggleGroupByField(col.field);
31824
- }
32149
+ check: binder.renderCheckBox({
32150
+ key: col.id,
32151
+ disabled: !col.computedGroupable,
32152
+ checked: col.computedGroupedBy,
32153
+ onChange: () => {
32154
+ dataSourceApi.toggleGroupByField(col.field);
31825
32155
  }
31826
- )
32156
+ })
31827
32157
  });
31828
32158
  });
31829
32159
  return {
@@ -31839,15 +32169,12 @@ function defaultGetColumnMenuItems(_items, params) {
31839
32169
  }
31840
32170
  ].filter((x) => !!x);
31841
32171
  }
31842
-
31843
- // src/components/InfiniteTable/utils/getMenuForColumn.tsx
31844
- function getMenuForColumn(columnId, context, onHideIntent) {
32172
+ function getColumnMenuProps(columnId, context, onHideIntent, getDefaultItems) {
31845
32173
  if (columnId == null) {
31846
32174
  return null;
31847
32175
  }
31848
32176
  const { getComputed, getState } = context;
31849
- const { components: components2, getColumnMenuItems } = getState();
31850
- const MenuCmp = components2?.Menu ?? Menu;
32177
+ const { getColumnMenuItems } = getState();
31851
32178
  const column = getComputed().computedColumnsMap.get(columnId);
31852
32179
  if (!column) {
31853
32180
  return null;
@@ -31857,38 +32184,192 @@ function getMenuForColumn(columnId, context, onHideIntent) {
31857
32184
  columnApi: getColumnApiForColumn(column.id, context),
31858
32185
  ...context
31859
32186
  };
31860
- const defaultItems = defaultGetColumnMenuItems([], param);
32187
+ const defaultItems = getDefaultItems(param);
31861
32188
  const items = getColumnMenuItems ? getColumnMenuItems(defaultItems, param) : defaultItems;
31862
- const onRootMouseDown = (event) => {
31863
- event.__insideMenu = true;
31864
- };
31865
- const onHide = (state) => {
31866
- state.domRef.current?.parentNode?.removeEventListener(
31867
- "mousedown",
31868
- onRootMouseDown
31869
- );
31870
- };
31871
32189
  if (!items || !items.length) {
31872
32190
  return null;
31873
32191
  }
31874
- return /* @__PURE__ */ React64.createElement(
31875
- MenuCmp,
31876
- {
31877
- autoFocus: true,
31878
- items,
31879
- onShow: (state) => {
31880
- state.domRef.current?.parentNode?.addEventListener(
31881
- "mousedown",
31882
- onRootMouseDown
31883
- );
32192
+ return {
32193
+ autoFocus: true,
32194
+ items,
32195
+ ...getMenuVisibilityProps(onHideIntent)
32196
+ };
32197
+ }
32198
+ function getFilterOperatorMenuProps(columnId, context, onHideIntent, binder) {
32199
+ if (columnId == null) {
32200
+ return null;
32201
+ }
32202
+ const {
32203
+ getComputed,
32204
+ getState,
32205
+ getDataSourceState,
32206
+ actions,
32207
+ dataSourceApi,
32208
+ dataSourceActions,
32209
+ api
32210
+ } = context;
32211
+ const { getFilterOperatorMenuItems } = getState();
32212
+ const column = getComputed().computedColumnsMap.get(columnId);
32213
+ if (!column) {
32214
+ return null;
32215
+ }
32216
+ const { filterTypes } = getDataSourceState();
32217
+ const columnFilterType = filterTypes[column.computedFilterType];
32218
+ if (!columnFilterType) {
32219
+ return null;
32220
+ }
32221
+ const operatorItems = columnFilterType.operators.map((operator) => {
32222
+ const key = operator.name;
32223
+ const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32224
+ return {
32225
+ key,
32226
+ icon: binder.renderOperatorIcon(operator),
32227
+ label: binder.renderOperatorLabel(operator.label ?? operator.name),
32228
+ onAction: () => {
32229
+ api.setColumnFilterOperator(columnId, key);
31884
32230
  },
31885
- onHide,
31886
- onHideIntent: (state) => {
31887
- onHide(state);
31888
- onHideIntent?.();
32231
+ checked: checked ? binder.renderDoneIcon() : null
32232
+ };
32233
+ });
32234
+ const firstItems = [
32235
+ {
32236
+ key: "close",
32237
+ label: "Close Menu",
32238
+ icon: null,
32239
+ onAction: () => {
32240
+ api.hideFilterOperatorMenu();
31889
32241
  }
31890
- }
32242
+ },
32243
+ {
32244
+ key: "reset",
32245
+ label: "Reset",
32246
+ icon: binder.renderClearIcon(),
32247
+ disabled: !column.computedFiltered,
32248
+ onAction: () => {
32249
+ api.clearColumnFilter(columnId);
32250
+ }
32251
+ },
32252
+ "-"
32253
+ ];
32254
+ const defaultItems = [...firstItems, ...operatorItems];
32255
+ const param = {
32256
+ column,
32257
+ api,
32258
+ getState,
32259
+ getDataSourceState,
32260
+ getComputed,
32261
+ actions,
32262
+ dataSourceApi,
32263
+ dataSourceActions,
32264
+ columnFilterValue: column.computedFilterValue,
32265
+ filterTypes
32266
+ };
32267
+ const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32268
+ return {
32269
+ autoFocus: true,
32270
+ columns: [
32271
+ {
32272
+ name: "icon"
32273
+ },
32274
+ { name: "label" },
32275
+ { name: "checked" }
32276
+ ],
32277
+ items,
32278
+ ...getMenuVisibilityProps(onHideIntent)
32279
+ };
32280
+ }
32281
+ function getContextMenuContent(menuDefinition, menuDefaultProps, binder) {
32282
+ const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32283
+ if (menuDefinition instanceof Promise) {
32284
+ return {
32285
+ menu: binder.renderLazyMenu(menuDefinition, menuDefaultProps),
32286
+ preventDefault
32287
+ };
32288
+ }
32289
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32290
+ if (!items || !items.length) {
32291
+ return { menu: null, preventDefault: Array.isArray(items) };
32292
+ }
32293
+ return {
32294
+ preventDefault,
32295
+ menu: binder.renderMenu({ ...menuDefaultProps, columns, items })
32296
+ };
32297
+ }
32298
+ function getCellContextMenuContent(cellLocation, context, onHideIntent, binder) {
32299
+ const { columnId, rowIndex, event } = cellLocation;
32300
+ const { getComputed, getState } = context;
32301
+ const { getCellContextMenuItems } = getState();
32302
+ const { computedColumnsMap } = getComputed();
32303
+ const column = computedColumnsMap.get(columnId);
32304
+ const cellContext = {
32305
+ ...getCellContext({
32306
+ ...context,
32307
+ rowIndex,
32308
+ columnId: column.id
32309
+ }),
32310
+ event
32311
+ };
32312
+ if (!column || !getCellContextMenuItems) {
32313
+ return {
32314
+ cellContext,
32315
+ menu: null,
32316
+ preventDefault: false
32317
+ };
32318
+ }
32319
+ const menuDefaultProps = getMenuDefaultProps({
32320
+ onHideIntent
32321
+ });
32322
+ const menuDefinition = getCellContextMenuItems(cellContext, context);
32323
+ return {
32324
+ cellContext,
32325
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32326
+ };
32327
+ }
32328
+ function getTableContextMenuContent(menuLocation, context, onHideIntent, binder) {
32329
+ const { getState, getComputed } = context;
32330
+ const { getContextMenuItems } = getState();
32331
+ const { computedColumnsMap } = getComputed();
32332
+ const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32333
+ const cellContext = column ? {
32334
+ ...menuLocation,
32335
+ ...getCellContext({
32336
+ ...context,
32337
+ rowIndex: menuLocation.rowIndex,
32338
+ columnId: column.id
32339
+ })
32340
+ } : menuLocation;
32341
+ if (!getContextMenuItems) {
32342
+ return { cellContext, menu: null, preventDefault: false };
32343
+ }
32344
+ const menuDefaultProps = getMenuDefaultProps({
32345
+ onHideIntent
32346
+ });
32347
+ const menuDefinition = getContextMenuItems(cellContext, context);
32348
+ return {
32349
+ cellContext,
32350
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32351
+ };
32352
+ }
32353
+
32354
+ // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
32355
+ function defaultGetColumnMenuItems(_items, params) {
32356
+ const CheckBoxCmp = params.getState().components?.CheckBox || InfiniteCheckBox;
32357
+ return getDefaultColumnMenuItems(params, {
32358
+ renderCheckBox: ({ key, ...props }) => /* @__PURE__ */ React63.createElement(CheckBoxCmp, { key, ...props }),
32359
+ getColumnLabel: (col) => getColumnLabel(col, params, "column-menu")
32360
+ });
32361
+ }
32362
+
32363
+ // src/components/InfiniteTable/utils/getMenuForColumn.tsx
32364
+ function getMenuForColumn(columnId, context, onHideIntent) {
32365
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32366
+ const menuProps = getColumnMenuProps(
32367
+ columnId,
32368
+ context,
32369
+ onHideIntent,
32370
+ (param) => defaultGetColumnMenuItems([], param)
31891
32371
  );
32372
+ return menuProps ? /* @__PURE__ */ React64.createElement(MenuCmp, { ...menuProps }) : null;
31892
32373
  }
31893
32374
 
31894
32375
  // src/components/InfiniteTable/utils/menuOverlayTargets.ts
@@ -31905,31 +32386,55 @@ function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer)
31905
32386
  return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
31906
32387
  }
31907
32388
 
31908
- // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
31909
- import { useMemo as useMemo19 } from "react";
31910
- function useMenuPortalContainer() {
31911
- const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
31912
- return {
31913
- getState: ctx.getState,
31914
- menuPortalContainer: ctx.state.menuPortalContainer
31915
- };
31916
- });
31917
- const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
31918
- return {
31919
- portalDOMRef: ctx.getMasterState().portalDOMRef
31920
- };
31921
- }) || {};
31922
- const defaultContainer = portalDOMRef?.current;
31923
- return useMemo19(
31924
- () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
31925
- [getState, menuPortalContainer, defaultContainer]
31926
- );
32389
+ // src/components/InfiniteTable/utils/menuOverlayShared.ts
32390
+ var CONTEXT_MENU_OFFSET = 5;
32391
+ var CONTEXT_MENU_ALIGN_POSITIONS = [
32392
+ ["TopLeft", "BottomLeft"],
32393
+ ["TopRight", "BottomRight"],
32394
+ ["BottomLeft", "BottomLeft"],
32395
+ ["BottomRight", "BottomRight"],
32396
+ ["TopCenter", "TopLeft"],
32397
+ ["BottomCenter", "TopLeft"],
32398
+ ["CenterLeft", "TopLeft"],
32399
+ ["CenterRight", "TopLeft"]
32400
+ ];
32401
+ var FILTER_OPERATOR_MENU_OFFSET = 10;
32402
+ function closeMenuOnOutsideMouseDown(close) {
32403
+ function handleMouseDown(event) {
32404
+ if (event.__insideMenu !== true) {
32405
+ close();
32406
+ }
32407
+ }
32408
+ document.documentElement.addEventListener("mousedown", handleMouseDown);
32409
+ return () => {
32410
+ document.documentElement.removeEventListener("mousedown", handleMouseDown);
32411
+ };
32412
+ }
32413
+ function menuVisibilityEffect(visible, clearAll, hide) {
32414
+ if (visible) {
32415
+ return closeMenuOnOutsideMouseDown(() => {
32416
+ clearAll();
32417
+ hide();
32418
+ });
32419
+ }
32420
+ clearAll();
32421
+ return void 0;
32422
+ }
32423
+ function getColumnMenuClickHandler(context) {
32424
+ const { getState, actions } = context;
32425
+ return (info) => {
32426
+ if (!info) {
32427
+ return;
32428
+ }
32429
+ getState().columnMenuTargetRef.current = info.target;
32430
+ actions.contextMenuVisibleFor = null;
32431
+ actions.cellContextMenuVisibleFor = null;
32432
+ actions.filterOperatorMenuVisibleForColumnId = null;
32433
+ actions.columnMenuVisibleForColumnId = info.column.id;
32434
+ };
31927
32435
  }
31928
-
31929
- // src/components/InfiniteTable/hooks/useColumnMenu.ts
31930
- var menuIconSelector2 = `[${MenuIconDataAttributes["data-name"]}="${MenuIconDataAttributesValues["data-name"]}"]`;
31931
32436
  function showMenuForColumn(options) {
31932
- const { columnId, context, clearAll, showOverlay } = options;
32437
+ const { columnId, context, clearAll, show } = options;
31933
32438
  const { getState, actions } = context;
31934
32439
  const { columnMenuTargetRef, domRef } = getState();
31935
32440
  function onHideIntent() {
@@ -31944,7 +32449,7 @@ function showMenuForColumn(options) {
31944
32449
  }
31945
32450
  }
31946
32451
  if (!target) {
31947
- const iconSelector = `[${InfiniteHeaderCellDataAttributes["data-column-id"]}="${columnId}"] ${menuIconSelector2}`;
32452
+ const iconSelector = `[data-column-id="${columnId}"] ${menuIconSelector}`;
31948
32453
  target = getState().domRef.current.querySelector(
31949
32454
  iconSelector
31950
32455
  );
@@ -31954,7 +32459,7 @@ function showMenuForColumn(options) {
31954
32459
  return;
31955
32460
  }
31956
32461
  columnMenuTargetRef.current = null;
31957
- showOverlay(() => getMenuForColumn(columnId, context, onHideIntent), {
32462
+ show(onHideIntent, {
31958
32463
  constrainTo: getMenuConstrainTo(getState()),
31959
32464
  id: "column-menu",
31960
32465
  alignTo: target,
@@ -31964,17 +32469,180 @@ function showMenuForColumn(options) {
31964
32469
  ]
31965
32470
  });
31966
32471
  }
32472
+ function columnMenuVisibilityEffect(context, overlay) {
32473
+ const { getState, actions } = context;
32474
+ const { clearAll } = overlay;
32475
+ const { columnMenuVisibleForColumnId, columnMenuTargetRef } = getState();
32476
+ if (columnMenuVisibleForColumnId) {
32477
+ const cleanup = closeMenuOnOutsideMouseDown(() => {
32478
+ clearAll();
32479
+ actions.columnMenuVisibleForColumnId = null;
32480
+ });
32481
+ showMenuForColumn({
32482
+ columnId: columnMenuVisibleForColumnId,
32483
+ context,
32484
+ clearAll,
32485
+ show: (onHideIntent, params) => overlay.show(columnMenuVisibleForColumnId, onHideIntent, params)
32486
+ });
32487
+ return cleanup;
32488
+ }
32489
+ columnMenuTargetRef.current = null;
32490
+ clearAll();
32491
+ return void 0;
32492
+ }
32493
+ function getContextMenuRect(event) {
32494
+ const point = {
32495
+ top: event.clientY,
32496
+ left: event.clientX
32497
+ };
32498
+ const rect = Rectangle.fromPoint(point);
32499
+ rect.width += CONTEXT_MENU_OFFSET;
32500
+ rect.height += CONTEXT_MENU_OFFSET;
32501
+ return { point, rect };
32502
+ }
32503
+ function getCellContextMenuHandler(context, overlay) {
32504
+ const { actions, getState, getDataSourceState } = context;
32505
+ const { clearAll } = overlay;
32506
+ return (info) => {
32507
+ if (!info) {
32508
+ return;
32509
+ }
32510
+ const { event } = info;
32511
+ function onHideIntent() {
32512
+ clearAll();
32513
+ actions.cellContextMenuVisibleFor = null;
32514
+ }
32515
+ const content = overlay.getContent(info, onHideIntent);
32516
+ const { cellContext, preventDefault } = content;
32517
+ const { rect } = getContextMenuRect(event);
32518
+ overlay.show(content, {
32519
+ constrainTo: getMenuConstrainTo(getState()),
32520
+ id: "cell-context-menu",
32521
+ alignTo: rect,
32522
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32523
+ });
32524
+ if (preventDefault) {
32525
+ event.preventDefault();
32526
+ }
32527
+ actions.cellContextMenuVisibleFor = {
32528
+ columnId: info.columnId,
32529
+ rowId: info.rowId,
32530
+ rowIndex: info.rowIndex,
32531
+ colIndex: info.colIndex
32532
+ };
32533
+ const { onCellContextMenu } = getState();
32534
+ if (onCellContextMenu) {
32535
+ onCellContextMenu(
32536
+ {
32537
+ ...cellContext,
32538
+ getState,
32539
+ getDataSourceState
32540
+ },
32541
+ event
32542
+ );
32543
+ }
32544
+ };
32545
+ }
32546
+ function getTableContextMenuHandler(context, overlay) {
32547
+ const { actions, getState } = context;
32548
+ const { clearAll } = overlay;
32549
+ return (info) => {
32550
+ if (!info) {
32551
+ return;
32552
+ }
32553
+ const { event } = info;
32554
+ function onHideIntent() {
32555
+ clearAll();
32556
+ actions.contextMenuVisibleFor = null;
32557
+ }
32558
+ const content = overlay.getContent(info, onHideIntent);
32559
+ const { cellContext, preventDefault } = content;
32560
+ const { point, rect } = getContextMenuRect(event);
32561
+ overlay.show(content, {
32562
+ constrainTo: getMenuConstrainTo(getState()),
32563
+ id: "table-context-menu",
32564
+ alignTo: rect,
32565
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32566
+ });
32567
+ if (preventDefault) {
32568
+ event.preventDefault();
32569
+ }
32570
+ actions.contextMenuVisibleFor = {
32571
+ point,
32572
+ ...info
32573
+ };
32574
+ const { onContextMenu } = getState();
32575
+ if (onContextMenu) {
32576
+ onContextMenu(
32577
+ {
32578
+ ...context,
32579
+ ...cellContext
32580
+ },
32581
+ event
32582
+ );
32583
+ }
32584
+ };
32585
+ }
32586
+ function getFilterOperatorMenuClickHandler(context, overlay) {
32587
+ const { getState, actions } = context;
32588
+ const { clearAll } = overlay;
32589
+ return (info) => {
32590
+ if (!info) {
32591
+ return;
32592
+ }
32593
+ const { target, column } = info;
32594
+ function onHideIntent() {
32595
+ clearAll();
32596
+ actions.filterOperatorMenuVisibleForColumnId = null;
32597
+ }
32598
+ const alignTo = target?.parentElement || target;
32599
+ const rect = Rectangle.from(alignTo.getBoundingClientRect());
32600
+ rect.top -= FILTER_OPERATOR_MENU_OFFSET;
32601
+ rect.left -= FILTER_OPERATOR_MENU_OFFSET;
32602
+ rect.width += 2 * FILTER_OPERATOR_MENU_OFFSET;
32603
+ rect.height += 2 * FILTER_OPERATOR_MENU_OFFSET;
32604
+ overlay.show(column.id, onHideIntent, {
32605
+ constrainTo: getMenuConstrainTo(getState()),
32606
+ id: "filter-operator-menu",
32607
+ alignTo: rect,
32608
+ alignPosition: [
32609
+ ["TopLeft", "BottomLeft"],
32610
+ ["TopRight", "BottomRight"]
32611
+ ]
32612
+ });
32613
+ actions.contextMenuVisibleFor = null;
32614
+ actions.cellContextMenuVisibleFor = null;
32615
+ actions.columnMenuVisibleForColumnId = null;
32616
+ actions.filterOperatorMenuVisibleForColumnId = column.id;
32617
+ };
32618
+ }
32619
+
32620
+ // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
32621
+ import { useMemo as useMemo19 } from "react";
32622
+ function useMenuPortalContainer() {
32623
+ const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
32624
+ return {
32625
+ getState: ctx.getState,
32626
+ menuPortalContainer: ctx.state.menuPortalContainer
32627
+ };
32628
+ });
32629
+ const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
32630
+ return {
32631
+ portalDOMRef: ctx.getMasterState().portalDOMRef
32632
+ };
32633
+ }) || {};
32634
+ const defaultContainer = portalDOMRef?.current;
32635
+ return useMemo19(
32636
+ () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
32637
+ [getState, menuPortalContainer, defaultContainer]
32638
+ );
32639
+ }
32640
+
32641
+ // src/components/InfiniteTable/hooks/useColumnMenu.ts
31967
32642
  function useColumnMenu() {
31968
32643
  const context = useInfiniteTableStableContext();
31969
- const {
31970
- getState,
31971
- actions,
31972
- columnMenuVisibleForColumnId,
31973
- columnMenuVisibleKey
31974
- } = useInfiniteTableSelector((ctx) => {
32644
+ const { columnMenuVisibleForColumnId, columnMenuVisibleKey } = useInfiniteTableSelector((ctx) => {
31975
32645
  return {
31976
- getState: ctx.getState,
31977
- actions: ctx.actions,
31978
32646
  columnMenuVisibleForColumnId: ctx.state.columnMenuVisibleForColumnId,
31979
32647
  columnMenuVisibleKey: ctx.state.columnMenuVisibleKey
31980
32648
  };
@@ -31987,47 +32655,16 @@ function useColumnMenu() {
31987
32655
  portalContainer: useMenuPortalContainer()
31988
32656
  });
31989
32657
  useEffect32(() => {
31990
- const state = getState();
31991
- return state.onColumnMenuClick.onChange((info) => {
31992
- if (!info) {
31993
- return;
31994
- }
31995
- state.columnMenuTargetRef.current = info.target;
31996
- actions.contextMenuVisibleFor = null;
31997
- actions.cellContextMenuVisibleFor = null;
31998
- actions.filterOperatorMenuVisibleForColumnId = null;
31999
- actions.columnMenuVisibleForColumnId = info.column.id;
32000
- });
32658
+ return context.getState().onColumnMenuClick.onChange(getColumnMenuClickHandler(context));
32001
32659
  }, []);
32002
32660
  useEffect32(() => {
32003
- const { columnMenuVisibleForColumnId: columnMenuVisibleForColumnId2, columnMenuTargetRef } = getState();
32004
- if (columnMenuVisibleForColumnId2) {
32005
- let handleMouseDown2 = function(event) {
32006
- if (event.__insideMenu !== true) {
32007
- clearAll();
32008
- actions.columnMenuVisibleForColumnId = null;
32009
- }
32010
- };
32011
- var handleMouseDown = handleMouseDown2;
32012
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32013
- showMenuForColumn({
32014
- columnId: columnMenuVisibleForColumnId2,
32015
- context,
32016
- clearAll,
32017
- showOverlay
32018
- });
32019
- return () => {
32020
- document.documentElement.removeEventListener(
32021
- "mousedown",
32022
- handleMouseDown2
32023
- );
32024
- };
32025
- } else {
32026
- columnMenuTargetRef.current = null;
32027
- clearAll();
32028
- }
32029
- return () => {
32030
- };
32661
+ return columnMenuVisibilityEffect(context, {
32662
+ clearAll,
32663
+ show: (columnId, onHideIntent, params) => showOverlay(
32664
+ () => getMenuForColumn(columnId, context, onHideIntent),
32665
+ params
32666
+ )
32667
+ });
32031
32668
  }, [columnMenuVisibleForColumnId, columnMenuVisibleKey]);
32032
32669
  return { menuPortal };
32033
32670
  }
@@ -32210,149 +32847,59 @@ function useOnEditPersisted() {
32210
32847
  };
32211
32848
  if (persisted instanceof Error) {
32212
32849
  onEditPersistError?.({ ...params, error: persisted });
32213
- } else {
32214
- onEditPersistSuccess?.(params);
32215
- }
32216
- }
32217
- }, [persisted]);
32218
- }
32219
- function useEditingCallbackProps() {
32220
- useOnEditCancelled();
32221
- useOnEditRejected();
32222
- useOnEditAccepted();
32223
- useOnEditPersisted();
32224
- useFocusOnEditStop();
32225
- }
32226
-
32227
- // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32228
- import { useEffect as useEffect34 } from "react";
32229
-
32230
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32231
- import * as React68 from "react";
32232
-
32233
- // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32234
- import * as React66 from "react";
32235
- var ClearIcon = (props) => {
32236
- return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32237
- };
32238
-
32239
- // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32240
- import * as React67 from "react";
32241
- var DoneIcon = (props) => {
32242
- return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32243
- };
32244
-
32245
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32246
- function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32247
- if (columnId == null) {
32248
- return null;
32249
- }
32250
- const {
32251
- getComputed,
32252
- getState,
32253
- getDataSourceState,
32254
- actions,
32255
- dataSourceApi,
32256
- dataSourceActions,
32257
- api
32258
- } = context;
32259
- const { components: components2, getFilterOperatorMenuItems } = getState();
32260
- const MenuCmp = components2?.Menu ?? Menu;
32261
- const column = getComputed().computedColumnsMap.get(columnId);
32262
- if (!column) {
32263
- return null;
32264
- }
32265
- const onRootMouseDown = (event) => {
32266
- event.__insideMenu = true;
32267
- };
32268
- const onHide = (state) => {
32269
- state.domRef.current?.parentNode?.removeEventListener(
32270
- "mousedown",
32271
- onRootMouseDown
32272
- );
32273
- };
32274
- const { filterTypes } = getDataSourceState();
32275
- const columnFilterType = filterTypes[column.computedFilterType];
32276
- if (!columnFilterType) {
32277
- return null;
32278
- }
32279
- const operatorItems = columnFilterType.operators.map((operator) => {
32280
- const key = operator.name;
32281
- const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32282
- const IconCmp = operator.components?.Icon ?? FilterIcon;
32283
- return {
32284
- key,
32285
- icon: /* @__PURE__ */ React68.createElement(IconCmp, null),
32286
- label: /* @__PURE__ */ React68.createElement(React68.Fragment, null, operator.label ?? operator.name),
32287
- onAction: () => {
32288
- api.setColumnFilterOperator(columnId, key);
32289
- },
32290
- checked: checked ? /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 }) : null
32291
- };
32292
- });
32293
- const firstItems = [
32294
- {
32295
- key: "close",
32296
- label: "Close Menu",
32297
- icon: null,
32298
- onAction: () => {
32299
- api.hideFilterOperatorMenu();
32300
- }
32301
- },
32302
- {
32303
- key: "reset",
32304
- label: "Reset",
32305
- icon: /* @__PURE__ */ React68.createElement(ClearIcon, null),
32306
- disabled: !column.computedFiltered,
32307
- onAction: () => {
32308
- api.clearColumnFilter(columnId);
32309
- }
32310
- },
32311
- "-"
32312
- ];
32313
- const defaultItems = [...firstItems, ...operatorItems];
32314
- const param = {
32315
- column,
32316
- api,
32317
- getState,
32318
- getDataSourceState,
32319
- getComputed,
32320
- actions,
32321
- dataSourceApi,
32322
- dataSourceActions,
32323
- columnFilterValue: column.computedFilterValue,
32324
- filterTypes
32325
- };
32326
- const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32327
- return /* @__PURE__ */ React68.createElement(
32328
- MenuCmp,
32850
+ } else {
32851
+ onEditPersistSuccess?.(params);
32852
+ }
32853
+ }
32854
+ }, [persisted]);
32855
+ }
32856
+ function useEditingCallbackProps() {
32857
+ useOnEditCancelled();
32858
+ useOnEditRejected();
32859
+ useOnEditAccepted();
32860
+ useOnEditPersisted();
32861
+ useFocusOnEditStop();
32862
+ }
32863
+
32864
+ // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32865
+ import { useEffect as useEffect34 } from "react";
32866
+
32867
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32868
+ import * as React68 from "react";
32869
+
32870
+ // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32871
+ import * as React66 from "react";
32872
+ var ClearIcon = (props) => {
32873
+ return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32874
+ };
32875
+
32876
+ // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32877
+ import * as React67 from "react";
32878
+ var DoneIcon = (props) => {
32879
+ return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32880
+ };
32881
+
32882
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32883
+ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32884
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32885
+ const menuProps = getFilterOperatorMenuProps(
32886
+ columnId,
32887
+ context,
32888
+ onHideIntent,
32329
32889
  {
32330
- autoFocus: true,
32331
- columns: [
32332
- {
32333
- name: "icon"
32334
- },
32335
- { name: "label" },
32336
- { name: "checked" }
32337
- ],
32338
- items,
32339
- onShow: (state) => {
32340
- state.domRef.current?.parentNode?.addEventListener(
32341
- "mousedown",
32342
- onRootMouseDown
32343
- );
32890
+ renderOperatorIcon: (operator) => {
32891
+ const IconCmp = operator.components?.Icon ?? FilterIcon;
32892
+ return /* @__PURE__ */ React68.createElement(IconCmp, null);
32344
32893
  },
32345
- onHide,
32346
- onHideIntent: (state) => {
32347
- onHide(state);
32348
- onHideIntent?.();
32349
- }
32894
+ renderOperatorLabel: (label) => /* @__PURE__ */ React68.createElement(React68.Fragment, null, label),
32895
+ renderClearIcon: () => /* @__PURE__ */ React68.createElement(ClearIcon, null),
32896
+ renderDoneIcon: () => /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 })
32350
32897
  }
32351
32898
  );
32899
+ return menuProps ? /* @__PURE__ */ React68.createElement(MenuCmp, { ...menuProps }) : null;
32352
32900
  }
32353
32901
 
32354
32902
  // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32355
- var OFFSET2 = 10;
32356
32903
  function useColumnFilterOperatorMenu() {
32357
32904
  const stableContext = useInfiniteTableStableContext();
32358
32905
  const { getState, actions } = stableContext;
@@ -32364,66 +32911,28 @@ function useColumnFilterOperatorMenu() {
32364
32911
  portalContainer: useMenuPortalContainer()
32365
32912
  });
32366
32913
  useEffect34(() => {
32367
- const state = getState();
32368
- return state.onFilterOperatorMenuClick.onChange((info) => {
32369
- if (!info) {
32370
- return;
32371
- }
32372
- const { target, column } = info;
32373
- function onHideIntent() {
32374
- clearAll();
32375
- actions.filterOperatorMenuVisibleForColumnId = null;
32376
- }
32377
- let alignTo = target?.parentElement || target;
32378
- const rect = Rectangle.from(alignTo.getBoundingClientRect());
32379
- rect.top -= OFFSET2;
32380
- rect.left -= OFFSET2;
32381
- rect.width += 2 * OFFSET2;
32382
- rect.height += 2 * OFFSET2;
32383
- showOverlay(
32384
- () => getFilterOperatorMenuForColumn(
32385
- column.id,
32386
- stableContext,
32387
- onHideIntent
32388
- ),
32389
- {
32390
- constrainTo: getMenuConstrainTo(getState()),
32391
- id: "filter-operator-menu",
32392
- alignTo: rect,
32393
- alignPosition: [
32394
- ["TopLeft", "BottomLeft"],
32395
- ["TopRight", "BottomRight"]
32396
- ]
32397
- }
32398
- );
32399
- actions.contextMenuVisibleFor = null;
32400
- actions.cellContextMenuVisibleFor = null;
32401
- actions.columnMenuVisibleForColumnId = null;
32402
- actions.filterOperatorMenuVisibleForColumnId = column.id;
32403
- });
32914
+ return getState().onFilterOperatorMenuClick.onChange(
32915
+ getFilterOperatorMenuClickHandler(stableContext, {
32916
+ clearAll,
32917
+ show: (columnId, onHideIntent, params) => showOverlay(
32918
+ () => getFilterOperatorMenuForColumn(
32919
+ columnId,
32920
+ stableContext,
32921
+ onHideIntent
32922
+ ),
32923
+ params
32924
+ )
32925
+ })
32926
+ );
32404
32927
  }, []);
32405
32928
  useEffect34(() => {
32406
- const { filterOperatorMenuVisibleForColumnId } = getState();
32407
- if (filterOperatorMenuVisibleForColumnId) {
32408
- let handleMouseDown2 = function(event) {
32409
- if (event.__insideMenu !== true) {
32410
- clearAll();
32411
- actions.filterOperatorMenuVisibleForColumnId = null;
32412
- }
32413
- };
32414
- var handleMouseDown = handleMouseDown2;
32415
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32416
- return () => {
32417
- document.documentElement.removeEventListener(
32418
- "mousedown",
32419
- handleMouseDown2
32420
- );
32421
- };
32422
- } else {
32423
- clearAll();
32424
- }
32425
- return () => {
32426
- };
32929
+ return menuVisibilityEffect(
32930
+ getState().filterOperatorMenuVisibleForColumnId,
32931
+ clearAll,
32932
+ () => {
32933
+ actions.filterOperatorMenuVisibleForColumnId = null;
32934
+ }
32935
+ );
32427
32936
  }, [getState().filterOperatorMenuVisibleForColumnId]);
32428
32937
  return { menuPortal };
32429
32938
  }
@@ -32436,159 +32945,46 @@ import * as React70 from "react";
32436
32945
 
32437
32946
  // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32438
32947
  import * as React69 from "react";
32439
-
32440
- // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
32441
- function getMenuItemsAndColumns(menuDefinition) {
32442
- let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
32443
- const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
32444
- return {
32445
- items,
32446
- columns
32447
- };
32448
- }
32449
- function getMenuDefaultProps(config) {
32450
- const onRootMouseDown = (event) => {
32451
- event.__insideMenu = true;
32452
- };
32453
- const onHide = (state) => {
32454
- state.domRef.current?.parentNode?.removeEventListener(
32455
- "mousedown",
32456
- onRootMouseDown
32457
- );
32458
- };
32459
- const menuDefaultProps = {
32460
- columns: [],
32461
- items: [],
32462
- autoFocus: true,
32463
- onShow: (state) => {
32464
- state.domRef.current?.parentNode?.addEventListener(
32465
- "mousedown",
32466
- onRootMouseDown
32467
- );
32468
- },
32469
- onHide,
32470
- onHideIntent: (state) => {
32471
- onHide(state);
32472
- config.onHideIntent?.();
32473
- }
32474
- };
32475
- return menuDefaultProps;
32476
- }
32477
-
32478
- // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32479
32948
  function getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp) {
32480
32949
  if (!menuDefinition) {
32481
32950
  return null;
32482
32951
  }
32483
32952
  const updater = buildSubscriptionCallback();
32484
32953
  menuDefinition.then((menuDefinition2) => {
32485
- const { items, columns } = getMenuItemsAndColumns(menuDefinition2);
32486
- if (items && items.length) {
32487
- updater(
32488
- /* @__PURE__ */ React69.createElement(MenuCmp, { ...menuDefaultProps, items: items || [], columns })
32489
- );
32954
+ const menuProps = getLazyMenuProps(menuDefinition2, menuDefaultProps);
32955
+ if (menuProps) {
32956
+ updater(/* @__PURE__ */ React69.createElement(MenuCmp, { ...menuProps }));
32490
32957
  }
32491
32958
  });
32492
32959
  return /* @__PURE__ */ React69.createElement(AvoidReactDiff, { updater });
32493
32960
  }
32494
32961
 
32495
32962
  // src/components/InfiniteTable/utils/getCellContextMenu.tsx
32496
- function getCellContextMenu(cellLocation, context, onHideIntent) {
32497
- const { columnId, rowIndex, event } = cellLocation;
32498
- const { getComputed, getState } = context;
32499
- const { components: components2, getCellContextMenuItems } = getState();
32500
- const MenuCmp = components2?.Menu ?? Menu;
32501
- const { computedColumnsMap } = getComputed();
32502
- const column = computedColumnsMap.get(columnId);
32503
- const cellContext = {
32504
- ...getCellContext({
32505
- ...context,
32506
- rowIndex,
32507
- columnId: column.id
32508
- }),
32509
- event
32510
- };
32511
- if (!column || !getCellContextMenuItems) {
32512
- return {
32513
- cellContext,
32514
- menu: null,
32515
- preventDefault: false
32516
- };
32517
- }
32518
- const menuDefaultProps = getMenuDefaultProps({
32519
- onHideIntent
32520
- });
32521
- const menuDefinition = getCellContextMenuItems(cellContext, context);
32522
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32523
- if (menuDefinition instanceof Promise) {
32524
- return {
32525
- cellContext,
32526
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32527
- preventDefault
32528
- };
32529
- }
32530
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32531
- if (!items || !items.length) {
32532
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32533
- }
32963
+ function getContextMenuBinder(context) {
32964
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32534
32965
  return {
32535
- preventDefault,
32536
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32537
- cellContext
32966
+ renderMenu: (props) => /* @__PURE__ */ React70.createElement(MenuCmp, { ...props }),
32967
+ renderLazyMenu: (menuDefinition, menuDefaultProps) => getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp)
32538
32968
  };
32539
32969
  }
32970
+ function getCellContextMenu(cellLocation, context, onHideIntent) {
32971
+ return getCellContextMenuContent(
32972
+ cellLocation,
32973
+ context,
32974
+ onHideIntent,
32975
+ getContextMenuBinder(context)
32976
+ );
32977
+ }
32540
32978
  function getTableContextMenu(menuLocation, context, onHideIntent) {
32541
- const { getState, getComputed } = context;
32542
- const { components: components2, getContextMenuItems } = getState();
32543
- const MenuCmp = components2?.Menu ?? Menu;
32544
- const { computedColumnsMap } = getComputed();
32545
- const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32546
- const cellContext = column ? {
32547
- ...menuLocation,
32548
- ...getCellContext({
32549
- ...context,
32550
- rowIndex: menuLocation.rowIndex,
32551
- columnId: column.id
32552
- })
32553
- } : menuLocation;
32554
- if (!getContextMenuItems) {
32555
- return { cellContext, menu: null, preventDefault: false };
32556
- }
32557
- const menuDefaultProps = getMenuDefaultProps({
32558
- onHideIntent
32559
- });
32560
- const menuDefinition = getContextMenuItems(cellContext, context);
32561
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32562
- if (menuDefinition instanceof Promise) {
32563
- return {
32564
- cellContext,
32565
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32566
- preventDefault
32567
- };
32568
- }
32569
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32570
- if (!items || !items.length) {
32571
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32572
- }
32573
- return {
32574
- preventDefault,
32575
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32576
- cellContext
32577
- };
32979
+ return getTableContextMenuContent(
32980
+ menuLocation,
32981
+ context,
32982
+ onHideIntent,
32983
+ getContextMenuBinder(context)
32984
+ );
32578
32985
  }
32579
32986
 
32580
32987
  // src/components/InfiniteTable/hooks/useContextMenu.ts
32581
- var OFFSET3 = 5;
32582
- var ALIGN_POSITIONS = [
32583
- ["TopLeft", "BottomLeft"],
32584
- ["TopRight", "BottomRight"],
32585
- ["BottomLeft", "BottomLeft"],
32586
- ["BottomRight", "BottomRight"],
32587
- ["TopCenter", "TopLeft"],
32588
- ["BottomCenter", "TopLeft"],
32589
- ["CenterLeft", "TopLeft"],
32590
- ["CenterRight", "TopLeft"]
32591
- ];
32592
32988
  function useCellContextMenu() {
32593
32989
  const context = useInfiniteTableStableContext();
32594
32990
  const { getState, actions } = context;
@@ -32600,78 +32996,22 @@ function useCellContextMenu() {
32600
32996
  portalContainer: useMenuPortalContainer()
32601
32997
  });
32602
32998
  useEffect35(() => {
32603
- const { actions: actions2, getState: getState2, getDataSourceState } = context;
32604
- const state = getState2();
32605
- return state.cellContextMenu.onChange((info) => {
32606
- if (!info) {
32607
- return;
32608
- }
32609
- const { event } = info;
32610
- function onHideIntent() {
32611
- clearAll();
32612
- actions2.cellContextMenuVisibleFor = null;
32613
- }
32614
- const { menu, cellContext, preventDefault } = getCellContextMenu(
32615
- info,
32616
- context,
32617
- onHideIntent
32618
- );
32619
- const rect = Rectangle.fromPoint({
32620
- top: event.clientY,
32621
- left: event.clientX
32622
- });
32623
- rect.width += OFFSET3;
32624
- rect.height += OFFSET3;
32625
- showOverlay(menu, {
32626
- constrainTo: getMenuConstrainTo(getState2()),
32627
- id: "cell-context-menu",
32628
- alignTo: rect,
32629
- alignPosition: ALIGN_POSITIONS
32630
- });
32631
- if (preventDefault) {
32632
- event.preventDefault();
32633
- }
32634
- actions2.cellContextMenuVisibleFor = {
32635
- columnId: info.columnId,
32636
- rowId: info.rowId,
32637
- rowIndex: info.rowIndex,
32638
- colIndex: info.colIndex
32639
- };
32640
- const { onCellContextMenu } = getState2();
32641
- if (onCellContextMenu) {
32642
- onCellContextMenu(
32643
- {
32644
- ...cellContext,
32645
- getState: getState2,
32646
- getDataSourceState
32647
- },
32648
- event
32649
- );
32650
- }
32651
- });
32999
+ return getState().cellContextMenu.onChange(
33000
+ getCellContextMenuHandler(context, {
33001
+ clearAll,
33002
+ getContent: (info, onHideIntent) => getCellContextMenu(info, context, onHideIntent),
33003
+ show: ({ menu }, params) => showOverlay(menu, params)
33004
+ })
33005
+ );
32652
33006
  }, []);
32653
33007
  useEffect35(() => {
32654
- const { cellContextMenuVisibleFor } = getState();
32655
- if (cellContextMenuVisibleFor) {
32656
- let handleMouseDown2 = function(event) {
32657
- if (event.__insideMenu !== true) {
32658
- clearAll();
32659
- actions.cellContextMenuVisibleFor = null;
32660
- }
32661
- };
32662
- var handleMouseDown = handleMouseDown2;
32663
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32664
- return () => {
32665
- document.documentElement.removeEventListener(
32666
- "mousedown",
32667
- handleMouseDown2
32668
- );
32669
- };
32670
- } else {
32671
- clearAll();
32672
- }
32673
- return () => {
32674
- };
33008
+ return menuVisibilityEffect(
33009
+ getState().cellContextMenuVisibleFor,
33010
+ clearAll,
33011
+ () => {
33012
+ actions.cellContextMenuVisibleFor = null;
33013
+ }
33014
+ );
32675
33015
  }, [getState().cellContextMenuVisibleFor]);
32676
33016
  return { menuPortal };
32677
33017
  }
@@ -32686,76 +33026,22 @@ function useTableContextMenu() {
32686
33026
  portalContainer: useMenuPortalContainer()
32687
33027
  });
32688
33028
  useEffect35(() => {
32689
- const { actions: actions2, getState: getState2 } = context;
32690
- const state = getState2();
32691
- return state.contextMenu.onChange((info) => {
32692
- if (!info) {
32693
- return;
32694
- }
32695
- const { event } = info;
32696
- function onHideIntent() {
32697
- clearAll();
32698
- actions2.contextMenuVisibleFor = null;
32699
- }
32700
- const { menu, cellContext, preventDefault } = getTableContextMenu(
32701
- info,
32702
- context,
32703
- onHideIntent
32704
- );
32705
- const point = {
32706
- top: event.clientY,
32707
- left: event.clientX
32708
- };
32709
- const rect = Rectangle.fromPoint(point);
32710
- rect.width += OFFSET3;
32711
- rect.height += OFFSET3;
32712
- showOverlay(menu, {
32713
- constrainTo: getMenuConstrainTo(getState2()),
32714
- id: "table-context-menu",
32715
- alignTo: rect,
32716
- alignPosition: ALIGN_POSITIONS
32717
- });
32718
- if (preventDefault) {
32719
- event.preventDefault();
32720
- }
32721
- actions2.contextMenuVisibleFor = {
32722
- point,
32723
- ...info
32724
- };
32725
- const { onContextMenu } = getState2();
32726
- if (onContextMenu) {
32727
- onContextMenu(
32728
- {
32729
- ...context,
32730
- ...cellContext
32731
- },
32732
- event
32733
- );
32734
- }
32735
- });
33029
+ return getState().contextMenu.onChange(
33030
+ getTableContextMenuHandler(context, {
33031
+ clearAll,
33032
+ getContent: (info, onHideIntent) => getTableContextMenu(info, context, onHideIntent),
33033
+ show: ({ menu }, params) => showOverlay(menu, params)
33034
+ })
33035
+ );
32736
33036
  }, []);
32737
33037
  useEffect35(() => {
32738
- const { contextMenuVisibleFor } = getState();
32739
- if (contextMenuVisibleFor) {
32740
- let handleMouseDown2 = function(event) {
32741
- if (event.__insideMenu !== true) {
32742
- clearAll();
32743
- actions.contextMenuVisibleFor = null;
32744
- }
32745
- };
32746
- var handleMouseDown = handleMouseDown2;
32747
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32748
- return () => {
32749
- document.documentElement.removeEventListener(
32750
- "mousedown",
32751
- handleMouseDown2
32752
- );
32753
- };
32754
- } else {
32755
- clearAll();
32756
- }
32757
- return () => {
32758
- };
33038
+ return menuVisibilityEffect(
33039
+ getState().contextMenuVisibleFor,
33040
+ clearAll,
33041
+ () => {
33042
+ actions.contextMenuVisibleFor = null;
33043
+ }
33044
+ );
32759
33045
  }, [getState().contextMenuVisibleFor]);
32760
33046
  return { menuPortal };
32761
33047
  }