@infinite-table/infinite-react 10.2.1 → 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,
@@ -23111,6 +23160,9 @@ function deepEqual(a, b) {
23111
23160
  if (a === b) return true;
23112
23161
  if (a == null || b == null) return a === b;
23113
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
+ }
23114
23166
  if (Array.isArray(a) && Array.isArray(b)) {
23115
23167
  if (a.length !== b.length) return false;
23116
23168
  for (let i = 0, len = a.length; i < len; i++) {
@@ -29548,8 +29600,8 @@ function getLicenseStatus(licenseKey = "", options) {
29548
29600
  return "valid";
29549
29601
  }
29550
29602
  const result = checkLicense(licenseKey, {
29551
- publishedAt: 1795523603652,
29552
- version: "10.2.1"
29603
+ publishedAt: 1795695384921,
29604
+ version: "11.0.0"
29553
29605
  });
29554
29606
  if (result === "invalid" && !licenseKey) {
29555
29607
  return "missing";
@@ -30858,6 +30910,14 @@ import {
30858
30910
  useState as useState23
30859
30911
  } from "react";
30860
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
+
30861
30921
  // src/components/Menu/menuDomUtils.ts
30862
30922
  function getMenuItemRect(menuId, itemKey) {
30863
30923
  const cells = getMenuItemNodes(menuId, itemKey);
@@ -30899,6 +30959,180 @@ function getFirstCheckBoxInsideMenuItem(menuId, itemKey) {
30899
30959
  return null;
30900
30960
  }
30901
30961
 
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);
30981
+ }
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) {
31039
+ return;
31040
+ }
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) {
31051
+ return;
31052
+ }
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
+
30902
31136
  // src/utils/pageGeometry/Triangle.ts
30903
31137
  var Triangle = class extends ConvexPoly {
30904
31138
  // uncommenting this here breaks our tests - WHAT????
@@ -31115,12 +31349,150 @@ var MenuTriangleContext = class {
31115
31349
  }
31116
31350
  };
31117
31351
 
31118
- // src/components/Menu/MenuContext.ts
31119
- import { createContext as createContext11, useContext as useContext12 } from "react";
31120
- var MenuContext = createContext11(null);
31121
- function useMenuContext() {
31122
- const contextValue = useContext12(MenuContext);
31123
- return contextValue;
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;
31124
31496
  }
31125
31497
 
31126
31498
  // src/components/hooks/useMounted.ts
