@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.js CHANGED
@@ -1975,6 +1975,62 @@ function computePropsDiff(params) {
1975
1975
  rawUpdatedPropsCount
1976
1976
  };
1977
1977
  }
1978
+ function applyPropsDiff(params) {
1979
+ const {
1980
+ currentProps,
1981
+ prevProps,
1982
+ state,
1983
+ propsToForward,
1984
+ propsToStateSet,
1985
+ dispatch,
1986
+ actions,
1987
+ onPropChange: onPropChange2,
1988
+ onPropsChange,
1989
+ beforeDispatch
1990
+ } = params;
1991
+ const diff = computePropsDiff({
1992
+ currentProps,
1993
+ prevProps,
1994
+ state,
1995
+ propsToForward,
1996
+ propsToStateSet
1997
+ });
1998
+ const {
1999
+ newMappedState,
2000
+ newMappedStateCount,
2001
+ updatedPropsToState,
2002
+ updatedPropsToStateCount,
2003
+ rawUpdatedProps,
2004
+ rawUpdatedPropsCount
2005
+ } = diff;
2006
+ if (updatedPropsToStateCount === 0 && newMappedStateCount === 0) {
2007
+ return false;
2008
+ }
2009
+ beforeDispatch?.(diff);
2010
+ dispatch({
2011
+ payload: {
2012
+ mappedState: newMappedStateCount ? newMappedState : null,
2013
+ updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
2014
+ }
2015
+ });
2016
+ if (onPropChange2) {
2017
+ for (const prop in rawUpdatedProps) {
2018
+ if (rawUpdatedProps.hasOwnProperty(prop)) {
2019
+ const { newValue, oldValue } = rawUpdatedProps[prop];
2020
+ onPropChange2(
2021
+ { name: prop, newValue, oldValue },
2022
+ currentProps,
2023
+ actions,
2024
+ state
2025
+ );
2026
+ }
2027
+ }
2028
+ }
2029
+ if (onPropsChange && rawUpdatedPropsCount) {
2030
+ onPropsChange(rawUpdatedProps, currentProps, actions, state);
2031
+ }
2032
+ return true;
2033
+ }
1978
2034
 
1979
2035
  // src/components/hooks/useComponentState/index.tsx
1980
2036
  var ComponentContext;
