@basic-ui/core 0.0.46 → 0.0.48

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.
@@ -0,0 +1,11 @@
1
+ import type { ElementType, HTMLAttributes } from 'react';
2
+ export declare type ContextMenuTriggerProps = HTMLAttributes<HTMLElement> & {
3
+ as?: ElementType<any>;
4
+ innerAs?: ElementType<any>;
5
+ disabled?: boolean;
6
+ };
7
+ export declare const ContextMenuTrigger: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLElement> & {
8
+ as?: ElementType<any> | undefined;
9
+ innerAs?: ElementType<any> | undefined;
10
+ disabled?: boolean | undefined;
11
+ } & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,60 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["as", "innerAs", "id", "onContextMenu", "disabled"];
4
+ import { forwardRef, useId } from 'react';
5
+ import { useMenuContext } from './context';
6
+ import { wrapEvent } from '../utils/wrap-event';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export var ContextMenuTrigger = /*#__PURE__*/forwardRef(function ContextMenuTrigger(props, forwardedRef) {
9
+ var _props$as = props.as,
10
+ Comp = _props$as === void 0 ? 'div' : _props$as,
11
+ innerAs = props.innerAs,
12
+ preferredId = props.id,
13
+ onContextMenu = props.onContextMenu,
14
+ disabled = props.disabled,
15
+ otherProps = _objectWithoutProperties(props, _excluded);
16
+
17
+ var _useMenuContext = useMenuContext(),
18
+ menuListIdRef = _useMenuContext.menuListIdRef,
19
+ open = _useMenuContext.open,
20
+ buttonRef = _useMenuContext.buttonRef,
21
+ onChange = _useMenuContext.onChange,
22
+ setOffsetFn = _useMenuContext.setOffsetFn,
23
+ isContextMenu = _useMenuContext.isContextMenu;
24
+
25
+ var idGenerated = useId();
26
+ var id = preferredId || idGenerated;
27
+
28
+ var handleContextMenu = function handleContextMenu(e) {
29
+ if (disabled) {
30
+ return;
31
+ }
32
+
33
+ var rect = e.currentTarget.getBoundingClientRect();
34
+ isContextMenu.current = true;
35
+ buttonRef.current = e.currentTarget;
36
+ onChange(e, true);
37
+ var mouseX = e.nativeEvent.x;
38
+ var mouseY = e.nativeEvent.y;
39
+ setOffsetFn(function () {
40
+ return function (_ref) {
41
+ var reference = _ref.reference;
42
+ return [mouseX - rect.x, mouseY - rect.y - reference.height];
43
+ };
44
+ });
45
+ e.preventDefault();
46
+ };
47
+
48
+ return /*#__PURE__*/_jsx(Comp, _extends({
49
+ ref: forwardedRef,
50
+ as: innerAs,
51
+ id: id,
52
+ "aria-haspopup": true,
53
+ "aria-controls": menuListIdRef.current,
54
+ "aria-expanded": open ? true : undefined,
55
+ "data-menu-trigger": "",
56
+ onContextMenu: wrapEvent(onContextMenu, handleContextMenu),
57
+ disabled: disabled
58
+ }, otherProps));
59
+ });
60
+ //# sourceMappingURL=ContextMenuTrigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuTrigger.js","names":["forwardRef","useId","useMenuContext","wrapEvent","ContextMenuTrigger","props","forwardedRef","as","Comp","innerAs","preferredId","id","onContextMenu","disabled","otherProps","menuListIdRef","open","buttonRef","onChange","setOffsetFn","isContextMenu","idGenerated","handleContextMenu","e","rect","currentTarget","getBoundingClientRect","current","mouseX","nativeEvent","x","mouseY","y","reference","height","preventDefault","undefined"],"sources":["../../../src/Menu/ContextMenuTrigger.tsx"],"sourcesContent":["import type {\n ElementType,\n HTMLAttributes,\n MouseEvent as ReactMouseEvent,\n} from 'react';\nimport { forwardRef, useId } from 'react';\n\nimport { useMenuContext } from './context';\nimport { wrapEvent } from '../utils/wrap-event';\nimport type { OffsetsFunction } from '../Popper';\n\nexport type ContextMenuTriggerProps = HTMLAttributes<HTMLElement> & {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n disabled?: boolean;\n};\n\nexport const ContextMenuTrigger = forwardRef<\n HTMLElement,\n ContextMenuTriggerProps\n>(function ContextMenuTrigger(props, forwardedRef) {\n const {\n as: Comp = 'div',\n innerAs,\n id: preferredId,\n onContextMenu,\n disabled,\n ...otherProps\n } = props;\n const {\n menuListIdRef,\n open,\n buttonRef,\n onChange,\n setOffsetFn,\n isContextMenu,\n } = useMenuContext();\n\n const idGenerated = useId();\n const id = preferredId || idGenerated;\n\n const handleContextMenu = (e: ReactMouseEvent<HTMLElement>) => {\n if (disabled) {\n return;\n }\n const rect = e.currentTarget.getBoundingClientRect();\n isContextMenu.current = true;\n\n buttonRef.current = e.currentTarget;\n onChange(e, true);\n\n const mouseX = e.nativeEvent.x;\n const mouseY = e.nativeEvent.y;\n setOffsetFn(\n (): OffsetsFunction =>\n ({ reference }) =>\n [mouseX - rect.x, mouseY - rect.y - reference.height]\n );\n e.preventDefault();\n };\n\n return (\n <Comp\n ref={forwardedRef}\n as={innerAs}\n id={id}\n aria-haspopup={true}\n aria-controls={menuListIdRef.current}\n aria-expanded={open ? true : undefined}\n data-menu-trigger=\"\"\n onContextMenu={wrapEvent(onContextMenu, handleContextMenu)}\n disabled={disabled}\n {...otherProps}\n />\n );\n});\n"],"mappings":";;;AAKA,SAASA,UAAT,EAAqBC,KAArB,QAAkC,OAAlC;AAEA,SAASC,cAAT,QAA+B,WAA/B;AACA,SAASC,SAAT,QAA0B,qBAA1B;;AASA,OAAO,IAAMC,kBAAkB,gBAAGJ,UAAU,CAG1C,SAASI,kBAAT,CAA4BC,KAA5B,EAAmCC,YAAnC,EAAiD;EACjD,gBAOID,KAPJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,KADb;EAAA,IAEEC,OAFF,GAOIJ,KAPJ,CAEEI,OAFF;EAAA,IAGMC,WAHN,GAOIL,KAPJ,CAGEM,EAHF;EAAA,IAIEC,aAJF,GAOIP,KAPJ,CAIEO,aAJF;EAAA,IAKEC,QALF,GAOIR,KAPJ,CAKEQ,QALF;EAAA,IAMKC,UANL,4BAOIT,KAPJ;;EAQA,sBAOIH,cAAc,EA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B,CAR1B;IASE,QAAQ,EAAET;EATZ,GAUMC,UAVN,EADF;AAcD,CA1D2C,CAArC"}
@@ -1,14 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["as", "open", "defaultOpen", "onChange"];
5
- import { forwardRef, useRef, Fragment, useId } from 'react';
4
+ var _excluded = ["as", "innerAs", "open", "defaultOpen", "onChange"];
5
+ import { useState, forwardRef, useRef, Fragment, useId } from 'react';
6
6
  import { MenuProvider } from './context';
