@infinite-table/infinite-react 10.2.0 → 11.0.0

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
@@ -11854,9 +11898,10 @@ var React28 = __toESM(require("react"));
11854
11898
  var import_react21 = require("react");
11855
11899
 
11856
11900
  // 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";
11901
+ var SortIconCls = "_1b8djff1 _16lm1iw1";
11902
+ var SortIconDirectionCls = { asc: "_1b8djff2", desc: "_1b8djff3", none: "_1b8djff4" };
11903
+ var SortIconLineCls = "_1b8djff5";
11904
+ var SortIconLineWidthVarName = "--_1b8djff0";
11860
11905
 
11861
11906
  // src/components/InfiniteTable/components/icons/SortIcon/shared.ts
11862
11907
  var defaultLineStyle3 = {
@@ -11926,7 +11971,11 @@ function SortIcon(props) {
11926
11971
  "div",
11927
11972
  {
11928
11973
  "data-name": "sort-icon",
11929
- style: { ...style2, width: size },
11974
+ style: {
11975
+ ...style2,
11976
+ width: size,
11977
+ [SortIconLineWidthVarName]: `${lineWidth}px`
11978
+ },
11930
11979
  className: join(
11931
11980
  className,
11932
11981
  InfiniteIconClassName,
@@ -15552,6 +15601,7 @@ var ListRowManager = class extends Logger {
15552
15601
  var ITEM_POSITION_WITH_TRANSFORM = true;
15553
15602
  var currentTransformY = stripVar(InternalVars.y);
15554
15603
  var scrollTopCSSVar = stripVar(InternalVars.scrollTop);
15604
+ var scrollLeftCSSVar2 = stripVar(InternalVars.scrollLeft);
15555
15605
  var columnOffsetAtIndex2 = stripVar(InternalVars.columnOffsetAtIndex);
15556
15606
  var columnOffsetAtIndexWhileReordering2 = stripVar(
15557
15607
  InternalVars.columnOffsetAtIndexWhileReordering
@@ -15565,6 +15615,16 @@ var GridRenderer = class extends Logger {
15565
15615
  this.scrolling = false;
15566
15616
  this.cellHoverClassNames = [];
15567
15617
  this.cellDetachedClassNames = [];
15618
+ /**
15619
+ * Inside InfiniteTable, the table owns the CSS vars that position the
15620
+ * cells horizontally (one offset var per column, plus the scroll position
15621
+ * vars used by pinned cells) and sets them on its root node.
15622
+ *
15623
+ * A HeadlessTable used on its own has nobody to set them. With this on,
15624
+ * the renderer writes each cell's x from the brain, and sets the scroll
15625
+ * position vars itself, on the parent node of the cells.
15626
+ */
15627
+ this.ownsPositionVars = false;
15568
15628
  this.lastEnteredRow = -1;
15569
15629
  this.lastExitedRow = -1;
15570
15630
  this.hoverRowUpdatesInProgress = /* @__PURE__ */ new Map();
@@ -15584,26 +15644,30 @@ var GridRenderer = class extends Logger {
15584
15644
  element.style.transform = `translate3d(${scrollLeft2 || 0}px, var(${currentTransformY}), 0)`;
15585
15645
  };
15586
15646
  this.setTransform = (element, _rowIndex, colIndex, {
15587
- //@ts-ignore
15588
15647
  x,
15589
15648
  y,
15590
- //@ts-ignore
15591
15649
  scrollLeft: scrollLeft2,
15592
15650
  scrollTop: scrollTop2
15593
15651
  }, zIndex2) => {
15594
15652
  const columnOffsetX = InternalVarUtils.columnOffsets.get(colIndex);
15595
15653
  const columnOffsetXWhileReordering = `${columnOffsetAtIndexWhileReordering2}-${colIndex}`;
15596
- const currentTransformYValue = scrollTop2 ? `calc( ${y}px + var(${scrollTopCSSVar}) )` : `${y - this.brain.getScrollOrigin().scrollTop}px`;
15654
+ const currentTransformYValue = scrollTop2 ? `calc( ${y}px + var(${scrollTopCSSVar}, 0px) )` : `${y - this.brain.getScrollOrigin().scrollTop}px`;
15597
15655
  if (element.__currentTransformY !== currentTransformYValue) {
15598
15656
  element.__currentTransformY = currentTransformYValue;
15599
15657
  element.style.setProperty(currentTransformY, currentTransformYValue);
15600
15658
  }
15601
- const transformValue = `translate3d(var(${columnOffsetXWhileReordering}, ${columnOffsetX}), var(${currentTransformY}), 0)`;
15659
+ const transformX2 = this.ownsPositionVars ? scrollLeft2 ? `calc( ${x}px + var(${scrollLeftCSSVar2}, 0px) )` : `${x - this.brain.getScrollOrigin().scrollLeft}px` : `var(${columnOffsetXWhileReordering}, ${columnOffsetX})`;
15660
+ const transformValue = `translate3d(${transformX2}, var(${currentTransformY}), 0)`;
15602
15661
  if (element.__transformValue !== transformValue) {
15603
15662
  element.__transformValue = transformValue;
15604
15663
  element.style.transform = transformValue;
15605
15664
  }
15606
- if (zIndex2 != null) {
15665
+ if (zIndex2 != null && this.ownsPositionVars) {
15666
+ const zIndexValue = `${zIndex2}`;
15667
+ if (element.__zIndex !== zIndexValue) {
15668
+ element.__zIndex = zIndexValue;
15669
+ element.style.zIndex = zIndexValue;
15670
+ }
15607
15671
  }
15608
15672
  };
15609
15673
  /**
@@ -15624,6 +15688,17 @@ var GridRenderer = class extends Logger {
15624
15688
  });
15625
15689
  this.adjustFixedElementsOnScroll();
15626
15690
  };
15691
+ /**
15692
+ * While a render pass is in progress, the cells it detaches are collected
15693
+ * here and only get the detached class names when the pass ends - if they
15694
+ * are still detached by then.
15695
+ *
15696
+ * Most of the cells detached by a render pass (while scrolling, all of
15697
+ * them) are re-attached at another position by the same pass, so they
15698
+ * would get the class names added and then removed, with no visible effect
15699
+ * - only the cost of the DOM writes and of the style invalidations.
15700
+ */
15701
+ this.cellsDetachedInRenderPass = null;
15627
15702
  this.getFullyVisibleRowsRange = () => {
15628
15703
  let {
15629
15704
  start: [startRow],
@@ -16113,11 +16188,18 @@ var GridRenderer = class extends Logger {
16113
16188
  itemElement.dataset.rowIndex = realCoords.rowIndex;
16114
16189
  itemElement.dataset.colIndex = realCoords.colIndex;
16115
16190
  if (ITEM_POSITION_WITH_TRANSFORM) {
16116
- this.setTransform(itemElement, rowIndex, colIndex, { x, y }, null);
16191
+ const fixedPlacement = this.ownsPositionVars ? this.getFixedCellPlacement(rowIndex, colIndex, { x, y }) : null;
16192
+ this.setTransform(
16193
+ itemElement,
16194
+ rowIndex,
16195
+ colIndex,
16196
+ fixedPlacement ?? { x, y },
16197
+ null
16198
+ );
16117
16199
  itemElement.style.willChange = "transform";
16118
16200
  itemElement.style.backfaceVisibility = "hidden";
16119
16201
  const hidden = options ? options.hidden : !!this.isCellCovered(rowIndex, colIndex);
16120
- const zIndex2 = hidden ? "-1" : (
16202
+ const zIndex2 = hidden ? "-1" : fixedPlacement ? `${fixedPlacement.zIndex}` : (
16121
16203
  // #updatezindex - we need to allow elements use their own zIndex, so we
16122
16204
  // resort to allowing them to have it as a data-z-index attribute
16123
16205
  itemElement.dataset.zIndex || "auto"
@@ -16220,126 +16302,51 @@ var GridRenderer = class extends Logger {
16220
16302
  // fixed cells are positioned with these, inside the scroll layer
16221
16303
  // which is translated relative to the scroll origin
16222
16304
  brain.getDOMScrollPosition(scrollPosition),
16223
- this.getInfiniteNode(attachedCell.getElement())
16305
+ this.ownsPositionVars ? (
16306
+ // null on the first render pass, before the cells are in the DOM:
16307
+ // the cells fall back to a scroll position of 0 - see setTransform
16308
+ attachedCell.getElement()?.parentElement ?? null
16309
+ ) : this.getInfiniteNode(attachedCell.getElement())
16224
16310
  );
16225
16311
  }
16226
- const fixedEndColsOffsets = this.brain.getFixedEndColsOffsets({
16227
- skipScroll: true
16228
- });
16229
- const fixedEndRowsOffsets = this.brain.getFixedEndRowsOffsets({
16230
- skipScroll: true
16231
- });
16312
+ const fixedEndOffsets = {
16313
+ cols: this.brain.getFixedEndColsOffsets({ skipScroll: true }),
16314
+ rows: this.brain.getFixedEndRowsOffsets({ skipScroll: true })
16315
+ };
16232
16316
  const { start, end } = this.brain.getRenderRange();
16233
16317
  const [startRow, startCol] = start;
16234
16318
  const [endRow, endCol] = end;
16235
- function adjustElementPosition(rowIndex, colIndex, fn) {
16236
- const cell = cellManager.getCellAt([rowIndex, colIndex]);
16237
- if (cell == null) {
16319
+ const adjust = (rowIndex, colIndex) => {
16320
+ const node = cellManager.getCellAt([rowIndex, colIndex])?.getElement();
16321
+ const itemPosition = node ? brain.getCellOffset(rowIndex, colIndex) : null;
16322
+ if (!node || !itemPosition) {
16238
16323
  return;
16239
16324
  }
16240
- const itemPosition = brain.getCellOffset(rowIndex, colIndex);
16241
- const node = cell.getElement();
16242
- if (node && itemPosition) {
16243
- fn(rowIndex, colIndex, node, itemPosition);
16244
- }
16245
- }
16246
- const adjustColStart = (_rowIndex, colIndex, node, { x, y }) => {
16247
- this.setTransform(
16248
- node,
16249
- _rowIndex,
16250
- colIndex,
16251
- { x, y, scrollLeft: true },
16252
- fixedColsStart - colIndex
16253
- );
16254
- };
16255
- const adjustRowStart = (rowIndex, _colIndex, node, coords) => {
16256
- this.setTransform(
16257
- node,
16258
- rowIndex,
16259
- _colIndex,
16260
- { x: coords.x, y: coords.y, scrollTop: true },
16261
- fixedRowsStart - rowIndex
16262
- );
16263
- };
16264
- const adjustColEnd = (_rowIndex, colIndex, node, { y }) => {
16265
- const val = fixedEndColsOffsets[colIndex];
16266
- this.setTransform(
16267
- node,
16268
- _rowIndex,
16269
- colIndex,
16270
- { x: val, y, scrollLeft: true },
16271
- cols - colIndex
16272
- );
16273
- };
16274
- const adjustRowEnd = (rowIndex, _colIndex, node, coords) => {
16275
- this.setTransform(
16276
- node,
16277
- rowIndex,
16278
- _colIndex,
16279
- { x: coords.x, y: fixedEndRowsOffsets[rowIndex], scrollTop: true },
16280
- rows - rowIndex
16281
- );
16282
- };
16283
- const adjustColStartRowStart = (_rowIndex, _colIndex, node, { x, y }) => {
16284
- this.setTransform(
16285
- node,
16286
- _rowIndex,
16287
- _colIndex,
16288
- { x, scrollLeft: true, y, scrollTop: true },
16289
- 1e5
16290
- );
16291
- };
16292
- const adjustColStartRowEnd = (_rowIndex, _colIndex, node, { x }) => {
16293
- this.setTransform(
16294
- node,
16295
- _rowIndex,
16296
- _colIndex,
16297
- {
16298
- x,
16299
- scrollLeft: true,
16300
- y: fixedEndRowsOffsets[_rowIndex],
16301
- scrollTop: true
16302
- },
16303
- 2e5
16304
- );
16305
- };
16306
- const adjustColEndRowStart = (_rowIndex, colIndex, node, coords) => {
16307
- this.setTransform(
16308
- node,
16309
- _rowIndex,
16310
- colIndex,
16311
- {
16312
- x: fixedEndColsOffsets[colIndex],
16313
- y: coords.y,
16314
- scrollLeft: true,
16315
- scrollTop: true
16316
- },
16317
- 3e5
16318
- );
16319
- };
16320
- const adjustColEndRowEnd = (rowIndex, colIndex, node) => {
16321
- this.setTransform(
16322
- node,
16325
+ const placement = this.getFixedCellPlacement(
16323
16326
  rowIndex,
16324
16327
  colIndex,
16325
- {
16326
- x: fixedEndColsOffsets[colIndex],
16327
- y: fixedEndRowsOffsets[rowIndex],
16328
- scrollLeft: true,
16329
- scrollTop: true
16330
- },
16331
- 4e5
16328
+ itemPosition,
16329
+ fixedEndOffsets
16332
16330
  );
16331
+ if (placement) {
16332
+ this.setTransform(
16333
+ node,
16334
+ rowIndex,
16335
+ colIndex,
16336
+ placement,
16337
+ placement.zIndex
16338
+ );
16339
+ }
16333
16340
  };
16334
16341
  if (fixedColsStart || fixedColsEnd) {
16335
16342
  for (let rowIndex = startRow; rowIndex < endRow; rowIndex++) {
16336
16343
  for (let colIndex = 0; colIndex < fixedColsStart; colIndex++) {
16337
- adjustElementPosition(rowIndex, colIndex, adjustColStart);
16344
+ adjust(rowIndex, colIndex);
16338
16345
  }
16339
16346
  if (fixedColsEnd) {
16340
16347
  const firstColFixedEnd = cols - fixedColsEnd;
16341
16348
  for (let colIndex = firstColFixedEnd; colIndex < cols; colIndex++) {
16342
- adjustElementPosition(rowIndex, colIndex, adjustColEnd);
16349
+ adjust(rowIndex, colIndex);
16343
16350
  }
16344
16351
  }
16345
16352
  }
@@ -16347,12 +16354,12 @@ var GridRenderer = class extends Logger {
16347
16354
  if (fixedRowsStart || fixedRowsEnd) {
16348
16355
  for (let colIndex = startCol; colIndex < endCol; colIndex++) {
16349
16356
  for (let rowIndex = 0; rowIndex < fixedRowsStart; rowIndex++) {
16350
- adjustElementPosition(rowIndex, colIndex, adjustRowStart);
16357
+ adjust(rowIndex, colIndex);
16351
16358
  }
16352
16359
  if (fixedRowsEnd) {
16353
16360
  const firstRowFixedEnd = rows - fixedRowsEnd;
16354
16361
  for (let rowIndex = firstRowFixedEnd; rowIndex < rows; rowIndex++) {
16355
- adjustElementPosition(rowIndex, colIndex, adjustRowEnd);
16362
+ adjust(rowIndex, colIndex);
16356
16363
  }
16357
16364
  }
16358
16365
  }
@@ -16360,7 +16367,7 @@ var GridRenderer = class extends Logger {
16360
16367
  if (fixedColsStart && fixedRowsStart) {
16361
16368
  for (let rowIndex = 0; rowIndex < fixedRowsStart; rowIndex++) {
16362
16369
  for (let colIndex = 0; colIndex < fixedColsStart; colIndex++) {
16363
- adjustElementPosition(rowIndex, colIndex, adjustColStartRowStart);
16370
+ adjust(rowIndex, colIndex);
16364
16371
  }
16365
16372
  }
16366
16373
  }
@@ -16368,7 +16375,7 @@ var GridRenderer = class extends Logger {
16368
16375
  const firstRowFixedEnd = rows - fixedRowsEnd;
16369
16376
  for (let rowIndex = firstRowFixedEnd; rowIndex < rows; rowIndex++) {
16370
16377
  for (let colIndex = 0; colIndex < fixedColsStart; colIndex++) {
16371
- adjustElementPosition(rowIndex, colIndex, adjustColStartRowEnd);
16378
+ adjust(rowIndex, colIndex);
16372
16379
  }
16373
16380
  }
16374
16381
  }
@@ -16376,7 +16383,7 @@ var GridRenderer = class extends Logger {
16376
16383
  const firstColFixedEnd = cols - fixedColsEnd;
16377
16384
  for (let rowIndex = 0; rowIndex < fixedRowsStart; rowIndex++) {
16378
16385
  for (let colIndex = firstColFixedEnd; colIndex < cols; colIndex++) {
16379
- adjustElementPosition(rowIndex, colIndex, adjustColEndRowStart);
16386
+ adjust(rowIndex, colIndex);
16380
16387
  }
16381
16388
  }
16382
16389
  }
@@ -16385,7 +16392,7 @@ var GridRenderer = class extends Logger {
16385
16392
  const firstColFixedEnd = cols - fixedColsEnd;
16386
16393
  for (let rowIndex = firstRowFixedEnd; rowIndex < rows; rowIndex++) {
16387
16394
  for (let colIndex = firstColFixedEnd; colIndex < cols; colIndex++) {
16388
- adjustElementPosition(rowIndex, colIndex, adjustColEndRowEnd);
16395
+ adjust(rowIndex, colIndex);
16389
16396
  }
16390
16397
  }
16391
16398
  }
@@ -16459,6 +16466,9 @@ var GridRenderer = class extends Logger {
16459
16466
  return this.infiniteNode;
16460
16467
  }
16461
16468
  onCellAttached(cell) {
16469
+ if (this.cellsDetachedInRenderPass?.delete(cell)) {
16470
+ return;
16471
+ }
16462
16472
  if (this.cellDetachedClassNames.length) {
16463
16473
  const el = cell.getElement();
16464
16474
  if (el) {
@@ -16469,6 +16479,13 @@ var GridRenderer = class extends Logger {
16469
16479
  }
16470
16480
  }
16471
16481
  onCellDetached(cell) {
16482
+ if (this.cellsDetachedInRenderPass) {
16483
+ this.cellsDetachedInRenderPass.add(cell);
16484
+ return;
16485
+ }
16486
+ this.addDetachedClassNames(cell);
16487
+ }
16488
+ addDetachedClassNames(cell) {
16472
16489
  if (this.cellDetachedClassNames.length) {
16473
16490
  const el = cell.getElement();
16474
16491
  if (el) {
@@ -16505,10 +16522,22 @@ var GridRenderer = class extends Logger {
16505
16522
  mapped: rendered
16506
16523
  };
16507
16524
  }
16508
- renderRange(range, { renderCell, renderDetailRow, force, onRender }) {
16525
+ renderRange(range, options) {
16509
16526
  if (this.destroyed) {
16510
16527
  return [];
16511
16528
  }
16529
+ if (this.cellsDetachedInRenderPass) {
16530
+ return this.renderRangeInternal(range, options);
16531
+ }
16532
+ const detachedCells = this.cellsDetachedInRenderPass = /* @__PURE__ */ new Set();
16533
+ try {
16534
+ return this.renderRangeInternal(range, options);
16535
+ } finally {
16536
+ this.cellsDetachedInRenderPass = null;
16537
+ detachedCells.forEach((cell) => this.addDetachedClassNames(cell));
16538
+ }
16539
+ }
16540
+ renderRangeInternal(range, { renderCell, renderDetailRow, force, onRender }) {
16512
16541
  const { start, end } = range;
16513
16542
  const horizontalLayout = this.brain.isHorizontalLayoutBrain;
16514
16543
  if (false) {
@@ -16783,6 +16812,34 @@ var GridRenderer = class extends Logger {
16783
16812
  this.updateElementPosition(cell, { hidden, rowspan, colspan });
16784
16813
  return;
16785
16814
  }
16815
+ /**
16816
+ * Where a fixed (pinned) cell goes: its x and/or y relative to the viewport
16817
+ * (`scrollLeft` / `scrollTop: true` - see setTransform), and its z-index:
16818
+ * the corners above the pinned rows and columns, those above the cells
16819
+ * scrolling under them. null for a cell that is not fixed.
16820
+ */
16821
+ getFixedCellPlacement(rowIndex, colIndex, { x, y }, fixedEndOffsets) {
16822
+ const { fixedRowsStart, fixedRowsEnd, fixedColsStart, fixedColsEnd } = this.brain.getFixedCellInfo();
16823
+ const cols = this.brain.getColCount();
16824
+ const rows = this.brain.getRowCount();
16825
+ const colStart = colIndex < fixedColsStart;
16826
+ const colEnd = !colStart && !!fixedColsEnd && colIndex >= cols - fixedColsEnd;
16827
+ const rowStart = rowIndex < fixedRowsStart;
16828
+ const rowEnd = !rowStart && !!fixedRowsEnd && rowIndex >= rows - fixedRowsEnd;
16829
+ const colFixed = colStart || colEnd;
16830
+ const rowFixed = rowStart || rowEnd;
16831
+ if (!colFixed && !rowFixed) {
16832
+ return null;
16833
+ }
16834
+ if (colEnd) {
16835
+ x = (fixedEndOffsets?.cols ?? this.brain.getFixedEndColsOffsets({ skipScroll: true }))[colIndex];
16836
+ }
16837
+ if (rowEnd) {
16838
+ y = (fixedEndOffsets?.rows ?? this.brain.getFixedEndRowsOffsets({ skipScroll: true }))[rowIndex];
16839
+ }
16840
+ const zIndex2 = colFixed && rowFixed ? colStart ? rowStart ? 1e5 : 2e5 : rowStart ? 3e5 : 4e5 : colStart ? fixedColsStart - colIndex : colEnd ? cols - colIndex : rowStart ? fixedRowsStart - rowIndex : rows - rowIndex;
16841
+ return { x, y, scrollLeft: colFixed, scrollTop: rowFixed, zIndex: zIndex2 };
16842
+ }
16786
16843
  reset() {
16787
16844
  this.cellManager.reset();
16788
16845
  this.rowManager.reset();
@@ -17374,13 +17431,18 @@ function createRenderer(brain) {
17374
17431
  }
17375
17432
 
17376
17433
  // src/components/HeadlessTable/RawTable.tsx
17434
+ function createOwnRenderer(brain) {
17435
+ const result = createRenderer(brain);
17436
+ result.renderer.ownsPositionVars = true;
17437
+ return result;
17438
+ }
17377
17439
  function RawTableFn(props) {
17378
17440
  const { brain, renderCell, renderDetailRow, forceRerenderTimestamp } = props;
17379
17441
  const { renderer, onRenderUpdater } = (0, import_react29.useMemo)(() => {
17380
17442
  return props.onRenderUpdater && props.renderer ? {
17381
17443
  renderer: props.renderer,
17382
17444
  onRenderUpdater: props.onRenderUpdater
17383
- } : createRenderer(brain);
17445
+ } : createOwnRenderer(brain);
17384
17446
  }, [brain, props.onRenderUpdater, props.renderer]);
17385
17447
  (0, import_react29.useLayoutEffect)(() => {
17386
17448
  renderer.cellHoverClassNames = props.cellHoverClassNames || [];
@@ -22506,6 +22568,80 @@ function treeTraverse(treeParams, traverseOptions, data) {
22506
22568
  }
22507
22569
  }
22508
22570
 
22571
+ // src/utils/multisort/sortByNumber.ts
22572
+ var SORT_BY_NUMBER_MIN_LENGTH = 1e3;
22573
+ var IS_LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
22574
+ function sortByNumber(array, getValue, dir) {
22575
+ const len = array.length;
22576
+ const keys = new Float64Array(len);
22577
+ for (let i = 0; i < len; i++) {
22578
+ const value = getValue(array[i]);
22579
+ if (typeof value !== "number" || value !== value) {
22580
+ return false;
22581
+ }
22582
+ keys[i] = (dir < 0 ? -value : value) + 0;
22583
+ }
22584
+ if (len < 2) {
22585
+ return true;
22586
+ }
22587
+ const words = new Uint32Array(keys.buffer);
22588
+ const LOW = IS_LITTLE_ENDIAN ? 0 : 1;
22589
+ const HIGH = IS_LITTLE_ENDIAN ? 1 : 0;
22590
+ const counts = new Uint32Array(8 * 256);
22591
+ for (let i = 0; i < len; i++) {
22592
+ let low = words[2 * i + LOW];
22593
+ let high = words[2 * i + HIGH];
22594
+ if (high & 2147483648) {
22595
+ high = ~high >>> 0;
22596
+ low = ~low >>> 0;
22597
+ words[2 * i + LOW] = low;
22598
+ } else {
22599
+ high = (high | 2147483648) >>> 0;
22600
+ }
22601
+ words[2 * i + HIGH] = high;
22602
+ counts[low & 255]++;
22603
+ counts[256 + (low >>> 8 & 255)]++;
22604
+ counts[512 + (low >>> 16 & 255)]++;
22605
+ counts[768 + (low >>> 24)]++;
22606
+ counts[1024 + (high & 255)]++;
22607
+ counts[1280 + (high >>> 8 & 255)]++;
22608
+ counts[1536 + (high >>> 16 & 255)]++;
22609
+ counts[1792 + (high >>> 24)]++;
22610
+ }
22611
+ let indexes = new Uint32Array(len);
22612
+ let nextIndexes = new Uint32Array(len);
22613
+ for (let i = 0; i < len; i++) {
22614
+ indexes[i] = i;
22615
+ }
22616
+ for (let digitIndex = 0; digitIndex < 8; digitIndex++) {
22617
+ const word = digitIndex < 4 ? LOW : HIGH;
22618
+ const shift = digitIndex % 4 * 8;
22619
+ const countsOffset = digitIndex * 256;
22620
+ if (counts[countsOffset + (words[word] >>> shift & 255)] === len) {
22621
+ continue;
22622
+ }
22623
+ let position2 = 0;
22624
+ for (let digit = 0; digit < 256; digit++) {
22625
+ const count = counts[countsOffset + digit];
22626
+ counts[countsOffset + digit] = position2;
22627
+ position2 += count;
22628
+ }
22629
+ for (let i = 0; i < len; i++) {
22630
+ const index = indexes[i];
22631
+ const digit = words[2 * index + word] >>> shift & 255;
22632
+ nextIndexes[counts[countsOffset + digit]++] = index;
22633
+ }
22634
+ const previousIndexes = indexes;
22635
+ indexes = nextIndexes;
22636
+ nextIndexes = previousIndexes;
22637
+ }
22638
+ const items = array.slice();
22639
+ for (let i = 0; i < len; i++) {
22640
+ array[i] = items[indexes[i]];
22641
+ }
22642
+ return true;
22643
+ }
22644
+
22509
22645
  // src/utils/multisort/sortTypes.ts
22510
22646
  var numberComparator = function(first, second) {
22511
22647
  return first - second;
@@ -22591,7 +22727,10 @@ var multisort = (sortInfo, array, options) => {
22591
22727
  if (marker) {
22592
22728
  marker.start();
22593
22729
  }
22594
- array.sort(getMultisortFunction(toPlainSortInfo(sortInfo), get));
22730
+ const plainSortInfo = toPlainSortInfo(sortInfo);
22731
+ if (!sortByNumberIfPossible(plainSortInfo, array, get)) {
22732
+ array.sort(getMultisortFunction(plainSortInfo, get));
22733
+ }
22595
22734
  if (marker) {
22596
22735
  marker.end();
22597
22736
  }
@@ -22657,6 +22796,30 @@ var multisortNested = (sortInfo, array, options) => {
22657
22796
  return array;
22658
22797
  };
22659
22798
  multisort.knownTypes = sortTypes_default;
22799
+ function sortByNumberIfPossible(sortInfo, array, get) {
22800
+ if (sortInfo.length !== 1 || array.length < SORT_BY_NUMBER_MIN_LENGTH) {
22801
+ return false;
22802
+ }
22803
+ const info = sortInfo[0];
22804
+ if (!info || info.fn || !info.type || info.dir !== 1 && info.dir !== -1) {
22805
+ return false;
22806
+ }
22807
+ const type = Array.isArray(info.type) ? info.type[0] : info.type;
22808
+ if (multisort.knownTypes[type] !== numberComparator) {
22809
+ return false;
22810
+ }
22811
+ const { field, valueGetter } = info;
22812
+ return sortByNumber(
22813
+ array,
22814
+ (item) => {
22815
+ if (get) {
22816
+ item = get(item);
22817
+ }
22818
+ return valueGetter ? valueGetter(item) : field ? item[field] : item;
22819
+ },
22820
+ info.dir
22821
+ );
22822
+ }
22660
22823
  var getSingleSortFunction = (info) => {
22661
22824
  if (!info) {
22662
22825
  return;
@@ -23059,6 +23222,9 @@ function deepEqual(a, b) {
23059
23222
  if (a === b) return true;
23060
23223
  if (a == null || b == null) return a === b;
23061
23224
  if (typeof a !== typeof b) return false;
23225
+ if (a instanceof Date || b instanceof Date) {
23226
+ return a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
23227
+ }
23062
23228
  if (Array.isArray(a) && Array.isArray(b)) {
23063
23229
  if (a.length !== b.length) return false;
23064
23230
  for (let i = 0, len = a.length; i < len; i++) {
@@ -29491,8 +29657,8 @@ function getLicenseStatus(licenseKey = "", options) {
29491
29657
  return "valid";
29492
29658
  }
29493
29659
  const result = checkLicense(licenseKey, {
29494
- publishedAt: 1794927344373,
29495
- version: "10.2.0"
29660
+ publishedAt: 1795695384921,
29661
+ version: "11.0.0"
29496
29662
  });
29497
29663
  if (result === "invalid" && !licenseKey) {
29498
29664
  return "missing";
@@ -30791,6 +30957,14 @@ var deriveStateFromProps2 = (params) => {
30791
30957
  var React61 = __toESM(require("react"));
30792
30958
  var import_react58 = require("react");
30793
30959
 
30960
+ // src/components/Menu/MenuContext.ts
30961
+ var import_react56 = require("react");
30962
+ var MenuContext = (0, import_react56.createContext)(null);
30963
+ function useMenuContext() {
30964
+ const contextValue = (0, import_react56.useContext)(MenuContext);
30965
+ return contextValue;
30966
+ }
30967
+
30794
30968
  // src/components/Menu/menuDomUtils.ts
30795
30969
  function getMenuItemRect(menuId, itemKey) {
30796
30970
  const cells = getMenuItemNodes(menuId, itemKey);
@@ -30832,41 +31006,215 @@ function getFirstCheckBoxInsideMenuItem(menuId, itemKey) {
30832
31006
  return null;
30833
31007
  }
30834
31008
 
30835
- // src/utils/pageGeometry/Triangle.ts
30836
- var Triangle = class extends ConvexPoly {
30837
- // uncommenting this here breaks our tests - WHAT????
30838
- // it's just narrowing down the type of the points member variable
30839
- // - this should not introduce any change in behavior!!! however, TS is crazy about this one
30840
- // points!: PointTimes3;
30841
- constructor(points) {
30842
- super(points.slice(0, 3));
31009
+ // src/components/Menu/menuKeyboardNav.ts
31010
+ function hideMenuAndParents(getState) {
31011
+ const state = getState();
31012
+ state.onHideIntent?.(state);
31013
+ }
31014
+ function runMenuItemClick(event, item, context) {
31015
+ const { getState, setActiveItemKey, setKeyboardActiveItemKey, hideAll } = context;
31016
+ setKeyboardActiveItemKey(item.key);
31017
+ setActiveItemKey(item.key);
31018
+ if (item.originalMenuItem.onClick) {
31019
+ item.originalMenuItem.onClick(event);
31020
+ }
31021
+ const onActionParam = {
31022
+ key: item.key,
31023
+ item: item.originalMenuItem,
31024
+ hideMenu: hideAll
31025
+ };
31026
+ if (item.originalMenuItem.onAction) {
31027
+ item.originalMenuItem.onAction(onActionParam);
30843
31028
  }
30844
- };
30845
-
30846
- // src/components/Menu/MenuTriangleContext.ts
30847
- var ACTIVE_OTHER_MENU_ITEM_TIMEOUT = 250;
30848
- function waitForValueOnRaf(getter, timeout = 100) {
30849
- const start = Date.now();
30850
- return new Promise((resolve) => {
30851
- let value;
30852
- const fn = () => {
30853
- value = getter();
30854
- if (value !== void 0) {
30855
- resolve(value);
31029
+ const { onAction } = getState();
31030
+ if (onAction) {
31031
+ onAction(onActionParam);
31032
+ }
31033
+ if (item.originalMenuItem.hideMenuOnAction) {
31034
+ hideAll();
31035
+ }
31036
+ }
31037
+ function handleMenuKeyDown(keyboardEvent, context) {
31038
+ const {
31039
+ getState,
31040
+ setActiveItemKey,
31041
+ setKeyboardActiveItemKey,
31042
+ destroy,
31043
+ getSubmenuApi,
31044
+ isMounted,
31045
+ onItemClick
31046
+ } = context;
31047
+ const { runtimeItems, runtimeSelectableItems, keyboardActiveItemKey } = getState();
31048
+ const keyboardActiveIndex = runtimeItems.findIndex(
31049
+ (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31050
+ );
31051
+ let newKeyboardActiveItemKey = keyboardActiveItemKey;
31052
+ const keyboardActiveItem = runtimeItems[keyboardActiveIndex];
31053
+ const validKeys3 = {
31054
+ ArrowUp: () => {
31055
+ const newActiveItem = runtimeItems.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31056
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31057
+ newKeyboardActiveItemKey = newActiveItem.key;
31058
+ }
31059
+ },
31060
+ ArrowDown: () => {
31061
+ const newActiveItem = runtimeItems.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31062
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31063
+ newKeyboardActiveItemKey = newActiveItem.key;
31064
+ }
31065
+ },
31066
+ Home: () => {
31067
+ validKeys3.PageUp();
31068
+ },
31069
+ End: () => {
31070
+ validKeys3.PageDown();
31071
+ },
31072
+ PageUp: () => {
31073
+ newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31074
+ },
31075
+ PageDown: () => {
31076
+ newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31077
+ },
31078
+ ArrowLeft: () => {
31079
+ setActiveItemKey(null);
31080
+ if (getState().parentMenuId) {
31081
+ destroy();
31082
+ }
31083
+ },
31084
+ ArrowRight: () => {
31085
+ if (!keyboardActiveItem) {
30856
31086
  return;
30857
31087
  }
30858
- if (Date.now() - start > timeout) {
30859
- resolve(void 0);
31088
+ setActiveItemKey(keyboardActiveItem.key);
31089
+ raf(() => {
31090
+ const submenuApi = getSubmenuApi();
31091
+ if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31092
+ submenuApi.focus();
31093
+ }
31094
+ });
31095
+ },
31096
+ Enter: () => {
31097
+ if (!keyboardActiveItem) {
30860
31098
  return;
30861
31099
  }
30862
- raf(fn);
30863
- };
30864
- raf(() => {
30865
- fn();
30866
- });
30867
- });
30868
- }
30869
- var globalObject = getGlobal();
31100
+ if (keyboardActiveItem.originalMenuItem?.menu) {
31101
+ if (getSubmenuApi()) {
31102
+ validKeys3.ArrowLeft();
31103
+ return;
31104
+ }
31105
+ setActiveItemKey(keyboardActiveItem.key);
31106
+ } else {
31107
+ onItemClick(keyboardEvent, keyboardActiveItem);
31108
+ }
31109
+ },
31110
+ " ": () => {
31111
+ if (!keyboardActiveItem) {
31112
+ return;
31113
+ }
31114
+ if (!keyboardActiveItem.originalMenuItem.menu) {
31115
+ onItemClick(keyboardEvent, keyboardActiveItem);
31116
+ }
31117
+ const checkbox = getFirstCheckBoxInsideMenuItem(
31118
+ getState().menuId,
31119
+ keyboardActiveItem.key
31120
+ );
31121
+ if (!checkbox) {
31122
+ return;
31123
+ }
31124
+ checkbox.click();
31125
+ },
31126
+ Escape: () => {
31127
+ validKeys3.ArrowLeft();
31128
+ const state = getState();
31129
+ if (!state.parentMenuId) {
31130
+ state.onHideIntent?.(state);
31131
+ }
31132
+ }
31133
+ };
31134
+ const fn = validKeys3[keyboardEvent.key];
31135
+ if (fn) {
31136
+ fn();
31137
+ keyboardEvent.preventDefault();
31138
+ }
31139
+ if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31140
+ setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31141
+ }
31142
+ }
31143
+ function createMenuFocus(context) {
31144
+ const {
31145
+ getState,
31146
+ setFocused,
31147
+ setKeyboardActiveItemKey,
31148
+ shouldSelectFirstItemOnFocus,
31149
+ hideAll
31150
+ } = context;
31151
+ const onMenuFocus = () => {
31152
+ setFocused(true);
31153
+ setTimeout(() => {
31154
+ const domNode = getState().domRef.current;
31155
+ if (shouldSelectFirstItemOnFocus() && domNode && domNode === document.activeElement && getState().keyboardActiveItemKey == null) {
31156
+ setKeyboardActiveItemKey(
31157
+ getState().runtimeSelectableItems[0]?.key ?? null
31158
+ );
31159
+ }
31160
+ });
31161
+ };
31162
+ const api = {
31163
+ hideMenu: hideAll,
31164
+ focus: () => {
31165
+ const domNode = getState().domRef.current;
31166
+ if (domNode) {
31167
+ domNode.focus();
31168
+ setTimeout(() => {
31169
+ const node = getState().domRef.current;
31170
+ if (node && node !== document.activeElement) {
31171
+ node.focus();
31172
+ }
31173
+ }, 10);
31174
+ onMenuFocus();
31175
+ }
31176
+ },
31177
+ getMenuId: () => getState().menuId,
31178
+ getParentMenuId: () => getState().parentMenuId
31179
+ };
31180
+ return { api, onMenuFocus };
31181
+ }
31182
+
31183
+ // src/utils/pageGeometry/Triangle.ts
31184
+ var Triangle = class extends ConvexPoly {
31185
+ // uncommenting this here breaks our tests - WHAT????
31186
+ // it's just narrowing down the type of the points member variable
31187
+ // - this should not introduce any change in behavior!!! however, TS is crazy about this one
31188
+ // points!: PointTimes3;
31189
+ constructor(points) {
31190
+ super(points.slice(0, 3));
31191
+ }
31192
+ };
31193
+
31194
+ // src/components/Menu/MenuTriangleContext.ts
31195
+ var ACTIVE_OTHER_MENU_ITEM_TIMEOUT = 250;
31196
+ function waitForValueOnRaf(getter, timeout = 100) {
31197
+ const start = Date.now();
31198
+ return new Promise((resolve) => {
31199
+ let value;
31200
+ const fn = () => {
31201
+ value = getter();
31202
+ if (value !== void 0) {
31203
+ resolve(value);
31204
+ return;
31205
+ }
31206
+ if (Date.now() - start > timeout) {
31207
+ resolve(void 0);
31208
+ return;
31209
+ }
31210
+ raf(fn);
31211
+ };
31212
+ raf(() => {
31213
+ fn();
31214
+ });
31215
+ });
31216
+ }
31217
+ var globalObject = getGlobal();
30870
31218
  var MenuTriangleContext = class {
30871
31219
  constructor(params) {
30872
31220
  this.activeItem = null;
@@ -31048,12 +31396,150 @@ var MenuTriangleContext = class {
31048
31396
  }
31049
31397
  };
31050
31398
 
31051
- // src/components/Menu/MenuContext.ts
31052
- var import_react56 = require("react");
31053
- var MenuContext = (0, import_react56.createContext)(null);
31054
- function useMenuContext() {
31055
- const contextValue = (0, import_react56.useContext)(MenuContext);
31056
- return contextValue;
31399
+ // src/components/Menu/menuViewShared.ts
31400
+ function getActiveSubmenuItem(runtimeItems, activeItemKey) {
31401
+ const activeItem = runtimeItems.filter(
31402
+ (item) => item.type === "item" && activeItemKey === item.key
31403
+ )[0];
31404
+ return activeItem && activeItem.menu ? activeItem : null;
31405
+ }
31406
+ function getSubmenuOverlayParams(menuId, item, constrainTo) {
31407
+ const alignTo = getMenuItemRect(menuId, item.key);
31408
+ if (!alignTo) {
31409
+ return null;
31410
+ }
31411
+ return {
31412
+ id: `${menuId}-submenu`,
31413
+ alignTo,
31414
+ alignPosition: [
31415
+ ["TopLeft", "TopRight"],
31416
+ ["TopRight", "TopLeft"]
31417
+ ],
31418
+ constrainTo
31419
+ };
31420
+ }
31421
+ function getSubmenuProps(item, context) {
31422
+ const {
31423
+ parentMenuId,
31424
+ constrainTo,
31425
+ api,
31426
+ hideAll,
31427
+ setSubmenuApi,
31428
+ setActiveItemKey,
31429
+ setKeyboardActiveItemKey
31430
+ } = context;
31431
+ let itemMenu = item.menu;
31432
+ if (!itemMenu) {
31433
+ return null;
31434
+ }
31435
+ if (typeof itemMenu === "function") {
31436
+ itemMenu = itemMenu();
31437
+ }
31438
+ const submenu = itemMenu;
31439
+ return {
31440
+ parentMenuItemKey: item.key,
31441
+ parentMenuId,
31442
+ constrainTo,
31443
+ ...submenu,
31444
+ autoFocus: false,
31445
+ onShow: (state, submenuApi) => {
31446
+ submenu?.onShow?.(state, submenuApi);
31447
+ setSubmenuApi(submenuApi);
31448
+ },
31449
+ onHideIntent: (state) => {
31450
+ submenu?.onHideIntent?.(state);
31451
+ hideAll();
31452
+ },
31453
+ onHide: (state) => {
31454
+ if (state.focused) {
31455
+ setActiveItemKey(null);
31456
+ setKeyboardActiveItemKey(item.key);
31457
+ api.focus();
31458
+ }
31459
+ }
31460
+ };
31461
+ }
31462
+ function createMenuTriangleHandlers(getState, onItemActivate) {
31463
+ return new MenuTriangleContext({
31464
+ parentMenuId: getState().parentMenuId,
31465
+ onItemActivate,
31466
+ itemHasSubMenu: (itemKey) => {
31467
+ const item = getState().runtimeItems.filter(
31468
+ (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31469
+ )[0];
31470
+ return !!item;
31471
+ },
31472
+ getMenuRectFor: (itemKey) => {
31473
+ const selector2 = `[data-submenu-for="${itemKey}"]`;
31474
+ const menuNode = document.querySelector(selector2);
31475
+ if (!menuNode) {
31476
+ return void 0;
31477
+ }
31478
+ return Rectangle.from(menuNode.getBoundingClientRect());
31479
+ }
31480
+ }).getHandlers();
31481
+ }
31482
+ function getMenuGridStyle(state, style2, toCssWidth = (width) => width) {
31483
+ const { columns, runtimeItems, wrapLabels } = state;
31484
+ const gridTemplateColumns = columns.map((col) => {
31485
+ return toCssWidth(
31486
+ col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto"
31487
+ );
31488
+ }).join(" ");
31489
+ const result = {
31490
+ ...style2,
31491
+ gridTemplateColumns,
31492
+ gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31493
+ };
31494
+ if (!wrapLabels) {
31495
+ result.whiteSpace = "nowrap";
31496
+ }
31497
+ return result;
31498
+ }
31499
+ function getMenuItemCells(item, columns, index, flags) {
31500
+ const { active, keyboardActive, pressed } = flags;
31501
+ const key = item.value.key;
31502
+ const className = join(
31503
+ MenuItemCls({
31504
+ active,
31505
+ disabled: !!item.disabled,
31506
+ keyboardActive,
31507
+ pressed: pressed || active
31508
+ }),
31509
+ item.className
31510
+ );
31511
+ const cells = [];
31512
+ let spanIndex = 0;
31513
+ columns.forEach((col, i) => {
31514
+ const target = item.value;
31515
+ const field = col.field || col.name;
31516
+ const start = i + 1;
31517
+ const end = start + item.span;
31518
+ if (start < spanIndex) {
31519
+ return;
31520
+ }
31521
+ spanIndex = end;
31522
+ cells.push({
31523
+ key: `${key}-${field}`,
31524
+ column: col,
31525
+ value: target[field],
31526
+ style: {
31527
+ ...col.style,
31528
+ ...item.style,
31529
+ gridColumnStart: start,
31530
+ gridColumnEnd: end
31531
+ },
31532
+ className,
31533
+ dataAttributes: {
31534
+ "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31535
+ "data-menu-col-name": `${col.name}`,
31536
+ "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31537
+ "data-menu-row-index": `${index}`,
31538
+ "data-menu-item-key": `${item.key}`
31539
+ }
31540
+ });
31541
+ });
31542
+ return cells;
31057
31543
  }
31058
31544
 
31059
31545
  // src/components/hooks/useMounted.ts
@@ -31072,84 +31558,29 @@ function useMounted() {
31072
31558
 
31073
31559
  // src/components/Menu/Menu.tsx
31074
31560
  function renderSubmenuForItem(item, config) {
31075
- const {
31076
- parentMenuId,
31077
- setSubmenuApi,
31078
- setActiveItemKey,
31079
- setKeyboardActiveItemKey,
31080
- constrainTo,
31081
- onHideIntent,
31082
- api
31083
- } = config;
31084
- const overlayId = `${parentMenuId}-submenu`;
31085
- let itemMenu = item.menu;
31086
- if (!itemMenu) {
31561
+ const overlayId = `${config.parentMenuId}-submenu`;
31562
+ const submenuProps = getSubmenuProps(item, config);
31563
+ if (!submenuProps) {
31087
31564
  return null;
31088
31565
  }
31089
- if (typeof itemMenu === "function") {
31090
- itemMenu = itemMenu();
31091
- }
31092
- return /* @__PURE__ */ React61.createElement(
31093
- Menu,
31094
- {
31095
- key: overlayId,
31096
- parentMenuItemKey: item.key,
31097
- parentMenuId,
31098
- constrainTo,
31099
- ...itemMenu,
31100
- autoFocus: false,
31101
- onShow: (state, api2) => {
31102
- itemMenu?.onShow?.(state, api2);
31103
- setSubmenuApi(api2);
31104
- },
31105
- onHideIntent: (state) => {
31106
- itemMenu?.onHideIntent?.(state);
31107
- onHideIntent(state);
31108
- },
31109
- onHide: (state) => {
31110
- if (state.focused) {
31111
- setActiveItemKey(null);
31112
- setKeyboardActiveItemKey(item.key);
31113
- api.focus();
31114
- }
31115
- }
31116
- }
31117
- );
31566
+ return /* @__PURE__ */ React61.createElement(Menu, { key: overlayId, ...submenuProps });
31118
31567
  }
31119
31568
  function useSubmenus({
31120
31569
  onItemActivate
31121
31570
  }) {
31122
31571
  const { getState } = useMenuContext();
31123
- const [{ onItemEnter, onItemLeave }] = (0, import_react58.useState)(() => {
31124
- return new MenuTriangleContext({
31125
- parentMenuId: getState().parentMenuId,
31126
- onItemActivate: (itemKey) => {
31127
- if (!itemKey) {
31128
- onItemActivate(null);
31129
- return;
31130
- }
31131
- const item = getState().runtimeItems.filter(
31132
- (item2) => item2.type === "item" && item2.key === itemKey
31133
- )[0];
31134
- onItemActivate(item);
31135
- },
31136
- itemHasSubMenu: (itemKey) => {
31137
- const item = getState().runtimeItems.filter(
31138
- (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31139
- )[0];
31140
- return !!item;
31141
- },
31142
- getMenuRectFor: (itemKey) => {
31143
- const selector2 = `[data-submenu-for="${itemKey}"]`;
31144
- const menuNode = document.querySelector(selector2);
31145
- if (!menuNode) {
31146
- return void 0;
31147
- }
31148
- const rect = Rectangle.from(menuNode.getBoundingClientRect());
31149
- return rect;
31572
+ const [{ onItemEnter, onItemLeave }] = (0, import_react58.useState)(
31573
+ () => createMenuTriangleHandlers(getState, (itemKey) => {
31574
+ if (!itemKey) {
31575
+ onItemActivate(null);
31576
+ return;
31150
31577
  }
31151
- }).getHandlers();
31152
- });
31578
+ const item = getState().runtimeItems.filter(
31579
+ (item2) => item2.type === "item" && item2.key === itemKey
31580
+ )[0];
31581
+ onItemActivate(item);
31582
+ })
31583
+ );
31153
31584
  return {
31154
31585
  onItemEnter: (0, import_react58.useCallback)(onItemEnter, []),
31155
31586
  onItemLeave: (0, import_react58.useCallback)(onItemLeave, [])
@@ -31158,6 +31589,7 @@ function useSubmenus({
31158
31589
  function MenuComponent(props) {
31159
31590
  const { domProps } = props;
31160
31591
  const {
31592
+ componentState,
31161
31593
  componentState: {
31162
31594
  columns,
31163
31595
  runtimeItems,
@@ -31166,8 +31598,6 @@ function MenuComponent(props) {
31166
31598
  keyboardActiveItemKey,
31167
31599
  constrainTo,
31168
31600
  destroyed,
31169
- onAction,
31170
- wrapLabels,
31171
31601
  onShow,
31172
31602
  onHide,
31173
31603
  autoFocus,
@@ -31185,62 +31615,56 @@ function MenuComponent(props) {
31185
31615
  }, []);
31186
31616
  const isMounted = useMounted();
31187
31617
  const [submenuApi, setSubmenuApi] = (0, import_react58.useState)(null);
31618
+ const shouldSelectFirstItemOnFocus = (0, import_react58.useRef)(true);
31619
+ const [{ api, onMenuFocus, hideAll }] = (0, import_react58.useState)(() => {
31620
+ const hideAll2 = () => hideMenuAndParents(getState);
31621
+ return {
31622
+ hideAll: hideAll2,
31623
+ ...createMenuFocus({
31624
+ getState,
31625
+ setFocused: (focused) => {
31626
+ componentActions.focused = focused;
31627
+ },
31628
+ setKeyboardActiveItemKey,
31629
+ shouldSelectFirstItemOnFocus: () => shouldSelectFirstItemOnFocus.current,
31630
+ hideAll: hideAll2
31631
+ })
31632
+ };
31633
+ });
31188
31634
  let renderedChildren = null;
31189
31635
  (0, import_react58.useLayoutEffect)(() => {
31190
31636
  const { runtimeItems: runtimeItems2 } = getState();
31191
- const activeItem = runtimeItems2.filter(
31192
- (item) => item.type === "item" && activeItemKey === item.key
31193
- )[0];
31194
- if (!activeItem || !activeItem.menu) {
31637
+ const activeItem = getActiveSubmenuItem(runtimeItems2, activeItemKey);
31638
+ if (!activeItem) {
31195
31639
  setSubmenuApi(null);
31196
31640
  clearAll();
31197
31641
  return;
31198
31642
  }
31199
- if (activeItem) {
31200
- const alignTo = getMenuItemRect(menuId, activeItem.key);
31201
- const menu = () => renderSubmenuForItem(activeItem, {
31202
- constrainTo,
31203
- setSubmenuApi,
31204
- setActiveItemKey,
31205
- setKeyboardActiveItemKey,
31206
- parentMenuId: menuId,
31207
- onHideIntent: hideAll,
31208
- api
31209
- });
31210
- if (alignTo) {
31211
- showOverlay(menu, {
31212
- id: `${menuId}-submenu`,
31213
- alignTo,
31214
- alignPosition: [
31215
- ["TopLeft", "TopRight"],
31216
- ["TopRight", "TopLeft"]
31217
- ],
31218
- constrainTo
31219
- });
31220
- }
31221
- return;
31643
+ const overlayParams = getSubmenuOverlayParams(
31644
+ menuId,
31645
+ activeItem,
31646
+ constrainTo
31647
+ );
31648
+ const menu = () => renderSubmenuForItem(activeItem, {
31649
+ constrainTo,
31650
+ setSubmenuApi,
31651
+ setActiveItemKey,
31652
+ setKeyboardActiveItemKey,
31653
+ parentMenuId: menuId,
31654
+ hideAll,
31655
+ api
31656
+ });
31657
+ if (overlayParams) {
31658
+ showOverlay(menu, overlayParams);
31222
31659
  }
31223
31660
  }, [activeItemKey]);
31224
31661
  const onItemClick = (event, item) => {
31225
- setKeyboardActiveItemKey(item.key);
31226
- setActiveItemKey(item.key);
31227
- if (item.originalMenuItem.onClick) {
31228
- item.originalMenuItem.onClick(event);
31229
- }
31230
- const onActionParam = {
31231
- key: item.key,
31232
- item: item.originalMenuItem,
31233
- hideMenu: hideAll
31234
- };
31235
- if (item.originalMenuItem.onAction) {
31236
- item.originalMenuItem.onAction(onActionParam);
31237
- }
31238
- if (onAction) {
31239
- onAction(onActionParam);
31240
- }
31241
- if (item.originalMenuItem.hideMenuOnAction) {
31242
- hideAll();
31243
- }
31662
+ runMenuItemClick(event, item, {
31663
+ getState,
31664
+ setActiveItemKey,
31665
+ setKeyboardActiveItemKey,
31666
+ hideAll
31667
+ });
31244
31668
  };
31245
31669
  const {
31246
31670
  showOverlay,
@@ -31278,185 +31702,54 @@ function MenuComponent(props) {
31278
31702
  onClick: onItemClick
31279
31703
  }
31280
31704
  ));
31281
- const gridTemplateColumns = columns.map((col) => {
31282
- return col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto";
31283
- }).join(" ");
31284
- const style2 = {
31285
- ...domProps.style,
31286
- gridTemplateColumns,
31287
- gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31288
- };
31289
- if (!wrapLabels) {
31290
- style2.whiteSpace = "nowrap";
31291
- }
31705
+ const style2 = getMenuGridStyle(
31706
+ componentState,
31707
+ domProps.style
31708
+ );
31292
31709
  function handleKeydown(keyboardEvent) {
31293
- const { runtimeItems: runtimeItems2, runtimeSelectableItems } = getState();
31294
- let keyboardActiveIndex = runtimeItems2.findIndex(
31295
- (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31296
- );
31297
- let newKeyboardActiveItemKey = keyboardActiveItemKey;
31298
- const keyboardActiveItem = runtimeItems2[keyboardActiveIndex];
31299
- const validKeys3 = {
31300
- ArrowUp: () => {
31301
- const newActiveItem = runtimeItems2.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31302
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31303
- newKeyboardActiveItemKey = newActiveItem.key;
31304
- }
31305
- },
31306
- ArrowDown: () => {
31307
- const newActiveItem = runtimeItems2.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31308
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31309
- newKeyboardActiveItemKey = newActiveItem.key;
31310
- }
31311
- },
31312
- Home: () => {
31313
- validKeys3.PageUp();
31710
+ handleMenuKeyDown(keyboardEvent, {
31711
+ getState,
31712
+ setActiveItemKey,
31713
+ setKeyboardActiveItemKey,
31714
+ destroy: () => {
31715
+ componentActions.destroyed = true;
31314
31716
  },
31315
- End: () => {
31316
- validKeys3.PageDown();
31717
+ // the submenu api of this render: the raf of ArrowRight reads it
31718
+ getSubmenuApi: () => submenuApi,
31719
+ isMounted,
31720
+ onItemClick
31721
+ });
31722
+ }
31723
+ function onMenuBlur() {
31724
+ componentActions.focused = false;
31725
+ }
31726
+ const refCallback = (0, import_react58.useCallback)((node) => {
31727
+ if (node) {
31728
+ domRef.current = node;
31729
+ onShow?.(getState(), api);
31730
+ if (autoFocus) {
31731
+ api.focus();
31732
+ }
31733
+ } else {
31734
+ onHide?.(getState());
31735
+ domRef.current = node;
31736
+ }
31737
+ }, []);
31738
+ const result = /* @__PURE__ */ React61.createElement("div", { className: display.contents }, /* @__PURE__ */ React61.createElement(
31739
+ "div",
31740
+ {
31741
+ ...domProps,
31742
+ "data-menu-id": menuId,
31743
+ "data-submenu-for": parentMenuItemKey,
31744
+ tabIndex: 0,
31745
+ ref: refCallback,
31746
+ onKeyDown: (event) => {
31747
+ domProps.onKeyDown?.(event);
31748
+ handleKeydown(event);
31317
31749
  },
31318
- PageUp: () => {
31319
- newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31320
- },
31321
- PageDown: () => {
31322
- newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31323
- },
31324
- ArrowLeft: () => {
31325
- setActiveItemKey(null);
31326
- if (getState().parentMenuId) {
31327
- componentActions.destroyed = true;
31328
- }
31329
- },
31330
- ArrowRight: () => {
31331
- if (!keyboardActiveItem) {
31332
- return;
31333
- }
31334
- setActiveItemKey(keyboardActiveItem.key);
31335
- raf(() => {
31336
- if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31337
- submenuApi.focus();
31338
- }
31339
- });
31340
- },
31341
- Enter: () => {
31342
- if (!keyboardActiveItem) {
31343
- return;
31344
- }
31345
- if (keyboardActiveItem.originalMenuItem?.menu) {
31346
- if (keyboardActiveItem && keyboardActiveItem.originalMenuItem.menu && submenuApi) {
31347
- validKeys3.ArrowLeft();
31348
- return;
31349
- }
31350
- if (keyboardActiveItem) {
31351
- setActiveItemKey(keyboardActiveItem.key);
31352
- }
31353
- } else {
31354
- onItemClick(
31355
- keyboardEvent,
31356
- keyboardActiveItem
31357
- );
31358
- }
31359
- },
31360
- " ": () => {
31361
- if (!keyboardActiveItem) {
31362
- return;
31363
- }
31364
- if (!keyboardActiveItem.originalMenuItem.menu) {
31365
- onItemClick(
31366
- keyboardEvent,
31367
- keyboardActiveItem
31368
- );
31369
- }
31370
- const checkbox = getFirstCheckBoxInsideMenuItem(
31371
- menuId,
31372
- keyboardActiveItem.key
31373
- );
31374
- if (!checkbox) {
31375
- return;
31376
- }
31377
- checkbox.click();
31378
- },
31379
- Escape: () => {
31380
- validKeys3.ArrowLeft();
31381
- const state = getState();
31382
- if (!state.parentMenuId) {
31383
- state.onHideIntent?.(state);
31384
- }
31385
- }
31386
- };
31387
- const fn = validKeys3[keyboardEvent.key];
31388
- if (fn) {
31389
- fn();
31390
- keyboardEvent.preventDefault();
31391
- }
31392
- if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31393
- setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31394
- }
31395
- }
31396
- function onMenuBlur() {
31397
- componentActions.focused = false;
31398
- }
31399
- const onMenuFocus = (0, import_react58.useCallback)(function() {
31400
- componentActions.focused = true;
31401
- setTimeout(() => {
31402
- if (shouldSelectFirstItemOnFocus.current && domRef.current && domRef.current === document.activeElement && getState().keyboardActiveItemKey == null) {
31403
- setKeyboardActiveItemKey(
31404
- getState().runtimeSelectableItems[0]?.key ?? null
31405
- );
31406
- }
31407
- });
31408
- }, []);
31409
- const shouldSelectFirstItemOnFocus = (0, import_react58.useRef)(true);
31410
- const hideAll = (0, import_react58.useCallback)(() => {
31411
- const state = getState();
31412
- state.onHideIntent?.(state);
31413
- }, [getState]);
31414
- const [api] = (0, import_react58.useState)(() => {
31415
- const result2 = {
31416
- hideMenu: hideAll,
31417
- focus: () => {
31418
- if (domRef.current) {
31419
- domRef.current.focus();
31420
- setTimeout(() => {
31421
- if (domRef.current && domRef.current !== document.activeElement) {
31422
- domRef.current.focus();
31423
- }
31424
- }, 10);
31425
- onMenuFocus();
31426
- }
31427
- },
31428
- getMenuId: () => getState().menuId,
31429
- getParentMenuId: () => getState().parentMenuId
31430
- };
31431
- return result2;
31432
- });
31433
- const refCallback = (0, import_react58.useCallback)((node) => {
31434
- if (node) {
31435
- domRef.current = node;
31436
- onShow?.(getState(), api);
31437
- if (autoFocus) {
31438
- api.focus();
31439
- }
31440
- } else {
31441
- onHide?.(getState());
31442
- domRef.current = node;
31443
- }
31444
- }, []);
31445
- const result = /* @__PURE__ */ React61.createElement("div", { className: display.contents }, /* @__PURE__ */ React61.createElement(
31446
- "div",
31447
- {
31448
- ...domProps,
31449
- "data-menu-id": menuId,
31450
- "data-submenu-for": parentMenuItemKey,
31451
- tabIndex: 0,
31452
- ref: refCallback,
31453
- onKeyDown: (event) => {
31454
- domProps.onKeyDown?.(event);
31455
- handleKeydown(event);
31456
- },
31457
- onMouseDown: (event) => {
31458
- shouldSelectFirstItemOnFocus.current = false;
31459
- domProps.onMouseDown?.(event);
31750
+ onMouseDown: (event) => {
31751
+ shouldSelectFirstItemOnFocus.current = false;
31752
+ domProps.onMouseDown?.(event);
31460
31753
  },
31461
31754
  onMouseUp: (event) => {
31462
31755
  shouldSelectFirstItemOnFocus.current = true;
@@ -31474,44 +31767,20 @@ function MenuComponent(props) {
31474
31767
  function RuntimeItemRenderer(props) {
31475
31768
  const [pressed, setPressed] = React61.useState(false);
31476
31769
  const { columns, item, index, active, keyboardActive } = props;
31477
- const key = item.type === "item" ? item.value.key : index;
31478
31770
  let content = null;
31479
31771
  if (item.type === "decoration") {
31480
31772
  content = /* @__PURE__ */ React61.createElement("div", { style: item.style }, item.value);
31481
31773
  } else {
31482
- let spanIndex = 0;
31483
- content = columns.map((col, i) => {
31484
- const target = item.value;
31485
- const field = col.field || col.name;
31486
- const start = i + 1;
31487
- const end = start + item.span;
31488
- if (start < spanIndex) {
31489
- return null;
31490
- }
31491
- spanIndex = end;
31492
- const style2 = {
31493
- ...col.style,
31494
- ...item.style,
31495
- gridColumnStart: start,
31496
- gridColumnEnd: end
31497
- };
31774
+ content = getMenuItemCells(item, columns, index, {
31775
+ active,
31776
+ keyboardActive,
31777
+ pressed
31778
+ }).map((cell) => {
31779
+ const col = cell.column;
31498
31780
  const domProps = {
31499
- style: style2,
31500
- //@ts-ignore
31501
- "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31502
- "data-menu-col-name": `${col.name}`,
31503
- "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31504
- "data-menu-row-index": `${index}`,
31505
- "data-menu-item-key": `${item.key}`,
31506
- className: join(
31507
- MenuItemCls({
31508
- active,
31509
- disabled: !!item.disabled,
31510
- keyboardActive,
31511
- pressed: pressed || props.active
31512
- }),
31513
- item.className
31514
- ),
31781
+ style: cell.style,
31782
+ ...cell.dataAttributes,
31783
+ className: cell.className,
31515
31784
  onPointerEnter: (event) => {
31516
31785
  if (!item.disabled) {
31517
31786
  props.onItemEnter?.(item, event);
@@ -31541,17 +31810,17 @@ function RuntimeItemRenderer(props) {
31541
31810
  return col.render ? /* @__PURE__ */ React61.createElement(
31542
31811
  RenderHookComponent,
31543
31812
  {
31544
- key: `${key}-${field}`,
31813
+ key: cell.key,
31545
31814
  render: col.render,
31546
31815
  renderParam: {
31547
- item: target,
31816
+ item: item.value,
31548
31817
  column: col,
31549
- value: target[field],
31818
+ value: cell.value,
31550
31819
  domProps
31551
31820
  }
31552
31821
  }
31553
- ) : /* @__PURE__ */ React61.createElement("div", { key: `${key}-${field}`, ...domProps }, target[field]);
31554
- }).filter(Boolean);
31822
+ ) : /* @__PURE__ */ React61.createElement("div", { key: cell.key, ...domProps }, cell.value);
31823
+ });
31555
31824
  }
31556
31825
  return /* @__PURE__ */ React61.createElement("div", { className: MenuRowCls }, content);
31557
31826
  }
@@ -31616,9 +31885,64 @@ Menu[propToIdentifyMenu] = true;
31616
31885
 
31617
31886
  // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
31618
31887
  var React63 = __toESM(require("react"));
31619
- function defaultGetColumnMenuItems(_items, params) {
31620
- const { columnApi, column, getComputed, api, dataSourceApi, getState } = params;
31621
- const CheckBoxCmp = getState().components?.CheckBox || InfiniteCheckBox;
31888
+
31889
+ // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
31890
+ function getMenuItemsAndColumns(menuDefinition) {
31891
+ let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
31892
+ const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
31893
+ return {
31894
+ items,
31895
+ columns
31896
+ };
31897
+ }
31898
+ function getMenuVisibilityProps(onHideIntent) {
31899
+ const onRootMouseDown = (event) => {
31900
+ event.__insideMenu = true;
31901
+ };
31902
+ const onHide = (state) => {
31903
+ state.domRef.current?.parentNode?.removeEventListener(
31904
+ "mousedown",
31905
+ onRootMouseDown
31906
+ );
31907
+ };
31908
+ return {
31909
+ onShow: (state) => {
31910
+ state.domRef.current?.parentNode?.addEventListener(
31911
+ "mousedown",
31912
+ onRootMouseDown
31913
+ );
31914
+ },
31915
+ onHide,
31916
+ onHideIntent: (state) => {
31917
+ onHide(state);
31918
+ onHideIntent?.();
31919
+ }
31920
+ };
31921
+ }
31922
+ function getMenuDefaultProps(config) {
31923
+ const menuDefaultProps = {
31924
+ columns: [],
31925
+ items: [],
31926
+ autoFocus: true,
31927
+ ...getMenuVisibilityProps(config.onHideIntent)
31928
+ };
31929
+ return menuDefaultProps;
31930
+ }
31931
+ function getLazyMenuProps(menuDefinition, menuDefaultProps) {
31932
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
31933
+ if (items && items.length) {
31934
+ return {
31935
+ ...menuDefaultProps,
31936
+ items: items || [],
31937
+ columns
31938
+ };
31939
+ }
31940
+ return null;
31941
+ }
31942
+
31943
+ // src/components/InfiniteTable/utils/menuItemsShared.ts
31944
+ function getDefaultColumnMenuItems(params, binder) {
31945
+ const { columnApi, column, getComputed, api, dataSourceApi } = params;
31622
31946
  const sortable = columnApi.isSortable();
31623
31947
  const sortItems = sortable ? [
31624
31948
  {
@@ -31699,25 +32023,22 @@ function defaultGetColumnMenuItems(_items, params) {
31699
32023
  const colItems = [];
31700
32024
  const computed = getComputed();
31701
32025
  computed.computedColumnsMapInInitialOrder.forEach((col, id) => {
31702
- const label = getColumnLabel(col, params, "column-menu");
32026
+ const label = binder.getColumnLabel(col);
31703
32027
  colItems.push({
31704
32028
  key: id,
31705
32029
  label,
31706
- check: /* @__PURE__ */ React63.createElement(
31707
- CheckBoxCmp,
31708
- {
31709
- key: col.id,
31710
- disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
31711
- checked: col.computedVisible,
31712
- onChange: (checked) => {
31713
- const visible = !!checked;
31714
- api.setVisibilityForColumn(col.id, visible);
31715
- requestAnimationFrame(() => {
31716
- api.realignColumnContextMenu();
31717
- });
31718
- }
32030
+ check: binder.renderCheckBox({
32031
+ key: col.id,
32032
+ disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
32033
+ checked: col.computedVisible,
32034
+ onChange: (checked) => {
32035
+ const visible = !!checked;
32036
+ api.setVisibilityForColumn(col.id, visible);
32037
+ requestAnimationFrame(() => {
32038
+ api.realignColumnContextMenu();
32039
+ });
31719
32040
  }
31720
- )
32041
+ })
31721
32042
  });
31722
32043
  });
31723
32044
  return {
@@ -31742,21 +32063,18 @@ function defaultGetColumnMenuItems(_items, params) {
31742
32063
  if (col.groupByForColumn) {
31743
32064
  return;
31744
32065
  }
31745
- const label = getColumnLabel(col, params, "column-menu");
32066
+ const label = binder.getColumnLabel(col);
31746
32067
  colItems.push({
31747
32068
  key: id,
31748
32069
  label,
31749
- check: /* @__PURE__ */ React63.createElement(
31750
- CheckBoxCmp,
31751
- {
31752
- key: col.id,
31753
- disabled: !col.computedGroupable,
31754
- checked: col.computedGroupedBy,
31755
- onChange: () => {
31756
- dataSourceApi.toggleGroupByField(col.field);
31757
- }
32070
+ check: binder.renderCheckBox({
32071
+ key: col.id,
32072
+ disabled: !col.computedGroupable,
32073
+ checked: col.computedGroupedBy,
32074
+ onChange: () => {
32075
+ dataSourceApi.toggleGroupByField(col.field);
31758
32076
  }
31759
- )
32077
+ })
31760
32078
  });
31761
32079
  });
31762
32080
  return {
@@ -31772,15 +32090,12 @@ function defaultGetColumnMenuItems(_items, params) {
31772
32090
  }
31773
32091
  ].filter((x) => !!x);
31774
32092
  }
31775
-
31776
- // src/components/InfiniteTable/utils/getMenuForColumn.tsx
31777
- function getMenuForColumn(columnId, context, onHideIntent) {
32093
+ function getColumnMenuProps(columnId, context, onHideIntent, getDefaultItems) {
31778
32094
  if (columnId == null) {
31779
32095
  return null;
31780
32096
  }
31781
32097
  const { getComputed, getState } = context;
31782
- const { components: components2, getColumnMenuItems } = getState();
31783
- const MenuCmp = components2?.Menu ?? Menu;
32098
+ const { getColumnMenuItems } = getState();
31784
32099
  const column = getComputed().computedColumnsMap.get(columnId);
31785
32100
  if (!column) {
31786
32101
  return null;
@@ -31790,124 +32105,465 @@ function getMenuForColumn(columnId, context, onHideIntent) {
31790
32105
  columnApi: getColumnApiForColumn(column.id, context),
31791
32106
  ...context
31792
32107
  };
31793
- const defaultItems = defaultGetColumnMenuItems([], param);
32108
+ const defaultItems = getDefaultItems(param);
31794
32109
  const items = getColumnMenuItems ? getColumnMenuItems(defaultItems, param) : defaultItems;
31795
- const onRootMouseDown = (event) => {
31796
- event.__insideMenu = true;
31797
- };
31798
- const onHide = (state) => {
31799
- state.domRef.current?.parentNode?.removeEventListener(
31800
- "mousedown",
31801
- onRootMouseDown
31802
- );
31803
- };
31804
32110
  if (!items || !items.length) {
31805
32111
  return null;
31806
32112
  }
31807
- return /* @__PURE__ */ React64.createElement(
31808
- MenuCmp,
31809
- {
31810
- autoFocus: true,
31811
- items,
31812
- onShow: (state) => {
31813
- state.domRef.current?.parentNode?.addEventListener(
31814
- "mousedown",
31815
- onRootMouseDown
31816
- );
31817
- },
31818
- onHide,
31819
- onHideIntent: (state) => {
31820
- onHide(state);
31821
- onHideIntent?.();
31822
- }
31823
- }
31824
- );
31825
- }
31826
-
31827
- // src/components/InfiniteTable/utils/menuOverlayTargets.ts
31828
- function resolveMenuElement(element) {
31829
- return typeof element === "function" ? element() : element;
31830
- }
31831
- function getMenuConstrainTo(state) {
31832
- return resolveMenuElement(state.menuConstrainTo) ?? state.domRef.current;
31833
- }
31834
- function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer) {
31835
- if (!menuPortalContainer) {
31836
- return defaultContainer || false;
31837
- }
31838
- return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
31839
- }
31840
-
31841
- // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
31842
- var import_react59 = require("react");
31843
- function useMenuPortalContainer() {
31844
- const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
31845
- return {
31846
- getState: ctx.getState,
31847
- menuPortalContainer: ctx.state.menuPortalContainer
31848
- };
31849
- });
31850
- const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
31851
- return {
31852
- portalDOMRef: ctx.getMasterState().portalDOMRef
31853
- };
31854
- }) || {};
31855
- const defaultContainer = portalDOMRef?.current;
31856
- return (0, import_react59.useMemo)(
31857
- () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
31858
- [getState, menuPortalContainer, defaultContainer]
31859
- );
32113
+ return {
32114
+ autoFocus: true,
32115
+ items,
32116
+ ...getMenuVisibilityProps(onHideIntent)
32117
+ };
31860
32118
  }
31861
-
31862
- // src/components/InfiniteTable/hooks/useColumnMenu.ts
31863
- var menuIconSelector2 = `[${MenuIconDataAttributes["data-name"]}="${MenuIconDataAttributesValues["data-name"]}"]`;
31864
- function showMenuForColumn(options) {
31865
- const { columnId, context, clearAll, showOverlay } = options;
31866
- const { getState, actions } = context;
31867
- const { columnMenuTargetRef, domRef } = getState();
31868
- function onHideIntent() {
31869
- clearAll();
31870
- actions.columnMenuVisibleForColumnId = null;
31871
- }
31872
- let target = options.target;
31873
- if (!target) {
31874
- target = columnMenuTargetRef.current ?? void 0;
31875
- if (target && !domRef.current.contains(target)) {
31876
- target = void 0;
31877
- }
31878
- }
31879
- if (!target) {
31880
- const iconSelector = `[${InfiniteHeaderCellDataAttributes["data-column-id"]}="${columnId}"] ${menuIconSelector2}`;
31881
- target = getState().domRef.current.querySelector(
31882
- iconSelector
31883
- );
31884
- }
31885
- if (!target) {
31886
- console.warn(`Cannot show column menu for column "${columnId}"`);
31887
- return;
32119
+ function getFilterOperatorMenuProps(columnId, context, onHideIntent, binder) {
32120
+ if (columnId == null) {
32121
+ return null;
31888
32122
  }
31889
- columnMenuTargetRef.current = null;
31890
- showOverlay(() => getMenuForColumn(columnId, context, onHideIntent), {
31891
- constrainTo: getMenuConstrainTo(getState()),
31892
- id: "column-menu",
31893
- alignTo: target,
31894
- alignPosition: [
31895
- ["TopLeft", "BottomLeft"],
31896
- ["TopRight", "BottomRight"]
31897
- ]
31898
- });
31899
- }
31900
- function useColumnMenu() {
31901
- const context = useInfiniteTableStableContext();
31902
32123
  const {
32124
+ getComputed,
31903
32125
  getState,
32126
+ getDataSourceState,
31904
32127
  actions,
31905
- columnMenuVisibleForColumnId,
31906
- columnMenuVisibleKey
31907
- } = useInfiniteTableSelector((ctx) => {
32128
+ dataSourceApi,
32129
+ dataSourceActions,
32130
+ api
32131
+ } = context;
32132
+ const { getFilterOperatorMenuItems } = getState();
32133
+ const column = getComputed().computedColumnsMap.get(columnId);
32134
+ if (!column) {
32135
+ return null;
32136
+ }
32137
+ const { filterTypes } = getDataSourceState();
32138
+ const columnFilterType = filterTypes[column.computedFilterType];
32139
+ if (!columnFilterType) {
32140
+ return null;
32141
+ }
32142
+ const operatorItems = columnFilterType.operators.map((operator) => {
32143
+ const key = operator.name;
32144
+ const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32145
+ return {
32146
+ key,
32147
+ icon: binder.renderOperatorIcon(operator),
32148
+ label: binder.renderOperatorLabel(operator.label ?? operator.name),
32149
+ onAction: () => {
32150
+ api.setColumnFilterOperator(columnId, key);
32151
+ },
32152
+ checked: checked ? binder.renderDoneIcon() : null
32153
+ };
32154
+ });
32155
+ const firstItems = [
32156
+ {
32157
+ key: "close",
32158
+ label: "Close Menu",
32159
+ icon: null,
32160
+ onAction: () => {
32161
+ api.hideFilterOperatorMenu();
32162
+ }
32163
+ },
32164
+ {
32165
+ key: "reset",
32166
+ label: "Reset",
32167
+ icon: binder.renderClearIcon(),
32168
+ disabled: !column.computedFiltered,
32169
+ onAction: () => {
32170
+ api.clearColumnFilter(columnId);
32171
+ }
32172
+ },
32173
+ "-"
32174
+ ];
32175
+ const defaultItems = [...firstItems, ...operatorItems];
32176
+ const param = {
32177
+ column,
32178
+ api,
32179
+ getState,
32180
+ getDataSourceState,
32181
+ getComputed,
32182
+ actions,
32183
+ dataSourceApi,
32184
+ dataSourceActions,
32185
+ columnFilterValue: column.computedFilterValue,
32186
+ filterTypes
32187
+ };
32188
+ const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32189
+ return {
32190
+ autoFocus: true,
32191
+ columns: [
32192
+ {
32193
+ name: "icon"
32194
+ },
32195
+ { name: "label" },
32196
+ { name: "checked" }
32197
+ ],
32198
+ items,
32199
+ ...getMenuVisibilityProps(onHideIntent)
32200
+ };
32201
+ }
32202
+ function getContextMenuContent(menuDefinition, menuDefaultProps, binder) {
32203
+ const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32204
+ if (menuDefinition instanceof Promise) {
32205
+ return {
32206
+ menu: binder.renderLazyMenu(menuDefinition, menuDefaultProps),
32207
+ preventDefault
32208
+ };
32209
+ }
32210
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32211
+ if (!items || !items.length) {
32212
+ return { menu: null, preventDefault: Array.isArray(items) };
32213
+ }
32214
+ return {
32215
+ preventDefault,
32216
+ menu: binder.renderMenu({ ...menuDefaultProps, columns, items })
32217
+ };
32218
+ }
32219
+ function getCellContextMenuContent(cellLocation, context, onHideIntent, binder) {
32220
+ const { columnId, rowIndex, event } = cellLocation;
32221
+ const { getComputed, getState } = context;
32222
+ const { getCellContextMenuItems } = getState();
32223
+ const { computedColumnsMap } = getComputed();
32224
+ const column = computedColumnsMap.get(columnId);
32225
+ const cellContext = {
32226
+ ...getCellContext({
32227
+ ...context,
32228
+ rowIndex,
32229
+ columnId: column.id
32230
+ }),
32231
+ event
32232
+ };
32233
+ if (!column || !getCellContextMenuItems) {
32234
+ return {
32235
+ cellContext,
32236
+ menu: null,
32237
+ preventDefault: false
32238
+ };
32239
+ }
32240
+ const menuDefaultProps = getMenuDefaultProps({
32241
+ onHideIntent
32242
+ });
32243
+ const menuDefinition = getCellContextMenuItems(cellContext, context);
32244
+ return {
32245
+ cellContext,
32246
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32247
+ };
32248
+ }
32249
+ function getTableContextMenuContent(menuLocation, context, onHideIntent, binder) {
32250
+ const { getState, getComputed } = context;
32251
+ const { getContextMenuItems } = getState();
32252
+ const { computedColumnsMap } = getComputed();
32253
+ const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32254
+ const cellContext = column ? {
32255
+ ...menuLocation,
32256
+ ...getCellContext({
32257
+ ...context,
32258
+ rowIndex: menuLocation.rowIndex,
32259
+ columnId: column.id
32260
+ })
32261
+ } : menuLocation;
32262
+ if (!getContextMenuItems) {
32263
+ return { cellContext, menu: null, preventDefault: false };
32264
+ }
32265
+ const menuDefaultProps = getMenuDefaultProps({
32266
+ onHideIntent
32267
+ });
32268
+ const menuDefinition = getContextMenuItems(cellContext, context);
32269
+ return {
32270
+ cellContext,
32271
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32272
+ };
32273
+ }
32274
+
32275
+ // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
32276
+ function defaultGetColumnMenuItems(_items, params) {
32277
+ const CheckBoxCmp = params.getState().components?.CheckBox || InfiniteCheckBox;
32278
+ return getDefaultColumnMenuItems(params, {
32279
+ renderCheckBox: ({ key, ...props }) => /* @__PURE__ */ React63.createElement(CheckBoxCmp, { key, ...props }),
32280
+ getColumnLabel: (col) => getColumnLabel(col, params, "column-menu")
32281
+ });
32282
+ }
32283
+
32284
+ // src/components/InfiniteTable/utils/getMenuForColumn.tsx
32285
+ function getMenuForColumn(columnId, context, onHideIntent) {
32286
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32287
+ const menuProps = getColumnMenuProps(
32288
+ columnId,
32289
+ context,
32290
+ onHideIntent,
32291
+ (param) => defaultGetColumnMenuItems([], param)
32292
+ );
32293
+ return menuProps ? /* @__PURE__ */ React64.createElement(MenuCmp, { ...menuProps }) : null;
32294
+ }
32295
+
32296
+ // src/components/InfiniteTable/utils/menuOverlayTargets.ts
32297
+ function resolveMenuElement(element) {
32298
+ return typeof element === "function" ? element() : element;
32299
+ }
32300
+ function getMenuConstrainTo(state) {
32301
+ return resolveMenuElement(state.menuConstrainTo) ?? state.domRef.current;
32302
+ }
32303
+ function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer) {
32304
+ if (!menuPortalContainer) {
32305
+ return defaultContainer || false;
32306
+ }
32307
+ return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
32308
+ }
32309
+
32310
+ // src/components/InfiniteTable/utils/menuOverlayShared.ts
32311
+ var CONTEXT_MENU_OFFSET = 5;
32312
+ var CONTEXT_MENU_ALIGN_POSITIONS = [
32313
+ ["TopLeft", "BottomLeft"],
32314
+ ["TopRight", "BottomRight"],
32315
+ ["BottomLeft", "BottomLeft"],
32316
+ ["BottomRight", "BottomRight"],
32317
+ ["TopCenter", "TopLeft"],
32318
+ ["BottomCenter", "TopLeft"],
32319
+ ["CenterLeft", "TopLeft"],
32320
+ ["CenterRight", "TopLeft"]
32321
+ ];
32322
+ var FILTER_OPERATOR_MENU_OFFSET = 10;
32323
+ function closeMenuOnOutsideMouseDown(close) {
32324
+ function handleMouseDown(event) {
32325
+ if (event.__insideMenu !== true) {
32326
+ close();
32327
+ }
32328
+ }
32329
+ document.documentElement.addEventListener("mousedown", handleMouseDown);
32330
+ return () => {
32331
+ document.documentElement.removeEventListener("mousedown", handleMouseDown);
32332
+ };
32333
+ }
32334
+ function menuVisibilityEffect(visible, clearAll, hide) {
32335
+ if (visible) {
32336
+ return closeMenuOnOutsideMouseDown(() => {
32337
+ clearAll();
32338
+ hide();
32339
+ });
32340
+ }
32341
+ clearAll();
32342
+ return void 0;
32343
+ }
32344
+ function getColumnMenuClickHandler(context) {
32345
+ const { getState, actions } = context;
32346
+ return (info) => {
32347
+ if (!info) {
32348
+ return;
32349
+ }
32350
+ getState().columnMenuTargetRef.current = info.target;
32351
+ actions.contextMenuVisibleFor = null;
32352
+ actions.cellContextMenuVisibleFor = null;
32353
+ actions.filterOperatorMenuVisibleForColumnId = null;
32354
+ actions.columnMenuVisibleForColumnId = info.column.id;
32355
+ };
32356
+ }
32357
+ function showMenuForColumn(options) {
32358
+ const { columnId, context, clearAll, show } = options;
32359
+ const { getState, actions } = context;
32360
+ const { columnMenuTargetRef, domRef } = getState();
32361
+ function onHideIntent() {
32362
+ clearAll();
32363
+ actions.columnMenuVisibleForColumnId = null;
32364
+ }
32365
+ let target = options.target;
32366
+ if (!target) {
32367
+ target = columnMenuTargetRef.current ?? void 0;
32368
+ if (target && !domRef.current.contains(target)) {
32369
+ target = void 0;
32370
+ }
32371
+ }
32372
+ if (!target) {
32373
+ const iconSelector = `[data-column-id="${columnId}"] ${menuIconSelector}`;
32374
+ target = getState().domRef.current.querySelector(
32375
+ iconSelector
32376
+ );
32377
+ }
32378
+ if (!target) {
32379
+ console.warn(`Cannot show column menu for column "${columnId}"`);
32380
+ return;
32381
+ }
32382
+ columnMenuTargetRef.current = null;
32383
+ show(onHideIntent, {
32384
+ constrainTo: getMenuConstrainTo(getState()),
32385
+ id: "column-menu",
32386
+ alignTo: target,
32387
+ alignPosition: [
32388
+ ["TopLeft", "BottomLeft"],
32389
+ ["TopRight", "BottomRight"]
32390
+ ]
32391
+ });
32392
+ }
32393
+ function columnMenuVisibilityEffect(context, overlay) {
32394
+ const { getState, actions } = context;
32395
+ const { clearAll } = overlay;
32396
+ const { columnMenuVisibleForColumnId, columnMenuTargetRef } = getState();
32397
+ if (columnMenuVisibleForColumnId) {
32398
+ const cleanup = closeMenuOnOutsideMouseDown(() => {
32399
+ clearAll();
32400
+ actions.columnMenuVisibleForColumnId = null;
32401
+ });
32402
+ showMenuForColumn({
32403
+ columnId: columnMenuVisibleForColumnId,
32404
+ context,
32405
+ clearAll,
32406
+ show: (onHideIntent, params) => overlay.show(columnMenuVisibleForColumnId, onHideIntent, params)
32407
+ });
32408
+ return cleanup;
32409
+ }
32410
+ columnMenuTargetRef.current = null;
32411
+ clearAll();
32412
+ return void 0;
32413
+ }
32414
+ function getContextMenuRect(event) {
32415
+ const point = {
32416
+ top: event.clientY,
32417
+ left: event.clientX
32418
+ };
32419
+ const rect = Rectangle.fromPoint(point);
32420
+ rect.width += CONTEXT_MENU_OFFSET;
32421
+ rect.height += CONTEXT_MENU_OFFSET;
32422
+ return { point, rect };
32423
+ }
32424
+ function getCellContextMenuHandler(context, overlay) {
32425
+ const { actions, getState, getDataSourceState } = context;
32426
+ const { clearAll } = overlay;
32427
+ return (info) => {
32428
+ if (!info) {
32429
+ return;
32430
+ }
32431
+ const { event } = info;
32432
+ function onHideIntent() {
32433
+ clearAll();
32434
+ actions.cellContextMenuVisibleFor = null;
32435
+ }
32436
+ const content = overlay.getContent(info, onHideIntent);
32437
+ const { cellContext, preventDefault } = content;
32438
+ const { rect } = getContextMenuRect(event);
32439
+ overlay.show(content, {
32440
+ constrainTo: getMenuConstrainTo(getState()),
32441
+ id: "cell-context-menu",
32442
+ alignTo: rect,
32443
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32444
+ });
32445
+ if (preventDefault) {
32446
+ event.preventDefault();
32447
+ }
32448
+ actions.cellContextMenuVisibleFor = {
32449
+ columnId: info.columnId,
32450
+ rowId: info.rowId,
32451
+ rowIndex: info.rowIndex,
32452
+ colIndex: info.colIndex
32453
+ };
32454
+ const { onCellContextMenu } = getState();
32455
+ if (onCellContextMenu) {
32456
+ onCellContextMenu(
32457
+ {
32458
+ ...cellContext,
32459
+ getState,
32460
+ getDataSourceState
32461
+ },
32462
+ event
32463
+ );
32464
+ }
32465
+ };
32466
+ }
32467
+ function getTableContextMenuHandler(context, overlay) {
32468
+ const { actions, getState } = context;
32469
+ const { clearAll } = overlay;
32470
+ return (info) => {
32471
+ if (!info) {
32472
+ return;
32473
+ }
32474
+ const { event } = info;
32475
+ function onHideIntent() {
32476
+ clearAll();
32477
+ actions.contextMenuVisibleFor = null;
32478
+ }
32479
+ const content = overlay.getContent(info, onHideIntent);
32480
+ const { cellContext, preventDefault } = content;
32481
+ const { point, rect } = getContextMenuRect(event);
32482
+ overlay.show(content, {
32483
+ constrainTo: getMenuConstrainTo(getState()),
32484
+ id: "table-context-menu",
32485
+ alignTo: rect,
32486
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32487
+ });
32488
+ if (preventDefault) {
32489
+ event.preventDefault();
32490
+ }
32491
+ actions.contextMenuVisibleFor = {
32492
+ point,
32493
+ ...info
32494
+ };
32495
+ const { onContextMenu } = getState();
32496
+ if (onContextMenu) {
32497
+ onContextMenu(
32498
+ {
32499
+ ...context,
32500
+ ...cellContext
32501
+ },
32502
+ event
32503
+ );
32504
+ }
32505
+ };
32506
+ }
32507
+ function getFilterOperatorMenuClickHandler(context, overlay) {
32508
+ const { getState, actions } = context;
32509
+ const { clearAll } = overlay;
32510
+ return (info) => {
32511
+ if (!info) {
32512
+ return;
32513
+ }
32514
+ const { target, column } = info;
32515
+ function onHideIntent() {
32516
+ clearAll();
32517
+ actions.filterOperatorMenuVisibleForColumnId = null;
32518
+ }
32519
+ const alignTo = target?.parentElement || target;
32520
+ const rect = Rectangle.from(alignTo.getBoundingClientRect());
32521
+ rect.top -= FILTER_OPERATOR_MENU_OFFSET;
32522
+ rect.left -= FILTER_OPERATOR_MENU_OFFSET;
32523
+ rect.width += 2 * FILTER_OPERATOR_MENU_OFFSET;
32524
+ rect.height += 2 * FILTER_OPERATOR_MENU_OFFSET;
32525
+ overlay.show(column.id, onHideIntent, {
32526
+ constrainTo: getMenuConstrainTo(getState()),
32527
+ id: "filter-operator-menu",
32528
+ alignTo: rect,
32529
+ alignPosition: [
32530
+ ["TopLeft", "BottomLeft"],
32531
+ ["TopRight", "BottomRight"]
32532
+ ]
32533
+ });
32534
+ actions.contextMenuVisibleFor = null;
32535
+ actions.cellContextMenuVisibleFor = null;
32536
+ actions.columnMenuVisibleForColumnId = null;
32537
+ actions.filterOperatorMenuVisibleForColumnId = column.id;
32538
+ };
32539
+ }
32540
+
32541
+ // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
32542
+ var import_react59 = require("react");
32543
+ function useMenuPortalContainer() {
32544
+ const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
31908
32545
  return {
31909
32546
  getState: ctx.getState,
31910
- actions: ctx.actions,
32547
+ menuPortalContainer: ctx.state.menuPortalContainer
32548
+ };
32549
+ });
32550
+ const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
32551
+ return {
32552
+ portalDOMRef: ctx.getMasterState().portalDOMRef
32553
+ };
32554
+ }) || {};
32555
+ const defaultContainer = portalDOMRef?.current;
32556
+ return (0, import_react59.useMemo)(
32557
+ () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
32558
+ [getState, menuPortalContainer, defaultContainer]
32559
+ );
32560
+ }
32561
+
32562
+ // src/components/InfiniteTable/hooks/useColumnMenu.ts
32563
+ function useColumnMenu() {
32564
+ const context = useInfiniteTableStableContext();
32565
+ const { columnMenuVisibleForColumnId, columnMenuVisibleKey } = useInfiniteTableSelector((ctx) => {
32566
+ return {
31911
32567
  columnMenuVisibleForColumnId: ctx.state.columnMenuVisibleForColumnId,
31912
32568
  columnMenuVisibleKey: ctx.state.columnMenuVisibleKey
31913
32569
  };
@@ -31920,47 +32576,16 @@ function useColumnMenu() {
31920
32576
  portalContainer: useMenuPortalContainer()
31921
32577
  });
31922
32578
  (0, import_react60.useEffect)(() => {
31923
- const state = getState();
31924
- return state.onColumnMenuClick.onChange((info) => {
31925
- if (!info) {
31926
- return;
31927
- }
31928
- state.columnMenuTargetRef.current = info.target;
31929
- actions.contextMenuVisibleFor = null;
31930
- actions.cellContextMenuVisibleFor = null;
31931
- actions.filterOperatorMenuVisibleForColumnId = null;
31932
- actions.columnMenuVisibleForColumnId = info.column.id;
31933
- });
32579
+ return context.getState().onColumnMenuClick.onChange(getColumnMenuClickHandler(context));
31934
32580
  }, []);
31935
32581
  (0, import_react60.useEffect)(() => {
31936
- const { columnMenuVisibleForColumnId: columnMenuVisibleForColumnId2, columnMenuTargetRef } = getState();
31937
- if (columnMenuVisibleForColumnId2) {
31938
- let handleMouseDown2 = function(event) {
31939
- if (event.__insideMenu !== true) {
31940
- clearAll();
31941
- actions.columnMenuVisibleForColumnId = null;
31942
- }
31943
- };
31944
- var handleMouseDown = handleMouseDown2;
31945
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
31946
- showMenuForColumn({
31947
- columnId: columnMenuVisibleForColumnId2,
31948
- context,
31949
- clearAll,
31950
- showOverlay
31951
- });
31952
- return () => {
31953
- document.documentElement.removeEventListener(
31954
- "mousedown",
31955
- handleMouseDown2
31956
- );
31957
- };
31958
- } else {
31959
- columnMenuTargetRef.current = null;
31960
- clearAll();
31961
- }
31962
- return () => {
31963
- };
32582
+ return columnMenuVisibilityEffect(context, {
32583
+ clearAll,
32584
+ show: (columnId, onHideIntent, params) => showOverlay(
32585
+ () => getMenuForColumn(columnId, context, onHideIntent),
32586
+ params
32587
+ )
32588
+ });
31964
32589
  }, [columnMenuVisibleForColumnId, columnMenuVisibleKey]);
31965
32590
  return { menuPortal };
31966
32591
  }
@@ -32143,149 +32768,59 @@ function useOnEditPersisted() {
32143
32768
  };
32144
32769
  if (persisted instanceof Error) {
32145
32770
  onEditPersistError?.({ ...params, error: persisted });
32146
- } else {
32147
- onEditPersistSuccess?.(params);
32148
- }
32149
- }
32150
- }, [persisted]);
32151
- }
32152
- function useEditingCallbackProps() {
32153
- useOnEditCancelled();
32154
- useOnEditRejected();
32155
- useOnEditAccepted();
32156
- useOnEditPersisted();
32157
- useFocusOnEditStop();
32158
- }
32159
-
32160
- // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32161
- var import_react63 = require("react");
32162
-
32163
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32164
- var React68 = __toESM(require("react"));
32165
-
32166
- // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32167
- var React66 = __toESM(require("react"));
32168
- var ClearIcon = (props) => {
32169
- return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32170
- };
32171
-
32172
- // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32173
- var React67 = __toESM(require("react"));
32174
- var DoneIcon = (props) => {
32175
- return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32176
- };
32177
-
32178
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32179
- function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32180
- if (columnId == null) {
32181
- return null;
32182
- }
32183
- const {
32184
- getComputed,
32185
- getState,
32186
- getDataSourceState,
32187
- actions,
32188
- dataSourceApi,
32189
- dataSourceActions,
32190
- api
32191
- } = context;
32192
- const { components: components2, getFilterOperatorMenuItems } = getState();
32193
- const MenuCmp = components2?.Menu ?? Menu;
32194
- const column = getComputed().computedColumnsMap.get(columnId);
32195
- if (!column) {
32196
- return null;
32197
- }
32198
- const onRootMouseDown = (event) => {
32199
- event.__insideMenu = true;
32200
- };
32201
- const onHide = (state) => {
32202
- state.domRef.current?.parentNode?.removeEventListener(
32203
- "mousedown",
32204
- onRootMouseDown
32205
- );
32206
- };
32207
- const { filterTypes } = getDataSourceState();
32208
- const columnFilterType = filterTypes[column.computedFilterType];
32209
- if (!columnFilterType) {
32210
- return null;
32211
- }
32212
- const operatorItems = columnFilterType.operators.map((operator) => {
32213
- const key = operator.name;
32214
- const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32215
- const IconCmp = operator.components?.Icon ?? FilterIcon;
32216
- return {
32217
- key,
32218
- icon: /* @__PURE__ */ React68.createElement(IconCmp, null),
32219
- label: /* @__PURE__ */ React68.createElement(React68.Fragment, null, operator.label ?? operator.name),
32220
- onAction: () => {
32221
- api.setColumnFilterOperator(columnId, key);
32222
- },
32223
- checked: checked ? /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 }) : null
32224
- };
32225
- });
32226
- const firstItems = [
32227
- {
32228
- key: "close",
32229
- label: "Close Menu",
32230
- icon: null,
32231
- onAction: () => {
32232
- api.hideFilterOperatorMenu();
32233
- }
32234
- },
32235
- {
32236
- key: "reset",
32237
- label: "Reset",
32238
- icon: /* @__PURE__ */ React68.createElement(ClearIcon, null),
32239
- disabled: !column.computedFiltered,
32240
- onAction: () => {
32241
- api.clearColumnFilter(columnId);
32242
- }
32243
- },
32244
- "-"
32245
- ];
32246
- const defaultItems = [...firstItems, ...operatorItems];
32247
- const param = {
32248
- column,
32249
- api,
32250
- getState,
32251
- getDataSourceState,
32252
- getComputed,
32253
- actions,
32254
- dataSourceApi,
32255
- dataSourceActions,
32256
- columnFilterValue: column.computedFilterValue,
32257
- filterTypes
32258
- };
32259
- const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32260
- return /* @__PURE__ */ React68.createElement(
32261
- MenuCmp,
32771
+ } else {
32772
+ onEditPersistSuccess?.(params);
32773
+ }
32774
+ }
32775
+ }, [persisted]);
32776
+ }
32777
+ function useEditingCallbackProps() {
32778
+ useOnEditCancelled();
32779
+ useOnEditRejected();
32780
+ useOnEditAccepted();
32781
+ useOnEditPersisted();
32782
+ useFocusOnEditStop();
32783
+ }
32784
+
32785
+ // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32786
+ var import_react63 = require("react");
32787
+
32788
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32789
+ var React68 = __toESM(require("react"));
32790
+
32791
+ // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32792
+ var React66 = __toESM(require("react"));
32793
+ var ClearIcon = (props) => {
32794
+ return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32795
+ };
32796
+
32797
+ // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32798
+ var React67 = __toESM(require("react"));
32799
+ var DoneIcon = (props) => {
32800
+ return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32801
+ };
32802
+
32803
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32804
+ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32805
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32806
+ const menuProps = getFilterOperatorMenuProps(
32807
+ columnId,
32808
+ context,
32809
+ onHideIntent,
32262
32810
  {
32263
- autoFocus: true,
32264
- columns: [
32265
- {
32266
- name: "icon"
32267
- },
32268
- { name: "label" },
32269
- { name: "checked" }
32270
- ],
32271
- items,
32272
- onShow: (state) => {
32273
- state.domRef.current?.parentNode?.addEventListener(
32274
- "mousedown",
32275
- onRootMouseDown
32276
- );
32811
+ renderOperatorIcon: (operator) => {
32812
+ const IconCmp = operator.components?.Icon ?? FilterIcon;
32813
+ return /* @__PURE__ */ React68.createElement(IconCmp, null);
32277
32814
  },
32278
- onHide,
32279
- onHideIntent: (state) => {
32280
- onHide(state);
32281
- onHideIntent?.();
32282
- }
32815
+ renderOperatorLabel: (label) => /* @__PURE__ */ React68.createElement(React68.Fragment, null, label),
32816
+ renderClearIcon: () => /* @__PURE__ */ React68.createElement(ClearIcon, null),
32817
+ renderDoneIcon: () => /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 })
32283
32818
  }
32284
32819
  );
32820
+ return menuProps ? /* @__PURE__ */ React68.createElement(MenuCmp, { ...menuProps }) : null;
32285
32821
  }
32286
32822
 
32287
32823
  // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32288
- var OFFSET2 = 10;
32289
32824
  function useColumnFilterOperatorMenu() {
32290
32825
  const stableContext = useInfiniteTableStableContext();
32291
32826
  const { getState, actions } = stableContext;
@@ -32297,66 +32832,28 @@ function useColumnFilterOperatorMenu() {
32297
32832
  portalContainer: useMenuPortalContainer()
32298
32833
  });
32299
32834
  (0, import_react63.useEffect)(() => {
32300
- const state = getState();
32301
- return state.onFilterOperatorMenuClick.onChange((info) => {
32302
- if (!info) {
32303
- return;
32304
- }
32305
- const { target, column } = info;
32306
- function onHideIntent() {
32307
- clearAll();
32308
- actions.filterOperatorMenuVisibleForColumnId = null;
32309
- }
32310
- let alignTo = target?.parentElement || target;
32311
- const rect = Rectangle.from(alignTo.getBoundingClientRect());
32312
- rect.top -= OFFSET2;
32313
- rect.left -= OFFSET2;
32314
- rect.width += 2 * OFFSET2;
32315
- rect.height += 2 * OFFSET2;
32316
- showOverlay(
32317
- () => getFilterOperatorMenuForColumn(
32318
- column.id,
32319
- stableContext,
32320
- onHideIntent
32321
- ),
32322
- {
32323
- constrainTo: getMenuConstrainTo(getState()),
32324
- id: "filter-operator-menu",
32325
- alignTo: rect,
32326
- alignPosition: [
32327
- ["TopLeft", "BottomLeft"],
32328
- ["TopRight", "BottomRight"]
32329
- ]
32330
- }
32331
- );
32332
- actions.contextMenuVisibleFor = null;
32333
- actions.cellContextMenuVisibleFor = null;
32334
- actions.columnMenuVisibleForColumnId = null;
32335
- actions.filterOperatorMenuVisibleForColumnId = column.id;
32336
- });
32835
+ return getState().onFilterOperatorMenuClick.onChange(
32836
+ getFilterOperatorMenuClickHandler(stableContext, {
32837
+ clearAll,
32838
+ show: (columnId, onHideIntent, params) => showOverlay(
32839
+ () => getFilterOperatorMenuForColumn(
32840
+ columnId,
32841
+ stableContext,
32842
+ onHideIntent
32843
+ ),
32844
+ params
32845
+ )
32846
+ })
32847
+ );
32337
32848
  }, []);
32338
32849
  (0, import_react63.useEffect)(() => {
32339
- const { filterOperatorMenuVisibleForColumnId } = getState();
32340
- if (filterOperatorMenuVisibleForColumnId) {
32341
- let handleMouseDown2 = function(event) {
32342
- if (event.__insideMenu !== true) {
32343
- clearAll();
32344
- actions.filterOperatorMenuVisibleForColumnId = null;
32345
- }
32346
- };
32347
- var handleMouseDown = handleMouseDown2;
32348
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32349
- return () => {
32350
- document.documentElement.removeEventListener(
32351
- "mousedown",
32352
- handleMouseDown2
32353
- );
32354
- };
32355
- } else {
32356
- clearAll();
32357
- }
32358
- return () => {
32359
- };
32850
+ return menuVisibilityEffect(
32851
+ getState().filterOperatorMenuVisibleForColumnId,
32852
+ clearAll,
32853
+ () => {
32854
+ actions.filterOperatorMenuVisibleForColumnId = null;
32855
+ }
32856
+ );
32360
32857
  }, [getState().filterOperatorMenuVisibleForColumnId]);
32361
32858
  return { menuPortal };
32362
32859
  }
@@ -32369,159 +32866,46 @@ var React70 = __toESM(require("react"));
32369
32866
 
32370
32867
  // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32371
32868
  var React69 = __toESM(require("react"));
32372
-
32373
- // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
32374
- function getMenuItemsAndColumns(menuDefinition) {
32375
- let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
32376
- const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
32377
- return {
32378
- items,
32379
- columns
32380
- };
32381
- }
32382
- function getMenuDefaultProps(config) {
32383
- const onRootMouseDown = (event) => {
32384
- event.__insideMenu = true;
32385
- };
32386
- const onHide = (state) => {
32387
- state.domRef.current?.parentNode?.removeEventListener(
32388
- "mousedown",
32389
- onRootMouseDown
32390
- );
32391
- };
32392
- const menuDefaultProps = {
32393
- columns: [],
32394
- items: [],
32395
- autoFocus: true,
32396
- onShow: (state) => {
32397
- state.domRef.current?.parentNode?.addEventListener(
32398
- "mousedown",
32399
- onRootMouseDown
32400
- );
32401
- },
32402
- onHide,
32403
- onHideIntent: (state) => {
32404
- onHide(state);
32405
- config.onHideIntent?.();
32406
- }
32407
- };
32408
- return menuDefaultProps;
32409
- }
32410
-
32411
- // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32412
32869
  function getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp) {
32413
32870
  if (!menuDefinition) {
32414
32871
  return null;
32415
32872
  }
32416
32873
  const updater = buildSubscriptionCallback();
32417
32874
  menuDefinition.then((menuDefinition2) => {
32418
- const { items, columns } = getMenuItemsAndColumns(menuDefinition2);
32419
- if (items && items.length) {
32420
- updater(
32421
- /* @__PURE__ */ React69.createElement(MenuCmp, { ...menuDefaultProps, items: items || [], columns })
32422
- );
32875
+ const menuProps = getLazyMenuProps(menuDefinition2, menuDefaultProps);
32876
+ if (menuProps) {
32877
+ updater(/* @__PURE__ */ React69.createElement(MenuCmp, { ...menuProps }));
32423
32878
  }
32424
32879
  });
32425
32880
  return /* @__PURE__ */ React69.createElement(AvoidReactDiff, { updater });
32426
32881
  }
32427
32882
 
32428
32883
  // src/components/InfiniteTable/utils/getCellContextMenu.tsx
32429
- function getCellContextMenu(cellLocation, context, onHideIntent) {
32430
- const { columnId, rowIndex, event } = cellLocation;
32431
- const { getComputed, getState } = context;
32432
- const { components: components2, getCellContextMenuItems } = getState();
32433
- const MenuCmp = components2?.Menu ?? Menu;
32434
- const { computedColumnsMap } = getComputed();
32435
- const column = computedColumnsMap.get(columnId);
32436
- const cellContext = {
32437
- ...getCellContext({
32438
- ...context,
32439
- rowIndex,
32440
- columnId: column.id
32441
- }),
32442
- event
32443
- };
32444
- if (!column || !getCellContextMenuItems) {
32445
- return {
32446
- cellContext,
32447
- menu: null,
32448
- preventDefault: false
32449
- };
32450
- }
32451
- const menuDefaultProps = getMenuDefaultProps({
32452
- onHideIntent
32453
- });
32454
- const menuDefinition = getCellContextMenuItems(cellContext, context);
32455
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32456
- if (menuDefinition instanceof Promise) {
32457
- return {
32458
- cellContext,
32459
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32460
- preventDefault
32461
- };
32462
- }
32463
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32464
- if (!items || !items.length) {
32465
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32466
- }
32884
+ function getContextMenuBinder(context) {
32885
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32467
32886
  return {
32468
- preventDefault,
32469
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32470
- cellContext
32887
+ renderMenu: (props) => /* @__PURE__ */ React70.createElement(MenuCmp, { ...props }),
32888
+ renderLazyMenu: (menuDefinition, menuDefaultProps) => getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp)
32471
32889
  };
32472
32890
  }
32891
+ function getCellContextMenu(cellLocation, context, onHideIntent) {
32892
+ return getCellContextMenuContent(
32893
+ cellLocation,
32894
+ context,
32895
+ onHideIntent,
32896
+ getContextMenuBinder(context)
32897
+ );
32898
+ }
32473
32899
  function getTableContextMenu(menuLocation, context, onHideIntent) {
32474
- const { getState, getComputed } = context;
32475
- const { components: components2, getContextMenuItems } = getState();
32476
- const MenuCmp = components2?.Menu ?? Menu;
32477
- const { computedColumnsMap } = getComputed();
32478
- const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32479
- const cellContext = column ? {
32480
- ...menuLocation,
32481
- ...getCellContext({
32482
- ...context,
32483
- rowIndex: menuLocation.rowIndex,
32484
- columnId: column.id
32485
- })
32486
- } : menuLocation;
32487
- if (!getContextMenuItems) {
32488
- return { cellContext, menu: null, preventDefault: false };
32489
- }
32490
- const menuDefaultProps = getMenuDefaultProps({
32491
- onHideIntent
32492
- });
32493
- const menuDefinition = getContextMenuItems(cellContext, context);
32494
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32495
- if (menuDefinition instanceof Promise) {
32496
- return {
32497
- cellContext,
32498
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32499
- preventDefault
32500
- };
32501
- }
32502
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32503
- if (!items || !items.length) {
32504
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32505
- }
32506
- return {
32507
- preventDefault,
32508
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32509
- cellContext
32510
- };
32900
+ return getTableContextMenuContent(
32901
+ menuLocation,
32902
+ context,
32903
+ onHideIntent,
32904
+ getContextMenuBinder(context)
32905
+ );
32511
32906
  }
32512
32907
 
32513
32908
  // src/components/InfiniteTable/hooks/useContextMenu.ts
32514
- var OFFSET3 = 5;
32515
- var ALIGN_POSITIONS = [
32516
- ["TopLeft", "BottomLeft"],
32517
- ["TopRight", "BottomRight"],
32518
- ["BottomLeft", "BottomLeft"],
32519
- ["BottomRight", "BottomRight"],
32520
- ["TopCenter", "TopLeft"],
32521
- ["BottomCenter", "TopLeft"],
32522
- ["CenterLeft", "TopLeft"],
32523
- ["CenterRight", "TopLeft"]
32524
- ];
32525
32909
  function useCellContextMenu() {
32526
32910
  const context = useInfiniteTableStableContext();
32527
32911
  const { getState, actions } = context;
@@ -32533,78 +32917,22 @@ function useCellContextMenu() {
32533
32917
  portalContainer: useMenuPortalContainer()
32534
32918
  });
32535
32919
  (0, import_react64.useEffect)(() => {
32536
- const { actions: actions2, getState: getState2, getDataSourceState } = context;
32537
- const state = getState2();
32538
- return state.cellContextMenu.onChange((info) => {
32539
- if (!info) {
32540
- return;
32541
- }
32542
- const { event } = info;
32543
- function onHideIntent() {
32544
- clearAll();
32545
- actions2.cellContextMenuVisibleFor = null;
32546
- }
32547
- const { menu, cellContext, preventDefault } = getCellContextMenu(
32548
- info,
32549
- context,
32550
- onHideIntent
32551
- );
32552
- const rect = Rectangle.fromPoint({
32553
- top: event.clientY,
32554
- left: event.clientX
32555
- });
32556
- rect.width += OFFSET3;
32557
- rect.height += OFFSET3;
32558
- showOverlay(menu, {
32559
- constrainTo: getMenuConstrainTo(getState2()),
32560
- id: "cell-context-menu",
32561
- alignTo: rect,
32562
- alignPosition: ALIGN_POSITIONS
32563
- });
32564
- if (preventDefault) {
32565
- event.preventDefault();
32566
- }
32567
- actions2.cellContextMenuVisibleFor = {
32568
- columnId: info.columnId,
32569
- rowId: info.rowId,
32570
- rowIndex: info.rowIndex,
32571
- colIndex: info.colIndex
32572
- };
32573
- const { onCellContextMenu } = getState2();
32574
- if (onCellContextMenu) {
32575
- onCellContextMenu(
32576
- {
32577
- ...cellContext,
32578
- getState: getState2,
32579
- getDataSourceState
32580
- },
32581
- event
32582
- );
32583
- }
32584
- });
32920
+ return getState().cellContextMenu.onChange(
32921
+ getCellContextMenuHandler(context, {
32922
+ clearAll,
32923
+ getContent: (info, onHideIntent) => getCellContextMenu(info, context, onHideIntent),
32924
+ show: ({ menu }, params) => showOverlay(menu, params)
32925
+ })
32926
+ );
32585
32927
  }, []);
32586
32928
  (0, import_react64.useEffect)(() => {
32587
- const { cellContextMenuVisibleFor } = getState();
32588
- if (cellContextMenuVisibleFor) {
32589
- let handleMouseDown2 = function(event) {
32590
- if (event.__insideMenu !== true) {
32591
- clearAll();
32592
- actions.cellContextMenuVisibleFor = null;
32593
- }
32594
- };
32595
- var handleMouseDown = handleMouseDown2;
32596
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32597
- return () => {
32598
- document.documentElement.removeEventListener(
32599
- "mousedown",
32600
- handleMouseDown2
32601
- );
32602
- };
32603
- } else {
32604
- clearAll();
32605
- }
32606
- return () => {
32607
- };
32929
+ return menuVisibilityEffect(
32930
+ getState().cellContextMenuVisibleFor,
32931
+ clearAll,
32932
+ () => {
32933
+ actions.cellContextMenuVisibleFor = null;
32934
+ }
32935
+ );
32608
32936
  }, [getState().cellContextMenuVisibleFor]);
32609
32937
  return { menuPortal };
32610
32938
  }
@@ -32619,76 +32947,22 @@ function useTableContextMenu() {
32619
32947
  portalContainer: useMenuPortalContainer()
32620
32948
  });
32621
32949
  (0, import_react64.useEffect)(() => {
32622
- const { actions: actions2, getState: getState2 } = context;
32623
- const state = getState2();
32624
- return state.contextMenu.onChange((info) => {
32625
- if (!info) {
32626
- return;
32627
- }
32628
- const { event } = info;
32629
- function onHideIntent() {
32630
- clearAll();
32631
- actions2.contextMenuVisibleFor = null;
32632
- }
32633
- const { menu, cellContext, preventDefault } = getTableContextMenu(
32634
- info,
32635
- context,
32636
- onHideIntent
32637
- );
32638
- const point = {
32639
- top: event.clientY,
32640
- left: event.clientX
32641
- };
32642
- const rect = Rectangle.fromPoint(point);
32643
- rect.width += OFFSET3;
32644
- rect.height += OFFSET3;
32645
- showOverlay(menu, {
32646
- constrainTo: getMenuConstrainTo(getState2()),
32647
- id: "table-context-menu",
32648
- alignTo: rect,
32649
- alignPosition: ALIGN_POSITIONS
32650
- });
32651
- if (preventDefault) {
32652
- event.preventDefault();
32653
- }
32654
- actions2.contextMenuVisibleFor = {
32655
- point,
32656
- ...info
32657
- };
32658
- const { onContextMenu } = getState2();
32659
- if (onContextMenu) {
32660
- onContextMenu(
32661
- {
32662
- ...context,
32663
- ...cellContext
32664
- },
32665
- event
32666
- );
32667
- }
32668
- });
32950
+ return getState().contextMenu.onChange(
32951
+ getTableContextMenuHandler(context, {
32952
+ clearAll,
32953
+ getContent: (info, onHideIntent) => getTableContextMenu(info, context, onHideIntent),
32954
+ show: ({ menu }, params) => showOverlay(menu, params)
32955
+ })
32956
+ );
32669
32957
  }, []);
32670
32958
  (0, import_react64.useEffect)(() => {
32671
- const { contextMenuVisibleFor } = getState();
32672
- if (contextMenuVisibleFor) {
32673
- let handleMouseDown2 = function(event) {
32674
- if (event.__insideMenu !== true) {
32675
- clearAll();
32676
- actions.contextMenuVisibleFor = null;
32677
- }
32678
- };
32679
- var handleMouseDown = handleMouseDown2;
32680
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32681
- return () => {
32682
- document.documentElement.removeEventListener(
32683
- "mousedown",
32684
- handleMouseDown2
32685
- );
32686
- };
32687
- } else {
32688
- clearAll();
32689
- }
32690
- return () => {
32691
- };
32959
+ return menuVisibilityEffect(
32960
+ getState().contextMenuVisibleFor,
32961
+ clearAll,
32962
+ () => {
32963
+ actions.contextMenuVisibleFor = null;
32964
+ }
32965
+ );
32692
32966
  }, [getState().contextMenuVisibleFor]);
32693
32967
  return { menuPortal };
32694
32968
  }