@@ -2070,79 +2126,56 @@ function buildManagedComponent(config) {
2070
2126
  const effectFn = config.layoutEffect ? import_react9.useLayoutEffect : import_react9.useEffect;
2071
2127
  effectFn(() => {
2072
2128
  const currentProps = props;
2073
- const {
2074
- newMappedState,
2075
- newMappedStateCount,
2076
- updatedPropsToState,
2077
- updatedPropsToStateCount,
2078
- rawUpdatedProps,
2079
- rawUpdatedPropsCount
2080
- } = computePropsDiff({
2129
+ const dispatched = applyPropsDiff({
2081
2130
  currentProps,
2082
2131
  prevProps,
2083
2132
  state,
2084
2133
  propsToForward,
2085
- propsToStateSet: propsToStateSetRef.current
2086
- });
2087
- if (updatedPropsToStateCount > 0 || newMappedStateCount > 0) {
2088
- const debugId = state.debugId;
2089
- const marker = debugId ? getMarker(debugId).track.ComponentState.label.PropUpdate.start() : void 0;
2090
- const debugChannelName = config.debugName ? typeof config.debugName === "function" ? `${config.debugName(currentProps)}:rerender` : `${config.debugName}:rerender` : "rerender";
2091
- const logger2 = dbg(debugChannelName);
2092
- logger2(
2093
- "Triggered by new values for the following props",
2094
- ...[
2095
- ...Object.keys(newMappedState ?? {}),
2096
- ...Object.keys(updatedPropsToState ?? {})
2097
- ]
2098
- );
2099
- if (marker) {
2100
- marker.end({
2101
- label: debugChannelName,
2102
- details: [
2103
- newMappedStateCount > 0 ? {
2104
- name: "Updated properties",
2105
- value: Object.keys(newMappedState).join(", ")
2106
- } : void 0,
2107
- updatedPropsToStateCount > 0 ? {
2108
- name: "Updated props",
2109
- value: Object.keys(updatedPropsToState).join(", ")
2110
- } : void 0,
2111
- updatedPropsToStateCount > 0 || updatedPropsToState ? {
2112
- name: "Details",
2113
- 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."
2114
- } : void 0
2115
- ].filter(notNullable)
2116
- });
2117
- }
2118
- const action = {
2119
- payload: {
2120
- mappedState: newMappedStateCount ? newMappedState : null,
2121
- updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
2122
- }
2123
- };
2124
- skipTriggerParentStateChangeRef.current = true;
2125
- dispatch(action);
2126
- if (config.onPropChange) {
2127
- for (var prop in rawUpdatedProps)
2128
- if (rawUpdatedProps.hasOwnProperty(prop)) {
2129
- const { newValue, oldValue } = rawUpdatedProps[prop];
2130
- config.onPropChange(
2131
- { name: prop, newValue, oldValue },
2132
- props,
2133
- actions,
2134
- state
2135
- );
2136
- }
2137
- }
2138
- if (config.onPropsChange && rawUpdatedPropsCount) {
2139
- config.onPropsChange(
2140
- rawUpdatedProps,
2141
- props,
2142
- actions,
2143
- state
2134
+ propsToStateSet: propsToStateSetRef.current,
2135
+ dispatch,
2136
+ actions,
2137
+ onPropChange: config.onPropChange,
2138
+ onPropsChange: config.onPropsChange,
2139
+ beforeDispatch: ({
2140
+ newMappedState,
2141
+ newMappedStateCount,
2142
+ updatedPropsToState,
2143
+ updatedPropsToStateCount
2144
+ }) => {
2145
+ const debugId = state.debugId;
2146
+ const marker = debugId ? getMarker(debugId).track.ComponentState.label.PropUpdate.start() : void 0;
2147
+ const debugChannelName = config.debugName ? typeof config.debugName === "function" ? `${config.debugName(currentProps)}:rerender` : `${config.debugName}:rerender` : "rerender";
2148
+ const logger2 = dbg(debugChannelName);
2149
+ logger2(
2150
+ "Triggered by new values for the following props",
2151
+ ...[
2152
+ ...Object.keys(newMappedState ?? {}),
2153
+ ...Object.keys(updatedPropsToState ?? {})
2154
+ ]
2144
2155
  );
2156
+ if (marker) {
2157
+ marker.end({
2158
+ label: debugChannelName,
2159
+ details: [
2160
+ newMappedStateCount > 0 ? {
2161
+ name: "Updated properties",
2162
+ value: Object.keys(newMappedState).join(", ")
2163
+ } : void 0,
2164
+ updatedPropsToStateCount > 0 ? {
2165
+ name: "Updated props",
2166
+ value: Object.keys(updatedPropsToState).join(", ")
2167
+ } : void 0,
2168
+ updatedPropsToStateCount > 0 || updatedPropsToState ? {
2169
+ name: "Details",
2170
+ 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."
2171
+ } : void 0
2172
+ ].filter(notNullable)
2173
+ });
2174
+ }
2145
2175
  }
2176
+ });
2177
+ if (dispatched) {
2178
+ skipTriggerParentStateChangeRef.current = true;
2146
2179
  }
2147
2180
  });
2148
2181
  effectFn(() => {
@@ -2526,7 +2559,7 @@ var HeaderFilterOperatorCls = "_12zfob12q _16lm1iw1p _16lm1iw2h _16lm1iw2j _16lm
2526
2559
  var HeaderFilterOperatorIconRecipe = createRuntimeFn({ defaultClassName: "_12zfob12r _16lm1iw1 _16lm1iw23", variantClassNames: { disabled: { true: "_12zfob12s", false: "_12zfob12t" } }, defaultVariants: {}, compoundVariants: [] });
2527
2560
  var HeaderFilterRecipe = createRuntimeFn({ defaultClassName: "_12zfob12n _16lm1iw1p _16lm1iw2h _16lm1iw2k _16lm1iw1", variantClassNames: { active: { true: "_12zfob12o", false: "_12zfob12p" } }, defaultVariants: {}, compoundVariants: [] });
2528
2561
  var HeaderGroupCls = "_12zfob12m _16lm1iw1p _16lm1iw2h _16lm1iw2j";
2529
- 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"]] });
2562
+ var HeaderMenuIconCls = createRuntimeFn({ defaultClassName: "_12zfob127 _16lm1iw1 _16lm1iw39", variantClassNames: { menuVisible: { true: "_12zfob128" }, reserveSpaceWhenHidden: { true: "_12zfob129", false: "_12zfob12a" } }, defaultVariants: {}, compoundVariants: [[{ menuVisible: true, reserveSpaceWhenHidden: false }, "_12zfob12b"]] });
2530
2563
  var HeaderScrollbarPlaceholderCls = "_12zfob1b _16lm1iw2";
2531
2564
  var HeaderSortIconCls = "_16lm1iw1";
2532
2565
  var HeaderSortIconIndexCls = "_12zfob16";
@@ -3773,8 +3806,7 @@ function getColumnApiForColumn(colOrColId, param) {
3773
3806
  }
3774
3807
 
3775
3808
  // src/components/InfiniteTable/components/InfiniteTableHeader/getColumnLabel.ts
3776
- function getColumnLabel(colIdOrCol, context, renderLocation) {
3777
- const col = typeof colIdOrCol === "string" ? context.getComputed().computedColumnsMap.get(colIdOrCol) : colIdOrCol;
3809
+ function getColumnLabelHeaderParam(col, context, renderLocation) {
3778
3810
  const {
3779
3811
  api,
3780
3812
  getComputed,
@@ -3786,35 +3818,47 @@ function getColumnLabel(colIdOrCol, context, renderLocation) {
3786
3818
  const dataSourceState = getDataSourceState();
3787
3819
  const { allRowsSelected, someRowsSelected, selectionMode } = dataSourceState;
3788
3820
  const computed = getComputed();
3789
- let label = col.header && typeof col.header !== "function" ? col.header : col.name || col.id || "";
3790
- if (typeof col.header === "function") {
3791
- const columnApi = getColumnApiForColumn(col.id, {
3792
- ...context,
3793
- actions,
3794
- dataSourceActions,
3795
- dataSourceApi
3796
- });
3797
- label = col.header({
3798
- horizontalLayoutPageIndex: null,
3799
- column: col,
3800
- columnApi,
3801
- dataSourceApi,
3802
- renderLocation,
3803
- dragging: false,
3804
- columnsMap: computed.computedColumnsMap,
3805
- columnSortInfo: col.computedSortInfo,
3806
- columnFilterValue: col.computedFilterValue,
3807
- filtered: col.computedFiltered,
3808
- allRowsSelected,
3809
- someRowsSelected,
3810
- selectionMode,
3811
- api,
3812
- renderBag: {
3813
- header: label
3814
- }
3815
- }) ?? null;
3821
+ const columnApi = getColumnApiForColumn(col.id, {
3822
+ ...context,
3823
+ actions,
3824
+ dataSourceActions,
3825
+ dataSourceApi
3826
+ });
3827
+ return {
3828
+ horizontalLayoutPageIndex: null,
3829
+ column: col,
3830
+ columnApi,
3831
+ dataSourceApi,
3832
+ renderLocation,
3833
+ dragging: false,
3834
+ columnsMap: computed.computedColumnsMap,
3835
+ columnSortInfo: col.computedSortInfo,
3836
+ columnFilterValue: col.computedFilterValue,
3837
+ filtered: col.computedFiltered,
3838
+ allRowsSelected,
3839
+ someRowsSelected,
3840
+ selectionMode,
3841
+ api,
3842
+ renderBag: {
3843
+ header: col.name || col.id || ""
3844
+ }
3845
+ };
3846
+ }
3847
+ function getColumnLabel(colIdOrCol, context, renderLocation, bind) {
3848
+ const col = typeof colIdOrCol === "string" ? context.getComputed().computedColumnsMap.get(colIdOrCol) : colIdOrCol;
3849
+ const header = col.header;
3850
+ if (typeof header === "function") {
3851
+ const param = getColumnLabelHeaderParam(col, context, renderLocation);
3852
+ const label = header(param) ?? null;
3853
+ return bind ? bind(label, param) : label;
3816
3854
  }
3817
- return label;
3855
+ if (header) {
3856
+ return bind ? bind(
3857
+ header,
3858
+ getColumnLabelHeaderParam(col, context, renderLocation)
3859
+ ) : header;
3860
+ }
3861
+ return col.name || col.id || "";
3818
3862
  }
3819
3863
 
3820
3864
  // src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilterContext.ts
@@ -3960,6 +4004,14 @@ function useInfiniteColumnFilterEditor() {
3960
4004
  const [theValue, setTheValue] = (0, import_react13.useState)(
3961
4005
  columnFilterValue?.filter.value ?? ""
3962
4006
  );
4007
+ const [droppedCount, setDroppedCount] = (0, import_react13.useState)(0);
4008
+ (0, import_react13.useEffect)(
4009
+ () => context.getState().pendingColumnFilters.onCancel(
4010
+ column.id,
4011
+ () => setDroppedCount((count) => count + 1)
4012
+ ),
4013
+ [column.id]
4014
+ );
3963
4015
  const onInputChange = React18.useCallback(
3964
4016
  (filterValue) => {
3965
4017
  setTheValue(filterValue);
@@ -3986,7 +4038,7 @@ function useInfiniteColumnFilterEditor() {
3986
4038
  }
3987
4039
  }
3988
4040
  }
3989
- }, [columnFilterValue?.filter.value]);
4041
+ }, [columnFilterValue?.filter.value, droppedCount]);
3990
4042
  const operator = filterContextValue.operator;
3991
4043
  const operatorName = operator?.name;
3992
4044
  return {
@@ -11854,9 +11906,10 @@ var React28 = __toESM(require("react"));
11854
11906
  var import_react21 = require("react");
11855
11907
 
11856
11908
  // src/components/InfiniteTable/components/icons/SortIcon/SortIcon.css.ts
11857
- var SortIconCls = "_1b8djff0 _16lm1iw1p _16lm1iw2f _16lm1iw1 _16lm1iw32";
11858
- var SortIconDirectionCls = { asc: "_1b8djff1", desc: "_1b8djff2", none: "_1b8djff3" };
11859
- var SortIconLineCls = "_1b8djff4";
11909
+ var SortIconCls = "_1b8djff1 _16lm1iw1";
11910
+ var SortIconDirectionCls = { asc: "_1b8djff2", desc: "_1b8djff3", none: "_1b8djff4" };
11911
+ var SortIconLineCls = "_1b8djff5";
11912
+ var SortIconLineWidthVarName = "--_1b8djff0";
11860
11913
 
11861
11914
  // src/components/InfiniteTable/components/icons/SortIcon/shared.ts
11862
11915
  var defaultLineStyle3 = {
@@ -11926,7 +11979,11 @@ function SortIcon(props) {
11926
11979
  "div",
11927
11980
  {
11928
11981
  "data-name": "sort-icon",
11929
- style: { ...style2, width: size },
11982
+ style: {
11983
+ ...style2,
11984
+ width: size,
11985
+ [SortIconLineWidthVarName]: `${lineWidth}px`
11986
+ },
11930
11987
  className: join(
11931
11988
  className,
11932
11989
  InfiniteIconClassName,
@@ -12323,6 +12380,116 @@ function useColumnResizeHandle(column, opts) {
12323
12380
  return resizeHandle;
12324
12381
  }
12325
12382
 
12383
+ // src/components/InfiniteTable/utils/pendingColumnFilters.ts
12384
+ function getColumnFilterValueItem(filterValue, column) {
12385
+ if (!filterValue || !column) {
12386
+ return null;
12387
+ }
12388
+ const fieldKey = column.field || column.groupByForColumn;
12389
+ let byId = null;
12390
+ let byField = null;
12391
+ for (const item of filterValue) {
12392
+ if (item.id === column.id || item.field === column.id) {
12393
+ byId = item;
12394
+ }
12395
+ if (fieldKey && (item.id === fieldKey || item.field === fieldKey)) {
12396
+ byField = item;
12397
+ }
12398
+ }
12399
+ return byId || byField;
12400
+ }
12401
+ function sameFilter(a, b) {
12402
+ if (!a || !b) {
12403
+ return a === b;
12404
+ }
12405
+ return a.filter.type === b.filter.type && a.filter.operator === b.filter.operator && a.filter.value === b.filter.value && !!a.disabled === !!b.disabled;
12406
+ }
12407
+ var PendingColumnFilters = class {
12408
+ constructor() {
12409
+ this.pending = /* @__PURE__ */ new Map();
12410
+ /** the value applied last, until the DataSource has it */
12411
+ this.applied = /* @__PURE__ */ new Map();
12412
+ this.cancelListeners = /* @__PURE__ */ new Map();
12413
+ }
12414
+ schedule(columnId, value, options) {
12415
+ const typedOver = options.getFilterValueItem();
12416
+ if (this.isLastApplied(columnId, typedOver)) {
12417
+ this.applied.delete(columnId);
12418
+ }
12419
+ const previous = this.pending.get(columnId);
12420
+ if (previous) {
12421
+ clearTimeout(previous.timeout);
12422
+ }
12423
+ const timeout = setTimeout(() => {
12424
+ this.pending.delete(columnId);
12425
+ const current = options.getFilterValueItem();
12426
+ if (!sameFilter(current, typedOver) && !this.isLastApplied(columnId, current)) {
12427
+ this.applied.delete(columnId);
12428
+ this.notifyCancel(columnId);
12429
+ return;
12430
+ }
12431
+ options.apply(value);
12432
+ const applied = options.getFilterValueItem();
12433
+ if (applied && applied.filter.value === value) {
12434
+ this.applied.delete(columnId);
12435
+ } else {
12436
+ this.applied.set(columnId, value);
12437
+ }
12438
+ }, options.delay);
12439
+ this.pending.set(columnId, { timeout, typedOver });
12440
+ }
12441
+ /** drops the value waiting for the column, if any */
12442
+ cancel(columnId) {
12443
+ const pending = this.pending.get(columnId);
12444
+ if (!pending) {
12445
+ return;
12446
+ }
12447
+ clearTimeout(pending.timeout);
12448
+ this.pending.delete(columnId);
12449
+ this.notifyCancel(columnId);
12450
+ }
12451
+ onCancel(columnId, fn) {
12452
+ let listeners = this.cancelListeners.get(columnId);
12453
+ if (!listeners) {
12454
+ listeners = /* @__PURE__ */ new Set();
12455
+ this.cancelListeners.set(columnId, listeners);
12456
+ }
12457
+ listeners.add(fn);
12458
+ return () => {
12459
+ listeners.delete(fn);
12460
+ if (!listeners.size && this.cancelListeners.get(columnId) === listeners) {
12461
+ this.cancelListeners.delete(columnId);
12462
+ }
12463
+ };
12464
+ }
12465
+ isLastApplied(columnId, item) {
12466
+ return !!item && this.applied.has(columnId) && item.filter.value === this.applied.get(columnId);
12467
+ }
12468
+ notifyCancel(columnId) {
12469
+ this.cancelListeners.get(columnId)?.forEach((fn) => fn());
12470
+ }
12471
+ };
12472
+ function createColumnFilterChangeHandler(params) {
12473
+ const { columnId, filterDelay, api } = params;
12474
+ const apply = (filterValue) => {
12475
+ api.setColumnFilter(columnId, filterValue);
12476
+ };
12477
+ if (!(filterDelay > 0)) {
12478
+ return apply;
12479
+ }
12480
+ const getFilterValueItem = () => getColumnFilterValueItem(
12481
+ params.getDataSourceState().filterValue,
12482
+ params.getComputed().computedColumnsMap.get(columnId)
12483
+ );
12484
+ return (filterValue) => {
12485
+ params.getState().pendingColumnFilters.schedule(columnId, filterValue, {
12486
+ delay: filterDelay,
12487
+ getFilterValueItem,
12488
+ apply
12489
+ });
12490
+ };
12491
+ }
12492
+
12326
12493
  // src/components/InfiniteTable/components/draggable/DragList.tsx
12327
12494
  var React31 = __toESM(require("react"));
12328
12495
  var import_react24 = require("react");
@@ -18927,15 +19094,17 @@ function InfiniteTableHeaderCellFn(props) {
18927
19094
  verticalAlign,
18928
19095
  align: align2
18929
19096
  };
18930
- const debouncedOnFilterValueChange = React49.useMemo(() => {
18931
- const fn = (filterValue) => {
18932
- api.setColumnFilter(column.id, filterValue);
18933
- };
18934
- if (filterDelay > 0) {
18935
- return debounce(fn, { wait: filterDelay });
18936
- }
18937
- return fn;
18938
- }, [filterDelay, column.id]);
19097
+ const debouncedOnFilterValueChange = React49.useMemo(
19098
+ () => createColumnFilterChangeHandler({
19099
+ columnId: column.id,
19100
+ filterDelay,
19101
+ api,
19102
+ getState,
19103
+ getComputed,
19104
+ getDataSourceState
19105
+ }),
19106
+ [filterDelay, column.id]
19107
+ );
18939
19108
  const filterTypeKey = column.computedFilterType;
18940
19109
  const filterType = filterTypes[filterTypeKey];
18941
19110
  const operatorName = column.computedFilterable ? column.computedFilterValue?.filter.operator ?? filterType?.defaultOperator : void 0;
@@ -21716,6 +21885,7 @@ var InfiniteTableApiImpl = class {
21716
21885
  this.actions.columnPinning = columnPinning;
21717
21886
  }
21718
21887
  setColumnFilter(columnId, filterValue) {
21888
+ this.getState().pendingColumnFilters.cancel(columnId);
21719
21889
  const col = this.getComputed().computedColumnsMap.get(columnId);
21720
21890
  if (!col) {
21721
21891
  return;
@@ -21753,6 +21923,7 @@ var InfiniteTableApiImpl = class {
21753
21923
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21754
21924
  }
21755
21925
  setColumnFilterOperator(columnId, newOperator) {
21926
+ this.getState().pendingColumnFilters.cancel(columnId);
21756
21927
  const col = this.getComputed().computedColumnsMap.get(columnId);
21757
21928
  if (!col) {
21758
21929
  return;
@@ -21796,6 +21967,7 @@ var InfiniteTableApiImpl = class {
21796
21967
  this.setFilterValueForColumn(columnId, newFilterValueForColumn);
21797
21968
  }
21798
21969
  setFilterValueForColumn(columnId, filterValue) {
21970
+ this.getState().pendingColumnFilters.cancel(columnId);
21799
21971
  const column = this.getComputed().computedColumnsMap.get(columnId);
21800
21972
  if (!column) {
21801
21973
  return;
@@ -21816,6 +21988,7 @@ var InfiniteTableApiImpl = class {
21816
21988
  this.dataSourceActions.filterValue = newFilterValue;
21817
21989
  }
21818
21990
  removeColumnFilter(columnId) {
21991
+ this.getState().pendingColumnFilters.cancel(columnId);
21819
21992
  const column = this.getComputed().computedColumnsMap.get(columnId);
21820
21993
  if (!column) {
21821
21994
  return;
@@ -21835,6 +22008,7 @@ var InfiniteTableApiImpl = class {
21835
22008
  }
21836
22009
  }
21837
22010
  clearColumnFilter(columnId) {
22011
+ this.getState().pendingColumnFilters.cancel(columnId);
21838
22012
  const column = this.getComputed().computedColumnsMap.get(columnId);
21839
22013
  if (!column) {
21840
22014
  return;
@@ -23173,6 +23347,9 @@ function deepEqual(a, b) {
23173
23347
  if (a === b) return true;
23174
23348
  if (a == null || b == null) return a === b;
23175
23349
  if (typeof a !== typeof b) return false;
23350
+ if (a instanceof Date || b instanceof Date) {
23351
+ return a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
23352
+ }
23176
23353
  if (Array.isArray(a) && Array.isArray(b)) {
23177
23354
  if (a.length !== b.length) return false;
23178
23355
  for (let i = 0, len = a.length; i < len; i++) {
@@ -27794,6 +27971,7 @@ function initSetupState2({
27794
27971
  cellContextMenu: buildSubscriptionCallback(),
27795
27972
  contextMenu: buildSubscriptionCallback(),
27796
27973
  onFilterOperatorMenuClick: buildSubscriptionCallback(),
27974
+ pendingColumnFilters: new PendingColumnFilters(),
27797
27975
  flashingDurationCSSVarValue: null,
27798
27976
  onFlashingDurationCSSVarChange: buildSubscriptionCallback(),
27799
27977
  onRowHeightCSSVarChange: buildSubscriptionCallback(),
@@ -29605,8 +29783,8 @@ function getLicenseStatus(licenseKey = "", options) {
29605
29783
  return "valid";
29606
29784
  }
29607
29785
  const result = checkLicense(licenseKey, {
29608
- publishedAt: 1795523603652,
29609
- version: "10.2.1"
29786
+ publishedAt: 1795784312033,
29787
+ version: "11.0.1"
29610
29788
  });
29611
29789
  if (result === "invalid" && !licenseKey) {
29612
29790
  return "missing";
@@ -30905,6 +31083,14 @@ var deriveStateFromProps2 = (params) => {
30905
31083
  var React61 = __toESM(require("react"));
30906
31084
  var import_react58 = require("react");
30907
31085
 
31086
+ // src/components/Menu/MenuContext.ts
31087
+ var import_react56 = require("react");
31088
+ var MenuContext = (0, import_react56.createContext)(null);
31089
+ function useMenuContext() {
31090
+ const contextValue = (0, import_react56.useContext)(MenuContext);
31091
+ return contextValue;
31092
+ }
31093
+
30908
31094
  // src/components/Menu/menuDomUtils.ts
30909
31095
  function getMenuItemRect(menuId, itemKey) {
30910
31096
  const cells = getMenuItemNodes(menuId, itemKey);
@@ -30946,6 +31132,180 @@ function getFirstCheckBoxInsideMenuItem(menuId, itemKey) {
30946
31132
  return null;
30947
31133
  }
30948
31134
 
31135
+ // src/components/Menu/menuKeyboardNav.ts
31136
+ function hideMenuAndParents(getState) {
31137
+ const state = getState();
31138
+ state.onHideIntent?.(state);
31139
+ }
31140
+ function runMenuItemClick(event, item, context) {
31141
+ const { getState, setActiveItemKey, setKeyboardActiveItemKey, hideAll } = context;
31142
+ setKeyboardActiveItemKey(item.key);
31143
+ setActiveItemKey(item.key);
31144
+ if (item.originalMenuItem.onClick) {
31145
+ item.originalMenuItem.onClick(event);
31146
+ }
31147
+ const onActionParam = {
31148
+ key: item.key,
31149
+ item: item.originalMenuItem,
31150
+ hideMenu: hideAll
31151
+ };
31152
+ if (item.originalMenuItem.onAction) {
31153
+ item.originalMenuItem.onAction(onActionParam);
31154
+ }
31155
+ const { onAction } = getState();
31156
+ if (onAction) {
31157
+ onAction(onActionParam);
31158
+ }
31159
+ if (item.originalMenuItem.hideMenuOnAction) {
31160
+ hideAll();
31161
+ }
31162
+ }
31163
+ function handleMenuKeyDown(keyboardEvent, context) {
31164
+ const {
31165
+ getState,
31166
+ setActiveItemKey,
31167
+ setKeyboardActiveItemKey,
31168
+ destroy,
31169
+ getSubmenuApi,
31170
+ isMounted,
31171
+ onItemClick
31172
+ } = context;
31173
+ const { runtimeItems, runtimeSelectableItems, keyboardActiveItemKey } = getState();
31174
+ const keyboardActiveIndex = runtimeItems.findIndex(
31175
+ (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31176
+ );
31177
+ let newKeyboardActiveItemKey = keyboardActiveItemKey;
31178
+ const keyboardActiveItem = runtimeItems[keyboardActiveIndex];
31179
+ const validKeys3 = {
31180
+ ArrowUp: () => {
31181
+ const newActiveItem = runtimeItems.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31182
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31183
+ newKeyboardActiveItemKey = newActiveItem.key;
31184
+ }
31185
+ },
31186
+ ArrowDown: () => {
31187
+ const newActiveItem = runtimeItems.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31188
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31189
+ newKeyboardActiveItemKey = newActiveItem.key;
31190
+ }
31191
+ },
31192
+ Home: () => {
31193
+ validKeys3.PageUp();
31194
+ },
31195
+ End: () => {
31196
+ validKeys3.PageDown();
31197
+ },
31198
+ PageUp: () => {
31199
+ newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31200
+ },
31201
+ PageDown: () => {
31202
+ newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31203
+ },
31204
+ ArrowLeft: () => {
31205
+ setActiveItemKey(null);
31206
+ if (getState().parentMenuId) {
31207
+ destroy();
31208
+ }
31209
+ },
31210
+ ArrowRight: () => {
31211
+ if (!keyboardActiveItem) {
31212
+ return;
31213
+ }
31214
+ setActiveItemKey(keyboardActiveItem.key);
31215
+ raf(() => {
31216
+ const submenuApi = getSubmenuApi();
31217
+ if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31218
+ submenuApi.focus();
31219
+ }
31220
+ });
31221
+ },
31222
+ Enter: () => {
31223
+ if (!keyboardActiveItem) {
31224
+ return;
31225
+ }
31226
+ if (keyboardActiveItem.originalMenuItem?.menu) {
31227
+ if (getSubmenuApi()) {
31228
+ validKeys3.ArrowLeft();
31229
+ return;
31230
+ }
31231
+ setActiveItemKey(keyboardActiveItem.key);
31232
+ } else {
31233
+ onItemClick(keyboardEvent, keyboardActiveItem);
31234
+ }
31235
+ },
31236
+ " ": () => {
31237
+ if (!keyboardActiveItem) {
31238
+ return;
31239
+ }
31240
+ if (!keyboardActiveItem.originalMenuItem.menu) {
31241
+ onItemClick(keyboardEvent, keyboardActiveItem);
31242
+ }
31243
+ const checkbox = getFirstCheckBoxInsideMenuItem(
31244
+ getState().menuId,
31245
+ keyboardActiveItem.key
31246
+ );
31247
+ if (!checkbox) {
31248
+ return;
31249
+ }
31250
+ checkbox.click();
31251
+ },
31252
+ Escape: () => {
31253
+ validKeys3.ArrowLeft();
31254
+ const state = getState();
31255
+ if (!state.parentMenuId) {
31256
+ state.onHideIntent?.(state);
31257
+ }
31258
+ }
31259
+ };
31260
+ const fn = validKeys3[keyboardEvent.key];
31261
+ if (fn) {
31262
+ fn();
31263
+ keyboardEvent.preventDefault();
31264
+ }
31265
+ if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31266
+ setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31267
+ }
31268
+ }
31269
+ function createMenuFocus(context) {
31270
+ const {
31271
+ getState,
31272
+ setFocused,
31273
+ setKeyboardActiveItemKey,
31274
+ shouldSelectFirstItemOnFocus,
31275
+ hideAll
31276
+ } = context;
31277
+ const onMenuFocus = () => {
31278
+ setFocused(true);
31279
+ setTimeout(() => {
31280
+ const domNode = getState().domRef.current;
31281
+ if (shouldSelectFirstItemOnFocus() && domNode && domNode === document.activeElement && getState().keyboardActiveItemKey == null) {
31282
+ setKeyboardActiveItemKey(
31283
+ getState().runtimeSelectableItems[0]?.key ?? null
31284
+ );
31285
+ }
31286
+ });
31287
+ };
31288
+ const api = {
31289
+ hideMenu: hideAll,
31290
+ focus: () => {
31291
+ const domNode = getState().domRef.current;
31292
+ if (domNode) {
31293
+ domNode.focus();
31294
+ setTimeout(() => {
31295
+ const node = getState().domRef.current;
31296
+ if (node && node !== document.activeElement) {
31297
+ node.focus();
31298
+ }
31299
+ }, 10);
31300
+ onMenuFocus();
31301
+ }
31302
+ },
31303
+ getMenuId: () => getState().menuId,
31304
+ getParentMenuId: () => getState().parentMenuId
31305
+ };
31306
+ return { api, onMenuFocus };
31307
+ }
31308
+
30949
31309
  // src/utils/pageGeometry/Triangle.ts
30950
31310
  var Triangle = class extends ConvexPoly {
30951
31311
  // uncommenting this here breaks our tests - WHAT????
@@ -31162,40 +31522,38 @@ var MenuTriangleContext = class {
31162
31522
  }
31163
31523
  };
31164
31524
 
31165
- // src/components/Menu/MenuContext.ts
31166
- var import_react56 = require("react");
31167
- var MenuContext = (0, import_react56.createContext)(null);
31168
- function useMenuContext() {
31169
- const contextValue = (0, import_react56.useContext)(MenuContext);
31170
- return contextValue;
31525
+ // src/components/Menu/menuViewShared.ts
31526
+ function getActiveSubmenuItem(runtimeItems, activeItemKey) {
31527
+ const activeItem = runtimeItems.filter(
31528
+ (item) => item.type === "item" && activeItemKey === item.key
31529
+ )[0];
31530
+ return activeItem && activeItem.menu ? activeItem : null;
31171
31531
  }
31172
-
31173
- // src/components/hooks/useMounted.ts
31174
- var import_react57 = require("react");
31175
- function useMounted() {
31176
- let mountedRef = (0, import_react57.useRef)(true);
31177
- (0, import_react57.useEffect)(() => {
31178
- mountedRef.current = true;
31179
- return () => {
31180
- mountedRef.current = false;
31181
- };
31182
- }, []);
31183
- const isMounted = (0, import_react57.useCallback)(() => mountedRef.current, []);
31184
- return isMounted;
31532
+ function getSubmenuOverlayParams(menuId, item, constrainTo) {
31533
+ const alignTo = getMenuItemRect(menuId, item.key);
31534
+ if (!alignTo) {
31535
+ return null;
31536
+ }
31537
+ return {
31538
+ id: `${menuId}-submenu`,
31539
+ alignTo,
31540
+ alignPosition: [
31541
+ ["TopLeft", "TopRight"],
31542
+ ["TopRight", "TopLeft"]
31543
+ ],
31544
+ constrainTo
31545
+ };
31185
31546
  }
31186
-
31187
- // src/components/Menu/Menu.tsx
31188
- function renderSubmenuForItem(item, config) {
31547
+ function getSubmenuProps(item, context) {
31189
31548
  const {
31190
31549
  parentMenuId,
31550
+ constrainTo,
31551
+ api,
31552
+ hideAll,
31191
31553
  setSubmenuApi,
31192
31554
  setActiveItemKey,
31193
- setKeyboardActiveItemKey,
31194
- constrainTo,
31195
- onHideIntent,
31196
- api
31197
- } = config;
31198
- const overlayId = `${parentMenuId}-submenu`;
31555
+ setKeyboardActiveItemKey
31556
+ } = context;
31199
31557
  let itemMenu = item.menu;
31200
31558
  if (!itemMenu) {
31201
31559
  return null;
@@ -31203,67 +31561,152 @@ function renderSubmenuForItem(item, config) {
31203
31561
  if (typeof itemMenu === "function") {
31204
31562
  itemMenu = itemMenu();
31205
31563
  }
31206
- return /* @__PURE__ */ React61.createElement(
31207
- Menu,
31208
- {
31209
- key: overlayId,
31210
- parentMenuItemKey: item.key,
31211
- parentMenuId,
31212
- constrainTo,
31213
- ...itemMenu,
31214
- autoFocus: false,
31215
- onShow: (state, api2) => {
31216
- itemMenu?.onShow?.(state, api2);
31217
- setSubmenuApi(api2);
31218
- },
31219
- onHideIntent: (state) => {
31220
- itemMenu?.onHideIntent?.(state);
31221
- onHideIntent(state);
31222
- },
31223
- onHide: (state) => {
31224
- if (state.focused) {
31225
- setActiveItemKey(null);
31226
- setKeyboardActiveItemKey(item.key);
31227
- api.focus();
31228
- }
31229
- }
31230
- }
31231
- );
31232
- }
31233
- function useSubmenus({
31234
- onItemActivate
31235
- }) {
31236
- const { getState } = useMenuContext();
31237
- const [{ onItemEnter, onItemLeave }] = (0, import_react58.useState)(() => {
31238
- return new MenuTriangleContext({
31239
- parentMenuId: getState().parentMenuId,
31240
- onItemActivate: (itemKey) => {
31241
- if (!itemKey) {
31242
- onItemActivate(null);
31243
- return;
31244
- }
31245
- const item = getState().runtimeItems.filter(
31246
- (item2) => item2.type === "item" && item2.key === itemKey
31247
- )[0];
31248
- onItemActivate(item);
31249
- },
31250
- itemHasSubMenu: (itemKey) => {
31251
- const item = getState().runtimeItems.filter(
31252
- (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31253
- )[0];
31254
- return !!item;
31564
+ const submenu = itemMenu;
31565
+ return {
31566
+ parentMenuItemKey: item.key,
31567
+ parentMenuId,
31568
+ constrainTo,
31569
+ ...submenu,
31570
+ autoFocus: false,
31571
+ onShow: (state, submenuApi) => {
31572
+ submenu?.onShow?.(state, submenuApi);
31573
+ setSubmenuApi(submenuApi);
31574
+ },
31575
+ onHideIntent: (state) => {
31576
+ submenu?.onHideIntent?.(state);
31577
+ hideAll();
31578
+ },
31579
+ onHide: (state) => {
31580
+ if (state.focused) {
31581
+ setActiveItemKey(null);
31582
+ setKeyboardActiveItemKey(item.key);
31583
+ api.focus();
31584
+ }
31585
+ }
31586
+ };
31587
+ }
31588
+ function createMenuTriangleHandlers(getState, onItemActivate) {
31589
+ return new MenuTriangleContext({
31590
+ parentMenuId: getState().parentMenuId,
31591
+ onItemActivate,
31592
+ itemHasSubMenu: (itemKey) => {
31593
+ const item = getState().runtimeItems.filter(
31594
+ (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31595
+ )[0];
31596
+ return !!item;
31597
+ },
31598
+ getMenuRectFor: (itemKey) => {
31599
+ const selector2 = `[data-submenu-for="${itemKey}"]`;
31600
+ const menuNode = document.querySelector(selector2);
31601
+ if (!menuNode) {
31602
+ return void 0;
31603
+ }
31604
+ return Rectangle.from(menuNode.getBoundingClientRect());
31605
+ }
31606
+ }).getHandlers();
31607
+ }
31608
+ function getMenuGridStyle(state, style2, toCssWidth = (width) => width) {
31609
+ const { columns, runtimeItems, wrapLabels } = state;
31610
+ const gridTemplateColumns = columns.map((col) => {
31611
+ return toCssWidth(
31612
+ col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto"
31613
+ );
31614
+ }).join(" ");
31615
+ const result = {
31616
+ ...style2,
31617
+ gridTemplateColumns,
31618
+ gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31619
+ };
31620
+ if (!wrapLabels) {
31621
+ result.whiteSpace = "nowrap";
31622
+ }
31623
+ return result;
31624
+ }
31625
+ function getMenuItemCells(item, columns, index, flags) {
31626
+ const { active, keyboardActive, pressed } = flags;
31627
+ const key = item.value.key;
31628
+ const className = join(
31629
+ MenuItemCls({
31630
+ active,
31631
+ disabled: !!item.disabled,
31632
+ keyboardActive,
31633
+ pressed: pressed || active
31634
+ }),
31635
+ item.className
31636
+ );
31637
+ const cells = [];
31638
+ let spanIndex = 0;
31639
+ columns.forEach((col, i) => {
31640
+ const target = item.value;
31641
+ const field = col.field || col.name;
31642
+ const start = i + 1;
31643
+ const end = start + item.span;
31644
+ if (start < spanIndex) {
31645
+ return;
31646
+ }
31647
+ spanIndex = end;
31648
+ cells.push({
31649
+ key: `${key}-${field}`,
31650
+ column: col,
31651
+ value: target[field],
31652
+ style: {
31653
+ ...col.style,
31654
+ ...item.style,
31655
+ gridColumnStart: start,
31656
+ gridColumnEnd: end
31255
31657
  },
31256
- getMenuRectFor: (itemKey) => {
31257
- const selector2 = `[data-submenu-for="${itemKey}"]`;
31258
- const menuNode = document.querySelector(selector2);
31259
- if (!menuNode) {
31260
- return void 0;
31261
- }
31262
- const rect = Rectangle.from(menuNode.getBoundingClientRect());
31263
- return rect;
31658
+ className,
31659
+ dataAttributes: {
31660
+ "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31661
+ "data-menu-col-name": `${col.name}`,
31662
+ "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31663
+ "data-menu-row-index": `${index}`,
31664
+ "data-menu-item-key": `${item.key}`
31264
31665
  }
31265
- }).getHandlers();
31666
+ });
31266
31667
  });
31668
+ return cells;
31669
+ }
31670
+
31671
+ // src/components/hooks/useMounted.ts
31672
+ var import_react57 = require("react");
31673
+ function useMounted() {
31674
+ let mountedRef = (0, import_react57.useRef)(true);
31675
+ (0, import_react57.useEffect)(() => {
31676
+ mountedRef.current = true;
31677
+ return () => {
31678
+ mountedRef.current = false;
31679
+ };
31680
+ }, []);
31681
+ const isMounted = (0, import_react57.useCallback)(() => mountedRef.current, []);
31682
+ return isMounted;
31683
+ }
31684
+
31685
+ // src/components/Menu/Menu.tsx
31686
+ function renderSubmenuForItem(item, config) {
31687
+ const overlayId = `${config.parentMenuId}-submenu`;
31688
+ const submenuProps = getSubmenuProps(item, config);
31689
+ if (!submenuProps) {
31690
+ return null;
31691
+ }
31692
+ return /* @__PURE__ */ React61.createElement(Menu, { key: overlayId, ...submenuProps });
31693
+ }
31694
+ function useSubmenus({
31695
+ onItemActivate
31696
+ }) {
31697
+ const { getState } = useMenuContext();
31698
+ const [{ onItemEnter, onItemLeave }] = (0, import_react58.useState)(
31699
+ () => createMenuTriangleHandlers(getState, (itemKey) => {
31700
+ if (!itemKey) {
31701
+ onItemActivate(null);
31702
+ return;
31703
+ }
31704
+ const item = getState().runtimeItems.filter(
31705
+ (item2) => item2.type === "item" && item2.key === itemKey
31706
+ )[0];
31707
+ onItemActivate(item);
31708
+ })
31709
+ );
31267
31710
  return {
31268
31711
  onItemEnter: (0, import_react58.useCallback)(onItemEnter, []),
31269
31712
  onItemLeave: (0, import_react58.useCallback)(onItemLeave, [])
@@ -31272,6 +31715,7 @@ function useSubmenus({
31272
31715
  function MenuComponent(props) {
31273
31716
  const { domProps } = props;
31274
31717
  const {
31718
+ componentState,
31275
31719
  componentState: {
31276
31720
  columns,
31277
31721
  runtimeItems,
@@ -31280,8 +31724,6 @@ function MenuComponent(props) {
31280
31724
  keyboardActiveItemKey,
31281
31725
  constrainTo,
31282
31726
  destroyed,
31283
- onAction,
31284
- wrapLabels,
31285
31727
  onShow,
31286
31728
  onHide,
31287
31729
  autoFocus,
@@ -31299,62 +31741,56 @@ function MenuComponent(props) {
31299
31741
  }, []);
31300
31742
  const isMounted = useMounted();
31301
31743
  const [submenuApi, setSubmenuApi] = (0, import_react58.useState)(null);
31744
+ const shouldSelectFirstItemOnFocus = (0, import_react58.useRef)(true);
31745
+ const [{ api, onMenuFocus, hideAll }] = (0, import_react58.useState)(() => {
31746
+ const hideAll2 = () => hideMenuAndParents(getState);
31747
+ return {
31748
+ hideAll: hideAll2,
31749
+ ...createMenuFocus({
31750
+ getState,
31751
+ setFocused: (focused) => {
31752
+ componentActions.focused = focused;
31753
+ },
31754
+ setKeyboardActiveItemKey,
31755
+ shouldSelectFirstItemOnFocus: () => shouldSelectFirstItemOnFocus.current,
31756
+ hideAll: hideAll2
31757
+ })
31758
+ };
31759
+ });
31302
31760
  let renderedChildren = null;
31303
31761
  (0, import_react58.useLayoutEffect)(() => {
31304
31762
  const { runtimeItems: runtimeItems2 } = getState();
31305
- const activeItem = runtimeItems2.filter(
31306
- (item) => item.type === "item" && activeItemKey === item.key
31307
- )[0];
31308
- if (!activeItem || !activeItem.menu) {
31763
+ const activeItem = getActiveSubmenuItem(runtimeItems2, activeItemKey);
31764
+ if (!activeItem) {
31309
31765
  setSubmenuApi(null);
31310
31766
  clearAll();
31311
31767
  return;
31312
31768
  }
31313
- if (activeItem) {
31314
- const alignTo = getMenuItemRect(menuId, activeItem.key);
31315
- const menu = () => renderSubmenuForItem(activeItem, {
31316
- constrainTo,
31317
- setSubmenuApi,
31318
- setActiveItemKey,
31319
- setKeyboardActiveItemKey,
31320
- parentMenuId: menuId,
31321
- onHideIntent: hideAll,
31322
- api
31323
- });
31324
- if (alignTo) {
31325
- showOverlay(menu, {
31326
- id: `${menuId}-submenu`,
31327
- alignTo,
31328
- alignPosition: [
31329
- ["TopLeft", "TopRight"],
31330
- ["TopRight", "TopLeft"]
31331
- ],
31332
- constrainTo
31333
- });
31334
- }
31335
- return;
31769
+ const overlayParams = getSubmenuOverlayParams(
31770
+ menuId,
31771
+ activeItem,
31772
+ constrainTo
31773
+ );
31774
+ const menu = () => renderSubmenuForItem(activeItem, {
31775
+ constrainTo,
31776
+ setSubmenuApi,
31777
+ setActiveItemKey,
31778
+ setKeyboardActiveItemKey,
31779
+ parentMenuId: menuId,
31780
+ hideAll,
31781
+ api
31782
+ });
31783
+ if (overlayParams) {
31784
+ showOverlay(menu, overlayParams);
31336
31785
  }
31337
31786
  }, [activeItemKey]);
31338
31787
  const onItemClick = (event, item) => {
31339
- setKeyboardActiveItemKey(item.key);
31340
- setActiveItemKey(item.key);
31341
- if (item.originalMenuItem.onClick) {
31342
- item.originalMenuItem.onClick(event);
31343
- }
31344
- const onActionParam = {
31345
- key: item.key,
31346
- item: item.originalMenuItem,
31347
- hideMenu: hideAll
31348
- };
31349
- if (item.originalMenuItem.onAction) {
31350
- item.originalMenuItem.onAction(onActionParam);
31351
- }
31352
- if (onAction) {
31353
- onAction(onActionParam);
31354
- }
31355
- if (item.originalMenuItem.hideMenuOnAction) {
31356
- hideAll();
31357
- }
31788
+ runMenuItemClick(event, item, {
31789
+ getState,
31790
+ setActiveItemKey,
31791
+ setKeyboardActiveItemKey,
31792
+ hideAll
31793
+ });
31358
31794
  };
31359
31795
  const {
31360
31796
  showOverlay,
@@ -31392,158 +31828,27 @@ function MenuComponent(props) {
31392
31828
  onClick: onItemClick
31393
31829
  }
31394
31830
  ));
31395
- const gridTemplateColumns = columns.map((col) => {
31396
- return col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto";
31397
- }).join(" ");
31398
- const style2 = {
31399
- ...domProps.style,
31400
- gridTemplateColumns,
31401
- gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31402
- };
31403
- if (!wrapLabels) {
31404
- style2.whiteSpace = "nowrap";
31405
- }
31831
+ const style2 = getMenuGridStyle(
31832
+ componentState,
31833
+ domProps.style
31834
+ );
31406
31835
  function handleKeydown(keyboardEvent) {
31407
- const { runtimeItems: runtimeItems2, runtimeSelectableItems } = getState();
31408
- let keyboardActiveIndex = runtimeItems2.findIndex(
31409
- (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31410
- );
31411
- let newKeyboardActiveItemKey = keyboardActiveItemKey;
31412
- const keyboardActiveItem = runtimeItems2[keyboardActiveIndex];
31413
- const validKeys3 = {
31414
- ArrowUp: () => {
31415
- const newActiveItem = runtimeItems2.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31416
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31417
- newKeyboardActiveItemKey = newActiveItem.key;
31418
- }
31419
- },
31420
- ArrowDown: () => {
31421
- const newActiveItem = runtimeItems2.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31422
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31423
- newKeyboardActiveItemKey = newActiveItem.key;
31424
- }
31425
- },
31426
- Home: () => {
31427
- validKeys3.PageUp();
31428
- },
31429
- End: () => {
31430
- validKeys3.PageDown();
31431
- },
31432
- PageUp: () => {
31433
- newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31434
- },
31435
- PageDown: () => {
31436
- newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31437
- },
31438
- ArrowLeft: () => {
31439
- setActiveItemKey(null);
31440
- if (getState().parentMenuId) {
31441
- componentActions.destroyed = true;
31442
- }
31443
- },
31444
- ArrowRight: () => {
31445
- if (!keyboardActiveItem) {
31446
- return;
31447
- }
31448
- setActiveItemKey(keyboardActiveItem.key);
31449
- raf(() => {
31450
- if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31451
- submenuApi.focus();
31452
- }
31453
- });
31454
- },
31455
- Enter: () => {
31456
- if (!keyboardActiveItem) {
31457
- return;
31458
- }
31459
- if (keyboardActiveItem.originalMenuItem?.menu) {
31460
- if (keyboardActiveItem && keyboardActiveItem.originalMenuItem.menu && submenuApi) {
31461
- validKeys3.ArrowLeft();
31462
- return;
31463
- }
31464
- if (keyboardActiveItem) {
31465
- setActiveItemKey(keyboardActiveItem.key);
31466
- }
31467
- } else {
31468
- onItemClick(
31469
- keyboardEvent,
31470
- keyboardActiveItem
31471
- );
31472
- }
31473
- },
31474
- " ": () => {
31475
- if (!keyboardActiveItem) {
31476
- return;
31477
- }
31478
- if (!keyboardActiveItem.originalMenuItem.menu) {
31479
- onItemClick(
31480
- keyboardEvent,
31481
- keyboardActiveItem
31482
- );
31483
- }
31484
- const checkbox = getFirstCheckBoxInsideMenuItem(
31485
- menuId,
31486
- keyboardActiveItem.key
31487
- );
31488
- if (!checkbox) {
31489
- return;
31490
- }
31491
- checkbox.click();
31836
+ handleMenuKeyDown(keyboardEvent, {
31837
+ getState,
31838
+ setActiveItemKey,
31839
+ setKeyboardActiveItemKey,
31840
+ destroy: () => {
31841
+ componentActions.destroyed = true;
31492
31842
  },
31493
- Escape: () => {
31494
- validKeys3.ArrowLeft();
31495
- const state = getState();
31496
- if (!state.parentMenuId) {
31497
- state.onHideIntent?.(state);
31498
- }
31499
- }
31500
- };
31501
- const fn = validKeys3[keyboardEvent.key];
31502
- if (fn) {
31503
- fn();
31504
- keyboardEvent.preventDefault();
31505
- }
31506
- if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31507
- setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31508
- }
31843
+ // the submenu api of this render: the raf of ArrowRight reads it
31844
+ getSubmenuApi: () => submenuApi,
31845
+ isMounted,
31846
+ onItemClick
31847
+ });
31509
31848
  }
31510
31849
  function onMenuBlur() {
31511
31850
  componentActions.focused = false;
31512
31851
  }
31513
- const onMenuFocus = (0, import_react58.useCallback)(function() {
31514
- componentActions.focused = true;
31515
- setTimeout(() => {
31516
- if (shouldSelectFirstItemOnFocus.current && domRef.current && domRef.current === document.activeElement && getState().keyboardActiveItemKey == null) {
31517
- setKeyboardActiveItemKey(
31518
- getState().runtimeSelectableItems[0]?.key ?? null
31519
- );
31520
- }
31521
- });
31522
- }, []);
31523
- const shouldSelectFirstItemOnFocus = (0, import_react58.useRef)(true);
31524
- const hideAll = (0, import_react58.useCallback)(() => {
31525
- const state = getState();
31526
- state.onHideIntent?.(state);
31527
- }, [getState]);
31528
- const [api] = (0, import_react58.useState)(() => {
31529
- const result2 = {
31530
- hideMenu: hideAll,
31531
- focus: () => {
31532
- if (domRef.current) {
31533
- domRef.current.focus();
31534
- setTimeout(() => {
31535
- if (domRef.current && domRef.current !== document.activeElement) {
31536
- domRef.current.focus();
31537
- }
31538
- }, 10);
31539
- onMenuFocus();
31540
- }
31541
- },
31542
- getMenuId: () => getState().menuId,
31543
- getParentMenuId: () => getState().parentMenuId
31544
- };
31545
- return result2;
31546
- });
31547
31852
  const refCallback = (0, import_react58.useCallback)((node) => {
31548
31853
  if (node) {
31549
31854
  domRef.current = node;
@@ -31588,44 +31893,20 @@ function MenuComponent(props) {
31588
31893
  function RuntimeItemRenderer(props) {
31589
31894
  const [pressed, setPressed] = React61.useState(false);
31590
31895
  const { columns, item, index, active, keyboardActive } = props;
31591
- const key = item.type === "item" ? item.value.key : index;
31592
31896
  let content = null;
31593
31897
  if (item.type === "decoration") {
31594
31898
  content = /* @__PURE__ */ React61.createElement("div", { style: item.style }, item.value);
31595
31899
  } else {
31596
- let spanIndex = 0;
31597
- content = columns.map((col, i) => {
31598
- const target = item.value;
31599
- const field = col.field || col.name;
31600
- const start = i + 1;
31601
- const end = start + item.span;
31602
- if (start < spanIndex) {
31603
- return null;
31604
- }
31605
- spanIndex = end;
31606
- const style2 = {
31607
- ...col.style,
31608
- ...item.style,
31609
- gridColumnStart: start,
31610
- gridColumnEnd: end
31611
- };
31900
+ content = getMenuItemCells(item, columns, index, {
31901
+ active,
31902
+ keyboardActive,
31903
+ pressed
31904
+ }).map((cell) => {
31905
+ const col = cell.column;
31612
31906
  const domProps = {
31613
- style: style2,
31614
- //@ts-ignore
31615
- "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31616
- "data-menu-col-name": `${col.name}`,
31617
- "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31618
- "data-menu-row-index": `${index}`,
31619
- "data-menu-item-key": `${item.key}`,
31620
- className: join(
31621
- MenuItemCls({
31622
- active,
31623
- disabled: !!item.disabled,
31624
- keyboardActive,
31625
- pressed: pressed || props.active
31626
- }),
31627
- item.className
31628
- ),
31907
+ style: cell.style,
31908
+ ...cell.dataAttributes,
31909
+ className: cell.className,
31629
31910
  onPointerEnter: (event) => {
31630
31911
  if (!item.disabled) {
31631
31912
  props.onItemEnter?.(item, event);
@@ -31655,17 +31936,17 @@ function RuntimeItemRenderer(props) {
31655
31936
  return col.render ? /* @__PURE__ */ React61.createElement(
31656
31937
  RenderHookComponent,
31657
31938
  {
31658
- key: `${key}-${field}`,
31939
+ key: cell.key,
31659
31940
  render: col.render,
31660
31941
  renderParam: {
31661
- item: target,
31942
+ item: item.value,
31662
31943
  column: col,
31663
- value: target[field],
31944
+ value: cell.value,
31664
31945
  domProps
31665
31946
  }
31666
31947
  }
31667
- ) : /* @__PURE__ */ React61.createElement("div", { key: `${key}-${field}`, ...domProps }, target[field]);
31668
- }).filter(Boolean);
31948
+ ) : /* @__PURE__ */ React61.createElement("div", { key: cell.key, ...domProps }, cell.value);
31949
+ });
31669
31950
  }
31670
31951
  return /* @__PURE__ */ React61.createElement("div", { className: MenuRowCls }, content);
31671
31952
  }
@@ -31730,9 +32011,64 @@ Menu[propToIdentifyMenu] = true;
31730
32011
 
31731
32012
  // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
31732
32013
  var React63 = __toESM(require("react"));
31733
- function defaultGetColumnMenuItems(_items, params) {
31734
- const { columnApi, column, getComputed, api, dataSourceApi, getState } = params;
31735
- const CheckBoxCmp = getState().components?.CheckBox || InfiniteCheckBox;
32014
+
32015
+ // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
32016
+ function getMenuItemsAndColumns(menuDefinition) {
32017
+ let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
32018
+ const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
32019
+ return {
32020
+ items,
32021
+ columns
32022
+ };
32023
+ }
32024
+ function getMenuVisibilityProps(onHideIntent) {
32025
+ const onRootMouseDown = (event) => {
32026
+ event.__insideMenu = true;
32027
+ };
32028
+ const onHide = (state) => {
32029
+ state.domRef.current?.parentNode?.removeEventListener(
32030
+ "mousedown",
32031
+ onRootMouseDown
32032
+ );
32033
+ };
32034
+ return {
32035
+ onShow: (state) => {
32036
+ state.domRef.current?.parentNode?.addEventListener(
32037
+ "mousedown",
32038
+ onRootMouseDown
32039
+ );
32040
+ },
32041
+ onHide,
32042
+ onHideIntent: (state) => {
32043
+ onHide(state);
32044
+ onHideIntent?.();
32045
+ }
32046
+ };
32047
+ }
32048
+ function getMenuDefaultProps(config) {
32049
+ const menuDefaultProps = {
32050
+ columns: [],
32051
+ items: [],
32052
+ autoFocus: true,
32053
+ ...getMenuVisibilityProps(config.onHideIntent)
32054
+ };
32055
+ return menuDefaultProps;
32056
+ }
32057
+ function getLazyMenuProps(menuDefinition, menuDefaultProps) {
32058
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32059
+ if (items && items.length) {
32060
+ return {
32061
+ ...menuDefaultProps,
32062
+ items: items || [],
32063
+ columns
32064
+ };
32065
+ }
32066
+ return null;
32067
+ }
32068
+
32069
+ // src/components/InfiniteTable/utils/menuItemsShared.ts
32070
+ function getDefaultColumnMenuItems(params, binder) {
32071
+ const { columnApi, column, getComputed, api, dataSourceApi } = params;
31736
32072
  const sortable = columnApi.isSortable();
31737
32073
  const sortItems = sortable ? [
31738
32074
  {
@@ -31813,25 +32149,22 @@ function defaultGetColumnMenuItems(_items, params) {
31813
32149
  const colItems = [];
31814
32150
  const computed = getComputed();
31815
32151
  computed.computedColumnsMapInInitialOrder.forEach((col, id) => {
31816
- const label = getColumnLabel(col, params, "column-menu");
32152
+ const label = binder.getColumnLabel(col);
31817
32153
  colItems.push({
31818
32154
  key: id,
31819
32155
  label,
31820
- check: /* @__PURE__ */ React63.createElement(
31821
- CheckBoxCmp,
31822
- {
31823
- key: col.id,
31824
- disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
31825
- checked: col.computedVisible,
31826
- onChange: (checked) => {
31827
- const visible = !!checked;
31828
- api.setVisibilityForColumn(col.id, visible);
31829
- requestAnimationFrame(() => {
31830
- api.realignColumnContextMenu();
31831
- });
31832
- }
32156
+ check: binder.renderCheckBox({
32157
+ key: col.id,
32158
+ disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
32159
+ checked: col.computedVisible,
32160
+ onChange: (checked) => {
32161
+ const visible = !!checked;
32162
+ api.setVisibilityForColumn(col.id, visible);
32163
+ requestAnimationFrame(() => {
32164
+ api.realignColumnContextMenu();
32165
+ });
31833
32166
  }
31834
- )
32167
+ })
31835
32168
  });
31836
32169
  });
31837
32170
  return {
@@ -31856,21 +32189,18 @@ function defaultGetColumnMenuItems(_items, params) {
31856
32189
  if (col.groupByForColumn) {
31857
32190
  return;
31858
32191
  }
31859
- const label = getColumnLabel(col, params, "column-menu");
32192
+ const label = binder.getColumnLabel(col);
31860
32193
  colItems.push({
31861
32194
  key: id,
31862
32195
  label,
31863
- check: /* @__PURE__ */ React63.createElement(
31864
- CheckBoxCmp,
31865
- {
31866
- key: col.id,
31867
- disabled: !col.computedGroupable,
31868
- checked: col.computedGroupedBy,
31869
- onChange: () => {
31870
- dataSourceApi.toggleGroupByField(col.field);
31871
- }
32196
+ check: binder.renderCheckBox({
32197
+ key: col.id,
32198
+ disabled: !col.computedGroupable,
32199
+ checked: col.computedGroupedBy,
32200
+ onChange: () => {
32201
+ dataSourceApi.toggleGroupByField(col.field);
31872
32202
  }
31873
- )
32203
+ })
31874
32204
  });
31875
32205
  });
31876
32206
  return {
@@ -31886,15 +32216,12 @@ function defaultGetColumnMenuItems(_items, params) {
31886
32216
  }
31887
32217
  ].filter((x) => !!x);
31888
32218
  }
31889
-
31890
- // src/components/InfiniteTable/utils/getMenuForColumn.tsx
31891
- function getMenuForColumn(columnId, context, onHideIntent) {
32219
+ function getColumnMenuProps(columnId, context, onHideIntent, getDefaultItems) {
31892
32220
  if (columnId == null) {
31893
32221
  return null;
31894
32222
  }
31895
32223
  const { getComputed, getState } = context;
31896
- const { components: components2, getColumnMenuItems } = getState();
31897
- const MenuCmp = components2?.Menu ?? Menu;
32224
+ const { getColumnMenuItems } = getState();
31898
32225
  const column = getComputed().computedColumnsMap.get(columnId);
31899
32226
  if (!column) {
31900
32227
  return null;
@@ -31904,38 +32231,192 @@ function getMenuForColumn(columnId, context, onHideIntent) {
31904
32231
  columnApi: getColumnApiForColumn(column.id, context),
31905
32232
  ...context
31906
32233
  };
31907
- const defaultItems = defaultGetColumnMenuItems([], param);
32234
+ const defaultItems = getDefaultItems(param);
31908
32235
  const items = getColumnMenuItems ? getColumnMenuItems(defaultItems, param) : defaultItems;
31909
- const onRootMouseDown = (event) => {
31910
- event.__insideMenu = true;
31911
- };
31912
- const onHide = (state) => {
31913
- state.domRef.current?.parentNode?.removeEventListener(
31914
- "mousedown",
31915
- onRootMouseDown
31916
- );
31917
- };
31918
32236
  if (!items || !items.length) {
31919
32237
  return null;
31920
32238
  }
31921
- return /* @__PURE__ */ React64.createElement(
31922
- MenuCmp,
31923
- {
31924
- autoFocus: true,
31925
- items,
31926
- onShow: (state) => {
31927
- state.domRef.current?.parentNode?.addEventListener(
31928
- "mousedown",
31929
- onRootMouseDown
31930
- );
32239
+ return {
32240
+ autoFocus: true,
32241
+ items,
32242
+ ...getMenuVisibilityProps(onHideIntent)
32243
+ };
32244
+ }
32245
+ function getFilterOperatorMenuProps(columnId, context, onHideIntent, binder) {
32246
+ if (columnId == null) {
32247
+ return null;
32248
+ }
32249
+ const {
32250
+ getComputed,
32251
+ getState,
32252
+ getDataSourceState,
32253
+ actions,
32254
+ dataSourceApi,
32255
+ dataSourceActions,
32256
+ api
32257
+ } = context;
32258
+ const { getFilterOperatorMenuItems } = getState();
32259
+ const column = getComputed().computedColumnsMap.get(columnId);
32260
+ if (!column) {
32261
+ return null;
32262
+ }
32263
+ const { filterTypes } = getDataSourceState();
32264
+ const columnFilterType = filterTypes[column.computedFilterType];
32265
+ if (!columnFilterType) {
32266
+ return null;
32267
+ }
32268
+ const operatorItems = columnFilterType.operators.map((operator) => {
32269
+ const key = operator.name;
32270
+ const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32271
+ return {
32272
+ key,
32273
+ icon: binder.renderOperatorIcon(operator),
32274
+ label: binder.renderOperatorLabel(operator.label ?? operator.name),
32275
+ onAction: () => {
32276
+ api.setColumnFilterOperator(columnId, key);
31931
32277
  },
31932
- onHide,
31933
- onHideIntent: (state) => {
31934
- onHide(state);
31935
- onHideIntent?.();
32278
+ checked: checked ? binder.renderDoneIcon() : null
32279
+ };
32280
+ });
32281
+ const firstItems = [
32282
+ {
32283
+ key: "close",
32284
+ label: "Close Menu",
32285
+ icon: null,
32286
+ onAction: () => {
32287
+ api.hideFilterOperatorMenu();
31936
32288
  }
31937
- }
32289
+ },
32290
+ {
32291
+ key: "reset",
32292
+ label: "Reset",
32293
+ icon: binder.renderClearIcon(),
32294
+ disabled: !column.computedFiltered,
32295
+ onAction: () => {
32296
+ api.clearColumnFilter(columnId);
32297
+ }
32298
+ },
32299
+ "-"
32300
+ ];
32301
+ const defaultItems = [...firstItems, ...operatorItems];
32302
+ const param = {
32303
+ column,
32304
+ api,
32305
+ getState,
32306
+ getDataSourceState,
32307
+ getComputed,
32308
+ actions,
32309
+ dataSourceApi,
32310
+ dataSourceActions,
32311
+ columnFilterValue: column.computedFilterValue,
32312
+ filterTypes
32313
+ };
32314
+ const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32315
+ return {
32316
+ autoFocus: true,
32317
+ columns: [
32318
+ {
32319
+ name: "icon"
32320
+ },
32321
+ { name: "label" },
32322
+ { name: "checked" }
32323
+ ],
32324
+ items,
32325
+ ...getMenuVisibilityProps(onHideIntent)
32326
+ };
32327
+ }
32328
+ function getContextMenuContent(menuDefinition, menuDefaultProps, binder) {
32329
+ const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32330
+ if (menuDefinition instanceof Promise) {
32331
+ return {
32332
+ menu: binder.renderLazyMenu(menuDefinition, menuDefaultProps),
32333
+ preventDefault
32334
+ };
32335
+ }
32336
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32337
+ if (!items || !items.length) {
32338
+ return { menu: null, preventDefault: Array.isArray(items) };
32339
+ }
32340
+ return {
32341
+ preventDefault,
32342
+ menu: binder.renderMenu({ ...menuDefaultProps, columns, items })
32343
+ };
32344
+ }
32345
+ function getCellContextMenuContent(cellLocation, context, onHideIntent, binder) {
32346
+ const { columnId, rowIndex, event } = cellLocation;
32347
+ const { getComputed, getState } = context;
32348
+ const { getCellContextMenuItems } = getState();
32349
+ const { computedColumnsMap } = getComputed();
32350
+ const column = computedColumnsMap.get(columnId);
32351
+ const cellContext = {
32352
+ ...getCellContext({
32353
+ ...context,
32354
+ rowIndex,
32355
+ columnId: column.id
32356
+ }),
32357
+ event
32358
+ };
32359
+ if (!column || !getCellContextMenuItems) {
32360
+ return {
32361
+ cellContext,
32362
+ menu: null,
32363
+ preventDefault: false
32364
+ };
32365
+ }
32366
+ const menuDefaultProps = getMenuDefaultProps({
32367
+ onHideIntent
32368
+ });
32369
+ const menuDefinition = getCellContextMenuItems(cellContext, context);
32370
+ return {
32371
+ cellContext,
32372
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32373
+ };
32374
+ }
32375
+ function getTableContextMenuContent(menuLocation, context, onHideIntent, binder) {
32376
+ const { getState, getComputed } = context;
32377
+ const { getContextMenuItems } = getState();
32378
+ const { computedColumnsMap } = getComputed();
32379
+ const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32380
+ const cellContext = column ? {
32381
+ ...menuLocation,
32382
+ ...getCellContext({
32383
+ ...context,
32384
+ rowIndex: menuLocation.rowIndex,
32385
+ columnId: column.id
32386
+ })
32387
+ } : menuLocation;
32388
+ if (!getContextMenuItems) {
32389
+ return { cellContext, menu: null, preventDefault: false };
32390
+ }
32391
+ const menuDefaultProps = getMenuDefaultProps({
32392
+ onHideIntent
32393
+ });
32394
+ const menuDefinition = getContextMenuItems(cellContext, context);
32395
+ return {
32396
+ cellContext,
32397
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32398
+ };
32399
+ }
32400
+
32401
+ // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
32402
+ function defaultGetColumnMenuItems(_items, params) {
32403
+ const CheckBoxCmp = params.getState().components?.CheckBox || InfiniteCheckBox;
32404
+ return getDefaultColumnMenuItems(params, {
32405
+ renderCheckBox: ({ key, ...props }) => /* @__PURE__ */ React63.createElement(CheckBoxCmp, { key, ...props }),
32406
+ getColumnLabel: (col) => getColumnLabel(col, params, "column-menu")
32407
+ });
32408
+ }
32409
+
32410
+ // src/components/InfiniteTable/utils/getMenuForColumn.tsx
32411
+ function getMenuForColumn(columnId, context, onHideIntent) {
32412
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32413
+ const menuProps = getColumnMenuProps(
32414
+ columnId,
32415
+ context,
32416
+ onHideIntent,
32417
+ (param) => defaultGetColumnMenuItems([], param)
31938
32418
  );
32419
+ return menuProps ? /* @__PURE__ */ React64.createElement(MenuCmp, { ...menuProps }) : null;
31939
32420
  }
31940
32421
 
31941
32422
  // src/components/InfiniteTable/utils/menuOverlayTargets.ts
@@ -31952,31 +32433,55 @@ function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer)
31952
32433
  return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
31953
32434
  }
31954
32435
 
31955
- // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
31956
- var import_react59 = require("react");
31957
- function useMenuPortalContainer() {
31958
- const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
31959
- return {
31960
- getState: ctx.getState,
31961
- menuPortalContainer: ctx.state.menuPortalContainer
31962
- };
31963
- });
31964
- const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
31965
- return {
31966
- portalDOMRef: ctx.getMasterState().portalDOMRef
31967
- };
31968
- }) || {};
31969
- const defaultContainer = portalDOMRef?.current;
31970
- return (0, import_react59.useMemo)(
31971
- () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
31972
- [getState, menuPortalContainer, defaultContainer]
31973
- );
32436
+ // src/components/InfiniteTable/utils/menuOverlayShared.ts
32437
+ var CONTEXT_MENU_OFFSET = 5;
32438
+ var CONTEXT_MENU_ALIGN_POSITIONS = [
32439
+ ["TopLeft", "BottomLeft"],
32440
+ ["TopRight", "BottomRight"],
32441
+ ["BottomLeft", "BottomLeft"],
32442
+ ["BottomRight", "BottomRight"],
32443
+ ["TopCenter", "TopLeft"],
32444
+ ["BottomCenter", "TopLeft"],
32445
+ ["CenterLeft", "TopLeft"],
32446
+ ["CenterRight", "TopLeft"]
32447
+ ];
32448
+ var FILTER_OPERATOR_MENU_OFFSET = 10;
32449
+ function closeMenuOnOutsideMouseDown(close) {
32450
+ function handleMouseDown(event) {
32451
+ if (event.__insideMenu !== true) {
32452
+ close();
32453
+ }
32454
+ }
32455
+ document.documentElement.addEventListener("mousedown", handleMouseDown);
32456
+ return () => {
32457
+ document.documentElement.removeEventListener("mousedown", handleMouseDown);
32458
+ };
32459
+ }
32460
+ function menuVisibilityEffect(visible, clearAll, hide) {
32461
+ if (visible) {
32462
+ return closeMenuOnOutsideMouseDown(() => {
32463
+ clearAll();
32464
+ hide();
32465
+ });
32466
+ }
32467
+ clearAll();
32468
+ return void 0;
32469
+ }
32470
+ function getColumnMenuClickHandler(context) {
32471
+ const { getState, actions } = context;
32472
+ return (info) => {
32473
+ if (!info) {
32474
+ return;
32475
+ }
32476
+ getState().columnMenuTargetRef.current = info.target;
32477
+ actions.contextMenuVisibleFor = null;
32478
+ actions.cellContextMenuVisibleFor = null;
32479
+ actions.filterOperatorMenuVisibleForColumnId = null;
32480
+ actions.columnMenuVisibleForColumnId = info.column.id;
32481
+ };
31974
32482
  }
31975
-
31976
- // src/components/InfiniteTable/hooks/useColumnMenu.ts
31977
- var menuIconSelector2 = `[${MenuIconDataAttributes["data-name"]}="${MenuIconDataAttributesValues["data-name"]}"]`;
31978
32483
  function showMenuForColumn(options) {
31979
- const { columnId, context, clearAll, showOverlay } = options;
32484
+ const { columnId, context, clearAll, show } = options;
31980
32485
  const { getState, actions } = context;
31981
32486
  const { columnMenuTargetRef, domRef } = getState();
31982
32487
  function onHideIntent() {
@@ -31991,7 +32496,7 @@ function showMenuForColumn(options) {
31991
32496
  }
31992
32497
  }
31993
32498
  if (!target) {
31994
- const iconSelector = `[${InfiniteHeaderCellDataAttributes["data-column-id"]}="${columnId}"] ${menuIconSelector2}`;
32499
+ const iconSelector = `[data-column-id="${columnId}"] ${menuIconSelector}`;
31995
32500
  target = getState().domRef.current.querySelector(
31996
32501
  iconSelector
31997
32502
  );
@@ -32001,7 +32506,7 @@ function showMenuForColumn(options) {
32001
32506
  return;
32002
32507
  }
32003
32508
  columnMenuTargetRef.current = null;
32004
- showOverlay(() => getMenuForColumn(columnId, context, onHideIntent), {
32509
+ show(onHideIntent, {
32005
32510
  constrainTo: getMenuConstrainTo(getState()),
32006
32511
  id: "column-menu",
32007
32512
  alignTo: target,
@@ -32011,17 +32516,180 @@ function showMenuForColumn(options) {
32011
32516
  ]
32012
32517
  });
32013
32518
  }
32519
+ function columnMenuVisibilityEffect(context, overlay) {
32520
+ const { getState, actions } = context;
32521
+ const { clearAll } = overlay;
32522
+ const { columnMenuVisibleForColumnId, columnMenuTargetRef } = getState();
32523
+ if (columnMenuVisibleForColumnId) {
32524
+ const cleanup = closeMenuOnOutsideMouseDown(() => {
32525
+ clearAll();
32526
+ actions.columnMenuVisibleForColumnId = null;
32527
+ });
32528
+ showMenuForColumn({
32529
+ columnId: columnMenuVisibleForColumnId,
32530
+ context,
32531
+ clearAll,
32532
+ show: (onHideIntent, params) => overlay.show(columnMenuVisibleForColumnId, onHideIntent, params)
32533
+ });
32534
+ return cleanup;
32535
+ }
32536
+ columnMenuTargetRef.current = null;
32537
+ clearAll();
32538
+ return void 0;
32539
+ }
32540
+ function getContextMenuRect(event) {
32541
+ const point = {
32542
+ top: event.clientY,
32543
+ left: event.clientX
32544
+ };
32545
+ const rect = Rectangle.fromPoint(point);
32546
+ rect.width += CONTEXT_MENU_OFFSET;
32547
+ rect.height += CONTEXT_MENU_OFFSET;
32548
+ return { point, rect };
32549
+ }
32550
+ function getCellContextMenuHandler(context, overlay) {
32551
+ const { actions, getState, getDataSourceState } = context;
32552
+ const { clearAll } = overlay;
32553
+ return (info) => {
32554
+ if (!info) {
32555
+ return;
32556
+ }
32557
+ const { event } = info;
32558
+ function onHideIntent() {
32559
+ clearAll();
32560
+ actions.cellContextMenuVisibleFor = null;
32561
+ }
32562
+ const content = overlay.getContent(info, onHideIntent);
32563
+ const { cellContext, preventDefault } = content;
32564
+ const { rect } = getContextMenuRect(event);
32565
+ overlay.show(content, {
32566
+ constrainTo: getMenuConstrainTo(getState()),
32567
+ id: "cell-context-menu",
32568
+ alignTo: rect,
32569
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32570
+ });
32571
+ if (preventDefault) {
32572
+ event.preventDefault();
32573
+ }
32574
+ actions.cellContextMenuVisibleFor = {
32575
+ columnId: info.columnId,
32576
+ rowId: info.rowId,
32577
+ rowIndex: info.rowIndex,
32578
+ colIndex: info.colIndex
32579
+ };
32580
+ const { onCellContextMenu } = getState();
32581
+ if (onCellContextMenu) {
32582
+ onCellContextMenu(
32583
+ {
32584
+ ...cellContext,
32585
+ getState,
32586
+ getDataSourceState
32587
+ },
32588
+ event
32589
+ );
32590
+ }
32591
+ };
32592
+ }
32593
+ function getTableContextMenuHandler(context, overlay) {
32594
+ const { actions, getState } = context;
32595
+ const { clearAll } = overlay;
32596
+ return (info) => {
32597
+ if (!info) {
32598
+ return;
32599
+ }
32600
+ const { event } = info;
32601
+ function onHideIntent() {
32602
+ clearAll();
32603
+ actions.contextMenuVisibleFor = null;
32604
+ }
32605
+ const content = overlay.getContent(info, onHideIntent);
32606
+ const { cellContext, preventDefault } = content;
32607
+ const { point, rect } = getContextMenuRect(event);
32608
+ overlay.show(content, {
32609
+ constrainTo: getMenuConstrainTo(getState()),
32610
+ id: "table-context-menu",
32611
+ alignTo: rect,
32612
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32613
+ });
32614
+ if (preventDefault) {
32615
+ event.preventDefault();
32616
+ }
32617
+ actions.contextMenuVisibleFor = {
32618
+ point,
32619
+ ...info
32620
+ };
32621
+ const { onContextMenu } = getState();
32622
+ if (onContextMenu) {
32623
+ onContextMenu(
32624
+ {
32625
+ ...context,
32626
+ ...cellContext
32627
+ },
32628
+ event
32629
+ );
32630
+ }
32631
+ };
32632
+ }
32633
+ function getFilterOperatorMenuClickHandler(context, overlay) {
32634
+ const { getState, actions } = context;
32635
+ const { clearAll } = overlay;
32636
+ return (info) => {
32637
+ if (!info) {
32638
+ return;
32639
+ }
32640
+ const { target, column } = info;
32641
+ function onHideIntent() {
32642
+ clearAll();
32643
+ actions.filterOperatorMenuVisibleForColumnId = null;
32644
+ }
32645
+ const alignTo = target?.parentElement || target;
32646
+ const rect = Rectangle.from(alignTo.getBoundingClientRect());
32647
+ rect.top -= FILTER_OPERATOR_MENU_OFFSET;
32648
+ rect.left -= FILTER_OPERATOR_MENU_OFFSET;
32649
+ rect.width += 2 * FILTER_OPERATOR_MENU_OFFSET;
32650
+ rect.height += 2 * FILTER_OPERATOR_MENU_OFFSET;
32651
+ overlay.show(column.id, onHideIntent, {
32652
+ constrainTo: getMenuConstrainTo(getState()),
32653
+ id: "filter-operator-menu",
32654
+ alignTo: rect,
32655
+ alignPosition: [
32656
+ ["TopLeft", "BottomLeft"],
32657
+ ["TopRight", "BottomRight"]
32658
+ ]
32659
+ });
32660
+ actions.contextMenuVisibleFor = null;
32661
+ actions.cellContextMenuVisibleFor = null;
32662
+ actions.columnMenuVisibleForColumnId = null;
32663
+ actions.filterOperatorMenuVisibleForColumnId = column.id;
32664
+ };
32665
+ }
32666
+
32667
+ // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
32668
+ var import_react59 = require("react");
32669
+ function useMenuPortalContainer() {
32670
+ const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
32671
+ return {
32672
+ getState: ctx.getState,
32673
+ menuPortalContainer: ctx.state.menuPortalContainer
32674
+ };
32675
+ });
32676
+ const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
32677
+ return {
32678
+ portalDOMRef: ctx.getMasterState().portalDOMRef
32679
+ };
32680
+ }) || {};
32681
+ const defaultContainer = portalDOMRef?.current;
32682
+ return (0, import_react59.useMemo)(
32683
+ () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
32684
+ [getState, menuPortalContainer, defaultContainer]
32685
+ );
32686
+ }
32687
+
32688
+ // src/components/InfiniteTable/hooks/useColumnMenu.ts
32014
32689
  function useColumnMenu() {
32015
32690
  const context = useInfiniteTableStableContext();
32016
- const {
32017
- getState,
32018
- actions,
32019
- columnMenuVisibleForColumnId,
32020
- columnMenuVisibleKey
32021
- } = useInfiniteTableSelector((ctx) => {
32691
+ const { columnMenuVisibleForColumnId, columnMenuVisibleKey } = useInfiniteTableSelector((ctx) => {
32022
32692
  return {
32023
- getState: ctx.getState,
32024
- actions: ctx.actions,
32025
32693
  columnMenuVisibleForColumnId: ctx.state.columnMenuVisibleForColumnId,
32026
32694
  columnMenuVisibleKey: ctx.state.columnMenuVisibleKey
32027
32695
  };
@@ -32034,47 +32702,16 @@ function useColumnMenu() {
32034
32702
  portalContainer: useMenuPortalContainer()
32035
32703
  });
32036
32704
  (0, import_react60.useEffect)(() => {
32037
- const state = getState();
32038
- return state.onColumnMenuClick.onChange((info) => {
32039
- if (!info) {
32040
- return;
32041
- }
32042
- state.columnMenuTargetRef.current = info.target;
32043
- actions.contextMenuVisibleFor = null;
32044
- actions.cellContextMenuVisibleFor = null;
32045
- actions.filterOperatorMenuVisibleForColumnId = null;
32046
- actions.columnMenuVisibleForColumnId = info.column.id;
32047
- });
32705
+ return context.getState().onColumnMenuClick.onChange(getColumnMenuClickHandler(context));
32048
32706
  }, []);
32049
32707
  (0, import_react60.useEffect)(() => {
32050
- const { columnMenuVisibleForColumnId: columnMenuVisibleForColumnId2, columnMenuTargetRef } = getState();
32051
- if (columnMenuVisibleForColumnId2) {
32052
- let handleMouseDown2 = function(event) {
32053
- if (event.__insideMenu !== true) {
32054
- clearAll();
32055
- actions.columnMenuVisibleForColumnId = null;
32056
- }
32057
- };
32058
- var handleMouseDown = handleMouseDown2;
32059
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32060
- showMenuForColumn({
32061
- columnId: columnMenuVisibleForColumnId2,
32062
- context,
32063
- clearAll,
32064
- showOverlay
32065
- });
32066
- return () => {
32067
- document.documentElement.removeEventListener(
32068
- "mousedown",
32069
- handleMouseDown2
32070
- );
32071
- };
32072
- } else {
32073
- columnMenuTargetRef.current = null;
32074
- clearAll();
32075
- }
32076
- return () => {
32077
- };
32708
+ return columnMenuVisibilityEffect(context, {
32709
+ clearAll,
32710
+ show: (columnId, onHideIntent, params) => showOverlay(
32711
+ () => getMenuForColumn(columnId, context, onHideIntent),
32712
+ params
32713
+ )
32714
+ });
32078
32715
  }, [columnMenuVisibleForColumnId, columnMenuVisibleKey]);
32079
32716
  return { menuPortal };
32080
32717
  }
@@ -32257,149 +32894,59 @@ function useOnEditPersisted() {
32257
32894
  };
32258
32895
  if (persisted instanceof Error) {
32259
32896
  onEditPersistError?.({ ...params, error: persisted });
32260
- } else {
32261
- onEditPersistSuccess?.(params);
32262
- }
32263
- }
32264
- }, [persisted]);
32265
- }
32266
- function useEditingCallbackProps() {
32267
- useOnEditCancelled();
32268
- useOnEditRejected();
32269
- useOnEditAccepted();
32270
- useOnEditPersisted();
32271
- useFocusOnEditStop();
32272
- }
32273
-
32274
- // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32275
- var import_react63 = require("react");
32276
-
32277
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32278
- var React68 = __toESM(require("react"));
32279
-
32280
- // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32281
- var React66 = __toESM(require("react"));
32282
- var ClearIcon = (props) => {
32283
- return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32284
- };
32285
-
32286
- // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32287
- var React67 = __toESM(require("react"));
32288
- var DoneIcon = (props) => {
32289
- return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32290
- };
32291
-
32292
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32293
- function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32294
- if (columnId == null) {
32295
- return null;
32296
- }
32297
- const {
32298
- getComputed,
32299
- getState,
32300
- getDataSourceState,
32301
- actions,
32302
- dataSourceApi,
32303
- dataSourceActions,
32304
- api
32305
- } = context;
32306
- const { components: components2, getFilterOperatorMenuItems } = getState();
32307
- const MenuCmp = components2?.Menu ?? Menu;
32308
- const column = getComputed().computedColumnsMap.get(columnId);
32309
- if (!column) {
32310
- return null;
32311
- }
32312
- const onRootMouseDown = (event) => {
32313
- event.__insideMenu = true;
32314
- };
32315
- const onHide = (state) => {
32316
- state.domRef.current?.parentNode?.removeEventListener(
32317
- "mousedown",
32318
- onRootMouseDown
32319
- );
32320
- };
32321
- const { filterTypes } = getDataSourceState();
32322
- const columnFilterType = filterTypes[column.computedFilterType];
32323
- if (!columnFilterType) {
32324
- return null;
32325
- }
32326
- const operatorItems = columnFilterType.operators.map((operator) => {
32327
- const key = operator.name;
32328
- const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32329
- const IconCmp = operator.components?.Icon ?? FilterIcon;
32330
- return {
32331
- key,
32332
- icon: /* @__PURE__ */ React68.createElement(IconCmp, null),
32333
- label: /* @__PURE__ */ React68.createElement(React68.Fragment, null, operator.label ?? operator.name),
32334
- onAction: () => {
32335
- api.setColumnFilterOperator(columnId, key);
32336
- },
32337
- checked: checked ? /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 }) : null
32338
- };
32339
- });
32340
- const firstItems = [
32341
- {
32342
- key: "close",
32343
- label: "Close Menu",
32344
- icon: null,
32345
- onAction: () => {
32346
- api.hideFilterOperatorMenu();
32347
- }
32348
- },
32349
- {
32350
- key: "reset",
32351
- label: "Reset",
32352
- icon: /* @__PURE__ */ React68.createElement(ClearIcon, null),
32353
- disabled: !column.computedFiltered,
32354
- onAction: () => {
32355
- api.clearColumnFilter(columnId);
32356
- }
32357
- },
32358
- "-"
32359
- ];
32360
- const defaultItems = [...firstItems, ...operatorItems];
32361
- const param = {
32362
- column,
32363
- api,
32364
- getState,
32365
- getDataSourceState,
32366
- getComputed,
32367
- actions,
32368
- dataSourceApi,
32369
- dataSourceActions,
32370
- columnFilterValue: column.computedFilterValue,
32371
- filterTypes
32372
- };
32373
- const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32374
- return /* @__PURE__ */ React68.createElement(
32375
- MenuCmp,
32897
+ } else {
32898
+ onEditPersistSuccess?.(params);
32899
+ }
32900
+ }
32901
+ }, [persisted]);
32902
+ }
32903
+ function useEditingCallbackProps() {
32904
+ useOnEditCancelled();
32905
+ useOnEditRejected();
32906
+ useOnEditAccepted();
32907
+ useOnEditPersisted();
32908
+ useFocusOnEditStop();
32909
+ }
32910
+
32911
+ // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32912
+ var import_react63 = require("react");
32913
+
32914
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32915
+ var React68 = __toESM(require("react"));
32916
+
32917
+ // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32918
+ var React66 = __toESM(require("react"));
32919
+ var ClearIcon = (props) => {
32920
+ return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32921
+ };
32922
+
32923
+ // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32924
+ var React67 = __toESM(require("react"));
32925
+ var DoneIcon = (props) => {
32926
+ return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32927
+ };
32928
+
32929
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32930
+ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32931
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32932
+ const menuProps = getFilterOperatorMenuProps(
32933
+ columnId,
32934
+ context,
32935
+ onHideIntent,
32376
32936
  {
32377
- autoFocus: true,
32378
- columns: [
32379
- {
32380
- name: "icon"
32381
- },
32382
- { name: "label" },
32383
- { name: "checked" }
32384
- ],
32385
- items,
32386
- onShow: (state) => {
32387
- state.domRef.current?.parentNode?.addEventListener(
32388
- "mousedown",
32389
- onRootMouseDown
32390
- );
32937
+ renderOperatorIcon: (operator) => {
32938
+ const IconCmp = operator.components?.Icon ?? FilterIcon;
32939
+ return /* @__PURE__ */ React68.createElement(IconCmp, null);
32391
32940
  },
32392
- onHide,
32393
- onHideIntent: (state) => {
32394
- onHide(state);
32395
- onHideIntent?.();
32396
- }
32941
+ renderOperatorLabel: (label) => /* @__PURE__ */ React68.createElement(React68.Fragment, null, label),
32942
+ renderClearIcon: () => /* @__PURE__ */ React68.createElement(ClearIcon, null),
32943
+ renderDoneIcon: () => /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 })
32397
32944
  }
32398
32945
  );
32946
+ return menuProps ? /* @__PURE__ */ React68.createElement(MenuCmp, { ...menuProps }) : null;
32399
32947
  }
32400
32948
 
32401
32949
  // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32402
- var OFFSET2 = 10;
32403
32950
  function useColumnFilterOperatorMenu() {
32404
32951
  const stableContext = useInfiniteTableStableContext();
32405
32952
  const { getState, actions } = stableContext;
@@ -32411,66 +32958,28 @@ function useColumnFilterOperatorMenu() {
32411
32958
  portalContainer: useMenuPortalContainer()
32412
32959
  });
32413
32960
  (0, import_react63.useEffect)(() => {
32414
- const state = getState();
32415
- return state.onFilterOperatorMenuClick.onChange((info) => {
32416
- if (!info) {
32417
- return;
32418
- }
32419
- const { target, column } = info;
32420
- function onHideIntent() {
32421
- clearAll();
32422
- actions.filterOperatorMenuVisibleForColumnId = null;
32423
- }
32424
- let alignTo = target?.parentElement || target;
32425
- const rect = Rectangle.from(alignTo.getBoundingClientRect());
32426
- rect.top -= OFFSET2;
32427
- rect.left -= OFFSET2;
32428
- rect.width += 2 * OFFSET2;
32429
- rect.height += 2 * OFFSET2;
32430
- showOverlay(
32431
- () => getFilterOperatorMenuForColumn(
32432
- column.id,
32433
- stableContext,
32434
- onHideIntent
32435
- ),
32436
- {
32437
- constrainTo: getMenuConstrainTo(getState()),
32438
- id: "filter-operator-menu",
32439
- alignTo: rect,
32440
- alignPosition: [
32441
- ["TopLeft", "BottomLeft"],
32442
- ["TopRight", "BottomRight"]
32443
- ]
32444
- }
32445
- );
32446
- actions.contextMenuVisibleFor = null;
32447
- actions.cellContextMenuVisibleFor = null;
32448
- actions.columnMenuVisibleForColumnId = null;
32449
- actions.filterOperatorMenuVisibleForColumnId = column.id;
32450
- });
32961
+ return getState().onFilterOperatorMenuClick.onChange(
32962
+ getFilterOperatorMenuClickHandler(stableContext, {
32963
+ clearAll,
32964
+ show: (columnId, onHideIntent, params) => showOverlay(
32965
+ () => getFilterOperatorMenuForColumn(
32966
+ columnId,
32967
+ stableContext,
32968
+ onHideIntent
32969
+ ),
32970
+ params
32971
+ )
32972
+ })
32973
+ );
32451
32974
  }, []);
32452
32975
  (0, import_react63.useEffect)(() => {
32453
- const { filterOperatorMenuVisibleForColumnId } = getState();
32454
- if (filterOperatorMenuVisibleForColumnId) {
32455
- let handleMouseDown2 = function(event) {
32456
- if (event.__insideMenu !== true) {
32457
- clearAll();
32458
- actions.filterOperatorMenuVisibleForColumnId = null;
32459
- }
32460
- };
32461
- var handleMouseDown = handleMouseDown2;
32462
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32463
- return () => {
32464
- document.documentElement.removeEventListener(
32465
- "mousedown",
32466
- handleMouseDown2
32467
- );
32468
- };
32469
- } else {
32470
- clearAll();
32471
- }
32472
- return () => {
32473
- };
32976
+ return menuVisibilityEffect(
32977
+ getState().filterOperatorMenuVisibleForColumnId,
32978
+ clearAll,
32979
+ () => {
32980
+ actions.filterOperatorMenuVisibleForColumnId = null;
32981
+ }
32982
+ );
32474
32983
  }, [getState().filterOperatorMenuVisibleForColumnId]);
32475
32984
  return { menuPortal };
32476
32985
  }
@@ -32483,159 +32992,46 @@ var React70 = __toESM(require("react"));
32483
32992
 
32484
32993
  // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32485
32994
  var React69 = __toESM(require("react"));
32486
-
32487
- // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
32488
- function getMenuItemsAndColumns(menuDefinition) {
32489
- let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
32490
- const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
32491
- return {
32492
- items,
32493
- columns
32494
- };
32495
- }
32496
- function getMenuDefaultProps(config) {
32497
- const onRootMouseDown = (event) => {
32498
- event.__insideMenu = true;
32499
- };
32500
- const onHide = (state) => {
32501
- state.domRef.current?.parentNode?.removeEventListener(
32502
- "mousedown",
32503
- onRootMouseDown
32504
- );
32505
- };
32506
- const menuDefaultProps = {
32507
- columns: [],
32508
- items: [],
32509
- autoFocus: true,
32510
- onShow: (state) => {
32511
- state.domRef.current?.parentNode?.addEventListener(
32512
- "mousedown",
32513
- onRootMouseDown
32514
- );
32515
- },
32516
- onHide,
32517
- onHideIntent: (state) => {
32518
- onHide(state);
32519
- config.onHideIntent?.();
32520
- }
32521
- };
32522
- return menuDefaultProps;
32523
- }
32524
-
32525
- // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32526
32995
  function getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp) {
32527
32996
  if (!menuDefinition) {
32528
32997
  return null;
32529
32998
  }
32530
32999
  const updater = buildSubscriptionCallback();
32531
33000
  menuDefinition.then((menuDefinition2) => {
32532
- const { items, columns } = getMenuItemsAndColumns(menuDefinition2);
32533
- if (items && items.length) {
32534
- updater(
32535
- /* @__PURE__ */ React69.createElement(MenuCmp, { ...menuDefaultProps, items: items || [], columns })
32536
- );
33001
+ const menuProps = getLazyMenuProps(menuDefinition2, menuDefaultProps);
33002
+ if (menuProps) {
33003
+ updater(/* @__PURE__ */ React69.createElement(MenuCmp, { ...menuProps }));
32537
33004
  }
32538
33005
  });
32539
33006
  return /* @__PURE__ */ React69.createElement(AvoidReactDiff, { updater });
32540
33007
  }
32541
33008
 
32542
33009
  // src/components/InfiniteTable/utils/getCellContextMenu.tsx
32543
- function getCellContextMenu(cellLocation, context, onHideIntent) {
32544
- const { columnId, rowIndex, event } = cellLocation;
32545
- const { getComputed, getState } = context;
32546
- const { components: components2, getCellContextMenuItems } = getState();
32547
- const MenuCmp = components2?.Menu ?? Menu;
32548
- const { computedColumnsMap } = getComputed();
32549
- const column = computedColumnsMap.get(columnId);
32550
- const cellContext = {
32551
- ...getCellContext({
32552
- ...context,
32553
- rowIndex,
32554
- columnId: column.id
32555
- }),
32556
- event
32557
- };
32558
- if (!column || !getCellContextMenuItems) {
32559
- return {
32560
- cellContext,
32561
- menu: null,
32562
- preventDefault: false
32563
- };
32564
- }
32565
- const menuDefaultProps = getMenuDefaultProps({
32566
- onHideIntent
32567
- });
32568
- const menuDefinition = getCellContextMenuItems(cellContext, context);
32569
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32570
- if (menuDefinition instanceof Promise) {
32571
- return {
32572
- cellContext,
32573
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32574
- preventDefault
32575
- };
32576
- }
32577
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32578
- if (!items || !items.length) {
32579
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32580
- }
33010
+ function getContextMenuBinder(context) {
33011
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32581
33012
  return {
32582
- preventDefault,
32583
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32584
- cellContext
33013
+ renderMenu: (props) => /* @__PURE__ */ React70.createElement(MenuCmp, { ...props }),
33014
+ renderLazyMenu: (menuDefinition, menuDefaultProps) => getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp)
32585
33015
  };
32586
33016
  }
33017
+ function getCellContextMenu(cellLocation, context, onHideIntent) {
33018
+ return getCellContextMenuContent(
33019
+ cellLocation,
33020
+ context,
33021
+ onHideIntent,
33022
+ getContextMenuBinder(context)
33023
+ );
33024
+ }
32587
33025
  function getTableContextMenu(menuLocation, context, onHideIntent) {
32588
- const { getState, getComputed } = context;
32589
- const { components: components2, getContextMenuItems } = getState();
32590
- const MenuCmp = components2?.Menu ?? Menu;
32591
- const { computedColumnsMap } = getComputed();
32592
- const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32593
- const cellContext = column ? {
32594
- ...menuLocation,
32595
- ...getCellContext({
32596
- ...context,
32597
- rowIndex: menuLocation.rowIndex,
32598
- columnId: column.id
32599
- })
32600
- } : menuLocation;
32601
- if (!getContextMenuItems) {
32602
- return { cellContext, menu: null, preventDefault: false };
32603
- }
32604
- const menuDefaultProps = getMenuDefaultProps({
32605
- onHideIntent
32606
- });
32607
- const menuDefinition = getContextMenuItems(cellContext, context);
32608
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32609
- if (menuDefinition instanceof Promise) {
32610
- return {
32611
- cellContext,
32612
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32613
- preventDefault
32614
- };
32615
- }
32616
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32617
- if (!items || !items.length) {
32618
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32619
- }
32620
- return {
32621
- preventDefault,
32622
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32623
- cellContext
32624
- };
33026
+ return getTableContextMenuContent(
33027
+ menuLocation,
33028
+ context,
33029
+ onHideIntent,
33030
+ getContextMenuBinder(context)
33031
+ );
32625
33032
  }
32626
33033
 
32627
33034
  // src/components/InfiniteTable/hooks/useContextMenu.ts
32628
- var OFFSET3 = 5;
32629
- var ALIGN_POSITIONS = [
32630
- ["TopLeft", "BottomLeft"],
32631
- ["TopRight", "BottomRight"],
32632
- ["BottomLeft", "BottomLeft"],
32633
- ["BottomRight", "BottomRight"],
32634
- ["TopCenter", "TopLeft"],
32635
- ["BottomCenter", "TopLeft"],
32636
- ["CenterLeft", "TopLeft"],
32637
- ["CenterRight", "TopLeft"]
32638
- ];
32639
33035
  function useCellContextMenu() {
32640
33036
  const context = useInfiniteTableStableContext();
32641
33037
  const { getState, actions } = context;
@@ -32647,78 +33043,22 @@ function useCellContextMenu() {
32647
33043
  portalContainer: useMenuPortalContainer()
32648
33044
  });
32649
33045
  (0, import_react64.useEffect)(() => {
32650
- const { actions: actions2, getState: getState2, getDataSourceState } = context;
32651
- const state = getState2();
32652
- return state.cellContextMenu.onChange((info) => {
32653
- if (!info) {
32654
- return;
32655
- }
32656
- const { event } = info;
32657
- function onHideIntent() {
32658
- clearAll();
32659
- actions2.cellContextMenuVisibleFor = null;
32660
- }
32661
- const { menu, cellContext, preventDefault } = getCellContextMenu(
32662
- info,
32663
- context,
32664
- onHideIntent
32665
- );
32666
- const rect = Rectangle.fromPoint({
32667
- top: event.clientY,
32668
- left: event.clientX
32669
- });
32670
- rect.width += OFFSET3;
32671
- rect.height += OFFSET3;
32672
- showOverlay(menu, {
32673
- constrainTo: getMenuConstrainTo(getState2()),
32674
- id: "cell-context-menu",
32675
- alignTo: rect,
32676
- alignPosition: ALIGN_POSITIONS
32677
- });
32678
- if (preventDefault) {
32679
- event.preventDefault();
32680
- }
32681
- actions2.cellContextMenuVisibleFor = {
32682
- columnId: info.columnId,
32683
- rowId: info.rowId,
32684
- rowIndex: info.rowIndex,
32685
- colIndex: info.colIndex
32686
- };
32687
- const { onCellContextMenu } = getState2();
32688
- if (onCellContextMenu) {
32689
- onCellContextMenu(
32690
- {
32691
- ...cellContext,
32692
- getState: getState2,
32693
- getDataSourceState
32694
- },
32695
- event
32696
- );
32697
- }
32698
- });
33046
+ return getState().cellContextMenu.onChange(
33047
+ getCellContextMenuHandler(context, {
33048
+ clearAll,
33049
+ getContent: (info, onHideIntent) => getCellContextMenu(info, context, onHideIntent),
33050
+ show: ({ menu }, params) => showOverlay(menu, params)
33051
+ })
33052
+ );
32699
33053
  }, []);
32700
33054
  (0, import_react64.useEffect)(() => {
32701
- const { cellContextMenuVisibleFor } = getState();
32702
- if (cellContextMenuVisibleFor) {
32703
- let handleMouseDown2 = function(event) {
32704
- if (event.__insideMenu !== true) {
32705
- clearAll();
32706
- actions.cellContextMenuVisibleFor = null;
32707
- }
32708
- };
32709
- var handleMouseDown = handleMouseDown2;
32710
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32711
- return () => {
32712
- document.documentElement.removeEventListener(
32713
- "mousedown",
32714
- handleMouseDown2
32715
- );
32716
- };
32717
- } else {
32718
- clearAll();
32719
- }
32720
- return () => {
32721
- };
33055
+ return menuVisibilityEffect(
33056
+ getState().cellContextMenuVisibleFor,
33057
+ clearAll,
33058
+ () => {
33059
+ actions.cellContextMenuVisibleFor = null;
33060
+ }
33061
+ );
32722
33062
  }, [getState().cellContextMenuVisibleFor]);
32723
33063
  return { menuPortal };
32724
33064
  }
@@ -32733,76 +33073,22 @@ function useTableContextMenu() {
32733
33073
  portalContainer: useMenuPortalContainer()
32734
33074
  });
32735
33075
  (0, import_react64.useEffect)(() => {
32736
- const { actions: actions2, getState: getState2 } = context;
32737
- const state = getState2();
32738
- return state.contextMenu.onChange((info) => {
32739
- if (!info) {
32740
- return;
32741
- }
32742
- const { event } = info;
32743
- function onHideIntent() {
32744
- clearAll();
32745
- actions2.contextMenuVisibleFor = null;
32746
- }
32747
- const { menu, cellContext, preventDefault } = getTableContextMenu(
32748
- info,
32749
- context,
32750
- onHideIntent
32751
- );
32752
- const point = {
32753
- top: event.clientY,
32754
- left: event.clientX
32755
- };
32756
- const rect = Rectangle.fromPoint(point);
32757
- rect.width += OFFSET3;
32758
- rect.height += OFFSET3;
32759
- showOverlay(menu, {
32760
- constrainTo: getMenuConstrainTo(getState2()),
32761
- id: "table-context-menu",
32762
- alignTo: rect,
32763
- alignPosition: ALIGN_POSITIONS
32764
- });
32765
- if (preventDefault) {
32766
- event.preventDefault();
32767
- }
32768
- actions2.contextMenuVisibleFor = {
32769
- point,
32770
- ...info
32771
- };
32772
- const { onContextMenu } = getState2();
32773
- if (onContextMenu) {
32774
- onContextMenu(
32775
- {
32776
- ...context,
32777
- ...cellContext
32778
- },
32779
- event
32780
- );
32781
- }
32782
- });
33076
+ return getState().contextMenu.onChange(
33077
+ getTableContextMenuHandler(context, {
33078
+ clearAll,
33079
+ getContent: (info, onHideIntent) => getTableContextMenu(info, context, onHideIntent),
33080
+ show: ({ menu }, params) => showOverlay(menu, params)
33081
+ })
33082
+ );
32783
33083
  }, []);
32784
33084
  (0, import_react64.useEffect)(() => {
32785
- const { contextMenuVisibleFor } = getState();
32786
- if (contextMenuVisibleFor) {
32787
- let handleMouseDown2 = function(event) {
32788
- if (event.__insideMenu !== true) {
32789
- clearAll();
32790
- actions.contextMenuVisibleFor = null;
32791
- }
32792
- };
32793
- var handleMouseDown = handleMouseDown2;
32794
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32795
- return () => {
32796
- document.documentElement.removeEventListener(
32797
- "mousedown",
32798
- handleMouseDown2
32799
- );
32800
- };
32801
- } else {
32802
- clearAll();
32803
- }
32804
- return () => {
32805
- };
33085
+ return menuVisibilityEffect(
33086
+ getState().contextMenuVisibleFor,
33087
+ clearAll,
33088
+ () => {
33089
+ actions.contextMenuVisibleFor = null;
33090
+ }
33091
+ );
32806
33092
  }, [getState().contextMenuVisibleFor]);
32807
33093
  return { menuPortal };
32808
33094
  }