@@ -31139,84 +31511,29 @@ function useMounted() {
31139
31511
 
31140
31512
  // src/components/Menu/Menu.tsx
31141
31513
  function renderSubmenuForItem(item, config) {
31142
- const {
31143
- parentMenuId,
31144
- setSubmenuApi,
31145
- setActiveItemKey,
31146
- setKeyboardActiveItemKey,
31147
- constrainTo,
31148
- onHideIntent,
31149
- api
31150
- } = config;
31151
- const overlayId = `${parentMenuId}-submenu`;
31152
- let itemMenu = item.menu;
31153
- if (!itemMenu) {
31514
+ const overlayId = `${config.parentMenuId}-submenu`;
31515
+ const submenuProps = getSubmenuProps(item, config);
31516
+ if (!submenuProps) {
31154
31517
  return null;
31155
31518
  }
31156
- if (typeof itemMenu === "function") {
31157
- itemMenu = itemMenu();
31158
- }
31159
- return /* @__PURE__ */ React61.createElement(
31160
- Menu,
31161
- {
31162
- key: overlayId,
31163
- parentMenuItemKey: item.key,
31164
- parentMenuId,
31165
- constrainTo,
31166
- ...itemMenu,
31167
- autoFocus: false,
31168
- onShow: (state, api2) => {
31169
- itemMenu?.onShow?.(state, api2);
31170
- setSubmenuApi(api2);
31171
- },
31172
- onHideIntent: (state) => {
31173
- itemMenu?.onHideIntent?.(state);
31174
- onHideIntent(state);
31175
- },
31176
- onHide: (state) => {
31177
- if (state.focused) {
31178
- setActiveItemKey(null);
31179
- setKeyboardActiveItemKey(item.key);
31180
- api.focus();
31181
- }
31182
- }
31183
- }
31184
- );
31519
+ return /* @__PURE__ */ React61.createElement(Menu, { key: overlayId, ...submenuProps });
31185
31520
  }
31186
31521
  function useSubmenus({
31187
31522
  onItemActivate
31188
31523
  }) {
31189
31524
  const { getState } = useMenuContext();
31190
- const [{ onItemEnter, onItemLeave }] = useState23(() => {
31191
- return new MenuTriangleContext({
31192
- parentMenuId: getState().parentMenuId,
31193
- onItemActivate: (itemKey) => {
31194
- if (!itemKey) {
31195
- onItemActivate(null);
31196
- return;
31197
- }
31198
- const item = getState().runtimeItems.filter(
31199
- (item2) => item2.type === "item" && item2.key === itemKey
31200
- )[0];
31201
- onItemActivate(item);
31202
- },
31203
- itemHasSubMenu: (itemKey) => {
31204
- const item = getState().runtimeItems.filter(
31205
- (item2) => item2.type === "item" && item2.key === itemKey && item2.menu
31206
- )[0];
31207
- return !!item;
31208
- },
31209
- getMenuRectFor: (itemKey) => {
31210
- const selector2 = `[data-submenu-for="${itemKey}"]`;
31211
- const menuNode = document.querySelector(selector2);
31212
- if (!menuNode) {
31213
- return void 0;
31214
- }
31215
- const rect = Rectangle.from(menuNode.getBoundingClientRect());
31216
- return rect;
31525
+ const [{ onItemEnter, onItemLeave }] = useState23(
31526
+ () => createMenuTriangleHandlers(getState, (itemKey) => {
31527
+ if (!itemKey) {
31528
+ onItemActivate(null);
31529
+ return;
31217
31530
  }
31218
- }).getHandlers();
31219
- });
31531
+ const item = getState().runtimeItems.filter(
31532
+ (item2) => item2.type === "item" && item2.key === itemKey
31533
+ )[0];
31534
+ onItemActivate(item);
31535
+ })
31536
+ );
31220
31537
  return {
31221
31538
  onItemEnter: useCallback30(onItemEnter, []),
31222
31539
  onItemLeave: useCallback30(onItemLeave, [])
@@ -31225,6 +31542,7 @@ function useSubmenus({
31225
31542
  function MenuComponent(props) {
31226
31543
  const { domProps } = props;
31227
31544
  const {
31545
+ componentState,
31228
31546
  componentState: {
31229
31547
  columns,
31230
31548
  runtimeItems,
@@ -31233,8 +31551,6 @@ function MenuComponent(props) {
31233
31551
  keyboardActiveItemKey,
31234
31552
  constrainTo,
31235
31553
  destroyed,
31236
- onAction,
31237
- wrapLabels,
31238
31554
  onShow,
31239
31555
  onHide,
31240
31556
  autoFocus,
@@ -31252,62 +31568,56 @@ function MenuComponent(props) {
31252
31568
  }, []);
31253
31569
  const isMounted = useMounted();
31254
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
+ });
31255
31587
  let renderedChildren = null;
31256
31588
  useLayoutEffect17(() => {
31257
31589
  const { runtimeItems: runtimeItems2 } = getState();
31258
- const activeItem = runtimeItems2.filter(
31259
- (item) => item.type === "item" && activeItemKey === item.key
31260
- )[0];
31261
- if (!activeItem || !activeItem.menu) {
31590
+ const activeItem = getActiveSubmenuItem(runtimeItems2, activeItemKey);
31591
+ if (!activeItem) {
31262
31592
  setSubmenuApi(null);
31263
31593
  clearAll();
31264
31594
  return;
31265
31595
  }
31266
- if (activeItem) {
31267
- const alignTo = getMenuItemRect(menuId, activeItem.key);
31268
- const menu = () => renderSubmenuForItem(activeItem, {
31269
- constrainTo,
31270
- setSubmenuApi,
31271
- setActiveItemKey,
31272
- setKeyboardActiveItemKey,
31273
- parentMenuId: menuId,
31274
- onHideIntent: hideAll,
31275
- api
31276
- });
31277
- if (alignTo) {
31278
- showOverlay(menu, {
31279
- id: `${menuId}-submenu`,
31280
- alignTo,
31281
- alignPosition: [
31282
- ["TopLeft", "TopRight"],
31283
- ["TopRight", "TopLeft"]
31284
- ],
31285
- constrainTo
31286
- });
31287
- }
31288
- return;
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);
31289
31612
  }
31290
31613
  }, [activeItemKey]);
31291
31614
  const onItemClick = (event, item) => {
31292
- setKeyboardActiveItemKey(item.key);
31293
- setActiveItemKey(item.key);
31294
- if (item.originalMenuItem.onClick) {
31295
- item.originalMenuItem.onClick(event);
31296
- }
31297
- const onActionParam = {
31298
- key: item.key,
31299
- item: item.originalMenuItem,
31300
- hideMenu: hideAll
31301
- };
31302
- if (item.originalMenuItem.onAction) {
31303
- item.originalMenuItem.onAction(onActionParam);
31304
- }
31305
- if (onAction) {
31306
- onAction(onActionParam);
31307
- }
31308
- if (item.originalMenuItem.hideMenuOnAction) {
31309
- hideAll();
31310
- }
31615
+ runMenuItemClick(event, item, {
31616
+ getState,
31617
+ setActiveItemKey,
31618
+ setKeyboardActiveItemKey,
31619
+ hideAll
31620
+ });
31311
31621
  };
31312
31622
  const {
31313
31623
  showOverlay,
@@ -31345,158 +31655,27 @@ function MenuComponent(props) {
31345
31655
  onClick: onItemClick
31346
31656
  }
31347
31657
  ));
31348
- const gridTemplateColumns = columns.map((col) => {
31349
- return col.width || (typeof col.flex === "number" ? `${col.flex}fr` : col.flex) || "auto";
31350
- }).join(" ");
31351
- const style2 = {
31352
- ...domProps.style,
31353
- gridTemplateColumns,
31354
- gridTemplateRows: runtimeItems.map(() => `auto`).join(" ")
31355
- };
31356
- if (!wrapLabels) {
31357
- style2.whiteSpace = "nowrap";
31358
- }
31658
+ const style2 = getMenuGridStyle(
31659
+ componentState,
31660
+ domProps.style
31661
+ );
31359
31662
  function handleKeydown(keyboardEvent) {
31360
- const { runtimeItems: runtimeItems2, runtimeSelectableItems } = getState();
31361
- let keyboardActiveIndex = runtimeItems2.findIndex(
31362
- (runtimeItem) => runtimeItem.type === "item" && runtimeItem.key === keyboardActiveItemKey
31363
- );
31364
- let newKeyboardActiveItemKey = keyboardActiveItemKey;
31365
- const keyboardActiveItem = runtimeItems2[keyboardActiveIndex];
31366
- const validKeys3 = {
31367
- ArrowUp: () => {
31368
- const newActiveItem = runtimeItems2.slice(0, keyboardActiveIndex).filter((item) => item.type === "item" && !item.disabled).pop();
31369
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31370
- newKeyboardActiveItemKey = newActiveItem.key;
31371
- }
31372
- },
31373
- ArrowDown: () => {
31374
- const newActiveItem = runtimeItems2.slice(keyboardActiveIndex + 1).filter((item) => item.type === "item" && !item.disabled)[0];
31375
- if (newActiveItem && newActiveItem.type === "item" && newActiveItem.key) {
31376
- newKeyboardActiveItemKey = newActiveItem.key;
31377
- }
31378
- },
31379
- Home: () => {
31380
- validKeys3.PageUp();
31381
- },
31382
- End: () => {
31383
- validKeys3.PageDown();
31384
- },
31385
- PageUp: () => {
31386
- newKeyboardActiveItemKey = runtimeSelectableItems[0].key;
31387
- },
31388
- PageDown: () => {
31389
- newKeyboardActiveItemKey = runtimeSelectableItems[runtimeSelectableItems.length - 1].key;
31390
- },
31391
- ArrowLeft: () => {
31392
- setActiveItemKey(null);
31393
- if (getState().parentMenuId) {
31394
- componentActions.destroyed = true;
31395
- }
31396
- },
31397
- ArrowRight: () => {
31398
- if (!keyboardActiveItem) {
31399
- return;
31400
- }
31401
- setActiveItemKey(keyboardActiveItem.key);
31402
- raf(() => {
31403
- if (isMounted() && submenuApi && submenuApi.getParentMenuId() === getState().menuId) {
31404
- submenuApi.focus();
31405
- }
31406
- });
31407
- },
31408
- Enter: () => {
31409
- if (!keyboardActiveItem) {
31410
- return;
31411
- }
31412
- if (keyboardActiveItem.originalMenuItem?.menu) {
31413
- if (keyboardActiveItem && keyboardActiveItem.originalMenuItem.menu && submenuApi) {
31414
- validKeys3.ArrowLeft();
31415
- return;
31416
- }
31417
- if (keyboardActiveItem) {
31418
- setActiveItemKey(keyboardActiveItem.key);
31419
- }
31420
- } else {
31421
- onItemClick(
31422
- keyboardEvent,
31423
- keyboardActiveItem
31424
- );
31425
- }
31426
- },
31427
- " ": () => {
31428
- if (!keyboardActiveItem) {
31429
- return;
31430
- }
31431
- if (!keyboardActiveItem.originalMenuItem.menu) {
31432
- onItemClick(
31433
- keyboardEvent,
31434
- keyboardActiveItem
31435
- );
31436
- }
31437
- const checkbox = getFirstCheckBoxInsideMenuItem(
31438
- menuId,
31439
- keyboardActiveItem.key
31440
- );
31441
- if (!checkbox) {
31442
- return;
31443
- }
31444
- checkbox.click();
31663
+ handleMenuKeyDown(keyboardEvent, {
31664
+ getState,
31665
+ setActiveItemKey,
31666
+ setKeyboardActiveItemKey,
31667
+ destroy: () => {
31668
+ componentActions.destroyed = true;
31445
31669
  },
31446
- Escape: () => {
31447
- validKeys3.ArrowLeft();
31448
- const state = getState();
31449
- if (!state.parentMenuId) {
31450
- state.onHideIntent?.(state);
31451
- }
31452
- }
31453
- };
31454
- const fn = validKeys3[keyboardEvent.key];
31455
- if (fn) {
31456
- fn();
31457
- keyboardEvent.preventDefault();
31458
- }
31459
- if (newKeyboardActiveItemKey != keyboardActiveItemKey) {
31460
- setKeyboardActiveItemKey(newKeyboardActiveItemKey);
31461
- }
31670
+ // the submenu api of this render: the raf of ArrowRight reads it
31671
+ getSubmenuApi: () => submenuApi,
31672
+ isMounted,
31673
+ onItemClick
31674
+ });
31462
31675
  }
31463
31676
  function onMenuBlur() {
31464
31677
  componentActions.focused = false;
31465
31678
  }
31466
- const onMenuFocus = useCallback30(function() {
31467
- componentActions.focused = true;
31468
- setTimeout(() => {
31469
- if (shouldSelectFirstItemOnFocus.current && domRef.current && domRef.current === document.activeElement && getState().keyboardActiveItemKey == null) {
31470
- setKeyboardActiveItemKey(
31471
- getState().runtimeSelectableItems[0]?.key ?? null
31472
- );
31473
- }
31474
- });
31475
- }, []);
31476
- const shouldSelectFirstItemOnFocus = useRef30(true);
31477
- const hideAll = useCallback30(() => {
31478
- const state = getState();
31479
- state.onHideIntent?.(state);
31480
- }, [getState]);
31481
- const [api] = useState23(() => {
31482
- const result2 = {
31483
- hideMenu: hideAll,
31484
- focus: () => {
31485
- if (domRef.current) {
31486
- domRef.current.focus();
31487
- setTimeout(() => {
31488
- if (domRef.current && domRef.current !== document.activeElement) {
31489
- domRef.current.focus();
31490
- }
31491
- }, 10);
31492
- onMenuFocus();
31493
- }
31494
- },
31495
- getMenuId: () => getState().menuId,
31496
- getParentMenuId: () => getState().parentMenuId
31497
- };
31498
- return result2;
31499
- });
31500
31679
  const refCallback = useCallback30((node) => {
31501
31680
  if (node) {
31502
31681
  domRef.current = node;
@@ -31541,44 +31720,20 @@ function MenuComponent(props) {
31541
31720
  function RuntimeItemRenderer(props) {
31542
31721
  const [pressed, setPressed] = React61.useState(false);
31543
31722
  const { columns, item, index, active, keyboardActive } = props;
31544
- const key = item.type === "item" ? item.value.key : index;
31545
31723
  let content = null;
31546
31724
  if (item.type === "decoration") {
31547
31725
  content = /* @__PURE__ */ React61.createElement("div", { style: item.style }, item.value);
31548
31726
  } else {
31549
- let spanIndex = 0;
31550
- content = columns.map((col, i) => {
31551
- const target = item.value;
31552
- const field = col.field || col.name;
31553
- const start = i + 1;
31554
- const end = start + item.span;
31555
- if (start < spanIndex) {
31556
- return null;
31557
- }
31558
- spanIndex = end;
31559
- const style2 = {
31560
- ...col.style,
31561
- ...item.style,
31562
- gridColumnStart: start,
31563
- gridColumnEnd: end
31564
- };
31727
+ content = getMenuItemCells(item, columns, index, {
31728
+ active,
31729
+ keyboardActive,
31730
+ pressed
31731
+ }).map((cell) => {
31732
+ const col = cell.column;
31565
31733
  const domProps = {
31566
- style: style2,
31567
- //@ts-ignore
31568
- "data-menu-column-id": `${item.parentMenuId}-col-${col.name}`,
31569
- "data-menu-col-name": `${col.name}`,
31570
- "data-menu-row-id": `${item.parentMenuId}-row-${index}`,
31571
- "data-menu-row-index": `${index}`,
31572
- "data-menu-item-key": `${item.key}`,
31573
- className: join(
31574
- MenuItemCls({
31575
- active,
31576
- disabled: !!item.disabled,
31577
- keyboardActive,
31578
- pressed: pressed || props.active
31579
- }),
31580
- item.className
31581
- ),
31734
+ style: cell.style,
31735
+ ...cell.dataAttributes,
31736
+ className: cell.className,
31582
31737
  onPointerEnter: (event) => {
31583
31738
  if (!item.disabled) {
31584
31739
  props.onItemEnter?.(item, event);
@@ -31608,17 +31763,17 @@ function RuntimeItemRenderer(props) {
31608
31763
  return col.render ? /* @__PURE__ */ React61.createElement(
31609
31764
  RenderHookComponent,
31610
31765
  {
31611
- key: `${key}-${field}`,
31766
+ key: cell.key,
31612
31767
  render: col.render,
31613
31768
  renderParam: {
31614
- item: target,
31769
+ item: item.value,
31615
31770
  column: col,
31616
- value: target[field],
31771
+ value: cell.value,
31617
31772
  domProps
31618
31773
  }
31619
31774
  }
31620
- ) : /* @__PURE__ */ React61.createElement("div", { key: `${key}-${field}`, ...domProps }, target[field]);
31621
- }).filter(Boolean);
31775
+ ) : /* @__PURE__ */ React61.createElement("div", { key: cell.key, ...domProps }, cell.value);
31776
+ });
31622
31777
  }
31623
31778
  return /* @__PURE__ */ React61.createElement("div", { className: MenuRowCls }, content);
31624
31779
  }
@@ -31683,9 +31838,64 @@ Menu[propToIdentifyMenu] = true;
31683
31838
 
31684
31839
  // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
31685
31840
  import * as React63 from "react";
31686
- function defaultGetColumnMenuItems(_items, params) {
31687
- const { columnApi, column, getComputed, api, dataSourceApi, getState } = params;
31688
- const CheckBoxCmp = getState().components?.CheckBox || InfiniteCheckBox;
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;
31689
31899
  const sortable = columnApi.isSortable();
31690
31900
  const sortItems = sortable ? [
31691
31901
  {
@@ -31766,25 +31976,22 @@ function defaultGetColumnMenuItems(_items, params) {
31766
31976
  const colItems = [];
31767
31977
  const computed = getComputed();
31768
31978
  computed.computedColumnsMapInInitialOrder.forEach((col, id) => {
31769
- const label = getColumnLabel(col, params, "column-menu");
31979
+ const label = binder.getColumnLabel(col);
31770
31980
  colItems.push({
31771
31981
  key: id,
31772
31982
  label,
31773
- check: /* @__PURE__ */ React63.createElement(
31774
- CheckBoxCmp,
31775
- {
31776
- key: col.id,
31777
- disabled: col.computedVisible && api.getVisibleColumnsCount() === 1,
31778
- checked: col.computedVisible,
31779
- onChange: (checked) => {
31780
- const visible = !!checked;
31781
- api.setVisibilityForColumn(col.id, visible);
31782
- requestAnimationFrame(() => {
31783
- api.realignColumnContextMenu();
31784
- });
31785
- }
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
+ });
31786
31993
  }
31787
- )
31994
+ })
31788
31995
  });
31789
31996
  });
31790
31997
  return {
@@ -31809,21 +32016,18 @@ function defaultGetColumnMenuItems(_items, params) {
31809
32016
  if (col.groupByForColumn) {
31810
32017
  return;
31811
32018
  }
31812
- const label = getColumnLabel(col, params, "column-menu");
32019
+ const label = binder.getColumnLabel(col);
31813
32020
  colItems.push({
31814
32021
  key: id,
31815
32022
  label,
31816
- check: /* @__PURE__ */ React63.createElement(
31817
- CheckBoxCmp,
31818
- {
31819
- key: col.id,
31820
- disabled: !col.computedGroupable,
31821
- checked: col.computedGroupedBy,
31822
- onChange: () => {
31823
- dataSourceApi.toggleGroupByField(col.field);
31824
- }
32023
+ check: binder.renderCheckBox({
32024
+ key: col.id,
32025
+ disabled: !col.computedGroupable,
32026
+ checked: col.computedGroupedBy,
32027
+ onChange: () => {
32028
+ dataSourceApi.toggleGroupByField(col.field);
31825
32029
  }
31826
- )
32030
+ })
31827
32031
  });
31828
32032
  });
31829
32033
  return {
@@ -31839,15 +32043,12 @@ function defaultGetColumnMenuItems(_items, params) {
31839
32043
  }
31840
32044
  ].filter((x) => !!x);
31841
32045
  }
31842
-
31843
- // src/components/InfiniteTable/utils/getMenuForColumn.tsx
31844
- function getMenuForColumn(columnId, context, onHideIntent) {
32046
+ function getColumnMenuProps(columnId, context, onHideIntent, getDefaultItems) {
31845
32047
  if (columnId == null) {
31846
32048
  return null;
31847
32049
  }
31848
32050
  const { getComputed, getState } = context;
31849
- const { components: components2, getColumnMenuItems } = getState();
31850
- const MenuCmp = components2?.Menu ?? Menu;
32051
+ const { getColumnMenuItems } = getState();
31851
32052
  const column = getComputed().computedColumnsMap.get(columnId);
31852
32053
  if (!column) {
31853
32054
  return null;
@@ -31857,79 +32058,257 @@ function getMenuForColumn(columnId, context, onHideIntent) {
31857
32058
  columnApi: getColumnApiForColumn(column.id, context),
31858
32059
  ...context
31859
32060
  };
31860
- const defaultItems = defaultGetColumnMenuItems([], param);
32061
+ const defaultItems = getDefaultItems(param);
31861
32062
  const items = getColumnMenuItems ? getColumnMenuItems(defaultItems, param) : defaultItems;
31862
- const onRootMouseDown = (event) => {
31863
- event.__insideMenu = true;
31864
- };
31865
- const onHide = (state) => {
31866
- state.domRef.current?.parentNode?.removeEventListener(
31867
- "mousedown",
31868
- onRootMouseDown
31869
- );
31870
- };
31871
32063
  if (!items || !items.length) {
31872
32064
  return null;
31873
32065
  }
31874
- return /* @__PURE__ */ React64.createElement(
31875
- MenuCmp,
31876
- {
31877
- autoFocus: true,
31878
- items,
31879
- onShow: (state) => {
31880
- state.domRef.current?.parentNode?.addEventListener(
31881
- "mousedown",
31882
- onRootMouseDown
31883
- );
31884
- },
31885
- onHide,
31886
- onHideIntent: (state) => {
31887
- onHide(state);
31888
- onHideIntent?.();
31889
- }
31890
- }
31891
- );
31892
- }
31893
-
31894
- // src/components/InfiniteTable/utils/menuOverlayTargets.ts
31895
- function resolveMenuElement(element) {
31896
- return typeof element === "function" ? element() : element;
31897
- }
31898
- function getMenuConstrainTo(state) {
31899
- return resolveMenuElement(state.menuConstrainTo) ?? state.domRef.current;
32066
+ return {
32067
+ autoFocus: true,
32068
+ items,
32069
+ ...getMenuVisibilityProps(onHideIntent)
32070
+ };
31900
32071
  }
31901
- function getMenuPortalContainer(getState, menuPortalContainer, defaultContainer) {
31902
- if (!menuPortalContainer) {
31903
- return defaultContainer || false;
32072
+ function getFilterOperatorMenuProps(columnId, context, onHideIntent, binder) {
32073
+ if (columnId == null) {
32074
+ return null;
31904
32075
  }
31905
- return () => resolveMenuElement(menuPortalContainer) ?? (defaultContainer || getState().portalDOMRef.current);
31906
- }
31907
-
31908
- // src/components/InfiniteTable/hooks/useMenuPortalContainer.ts
31909
- import { useMemo as useMemo19 } from "react";
31910
- function useMenuPortalContainer() {
31911
- const { getState, menuPortalContainer } = useInfiniteTableSelector((ctx) => {
32076
+ const {
32077
+ getComputed,
32078
+ getState,
32079
+ getDataSourceState,
32080
+ actions,
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;
31912
32098
  return {
31913
- getState: ctx.getState,
31914
- menuPortalContainer: ctx.state.menuPortalContainer
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
31915
32106
  };
31916
32107
  });
31917
- const { portalDOMRef } = useDataSourceMasterDetailSelector((ctx) => {
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) {
31918
32158
  return {
31919
- portalDOMRef: ctx.getMasterState().portalDOMRef
32159
+ menu: binder.renderLazyMenu(menuDefinition, menuDefaultProps),
32160
+ preventDefault
31920
32161
  };
31921
- }) || {};
31922
- const defaultContainer = portalDOMRef?.current;
31923
- return useMemo19(
31924
- () => getMenuPortalContainer(getState, menuPortalContainer, defaultContainer),
31925
- [getState, menuPortalContainer, defaultContainer]
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)
31926
32245
  );
32246
+ return menuProps ? /* @__PURE__ */ React64.createElement(MenuCmp, { ...menuProps }) : null;
31927
32247
  }
31928
32248
 
31929
- // src/components/InfiniteTable/hooks/useColumnMenu.ts
31930
- var menuIconSelector2 = `[${MenuIconDataAttributes["data-name"]}="${MenuIconDataAttributesValues["data-name"]}"]`;
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
+ }
31931
32310
  function showMenuForColumn(options) {
31932
- const { columnId, context, clearAll, showOverlay } = options;
32311
+ const { columnId, context, clearAll, show } = options;
31933
32312
  const { getState, actions } = context;
31934
32313
  const { columnMenuTargetRef, domRef } = getState();
31935
32314
  function onHideIntent() {
@@ -31944,7 +32323,7 @@ function showMenuForColumn(options) {
31944
32323
  }
31945
32324
  }
31946
32325
  if (!target) {
31947
- const iconSelector = `[${InfiniteHeaderCellDataAttributes["data-column-id"]}="${columnId}"] ${menuIconSelector2}`;
32326
+ const iconSelector = `[data-column-id="${columnId}"] ${menuIconSelector}`;
31948
32327
  target = getState().domRef.current.querySelector(
31949
32328
  iconSelector
31950
32329
  );
@@ -31954,7 +32333,7 @@ function showMenuForColumn(options) {
31954
32333
  return;
31955
32334
  }
31956
32335
  columnMenuTargetRef.current = null;
31957
- showOverlay(() => getMenuForColumn(columnId, context, onHideIntent), {
32336
+ show(onHideIntent, {
31958
32337
  constrainTo: getMenuConstrainTo(getState()),
31959
32338
  id: "column-menu",
31960
32339
  alignTo: target,
@@ -31964,17 +32343,180 @@ function showMenuForColumn(options) {
31964
32343
  ]
31965
32344
  });
31966
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) => {
32498
+ return {
32499
+ getState: ctx.getState,
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
31967
32516
  function useColumnMenu() {
31968
32517
  const context = useInfiniteTableStableContext();
31969
- const {
31970
- getState,
31971
- actions,
31972
- columnMenuVisibleForColumnId,
31973
- columnMenuVisibleKey
31974
- } = useInfiniteTableSelector((ctx) => {
32518
+ const { columnMenuVisibleForColumnId, columnMenuVisibleKey } = useInfiniteTableSelector((ctx) => {
31975
32519
  return {
31976
- getState: ctx.getState,
31977
- actions: ctx.actions,
31978
32520
  columnMenuVisibleForColumnId: ctx.state.columnMenuVisibleForColumnId,
31979
32521
  columnMenuVisibleKey: ctx.state.columnMenuVisibleKey
31980
32522
  };
@@ -31987,47 +32529,16 @@ function useColumnMenu() {
31987
32529
  portalContainer: useMenuPortalContainer()
31988
32530
  });
31989
32531
  useEffect32(() => {
31990
- const state = getState();
31991
- return state.onColumnMenuClick.onChange((info) => {
31992
- if (!info) {
31993
- return;
31994
- }
31995
- state.columnMenuTargetRef.current = info.target;
31996
- actions.contextMenuVisibleFor = null;
31997
- actions.cellContextMenuVisibleFor = null;
31998
- actions.filterOperatorMenuVisibleForColumnId = null;
31999
- actions.columnMenuVisibleForColumnId = info.column.id;
32000
- });
32532
+ return context.getState().onColumnMenuClick.onChange(getColumnMenuClickHandler(context));
32001
32533
  }, []);
32002
32534
  useEffect32(() => {
32003
- const { columnMenuVisibleForColumnId: columnMenuVisibleForColumnId2, columnMenuTargetRef } = getState();
32004
- if (columnMenuVisibleForColumnId2) {
32005
- let handleMouseDown2 = function(event) {
32006
- if (event.__insideMenu !== true) {
32007
- clearAll();
32008
- actions.columnMenuVisibleForColumnId = null;
32009
- }
32010
- };
32011
- var handleMouseDown = handleMouseDown2;
32012
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32013
- showMenuForColumn({
32014
- columnId: columnMenuVisibleForColumnId2,
32015
- context,
32016
- clearAll,
32017
- showOverlay
32018
- });
32019
- return () => {
32020
- document.documentElement.removeEventListener(
32021
- "mousedown",
32022
- handleMouseDown2
32023
- );
32024
- };
32025
- } else {
32026
- columnMenuTargetRef.current = null;
32027
- clearAll();
32028
- }
32029
- return () => {
32030
- };
32535
+ return columnMenuVisibilityEffect(context, {
32536
+ clearAll,
32537
+ show: (columnId, onHideIntent, params) => showOverlay(
32538
+ () => getMenuForColumn(columnId, context, onHideIntent),
32539
+ params
32540
+ )
32541
+ });
32031
32542
  }, [columnMenuVisibleForColumnId, columnMenuVisibleKey]);
32032
32543
  return { menuPortal };
32033
32544
  }
@@ -32210,149 +32721,59 @@ function useOnEditPersisted() {
32210
32721
  };
32211
32722
  if (persisted instanceof Error) {
32212
32723
  onEditPersistError?.({ ...params, error: persisted });
32213
- } else {
32214
- onEditPersistSuccess?.(params);
32215
- }
32216
- }
32217
- }, [persisted]);
32218
- }
32219
- function useEditingCallbackProps() {
32220
- useOnEditCancelled();
32221
- useOnEditRejected();
32222
- useOnEditAccepted();
32223
- useOnEditPersisted();
32224
- useFocusOnEditStop();
32225
- }
32226
-
32227
- // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32228
- import { useEffect as useEffect34 } from "react";
32229
-
32230
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32231
- import * as React68 from "react";
32232
-
32233
- // src/components/InfiniteTable/components/icons/ClearIcon.tsx
32234
- import * as React66 from "react";
32235
- var ClearIcon = (props) => {
32236
- return /* @__PURE__ */ React66.createElement(Icon, { ...props, icon: "clear" }, /* @__PURE__ */ React66.createElement("path", { d: iconPaths.clear[0] }));
32237
- };
32238
-
32239
- // src/components/InfiniteTable/components/icons/DoneIcon.tsx
32240
- import * as React67 from "react";
32241
- var DoneIcon = (props) => {
32242
- return /* @__PURE__ */ React67.createElement(Icon, { ...props, icon: "done" }, /* @__PURE__ */ React67.createElement("path", { d: iconPaths.done[0] }));
32243
- };
32244
-
32245
- // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
32246
- function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
32247
- if (columnId == null) {
32248
- return null;
32249
- }
32250
- const {
32251
- getComputed,
32252
- getState,
32253
- getDataSourceState,
32254
- actions,
32255
- dataSourceApi,
32256
- dataSourceActions,
32257
- api
32258
- } = context;
32259
- const { components: components2, getFilterOperatorMenuItems } = getState();
32260
- const MenuCmp = components2?.Menu ?? Menu;
32261
- const column = getComputed().computedColumnsMap.get(columnId);
32262
- if (!column) {
32263
- return null;
32264
- }
32265
- const onRootMouseDown = (event) => {
32266
- event.__insideMenu = true;
32267
- };
32268
- const onHide = (state) => {
32269
- state.domRef.current?.parentNode?.removeEventListener(
32270
- "mousedown",
32271
- onRootMouseDown
32272
- );
32273
- };
32274
- const { filterTypes } = getDataSourceState();
32275
- const columnFilterType = filterTypes[column.computedFilterType];
32276
- if (!columnFilterType) {
32277
- return null;
32278
- }
32279
- const operatorItems = columnFilterType.operators.map((operator) => {
32280
- const key = operator.name;
32281
- const checked = column.computedFilterValue ? column.computedFilterValue.filter.operator === key : key === columnFilterType.defaultOperator;
32282
- const IconCmp = operator.components?.Icon ?? FilterIcon;
32283
- return {
32284
- key,
32285
- icon: /* @__PURE__ */ React68.createElement(IconCmp, null),
32286
- label: /* @__PURE__ */ React68.createElement(React68.Fragment, null, operator.label ?? operator.name),
32287
- onAction: () => {
32288
- api.setColumnFilterOperator(columnId, key);
32289
- },
32290
- checked: checked ? /* @__PURE__ */ React68.createElement(DoneIcon, { size: 16 }) : null
32291
- };
32292
- });
32293
- const firstItems = [
32294
- {
32295
- key: "close",
32296
- label: "Close Menu",
32297
- icon: null,
32298
- onAction: () => {
32299
- api.hideFilterOperatorMenu();
32300
- }
32301
- },
32302
- {
32303
- key: "reset",
32304
- label: "Reset",
32305
- icon: /* @__PURE__ */ React68.createElement(ClearIcon, null),
32306
- disabled: !column.computedFiltered,
32307
- onAction: () => {
32308
- api.clearColumnFilter(columnId);
32309
- }
32310
- },
32311
- "-"
32312
- ];
32313
- const defaultItems = [...firstItems, ...operatorItems];
32314
- const param = {
32315
- column,
32316
- api,
32317
- getState,
32318
- getDataSourceState,
32319
- getComputed,
32320
- actions,
32321
- dataSourceApi,
32322
- dataSourceActions,
32323
- columnFilterValue: column.computedFilterValue,
32324
- filterTypes
32325
- };
32326
- const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
32327
- return /* @__PURE__ */ React68.createElement(
32328
- MenuCmp,
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,
32329
32763
  {
32330
- autoFocus: true,
32331
- columns: [
32332
- {
32333
- name: "icon"
32334
- },
32335
- { name: "label" },
32336
- { name: "checked" }
32337
- ],
32338
- items,
32339
- onShow: (state) => {
32340
- state.domRef.current?.parentNode?.addEventListener(
32341
- "mousedown",
32342
- onRootMouseDown
32343
- );
32764
+ renderOperatorIcon: (operator) => {
32765
+ const IconCmp = operator.components?.Icon ?? FilterIcon;
32766
+ return /* @__PURE__ */ React68.createElement(IconCmp, null);
32344
32767
  },
32345
- onHide,
32346
- onHideIntent: (state) => {
32347
- onHide(state);
32348
- onHideIntent?.();
32349
- }
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 })
32350
32771
  }
32351
32772
  );
32773
+ return menuProps ? /* @__PURE__ */ React68.createElement(MenuCmp, { ...menuProps }) : null;
32352
32774
  }
32353
32775
 
32354
32776
  // src/components/InfiniteTable/hooks/useColumnFilterOperatorMenu.ts
32355
- var OFFSET2 = 10;
32356
32777
  function useColumnFilterOperatorMenu() {
32357
32778
  const stableContext = useInfiniteTableStableContext();
32358
32779
  const { getState, actions } = stableContext;
@@ -32364,66 +32785,28 @@ function useColumnFilterOperatorMenu() {
32364
32785
  portalContainer: useMenuPortalContainer()
32365
32786
  });
32366
32787
  useEffect34(() => {
32367
- const state = getState();
32368
- return state.onFilterOperatorMenuClick.onChange((info) => {
32369
- if (!info) {
32370
- return;
32371
- }
32372
- const { target, column } = info;
32373
- function onHideIntent() {
32374
- clearAll();
32375
- actions.filterOperatorMenuVisibleForColumnId = null;
32376
- }
32377
- let alignTo = target?.parentElement || target;
32378
- const rect = Rectangle.from(alignTo.getBoundingClientRect());
32379
- rect.top -= OFFSET2;
32380
- rect.left -= OFFSET2;
32381
- rect.width += 2 * OFFSET2;
32382
- rect.height += 2 * OFFSET2;
32383
- showOverlay(
32384
- () => getFilterOperatorMenuForColumn(
32385
- column.id,
32386
- stableContext,
32387
- onHideIntent
32388
- ),
32389
- {
32390
- constrainTo: getMenuConstrainTo(getState()),
32391
- id: "filter-operator-menu",
32392
- alignTo: rect,
32393
- alignPosition: [
32394
- ["TopLeft", "BottomLeft"],
32395
- ["TopRight", "BottomRight"]
32396
- ]
32397
- }
32398
- );
32399
- actions.contextMenuVisibleFor = null;
32400
- actions.cellContextMenuVisibleFor = null;
32401
- actions.columnMenuVisibleForColumnId = null;
32402
- actions.filterOperatorMenuVisibleForColumnId = column.id;
32403
- });
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
+ );
32404
32801
  }, []);
32405
32802
  useEffect34(() => {
32406
- const { filterOperatorMenuVisibleForColumnId } = getState();
32407
- if (filterOperatorMenuVisibleForColumnId) {
32408
- let handleMouseDown2 = function(event) {
32409
- if (event.__insideMenu !== true) {
32410
- clearAll();
32411
- actions.filterOperatorMenuVisibleForColumnId = null;
32412
- }
32413
- };
32414
- var handleMouseDown = handleMouseDown2;
32415
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32416
- return () => {
32417
- document.documentElement.removeEventListener(
32418
- "mousedown",
32419
- handleMouseDown2
32420
- );
32421
- };
32422
- } else {
32423
- clearAll();
32424
- }
32425
- return () => {
32426
- };
32803
+ return menuVisibilityEffect(
32804
+ getState().filterOperatorMenuVisibleForColumnId,
32805
+ clearAll,
32806
+ () => {
32807
+ actions.filterOperatorMenuVisibleForColumnId = null;
32808
+ }
32809
+ );
32427
32810
  }, [getState().filterOperatorMenuVisibleForColumnId]);
32428
32811
  return { menuPortal };
32429
32812
  }
@@ -32436,159 +32819,46 @@ import * as React70 from "react";
32436
32819
 
32437
32820
  // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32438
32821
  import * as React69 from "react";
32439
-
32440
- // src/components/InfiniteTable/utils/contextMenuUtilsShared.ts
32441
- function getMenuItemsAndColumns(menuDefinition) {
32442
- let items = menuDefinition ? Array.isArray(menuDefinition) ? menuDefinition : menuDefinition.items : null;
32443
- const columns = menuDefinition && !Array.isArray(menuDefinition) ? menuDefinition.columns : void 0;
32444
- return {
32445
- items,
32446
- columns
32447
- };
32448
- }
32449
- function getMenuDefaultProps(config) {
32450
- const onRootMouseDown = (event) => {
32451
- event.__insideMenu = true;
32452
- };
32453
- const onHide = (state) => {
32454
- state.domRef.current?.parentNode?.removeEventListener(
32455
- "mousedown",
32456
- onRootMouseDown
32457
- );
32458
- };
32459
- const menuDefaultProps = {
32460
- columns: [],
32461
- items: [],
32462
- autoFocus: true,
32463
- onShow: (state) => {
32464
- state.domRef.current?.parentNode?.addEventListener(
32465
- "mousedown",
32466
- onRootMouseDown
32467
- );
32468
- },
32469
- onHide,
32470
- onHideIntent: (state) => {
32471
- onHide(state);
32472
- config.onHideIntent?.();
32473
- }
32474
- };
32475
- return menuDefaultProps;
32476
- }
32477
-
32478
- // src/components/InfiniteTable/utils/contextMenuUtils.tsx
32479
32822
  function getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp) {
32480
32823
  if (!menuDefinition) {
32481
32824
  return null;
32482
32825
  }
32483
32826
  const updater = buildSubscriptionCallback();
32484
32827
  menuDefinition.then((menuDefinition2) => {
32485
- const { items, columns } = getMenuItemsAndColumns(menuDefinition2);
32486
- if (items && items.length) {
32487
- updater(
32488
- /* @__PURE__ */ React69.createElement(MenuCmp, { ...menuDefaultProps, items: items || [], columns })
32489
- );
32828
+ const menuProps = getLazyMenuProps(menuDefinition2, menuDefaultProps);
32829
+ if (menuProps) {
32830
+ updater(/* @__PURE__ */ React69.createElement(MenuCmp, { ...menuProps }));
32490
32831
  }
32491
32832
  });
32492
32833
  return /* @__PURE__ */ React69.createElement(AvoidReactDiff, { updater });
32493
32834
  }
32494
32835
 
32495
32836
  // src/components/InfiniteTable/utils/getCellContextMenu.tsx
32496
- function getCellContextMenu(cellLocation, context, onHideIntent) {
32497
- const { columnId, rowIndex, event } = cellLocation;
32498
- const { getComputed, getState } = context;
32499
- const { components: components2, getCellContextMenuItems } = getState();
32500
- const MenuCmp = components2?.Menu ?? Menu;
32501
- const { computedColumnsMap } = getComputed();
32502
- const column = computedColumnsMap.get(columnId);
32503
- const cellContext = {
32504
- ...getCellContext({
32505
- ...context,
32506
- rowIndex,
32507
- columnId: column.id
32508
- }),
32509
- event
32510
- };
32511
- if (!column || !getCellContextMenuItems) {
32512
- return {
32513
- cellContext,
32514
- menu: null,
32515
- preventDefault: false
32516
- };
32517
- }
32518
- const menuDefaultProps = getMenuDefaultProps({
32519
- onHideIntent
32520
- });
32521
- const menuDefinition = getCellContextMenuItems(cellContext, context);
32522
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32523
- if (menuDefinition instanceof Promise) {
32524
- return {
32525
- cellContext,
32526
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32527
- preventDefault
32528
- };
32529
- }
32530
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32531
- if (!items || !items.length) {
32532
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32533
- }
32837
+ function getContextMenuBinder(context) {
32838
+ const MenuCmp = context.getState().components?.Menu ?? Menu;
32534
32839
  return {
32535
- preventDefault,
32536
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32537
- cellContext
32840
+ renderMenu: (props) => /* @__PURE__ */ React70.createElement(MenuCmp, { ...props }),
32841
+ renderLazyMenu: (menuDefinition, menuDefaultProps) => getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp)
32538
32842
  };
32539
32843
  }
32844
+ function getCellContextMenu(cellLocation, context, onHideIntent) {
32845
+ return getCellContextMenuContent(
32846
+ cellLocation,
32847
+ context,
32848
+ onHideIntent,
32849
+ getContextMenuBinder(context)
32850
+ );
32851
+ }
32540
32852
  function getTableContextMenu(menuLocation, context, onHideIntent) {
32541
- const { getState, getComputed } = context;
32542
- const { components: components2, getContextMenuItems } = getState();
32543
- const MenuCmp = components2?.Menu ?? Menu;
32544
- const { computedColumnsMap } = getComputed();
32545
- const column = menuLocation.columnId ? computedColumnsMap.get(menuLocation.columnId) : void 0;
32546
- const cellContext = column ? {
32547
- ...menuLocation,
32548
- ...getCellContext({
32549
- ...context,
32550
- rowIndex: menuLocation.rowIndex,
32551
- columnId: column.id
32552
- })
32553
- } : menuLocation;
32554
- if (!getContextMenuItems) {
32555
- return { cellContext, menu: null, preventDefault: false };
32556
- }
32557
- const menuDefaultProps = getMenuDefaultProps({
32558
- onHideIntent
32559
- });
32560
- const menuDefinition = getContextMenuItems(cellContext, context);
32561
- const preventDefault = menuDefinition instanceof Promise ? true : Array.isArray(menuDefinition) ? true : !!(menuDefinition && Array.isArray(menuDefinition.items));
32562
- if (menuDefinition instanceof Promise) {
32563
- return {
32564
- cellContext,
32565
- menu: getLazyMenu(menuDefinition, menuDefaultProps, MenuCmp),
32566
- preventDefault
32567
- };
32568
- }
32569
- const { items, columns } = getMenuItemsAndColumns(menuDefinition);
32570
- if (!items || !items.length) {
32571
- return { cellContext, menu: null, preventDefault: Array.isArray(items) };
32572
- }
32573
- return {
32574
- preventDefault,
32575
- menu: /* @__PURE__ */ React70.createElement(MenuCmp, { ...menuDefaultProps, columns, items }),
32576
- cellContext
32577
- };
32853
+ return getTableContextMenuContent(
32854
+ menuLocation,
32855
+ context,
32856
+ onHideIntent,
32857
+ getContextMenuBinder(context)
32858
+ );
32578
32859
  }
32579
32860
 
32580
32861
  // src/components/InfiniteTable/hooks/useContextMenu.ts
32581
- var OFFSET3 = 5;
32582
- var ALIGN_POSITIONS = [
32583
- ["TopLeft", "BottomLeft"],
32584
- ["TopRight", "BottomRight"],
32585
- ["BottomLeft", "BottomLeft"],
32586
- ["BottomRight", "BottomRight"],
32587
- ["TopCenter", "TopLeft"],
32588
- ["BottomCenter", "TopLeft"],
32589
- ["CenterLeft", "TopLeft"],
32590
- ["CenterRight", "TopLeft"]
32591
- ];
32592
32862
  function useCellContextMenu() {
32593
32863
  const context = useInfiniteTableStableContext();
32594
32864
  const { getState, actions } = context;
@@ -32600,78 +32870,22 @@ function useCellContextMenu() {
32600
32870
  portalContainer: useMenuPortalContainer()
32601
32871
  });
32602
32872
  useEffect35(() => {
32603
- const { actions: actions2, getState: getState2, getDataSourceState } = context;
32604
- const state = getState2();
32605
- return state.cellContextMenu.onChange((info) => {
32606
- if (!info) {
32607
- return;
32608
- }
32609
- const { event } = info;
32610
- function onHideIntent() {
32611
- clearAll();
32612
- actions2.cellContextMenuVisibleFor = null;
32613
- }
32614
- const { menu, cellContext, preventDefault } = getCellContextMenu(
32615
- info,
32616
- context,
32617
- onHideIntent
32618
- );
32619
- const rect = Rectangle.fromPoint({
32620
- top: event.clientY,
32621
- left: event.clientX
32622
- });
32623
- rect.width += OFFSET3;
32624
- rect.height += OFFSET3;
32625
- showOverlay(menu, {
32626
- constrainTo: getMenuConstrainTo(getState2()),
32627
- id: "cell-context-menu",
32628
- alignTo: rect,
32629
- alignPosition: ALIGN_POSITIONS
32630
- });
32631
- if (preventDefault) {
32632
- event.preventDefault();
32633
- }
32634
- actions2.cellContextMenuVisibleFor = {
32635
- columnId: info.columnId,
32636
- rowId: info.rowId,
32637
- rowIndex: info.rowIndex,
32638
- colIndex: info.colIndex
32639
- };
32640
- const { onCellContextMenu } = getState2();
32641
- if (onCellContextMenu) {
32642
- onCellContextMenu(
32643
- {
32644
- ...cellContext,
32645
- getState: getState2,
32646
- getDataSourceState
32647
- },
32648
- event
32649
- );
32650
- }
32651
- });
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
+ );
32652
32880
  }, []);
32653
32881
  useEffect35(() => {
32654
- const { cellContextMenuVisibleFor } = getState();
32655
- if (cellContextMenuVisibleFor) {
32656
- let handleMouseDown2 = function(event) {
32657
- if (event.__insideMenu !== true) {
32658
- clearAll();
32659
- actions.cellContextMenuVisibleFor = null;
32660
- }
32661
- };
32662
- var handleMouseDown = handleMouseDown2;
32663
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32664
- return () => {
32665
- document.documentElement.removeEventListener(
32666
- "mousedown",
32667
- handleMouseDown2
32668
- );
32669
- };
32670
- } else {
32671
- clearAll();
32672
- }
32673
- return () => {
32674
- };
32882
+ return menuVisibilityEffect(
32883
+ getState().cellContextMenuVisibleFor,
32884
+ clearAll,
32885
+ () => {
32886
+ actions.cellContextMenuVisibleFor = null;
32887
+ }
32888
+ );
32675
32889
  }, [getState().cellContextMenuVisibleFor]);
32676
32890
  return { menuPortal };
32677
32891
  }
@@ -32686,76 +32900,22 @@ function useTableContextMenu() {
32686
32900
  portalContainer: useMenuPortalContainer()
32687
32901
  });
32688
32902
  useEffect35(() => {
32689
- const { actions: actions2, getState: getState2 } = context;
32690
- const state = getState2();
32691
- return state.contextMenu.onChange((info) => {
32692
- if (!info) {
32693
- return;
32694
- }
32695
- const { event } = info;
32696
- function onHideIntent() {
32697
- clearAll();
32698
- actions2.contextMenuVisibleFor = null;
32699
- }
32700
- const { menu, cellContext, preventDefault } = getTableContextMenu(
32701
- info,
32702
- context,
32703
- onHideIntent
32704
- );
32705
- const point = {
32706
- top: event.clientY,
32707
- left: event.clientX
32708
- };
32709
- const rect = Rectangle.fromPoint(point);
32710
- rect.width += OFFSET3;
32711
- rect.height += OFFSET3;
32712
- showOverlay(menu, {
32713
- constrainTo: getMenuConstrainTo(getState2()),
32714
- id: "table-context-menu",
32715
- alignTo: rect,
32716
- alignPosition: ALIGN_POSITIONS
32717
- });
32718
- if (preventDefault) {
32719
- event.preventDefault();
32720
- }
32721
- actions2.contextMenuVisibleFor = {
32722
- point,
32723
- ...info
32724
- };
32725
- const { onContextMenu } = getState2();
32726
- if (onContextMenu) {
32727
- onContextMenu(
32728
- {
32729
- ...context,
32730
- ...cellContext
32731
- },
32732
- event
32733
- );
32734
- }
32735
- });
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
+ );
32736
32910
  }, []);
32737
32911
  useEffect35(() => {
32738
- const { contextMenuVisibleFor } = getState();
32739
- if (contextMenuVisibleFor) {
32740
- let handleMouseDown2 = function(event) {
32741
- if (event.__insideMenu !== true) {
32742
- clearAll();
32743
- actions.contextMenuVisibleFor = null;
32744
- }
32745
- };
32746
- var handleMouseDown = handleMouseDown2;
32747
- document.documentElement.addEventListener("mousedown", handleMouseDown2);
32748
- return () => {
32749
- document.documentElement.removeEventListener(
32750
- "mousedown",
32751
- handleMouseDown2
32752
- );
32753
- };
32754
- } else {
32755
- clearAll();
32756
- }
32757
- return () => {
32758
- };
32912
+ return menuVisibilityEffect(
32913
+ getState().contextMenuVisibleFor,
32914
+ clearAll,
32915
+ () => {
32916
+ actions.contextMenuVisibleFor = null;
32917
+ }
32918
+ );
32759
32919
  }, [getState().contextMenuVisibleFor]);
32760
32920
  return { menuPortal };
32761
32921
  }