@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.mjs CHANGED
@@ -1900,6 +1900,62 @@ function computePropsDiff(params) {
1900
1900
  rawUpdatedPropsCount
1901
1901
  };
1902
1902
  }
1903
+ function applyPropsDiff(params) {
1904
+ const {
1905
+ currentProps,
1906
+ prevProps,
1907
+ state,
1908
+ propsToForward,
1909
+ propsToStateSet,
1910
+ dispatch,
1911
+ actions,
1912
+ onPropChange: onPropChange2,
1913
+ onPropsChange,
1914
+ beforeDispatch
1915
+ } = params;
1916
+ const diff = computePropsDiff({
1917
+ currentProps,
1918
+ prevProps,
1919
+ state,
1920
+ propsToForward,
1921
+ propsToStateSet
1922
+ });
1923
+ const {
1924
+ newMappedState,
1925
+ newMappedStateCount,
1926
+ updatedPropsToState,
1927
+ updatedPropsToStateCount,
1928
+ rawUpdatedProps,
1929
+ rawUpdatedPropsCount
1930
+ } = diff;
1931
+ if (updatedPropsToStateCount === 0 && newMappedStateCount === 0) {
1932
+ return false;
1933
+ }
1934
+ beforeDispatch?.(diff);
1935
+ dispatch({
1936
+ payload: {
1937
+ mappedState: newMappedStateCount ? newMappedState : null,
1938
+ updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
1939
+ }
1940
+ });
1941
+ if (onPropChange2) {
1942
+ for (const prop in rawUpdatedProps) {
1943
+ if (rawUpdatedProps.hasOwnProperty(prop)) {
1944
+ const { newValue, oldValue } = rawUpdatedProps[prop];
1945
+ onPropChange2(
1946
+ { name: prop, newValue, oldValue },
1947
+ currentProps,
1948
+ actions,
1949
+ state
1950
+ );
1951
+ }
1952
+ }
1953
+ }
1954
+ if (onPropsChange && rawUpdatedPropsCount) {
1955
+ onPropsChange(rawUpdatedProps, currentProps, actions, state);
1956
+ }
1957
+ return true;
1958
+ }
1903
1959
 
1904
1960
  // src/components/hooks/useComponentState/index.tsx
1905
1961
  var ComponentContext;