7
7
  import { useControlledState } from '../hooks';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  export var Menu = /*#__PURE__*/forwardRef(function Menu(props, forwardedRef) {
10
10
  var _props$as = props.as,
11
11
  Comp = _props$as === void 0 ? Fragment : _props$as,
12
+ innerAs = props.innerAs,
12
13
  openProp = props.open,
13
14
  _props$defaultOpen = props.defaultOpen,
14
15
  defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
@@ -28,17 +29,33 @@ export var Menu = /*#__PURE__*/forwardRef(function Menu(props, forwardedRef) {
28
29
  open = _useControlledState2[0],
29
30
  onChange = _useControlledState2[1];
30
31
 
32
+ var _useState = useState(undefined),
33
+ _useState2 = _slicedToArray(_useState, 2),
34
+ offsetFn = _useState2[0],
35
+ setOffsetFn = _useState2[1];
36
+
31
37
  menuListIdRef.current = useId();
38
+ var isContextMenu = useRef(false);
39
+
40
+ if (!open && offsetFn) {
41
+ setOffsetFn(undefined);
42
+ }
43
+
32
44
  var value = {
33
45
  menuListIdRef: menuListIdRef,
34
46
  openWithArrowKeyRef: openWithArrowKeyRef,
35
47
  open: open,
36
48
  onChange: onChange,
37
- buttonRef: buttonRef
49
+ buttonRef: buttonRef,
50
+ offsetFn: offsetFn,
51
+ setOffsetFn: setOffsetFn,
52
+ isContextMenu: isContextMenu
38
53
  };
39
54
  return /*#__PURE__*/_jsx(MenuProvider, {
40
55
  value: value,
41
- children: /*#__PURE__*/_jsx(Comp, _extends({
56
+ children: /*#__PURE__*/_jsx(Comp, _extends(_extends({}, Comp !== Fragment ? {
57
+ as: innerAs
58
+ } : {}), {}, {
42
59
  ref: forwardedRef
43
60
  }, otherProps))
44
61
  });
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.js","names":["forwardRef","useRef","Fragment","useId","MenuProvider","useControlledState","Menu","props","forwardedRef","as","Comp","openProp","open","defaultOpen","onChangeProp","onChange","otherProps","menuListIdRef","openWithArrowKeyRef","buttonRef","setState","e","isOpen","current","value"],"sources":["../../../src/Menu/Menu.tsx"],"sourcesContent":["import type {\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ElementType,\n} from 'react';\nimport { forwardRef, useRef, Fragment, useId } from 'react';\n\nimport type { MenuContextProps } from './context';\nimport { MenuProvider } from './context';\nimport { useControlledState } from '../hooks';\n\nexport interface MenuProps {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n onChange?: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open?: boolean;\n defaultOpen?: boolean;\n}\n\nexport const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(\n props,\n forwardedRef\n) {\n const {\n as: Comp = Fragment,\n open: openProp,\n defaultOpen = false,\n onChange: onChangeProp,\n ...otherProps\n } = props;\n const menuListIdRef = useRef<string>();\n const openWithArrowKeyRef = useRef<'ArrowUp' | 'ArrowDown' | null>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [open, onChange] = useControlledState(\n openProp,\n onChangeProp,\n defaultOpen,\n (setState) => (e, isOpen) => {\n setState(isOpen);\n }\n );\n\n menuListIdRef.current = useId();\n\n const value: MenuContextProps = {\n menuListIdRef,\n openWithArrowKeyRef,\n open,\n onChange,\n buttonRef,\n };\n\n return (\n <Men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AAEK,KAArB;IAAA,uBACE,KAAC,IAAD;MAAM,GAAG,EAAEhB;IAAX,GAA6BQ,UAA7B;EADF,EADF;AAKD,CAtC6B,CAAvB"}
1
+ {"version":3,"file":"Menu.js","names":["useState","forwardRef","useRef","Fragment","useId","MenuProvider","useControlledState","Menu","props","forwardedRef","as","Comp","innerAs","openProp","open","defaultOpen","onChangeProp","onChange","otherProps","menuListIdRef","openWithArrowKeyRef","buttonRef","setState","e","isOpen","undefined","offsetFn","setOffsetFn","current","isContextMenu","value"],"sources":["../../../src/Menu/Menu.tsx"],"sourcesContent":["import type {\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ElementType,\n} from 'react';\nimport { useState, forwardRef, useRef, Fragment, useId } from 'react';\n\nimport type { MenuContextProps } from './context';\nimport { MenuProvider } from './context';\nimport { useControlledState } from '../hooks';\nimport type { OffsetsFunction } from '../Popper';\n\nexport interface MenuProps {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n onChange?: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open?: boolean;\n defaultOpen?: boolean;\n}\n\nexport const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(\n props,\n forwardedRef\n) {\n const {\n as: Comp = Fragment,\n innerAs,\n open: openProp,\n defaultOpen = false,\n onChange: onChangeProp,\n ...otherProps\n } = props;\n const menuListIdRef = useRef<string>();\n const openWithArrowKeyRef = useRef<'ArrowUp' | 'ArrowDown' | null>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [open, onChange] = useControlledState(\n openProp,\n onChangeProp,\n defaultOpen,\n (setState) => (e, isOpen) => {\n setState(isOpen);\n }\n );\n const [offsetFn, setOffsetFn] = useState<OffsetsFunction | undefined>(\n undefined\n );\n menuListIdRef.current = useId();\n const isContextMenu = useRef(false);\n\n if (!open && offsetFn) {\n setOffsetFn(undefined);\n }\n\n const value: MenuContextProps = {\n menuListIdRef,\n openWithArrowKeyRef,\n open,\n onChange,\n buttonRef,\n offsetFn,\n setOffsetFn,\n isContextMenu,\n };\n\n return (\n <MenuProvider value={value}>\n <Comp\n {...(Comp !== Fragment ? { as: innerAs } : {})}\n ref={forwardedRef}\n {...otherProps}\n />\n </MenuProvider>\n );\n});\n"],"mappings":";;;;AAOA,SAASA,QAAT,EAAmBC,UAAnB,EAA+BC,MAA/B,EAAuCC,QAAvC,EAAiDC,KAAjD,QAA8D,OAA9D;AAGA,SAASC,YAAT,QAA6B,WAA7B;AACA,SAASC,kBAAT,QAAmC,UAAnC;;AAkBA,OAAO,IAAMC,IAAI,gBAAGN,UAAU,CAA4B,SAASM,IAAT,CACxDC,KADwD,EAExDC,YAFwD,EAGxD;EACA,gBAOID,KAPJ,CACEE,EADF;EAAA,IACMC,IADN,0BACaR,QADb;EAAA,IAEES,OAFF,GAOIJ,KAPJ,CAEEI,OAFF;EAAA,IAGQC,QAHR,GAOIL,KAPJ,CAGEM,IAHF;EAAA,yBAOIN,KAPJ,CAIEO,WAJF;EAAA,IAIEA,WAJF,mCAIgB,KAJhB;EAAA,IAKYC,YALZ,GAOIR,KAPJ,CAKES,QALF;EAAA,IAMKC,UANL,4BAOIV,KAPJ;;EAQA,IAAMW,aAAa,GAAGjB,MAAM,EAA5B;EACA,IAAMkB,mBAAmB,GAAGlB,MAAM,CAAiC,IAAjC,CAAlC;EACA,IAAMmB,SAAS,GAAGnB,MAAM,CAAoB,IAApB,CAAxB;;EACA,0BAAyBI,kBAAkB,CACzCO,QADyC,EAEzCG,YAFyC,EAGzCD,WAHyC,EAIzC,UAACO,QAAD;IAAA,OAAc,UAACC,CAAD,EAAIC,MAAJ,EAAe;MAC3BF,QAAQ,CAACE,MAAD,CAAR;IACD,CAFD;EAAA,CAJyC,CAA3C;EAAA;EAAA,IAAOV,IAAP;EAAA,IAAaG,QAAb;;EAQA,gBAAgCjB,QAAQ,CACtCyB,SADsC,CAAxC;EAAA;EAAA,IAAOC,QAAP;EAAA,IAAiBC,WAAjB;;EAGAR,aAAa,CAACS,OAAd,GAAwBxB,KAAK,EAA7B;EACA,IAAMyB,aAAa,GAAG3B,MAAM,CAAC,KAAD,CAA5B;;EAEA,IAAI,CAACY,IAAD,IAASY,QAAb,EAAuB;IACrBC,WAAW,CAACF,SAAD,CAAX;EACD;;EAED,IAAMK,KAAuB,GAAG;IAC9BX,aAAa,EAAbA,aAD8B;IAE9BC,mBAAmB,EAAnBA,mBAF8B;IAG9BN,IAAI,EAAJA,IAH8B;IAI9BG,QAAQ,EAARA,QAJ8B;IAK9BI,SAAS,EAATA,SAL8B;IAM9BK,QAAQ,EAARA,QAN8B;IAO9BC,WAAW,EAAXA,WAP8B;IAQ9BE,aAAa,EAAbA;EAR8B,CAAhC;EAWA,oBACE,KAAC,YAAD;IAAc,KAAK,EAAEC,KAArB;IAAA,uBACE,KAAC,IAAD,wBACOnB,IAAI,KAAKR,QAAT,GAAoB;MAAEO,EAAE,EAAEE;IAAN,CAApB,GAAsC,EAD7C;MAEE,GAAG,EAAEH;IAFP,GAGMS,UAHN;EADF,EADF;AASD,CArD6B,CAAvB"}
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["as", "id", "onClick", "onKeyDown", "disabled"];
3
+ var _excluded = ["as", "innerAs", "id", "onClick", "onKeyDown", "disabled"];
4
4
  import { forwardRef, useId } from 'react';
5
5
  import { useMenuContext } from './context';
6
6
  import { wrapEvent } from '../utils/wrap-event';
@@ -8,6 +8,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
8
8
  export var MenuButton = /*#__PURE__*/forwardRef(function MenuButton(props, forwardedRef) {
9
9
  var _props$as = props.as,
10
10
  Comp = _props$as === void 0 ? 'button' : _props$as,
11
+ innerAs = props.innerAs,
11
12
  preferredId = props.id,
12
13
  onClick = props.onClick,
13
14
  onKeyDown = props.onKeyDown,
@@ -47,7 +48,7 @@ export var MenuButton = /*#__PURE__*/forwardRef(function MenuButton(props, forwa
47
48
  openWithArrowKeyRef.current = e.key;
48
49
  }
49
50
 
50
- onChange && onChange(e, true);
51
+ onChange(e, true);
51
52
  e.preventDefault();
52
53
  }
53
54
  };
@@ -58,11 +59,12 @@ export var MenuButton = /*#__PURE__*/forwardRef(function MenuButton(props, forwa
58
59
  }
59
60
 
60
61
  buttonRef.current = e.currentTarget;
61
- onChange && onChange(e, !open);
62
+ onChange(e, !open);
62
63
  };
63
64
 
64
65
  return /*#__PURE__*/_jsx(Comp, _extends({
65
66
  ref: forwardedRef,
67
+ as: innerAs,
66
68
  id: buttonId,
67
69
  role: "button",
68
70
  type: "button",
@@ -1 +1 @@
1
- {"version":3,"file":"MenuButton.js","names":["forwardRef","useId","useMenuContext","wrapEvent","MenuButton","props","forwardedRef","as","Comp","preferredId","id","onClick","onKeyDown","disabled","otherProps","menuListIdRef","openWithArrowKeyRef","open","buttonRef","onChange","buttonIdGenerated","buttonId","handleKeyDown","e","current","currentTarget","isArrowKey","includes","key","isEnterKey","openedWithArrow","preventDefault","handleClick","undefined"],"sources":["../../../src/Menu/MenuButton.tsx"],"sourcesContent":["import type {\n ButtonHTMLAttributes,\n ElementType,\n KeyboardEvent,\n MouseEvent,\n} from 'react';\nimport { forwardRef, useId } from 'react';\n\nimport { useMenuContext } from './context';\nimport { wrapEvent } from '../utils/wrap-event';\n\nexport type MenuButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onClick?: (\n e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>\n ) => void;\n};\n\nexport const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(\n function MenuButton(props, forwardedRef) {\n const {\n as: Comp = 'button',\n id: preferredId,\n onClick,\n onKeyDown,\n disabled,\n ...otherProps\n } = props;\n const { menuListIdRef, openWithArrowKeyRef, open, buttonRef, onChange } =\n useMenuContext();\n\n const buttonIdGenerated = useId();\n const buttonId = preferredId || buttonIdGenerated;\n\n const handleKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n buttonRef.current = e.currentTarget;\n\n const isArrowKey = () => ['ArrowUp', 'ArrowDown'].includes(e.key);\n const isEnterKey = () => [' ', 'Enter'].includes(e.key);\n\n const openedWithArrow = isArrowKey();\n if (openedWithArrow || isEnterKey()) {\n if (openedWithArrow) {\n // Used to make it open at the end or begining of the list\n openWithArrowKeyRef.current = e.key;\n }\n onChange && onChange(e, true);\n e.preventDefault();\n }\n };\n\n const handleClick = (e: MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n buttonRef.current = e.currentTarget;\n\n onChange && onChange(e, !open);\n };\n\n return (\n <Comp\n ref={forwardedRef}\n id={buttonId}\n role=\"button\"\n type=\"button\"\n aria-haspopup={true}\n aria-controls={menuListIdRef.current}\n aria-expanded={open ? true : undefined}\n data-menu-button=\"\"\n onClick={wrapEvent(onClick, handleClick)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n disabled={disabled}\n {...otherProps}\n />\n );\n }\n);\n"],"mappings":";;;AAMA,SAASA,UAAT,EAAqBC,KAArB,QAAkC,OAAlC;AAEA,SAASC,cAAT,QAA+B,WAA/B;AACA,SAASC,SAAT,QAA0B,qBAA1B;;AAUA,OAAO,IAAMC,UAAU,gBAAGJ,UAAU,CAClC,SAASI,UAAT,CAAoBC,KAApB,EAA2BC,YAA3B,EAAyC;EACvC,gBAOID,KAPJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,QADb;EAAA,IAEMC,WAFN,GAOIJ,KAPJ,CAEEK,EAFF;EAAA,IAGEC,OAHF,GAOIN,KAPJ,CAGEM,OAHF;EAAA,IAIEC,SAJF,GAOIP,KAPJ,CAIEO,SAJF;EAAA,IAKEC,QALF,GAOIR,KAPJ,CAKEQ,QALF;EAAA,IAMKC,UANL,4BAOIT,KA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L,CAApB;EACD,CAPD;;EASA,oBACE,KAAC,IAAD;IACE,GAAG,EAAEX,YADP;IAEE,EAAE,EAAEe,QAFN;IAGE,IAAI,EAAC,QAHP;IAIE,IAAI,EAAC,QAJP;IAKE,iBAAe,IALjB;IAME,iBAAeN,aAAa,CAACS,OAN/B;IAOE,iBAAeP,IAAI,GAAG,IAAH,GAAUgB,SAP/B;IAQE,oBAAiB,EARnB;IASE,OAAO,EAAE9B,SAAS,CAACQ,OAAD,EAAUqB,WAAV,CATpB;IAUE,SAAS,EAAE7B,SAAS,CAACS,SAAD,EAAYU,aAAZ,CAVtB;IAWE,QAAQ,EAAET;EAXZ,GAYMC,UAZN,EADF;AAgBD,CA7DiC,CAA7B"}
1
+ {"version":3,"file":"MenuButton.js","names":["forwardRef","useId","useMenuContext","wrapEvent","MenuButton","props","forwardedRef","as","Comp","innerAs","preferredId","id","onClick","onKeyDown","disabled","otherProps","menuListIdRef","openWithArrowKeyRef","open","buttonRef","onChange","buttonIdGenerated","buttonId","handleKeyDown","e","current","currentTarget","isArrowKey","includes","key","isEnterKey","openedWithArrow","preventDefault","handleClick","undefined"],"sources":["../../../src/Menu/MenuButton.tsx"],"sourcesContent":["import type {\n ButtonHTMLAttributes,\n ElementType,\n KeyboardEvent,\n MouseEvent,\n} from 'react';\nimport { forwardRef, useId } from 'react';\n\nimport { useMenuContext } from './context';\nimport { wrapEvent } from '../utils/wrap-event';\n\nexport type MenuButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onClick?: (\n e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>\n ) => void;\n};\n\nexport const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(\n function MenuButton(props, forwardedRef) {\n const {\n as: Comp = 'button',\n innerAs,\n id: preferredId,\n onClick,\n onKeyDown,\n disabled,\n ...otherProps\n } = props;\n const { menuListIdRef, openWithArrowKeyRef, open, buttonRef, onChange } =\n useMenuContext();\n\n const buttonIdGenerated = useId();\n const buttonId = preferredId || buttonIdGenerated;\n\n const handleKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n buttonRef.current = e.currentTarget;\n\n const isArrowKey = () => ['ArrowUp', 'ArrowDown'].includes(e.key);\n const isEnterKey = () => [' ', 'Enter'].includes(e.key);\n\n const openedWithArrow = isArrowKey();\n if (openedWithArrow || isEnterKey()) {\n if (openedWithArrow) {\n // Used to make it open at the end or begining of the list\n openWithArrowKeyRef.current = e.key;\n }\n onChange(e, true);\n e.preventDefault();\n }\n };\n\n const handleClick = (e: MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n buttonRef.current = e.currentTarget;\n onChange(e, !open);\n };\n\n return (\n <Comp\n ref={forwardedRef}\n as={innerAs}\n id={buttonId}\n role=\"button\"\n type=\"button\"\n aria-haspopup={true}\n aria-controls={menuListIdRef.current}\n aria-expanded={open ? true : undefined}\n data-menu-button=\"\"\n onClick={wrapEvent(onClick, handleClick)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n disabled={disabled}\n {...otherProps}\n />\n );\n }\n);\n"],"mappings":";;;AAMA,SAASA,UAAT,EAAqBC,KAArB,QAAkC,OAAlC;AAEA,SAASC,cAAT,QAA+B,WAA/B;AACA,SAASC,SAAT,QAA0B,qBAA1B;;AAUA,OAAO,IAAMC,UAAU,gBAAGJ,UAAU,CAClC,SAASI,UAAT,CAAoBC,KAApB,EAA2BC,YAA3B,EAAyC;EACvC,gBAQID,KARJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,QADb;EAAA,IAEEC,OAFF,GAQIJ,KARJ,CAEEI,OAFF;EAAA,IAGMC,WAHN,GAQIL,KARJ,CAGEM,EAHF;EAAA,IAIEC,OAJF,GAQIP,KARJ,CAIEO,OAJF;EAAA,IAKEC,SALF,GAQIR,KARJ,CAKEQ,SALF;EAAA,IAMEC,QANF,GAQIT,KARJ,CAMES,QANF;EAAA,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EACD,CAND;;EAQA,oBACE,KAAC,IAAD;IACE,GAAG,EAAEZ,YADP;IAEE,EAAE,EAAEG,OAFN;IAGE,EAAE,EAAEa,QAHN;IAIE,IAAI,EAAC,QAJP;IAKE,IAAI,EAAC,QALP;IAME,iBAAe,IANjB;IAOE,iBAAeN,aAAa,CAACS,OAP/B;IAQE,iBAAeP,IAAI,GAAG,IAAH,GAAUgB,SAR/B;IASE,oBAAiB,EATnB;IAUE,OAAO,EAAE/B,SAAS,CAACS,OAAD,EAAUqB,WAAV,CAVpB;IAWE,SAAS,EAAE9B,SAAS,CAACU,SAAD,EAAYU,aAAZ,CAXtB;IAYE,QAAQ,EAAET;EAZZ,GAaMC,UAbN,EADF;AAiBD,CA9DiC,CAA7B"}
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["as", "disabled", "onSelect", "onClick", "onKeyDown"];
3
+ var _excluded = ["as", "innerAs", "disabled", "onSelect", "onClick", "onKeyDown"];
4
4
  import { forwardRef, useRef, useId } from 'react';
5
5
  import { useMenuContext, useMenuListContext } from './context';
6
6
  import { assignMultipleRefs } from '../utils/assign-ref';
@@ -9,6 +9,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
9
9
  export var MenuItem = /*#__PURE__*/forwardRef(function MenuItem(props, forwardedRef) {
10
10
  var _props$as = props.as,
11
11
  Comp = _props$as === void 0 ? 'li' : _props$as,
12
+ innerAs = props.innerAs,
12
13
  disabled = props.disabled,
13
14
  onSelect = props.onSelect,
14
15
  onClick = props.onClick,
@@ -29,7 +30,7 @@ export var MenuItem = /*#__PURE__*/forwardRef(function MenuItem(props, forwarded
29
30
  var handleSelect = wrapEvent(onSelect, function (e) {
30
31
  var _buttonRef$current;
31
32
 
32
- onChange && onChange(e, false);
33
+ onChange(e, false);
33
34
  (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.focus();
34
35
  e.preventDefault();
35
36
  });
@@ -55,6 +56,7 @@ export var MenuItem = /*#__PURE__*/forwardRef(function MenuItem(props, forwarded
55
56
 
56
57
  return /*#__PURE__*/_jsx(Comp, _extends({
57
58
  ref: assignMultipleRefs(ref, forwardedRef),
59
+ as: innerAs,
58
60
  id: disabled ? undefined : itemId,
59
61
  "data-menu-item": "",
60
62
  "data-highlighted": isActive ? '' : undefined,
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.js","names":["forwardRef","useRef","useId","useMenuContext","useMenuListContext","assignMultipleRefs","wrapEvent","MenuItem","props","forwardedRef","as","Comp","disabled","onSelect","onClick","onKeyDown","otherProps","onChange","buttonRef","navigationItem","onNavigate","ref","itemId","isActive","current","handleSelect","e","focus","preventDefault","handleClick","handleKeyDown","key","undefined"],"sources":["../../../src/Menu/MenuItem.tsx"],"sourcesContent":["import type {\n LiHTMLAttributes,\n ElementType,\n MouseEvent,\n KeyboardEvent,\n KeyboardEventHandler,\n} from 'react';\nimport { forwardRef, useRef, useId } from 'react';\n\nimport { useMenuContext, useMenuListContext } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { wrapEvent } from '../utils';\n\nexport interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onSelect?: (\n e: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>\n ) => void;\n disabled?: boolean;\n}\n\nexport const MenuItem = forwardRef<any, MenuItemProps>(function MenuItem(\n props,\n forwardedRef\n) {\n const {\n as: Comp = 'li',\n disabled,\n onSelect,\n onClick,\n onKeyDown,\n ...otherProps\n } = props;\n const { onChange, buttonRef } = useMenuContext();\n const { navigationItem, onNavigate } = useMenuListContext();\n const ref = useRef<HTMLLIElement>();\n const itemId = useId();\n\n const isActive = ref.current && ref.current === navigationItem;\n\n const handleSelect = wrapEvent(\n onSelect,\n (e: KeyboardEvent<HTMLLIElement> | MouseEvent<HTMLLIElement>) => {\n onChange && onChange(e, false);\n buttonRef.current?.focus();\n e.preventDefault();\n }\n );\n\n const handleClick = (e: MouseEvent<HTMLLIElement>) => {\n if (!disabled) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onNavigate && onNavigate(ref.current!);\n handleSelect(e);\n }\n };\n\n const handleKeyDown: KeyboardEventHandler<HTMLLIElement> = (e) => {\n switch (e.key) {\n case 'Enter':\n if (!disabled) {\n handleSelect(e);\n }\n break;\n }\n };\n\n return (\n <Comp\n ref={assignMultipleRefs(ref, forwardedRef)}\n id={disabled ? undefined : itemId}\n data-menu-item=\"\"\n data-highlighted={isActive ? '' : undefined}\n role=\"menuitem\"\n onClick={wrapEvent(onClick, handleClick)}\n tabIndex={disabled ? -1 : 0}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n data-disabled={disabled ? '' : undefined}\n aria-disabled={disabled ? '' : undefined}\n disabled={disabled}\n {...otherProps}\n />\n );\n});\n"],"mappings":";;;AAOA,SAASA,UAAT,EAAqBC,MAArB,EAA6BC,KAA7B,QAA0C,OAA1C;AAEA,SAASC,cAAT,EAAyBC,kBAAzB,QAAmD,WAAnD;AACA,SAASC,kBAAT,QAAmC,qBAAnC;AACA,SAASC,SAAT,QAA0B,UAA1B;;AAWA,OAAO,IAAMC,QAAQ,gBAAGP,UAAU,CAAqB,SAASO,QAAT,CACrDC,KADqD,EAErDC,YAFqD,EAGrD;EACA,gBAOID,KAPJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,IADb;EAAA,IAEEC,QAFF,GAOIJ,KAPJ,CAEEI,QAFF;EAAA,IAGEC,QAHF,GAOIL,KAPJ,CAGEK,QAHF;EAAA,IAIEC,OAJF,GAOIN,KAPJ,CAIEM,OAJF;EAAA,IAKEC,SALF,GAOIP,KAPJ,CAKEO,SALF;EAAA,IAMKC,UANL,4BAOIR,KAPJ;;EAQA,sBAAgCL,cAAc,EAA9C;EAAA,IAAQc,QAAR,mBAAQA,QAAR;EAA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OE,QAAQ,EAAEjB,QAAQ,GAAG,CAAC,CAAJ,GAAQ,CAP5B;IAQE,SAAS,EAAEN,SAAS,CAACS,SAAD,EAAYe,aAAZ,CARtB;IASE,iBAAelB,QAAQ,GAAG,EAAH,GAAQoB,SATjC;IAUE,iBAAepB,QAAQ,GAAG,EAAH,GAAQoB,SAVjC;IAWE,QAAQ,EAAEpB;EAXZ,GAYMI,UAZN,EADF;AAgBD,CA9DiC,CAA3B"}
1
+ {"version":3,"file":"MenuItem.js","names":["forwardRef","useRef","useId","useMenuContext","useMenuListContext","assignMultipleRefs","wrapEvent","MenuItem","props","forwardedRef","as","Comp","innerAs","disabled","onSelect","onClick","onKeyDown","otherProps","onChange","buttonRef","navigationItem","onNavigate","ref","itemId","isActive","current","handleSelect","e","focus","preventDefault","handleClick","handleKeyDown","key","undefined"],"sources":["../../../src/Menu/MenuItem.tsx"],"sourcesContent":["import type {\n LiHTMLAttributes,\n ElementType,\n MouseEvent,\n KeyboardEvent,\n KeyboardEventHandler,\n} from 'react';\nimport { forwardRef, useRef, useId } from 'react';\n\nimport { useMenuContext, useMenuListContext } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { wrapEvent } from '../utils';\n\nexport interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onSelect?: (\n e: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>\n ) => void;\n disabled?: boolean;\n}\n\nexport const MenuItem = forwardRef<any, MenuItemProps>(function MenuItem(\n props,\n forwardedRef\n) {\n const {\n as: Comp = 'li',\n innerAs,\n disabled,\n onSelect,\n onClick,\n onKeyDown,\n ...otherProps\n } = props;\n const { onChange, buttonRef } = useMenuContext();\n const { navigationItem, onNavigate } = useMenuListContext();\n const ref = useRef<HTMLLIElement>();\n const itemId = useId();\n\n const isActive = ref.current && ref.current === navigationItem;\n\n const handleSelect = wrapEvent(\n onSelect,\n (e: KeyboardEvent<HTMLLIElement> | MouseEvent<HTMLLIElement>) => {\n onChange(e, false);\n buttonRef.current?.focus();\n e.preventDefault();\n }\n );\n\n const handleClick = (e: MouseEvent<HTMLLIElement>) => {\n if (!disabled) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onNavigate && onNavigate(ref.current!);\n handleSelect(e);\n }\n };\n\n const handleKeyDown: KeyboardEventHandler<HTMLLIElement> = (e) => {\n switch (e.key) {\n case 'Enter':\n if (!disabled) {\n handleSelect(e);\n }\n break;\n }\n };\n\n return (\n <Comp\n ref={assignMultipleRefs(ref, forwardedRef)}\n as={innerAs}\n id={disabled ? undefined : itemId}\n data-menu-item=\"\"\n data-highlighted={isActive ? '' : undefined}\n role=\"menuitem\"\n onClick={wrapEvent(onClick, handleClick)}\n tabIndex={disabled ? -1 : 0}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n data-disabled={disabled ? '' : undefined}\n aria-disabled={disabled ? '' : undefined}\n disabled={disabled}\n {...otherProps}\n />\n );\n});\n"],"mappings":";;;AAOA,SAASA,UAAT,EAAqBC,MAArB,EAA6BC,KAA7B,QAA0C,OAA1C;AAEA,SAASC,cAAT,EAAyBC,kBAAzB,QAAmD,WAAnD;AACA,SAASC,kBAAT,QAAmC,qBAAnC;AACA,SAASC,SAAT,QAA0B,UAA1B;;AAWA,OAAO,IAAMC,QAAQ,gBAAGP,UAAU,CAAqB,SAASO,QAAT,CACrDC,KADqD,EAErDC,YAFqD,EAGrD;EACA,gBAQID,KARJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,IADb;EAAA,IAEEC,OAFF,GAQIJ,KARJ,CAEEI,OAFF;EAAA,IAGEC,QAHF,GAQIL,KARJ,CAGEK,QAHF;EAAA,IAIEC,QAJF,GAQIN,KARJ,CAIEM,QAJF;EAAA,IAKEC,OALF,GAQIP,KARJ,CAKEO,OALF;EAAA,IAMEC,SANF,GAQIR,KARJ,CAMEQ,SANF;EAAA,IAOKC,UAPL,4BAQIT,KARJ;;EASA,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EAAC,UANP;IAOE,OAAO,EAAE3B,SAAS,CAACS,OAAD,EAAUe,WAAV,CAPpB;IAQE,QAAQ,EAAEjB,QAAQ,GAAG,CAAC,CAAJ,GAAQ,CAR5B;IASE,SAAS,EAAEP,SAAS,CAACU,SAAD,EAAYe,aAAZ,CATtB;IAUE,iBAAelB,QAAQ,GAAG,EAAH,GAAQoB,SAVjC;IAWE,iBAAepB,QAAQ,GAAG,EAAH,GAAQoB,SAXjC;IAYE,QAAQ,EAAEpB;EAZZ,GAaMI,UAbN,EADF;AAiBD,CAhEiC,CAA3B"}
@@ -1,8 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["as", "onKeyDown", "id", "defaultActiveItemValue"];
5
- import { forwardRef, useEffect, useRef, useState, useLayoutEffect } from 'react';
4
+ var _excluded = ["as", "innerAs", "onKeyDown", "id", "defaultActiveItemValue"];
5
+ import { useCallback, forwardRef, useEffect, useRef, useState, useLayoutEffect } from 'react';
6
6
  import { useMenuContext, MenuListProvider } from './context';
7
7
  import { assignMultipleRefs } from '../utils/assign-ref';
8
8
  import { useOnClickOutside } from '../hooks/useOnClickOutside';
@@ -16,11 +16,13 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
16
16
 
17
17
  var _props$as = props.as,
18
18
  Comp = _props$as === void 0 ? 'ul' : _props$as,
19
+ innerAs = props.innerAs,
19
20
  onKeyDown = props.onKeyDown,
20
21
  preferredId = props.id,
21
22
  defaultActiveItemValue = props.defaultActiveItemValue,
22
23
  otherProps = _objectWithoutProperties(props, _excluded);
23
24
 
25
+ var interactedOutside = useRef(false);
24
26
  var itemSearchStr = useRef('');
25
27
  var itemSearchClearTimeout = useRef();
26
28
 
@@ -29,7 +31,8 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
29
31
  buttonRef = _useMenuContext.buttonRef,
30
32
  onChange = _useMenuContext.onChange,
31
33
  openWithArrowKeyRef = _useMenuContext.openWithArrowKeyRef,
32
- open = _useMenuContext.open;
34
+ open = _useMenuContext.open,
35
+ isContextMenu = _useMenuContext.isContextMenu;
33
36
 
34
37
  var _useState = useState(),
35
38
  _useState2 = _slicedToArray(_useState, 2),
@@ -72,15 +75,29 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
72
75
  openWithArrowKeyRef.current = null;
73
76
  setMounted(true);
74
77
  }, [mounted, navigationItem, onNavigate, openWithArrowKeyRef, scope, defaultActiveItemValue]);
75
- useOnClickOutside(menuListRef, function (e) {
76
- var _buttonRef$current;
78
+ var handleClickOutside = useCallback(function (e) {
79
+ if (!interactedOutside.current) {
80
+ // First interaction should be ignored, because
81
+ // this is what triggered the context menu to open
82
+ interactedOutside.current = true;
83
+ return;
84
+ }
85
+
86
+ if (isContextMenu.current) {
87
+ if (e.button === 0) {
88
+ onChange(e, false);
89
+ }
90
+ } else {
91
+ var _buttonRef$current;
77
92
 
78
- if (e.target instanceof HTMLElement && e.target !== buttonRef.current && !((_buttonRef$current = buttonRef.current) !== null && _buttonRef$current !== void 0 && _buttonRef$current.contains(e.target))) {
79
- onChange && onChange(e, false);
93
+ if (e.target instanceof HTMLElement && e.target !== buttonRef.current && !((_buttonRef$current = buttonRef.current) !== null && _buttonRef$current !== void 0 && _buttonRef$current.contains(e.target))) {
94
+ onChange(e, false);
95
+ }
80
96
  }
81
97
 
82
98
  e.preventDefault();
83
- }, true);
99
+ }, [buttonRef, isContextMenu, onChange]);
100
+ useOnClickOutside(menuListRef, handleClickOutside, open);
84
101
 
85
102
  function handleKeyDown(e) {
86
103
  switch (e.key) {
@@ -89,7 +106,7 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
89
106
  {
90
107
  var _buttonRef$current2;
91
108
 
92
- onChange && onChange(e, false);
109
+ onChange(e, false);
93
110
  e.preventDefault(); // prevents focusing on next element, because we will be handling it
94
111
 
95
112
  itemSearchStr.current = '';
@@ -184,6 +201,7 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
184
201
  }
185
202
 
186
203
  if (!open) {
204
+ interactedOutside.current = false;
187
205
  return null;
188
206
  }
189
207
 
@@ -194,6 +212,7 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
194
212
  },
195
213
  children: /*#__PURE__*/_jsx(Comp, _extends({
196
214
  ref: assignMultipleRefs(forwardedRef, menuListRef),
215
+ as: innerAs,
197
216
  id: menuListIdRef.current,
198
217
  role: "menu",
199
218
  "aria-labelledby": (_buttonRef$current3 = buttonRef.current) === null || _buttonRef$current3 === void 0 ? void 0 : _buttonRef$current3.id,
@@ -1 +1 @@
1
- {"version":3,"file":"MenuList.js","names":["forwardRef","useEffect","useRef","useState","useLayoutEffect","useMenuContext","MenuListProvider","assignMultipleRefs","useOnClickOutside","useScope","queryScope","getCircularIndex","wrapEvent","useEnhancedEffect","window","MenuList","props","forwardedRef","as","Comp","onKeyDown","preferredId","id","defaultActiveItemValue","otherProps","itemSearchStr","itemSearchClearTimeout","menuListIdRef","buttonRef","onChange","openWithArrowKeyRef","open","navigationItem","setNavigationItem","mounted","setMounted","menuListRef","scope","onNavigate","el","focus","current","allItems","queryAllNodes","index","length","i","dataset","value","e","target","HTMLElement","contains","preventDefault","handleKeyDown","key","currentIndex","findIndex","nextIndex","ctrlKey","altKey","slice","clearTimeout","setTimeout","searchStr","idx","dom","domText","innerText","toLowerCase","startsWith"],"sources":["../../../src/Menu/MenuList.tsx"],"sourcesContent":["import type { HTMLAttributes, ElementType, KeyboardEvent } from 'react';\nimport {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n} from 'react';\n\nimport { useMenuContext, MenuListProvider } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { useOnClickOutside } from '../hooks/useOnClickOutside';\nimport { useScope } from '../hooks';\nimport { queryScope } from './scope';\nimport { getCircularIndex, wrapEvent } from '../utils';\n\nconst useEnhancedEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport interface MenuListProps extends HTMLAttributes<HTMLUListElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n defaultActiveItemValue?: string;\n}\n\nexport const MenuList = forwardRef<HTMLUListElement, MenuListProps>(\n function MenuList(props, forwardedRef) {\n const {\n as: Comp = 'ul',\n onKeyDown,\n id: preferredId,\n defaultActiveItemValue,\n ...otherProps\n } = props;\n\n const itemSearchStr = useRef('');\n const itemSearchClearTimeout = useRef<ReturnType<typeof setTimeout>>();\n\n const { menuListIdRef, buttonRef, onChange, openWithArrowKeyRef, open } =\n useMenuContext();\n\n const [navigationItem, setNavigationItem] = useState<\n HTMLElement | undefined\n >();\n\n const [mounted, setMounted] = useState(false);\n\n const menuListRef = useRef<HTMLUListElement>();\n\n const scope = useScope<HTMLLIElement, HTMLUListElement>(menuListRef);\n\n const onNavigate = (el: HTMLElement) => {\n el.focus();\n setNavigationItem(el);\n };\n\n menuListIdRef.current = preferredId || menuListIdRef.current;\n\n useEnhancedEffect(() => {\n if (!mounted) {\n const allItems = scope.current.queryAllNodes(queryScope);\n let index = getCircularIndex(\n openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0,\n allItems.length\n );\n\n if (defaultActiveItemValue) {\n for (let i = 0; i < allItems.length; i++) {\n if (allItems[i].dataset.value === defaultActiveItemValue) {\n index = i;\n break;\n }\n }\n }\n\n if (index !== null) {\n onNavigate && onNavigate(allItems[index]);\n }\n }\n\n openWithArrowKeyRef.current = null;\n setMounted(true);\n }, [\n mounted,\n navigationItem,\n onNavigate,\n openWithArrowKeyRef,\n scope,\n defaultActiveItemValue,\n ]);\n\n useOnClickOutside(\n menuListRef,\n (e) => {\n if (\n e.target instanceof HTMLElement &&\n e.target !== buttonRef.current &&\n !buttonRef.current?.contains(e.target)\n ) {\n onChange && onChange(e as any, false);\n }\n e.preventDefault();\n },\n true\n );\n\n function handleKeyDown(e: KeyboardEvent<HTMLUListElement>) {\n switch (e.key) {\n case 'Escape':\n case 'Tab': {\n onChange && onChange(e, false);\n e.preventDefault(); // prevents focusing on next element, because we will be handling it\n itemSearchStr.current = '';\n buttonRef.current?.focus();\n break;\n }\n case 'Home':\n case 'End':\n case 'ArrowDown':\n case 'ArrowUp':\n e.preventDefault();\n itemSearchStr.current = '';\n const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];\n const currentIndex = allItems.findIndex((e) => e === navigationItem);\n if (allItems.length === 0) {\n return;\n }\n let nextIndex: number = currentIndex;\n switch (e.key) {\n case 'ArrowUp':\n nextIndex += -1;\n break;\n case 'ArrowDown':\n nextIndex += 1;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = -1;\n break;\n }\n // We already checked if allItems.length = 0 above\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n nextIndex = getCircularIndex(nextIndex, allItems.length)!;\n onNavigate && onNavigate(allItems[nextIndex]);\n break;\n default: {\n if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {\n // A-Z\n e.preventDefault();\n\n if (\n itemSearchStr.current.length === 0 ||\n itemSearchStr.current.slice(-1) !== e.key\n ) {\n itemSearchStr.current = itemSearchStr.current + e.key;\n }\n clearTimeout(itemSearchClearTimeout.current as any);\n itemSearchClearTimeout.current = setTimeout(() => {\n itemSearchStr.current = '';\n }, 500);\n\n const allItems = scope\n ? scope.current.queryAllNodes(queryScope)\n : [];\n const currentIndex = allItems.findIndex(\n (e) => e === navigationItem\n );\n const searchStr = itemSearchStr.current;\n let nextIndex = -1;\n for (\n let i = searchStr.length === 1 ? 1 : 0;\n i < allItems.length;\n i++\n ) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const idx = getCircularIndex(currentIndex + i, allItems.length)!;\n const dom = allItems[idx];\n const domText = dom.innerText.toLowerCase();\n if (domText.length > 0 && domText.startsWith(searchStr)) {\n nextIndex = idx;\n break;\n }\n }\n if (nextIndex >= 0 && nextIndex < allItems.length) {\n onNavigate && onNavigate(allItems[nextIndex]);\n }\n }\n }\n }\n }\n\n if (!open) {\n return null;\n }\n\n return (\n <MenuListProvider\n value={{\n navigationItem,\n onNavigate,\n }}\n >\n <Comp\n ref={assignMultipleRefs(forwardedRef, menuListRef)}\n id={menuListIdRef.current}\n role=\"menu\"\n aria-labelledby={buttonRef.current?.id}\n data-menu-list=\"\"\n tabIndex=\"-1\"\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n {...otherProps}\n />\n </MenuListProvider>\n );\n }\n);\n"],"mappings":";;;;AACA,SACEA,UADF,EAEEC,SAFF,EAGEC,MAHF,EAIEC,QAJF,EAKEC,eALF,QAMO,OANP;AAQA,SAASC,cAAT,EAAyBC,gBAAzB,QAAiD,WAAjD;AACA,SAASC,kBAAT,QAAmC,qBAAnC;AACA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,QAAT,QAAyB,UAAzB;AACA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,UAA5C;;AAEA,IAAMC,iBAAiB,GACrB,OAAOC,MAAP,KAAkB,WAAlB,GAAgCV,eAAhC,GAAkDH,SADpD;AASA,OAAO,IAAMc,QAAQ,gBAAGf,UAAU,CAChC,SAASe,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;EAAA;;EACrC,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,IADb;EAAA,IAEEC,SAFF,GAMIJ,KANJ,CAEEI,SAFF;EAAA,IAGMC,WAHN,GAMIL,KANJ,CAGEM,EAHF;EAAA,IAIEC,sBAJF,GAMIP,KANJ,CAIEO,sBAJF;EAAA,IAKKC,UALL,4BAMIR,KANJ;;EAQA,IAAMS,aAAa,GAAGvB,MAAM,CAAC,EAAD,CAA5B;EACA,IAAMwB,sBAAsB,GAAGxB,MAAM,EAArC;;EAEA,sBACEG,cAAc,EADhB;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AACU,YAAD,EAAemB,WAAf,CADzB;MAEE,EAAE,EAAET,aAAa,CAACc,OAFpB;MAGE,IAAI,EAAC,MAHP;MAIE,0CAAiBb,SAAS,CAACa,OAA3B,wDAAiB,oBAAmBnB,EAJtC;MAKE,kBAAe,EALjB;MAME,QAAQ,EAAC,IANX;MAOE,SAAS,EAAEV,SAAS,CAACQ,SAAD,EAAYkC,aAAZ;IAPtB,GAQM9B,UARN;EANF,EADF;AAmBD,CA/L+B,CAA3B"}
1
+ {"version":3,"file":"MenuList.js","names":["useCallback","forwardRef","useEffect","useRef","useState","useLayoutEffect","useMenuContext","MenuListProvider","assignMultipleRefs","useOnClickOutside","useScope","queryScope","getCircularIndex","wrapEvent","useEnhancedEffect","window","MenuList","props","forwardedRef","as","Comp","innerAs","onKeyDown","preferredId","id","defaultActiveItemValue","otherProps","interactedOutside","itemSearchStr","itemSearchClearTimeout","menuListIdRef","buttonRef","onChange","openWithArrowKeyRef","open","isContextMenu","navigationItem","setNavigationItem","mounted","setMounted","menuListRef","scope","onNavigate","el","focus","current","allItems","queryAllNodes","index","length","i","dataset","value","handleClickOutside","e","button","target","HTMLElement","contains","preventDefault","handleKeyDown","key","currentIndex","findIndex","nextIndex","ctrlKey","altKey","slice","clearTimeout","setTimeout","searchStr","idx","dom","domText","innerText","toLowerCase","startsWith"],"sources":["../../../src/Menu/MenuList.tsx"],"sourcesContent":["import type { HTMLAttributes, ElementType, KeyboardEvent } from 'react';\nimport {\n useCallback,\n forwardRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n} from 'react';\n\nimport { useMenuContext, MenuListProvider } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { useOnClickOutside } from '../hooks/useOnClickOutside';\nimport { useScope } from '../hooks';\nimport { queryScope } from './scope';\nimport { getCircularIndex, wrapEvent } from '../utils';\n\nconst useEnhancedEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport interface MenuListProps extends HTMLAttributes<HTMLUListElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n defaultActiveItemValue?: string;\n}\n\nexport const MenuList = forwardRef<HTMLUListElement, MenuListProps>(\n function MenuList(props, forwardedRef) {\n const {\n as: Comp = 'ul',\n innerAs,\n onKeyDown,\n id: preferredId,\n defaultActiveItemValue,\n ...otherProps\n } = props;\n\n const interactedOutside = useRef(false);\n const itemSearchStr = useRef('');\n const itemSearchClearTimeout = useRef<ReturnType<typeof setTimeout>>();\n\n const {\n menuListIdRef,\n buttonRef,\n onChange,\n openWithArrowKeyRef,\n open,\n isContextMenu,\n } = useMenuContext();\n\n const [navigationItem, setNavigationItem] = useState<\n HTMLElement | undefined\n >();\n\n const [mounted, setMounted] = useState(false);\n\n const menuListRef = useRef<HTMLUListElement>();\n\n const scope = useScope<HTMLLIElement, HTMLUListElement>(menuListRef);\n\n const onNavigate = (el: HTMLElement) => {\n el.focus();\n setNavigationItem(el);\n };\n\n menuListIdRef.current = preferredId || menuListIdRef.current;\n\n useEnhancedEffect(() => {\n if (!mounted) {\n const allItems = scope.current.queryAllNodes(queryScope);\n let index = getCircularIndex(\n openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0,\n allItems.length\n );\n\n if (defaultActiveItemValue) {\n for (let i = 0; i < allItems.length; i++) {\n if (allItems[i].dataset.value === defaultActiveItemValue) {\n index = i;\n break;\n }\n }\n }\n\n if (index !== null) {\n onNavigate && onNavigate(allItems[index]);\n }\n }\n\n openWithArrowKeyRef.current = null;\n setMounted(true);\n }, [\n mounted,\n navigationItem,\n onNavigate,\n openWithArrowKeyRef,\n scope,\n defaultActiveItemValue,\n ]);\n\n const handleClickOutside = useCallback(\n (e: PointerEvent) => {\n if (!interactedOutside.current) {\n // First interaction should be ignored, because\n // this is what triggered the context menu to open\n interactedOutside.current = true;\n return;\n }\n\n if (isContextMenu.current) {\n if (e.button === 0) {\n onChange(e as any, false);\n }\n } else {\n if (\n e.target instanceof HTMLElement &&\n e.target !== buttonRef.current &&\n !buttonRef.current?.contains(e.target)\n ) {\n onChange(e as any, false);\n }\n }\n e.preventDefault();\n },\n [buttonRef, isContextMenu, onChange]\n );\n\n useOnClickOutside(menuListRef, handleClickOutside, open);\n\n function handleKeyDown(e: KeyboardEvent<HTMLUListElement>) {\n switch (e.key) {\n case 'Escape':\n case 'Tab': {\n onChange(e, false);\n e.preventDefault(); // prevents focusing on next element, because we will be handling it\n itemSearchStr.current = '';\n buttonRef.current?.focus();\n break;\n }\n case 'Home':\n case 'End':\n case 'ArrowDown':\n case 'ArrowUp':\n e.preventDefault();\n itemSearchStr.current = '';\n const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];\n const currentIndex = allItems.findIndex((e) => e === navigationItem);\n if (allItems.length === 0) {\n return;\n }\n let nextIndex: number = currentIndex;\n switch (e.key) {\n case 'ArrowUp':\n nextIndex += -1;\n break;\n case 'ArrowDown':\n nextIndex += 1;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = -1;\n break;\n }\n // We already checked if allItems.length = 0 above\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n nextIndex = getCircularIndex(nextIndex, allItems.length)!;\n onNavigate && onNavigate(allItems[nextIndex]);\n break;\n default: {\n if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {\n // A-Z\n e.preventDefault();\n\n if (\n itemSearchStr.current.length === 0 ||\n itemSearchStr.current.slice(-1) !== e.key\n ) {\n itemSearchStr.current = itemSearchStr.current + e.key;\n }\n clearTimeout(itemSearchClearTimeout.current as any);\n itemSearchClearTimeout.current = setTimeout(() => {\n itemSearchStr.current = '';\n }, 500);\n\n const allItems = scope\n ? scope.current.queryAllNodes(queryScope)\n : [];\n const currentIndex = allItems.findIndex(\n (e) => e === navigationItem\n );\n const searchStr = itemSearchStr.current;\n let nextIndex = -1;\n for (\n let i = searchStr.length === 1 ? 1 : 0;\n i < allItems.length;\n i++\n ) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const idx = getCircularIndex(currentIndex + i, allItems.length)!;\n const dom = allItems[idx];\n const domText = dom.innerText.toLowerCase();\n if (domText.length > 0 && domText.startsWith(searchStr)) {\n nextIndex = idx;\n break;\n }\n }\n if (nextIndex >= 0 && nextIndex < allItems.length) {\n onNavigate && onNavigate(allItems[nextIndex]);\n }\n }\n }\n }\n }\n\n if (!open) {\n interactedOutside.current = false;\n return null;\n }\n\n return (\n <MenuListProvider\n value={{\n navigationItem,\n onNavigate,\n }}\n >\n <Comp\n ref={assignMultipleRefs(forwardedRef, menuListRef)}\n as={innerAs}\n id={menuListIdRef.current}\n role=\"menu\"\n aria-labelledby={buttonRef.current?.id}\n data-menu-list=\"\"\n tabIndex=\"-1\"\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n {...otherProps}\n />\n </MenuListProvider>\n );\n }\n);\n"],"mappings":";;;;AACA,SACEA,WADF,EAEEC,UAFF,EAGEC,SAHF,EAIEC,MAJF,EAKEC,QALF,EAMEC,eANF,QAOO,OAPP;AASA,SAASC,cAAT,EAAyBC,gBAAzB,QAAiD,WAAjD;AACA,SAASC,kBAAT,QAAmC,qBAAnC;AACA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,QAAT,QAAyB,UAAzB;AACA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,UAA5C;;AAEA,IAAMC,iBAAiB,GACrB,OAAOC,MAAP,KAAkB,WAAlB,GAAgCV,eAAhC,GAAkDH,SADpD;AASA,OAAO,IAAMc,QAAQ,gBAAGf,UAAU,CAChC,SAASe,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;EAAA;;EACrC,gBAOID,KAPJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,IADb;EAAA,IAEEC,OAFF,GAOIJ,KAPJ,CAEEI,OAFF;EAAA,IAGEC,SAHF,GAOIL,KAPJ,CAGEK,SAHF;EAAA,IAIMC,WAJN,GAOIN,KAPJ,CAIEO,EAJF;EAAA,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B,CAA5B;cACA,IAAMuB,GAAG,GAAG1B,SAAQ,CAACyB,GAAD,CAApB;cACA,IAAME,OAAO,GAAGD,GAAG,CAACE,SAAJ,CAAcC,WAAd,EAAhB;;cACA,IAAIF,OAAO,CAACxB,MAAR,GAAiB,CAAjB,IAAsBwB,OAAO,CAACG,UAAR,CAAmBN,SAAnB,CAA1B,EAAyD;gBACvDN,UAAS,GAAGO,GAAZ;gBACA;cACD;YACF;;YACD,IAAIP,UAAS,IAAI,CAAb,IAAkBA,UAAS,GAAGlB,SAAQ,CAACG,MAA3C,EAAmD;cACjDP,UAAU,IAAIA,UAAU,CAACI,SAAQ,CAACkB,UAAD,CAAT,CAAxB;YACD;UACF;QACF;IAlFH;EAoFD;;EAED,IAAI,CAAC9B,IAAL,EAAW;IACTP,iBAAiB,CAACkB,OAAlB,GAA4B,KAA5B;IACA,OAAO,IAAP;EACD;;EAED,oBACE,KAAC,gBAAD;IACE,KAAK,EAAE;MACLT,cAAc,EAAdA,cADK;MAELM,UAAU,EAAVA;IAFK,CADT;IAAA,uBAME,KAAC,IAAD;MACE,GAAG,EAAElC,kBAAkB,CAACU,YAAD,EAAesB,WAAf,CADzB;MAEE,EAAE,EAAEnB,OAFN;MAGE,EAAE,EAAES,aAAa,CAACe,OAHpB;MAIE,IAAI,EAAC,MAJP;MAKE,0CAAiBd,SAAS,CAACc,OAA3B,wDAAiB,oBAAmBrB,EALtC;MAME,kBAAe,EANjB;MAOE,QAAQ,EAAC,IAPX;MAQE,SAAS,EAAEX,SAAS,CAACS,SAAD,EAAYsC,aAAZ;IARtB,GASMlC,UATN;EANF,EADF;AAoBD,CAvN+B,CAA3B"}
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["as"];
3
+ var _excluded = ["as", "innerAs"];
4
4
  import { forwardRef } from 'react';
5
5
  import { Popper } from '../Popper';
6
6
  import { useMenuContext } from './context';
@@ -8,11 +8,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
8
8
  export var MenuPopover = /*#__PURE__*/forwardRef(function MenuPopover(props, forwardedRef) {
9
9
  var _props$as = props.as,
10
10
  as = _props$as === void 0 ? 'div' : _props$as,
11
+ innerAs = props.innerAs,
11
12
  otherProps = _objectWithoutProperties(props, _excluded);
12
13
 
13
14
  var _useMenuContext = useMenuContext(),
14
15
  buttonRef = _useMenuContext.buttonRef,
15
- open = _useMenuContext.open;
16
+ open = _useMenuContext.open,
17
+ offsetFn = _useMenuContext.offsetFn,
18
+ isContextMenu = _useMenuContext.isContextMenu;
16
19
 
17
20
  if (!open) {
18
21
  return null;
@@ -20,8 +23,11 @@ export var MenuPopover = /*#__PURE__*/forwardRef(function MenuPopover(props, for
20
23
 
21
24
  return /*#__PURE__*/_jsx(Popper, _extends({
22
25
  as: as,
26
+ innerAs: innerAs,
23
27
  ref: forwardedRef,
24
- anchorEl: buttonRef
28
+ anchorEl: buttonRef,
29
+ offsetFn: offsetFn,
30
+ placement: isContextMenu.current ? 'bottom-start' : undefined
25
31
  }, otherProps));
26
32
  });
27
33
  //# sourceMappingURL=MenuPopover.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MenuPopover.js","names":["forwardRef","Popper","useMenuContext","MenuPopover","props","forwardedRef","as","otherProps","buttonRef","open"],"sources":["../../../src/Menu/MenuPopover.tsx"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport { forwardRef } from 'react';\n\nimport type { PopperProps } from '../Popper';\nimport { Popper } from '../Popper';\nimport { useMenuContext } from './context';\n\nexport interface MenuPopoverProps extends Omit<PopperProps, 'anchorEl'> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n}\n\nexport const MenuPopover = forwardRef<HTMLDivElement, MenuPopoverProps>(\n function MenuPopover(props, forwardedRef) {\n const { as = 'div', ...otherProps } = props;\n const { buttonRef, open } = useMenuContext();\n\n if (!open) {\n return null;\n }\n\n return (\n <Popper as={as} ref={forwardedRef} anchorEl={buttonRef} {...otherProps} />\n );\n }\n);\n"],"mappings":";;;AACA,SAASA,UAAT,QAA2B,OAA3B;AAGA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,cAAT,QAA+B,WAA/B;;AAQA,OAAO,IAAMC,WAAW,gBAAGH,UAAU,CACnC,SAASG,WAAT,CAAqBC,KAArB,EAA4BC,YAA5B,EAA0C;EACxC,gBAAsCD,KAAtC,CAAQE,EAAR;EAAA,IAAQA,EAAR,0BAAa,KAAb;EAAA,IAAuBC,UAAvB,4BAAsCH,KAAtC;;EACA,sBAA4BF,cAAc,EAA1C;EAAA,IAAQM,SAAR,mBAAQA,SAAR;EAAA,IAAmBC,IAAnB,mBAAmBA,IAAnB;;EAEA,IAAI,CAACA,IAAL,EAAW;IACT,OAAO,IAAP;EACD;;EAED,oBACE,KAAC,MAAD;IAAQ,EAAE,EAAEH,EAAZ;IAAgB,GAAG,EAAED,YAArB;IAAmC,QAAQ,EAAEG;EAA7C,GAA4DD,UAA5D,EADF;AAGD,CAZkC,CAA9B"}
1
+ {"version":3,"file":"MenuPopover.js","names":["forwardRef","Popper","useMenuContext","MenuPopover","props","forwardedRef","as","innerAs","otherProps","buttonRef","open","offsetFn","isContextMenu","current","undefined"],"sources":["../../../src/Menu/MenuPopover.tsx"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport { forwardRef } from 'react';\n\nimport type { PopperProps } from '../Popper';\nimport { Popper } from '../Popper';\nimport { useMenuContext } from './context';\n\nexport interface MenuPopoverProps extends Omit<PopperProps, 'anchorEl'> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n}\n\nexport const MenuPopover = forwardRef<HTMLDivElement, MenuPopoverProps>(\n function MenuPopover(props, forwardedRef) {\n const { as = 'div', innerAs, ...otherProps } = props;\n const { buttonRef, open, offsetFn, isContextMenu } = useMenuContext();\n\n if (!open) {\n return null;\n }\n\n return (\n <Popper\n as={as}\n innerAs={innerAs}\n ref={forwardedRef}\n anchorEl={buttonRef}\n offsetFn={offsetFn}\n placement={isContextMenu.current ? 'bottom-start' : undefined}\n {...otherProps}\n />\n );\n }\n);\n"],"mappings":";;;AACA,SAASA,UAAT,QAA2B,OAA3B;AAGA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,cAAT,QAA+B,WAA/B;;AAQA,OAAO,IAAMC,WAAW,gBAAGH,UAAU,CACnC,SAASG,WAAT,CAAqBC,KAArB,EAA4BC,YAA5B,EAA0C;EACxC,gBAA+CD,KAA/C,CAAQE,EAAR;EAAA,IAAQA,EAAR,0BAAa,KAAb;EAAA,IAAoBC,OAApB,GAA+CH,KAA/C,CAAoBG,OAApB;EAAA,IAAgCC,UAAhC,4BAA+CJ,KAA/C;;EACA,sBAAqDF,cAAc,EAAnE;EAAA,IAAQO,SAAR,mBAAQA,SAAR;EAAA,IAAmBC,IAAnB,mBAAmBA,IAAnB;EAAA,IAAyBC,QAAzB,mBAAyBA,QAAzB;EAAA,IAAmCC,aAAnC,mBAAmCA,aAAnC;;EAEA,IAAI,CAACF,IAAL,EAAW;IACT,OAAO,IAAP;EACD;;EAED,oBACE,KAAC,MAAD;IACE,EAAE,EAAEJ,EADN;IAEE,OAAO,EAAEC,OAFX;IAGE,GAAG,EAAEF,YAHP;IAIE,QAAQ,EAAEI,SAJZ;IAKE,QAAQ,EAAEE,QALZ;IAME,SAAS,EAAEC,aAAa,CAACC,OAAd,GAAwB,cAAxB,GAAyCC;EANtD,GAOMN,UAPN,EADF;AAWD,CApBkC,CAA9B"}
@@ -1,15 +1,19 @@
1
- import type { KeyboardEvent, MouseEvent, MutableRefObject, PointerEvent } from 'react';
1
+ import type { OffsetsFunction } from '@popperjs/core/lib/modifiers/offset';
2
+ import type { Dispatch, KeyboardEvent, MouseEvent, MutableRefObject, PointerEvent, SetStateAction } from 'react';
2
3
  export declare type ItemObject = {
3
4
  text: string;
4
5
  value: any;
5
6
  id: string | undefined;
6
7
  };
7
8
  export interface MenuContextProps {
8
- buttonRef: MutableRefObject<HTMLButtonElement | null>;
9
+ buttonRef: MutableRefObject<HTMLElement | null>;
9
10
  menuListIdRef: MutableRefObject<undefined | string>;
10
11
  openWithArrowKeyRef: MutableRefObject<string | null>;
11
- onChange?: (e: KeyboardEvent<HTMLElement> | MouseEvent<HTMLElement> | PointerEvent<HTMLElement>, isOpen: boolean) => void;
12
+ onChange: (e: KeyboardEvent<HTMLElement> | MouseEvent<HTMLElement> | PointerEvent<HTMLElement>, isOpen: boolean) => void;
12
13
  open: boolean;
14
+ offsetFn: OffsetsFunction | undefined;
15
+ setOffsetFn: Dispatch<SetStateAction<OffsetsFunction | undefined>>;
16
+ isContextMenu: MutableRefObject<boolean>;
13
17
  }
14
18
  export declare const MenuProvider: import("react").Provider<MenuContextProps>;
15
19
  export declare const useMenuContext: () => MenuContextProps;
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":["createContext","useContext","menuContext","MenuProvider","Provider","useMenuContext","menuListContext","MenuListProvider","useMenuListContext"],"sources":["../../../src/Menu/context.ts"],"sourcesContent":["import type {\n KeyboardEvent,\n MouseEvent,\n MutableRefObject,\n PointerEvent,\n} from 'react';\nimport { createContext, useContext } from 'react';\n\nexport type ItemObject = { text: string; value: any; id: string | undefined };\n\n// MenuRoot\nexport interface MenuContextProps {\n buttonRef: MutableRefObject<HTMLButtonElement | null>;\n menuListIdRef: MutableRefObject<undefined | string>;\n openWithArrowKeyRef: MutableRefObject<string | null>;\n onChange?: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open: boolean;\n}\n\nconst menuContext = createContext<MenuContextProps>(null as any);\nexport const { Provider: MenuProvider } = menuContext;\nexport const useMenuContext = () => useContext(menuContext);\n\n// MenuList\nexport interface MenuListContextProps {\n navigationItem: HTMLElement | undefined;\n onNavigate: undefined | ((idx: HTMLElement) => void);\n}\n\nconst menuListContext = createContext<MenuListContextProps>(null as any);\nexport const MenuListProvider = menuListContext.Provider;\nexport const useMenuListContext = () => useContext(menuListContext);\n"],"mappings":"AAMA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAmBA,IAAMC,WAAW,gBAAGF,aAAa,CAAmB,IAAnB,CAAjC;AACO,IAAkBG,YAAlB,GAAmCD,WAAnC,CAAQE,QAAR;;AACP,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB;EAAA,OAAMJ,UAAU,CAACC,WAAD,CAAhB;AAAA,CAAvB,C,CAEP;;AAMA,IAAMI,eAAe,gBAAGN,aAAa,CAAuB,IAAvB,CAArC;AACA,OAAO,IAAMO,gBAAgB,GAAGD,eAAe,CAACF,QAAzC;AACP,OAAO,IAAMI,kBAAkB,GAAG,SAArBA,kBAAqB;EAAA,OAAMP,UAAU,CAACK,eAAD,CAAhB;AAAA,CAA3B"}
1
+ {"version":3,"file":"context.js","names":["createContext","useContext","menuContext","MenuProvider","Provider","useMenuContext","menuListContext","MenuListProvider","useMenuListContext"],"sources":["../../../src/Menu/context.ts"],"sourcesContent":["import type { OffsetsFunction } from '@popperjs/core/lib/modifiers/offset';\nimport type {\n Dispatch,\n KeyboardEvent,\n MouseEvent,\n MutableRefObject,\n PointerEvent,\n SetStateAction,\n} from 'react';\nimport { createContext, useContext } from 'react';\n\nexport type ItemObject = { text: string; value: any; id: string | undefined };\n\n// MenuRoot\nexport interface MenuContextProps {\n buttonRef: MutableRefObject<HTMLElement | null>;\n menuListIdRef: MutableRefObject<undefined | string>;\n openWithArrowKeyRef: MutableRefObject<string | null>;\n onChange: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open: boolean;\n offsetFn: OffsetsFunction | undefined;\n setOffsetFn: Dispatch<SetStateAction<OffsetsFunction | undefined>>;\n isContextMenu: MutableRefObject<boolean>;\n}\n\nconst menuContext = createContext<MenuContextProps>(null as any);\nexport const { Provider: MenuProvider } = menuContext;\nexport const useMenuContext = () => useContext(menuContext);\n\n// MenuList\nexport interface MenuListContextProps {\n navigationItem: HTMLElement | undefined;\n onNavigate: undefined | ((idx: HTMLElement) => void);\n}\n\nconst menuListContext = createContext<MenuListContextProps>(null as any);\nexport const MenuListProvider = menuListContext.Provider;\nexport const useMenuListContext = () => useContext(menuListContext);\n"],"mappings":"AASA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAsBA,IAAMC,WAAW,gBAAGF,aAAa,CAAmB,IAAnB,CAAjC;AACO,IAAkBG,YAAlB,GAAmCD,WAAnC,CAAQE,QAAR;;AACP,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB;EAAA,OAAMJ,UAAU,CAACC,WAAD,CAAhB;AAAA,CAAvB,C,CAEP;;AAMA,IAAMI,eAAe,gBAAGN,aAAa,CAAuB,IAAvB,CAArC;AACA,OAAO,IAAMO,gBAAgB,GAAGD,eAAe,CAACF,QAAzC;AACP,OAAO,IAAMI,kBAAkB,GAAG,SAArBA,kBAAqB;EAAA,OAAMP,UAAU,CAACK,eAAD,CAAhB;AAAA,CAA3B"}
@@ -1,5 +1,6 @@
1
1
  export * from './Menu';
2
2
  export * from './MenuButton';
3
+ export * from './ContextMenuTrigger';
3
4
  export * from './MenuItem';
4
5
  export * from './MenuList';
5
6
  export * from './MenuPopover';
@@ -1,5 +1,6 @@
1
1
  export * from './Menu';
2
2
  export * from './MenuButton';
3
+ export * from './ContextMenuTrigger';
3
4
  export * from './MenuItem';
4
5
  export * from './MenuList';
5
6
  export * from './MenuPopover';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/Menu/index.ts"],"sourcesContent":["export * from './Menu';\nexport * from './MenuButton';\nexport * from './MenuItem';\nexport * from './MenuList';\nexport * from './MenuPopover';\n"],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,cAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd;AACA,cAAc,eAAd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/Menu/index.ts"],"sourcesContent":["export * from './Menu';\nexport * from './MenuButton';\nexport * from './ContextMenuTrigger';\nexport * from './MenuItem';\nexport * from './MenuList';\nexport * from './MenuPopover';\n"],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,cAAd;AACA,cAAc,sBAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd;AACA,cAAc,eAAd"}