@@ -1995,79 +2051,56 @@ function buildManagedComponent(config) {
1995
2051
  const effectFn = config.layoutEffect ? useLayoutEffect4 : useEffect3;
1996
2052
  effectFn(() => {
1997
2053
  const currentProps = props;
1998
- const {
1999
- newMappedState,
2000
- newMappedStateCount,
2001
- updatedPropsToState,
2002
- updatedPropsToStateCount,
2003
- rawUpdatedProps,
2004
- rawUpdatedPropsCount
2005
- } = computePropsDiff({
2054
+ const dispatched = applyPropsDiff({
2006
2055
  currentProps,
2007
2056
  prevProps,
2008
2057
  state,
2009
2058
  propsToForward,
2010
- propsToStateSet: propsToStateSetRef.current
2011
- });
2012
- if (updatedPropsToStateCount > 0 || newMappedStateCount > 0) {
2013
- const debugId = state.debugId;
2014
- const marker = debugId ? getMarker(debugId).track.ComponentState.label.PropUpdate.start() : void 0;
2015
- const debugChannelName = config.debugName ? typeof config.debugName === "function" ? `${config.debugName(currentProps)}:rerender` : `${config.debugName}:rerender` : "rerender";
2016
- const logger2 = dbg(debugChannelName);
2017
- logger2(
2018
- "Triggered by new values for the following props",
2019
- ...[
2020
- ...Object.keys(newMappedState ?? {}),
2021
- ...Object.keys(updatedPropsToState ?? {})
2022
- ]
2023
- );
2024
- if (marker) {
2025
- marker.end({
2026
- label: debugChannelName,
2027
- details: [
2028
- newMappedStateCount > 0 ? {
2029
- name: "Updated properties",
2030
- value: Object.keys(newMappedState).join(", ")
2031
- } : void 0,
2032
- updatedPropsToStateCount > 0 ? {
2033
- name: "Updated props",
2034
- value: Object.keys(updatedPropsToState).join(", ")
2035
- } : void 0,
2036
- updatedPropsToStateCount > 0 || updatedPropsToState ? {
2037
- name: "Details",
2038
- value: "The time for this marker is not accurate. The marker is only displayed so you can easily identify the props that triggered the rerender."
2039
- } : void 0
2040
- ].filter(notNullable)
2041
- });
2042
- }
2043
- const action = {
2044
- payload: {
2045
- mappedState: newMappedStateCount ? newMappedState : null,
2046
- updatedPropsToState: updatedPropsToStateCount ? updatedPropsToState : null
2047
- }
2048
- };
2049
- skipTriggerParentStateChangeRef.current = true;
2050
- dispatch(action);
2051
- if (config.onPropChange) {
2052
- for (var prop in rawUpdatedProps)
2053
- if (rawUpdatedProps.hasOwnProperty(prop)) {
2054
- const { newValue, oldValue } = rawUpdatedProps[prop];
2055
- config.onPropChange(
2056
- { name: prop, newValue, oldValue },
2057
- props,
2058
- actions,
2059
- state
2060
- );
2061
- }
2062
- }
2063
- if (config.onPropsChange && rawUpdatedPropsCount) {
2064
- config.onPropsChange(
2065
- rawUpdatedProps,
2066
- props,
2067
- actions,
2068
- state
2059
+ propsToStateSet: propsToStateSetRef.current,
2060
+ dispatch,
2061
+ actions,
2062
+ onPropChange: config.onPropChange,
2063
+ onPropsChange: config.onPropsChange,
2064
+ beforeDispatch: ({
2065
+ newMappedState,
2066
+ newMappedStateCount,
2067
+ updatedPropsToState,
2068
+ updatedPropsToStateCount
2069
+ }) => {
2070
+ const debugId = state.debugId;
2071
+ const marker = debugId ? getMarker(debugId).track.ComponentState.label.PropUpdate.start() : void 0;
2072
+ const debugChannelName = config.debugName ? typeof config.debugName === "function" ? `${config.debugName(currentProps)}:rerender` : `${config.debugName}:rerender` : "rerender";
2073
+ const logger2 = dbg(debugChannelName);
2074
+ logger2(
2075
+ "Triggered by new values for the following props",
2076
+ ...[
2077
+ ...Object.keys(newMappedState ?? {}),
2078
+ ...Object.keys(updatedPropsToState ?? {})
2079
+ ]
2069
2080
  );
2081
+ if (marker) {
2082
+ marker.end({
2083
+ label: debugChannelName,
2084
+ details: [
2085
+ newMappedStateCount > 0 ? {
2086
+ name: "Updated properties",
2087
+ value: Object.keys(newMappedState).join(", ")
2088
+ } : void 0,
2089
+ updatedPropsToStateCount > 0 ? {
2090
+ name: "Updated props",
2091
+ value: Object.keys(updatedPropsToState).join(", ")
2092
+ } : void 0,
2093
+ updatedPropsToStateCount > 0 || updatedPropsToState ? {
2094
+ name: "Details",
2095
+ value: "The time for this marker is not accurate. The marker is only displayed so you can easily identify the props that triggered the rerender."
2096
+ } : void 0
2097
+ ].filter(notNullable)
2098
+ });
2099
+ }
2070
2100
  }
2101
+ });
2102
+ if (dispatched) {
2103
+ skipTriggerParentStateChangeRef.current = true;
2071
2104
  }
2072
2105
  });
2073
2106
  effectFn(() => {
@@ -2451,7 +2484,7 @@ var HeaderFilterOperatorCls = "_12zfob12q _16lm1iw1p _16lm1iw2h _16lm1iw2j _16lm
2451
2484
  var HeaderFilterOperatorIconRecipe = createRuntimeFn({ defaultClassName: "_12zfob12r _16lm1iw1 _16lm1iw23", variantClassNames: { disabled: { true: "_12zfob12s", false: "_12zfob12t" } }, defaultVariants: {}, compoundVariants: [] });
2452
2485
  var HeaderFilterRecipe = createRuntimeFn({ defaultClassName: "_12zfob12n _16lm1iw1p _16lm1iw2h _16lm1iw2k _16lm1iw1", variantClassNames: { active: { true: "_12zfob12o", false: "_12zfob12p" } }, defaultVariants: {}, compoundVariants: [] });
2453
2486
  var HeaderGroupCls = "_12zfob12m _16lm1iw1p _16lm1iw2h _16lm1iw2j";
2454
- var HeaderMenuIconCls = createRuntimeFn({ defaultClassName: "_12zfob127 _16lm1iw1 _16lm1iw1p _16lm1iw2f _16lm1iw32 _16lm1iw39", variantClassNames: { menuVisible: { true: "_12zfob128" }, reserveSpaceWhenHidden: { true: "_12zfob129", false: "_12zfob12a" } }, defaultVariants: {}, compoundVariants: [[{ menuVisible: true, reserveSpaceWhenHidden: false }, "_12zfob12b"]] });
2487
+ var HeaderMenuIconCls = createRuntimeFn({ defaultClassName: "_12zfob127 _16lm1iw1 _16lm1iw39", variantClassNames: { menuVisible: { true: "_12zfob128" }, reserveSpaceWhenHidden: { true: "_12zfob129", false: "_12zfob12a" } }, defaultVariants: {}, compoundVariants: [[{ menuVisible: true, reserveSpaceWhenHidden: false }, "_12zfob12b"]] });
2455
2488
  var HeaderScrollbarPlaceholderCls = "_12zfob1b _16lm1iw2";
2456
2489
  var HeaderSortIconCls = "_16lm1iw1";
2457
2490
  var HeaderSortIconIndexCls = "_12zfob16";
@@ -3698,8 +3731,7 @@ function getColumnApiForColumn(colOrColId, param) {
3698
3731
  }
3699
3732
 
3700
3733
  // src/components/InfiniteTable/components/InfiniteTableHeader/getColumnLabel.ts
3701
- function getColumnLabel(colIdOrCol, context, renderLocation) {
3702
- const col = typeof colIdOrCol === "string" ? context.getComputed().computedColumnsMap.get(colIdOrCol) : colIdOrCol;
3734
+ function getColumnLabelHeaderParam(col, context, renderLocation) {
3703
3735
  const {
3704
3736
  api,
3705
3737
  getComputed,
@@ -3711,35 +3743,47 @@ function getColumnLabel(colIdOrCol, context, renderLocation) {
3711
3743
  const dataSourceState = getDataSourceState();
3712
3744
  const { allRowsSelected, someRowsSelected, selectionMode } = dataSourceState;
3713
3745
  const computed = getComputed();
3714
- let label = col.header && typeof col.header !== "function" ? col.header : col.name || col.id || "";
3715
- if (typeof col.header === "function") {
3716
- const columnApi = getColumnApiForColumn(col.id, {
3717
- ...context,
3718
- actions,
3719
- dataSourceActions,
3720
- dataSourceApi
3721
- });
3722
- label = col.header({
3723
- horizontalLayoutPageIndex: null,
3724
- column: col,
3725
- columnApi,
3726
- dataSourceApi,
3727
- renderLocation,
3728
- dragging: false,
3729
- columnsMap: computed.computedColumnsMap,
3730
- columnSortInfo: col.computedSortInfo,
3731
- columnFilterValue: col.computedFilterValue,
3732
- filtered: col.computedFiltered,
3733
- allRowsSelected,
3734
- someRowsSelected,
3735
- selectionMode,
3736
- api,
3737
- renderBag: {
3738
- header: label
3739
- }
3740
- }) ?? null;
3746
+ const columnApi = getColumnApiForColumn(col.id, {
3747
+ ...context,
3748
+ actions,
3749
+ dataSourceActions,
3750
+ dataSourceApi
3751
+ });
3752
+ return {
3753
+ horizontalLayoutPageIndex: null,
3754
+ column: col,
3755
+ columnApi,
3756
+ dataSourceApi,
3757
+ renderLocation,
3758
+ dragging: false,
3759
+ columnsMap: computed.computedColumnsMap,
3760
+ columnSortInfo: col.computedSortInfo,
3761
+ columnFilterValue: col.computedFilterValue,
3762
+ filtered: col.computedFiltered,
3763
+ allRowsSelected,
3764
+ someRowsSelected,
3765
+ selectionMode,
3766
+ api,
3767
+ renderBag: {
3768
+ header: col.name || col.id || ""
3769
+ }
3770
+ };
3771
+ }
3772
+ function getColumnLabel(colIdOrCol, context, renderLocation, bind) {
3773
+ const col = typeof colIdOrCol === "string" ? context.getComputed().computedColumnsMap.get(colIdOrCol) : colIdOrCol;
3774
+ const header = col.header;
3775
+ if (typeof header === "function") {
3776
+ const param = getColumnLabelHeaderParam(col, context, renderLocation);
3777
+ const label = header(param) ?? null;
3778
+ return bind ? bind(label, param) : label;
3741
3779
  }
3742
- return label;
3780
+ if (header) {
3781
+ return bind ? bind(
3782
+ header,
3783
+ getColumnLabelHeaderParam(col, context, renderLocation)
3784
+ ) : header;
3785
+ }
3786
+ return col.name || col.id || "";
3743
3787
  }
3744
3788
 
3745
3789
  // src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilterContext.ts
@@ -11786,9 +11830,10 @@ import * as React28 from "react";
11786
11830
  import { useEffect as useEffect10, useState as useState9 } from "react";
11787
11831
 
11788
11832
  // src/components/InfiniteTable/components/icons/SortIcon/SortIcon.css.ts
11789
- var SortIconCls = "_1b8djff0 _16lm1iw1p _16lm1iw2f _16lm1iw1 _16lm1iw32";
11790
- var SortIconDirectionCls = { asc: "_1b8djff1", desc: "_1b8djff2", none: "_1b8djff3" };
11791
- var SortIconLineCls = "_1b8djff4";
11833
+ var SortIconCls = "_1b8djff1 _16lm1iw1";
11834
+ var SortIconDirectionCls = { asc: "_1b8djff2", desc: "_1b8djff3", none: "_1b8djff4" };
11835
+ var SortIconLineCls = "_1b8djff5";
11836
+ var SortIconLineWidthVarName = "--_1b8djff0";
11792
11837
 
11793
11838
  // src/components/InfiniteTable/components/icons/SortIcon/shared.ts
11794
11839
  var defaultLineStyle3 = {
@@ -11858,7 +11903,11 @@ function SortIcon(props) {
11858
11903
  "div",
11859
11904
  {
11860
11905
  "data-name": "sort-icon",
11861
- style: { ...style2, width: size },
11906
+ style: {
11907
+ ...style2,
11908
+ width: size,
11909
+ [SortIconLineWidthVarName]: `${lineWidth}px`
11910
+ },
11862
11911
  className: join(
11863
11912
  className,
11864
11913
  InfiniteIconClassName,
@@ -15490,6 +15539,7 @@ var ListRowManager = class extends Logger {
15490
15539
  var ITEM_POSITION_WITH_TRANSFORM = true;
15491
15540
  var currentTransformY = stripVar(InternalVars.y);
15492
15541
  var scrollTopCSSVar = stripVar(InternalVars.scrollTop);
15542
+ var scrollLeftCSSVar2 = stripVar(InternalVars.scrollLeft);
15493
15543
  var columnOffsetAtIndex2 = stripVar(InternalVars.columnOffsetAtIndex);
15494
15544
  var columnOffsetAtIndexWhileReordering2 = stripVar(
15495
15545
  InternalVars.columnOffsetAtIndexWhileReordering
@@ -15503,6 +15553,16 @@ var GridRenderer = class extends Logger {
15503
15553
  this.scrolling = false;
15504
15554
  this.cellHoverClassNames = [];
15505
15555
  this.cellDetachedClassNames = [];
15556
+ /**
15557
+ * Inside InfiniteTable, the table owns the CSS vars that position the
15558
+ * cells horizontally (one offset var per column, plus the scroll position
15559
+ * vars used by pinned cells) and sets them on its root node.
15560
+ *
15561
+ * A HeadlessTable used on its own has nobody to set them. With this on,
15562
+ * the renderer writes each cell's x from the brain, and sets the scroll
15563
+ * position vars itself, on the parent node of the cells.
15564
+ */
15565
+ this.ownsPositionVars = false;
15506
15566
  this.lastEnteredRow = -1;
15507
15567
  this.lastExitedRow = -1;
15508
15568
  this.hoverRowUpdatesInProgress = /* @__PURE__ */ new Map();
@@ -15522,26 +15582,30 @@ var GridRenderer = class extends Logger {
15522
15582
  element.style.transform = `translate3d(${scrollLeft2 || 0}px, var(${currentTransformY}), 0)`;
15523
15583
  };
15524
15584
  this.setTransform = (element, _rowIndex, colIndex, {
15525
- //@ts-ignore
15526
15585
  x,
15527
15586
  y,
15528
- //@ts-ignore
15529
15587
  scrollLeft: scrollLeft2,
15530
15588
  scrollTop: scrollTop2
15531
15589
  }, zIndex2) => {
15532
15590
  const columnOffsetX = InternalVarUtils.columnOffsets.get(colIndex);
15533
15591
  const columnOffsetXWhileReordering = `${columnOffsetAtIndexWhileReordering2}-${colIndex}`;
15534
- const currentTransformYValue = scrollTop2 ? `calc( ${y}px + var(${scrollTopCSSVar}) )` : `${y - this.brain.getScrollOrigin().scrollTop}px`;
15592
+ const currentTransformYValue = scrollTop2 ? `calc( ${y}px + var(${scrollTopCSSVar}, 0px) )` : `${y - this.brain.getScrollOrigin().scrollTop}px`;
15535
15593
  if (element.__currentTransformY !== currentTransformYValue) {
15536
15594
  element.__currentTransformY = currentTransformYValue;
15537
15595
  element.style.setProperty(currentTransformY, currentTransformYValue);
15538
15596
  }
15539
- const transformValue = `translate3d(var(${columnOffsetXWhileReordering}, ${columnOffsetX}), var(${currentTransformY}), 0)`;
15597
+ const transformX2 = this.ownsPositionVars ? scrollLeft2 ? `calc( ${x}px + var(${scrollLeftCSSVar2}, 0px) )` : `${x - this.brain.getScrollOrigin().scrollLeft}px` : `var(${columnOffsetXWhileReordering}, ${columnOffsetX})`;
15598
+ const transformValue = `translate3d(${transformX2}, var(${currentTransformY}), 0)`;
15540
15599
  if (element.__transformValue !== transformValue) {
15541
15600
  element.__transformValue = transformValue;
15542
15601
  element.style.transform = transformValue;
15543
15602
  }
15544
- if (zIndex2 != null) {
15603
+ if (zIndex2 != null && this.ownsPositionVars) {
15604
+ const zIndexValue = `${zIndex2}`;
15605
+ if (element.__zIndex !== zIndexValue) {
15606
+ element.__zIndex = zIndexValue;
15607
+ element.style.zIndex = zIndexValue;
15608
+ }
15545
15609
  }
15546
15610
  };
15547
15611
  /**
@@ -15562,6 +15626,17 @@ var GridRenderer = class extends Logger {
15562
15626
  });
15563
15627
  this.adjustFixedElementsOnScroll();
15564
15628
  };
15629
+ /**
15630
+ * While a render pass is in progress, the cells it detaches are collected
15631
+ * here and only get the detached class names when the pass ends - if they
15632
+ * are still detached by then.
15633
+ *
15634
+ * Most of the cells detached by a render pass (while scrolling, all of
15635
+ * them) are re-attached at another position by the same pass, so they
15636
+ * would get the class names added and then removed, with no visible effect
15637
+ * - only the cost of the DOM writes and of the style invalidations.
15638
+ */
15639
+ this.cellsDetachedInRenderPass = null;
15565
15640
  this.getFullyVisibleRowsRange = () => {
15566
15641
  let {
15567
15642
  start: [startRow],
@@ -16051,11 +16126,18 @@ var GridRenderer = class extends Logger {
16051
16126
  itemElement.dataset.rowIndex = realCoords.rowIndex;
16052
16127
  itemElement.dataset.colIndex = realCoords.colIndex;
16053
16128
  if (ITEM_POSITION_WITH_TRANSFORM) {
16054
- this.setTransform(itemElement, rowIndex, colIndex, { x, y }, null);
16129
+ const fixedPlacement = this.ownsPositionVars ? this.getFixedCellPlacement(rowIndex, colIndex, { x, y }) : null;
16130
+ this.setTransform(
16131
+ itemElement,
16132
+ rowIndex,
16133
+ colIndex,
16134
+ fixedPlacement ?? { x, y },
16135
+ null
16136
+ );
16055
16137
  itemElement.style.willChange = "transform";
16056
16138
  itemElement.style.backfaceVisibility = "hidden";
16057
16139
  const hidden = options ? options.hidden : !!this.isCellCovered(rowIndex, colIndex);
16058
- const zIndex2 = hidden ? "-1" : (
16140
+ const zIndex2 = hidden ? "-1" : fixedPlacement ? `${fixedPlacement.zIndex}` : (
16059
16141
  // #updatezindex - we need to allow elements use their own zIndex, so we
16060
16142
  // resort to allowing them to have it as a data-z-index attribute
16061
16143
  itemElement.dataset.zIndex || "auto"
@@ -16158,126 +16240,51 @@ var GridRenderer = class extends Logger {
16158
16240
  // fixed cells are positioned with these, inside the scroll layer
16159
16241
  // which is translated relative to the scroll origin
16160
16242
  brain.getDOMScrollPosition(scrollPosition),
16161
- this.getInfiniteNode(attachedCell.getElement())
16243
+ this.ownsPositionVars ? (
16244
+ // null on the first render pass, before the cells are in the DOM:
16245
+ // the cells fall back to a scroll position of 0 - see setTransform
16246
+ attachedCell.getElement()?.parentElement ?? null
16247
+ ) : this.getInfiniteNode(attachedCell.getElement())
16162
16248
  );
16163
16249
  }
16164
- const fixedEndColsOffsets = this.brain.getFixedEndColsOffsets({
16165
- skipScroll: true
16166
- });
16167
- const fixedEndRowsOffsets = this.brain.getFixedEndRowsOffsets({
16168
- skipScroll: true
16169
- });
16250
+ const fixedEndOffsets = {
16251
+ cols: this.brain.getFixedEndColsOffsets({ skipScroll: true }),
16252
+ rows: this.brain.getFixedEndRowsOffsets({ skipScroll: true })
16253
+ };
16170
16254
  const { start, end } = this.brain.getRenderRange();
16171
16255
  const [startRow, startCol] = start;
16172
16256
  const [endRow, endCol] = end;
16173
- function adjustElementPosition(rowIndex, colIndex, fn) {
16174
- const cell = cellManager.getCellAt([rowIndex, colIndex]);
16175
- if (cell == null) {
16257
+ const adjust = (rowIndex, colIndex) => {
16258
+ const node = cellManager.getCellAt([rowIndex, colIndex])?.getElement();
16259
+ const itemPosition = node ? brain.getCellOffset(rowIndex, colIndex) : null;
16260
+ if (!node || !itemPosition) {
16176
16261
  return;
16177
16262
  }
16178
- const itemPosition = brain.getCellOffset(rowIndex, colIndex);
16179
- const node = cell.getElement();
16180
- if (node && itemPosition) {
16181
- fn(rowIndex, colIndex, node, itemPosition);
16182
- }
16183
- }
16184
- const adjustColStart = (_rowIndex, colIndex, node, { x, y }) => {
16185
- this.setTransform(
16186
- node,
16187
- _rowIndex,
16188
- colIndex,
16189
- { x, y, scrollLeft: true },
16190
- fixedColsStart - colIndex
16191
- );
16192
- };
16193
- const adjustRowStart = (rowIndex, _colIndex, node, coords) => {
16194
- this.setTransform(
16195
- node,
16196
- rowIndex,
16197
- _colIndex,
16198
- { x: coords.x, y: coords.y, scrollTop: true },
16199
- fixedRowsStart - rowIndex
16200
- );
16201
- };
16202
- const adjustColEnd = (_rowIndex, colIndex, node, { y }) => {
16203
- const val = fixedEndColsOffsets[colIndex];
16204
- this.setTransform(
16205
- node,
16206
- _rowIndex,
16207
- colIndex,
16208
- { x: val, y, scrollLeft: true },
16209
- cols - colIndex
16210
- );
16211
- };
16212
- const adjustRowEnd = (rowIndex, _colIndex, node, coords) => {
16213
- this.setTransform(
16214
- node,
16215
- rowIndex,
16216
- _colIndex,
16217
- { x: coords.x, y: fixedEndRowsOffsets[rowIndex], scrollTop: true },
16218
- rows - rowIndex
16219
- );
16220
- };
16221
- const adjustColStartRowStart = (_rowIndex, _colIndex, node, { x, y }) => {
16222
- this.setTransform(
16223
- node,
16224
- _rowIndex,
16225
- _colIndex,
16226
- { x, scrollLeft: true, y, scrollTop: true },
16227
- 1e5
16228
- );
16229
- };
16230
- const adjustColStartRowEnd = (_rowIndex, _colIndex, node, { x }) => {
16231
- this.setTransform(
16232
- node,
16233
- _rowIndex,
16234
- _colIndex,
16235
- {
16236
- x,
16237
- scrollLeft: true,
16238
- y: fixedEndRowsOffsets[_rowIndex],
16239
- scrollTop: true
16240
- },
16241
- 2e5
16242
- );
16243
- };
16244
- const adjustColEndRowStart = (_rowIndex, colIndex, node, coords) => {
16245
- this.setTransform(
16246
- node,
16247
- _rowIndex,
16248
- colIndex,
16249
- {
16250
- x: fixedEndColsOffsets[colIndex],
16251
- y: coords.y,
16252
- scrollLeft: true,
16253
- scrollTop: true
16254
- },
16255
- 3e5
16256
- );
16257
- };
16258
- const adjustColEndRowEnd = (rowIndex, colIndex, node) => {
16259
- this.setTransform(
16260
- node,
16263
+ const placement = this.getFixedCellPlacement(
16261
16264
  rowIndex,
16262
16265
  colIndex,
16263
- {
16264
- x: fixedEndColsOffsets[colIndex],
16265
- y: fixedEndRowsOffsets[rowIndex],
16266
- scrollLeft: true,
16267
- scrollTop: true
16268
- },
16269
- 4e5
16266
+ itemPosition,
16267
+ fixedEndOffsets
16270
16268
  );
16269
+ if (placement) {
16270
+ this.setTransform(
16271
+ node,
16272
+ rowIndex,
16273
+ colIndex,
16274
+ placement,
16275
+ placement.zIndex
16276
+ );
16277
+ }
16271
16278
  };
16272
16279
  if (fixedColsStart || fixedColsEnd) {
16273
16280
  for (let rowIndex = startRow; rowIndex < endRow; rowIndex++) {
16274
16281
  for (let colIndex = 0; colIndex < fixedColsStart; colIndex++) {
16275
- adjustElementPosition(rowIndex, colIndex, adjustColStart);
16282
+ adjust(rowIndex, colIndex);
16276
16283
  }
16277
16284
  if (fixedColsEnd) {
16278
16285
  const firstColFixedEnd = cols - fixedColsEnd;
16279
16286
  for (let colIndex = firstColFixedEnd; colIndex < cols; colIndex++) {
16280
- adjustElementPosition(rowIndex, colIndex, adjustColEnd);
16287
+ adjust(rowIndex, colIndex);
16281
16288
  }
16282
16289
  }
16283
16290
  }
@@ -16285,12 +16292,12 @@ var GridRenderer = class extends Logger {
16285
16292
  if (fixedRowsStart || fixedRowsEnd) {
16286
16293
  for (let colIndex = startCol; colIndex < endCol; colIndex++) {
16287
16294
  for (let rowIndex = 0; rowIndex < fixedRowsStart; rowIndex++) {
16288
- adjustElementPosition(rowIndex, colIndex, adjustRowStart);
16295
+ adjust(rowIndex, colIndex);
16289
16296
  }
16290
16297
  if (fixedRowsEnd) {
16291
16298
  const firstRowFixedEnd = rows - fixedRowsEnd;
16292
16299
  for (let rowIndex = firstRowFixedEnd; rowIndex < rows; rowIndex++) {
16293
- adjustElementPosition(rowIndex, colIndex, adjustRowEnd);
16300
+ adjust(rowIndex, colIndex);
16294
16301
  }
16295
16302
  }
16296
16303
  }
@@ -16298,7 +16305,7 @@ var GridRenderer = class extends Logger {
16298
16305
  if (fixedColsStart && fixedRowsStart) {
16299
16306
  for (let rowIndex = 0; rowIndex < fixedRowsStart; rowIndex++) {
16300
16307
  for (let colIndex = 0; colIndex < fixedColsStart; colIndex++) {
16301
- adjustElementPosition(rowIndex, colIndex, adjustColStartRowStart);
16308
+ adjust(rowIndex, colIndex);
16302
16309
  }
16303
16310
  }
16304
16311
  }
@@ -16306,7 +16313,7 @@ var GridRenderer = class extends Logger {
16306
16313
  const firstRowFixedEnd = rows - fixedRowsEnd;
16307
16314
  for (let rowIndex = firstRowFixedEnd; rowIndex < rows; rowIndex++) {
16308
16315
  for (let colIndex = 0; colIndex < fixedColsStart; colIndex++) {
16309
- adjustElementPosition(rowIndex, colIndex, adjustColStartRowEnd);
16316
+ adjust(rowIndex, colIndex);
16310
16317
  }
16311
16318
  }
16312
16319
  }
@@ -16314,7 +16321,7 @@ var GridRenderer = class extends Logger {
16314
16321
  const firstColFixedEnd = cols - fixedColsEnd;
16315
16322
  for (let rowIndex = 0; rowIndex < fixedRowsStart; rowIndex++) {
16316
16323
  for (let colIndex = firstColFixedEnd; colIndex < cols; colIndex++) {
16317
- adjustElementPosition(rowIndex, colIndex, adjustColEndRowStart);
16324
+ adjust(rowIndex, colIndex);
16318
16325
  }
16319
16326
  }
16320
16327
  }
@@ -16323,7 +16330,7 @@ var GridRenderer = class extends Logger {
16323
16330
  const firstColFixedEnd = cols - fixedColsEnd;
16324
16331
  for (let rowIndex = firstRowFixedEnd; rowIndex < rows; rowIndex++) {
16325
16332
  for (let colIndex = firstColFixedEnd; colIndex < cols; colIndex++) {
16326
- adjustElementPosition(rowIndex, colIndex, adjustColEndRowEnd);
16333
+ adjust(rowIndex, colIndex);
16327
16334
  }
16328
16335
  }
16329
16336
  }
@@ -16397,6 +16404,9 @@ var GridRenderer = class extends Logger {
16397
16404
  return this.infiniteNode;
16398
16405
  }
16399
16406
  onCellAttached(cell) {
16407
+ if (this.cellsDetachedInRenderPass?.delete(cell)) {
16408
+ return;
16409
+ }
16400
16410
  if (this.cellDetachedClassNames.length) {
16401
16411
  const el = cell.getElement();
16402
16412
  if (el) {
@@ -16407,6 +16417,13 @@ var GridRenderer = class extends Logger {
16407
16417
  }
16408
16418
  }
16409
16419
  onCellDetached(cell) {
16420
+ if (this.cellsDetachedInRenderPass) {
16421
+ this.cellsDetachedInRenderPass.add(cell);
16422
+ return;
16423
+ }
16424
+ this.addDetachedClassNames(cell);
16425
+ }
16426
+ addDetachedClassNames(cell) {
16410
16427
  if (this.cellDetachedClassNames.length) {
16411
16428
  const el = cell.getElement();
16412
16429
  if (el) {
@@ -16443,10 +16460,22 @@ var GridRenderer = class extends Logger {
16443
16460
  mapped: rendered
16444
16461
  };
16445
16462
  }
16446
- renderRange(range, { renderCell, renderDetailRow, force, onRender }) {
16463
+ renderRange(range, options) {
16447
16464
  if (this.destroyed) {
16448
16465
  return [];
16449
16466
  }
16467
+ if (this.cellsDetachedInRenderPass) {
16468
+ return this.renderRangeInternal(range, options);
16469
+ }
16470
+ const detachedCells = this.cellsDetachedInRenderPass = /* @__PURE__ */ new Set();
16471
+ try {
16472
+ return this.renderRangeInternal(range, options);
16473
+ } finally {
16474
+ this.cellsDetachedInRenderPass = null;
16475
+ detachedCells.forEach((cell) => this.addDetachedClassNames(cell));
16476
+ }
16477
+ }
16478
+ renderRangeInternal(range, { renderCell, renderDetailRow, force, onRender }) {
16450
16479
  const { start, end } = range;
16451
16480
  const horizontalLayout = this.brain.isHorizontalLayoutBrain;
16452
16481
  if (false) {
@@ -16721,6 +16750,34 @@ var GridRenderer = class extends Logger {
16721
16750
  this.updateElementPosition(cell, { hidden, rowspan, colspan });
16722
16751
  return;
16723
16752
  }
16753
+ /**
16754
+ * Where a fixed (pinned) cell goes: its x and/or y relative to the viewport
16755
+ * (`scrollLeft` / `scrollTop: true` - see setTransform), and its z-index:
16756
+ * the corners above the pinned rows and columns, those above the cells
16757
+ * scrolling under them. null for a cell that is not fixed.
16758
+ */
16759
+ getFixedCellPlacement(rowIndex, colIndex, { x, y }, fixedEndOffsets) {
16760
+ const { fixedRowsStart, fixedRowsEnd, fixedColsStart, fixedColsEnd } = this.brain.getFixedCellInfo();
16761
+ const cols = this.brain.getColCount();
16762
+ const rows = this.brain.getRowCount();
16763
+ const colStart = colIndex < fixedColsStart;
16764
+ const colEnd = !colStart && !!fixedColsEnd && colIndex >= cols - fixedColsEnd;
16765
+ const rowStart = rowIndex < fixedRowsStart;
16766
+ const rowEnd = !rowStart && !!fixedRowsEnd && rowIndex >= rows - fixedRowsEnd;
16767
+ const colFixed = colStart || colEnd;
16768
+ const rowFixed = rowStart || rowEnd;
16769
+ if (!colFixed && !rowFixed) {
16770
+ return null;
16771
+ }
16772
+ if (colEnd) {
16773
+ x = (fixedEndOffsets?.cols ?? this.brain.getFixedEndColsOffsets({ skipScroll: true }))[colIndex];
16774
+ }
16775
+ if (rowEnd) {
16776
+ y = (fixedEndOffsets?.rows ?? this.brain.getFixedEndRowsOffsets({ skipScroll: true }))[rowIndex];
16777
+ }
16778
+ const zIndex2 = colFixed && rowFixed ? colStart ? rowStart ? 1e5 : 2e5 : rowStart ? 3e5 : 4e5 : colStart ? fixedColsStart - colIndex : colEnd ? cols - colIndex : rowStart ? fixedRowsStart - rowIndex : rows - rowIndex;
16779
+ return { x, y, scrollLeft: colFixed, scrollTop: rowFixed, zIndex: zIndex2 };
16780
+ }
16724
16781
  reset() {
16725
16782
  this.cellManager.reset();
16726
16783
  this.rowManager.reset();
@@ -17312,13 +17369,18 @@ function createRenderer(brain) {
17312
17369
  }
17313
17370
 
17314
17371
  // src/components/HeadlessTable/RawTable.tsx
17372
+ function createOwnRenderer(brain) {
17373
+ const result = createRenderer(brain);
17374
+ result.renderer.ownsPositionVars = true;
17375
+ return result;
17376
+ }
17315
17377
  function RawTableFn(props) {
17316
17378
  const { brain, renderCell, renderDetailRow, forceRerenderTimestamp } = props;
17317
17379
  const { renderer, onRenderUpdater } = useMemo7(() => {
17318
17380
  return props.onRenderUpdater && props.renderer ? {
17319
17381
  renderer: props.renderer,
17320
17382
  onRenderUpdater: props.onRenderUpdater
17321
- } : createRenderer(brain);
17383
+ } : createOwnRenderer(brain);
17322
17384
  }, [brain, props.onRenderUpdater, props.renderer]);
17323
17385
  useLayoutEffect8(() => {
17324
17386
  renderer.cellHoverClassNames = props.cellHoverClassNames || [];
@@ -22444,6 +22506,80 @@ function treeTraverse(treeParams, traverseOptions, data) {
22444
22506
  }
22445
22507
  }
22446
22508
 
22509
+ // src/utils/multisort/sortByNumber.ts
22510
+ var SORT_BY_NUMBER_MIN_LENGTH = 1e3;
22511
+ var IS_LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
22512
+ function sortByNumber(array, getValue, dir) {
22513
+ const len = array.length;
22514
+ const keys = new Float64Array(len);
22515
+ for (let i = 0; i < len; i++) {
22516
+ const value = getValue(array[i]);
22517
+ if (typeof value !== "number" || value !== value) {
22518
+ return false;
22519
+ }
22520
+ keys[i] = (dir < 0 ? -value : value) + 0;
22521
+ }
22522
+ if (len < 2) {
22523
+ return true;
22524
+ }
22525
+ const words = new Uint32Array(keys.buffer);
22526
+ const LOW = IS_LITTLE_ENDIAN ? 0 : 1;
22527
+ const HIGH = IS_LITTLE_ENDIAN ? 1 : 0;
22528
+ const counts = new Uint32Array(8 * 256);
22529
+ for (let i = 0; i < len; i++) {
22530
+ let low = words[2 * i + LOW];
22531
+ let high = words[2 * i + HIGH];
22532
+ if (high & 2147483648) {
22533
+ high = ~high >>> 0;
22534
+ low = ~low >>> 0;
22535
+ words[2 * i + LOW] = low;
22536
+ } else {
22537
+ high = (high | 2147483648) >>> 0;
22538
+ }
22539
+ words[2 * i + HIGH] = high;
22540
+ counts[low & 255]++;
22541
+ counts[256 + (low >>> 8 & 255)]++;
22542
+ counts[512 + (low >>> 16 & 255)]++;
22543
+ counts[768 + (low >>> 24)]++;
22544
+ counts[1024 + (high & 255)]++;
22545
+ counts[1280 + (high >>> 8 & 255)]++;
22546
+ counts[1536 + (high >>> 16 & 255)]++;
22547
+ counts[1792 + (high >>> 24)]++;
22548
+ }
22549
+ let indexes = new Uint32Array(len);
22550
+ let nextIndexes = new Uint32Array(len);
22551
+ for (let i = 0; i < len; i++) {
22552
+ indexes[i] = i;
22553
+ }
22554
+ for (let digitIndex = 0; digitIndex < 8; digitIndex++) {
22555
+ const word = digitIndex < 4 ? LOW : HIGH;
22556
+ const shift = digitIndex % 4 * 8;
22557
+ const countsOffset = digitIndex * 256;
22558
+ if (counts[countsOffset + (words[word] >>> shift & 255)] === len) {
22559
+ continue;
22560
+ }
22561
+ let position2 = 0;
22562
+ for (let digit = 0; digit < 256; digit++) {
22563
+ const count = counts[countsOffset + digit];
22564
+ counts[countsOffset + digit] = position2;
22565
+ position2 += count;
22566
+ }
22567
+ for (let i = 0; i < len; i++) {
22568
+ const index = indexes[i];
22569
+ const digit = words[2 * index + word] >>> shift & 255;
22570
+ nextIndexes[counts[countsOffset + digit]++] = index;
22571
+ }
22572
+ const previousIndexes = indexes;
22573
+ indexes = nextIndexes;
22574
+ nextIndexes = previousIndexes;
22575
+ }
22576
+ const items = array.slice();
22577
+ for (let i = 0; i < len; i++) {
22578
+ array[i] = items[indexes[i]];
22579
+ }
22580
+ return true;
22581
+ }
22582
+
22447
22583
  // src/utils/multisort/sortTypes.ts
22448
22584
  var numberComparator = function(first, second) {
22449
22585
  return first - second;
@@ -22529,7 +22665,10 @@ var multisort = (sortInfo, array, options) => {
22529
22665
  if (marker) {
22530
22666
  marker.start();
22531
22667
  }
22532
- array.sort(getMultisortFunction(toPlainSortInfo(sortInfo), get));
22668
+ const plainSortInfo = toPlainSortInfo(sortInfo);
22669
+ if (!sortByNumberIfPossible(plainSortInfo, array, get)) {
22670
+ array.sort(getMultisortFunction(plainSortInfo, get));
22671
+ }
22533
22672
  if (marker) {
22534
22673
  marker.end();
22535
22674
  }
@@ -22595,6 +22734,30 @@ var multisortNested = (sortInfo, array, options) => {
22595
22734
  return array;
22596
22735
  };
22597
22736
  multisort.knownTypes = sortTypes_default;
22737
+ function sortByNumberIfPossible(sortInfo, array, get) {
22738
+ if (sortInfo.length !== 1 || array.length < SORT_BY_NUMBER_MIN_LENGTH) {
22739
+ return false;
22740
+ }
22741
+ const info = sortInfo[0];
22742
+ if (!info || info.fn || !info.type || info.dir !== 1 && info.dir !== -1) {
22743
+ return false;
22744
+ }
22745
+ const type = Array.isArray(info.type) ? info.type[0] : info.type;
22746
+ if (multisort.knownTypes[type] !== numberComparator) {
22747
+ return false;
22748
+ }
22749
+ const { field, valueGetter } = info;
22750
+ return sortByNumber(
22751
+ array,
22752
+ (item) => {
22753
+ if (get) {
22754
+ item = get(item);
22755
+ }
22756
+ return valueGetter ? valueGetter(item) : field ? item[field] : item;
22757
+ },
22758
+ info.dir
22759
+ );
22760
+ }
22598
22761
  var getSingleSortFunction = (info) => {
22599
22762
  if (!info) {
22600
22763
  return;
@@ -22997,6 +23160,9 @@ function deepEqual(a, b) {
22997
23160
  if (a === b) return true;
22998
23161
  if (a == null || b == null) return a === b;
22999
23162
  if (typeof a !== typeof b) return false;
23163
+ if (a instanceof Date || b instanceof Date) {
23164
+ return a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
23165
+ }
23000
23166
  if (Array.isArray(a) && Array.isArray(b)) {
23001
23167
  if (a.length !== b.length) return false;
23002
23168
  for (let i = 0, len = a.length; i < len; i++) {
@@ -29434,8 +29600,8 @@ function getLicenseStatus(licenseKey = "", options) {
29434
29600
  return "valid";
29435
29601
  }
29436
29602
  const result = checkLicense(licenseKey, {
29437
- publishedAt: 1794927344373,
29438
- version: "10.2.0"
29603
+ publishedAt: 1795695384921,
29604
+ version: "11.0.0"
29439
29605
  });
29440
29606
  if (result === "invalid" && !licenseKey) {
29441
29607
  return "missing";
@@ -30744,6 +30910,14 @@ import {
30744
30910
  useState as useState23
30745
30911
  } from "react";
30746
30912
 
30913
+ // src/components/Menu/MenuContext.ts
30914
+ import { createContext as createContext11, useContext as useContext12 } from "react";
30915
+ var MenuContext = createContext11(null);
30916
+ function useMenuContext() {
30917
+ const contextValue = useContext12(MenuContext);
30918
+ return contextValue;
30919
+ }
30920
+
30747
30921
  // src/components/Menu/menuDomUtils.ts
30748
30922
  function getMenuItemRect(menuId, itemKey) {
30749
30923
  const cells = getMenuItemNodes(menuId, itemKey);
@@ -30785,41 +30959,215 @@ function getFirstCheckBoxInsideMenuItem(menuId, itemKey) {
30785
30959
  return null;
30786
30960
  }
30787
30961
 
30788
- // src/utils/pageGeometry/Triangle.ts
30789
- var Triangle = class extends ConvexPoly {
30790
- // uncommenting this here breaks our tests - WHAT????
30791
- // it's just narrowing down the type of the points member variable
30792
- // - this should not introduce any change in behavior!!! however, TS is crazy about this one
30793
- // points!: PointTimes3;
30794
- constructor(points) {
30795
- super(points.slice(0, 3));
30962
+ // src/components/Menu/menuKeyboardNav.ts
30963
+ function hideMenuAndParents(getState) {
30964
+ const state = getState();
30965
+ state.onHideIntent?.(state);
30966
+ }
30967
+ function runMenuItemClick(event, item, context) {
30968
+ const { getState, setActiveItemKey, setKeyboardActiveItemKey, hideAll } = context;
30969
+ setKeyboardActiveItemKey(item.key);
30970
+ setActiveItemKey(item.key);
30971
+ if (item.originalMenuItem.onClick) {
30972
+ item.originalMenuItem.onClick(event);
30973
+ }
30974
+ const onActionParam = {
30975
+ key: item.key,
30976
+ item: item.originalMenuItem,
30977
+ hideMenu: hideAll
30978
+ };
30979
+ if (item.originalMenuItem.onAction) {
30980
+ item.originalMenuItem.onAction(onActionParam);
30796
30981
  }
30797
- };
30798
-
30799
- // src/components/Menu/MenuTriangleContext.ts
30800
- var ACTIVE_OTHER_MENU_ITEM_TIMEOUT = 250;
30801
- function waitForValueOnRaf(getter, timeout = 100) {
30802
- const start = Date.now();
30803
- return new Promise((resolve) => {
30804
- let value;
30805
- const fn = () => {
30806
- value = getter();
30807
- if (value !== void 0) {
30808
- resolve(value);
30982
+ const { onAction } = getState();
30983
+ if (onAction) {
30984
+ onAction(onActionParam);
30985
+ }
30986
+ if (item.originalMenuItem.hideMenuOnAction) {
30987
+ hideAll();
30988
+ }
30989
+ }
30990
+ function handleMenuKeyDown(keyboardEvent, context) {
30991
+ const {
30992
+ getState,
30993
+ setActiveItemKey,
30994
+ setKeyboardActiveItemKey,
30995
+ destroy,
30996
+ getSubmenuApi,
30997
+ isMounted,
30998
+ onItemClick
30999
+ } = context;
31000
+ const { runtimeItems, runtimeSelectableItems, keyboardActiveItemKey } = getState();
31001
+ const keyboardActiveIndex = runtimeItems.findIndex(
31002
+ (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31003
+ );
31004
+ let newKeyboardActiveItemKey = keyboardActiveItemKey;
31005
+ const keyboardActiveItem = runtimeItems[keyboardActiveIndex];
31006
+ const validKeys3 = {
31007
+ ArrowUp: () => {
31008
+ const newActiveItem = runtimeItems.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31009
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31010
+ newKeyboardActiveItemKey = newActiveItem.key;
31011
+ }
31012
+ },
31013
+ ArrowDown: () => {
31014
+ const newActiveItem = runtimeItems.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31015
+ if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31016
+ newKeyboardActiveItemKey = newActiveItem.key;
31017
+ }
31018
+ },
31019
+ Home: () => {
31020
+ validKeys3.PageUp();
31021
+ },
31022
+ End: () => {
31023
+ validKeys3.PageDown();
31024
+ },
31025
+ PageUp: () => {
31026
+ newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31027
+ },
31028
+ PageDown: () => {
31029
+ newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31030
+ },
31031
+ ArrowLeft: () => {
31032
+ setActiveItemKey(null);
31033
+ if (getState().parentMenuId) {
31034
+ destroy();
31035
+ }
31036
+ },
31037
+ ArrowRight: () => {
31038
+ if (!keyboardActiveItem) {
30809
31039
  return;
30810
31040
  }
30811
- if (Date.now() - start > timeout) {
30812
- resolve(void 0);
31041
+ setActiveItemKey(keyboardActiveItem.key);
31042
+ raf(() => {
31043
+ const submenuApi = getSubmenuApi();
31044
+ if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31045
+ submenuApi.focus();
31046
+ }
31047
+ });
31048
+ },
31049
+ Enter: () => {
31050
+ if (!keyboardActiveItem) {
30813
31051
  return;
30814
31052
  }
30815
- raf(fn);
30816
- };
30817
- raf(() => {
30818
- fn();
30819
- });
30820
- });
30821
- }
30822
- var globalObject = getGlobal();
31053
+ if (keyboardActiveItem.originalMenuItem?.menu) {
31054
+ if (getSubmenuApi()) {
31055
+ validKeys3.ArrowLeft();
31056
+ return;
31057
+ }
31058
+ setActiveItemKey(keyboardActiveItem.key);
31059
+ } else {
31060
+ onItemClick(keyboardEvent, keyboardActiveItem);
31061
+ }
31062
+ },
31063
+ " ": () => {
31064
+ if (!keyboardActiveItem) {
31065
+ return;
31066
+ }
31067
+ if (!keyboardActiveItem.originalMenuItem.menu) {
31068
+ onItemClick(keyboardEvent, keyboardActiveItem);
31069
+ }
31070
+ const checkbox = getFirstCheckBoxInsideMenuItem(
31071
+ getState().menuId,
31072
+ keyboardActiveItem.key
31073
+ );
31074
+ if (!checkbox) {
31075
+ return;
31076
+ }
31077
+ checkbox.click();
31078
+ },
31079
+ Escape: () => {
31080
+ validKeys3.ArrowLeft();
31081
+ const state = getState();
31082
+ if (!state.parentMenuId) {
31083
+ state.onHideIntent?.(state);
31084
+ }
31085
+ }
31086
+ };
31087
+ const fn = validKeys3[keyboardEvent.key];
31088
+ if (fn) {
31089
+ fn();
31090
+ keyboardEvent.preventDefault();
31091
+ }
31092
+ if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31093
+ setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31094
+ }
31095
+ }
31096
+ function createMenuFocus(context) {
31097
+ const {
31098
+ getState,
31099
+ setFocused,
31100
+ setKeyboardActiveItemKey,
31101
+ shouldSelectFirstItemOnFocus,
31102
+ hideAll
31103
+ } = context;
31104
+ const onMenuFocus = () => {
31105
+ setFocused(true);
31106
+ setTimeout(() => {
31107
+ const domNode = getState().domRef.current;
31108
+ if (shouldSelectFirstItemOnFocus() && domNode && domNode === document.activeElement && getState().keyboardActiveItemKey == null) {
31109
+ setKeyboardActiveItemKey(
31110
+ getState().runtimeSelectableItems[0]?.key ?? null
31111
+ );
31112
+ }
31113
+ });
31114
+ };
31115
+ const api = {
31116
+ hideMenu: hideAll,
31117
+ focus: () => {
31118
+ const domNode = getState().domRef.current;
31119
+ if (domNode) {
31120
+ domNode.focus();
31121
+ setTimeout(() => {
31122
+ const node = getState().domRef.current;
31123
+ if (node && node !== document.activeElement) {
31124
+ node.focus();
31125
+ }
31126
+ }, 10);
31127
+ onMenuFocus();
31128
+ }
31129
+ },
31130
+ getMenuId: () => getState().menuId,
31131
+ getParentMenuId: () => getState().parentMenuId
31132
+ };
31133
+ return { api, onMenuFocus };
31134
+ }
31135
+
31136
+ // src/utils/pageGeometry/Triangle.ts
31137
+ var Triangle = class extends ConvexPoly {
31138
+ // uncommenting this here breaks our tests - WHAT????
31139
+ // it's just narrowing down the type of the points member variable
31140
+ // - this should not introduce any change in behavior!!! however, TS is crazy about this one
31141
+ // points!: PointTimes3;
31142
+ constructor(points) {
31143
+ super(points.slice(0, 3));
31144
+ }
31145
+ };
31146
+
31147
+ // src/components/Menu/MenuTriangleContext.ts
31148
+ var ACTIVE_OTHER_MENU_ITEM_TIMEOUT = 250;
31149
+ function waitForValueOnRaf(getter, timeout = 100) {
31150
+ const start = Date.now();
31151
+ return new Promise((resolve) => {
31152
+ let value;
31153
+ const fn = () => {
31154
+ value = getter();
31155
+ if (value !== void 0) {
31156
+ resolve(value);
31157
+ return;
31158
+ }
31159
+ if (Date.now() - start > timeout) {
31160
+ resolve(void 0);
31161
+ return;
31162
+ }
31163
+ raf(fn);
31164
+ };
31165
+ raf(() => {
31166
+ fn();
31167
+ });
31168
+ });
31169
+ }
31170
+ var globalObject = getGlobal();
30823
31171
  var MenuTriangleContext = class {
30824
31172
  constructor(params) {
30825
31173
  this.activeItem = null;
@@ -31001,12 +31349,150 @@ var MenuTriangleContext = class {
31001
31349
  }
31002
31350
  };
31003
31351
 
31004
- // src/components/Menu/MenuContext.ts
31005
- import { createContext as createContext11, useContext as useContext12 } from "react";
31006
- var MenuContext = createContext11(null);
31007
- function useMenuContext() {
31008
- const contextValue = useContext12(MenuContext);
31009
- return contextValue;
31352
+ // src/components/Menu/menuViewShared.ts
31353
+ function getActiveSubmenuItem(runtimeItems, activeItemKey) {
31354
+ const activeItem = runtimeItems.filter(
31355
+ (item) => item.type === "item" && activeItemKey === item.key
31356
+ )[0];
31357
+ return activeItem && activeItem.menu ? activeItem : null;
31358
+ }
31359
+ function getSubmenuOverlayParams(menuId, item, constrainTo) {
31360
+ const alignTo = getMenuItemRect(menuId, item.key);
31361
+ if (!alignTo) {
31362
+ return null;
31363
+ }
31364
+ return {
31365
+ id: `${menuId}-submenu`,
31366
+ alignTo,
31367
+ alignPosition: [
31368
+ ["TopLeft", "TopRight"],
31369
+ ["TopRight", "TopLeft"]
31370
+ ],
31371
+ constrainTo
31372
+ };
31373
+ }
31374
+ function getSubmenuProps(item, context) {
31375
+ const {
31376
+ parentMenuId,
31377
+ constrainTo,
31378
+ api,
31379
+ hideAll,
31380
+ setSubmenuApi,
31381
+ setActiveItemKey,
31382
+ setKeyboardActiveItemKey
31383
+ } = context;
31384
+ let itemMenu = item.menu;
31385
+ if (!itemMenu) {
31386
+ return null;
31387
+ }
31388
+ if (typeof itemMenu === "function") {
31389
+ itemMenu = itemMenu();
31390
+ }
31391
+ const submenu = itemMenu;
31392
+ return {
31393
+ parentMenuItemKey: item.key,
31394
+ parentMenuId,
31395
+ constrainTo,
31396
+ ...submenu,
31397
+ autoFocus: false,
31398
+ onShow: (state, submenuApi) => {
31399
+ submenu?.onShow?.(state, submenuApi);
31400
+ setSubmenuApi(submenuApi);
31401
+ },
31402
+ onHideIntent: (state) => {
31403
+ submenu?.onHideIntent?.(state);
31404
+ hideAll();
31405
+ },
31406
+ onHide: (state) => {
31407
+ if (state.focused) {
31408
+ setActiveItemKey(null);
31409
+ setKeyboardActiveItemKey(item.key);
31410
+ api.focus();
31411
+ }
31412
+ }
31413
+ };
31414
+ }
31415
+ function createMenuTriangleHandlers(getState, onItemActivate) {
31416
+ return new MenuTriangleContext({
31417
+ parentMenuId: getState().parentMenuId,
31418
+ onItemActivate,
31419
+ itemHasSubMenu: (itemKey) => {
31420
+ const item = getState().runtimeItems.filter(
31421
+ (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31422
+ )[0];
31423
+ return !!item;
31424
+ },
31425
+ getMenuRectFor: (itemKey) => {
31426
+ const selector2 = `[data-submenu-for="${itemKey}"]`;
31427
+ const menuNode = document.querySelector(selector2);
31428
+ if (!menuNode) {
31429
+ return void 0;
31430
+ }
31431
+ return Rectangle.from(menuNode.getBoundingClientRect());
31432
+ }
31433
+ }).getHandlers();
31434
+ }
31435
+ function getMenuGridStyle(state, style2, toCssWidth = (width) => width) {
31436
+ const { columns, runtimeItems, wrapLabels } = state;
31437
+ const gridTemplateColumns = columns.map((col) => {
31438
+ return toCssWidth(
31439
+ col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto"
31440
+ );
31441
+ }).join(" ");
31442
+ const result = {
31443
+ ...style2,
31444
+ gridTemplateColumns,
31445
+ gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31446
+ };
31447
+ if (!wrapLabels) {
31448
+ result.whiteSpace = "nowrap";
31449
+ }
31450
+ return result;
31451
+ }
31452
+ function getMenuItemCells(item, columns, index, flags) {
31453
+ const { active, keyboardActive, pressed } = flags;
31454
+ const key = item.value.key;
31455
+ const className = join(
31456
+ MenuItemCls({
31457
+ active,
31458
+ disabled: !!item.disabled,
31459
+ keyboardActive,
31460
+ pressed: pressed || active
31461
+ }),
31462
+ item.className
31463
+ );
31464
+ const cells = [];
31465
+ let spanIndex = 0;
31466
+ columns.forEach((col, i) => {
31467
+ const target = item.value;
31468
+ const field = col.field || col.name;
31469
+ const start = i + 1;
31470
+ const end = start + item.span;
31471
+ if (start < spanIndex) {
31472
+ return;
31473
+ }
31474
+ spanIndex = end;
31475
+ cells.push({
31476
+ key: `${key}-${field}`,
31477
+ column: col,
31478
+ value: target[field],
31479
+ style: {
31480
+ ...col.style,
31481
+ ...item.style,
31482
+ gridColumnStart: start,
31483
+ gridColumnEnd: end
31484
+ },
31485
+ className,
31486
+ dataAttributes: {
31487
+ "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31488
+ "data-menu-col-name": `${col.name}`,
31489
+ "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31490
+ "data-menu-row-index": `${index}`,
31491
+ "data-menu-item-key": `${item.key}`
31492
+ }
31493
+ });
31494
+ });
31495
+ return cells;
31010
31496
  }
31011
31497
 
31012
31498
  // src/components/hooks/useMounted.ts
@@ -31025,84 +31511,29 @@ function useMounted() {
31025
31511
 
31026
31512
  // src/components/Menu/Menu.tsx
31027
31513
  function renderSubmenuForItem(item, config) {
31028
- const {
31029
- parentMenuId,
31030
- setSubmenuApi,
31031
- setActiveItemKey,
31032
- setKeyboardActiveItemKey,
31033
- constrainTo,
31034
- onHideIntent,
31035
- api
31036
- } = config;
31037
- const overlayId = `${parentMenuId}-submenu`;
31038
- let itemMenu = item.menu;
31039
- if (!itemMenu) {
31514
+ const overlayId = `${config.parentMenuId}-submenu`;
31515
+ const submenuProps = getSubmenuProps(item, config);
31516
+ if (!submenuProps) {
31040
31517
  return null;
31041
31518
  }
31042
- if (typeof itemMenu === "function") {
31043
- itemMenu = itemMenu();
31044
- }
31045
- return /* @__PURE__ */ React61.createElement(
31046
- Menu,
31047
- {
31048
- key: overlayId,
31049
- parentMenuItemKey: item.key,
31050
- parentMenuId,
31051
- constrainTo,
31052
- ...itemMenu,
31053
- autoFocus: false,
31054
- onShow: (state, api2) => {
31055
- itemMenu?.onShow?.(state, api2);
31056
- setSubmenuApi(api2);
31057
- },
31058
- onHideIntent: (state) => {
31059
- itemMenu?.onHideIntent?.(state);
31060
- onHideIntent(state);
31061
- },
31062
- onHide: (state) => {
31063
- if (state.focused) {
31064
- setActiveItemKey(null);
31065
- setKeyboardActiveItemKey(item.key);
31066
- api.focus();
31067
- }
31068
- }
31069
- }
31070
- );
31519
+ return /* @__PURE__ */ React61.createElement(Menu, { key: overlayId, ...submenuProps });
31071
31520
  }
31072
31521
  function useSubmenus({
31073
31522
  onItemActivate
31074
31523
  }) {
31075
31524
  const { getState } = useMenuContext();
31076
- const [{ onItemEnter, onItemLeave }] = useState23(() => {
31077
- return new MenuTriangleContext({
31078
- parentMenuId: getState().parentMenuId,
31079
- onItemActivate: (itemKey) => {
31080
- if (!itemKey) {
31081
- onItemActivate(null);
31082
- return;
31083
- }
31084
- const item = getState().runtimeItems.filter(
31085
- (item2) => item2.type === "item" && item2.key === itemKey
31086
- )[0];
31087
- onItemActivate(item);
31088
- },
31089
- itemHasSubMenu: (itemKey) => {
31090
- const item = getState().runtimeItems.filter(
31091
- (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31092
- )[0];
31093
- return !!item;
31094
- },
31095
- getMenuRectFor: (itemKey) => {
31096
- const selector2 = `[data-submenu-for="${itemKey}"]`;
31097
- const menuNode = document.querySelector(selector2);
31098
- if (!menuNode) {
31099
- return void 0;
31100
- }
31101
- const rect = Rectangle.from(menuNode.getBoundingClientRect());
31102
- return rect;
31525
+ const [{ onItemEnter, onItemLeave }] = useState23(
31526
+ () => createMenuTriangleHandlers(getState, (itemKey) => {
31527
+ if (!itemKey) {
31528
+ onItemActivate(null);
31529
+ return;
31103
31530
  }
31104
- }).getHandlers();
31105
- });
31531
+ const item = getState().runtimeItems.filter(
31532
+ (item2) => item2.type === "item" && item2.key === itemKey
31533
+ )[0];
31534
+ onItemActivate(item);
31535
+ })
31536
+ );
31106
31537
  return {
31107
31538
  onItemEnter: useCallback30(onItemEnter, []),
31108
31539
  onItemLeave: useCallback30(onItemLeave, [])
@@ -31111,6 +31542,7 @@ function useSubmenus({
31111
31542
  function MenuComponent(props) {
31112
31543
  const { domProps } = props;
31113
31544
  const {
31545
+ componentState,
31114
31546
  componentState: {
31115
31547
  columns,
31116
31548
  runtimeItems,
@@ -31119,8 +31551,6 @@ function MenuComponent(props) {
31119
31551
  keyboardActiveItemKey,
31120
31552
  constrainTo,
31121
31553
  destroyed,
31122
- onAction,
31123
- wrapLabels,
31124
31554
  onShow,
31125
31555
  onHide,
31126
31556
  autoFocus,
@@ -31138,62 +31568,56 @@ function MenuComponent(props) {
31138
31568
  }, []);
31139
31569
  const isMounted = useMounted();
31140
31570
  const [submenuApi, setSubmenuApi] = useState23(null);
31571
+ const shouldSelectFirstItemOnFocus = useRef30(true);
31572
+ const [{ api, onMenuFocus, hideAll }] = useState23(() => {
31573
+ const hideAll2 = () => hideMenuAndParents(getState);
31574
+ return {
31575
+ hideAll: hideAll2,
31576
+ ...createMenuFocus({
31577
+ getState,
31578
+ setFocused: (focused) => {
31579
+ componentActions.focused = focused;
31580
+ },
31581
+ setKeyboardActiveItemKey,
31582
+ shouldSelectFirstItemOnFocus: () => shouldSelectFirstItemOnFocus.current,
31583
+ hideAll: hideAll2
31584
+ })
31585
+ };
31586
+ });
31141
31587
  let renderedChildren = null;
31142
31588
  useLayoutEffect17(() => {
31143
31589
  const { runtimeItems: runtimeItems2 } = getState();
31144
- const activeItem = runtimeItems2.filter(
31145
- (item) => item.type === "item" && activeItemKey === item.key
31146
- )[0];
31147
- if (!activeItem || !activeItem.menu) {
31590
+ const activeItem = getActiveSubmenuItem(runtimeItems2, activeItemKey);
31591
+ if (!activeItem) {
31148
31592
  setSubmenuApi(null);
31149
31593
  clearAll();
31150
31594
  return;
31151
31595
  }
31152
- if (activeItem) {
31153
- const alignTo = getMenuItemRect(menuId, activeItem.key);
31154
- const menu = () => renderSubmenuForItem(activeItem, {
31155
- constrainTo,
31156
- setSubmenuApi,
31157
- setActiveItemKey,
31158
- setKeyboardActiveItemKey,
31159
- parentMenuId: menuId,
31160
- onHideIntent: hideAll,
31161
- api
31162
- });
31163
- if (alignTo) {
31164
- showOverlay(menu, {
31165
- id: `${menuId}-submenu`,
31166
- alignTo,
31167
- alignPosition: [
31168
- ["TopLeft", "TopRight"],
31169
- ["TopRight", "TopLeft"]
31170
- ],
31171
- constrainTo
31172
- });
31173
- }
31174
- return;
31596
+ const overlayParams = getSubmenuOverlayParams(
31597
+ menuId,
31598
+ activeItem,
31599
+ constrainTo
31600
+ );
31601
+ const menu = () => renderSubmenuForItem(activeItem, {
31602
+ constrainTo,
31603
+ setSubmenuApi,
31604
+ setActiveItemKey,
31605
+ setKeyboardActiveItemKey,
31606
+ parentMenuId: menuId,
31607
+ hideAll,
31608
+ api
31609
+ });
31610
+ if (overlayParams) {
31611
+ showOverlay(menu, overlayParams);
31175
31612
  }
31176
31613
  }, [activeItemKey]);
31177
31614
  const onItemClick = (event, item) => {
31178
- setKeyboardActiveItemKey(item.key);
31179
- setActiveItemKey(item.key);
31180
- if (item.originalMenuItem.onClick) {
31181
- item.originalMenuItem.onClick(event);
31182
- }
31183
- const onActionParam = {
31184
- key: item.key,
31185
- item: item.originalMenuItem,
31186
- hideMenu: hideAll
31187
- };
31188
- if (item.originalMenuItem.onAction) {
31189
- item.originalMenuItem.onAction(onActionParam);
31190
- }
31191
- if (onAction) {
31192
- onAction(onActionParam);
31193
- }
31194
- if (item.originalMenuItem.hideMenuOnAction) {
31195
- hideAll();
31196
- }
31615
+ runMenuItemClick(event, item, {
31616
+ getState,
31617
+ setActiveItemKey,
31618
+ setKeyboardActiveItemKey,
31619
+ hideAll
31620
+ });
31197
31621
  };
31198
31622
  const {
31199
31623
  showOverlay,
@@ -31231,185 +31655,54 @@ function MenuComponent(props) {
31231
31655
  onClick: onItemClick
31232
31656
  }
31233
31657
  ));
31234
- const gridTemplateColumns = columns.map((col) => {
31235
- return col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto";
31236
- }).join(" ");
31237
- const style2 = {
31238
- ...domProps.style,
31239
- gridTemplateColumns,
31240
- gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31241
- };
31242
- if (!wrapLabels) {
31243
- style2.whiteSpace = "nowrap";
31244
- }
31658
+ const style2 = getMenuGridStyle(
31659
+ componentState,
31660
+ domProps.style
31661
+ );
31245
31662
  function handleKeydown(keyboardEvent) {
31246
- const { runtimeItems: runtimeItems2, runtimeSelectableItems } = getState();
31247
- let keyboardActiveIndex = runtimeItems2.findIndex(
31248
- (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31249
- );
31250
- let newKeyboardActiveItemKey = keyboardActiveItemKey;
31251
- const keyboardActiveItem = runtimeItems2[keyboardActiveIndex];
31252
- const validKeys3 = {
31253
- ArrowUp: () => {
31254
- const newActiveItem = runtimeItems2.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31255
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31256
- newKeyboardActiveItemKey = newActiveItem.key;
31257
- }
31258
- },
31259
- ArrowDown: () => {
31260
- const newActiveItem = runtimeItems2.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31261
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31262
- newKeyboardActiveItemKey = newActiveItem.key;
31263
- }
31264
- },
31265
- Home: () => {
31266
- validKeys3.PageUp();
31663
+ handleMenuKeyDown(keyboardEvent, {
31664
+ getState,
31665
+ setActiveItemKey,
31666
+ setKeyboardActiveItemKey,
31667
+ destroy: () => {
31668
+ componentActions.destroyed = true;
31267
31669
  },
31268
- End: () => {
31269
- validKeys3.PageDown();
31670
+ // the submenu api of this render: the raf of ArrowRight reads it
31671
+ getSubmenuApi: () => submenuApi,
31672
+ isMounted,
31673
+ onItemClick
31674
+ });
31675
+ }
31676
+ function onMenuBlur() {
31677
+ componentActions.focused = false;
31678
+ }
31679
+ const refCallback = useCallback30((node) => {
31680
+ if (node) {
31681
+ domRef.current = node;
31682
+ onShow?.(getState(), api);
31683
+ if (autoFocus) {
31684
+ api.focus();
31685
+ }
31686
+ } else {
31687
+ onHide?.(getState());
31688
+ domRef.current = node;
31689
+ }
31690
+ }, []);
31691
+ const result = /* @__PURE__ */ React61.createElement("div", { className: display.contents }, /* @__PURE__ */ React61.createElement(
31692
+ "div",
31693
+ {
31694
+ ...domProps,
31695
+ "data-menu-id": menuId,
31696
+ "data-submenu-for": parentMenuItemKey,
31697
+ tabIndex: 0,
31698
+ ref: refCallback,
31699
+ onKeyDown: (event) => {
31700
+ domProps.onKeyDown?.(event);
31701
+ handleKeydown(event);
31270
31702
  },
31271
- PageUp: () => {
31272
- newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31273
- },
31274
- PageDown: () => {
31275
- newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31276
- },
31277
- ArrowLeft: () => {
31278
- setActiveItemKey(null);
31279
- if (getState().parentMenuId) {
31280
- componentActions.destroyed = true;
31281
- }
31282
- },
31283
- ArrowRight: () => {
31284
- if (!keyboardActiveItem) {
31285
- return;
31286
- }
31287
- setActiveItemKey(keyboardActiveItem.key);
31288
- raf(() => {
31289
- if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31290
- submenuApi.focus();
31291
- }
31292
- });
31293
- },
31294
- Enter: () => {
31295
- if (!keyboardActiveItem) {
31296
- return;
31297
- }
31298
- if (keyboardActiveItem.originalMenuItem?.menu) {
31299
- if (keyboardActiveItem && keyboardActiveItem.originalMenuItem.menu && submenuApi) {
31300
- validKeys3.ArrowLeft();
31301
- return;
31302
- }
31303
- if (keyboardActiveItem) {
31304
- setActiveItemKey(keyboardActiveItem.key);
31305
- }
31306
- } else {
31307
- onItemClick(
31308
- keyboardEvent,
31309
- keyboardActiveItem
31310
- );
31311
- }
31312
- },
31313
- " ": () => {
31314
- if (!keyboardActiveItem) {
31315
- return;
31316
- }
31317
- if (!keyboardActiveItem.originalMenuItem.menu) {
31318
- onItemClick(
31319
- keyboardEvent,
31320
- keyboardActiveItem
31321
- );
31322
- }
31323
- const checkbox = getFirstCheckBoxInsideMenuItem(
31324
- menuId,
31325
- keyboardActiveItem.key
31326
- );
31327
- if (!checkbox) {
31328
- return;
31329
- }
31330
- checkbox.click();
31331
- },
31332
- Escape: () => {
31333
- validKeys3.ArrowLeft();
31334
- const state = getState();
31335
- if (!state.parentMenuId) {
31336
- state.onHideIntent?.(state);
31337
- }
31338
- }
31339
- };
31340
- const fn = validKeys3[keyboardEvent.key];
31341
- if (fn) {
31342
- fn();
31343
- keyboardEvent.preventDefault();
31344
- }
31345
- if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31346
- setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31347
- }
31348
- }
31349
- function onMenuBlur() {
31350
- componentActions.focused = false;
31351
- }
31352
- const onMenuFocus = useCallback30(function() {
31353
- componentActions.focused = true;
31354
- setTimeout(() => {
31355
- if (shouldSelectFirstItemOnFocus.current && domRef.current && domRef.current === document.activeElement && getState().keyboardActiveItemKey == null) {
31356
- setKeyboardActiveItemKey(
31357
- getState().runtimeSelectableItems[0]?.key ?? null
31358
- );
31359
- }
31360
- });
31361
- }, []);
31362
- const shouldSelectFirstItemOnFocus = useRef30(true);
31363
- const hideAll = useCallback30(() => {
31364
- const state = getState();
31365
- state.onHideIntent?.(state);
31366
- }, [getState]);
31367
- const [api] = useState23(() => {
31368
- const result2 = {
31369
- hideMenu: hideAll,
31370
- focus: () => {
31371
- if (domRef.current) {
31372
- domRef.current.focus();
31373
- setTimeout(() => {
31374
- if (domRef.current && domRef.current !== document.activeElement) {
31375
- domRef.current.focus();
31376
- }
31377
- }, 10);
31378
- onMenuFocus();
31379
- }
31380
- },
31381
- getMenuId: () => getState().menuId,
31382
- getParentMenuId: () => getState().parentMenuId
31383
- };
31384
- return result2;
31385
- });
31386
- const refCallback = useCallback30((node) => {
31387
- if (node) {
31388
- domRef.current = node;
31389
- onShow?.(getState(), api);
31390
- if (autoFocus) {
31391
- api.focus();
31392
- }
31393
- } else {
31394
- onHide?.(getState());
31395
- domRef.current = node;
31396
- }
31397
- }, []);
31398
- const result = /* @__PURE__ */ React61.createElement("div", { className: display.contents }, /* @__PURE__ */ React61.createElement(
31399
- "div",
31400
- {
31401
- ...domProps,
31402
- "data-menu-id": menuId,
31403
- "data-submenu-for": parentMenuItemKey,
31404
- tabIndex: 0,
31405
- ref: refCallback,
31406
- onKeyDown: (event) => {
31407
- domProps.onKeyDown?.(event);
31408
- handleKeydown(event);
31409
- },
31410
- onMouseDown: (event) => {
31411
- shouldSelectFirstItemOnFocus.current = false;
31412
- domProps.onMouseDown?.(event);
31703
+ onMouseDown: (event) => {
31704
+ shouldSelectFirstItemOnFocus.current = false;
31705
+ domProps.onMouseDown?.(event);
31413
31706
  },
31414
31707
  onMouseUp: (event) => {
31415
31708
  shouldSelectFirstItemOnFocus.current = true;
@@ -31427,44 +31720,20 @@ function MenuComponent(props) {
31427
31720
  function RuntimeItemRenderer(props) {
31428
31721
  const [pressed, setPressed] = React61.useState(false);
31429
31722
  const { columns, item, index, active, keyboardActive } = props;
31430
- const key = item.type === "item" ? item.value.key : index;
31431
31723
  let content = null;
31432
31724
  if (item.type === "decoration") {
31433
31725
  content = /* @__PURE__ */ React61.createElement("div", { style: item.style }, item.value);
31434
31726
  } else {
31435
- let spanIndex = 0;
31436
- content = columns.map((col, i) => {
31437
- const target = item.value;
31438
- const field = col.field || col.name;
31439
- const start = i + 1;
31440
- const end = start + item.span;
31441
- if (start < spanIndex) {
31442
- return null;
31443
- }
31444
- spanIndex = end;
31445
- const style2 = {
31446
- ...col.style,
31447
- ...item.style,
31448
- gridColumnStart: start,
31449
- gridColumnEnd: end
31450
- };
31727
+ content = getMenuItemCells(item, columns, index, {
31728
+ active,
31729
+ keyboardActive,
31730
+ pressed
31731
+ }).map((cell) => {
31732
+ const col = cell.column;
31451
31733
  const domProps = {
31452
- style: style2,
31453
- //@ts-ignore
31454
- "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31455
- "data-menu-col-name": `${col.name}`,
31456
- "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31457
- "data-menu-row-index": `${index}`,
31458
- "data-menu-item-key": `${item.key}`,
31459
- className: join(
31460
- MenuItemCls({
31461
- active,
31462
- disabled: !!item.disabled,
31463
- keyboardActive,
31464
- pressed: pressed || props.active
31465
- }),
31466
- item.className
31467
- ),
31734
+ style: cell.style,
31735
+ ...cell.dataAttributes,
31736
+ className: cell.className,
31468
31737
  onPointerEnter: (event) => {
31469
31738
  if (!item.disabled) {
31470
31739
  props.onItemEnter?.(item, event);
@@ -31494,17 +31763,17 @@ function RuntimeItemRenderer(props) {
31494
31763
  return col.render ? /* @__PURE__ */ React61.createElement(
31495
31764
  RenderHookComponent,
31496
31765
  {
31497
- key: `${key}-${field}`,
31766
+ key: cell.key,
31498
31767
  render: col.render,
31499
31768
  renderParam: {
31500
- item: target,
31769
+ item: item.value,
31501
31770
  column: col,
31502
- value: target[field],
31771
+ value: cell.value,
31503
31772
  domProps
31504
31773
  }
31505
31774
  }
31506
- ) : /* @__PURE__ */ React61.createElement("div", { key: `${key}-${field}`, ...domProps }, target[field]);
31507
- }).filter(Boolean);
31775
+ ) : /* @__PURE__ */ React61.createElement("div", { key: cell.key, ...domProps }, cell.value);
31776
+ });
31508
31777
  }
31509
31778
  return /* @__PURE__ */ React61.createElement("div", { className: MenuRowCls }, content);
31510
31779
  }
@@ -31569,9 +31838,64 @@ Menu[propToIdentifyMenu] = true;
31569
31838
 
31570
31839
  // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
31571
31840
  import * as React63 from "react";
31572
- function defaultGetColumnMenuItems(_items, params) {
31573
- const { columnApi, column, getComputed, api, dataSourceApi, getState } = params;
31574
- const CheckBoxCmp = getState().components?.CheckBox || InfiniteCheckBox;
31841
+
31842
+ // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
31843
+ function getMenuItemsAndColumns(menuDefinition) {
31844
+ let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
31845
+ const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
31846
+ return {
31847
+ items,
31848
+ columns
31849
+ };
31850
+ }
31851
+ function getMenuVisibilityProps(onHideIntent) {
31852
+ const onRootMouseDown = (event) => {
31853
+ event.__insideMenu = true;
31854
+ };
31855
+ const onHide = (state) => {
31856
+ state.domRef.current?.parentNode?.removeEventListener(
31857
+ "mousedown",
31858
+ onRootMouseDown
31859
+ );
31860
+ };
31861
+ return {
31862
+ onShow: (state) => {
31863
+ state.domRef.current?.parentNode?.addEventListener(
31864
+ "mousedown",
31865
+ onRootMouseDown
31866
+ );
31867
+ },
31868
+ onHide,
31869
+ onHideIntent: (state) => {
31870
+ onHide(state);
31871
+ onHideIntent?.();
31872
+ }
31873
+ };
31874
+ }
31875
+ function getMenuDefaultProps(config) {
31876
+ const menuDefaultProps = {
31877
+ columns: [],
31878
+ items: [],
31879
+ autoFocus: true,
31880
+ ...getMenuVisibilityProps(config.onHideIntent)
31881
+ };
31882
+ return menuDefaultProps;
31883
+ }
31884
+ function getLazyMenuProps(menuDefinition, menuDefaultProps) {
31885
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
31886
+ if (items && items.length) {
31887
+ return {
31888
+ ...menuDefaultProps,
31889
+ items: items || [],
31890
+ columns
31891
+ };
31892
+ }
31893
+ return null;
31894
+ }
31895
+
31896
+ // src/components/InfiniteTable/utils/menuItemsShared.ts
31897
+ function getDefaultColumnMenuItems(params, binder) {
31898
+ const { columnApi, column, getComputed, api, dataSourceApi } = params;
31575
31899
  const sortable = columnApi.isSortable();
31576
31900
  const sortItems = sortable ? [
31577
31901
  {
@@ -31652,25 +31976,22 @@ function defaultGetColumnMenuItems(_items, params) {
31652
31976
  const colItems = [];
31653
31977
  const computed = getComputed();
31654
31978
  computed.computedColumnsMapInInitialOrder.forEach((col, id) => {
31655
- const label = getColumnLabel(col, params, "column-menu");
31979
+ const label = binder.getColumnLabel(col);
31656
31980
  colItems.push({
31657
31981
  key: id,
31658
31982
  label,
31659
- check: /* @__PURE__ */ React63.createElement(
31660
- CheckBoxCmp,
31661
- {
31662
- key: col.id,
31663
- disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
31664
- checked: col.computedVisible,
31665
- onChange: (checked) => {
31666
- const visible = !!checked;
31667
- api.setVisibilityForColumn(col.id, visible);
31668
- requestAnimationFrame(() => {
31669
- api.realignColumnContextMenu();
31670
- });
31671
- }
31983
+ check: binder.renderCheckBox({
31984
+ key: col.id,
31985
+ disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
31986
+ checked: col.computedVisible,
31987
+ onChange: (checked) => {
31988
+ const visible = !!checked;
31989
+ api.setVisibilityForColumn(col.id, visible);
31990
+ requestAnimationFrame(() => {
31991
+ api.realignColumnContextMenu();
31992
+ });
31672
31993
  }
31673
- )
31994
+ })
31674
31995
  });
31675
31996
  });
31676
31997
  return {
@@ -31695,21 +32016,18 @@ function defaultGetColumnMenuItems(_items, params) {
31695
32016
  if (col.groupByForColumn) {
31696
32017
  return;
31697
32018
  }
31698
- const label = getColumnLabel(col, params, "column-menu");
32019
+ const label = binder.getColumnLabel(col);
31699
32020
  colItems.push({
31700
32021
  key: id,
31701
32022
  label,
31702
- check: /* @__PURE__ */ React63.createElement(
31703
- CheckBoxCmp,
31704
- {
31705
- key: col.id,
31706
- disabled: !col.computedGroupable,
31707
- checked: col.computedGroupedBy,
31708
- onChange: () => {
31709
- dataSourceApi.toggleGroupByField(col.field);
31710
- }
32023
+ check: binder.renderCheckBox({
32024
+ key: col.id,
32025
+ disabled: !col.computedGroupable,
32026
+ checked: col.computedGroupedBy,
32027
+ onChange: () => {
32028
+ dataSourceApi.toggleGroupByField(col.field);
31711
32029
  }
31712
- )
32030
+ })
31713
32031
  });
31714
32032
  });
31715
32033
  return {
@@ -31725,15 +32043,12 @@ function defaultGetColumnMenuItems(_items, params) {
31725
32043
  }
31726
32044
  ].filter((x) => !!x);
31727
32045
  }
31728
-
31729
- // src/components/InfiniteTable/utils/getMenuForColumn.tsx
31730
- function getMenuForColumn(columnId, context, onHideIntent) {
32046
+ function getColumnMenuProps(columnId, context, onHideIntent, getDefaultItems) {
31731
32047
  if (columnId == null) {
31732
32048
  return null;
31733
32049
  }
31734
32050
  const { getComputed, getState } = context;
31735
- const { components: components2, getColumnMenuItems } = getState();
31736
- const MenuCmp = components2?.Menu ?? Menu;
32051
+ const { getColumnMenuItems } = getState();
31737
32052
  const column = getComputed().computedColumnsMap.get(columnId);
31738
32053
  if (!column) {
31739
32054
  return null;
@@ -31743,124 +32058,465 @@ function getMenuForColumn(columnId, context, onHideIntent) {
31743
32058
  columnApi: getColumnApiForColumn(column.id, context),
31744
32059
  ...context
31745
32060
  };
31746
- const defaultItems = defaultGetColumnMenuItems([], param);
32061
+ const defaultItems = getDefaultItems(param);
31747
32062
  const items = getColumnMenuItems ? getColumnMenuItems(defaultItems, param) : defaultItems;
31748
- const onRootMouseDown = (event) => {
31749
- event.__insideMenu = true;
31750
- };
31751
- const onHide = (state) => {
31752
- state.domRef.current?.parentNode?.removeEventListener(
31753
- "mousedown",
31754
- onRootMouseDown
31755
- );
31756
- };
31757
32063
  if (!items || !items.length) {
31758
32064
  return null;
31759
32065
  }
31760
- return /* @__PURE__ */ React64.createElement(
31761
- MenuCmp,
31762
- {
31763
- autoFocus: true,
31764
- items,
31765
- onShow: (state) => {
31766
- state.domRef.current?.parentNode?.addEventListener(
31767
- "mousedown",
31768
- onRootMouseDown
31769
- );
31770
- },
31771
- onHide,
31772
- onHideIntent: (state) => {
31773
- onHide(state);
31774
- onHideIntent?.();
31775
- }
31776
- }
31777
- );
31778
- }
31779
-
31780
- // src/components/InfiniteTable/utils/menuOverlayTargets.ts
31781
- function resolveMenuElement(element) {
31782
- return typeof element === "function" ? element() : element;
31783
- }
31784
- function getMenuConstrainTo(state) {
31785
- return resolveMenuElement(state.menuConstrainTo) ?? state.domRef.current;
31786
- }
31787
- function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer) {
31788
- if (!menuPortalContainer) {
31789
- return defaultContainer || false;
31790
- }
31791
- return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
31792
- }
31793
-
31794
- // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
31795
- import { useMemo as useMemo19 } from "react";
31796
- function useMenuPortalContainer() {
31797
- const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
31798
- return {
31799
- getState: ctx.getState,
31800
- menuPortalContainer: ctx.state.menuPortalContainer
31801
- };
31802
- });
31803
- const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
31804
- return {
31805
- portalDOMRef: ctx.getMasterState().portalDOMRef
31806
- };
31807
- }) || {};
31808
- const defaultContainer = portalDOMRef?.current;
31809
- return useMemo19(
31810
- () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
31811
- [getState, menuPortalContainer, defaultContainer]
31812
- );
32066
+ return {
32067
+ autoFocus: true,
32068
+ items,
32069
+ ...getMenuVisibilityProps(onHideIntent)
32070
+ };
31813
32071
  }
31814
-
31815
- // src/components/InfiniteTable/hooks/useColumnMenu.ts
31816
- var menuIconSelector2 = `[${MenuIconDataAttributes["data-name"]}="${MenuIconDataAttributesValues["data-name"]}"]`;
31817
- function showMenuForColumn(options) {
31818
- const { columnId, context, clearAll, showOverlay } = options;
31819
- const { getState, actions } = context;
31820
- const { columnMenuTargetRef, domRef } = getState();
31821
- function onHideIntent() {
31822
- clearAll();
31823
- actions.columnMenuVisibleForColumnId = null;
31824
- }
31825
- let target = options.target;
31826
- if (!target) {
31827
- target = columnMenuTargetRef.current ?? void 0;
31828
- if (target && !domRef.current.contains(target)) {
31829
- target = void 0;
31830
- }
31831
- }
31832
- if (!target) {
31833
- const iconSelector = `[${InfiniteHeaderCellDataAttributes["data-column-id"]}="${columnId}"] ${menuIconSelector2}`;
31834
- target = getState().domRef.current.querySelector(
31835
- iconSelector
31836
- );
31837
- }
31838
- if (!target) {
31839
- console.warn(`Cannot show column menu for column "${columnId}"`);
31840
- return;
32072
+ function getFilterOperatorMenuProps(columnId, context, onHideIntent, binder) {
32073
+ if (columnId == null) {
32074
+ return null;
31841
32075
  }
31842
- columnMenuTargetRef.current = null;
31843
- showOverlay(() => getMenuForColumn(columnId, context, onHideIntent), {
31844
- constrainTo: getMenuConstrainTo(getState()),
31845
- id: "column-menu",
31846
- alignTo: target,
31847
- alignPosition: [
31848
- ["TopLeft", "BottomLeft"],
31849
- ["TopRight", "BottomRight"]
31850
- ]
31851
- });
31852
- }
31853
- function useColumnMenu() {
31854
- const context = useInfiniteTableStableContext();
31855
32076
  const {
32077
+ getComputed,
31856
32078
  getState,
32079
+ getDataSourceState,
31857
32080
  actions,
31858
- columnMenuVisibleForColumnId,
31859
- columnMenuVisibleKey
31860
- } = useInfiniteTableSelector((ctx) => {
32081
+ dataSourceApi,
32082
+ dataSourceActions,
32083
+ api
32084
+ } = context;
32085
+ const { getFilterOperatorMenuItems } = getState();
32086
+ const column = getComputed().computedColumnsMap.get(columnId);
32087
+ if (!column) {
32088
+ return null;
32089
+ }
32090
+ const { filterTypes } = getDataSourceState();
32091
+ const columnFilterType = filterTypes[column.computedFilterType];
32092
+ if (!columnFilterType) {
32093
+ return null;
32094
+ }
32095
+ const operatorItems = columnFilterType.operators.map((operator) => {
32096
+ const key = operator.name;
32097
+ const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32098
+ return {
32099
+ key,
32100
+ icon: binder.renderOperatorIcon(operator),
32101
+ label: binder.renderOperatorLabel(operator.label ?? operator.name),
32102
+ onAction: () => {
32103
+ api.setColumnFilterOperator(columnId, key);
32104
+ },
32105
+ checked: checked ? binder.renderDoneIcon() : null
32106
+ };
32107
+ });
32108
+ const firstItems = [
32109
+ {
32110
+ key: "close",
32111
+ label: "Close Menu",
32112
+ icon: null,
32113
+ onAction: () => {
32114
+ api.hideFilterOperatorMenu();
32115
+ }
32116
+ },
32117
+ {
32118
+ key: "reset",
32119
+ label: "Reset",
32120
+ icon: binder.renderClearIcon(),
32121
+ disabled: !column.computedFiltered,
32122
+ onAction: () => {
32123
+ api.clearColumnFilter(columnId);
32124
+ }
32125
+ },
32126
+ "-"
32127
+ ];
32128
+ const defaultItems = [...firstItems, ...operatorItems];
32129
+ const param = {
32130
+ column,
32131
+ api,
32132
+ getState,
32133
+ getDataSourceState,
32134
+ getComputed,
32135
+ actions,
32136
+ dataSourceApi,
32137
+ dataSourceActions,
32138
+ columnFilterValue: column.computedFilterValue,
32139
+ filterTypes
32140
+ };
32141
+ const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32142
+ return {
32143
+ autoFocus: true,
32144
+ columns: [
32145
+ {
32146
+ name: "icon"
32147
+ },
32148
+ { name: "label" },
32149
+ { name: "checked" }
32150
+ ],
32151
+ items,
32152
+ ...getMenuVisibilityProps(onHideIntent)
32153
+ };
32154
+ }
32155
+ function getContextMenuContent(menuDefinition, menuDefaultProps, binder) {
32156
+ const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32157
+ if (menuDefinition instanceof Promise) {
32158
+ return {
32159
+ menu: binder.renderLazyMenu(menuDefinition, menuDefaultProps),
32160
+ preventDefault
32161
+ };
32162
+ }
32163
+ const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32164
+ if (!items || !items.length) {
32165
+ return { menu: null, preventDefault: Array.isArray(items) };
32166
+ }
32167
+ return {
32168
+ preventDefault,
32169
+ menu: binder.renderMenu({ ...menuDefaultProps, columns, items })
32170
+ };
32171
+ }
32172
+ function getCellContextMenuContent(cellLocation, context, onHideIntent, binder) {
32173
+ const { columnId, rowIndex, event } = cellLocation;
32174
+ const { getComputed, getState } = context;
32175
+ const { getCellContextMenuItems } = getState();
32176
+ const { computedColumnsMap } = getComputed();
32177
+ const column = computedColumnsMap.get(columnId);
32178
+ const cellContext = {
32179
+ ...getCellContext({
32180
+ ...context,
32181
+ rowIndex,
32182
+ columnId: column.id
32183
+ }),
32184
+ event
32185
+ };
32186
+ if (!column || !getCellContextMenuItems) {
32187
+ return {
32188
+ cellContext,
32189
+ menu: null,
32190
+ preventDefault: false
32191
+ };
32192
+ }
32193
+ const menuDefaultProps = getMenuDefaultProps({
32194
+ onHideIntent
32195
+ });
32196
+ const menuDefinition = getCellContextMenuItems(cellContext, context);
32197
+ return {
32198
+ cellContext,
32199
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32200
+ };
32201
+ }
32202
+ function getTableContextMenuContent(menuLocation, context, onHideIntent, binder) {
32203
+ const { getState, getComputed } = context;
32204
+ const { getContextMenuItems } = getState();
32205
+ const { computedColumnsMap } = getComputed();
32206
+ const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32207
+ const cellContext = column ? {
32208
+ ...menuLocation,
32209
+ ...getCellContext({
32210
+ ...context,
32211
+ rowIndex: menuLocation.rowIndex,
32212
+ columnId: column.id
32213
+ })
32214
+ } : menuLocation;
32215
+ if (!getContextMenuItems) {
32216
+ return { cellContext, menu: null, preventDefault: false };
32217
+ }
32218
+ const menuDefaultProps = getMenuDefaultProps({
32219
+ onHideIntent
32220
+ });
32221
+ const menuDefinition = getContextMenuItems(cellContext, context);
32222
+ return {
32223
+ cellContext,
32224
+ ...getContextMenuContent(menuDefinition, menuDefaultProps, binder)
32225
+ };
32226
+ }
32227
+
32228
+ // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
32229
+ function defaultGetColumnMenuItems(_items, params) {
32230
+ const CheckBoxCmp = params.getState().components?.CheckBox || InfiniteCheckBox;
32231
+ return getDefaultColumnMenuItems(params, {
32232
+ renderCheckBox: ({ key, ...props }) => /* @__PURE__ */ React63.createElement(CheckBoxCmp, { key, ...props }),
32233
+ getColumnLabel: (col) => getColumnLabel(col, params, "column-menu")
32234
+ });
32235
+ }
32236
+
32237
+ // src/components/InfiniteTable/utils/getMenuForColumn.tsx
32238
+ function getMenuForColumn(columnId, context, onHideIntent) {
32239
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32240
+ const menuProps = getColumnMenuProps(
32241
+ columnId,
32242
+ context,
32243
+ onHideIntent,
32244
+ (param) => defaultGetColumnMenuItems([], param)
32245
+ );
32246
+ return menuProps ? /* @__PURE__ */ React64.createElement(MenuCmp, { ...menuProps }) : null;
32247
+ }
32248
+
32249
+ // src/components/InfiniteTable/utils/menuOverlayTargets.ts
32250
+ function resolveMenuElement(element) {
32251
+ return typeof element === "function" ? element() : element;
32252
+ }
32253
+ function getMenuConstrainTo(state) {
32254
+ return resolveMenuElement(state.menuConstrainTo) ?? state.domRef.current;
32255
+ }
32256
+ function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer) {
32257
+ if (!menuPortalContainer) {
32258
+ return defaultContainer || false;
32259
+ }
32260
+ return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
32261
+ }
32262
+
32263
+ // src/components/InfiniteTable/utils/menuOverlayShared.ts
32264
+ var CONTEXT_MENU_OFFSET = 5;
32265
+ var CONTEXT_MENU_ALIGN_POSITIONS = [
32266
+ ["TopLeft", "BottomLeft"],
32267
+ ["TopRight", "BottomRight"],
32268
+ ["BottomLeft", "BottomLeft"],
32269
+ ["BottomRight", "BottomRight"],
32270
+ ["TopCenter", "TopLeft"],
32271
+ ["BottomCenter", "TopLeft"],
32272
+ ["CenterLeft", "TopLeft"],
32273
+ ["CenterRight", "TopLeft"]
32274
+ ];
32275
+ var FILTER_OPERATOR_MENU_OFFSET = 10;
32276
+ function closeMenuOnOutsideMouseDown(close) {
32277
+ function handleMouseDown(event) {
32278
+ if (event.__insideMenu !== true) {
32279
+ close();
32280
+ }
32281
+ }
32282
+ document.documentElement.addEventListener("mousedown", handleMouseDown);
32283
+ return () => {
32284
+ document.documentElement.removeEventListener("mousedown", handleMouseDown);
32285
+ };
32286
+ }
32287
+ function menuVisibilityEffect(visible, clearAll, hide) {
32288
+ if (visible) {
32289
+ return closeMenuOnOutsideMouseDown(() => {
32290
+ clearAll();
32291
+ hide();
32292
+ });
32293
+ }
32294
+ clearAll();
32295
+ return void 0;
32296
+ }
32297
+ function getColumnMenuClickHandler(context) {
32298
+ const { getState, actions } = context;
32299
+ return (info) => {
32300
+ if (!info) {
32301
+ return;
32302
+ }
32303
+ getState().columnMenuTargetRef.current = info.target;
32304
+ actions.contextMenuVisibleFor = null;
32305
+ actions.cellContextMenuVisibleFor = null;
32306
+ actions.filterOperatorMenuVisibleForColumnId = null;
32307
+ actions.columnMenuVisibleForColumnId = info.column.id;
32308
+ };
32309
+ }
32310
+ function showMenuForColumn(options) {
32311
+ const { columnId, context, clearAll, show } = options;
32312
+ const { getState, actions } = context;
32313
+ const { columnMenuTargetRef, domRef } = getState();
32314
+ function onHideIntent() {
32315
+ clearAll();
32316
+ actions.columnMenuVisibleForColumnId = null;
32317
+ }
32318
+ let target = options.target;
32319
+ if (!target) {
32320
+ target = columnMenuTargetRef.current ?? void 0;
32321
+ if (target && !domRef.current.contains(target)) {
32322
+ target = void 0;
32323
+ }
32324
+ }
32325
+ if (!target) {
32326
+ const iconSelector = `[data-column-id="${columnId}"] ${menuIconSelector}`;
32327
+ target = getState().domRef.current.querySelector(
32328
+ iconSelector
32329
+ );
32330
+ }
32331
+ if (!target) {
32332
+ console.warn(`Cannot show column menu for column "${columnId}"`);
32333
+ return;
32334
+ }
32335
+ columnMenuTargetRef.current = null;
32336
+ show(onHideIntent, {
32337
+ constrainTo: getMenuConstrainTo(getState()),
32338
+ id: "column-menu",
32339
+ alignTo: target,
32340
+ alignPosition: [
32341
+ ["TopLeft", "BottomLeft"],
32342
+ ["TopRight", "BottomRight"]
32343
+ ]
32344
+ });
32345
+ }
32346
+ function columnMenuVisibilityEffect(context, overlay) {
32347
+ const { getState, actions } = context;
32348
+ const { clearAll } = overlay;
32349
+ const { columnMenuVisibleForColumnId, columnMenuTargetRef } = getState();
32350
+ if (columnMenuVisibleForColumnId) {
32351
+ const cleanup = closeMenuOnOutsideMouseDown(() => {
32352
+ clearAll();
32353
+ actions.columnMenuVisibleForColumnId = null;
32354
+ });
32355
+ showMenuForColumn({
32356
+ columnId: columnMenuVisibleForColumnId,
32357
+ context,
32358
+ clearAll,
32359
+ show: (onHideIntent, params) => overlay.show(columnMenuVisibleForColumnId, onHideIntent, params)
32360
+ });
32361
+ return cleanup;
32362
+ }
32363
+ columnMenuTargetRef.current = null;
32364
+ clearAll();
32365
+ return void 0;
32366
+ }
32367
+ function getContextMenuRect(event) {
32368
+ const point = {
32369
+ top: event.clientY,
32370
+ left: event.clientX
32371
+ };
32372
+ const rect = Rectangle.fromPoint(point);
32373
+ rect.width += CONTEXT_MENU_OFFSET;
32374
+ rect.height += CONTEXT_MENU_OFFSET;
32375
+ return { point, rect };
32376
+ }
32377
+ function getCellContextMenuHandler(context, overlay) {
32378
+ const { actions, getState, getDataSourceState } = context;
32379
+ const { clearAll } = overlay;
32380
+ return (info) => {
32381
+ if (!info) {
32382
+ return;
32383
+ }
32384
+ const { event } = info;
32385
+ function onHideIntent() {
32386
+ clearAll();
32387
+ actions.cellContextMenuVisibleFor = null;
32388
+ }
32389
+ const content = overlay.getContent(info, onHideIntent);
32390
+ const { cellContext, preventDefault } = content;
32391
+ const { rect } = getContextMenuRect(event);
32392
+ overlay.show(content, {
32393
+ constrainTo: getMenuConstrainTo(getState()),
32394
+ id: "cell-context-menu",
32395
+ alignTo: rect,
32396
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32397
+ });
32398
+ if (preventDefault) {
32399
+ event.preventDefault();
32400
+ }
32401
+ actions.cellContextMenuVisibleFor = {
32402
+ columnId: info.columnId,
32403
+ rowId: info.rowId,
32404
+ rowIndex: info.rowIndex,
32405
+ colIndex: info.colIndex
32406
+ };
32407
+ const { onCellContextMenu } = getState();
32408
+ if (onCellContextMenu) {
32409
+ onCellContextMenu(
32410
+ {
32411
+ ...cellContext,
32412
+ getState,
32413
+ getDataSourceState
32414
+ },
32415
+ event
32416
+ );
32417
+ }
32418
+ };
32419
+ }
32420
+ function getTableContextMenuHandler(context, overlay) {
32421
+ const { actions, getState } = context;
32422
+ const { clearAll } = overlay;
32423
+ return (info) => {
32424
+ if (!info) {
32425
+ return;
32426
+ }
32427
+ const { event } = info;
32428
+ function onHideIntent() {
32429
+ clearAll();
32430
+ actions.contextMenuVisibleFor = null;
32431
+ }
32432
+ const content = overlay.getContent(info, onHideIntent);
32433
+ const { cellContext, preventDefault } = content;
32434
+ const { point, rect } = getContextMenuRect(event);
32435
+ overlay.show(content, {
32436
+ constrainTo: getMenuConstrainTo(getState()),
32437
+ id: "table-context-menu",
32438
+ alignTo: rect,
32439
+ alignPosition: CONTEXT_MENU_ALIGN_POSITIONS
32440
+ });
32441
+ if (preventDefault) {
32442
+ event.preventDefault();
32443
+ }
32444
+ actions.contextMenuVisibleFor = {
32445
+ point,
32446
+ ...info
32447
+ };
32448
+ const { onContextMenu } = getState();
32449
+ if (onContextMenu) {
32450
+ onContextMenu(
32451
+ {
32452
+ ...context,
32453
+ ...cellContext
32454
+ },
32455
+ event
32456
+ );
32457
+ }
32458
+ };
32459
+ }
32460
+ function getFilterOperatorMenuClickHandler(context, overlay) {
32461
+ const { getState, actions } = context;
32462
+ const { clearAll } = overlay;
32463
+ return (info) => {
32464
+ if (!info) {
32465
+ return;
32466
+ }
32467
+ const { target, column } = info;
32468
+ function onHideIntent() {
32469
+ clearAll();
32470
+ actions.filterOperatorMenuVisibleForColumnId = null;
32471
+ }
32472
+ const alignTo = target?.parentElement || target;
32473
+ const rect = Rectangle.from(alignTo.getBoundingClientRect());
32474
+ rect.top -= FILTER_OPERATOR_MENU_OFFSET;
32475
+ rect.left -= FILTER_OPERATOR_MENU_OFFSET;
32476
+ rect.width += 2 * FILTER_OPERATOR_MENU_OFFSET;
32477
+ rect.height += 2 * FILTER_OPERATOR_MENU_OFFSET;
32478
+ overlay.show(column.id, onHideIntent, {
32479
+ constrainTo: getMenuConstrainTo(getState()),
32480
+ id: "filter-operator-menu",
32481
+ alignTo: rect,
32482
+ alignPosition: [
32483
+ ["TopLeft", "BottomLeft"],
32484
+ ["TopRight", "BottomRight"]
32485
+ ]
32486
+ });
32487
+ actions.contextMenuVisibleFor = null;
32488
+ actions.cellContextMenuVisibleFor = null;
32489
+ actions.columnMenuVisibleForColumnId = null;
32490
+ actions.filterOperatorMenuVisibleForColumnId = column.id;
32491
+ };
32492
+ }
32493
+
32494
+ // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
32495
+ import { useMemo as useMemo19 } from "react";
32496
+ function useMenuPortalContainer() {
32497
+ const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
31861
32498
  return {
31862
32499
  getState: ctx.getState,
31863
- actions: ctx.actions,
32500
+ menuPortalContainer: ctx.state.menuPortalContainer
32501
+ };
32502
+ });
32503
+ const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
32504
+ return {
32505
+ portalDOMRef: ctx.getMasterState().portalDOMRef
32506
+ };
32507
+ }) || {};
32508
+ const defaultContainer = portalDOMRef?.current;
32509
+ return useMemo19(
32510
+ () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
32511
+ [getState, menuPortalContainer, defaultContainer]
32512
+ );
32513
+ }
32514
+
32515
+ // src/components/InfiniteTable/hooks/useColumnMenu.ts
32516
+ function useColumnMenu() {
32517
+ const context = useInfiniteTableStableContext();
32518
+ const { columnMenuVisibleForColumnId, columnMenuVisibleKey } = useInfiniteTableSelector((ctx) => {
32519
+ return {
31864
32520
  columnMenuVisibleForColumnId: ctx.state.columnMenuVisibleForColumnId,
31865
32521
  columnMenuVisibleKey: ctx.state.columnMenuVisibleKey
31866
32522
  };
@@ -31873,47 +32529,16 @@ function useColumnMenu() {
31873
32529
  portalContainer: useMenuPortalContainer()
31874
32530
  });
31875
32531
  useEffect32(() => {
31876
- const state = getState();
31877
- return state.onColumnMenuClick.onChange((info) => {
31878
- if (!info) {
31879
- return;
31880
- }
31881
- state.columnMenuTargetRef.current = info.target;
31882
- actions.contextMenuVisibleFor = null;
31883
- actions.cellContextMenuVisibleFor = null;
31884
- actions.filterOperatorMenuVisibleForColumnId = null;
31885
- actions.columnMenuVisibleForColumnId = info.column.id;
31886
- });
32532
+ return context.getState().onColumnMenuClick.onChange(getColumnMenuClickHandler(context));
31887
32533
  }, []);
31888
32534
  useEffect32(() => {
31889
- const { columnMenuVisibleForColumnId: columnMenuVisibleForColumnId2, columnMenuTargetRef } = getState();
31890
- if (columnMenuVisibleForColumnId2) {
31891
- let handleMouseDown2 = function(event) {
31892
- if (event.__insideMenu !== true) {
31893
- clearAll();
31894
- actions.columnMenuVisibleForColumnId = null;
31895
- }
31896
- };
31897
- var handleMouseDown = handleMouseDown2;
31898
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
31899
- showMenuForColumn({
31900
- columnId: columnMenuVisibleForColumnId2,
31901
- context,
31902
- clearAll,
31903
- showOverlay
31904
- });
31905
- return () => {
31906
- document.documentElement.removeEventListener(
31907
- "mousedown",
31908
- handleMouseDown2
31909
- );
31910
- };
31911
- } else {
31912
- columnMenuTargetRef.current = null;
31913
- clearAll();
31914
- }
31915
- return () => {
31916
- };
32535
+ return columnMenuVisibilityEffect(context, {
32536
+ clearAll,
32537
+ show: (columnId, onHideIntent, params) => showOverlay(
32538
+ () => getMenuForColumn(columnId, context, onHideIntent),
32539
+ params
32540
+ )
32541
+ });
31917
32542
  }, [columnMenuVisibleForColumnId, columnMenuVisibleKey]);
31918
32543
  return { menuPortal };
31919
32544
  }
@@ -32096,149 +32721,59 @@ function useOnEditPersisted() {
32096
32721
  };
32097
32722
  if (persisted instanceof Error) {
32098
32723
  onEditPersistError?.({ ...params, error: persisted });
32099
- } else {
32100
- onEditPersistSuccess?.(params);
32101
- }
32102
- }
32103
- }, [persisted]);
32104
- }
32105
- function useEditingCallbackProps() {
32106
- useOnEditCancelled();
32107
- useOnEditRejected();
32108
- useOnEditAccepted();
32109
- useOnEditPersisted();
32110
- useFocusOnEditStop();
32111
- }
32112
-
32113
- // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32114
- import { useEffect as useEffect34 } from "react";
32115
-
32116
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32117
- import * as React68 from "react";
32118
-
32119
- // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32120
- import * as React66 from "react";
32121
- var ClearIcon = (props) => {
32122
- return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32123
- };
32124
-
32125
- // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32126
- import * as React67 from "react";
32127
- var DoneIcon = (props) => {
32128
- return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32129
- };
32130
-
32131
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32132
- function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32133
- if (columnId == null) {
32134
- return null;
32135
- }
32136
- const {
32137
- getComputed,
32138
- getState,
32139
- getDataSourceState,
32140
- actions,
32141
- dataSourceApi,
32142
- dataSourceActions,
32143
- api
32144
- } = context;
32145
- const { components: components2, getFilterOperatorMenuItems } = getState();
32146
- const MenuCmp = components2?.Menu ?? Menu;
32147
- const column = getComputed().computedColumnsMap.get(columnId);
32148
- if (!column) {
32149
- return null;
32150
- }
32151
- const onRootMouseDown = (event) => {
32152
- event.__insideMenu = true;
32153
- };
32154
- const onHide = (state) => {
32155
- state.domRef.current?.parentNode?.removeEventListener(
32156
- "mousedown",
32157
- onRootMouseDown
32158
- );
32159
- };
32160
- const { filterTypes } = getDataSourceState();
32161
- const columnFilterType = filterTypes[column.computedFilterType];
32162
- if (!columnFilterType) {
32163
- return null;
32164
- }
32165
- const operatorItems = columnFilterType.operators.map((operator) => {
32166
- const key = operator.name;
32167
- const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32168
- const IconCmp = operator.components?.Icon ?? FilterIcon;
32169
- return {
32170
- key,
32171
- icon: /* @__PURE__ */ React68.createElement(IconCmp, null),
32172
- label: /* @__PURE__ */ React68.createElement(React68.Fragment, null, operator.label ?? operator.name),
32173
- onAction: () => {
32174
- api.setColumnFilterOperator(columnId, key);
32175
- },
32176
- checked: checked ? /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 }) : null
32177
- };
32178
- });
32179
- const firstItems = [
32180
- {
32181
- key: "close",
32182
- label: "Close Menu",
32183
- icon: null,
32184
- onAction: () => {
32185
- api.hideFilterOperatorMenu();
32186
- }
32187
- },
32188
- {
32189
- key: "reset",
32190
- label: "Reset",
32191
- icon: /* @__PURE__ */ React68.createElement(ClearIcon, null),
32192
- disabled: !column.computedFiltered,
32193
- onAction: () => {
32194
- api.clearColumnFilter(columnId);
32195
- }
32196
- },
32197
- "-"
32198
- ];
32199
- const defaultItems = [...firstItems, ...operatorItems];
32200
- const param = {
32201
- column,
32202
- api,
32203
- getState,
32204
- getDataSourceState,
32205
- getComputed,
32206
- actions,
32207
- dataSourceApi,
32208
- dataSourceActions,
32209
- columnFilterValue: column.computedFilterValue,
32210
- filterTypes
32211
- };
32212
- const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32213
- return /* @__PURE__ */ React68.createElement(
32214
- MenuCmp,
32724
+ } else {
32725
+ onEditPersistSuccess?.(params);
32726
+ }
32727
+ }
32728
+ }, [persisted]);
32729
+ }
32730
+ function useEditingCallbackProps() {
32731
+ useOnEditCancelled();
32732
+ useOnEditRejected();
32733
+ useOnEditAccepted();
32734
+ useOnEditPersisted();
32735
+ useFocusOnEditStop();
32736
+ }
32737
+
32738
+ // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32739
+ import { useEffect as useEffect34 } from "react";
32740
+
32741
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32742
+ import * as React68 from "react";
32743
+
32744
+ // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32745
+ import * as React66 from "react";
32746
+ var ClearIcon = (props) => {
32747
+ return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32748
+ };
32749
+
32750
+ // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32751
+ import * as React67 from "react";
32752
+ var DoneIcon = (props) => {
32753
+ return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32754
+ };
32755
+
32756
+ // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32757
+ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32758
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32759
+ const menuProps = getFilterOperatorMenuProps(
32760
+ columnId,
32761
+ context,
32762
+ onHideIntent,
32215
32763
  {
32216
- autoFocus: true,
32217
- columns: [
32218
- {
32219
- name: "icon"
32220
- },
32221
- { name: "label" },
32222
- { name: "checked" }
32223
- ],
32224
- items,
32225
- onShow: (state) => {
32226
- state.domRef.current?.parentNode?.addEventListener(
32227
- "mousedown",
32228
- onRootMouseDown
32229
- );
32764
+ renderOperatorIcon: (operator) => {
32765
+ const IconCmp = operator.components?.Icon ?? FilterIcon;
32766
+ return /* @__PURE__ */ React68.createElement(IconCmp, null);
32230
32767
  },
32231
- onHide,
32232
- onHideIntent: (state) => {
32233
- onHide(state);
32234
- onHideIntent?.();
32235
- }
32768
+ renderOperatorLabel: (label) => /* @__PURE__ */ React68.createElement(React68.Fragment, null, label),
32769
+ renderClearIcon: () => /* @__PURE__ */ React68.createElement(ClearIcon, null),
32770
+ renderDoneIcon: () => /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 })
32236
32771
  }
32237
32772
  );
32773
+ return menuProps ? /* @__PURE__ */ React68.createElement(MenuCmp, { ...menuProps }) : null;
32238
32774
  }
32239
32775
 
32240
32776
  // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32241
- var OFFSET2 = 10;
32242
32777
  function useColumnFilterOperatorMenu() {
32243
32778
  const stableContext = useInfiniteTableStableContext();
32244
32779
  const { getState, actions } = stableContext;
@@ -32250,66 +32785,28 @@ function useColumnFilterOperatorMenu() {
32250
32785
  portalContainer: useMenuPortalContainer()
32251
32786
  });
32252
32787
  useEffect34(() => {
32253
- const state = getState();
32254
- return state.onFilterOperatorMenuClick.onChange((info) => {
32255
- if (!info) {
32256
- return;
32257
- }
32258
- const { target, column } = info;
32259
- function onHideIntent() {
32260
- clearAll();
32261
- actions.filterOperatorMenuVisibleForColumnId = null;
32262
- }
32263
- let alignTo = target?.parentElement || target;
32264
- const rect = Rectangle.from(alignTo.getBoundingClientRect());
32265
- rect.top -= OFFSET2;
32266
- rect.left -= OFFSET2;
32267
- rect.width += 2 * OFFSET2;
32268
- rect.height += 2 * OFFSET2;
32269
- showOverlay(
32270
- () => getFilterOperatorMenuForColumn(
32271
- column.id,
32272
- stableContext,
32273
- onHideIntent
32274
- ),
32275
- {
32276
- constrainTo: getMenuConstrainTo(getState()),
32277
- id: "filter-operator-menu",
32278
- alignTo: rect,
32279
- alignPosition: [
32280
- ["TopLeft", "BottomLeft"],
32281
- ["TopRight", "BottomRight"]
32282
- ]
32283
- }
32284
- );
32285
- actions.contextMenuVisibleFor = null;
32286
- actions.cellContextMenuVisibleFor = null;
32287
- actions.columnMenuVisibleForColumnId = null;
32288
- actions.filterOperatorMenuVisibleForColumnId = column.id;
32289
- });
32788
+ return getState().onFilterOperatorMenuClick.onChange(
32789
+ getFilterOperatorMenuClickHandler(stableContext, {
32790
+ clearAll,
32791
+ show: (columnId, onHideIntent, params) => showOverlay(
32792
+ () => getFilterOperatorMenuForColumn(
32793
+ columnId,
32794
+ stableContext,
32795
+ onHideIntent
32796
+ ),
32797
+ params
32798
+ )
32799
+ })
32800
+ );
32290
32801
  }, []);
32291
32802
  useEffect34(() => {
32292
- const { filterOperatorMenuVisibleForColumnId } = getState();
32293
- if (filterOperatorMenuVisibleForColumnId) {
32294
- let handleMouseDown2 = function(event) {
32295
- if (event.__insideMenu !== true) {
32296
- clearAll();
32297
- actions.filterOperatorMenuVisibleForColumnId = null;
32298
- }
32299
- };
32300
- var handleMouseDown = handleMouseDown2;
32301
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32302
- return () => {
32303
- document.documentElement.removeEventListener(
32304
- "mousedown",
32305
- handleMouseDown2
32306
- );
32307
- };
32308
- } else {
32309
- clearAll();
32310
- }
32311
- return () => {
32312
- };
32803
+ return menuVisibilityEffect(
32804
+ getState().filterOperatorMenuVisibleForColumnId,
32805
+ clearAll,
32806
+ () => {
32807
+ actions.filterOperatorMenuVisibleForColumnId = null;
32808
+ }
32809
+ );
32313
32810
  }, [getState().filterOperatorMenuVisibleForColumnId]);
32314
32811
  return { menuPortal };
32315
32812
  }
@@ -32322,159 +32819,46 @@ import * as React70 from "react";
32322
32819
 
32323
32820
  // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32324
32821
  import * as React69 from "react";
32325
-
32326
- // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
32327
- function getMenuItemsAndColumns(menuDefinition) {
32328
- let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
32329
- const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
32330
- return {
32331
- items,
32332
- columns
32333
- };
32334
- }
32335
- function getMenuDefaultProps(config) {
32336
- const onRootMouseDown = (event) => {
32337
- event.__insideMenu = true;
32338
- };
32339
- const onHide = (state) => {
32340
- state.domRef.current?.parentNode?.removeEventListener(
32341
- "mousedown",
32342
- onRootMouseDown
32343
- );
32344
- };
32345
- const menuDefaultProps = {
32346
- columns: [],
32347
- items: [],
32348
- autoFocus: true,
32349
- onShow: (state) => {
32350
- state.domRef.current?.parentNode?.addEventListener(
32351
- "mousedown",
32352
- onRootMouseDown
32353
- );
32354
- },
32355
- onHide,
32356
- onHideIntent: (state) => {
32357
- onHide(state);
32358
- config.onHideIntent?.();
32359
- }
32360
- };
32361
- return menuDefaultProps;
32362
- }
32363
-
32364
- // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32365
32822
  function getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp) {
32366
32823
  if (!menuDefinition) {
32367
32824
  return null;
32368
32825
  }
32369
32826
  const updater = buildSubscriptionCallback();
32370
32827
  menuDefinition.then((menuDefinition2) => {
32371
- const { items, columns } = getMenuItemsAndColumns(menuDefinition2);
32372
- if (items && items.length) {
32373
- updater(
32374
- /* @__PURE__ */ React69.createElement(MenuCmp, { ...menuDefaultProps, items: items || [], columns })
32375
- );
32828
+ const menuProps = getLazyMenuProps(menuDefinition2, menuDefaultProps);
32829
+ if (menuProps) {
32830
+ updater(/* @__PURE__ */ React69.createElement(MenuCmp, { ...menuProps }));
32376
32831
  }
32377
32832
  });
32378
32833
  return /* @__PURE__ */ React69.createElement(AvoidReactDiff, { updater });
32379
32834
  }
32380
32835
 
32381
32836
  // src/components/InfiniteTable/utils/getCellContextMenu.tsx
32382
- function getCellContextMenu(cellLocation, context, onHideIntent) {
32383
- const { columnId, rowIndex, event } = cellLocation;
32384
- const { getComputed, getState } = context;
32385
- const { components: components2, getCellContextMenuItems } = getState();
32386
- const MenuCmp = components2?.Menu ?? Menu;
32387
- const { computedColumnsMap } = getComputed();
32388
- const column = computedColumnsMap.get(columnId);
32389
- const cellContext = {
32390
- ...getCellContext({
32391
- ...context,
32392
- rowIndex,
32393
- columnId: column.id
32394
- }),
32395
- event
32396
- };
32397
- if (!column || !getCellContextMenuItems) {
32398
- return {
32399
- cellContext,
32400
- menu: null,
32401
- preventDefault: false
32402
- };
32403
- }
32404
- const menuDefaultProps = getMenuDefaultProps({
32405
- onHideIntent
32406
- });
32407
- const menuDefinition = getCellContextMenuItems(cellContext, context);
32408
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32409
- if (menuDefinition instanceof Promise) {
32410
- return {
32411
- cellContext,
32412
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32413
- preventDefault
32414
- };
32415
- }
32416
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32417
- if (!items || !items.length) {
32418
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32419
- }
32837
+ function getContextMenuBinder(context) {
32838
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32420
32839
  return {
32421
- preventDefault,
32422
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32423
- cellContext
32840
+ renderMenu: (props) => /* @__PURE__ */ React70.createElement(MenuCmp, { ...props }),
32841
+ renderLazyMenu: (menuDefinition, menuDefaultProps) => getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp)
32424
32842
  };
32425
32843
  }
32844
+ function getCellContextMenu(cellLocation, context, onHideIntent) {
32845
+ return getCellContextMenuContent(
32846
+ cellLocation,
32847
+ context,
32848
+ onHideIntent,
32849
+ getContextMenuBinder(context)
32850
+ );
32851
+ }
32426
32852
  function getTableContextMenu(menuLocation, context, onHideIntent) {
32427
- const { getState, getComputed } = context;
32428
- const { components: components2, getContextMenuItems } = getState();
32429
- const MenuCmp = components2?.Menu ?? Menu;
32430
- const { computedColumnsMap } = getComputed();
32431
- const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32432
- const cellContext = column ? {
32433
- ...menuLocation,
32434
- ...getCellContext({
32435
- ...context,
32436
- rowIndex: menuLocation.rowIndex,
32437
- columnId: column.id
32438
- })
32439
- } : menuLocation;
32440
- if (!getContextMenuItems) {
32441
- return { cellContext, menu: null, preventDefault: false };
32442
- }
32443
- const menuDefaultProps = getMenuDefaultProps({
32444
- onHideIntent
32445
- });
32446
- const menuDefinition = getContextMenuItems(cellContext, context);
32447
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32448
- if (menuDefinition instanceof Promise) {
32449
- return {
32450
- cellContext,
32451
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32452
- preventDefault
32453
- };
32454
- }
32455
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32456
- if (!items || !items.length) {
32457
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32458
- }
32459
- return {
32460
- preventDefault,
32461
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32462
- cellContext
32463
- };
32853
+ return getTableContextMenuContent(
32854
+ menuLocation,
32855
+ context,
32856
+ onHideIntent,
32857
+ getContextMenuBinder(context)
32858
+ );
32464
32859
  }
32465
32860
 
32466
32861
  // src/components/InfiniteTable/hooks/useContextMenu.ts
32467
- var OFFSET3 = 5;
32468
- var ALIGN_POSITIONS = [
32469
- ["TopLeft", "BottomLeft"],
32470
- ["TopRight", "BottomRight"],
32471
- ["BottomLeft", "BottomLeft"],
32472
- ["BottomRight", "BottomRight"],
32473
- ["TopCenter", "TopLeft"],
32474
- ["BottomCenter", "TopLeft"],
32475
- ["CenterLeft", "TopLeft"],
32476
- ["CenterRight", "TopLeft"]
32477
- ];
32478
32862
  function useCellContextMenu() {
32479
32863
  const context = useInfiniteTableStableContext();
32480
32864
  const { getState, actions } = context;
@@ -32486,78 +32870,22 @@ function useCellContextMenu() {
32486
32870
  portalContainer: useMenuPortalContainer()
32487
32871
  });
32488
32872
  useEffect35(() => {
32489
- const { actions: actions2, getState: getState2, getDataSourceState } = context;
32490
- const state = getState2();
32491
- return state.cellContextMenu.onChange((info) => {
32492
- if (!info) {
32493
- return;
32494
- }
32495
- const { event } = info;
32496
- function onHideIntent() {
32497
- clearAll();
32498
- actions2.cellContextMenuVisibleFor = null;
32499
- }
32500
- const { menu, cellContext, preventDefault } = getCellContextMenu(
32501
- info,
32502
- context,
32503
- onHideIntent
32504
- );
32505
- const rect = Rectangle.fromPoint({
32506
- top: event.clientY,
32507
- left: event.clientX
32508
- });
32509
- rect.width += OFFSET3;
32510
- rect.height += OFFSET3;
32511
- showOverlay(menu, {
32512
- constrainTo: getMenuConstrainTo(getState2()),
32513
- id: "cell-context-menu",
32514
- alignTo: rect,
32515
- alignPosition: ALIGN_POSITIONS
32516
- });
32517
- if (preventDefault) {
32518
- event.preventDefault();
32519
- }
32520
- actions2.cellContextMenuVisibleFor = {
32521
- columnId: info.columnId,
32522
- rowId: info.rowId,
32523
- rowIndex: info.rowIndex,
32524
- colIndex: info.colIndex
32525
- };
32526
- const { onCellContextMenu } = getState2();
32527
- if (onCellContextMenu) {
32528
- onCellContextMenu(
32529
- {
32530
- ...cellContext,
32531
- getState: getState2,
32532
- getDataSourceState
32533
- },
32534
- event
32535
- );
32536
- }
32537
- });
32873
+ return getState().cellContextMenu.onChange(
32874
+ getCellContextMenuHandler(context, {
32875
+ clearAll,
32876
+ getContent: (info, onHideIntent) => getCellContextMenu(info, context, onHideIntent),
32877
+ show: ({ menu }, params) => showOverlay(menu, params)
32878
+ })
32879
+ );
32538
32880
  }, []);
32539
32881
  useEffect35(() => {
32540
- const { cellContextMenuVisibleFor } = getState();
32541
- if (cellContextMenuVisibleFor) {
32542
- let handleMouseDown2 = function(event) {
32543
- if (event.__insideMenu !== true) {
32544
- clearAll();
32545
- actions.cellContextMenuVisibleFor = null;
32546
- }
32547
- };
32548
- var handleMouseDown = handleMouseDown2;
32549
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32550
- return () => {
32551
- document.documentElement.removeEventListener(
32552
- "mousedown",
32553
- handleMouseDown2
32554
- );
32555
- };
32556
- } else {
32557
- clearAll();
32558
- }
32559
- return () => {
32560
- };
32882
+ return menuVisibilityEffect(
32883
+ getState().cellContextMenuVisibleFor,
32884
+ clearAll,
32885
+ () => {
32886
+ actions.cellContextMenuVisibleFor = null;
32887
+ }
32888
+ );
32561
32889
  }, [getState().cellContextMenuVisibleFor]);
32562
32890
  return { menuPortal };
32563
32891
  }
@@ -32572,76 +32900,22 @@ function useTableContextMenu() {
32572
32900
  portalContainer: useMenuPortalContainer()
32573
32901
  });
32574
32902
  useEffect35(() => {
32575
- const { actions: actions2, getState: getState2 } = context;
32576
- const state = getState2();
32577
- return state.contextMenu.onChange((info) => {
32578
- if (!info) {
32579
- return;
32580
- }
32581
- const { event } = info;
32582
- function onHideIntent() {
32583
- clearAll();
32584
- actions2.contextMenuVisibleFor = null;
32585
- }
32586
- const { menu, cellContext, preventDefault } = getTableContextMenu(
32587
- info,
32588
- context,
32589
- onHideIntent
32590
- );
32591
- const point = {
32592
- top: event.clientY,
32593
- left: event.clientX
32594
- };
32595
- const rect = Rectangle.fromPoint(point);
32596
- rect.width += OFFSET3;
32597
- rect.height += OFFSET3;
32598
- showOverlay(menu, {
32599
- constrainTo: getMenuConstrainTo(getState2()),
32600
- id: "table-context-menu",
32601
- alignTo: rect,
32602
- alignPosition: ALIGN_POSITIONS
32603
- });
32604
- if (preventDefault) {
32605
- event.preventDefault();
32606
- }
32607
- actions2.contextMenuVisibleFor = {
32608
- point,
32609
- ...info
32610
- };
32611
- const { onContextMenu } = getState2();
32612
- if (onContextMenu) {
32613
- onContextMenu(
32614
- {
32615
- ...context,
32616
- ...cellContext
32617
- },
32618
- event
32619
- );
32620
- }
32621
- });
32903
+ return getState().contextMenu.onChange(
32904
+ getTableContextMenuHandler(context, {
32905
+ clearAll,
32906
+ getContent: (info, onHideIntent) => getTableContextMenu(info, context, onHideIntent),
32907
+ show: ({ menu }, params) => showOverlay(menu, params)
32908
+ })
32909
+ );
32622
32910
  }, []);
32623
32911
  useEffect35(() => {
32624
- const { contextMenuVisibleFor } = getState();
32625
- if (contextMenuVisibleFor) {
32626
- let handleMouseDown2 = function(event) {
32627
- if (event.__insideMenu !== true) {
32628
- clearAll();
32629
- actions.contextMenuVisibleFor = null;
32630
- }
32631
- };
32632
- var handleMouseDown = handleMouseDown2;
32633
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32634
- return () => {
32635
- document.documentElement.removeEventListener(
32636
- "mousedown",
32637
- handleMouseDown2
32638
- );
32639
- };
32640
- } else {
32641
- clearAll();
32642
- }
32643
- return () => {
32644
- };
32912
+ return menuVisibilityEffect(
32913
+ getState().contextMenuVisibleFor,
32914
+ clearAll,
32915
+ () => {
32916
+ actions.contextMenuVisibleFor = null;
32917
+ }
32918
+ );
32645
32919
  }, [getState().contextMenuVisibleFor]);
32646
32920
  return { menuPortal };
32647
32921
  }