mantine-contextmenu 6.0.2 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +21 -21
  2. package/dist/cjs/ContextMenu.js +60 -0
  3. package/dist/cjs/ContextMenu.js.map +1 -0
  4. package/dist/cjs/ContextMenuDivider.js +14 -0
  5. package/dist/cjs/ContextMenuDivider.js.map +1 -0
  6. package/dist/cjs/ContextMenuItem.js +53 -0
  7. package/dist/cjs/ContextMenuItem.js.map +1 -0
  8. package/dist/cjs/ContextMenuPortal.js +39 -0
  9. package/dist/cjs/ContextMenuPortal.js.map +1 -0
  10. package/dist/cjs/ContextMenuProvider.js +58 -0
  11. package/dist/cjs/ContextMenuProvider.js.map +1 -0
  12. package/dist/cjs/index.js +22 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/types.js +3 -0
  15. package/dist/cjs/types.js.map +1 -0
  16. package/dist/cjs/utils.js +27 -0
  17. package/dist/cjs/utils.js.map +1 -0
  18. package/dist/css/styles.css +53 -0
  19. package/dist/css/styles.layer.css +61 -0
  20. package/dist/esm/ContextMenu.js +37 -0
  21. package/dist/esm/ContextMenu.js.map +1 -0
  22. package/dist/esm/ContextMenuDivider.js +9 -0
  23. package/dist/esm/ContextMenuDivider.js.map +1 -0
  24. package/dist/esm/ContextMenuItem.js +44 -0
  25. package/dist/esm/ContextMenuItem.js.map +1 -0
  26. package/dist/esm/ContextMenuPortal.js +12 -0
  27. package/dist/esm/ContextMenuPortal.js.map +1 -0
  28. package/dist/esm/ContextMenuProvider.js +41 -0
  29. package/dist/esm/ContextMenuProvider.js.map +1 -0
  30. package/dist/esm/index.js +6 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/types.js +2 -0
  33. package/dist/esm/types.js.map +1 -0
  34. package/dist/esm/utils.js +18 -0
  35. package/dist/esm/utils.js.map +1 -0
  36. package/dist/{ContextMenu.d.ts → types/ContextMenu.d.ts} +1 -2
  37. package/dist/types/ContextMenuDivider.d.ts +3 -0
  38. package/dist/{ContextMenuItem.d.ts → types/ContextMenuItem.d.ts} +1 -2
  39. package/dist/{ContextMenuPortal.d.ts → types/ContextMenuPortal.d.ts} +0 -1
  40. package/dist/{ContextMenuProvider.d.ts → types/ContextMenuProvider.d.ts} +0 -1
  41. package/dist/{index.d.ts → types/index.d.ts} +1 -2
  42. package/dist/{types.d.ts → types/types.d.ts} +8 -19
  43. package/dist/types/utils.d.ts +18 -0
  44. package/package.json +56 -19
  45. package/LICENSE +0 -21
  46. package/dist/ContextMenu.d.ts.map +0 -1
  47. package/dist/ContextMenuDivider.d.ts +0 -9
  48. package/dist/ContextMenuDivider.d.ts.map +0 -1
  49. package/dist/ContextMenuItem.d.ts.map +0 -1
  50. package/dist/ContextMenuPortal.d.ts.map +0 -1
  51. package/dist/ContextMenuProvider.d.ts.map +0 -1
  52. package/dist/index.cjs +0 -2
  53. package/dist/index.cjs.map +0 -7
  54. package/dist/index.d.ts.map +0 -1
  55. package/dist/index.mjs +0 -2
  56. package/dist/index.mjs.map +0 -7
  57. package/dist/types.d.ts.map +0 -1
  58. package/dist/utils.d.ts +0 -8
  59. package/dist/utils.d.ts.map +0 -1
@@ -0,0 +1,9 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Box, useMantineTheme } from '@mantine/core';
4
+ import { cs } from './utils';
5
+ export function ContextMenuDivider({ className, style }) {
6
+ const theme = useMantineTheme();
7
+ return (_jsx(Box, { className: cs('mantine-cm-divider', className), style: typeof style === 'function' ? style(theme) : style }));
8
+ }
9
+ //# sourceMappingURL=ContextMenuDivider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuDivider.js","sourceRoot":"","sources":["../../package/ContextMenuDivider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAI7B,MAAM,UAAU,kBAAkB,CAAC,EAAE,SAAS,EAAE,KAAK,EAA2B;IAC9E,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,OAAO,CACL,KAAC,GAAG,IAAC,SAAS,EAAE,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAI,CACnH,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Box, useMantineTheme } from '@mantine/core';\nimport { ContextMenuItemOptions } from './types';\nimport { cs } from './utils';\n\nexport type ContextMenuDividerProps = Pick<ContextMenuItemOptions, 'className' | 'style'>;\n\nexport function ContextMenuDivider({ className, style }: ContextMenuDividerProps) {\n const theme = useMantineTheme();\n return (\n <Box className={cs('mantine-cm-divider', className)} style={typeof style === 'function' ? style(theme) : style} />\n );\n}\n"]}
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Box, UnstyledButton, getThemeColor, rgba, useMantineTheme } from '@mantine/core';
4
+ import { useRef, useState } from 'react';
5
+ import { ContextMenu } from './ContextMenu';
6
+ import { cs } from './utils';
7
+ export function ContextMenuItem({ className, style, icon, title, color, disabled, onClick, onHide, items, }) {
8
+ const ref = useRef(null);
9
+ const [submenuPosition, setSubmenuPosition] = useState(null);
10
+ const handleClick = onClick
11
+ ? (e) => {
12
+ onHide();
13
+ onClick(e);
14
+ }
15
+ : undefined;
16
+ const showSubmenu = () => {
17
+ const { top: y, right: x } = ref.current.getBoundingClientRect();
18
+ setSubmenuPosition({ x, y });
19
+ };
20
+ const hideSubmenu = () => {
21
+ setSubmenuPosition(null);
22
+ };
23
+ const hasItemsAndIsNotDisabled = items && !disabled;
24
+ const theme = useMantineTheme();
25
+ const { colors } = theme;
26
+ const parsedColor = color ? getThemeColor(color, theme) : undefined;
27
+ return (_jsxs("div", { onMouseOver: hasItemsAndIsNotDisabled ? showSubmenu : undefined, onMouseOut: hasItemsAndIsNotDisabled ? hideSubmenu : undefined, children: [_jsxs(UnstyledButton, { ref: ref, style: {
28
+ '--mantine-cm-item-button-color': parsedColor ? parsedColor : 'var(--mantine-color-text)',
29
+ '--mantine-cm-item-button-hover-bg-color-light': parsedColor
30
+ ? rgba(parsedColor, 0.08)
31
+ : rgba(colors.gray[4], 0.25),
32
+ '--mantine-cm-item-button-hover-bg-color-dark': parsedColor
33
+ ? rgba(parsedColor, 0.15)
34
+ : rgba(colors.dark[3], 0.25),
35
+ '--mantine-cm-item-button-pressed-bg-color-light': parsedColor
36
+ ? rgba(parsedColor, 0.2)
37
+ : rgba(colors.gray[4], 0.5),
38
+ '--mantine-cm-item-button-pressed-bg-color-dark': parsedColor
39
+ ? rgba(parsedColor, 0.3)
40
+ : rgba(colors.dark[3], 0.5),
41
+ ...(typeof style === 'function' ? style(theme) : style),
42
+ }, className: cs('mantine-cm-item-button', className), disabled: disabled, onClick: handleClick, children: [icon && (_jsx(Box, { fz: 0, mr: "xs", children: icon })), _jsx("div", { className: 'mantine-cm-item-button-title', children: title }), items && (_jsx(Box, { fz: 10, mt: -2, ml: "xs", children: "\u25B6" }))] }), submenuPosition && _jsx(ContextMenu, { content: items, onHide: onHide, ...submenuPosition })] }));
43
+ }
44
+ //# sourceMappingURL=ContextMenuItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuItem.js","sourceRoot":"","sources":["../../package/ContextMenuItem.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAqB,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE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S,EAAE,8BAA8B,YAAG,KAAK,GAAO,EAC5D,KAAK,IAAI,CACR,KAAC,GAAG,IAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAC,IAAI,uBAEtB,CACP,IACc,EAChB,eAAe,IAAI,KAAC,WAAW,IAAC,OAAO,EAAE,KAA2B,EAAE,MAAM,EAAE,MAAM,KAAM,eAAe,GAAI,IAC1G,CACP,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Box, UnstyledButton, getThemeColor, rgba, useMantineTheme } from '@mantine/core';\nimport { MouseEventHandler, useRef, useState } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport { ContextMenuContent, ContextMenuItemOptions } from './types';\nimport { cs, type WithRequiredProperty } from './utils';\n\nexport function ContextMenuItem({\n className,\n style,\n icon,\n title,\n color,\n disabled,\n onClick,\n onHide,\n items,\n}: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title'> & { onHide: () => void }) {\n const ref = useRef<HTMLButtonElement>(null);\n const [submenuPosition, setSubmenuPosition] = useState<{ x: number; y: number } | null>(null);\n\n const handleClick: MouseEventHandler<HTMLButtonElement> | undefined = onClick\n ? (e) => {\n onHide();\n onClick!(e);\n }\n : undefined;\n\n const showSubmenu = () => {\n const { top: y, right: x } = ref.current!.getBoundingClientRect();\n setSubmenuPosition({ x, y });\n };\n\n const hideSubmenu = () => {\n setSubmenuPosition(null);\n };\n\n const hasItemsAndIsNotDisabled = items && !disabled;\n\n const theme = useMantineTheme();\n const { colors } = theme;\n const parsedColor = color ? getThemeColor(color, theme) : undefined;\n\n return (\n <div\n onMouseOver={hasItemsAndIsNotDisabled ? showSubmenu : undefined}\n onMouseOut={hasItemsAndIsNotDisabled ? hideSubmenu : undefined}\n >\n <UnstyledButton\n ref={ref}\n style={{\n '--mantine-cm-item-button-color': parsedColor ? parsedColor : 'var(--mantine-color-text)',\n '--mantine-cm-item-button-hover-bg-color-light': parsedColor\n ? rgba(parsedColor, 0.08)\n : rgba(colors.gray[4], 0.25),\n '--mantine-cm-item-button-hover-bg-color-dark': parsedColor\n ? rgba(parsedColor, 0.15)\n : rgba(colors.dark[3], 0.25),\n '--mantine-cm-item-button-pressed-bg-color-light': parsedColor\n ? rgba(parsedColor, 0.2)\n : rgba(colors.gray[4], 0.5),\n '--mantine-cm-item-button-pressed-bg-color-dark': parsedColor\n ? rgba(parsedColor, 0.3)\n : rgba(colors.dark[3], 0.5),\n ...(typeof style === 'function' ? style(theme) : style),\n }}\n className={cs('mantine-cm-item-button', className)}\n disabled={disabled}\n onClick={handleClick}\n >\n {icon && (\n <Box fz={0} mr=\"xs\">\n {icon}\n </Box>\n )}\n <div className={'mantine-cm-item-button-title'}>{title}</div>\n {items && (\n <Box fz={10} mt={-2} ml=\"xs\">\n ▶\n </Box>\n )}\n </UnstyledButton>\n {submenuPosition && <ContextMenu content={items as ContextMenuContent} onHide={onHide} {...submenuPosition} />}\n </div>\n );\n}\n"]}
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Portal } from '@mantine/core';
4
+ import { useClickOutside, useWindowEvent } from '@mantine/hooks';
5
+ import { ContextMenu } from './ContextMenu';
6
+ export function ContextMenuPortal({ onHide, ...otherProps }) {
7
+ useWindowEvent('resize', onHide);
8
+ useWindowEvent('scroll', onHide);
9
+ const ref = useClickOutside(onHide);
10
+ return (_jsx(Portal, { ref: ref, children: _jsx(ContextMenu, { ...otherProps, onHide: onHide }) }));
11
+ }
12
+ //# sourceMappingURL=ContextMenuPortal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuPortal.js","sourceRoot":"","sources":["../../package/ContextMenuPortal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AAEnE,MAAM,UAAU,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,EAAoB;IAC3E,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAEpC,OAAO,CACL,KAAC,MAAM,IAAC,GAAG,EAAE,GAAG,YACd,KAAC,WAAW,OAAK,UAAU,EAAE,MAAM,EAAE,MAAM,GAAI,GACxC,CACV,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Portal } from '@mantine/core';\nimport { useClickOutside, useWindowEvent } from '@mantine/hooks';\nimport { ContextMenu, type ContextMenuProps } from './ContextMenu';\n\nexport function ContextMenuPortal({ onHide, ...otherProps }: ContextMenuProps) {\n useWindowEvent('resize', onHide);\n useWindowEvent('scroll', onHide);\n const ref = useClickOutside(onHide);\n\n return (\n <Portal ref={ref}>\n <ContextMenu {...otherProps} onHide={onHide} />\n </Portal>\n );\n}\n"]}
@@ -0,0 +1,41 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { MantineProvider } from '@mantine/core';
4
+ import { createContext, useContext, useState } from 'react';
5
+ import { ContextMenuPortal } from './ContextMenuPortal';
6
+ const MenuContext = createContext(() => () => undefined);
7
+ /**
8
+ * Provider that allows to show a context menu anywhere in your application.
9
+ * If you wrap your application with this provider, you can use the `useContextMenu` hook
10
+ * anywhere in the component tree to access a function that shows the context menu.
11
+ */
12
+ export function ContextMenuProvider({ zIndex = 9999, shadow = 'sm', borderRadius = 'xs', children, }) {
13
+ const [data, setData] = useState(null);
14
+ const destroy = () => {
15
+ setData(null);
16
+ };
17
+ const showContextMenu = (content, options) => (e) => {
18
+ e.preventDefault();
19
+ e.stopPropagation();
20
+ setData({
21
+ x: e.clientX,
22
+ y: e.clientY,
23
+ content,
24
+ zIndex: options?.zIndex || zIndex,
25
+ shadow: options?.shadow || shadow,
26
+ borderRadius: options?.borderRadius || borderRadius,
27
+ className: options?.className,
28
+ style: options?.style,
29
+ classNames: options?.classNames,
30
+ styles: options?.styles,
31
+ });
32
+ };
33
+ return (_jsxs(MenuContext.Provider, { value: showContextMenu, children: [children, _jsx(MantineProvider, { children: data && _jsx(ContextMenuPortal, { onHide: destroy, ...data }) })] }));
34
+ }
35
+ /**
36
+ * Hook returning a function that shows a context menu.
37
+ */
38
+ export function useContextMenu() {
39
+ return useContext(MenuContext);
40
+ }
41
+ //# sourceMappingURL=ContextMenuProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuProvider.js","sourceRoot":"","sources":["../../package/ContextMenuProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,WAAW,GAAG,aAAa,CAA0B,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAElF;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,MAAM,GAAG,IAAI,EACb,MAAM,GAAG,IAAI,EACb,YAAY,GAAG,IAAI,EACnB,QAAQ,GACiB;IACzB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAA2D,IAAI,CAAC,CAAC;IAEjG,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,eAAe,GAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3E,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,CAAC,CAAC,eAAe,EAAE,CAAC;QACpB,OAAO,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,OAAO;YACZ,CAAC,EAAE,CAAC,CAAC,OAAO;YACZ,OAAO;YACP,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,MAAM;YACjC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,MAAM;YACjC,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,YAAY;YACnD,SAAS,EAAE,OAAO,EAAE,SAAS;YAC7B,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,UAAU,EAAE,OAAO,EAAE,UAAU;YAC/B,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CACL,MAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,aACzC,QAAQ,EACT,KAAC,eAAe,cAAE,IAAI,IAAI,KAAC,iBAAiB,IAAC,MAAM,EAAE,OAAO,KAAM,IAAI,GAAI,GAAmB,IACxE,CACxB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC","sourcesContent":["'use client';\n\nimport { MantineProvider } from '@mantine/core';\nimport { createContext, useContext, useState } from 'react';\nimport { ContextMenuInstanceOptions } from './ContextMenu';\nimport { ContextMenuPortal } from './ContextMenuPortal';\nimport type { ContextMenuOptions, ContextMenuProviderProps, ShowContextMenuFunction } from './types';\n\nconst MenuContext = createContext<ShowContextMenuFunction>(() => () => undefined);\n\n/**\n * Provider that allows to show a context menu anywhere in your application.\n * If you wrap your application with this provider, you can use the `useContextMenu` hook\n * anywhere in the component tree to access a function that shows the context menu.\n */\nexport function ContextMenuProvider({\n zIndex = 9999,\n shadow = 'sm',\n borderRadius = 'xs',\n children,\n}: ContextMenuProviderProps) {\n const [data, setData] = useState<(ContextMenuInstanceOptions & ContextMenuOptions) | null>(null);\n\n const destroy = () => {\n setData(null);\n };\n\n const showContextMenu: ShowContextMenuFunction = (content, options) => (e) => {\n e.preventDefault();\n e.stopPropagation();\n setData({\n x: e.clientX,\n y: e.clientY,\n content,\n zIndex: options?.zIndex || zIndex,\n shadow: options?.shadow || shadow,\n borderRadius: options?.borderRadius || borderRadius,\n className: options?.className,\n style: options?.style,\n classNames: options?.classNames,\n styles: options?.styles,\n });\n };\n\n return (\n <MenuContext.Provider value={showContextMenu}>\n {children}\n <MantineProvider>{data && <ContextMenuPortal onHide={destroy} {...data} />}</MantineProvider>\n </MenuContext.Provider>\n );\n}\n\n/**\n * Hook returning a function that shows a context menu.\n */\nexport function useContextMenu() {\n return useContext(MenuContext);\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export * from './ContextMenuDivider';
2
+ export * from './ContextMenuItem';
3
+ export * from './ContextMenuPortal';
4
+ export * from './ContextMenuProvider';
5
+ export * from './utils';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../package/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC","sourcesContent":["export * from './ContextMenuDivider';\nexport * from './ContextMenuItem';\nexport * from './ContextMenuPortal';\nexport * from './ContextMenuProvider';\nexport * from './utils';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../package/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MantineColor, MantineShadow, MantineSize, MantineTheme } from '@mantine/core';\nimport type { CSSProperties, MouseEventHandler, ReactNode } from 'react';\n\nexport type ContextMenuOptions = {\n /**\n * zIndex of context menu\n * @default 9999\n */\n zIndex?: number;\n\n /**\n * Context menu shadow\n * @default 'sm'\n */\n shadow?: MantineShadow;\n\n /**\n * Context menu border radius\n * @default 'xs'\n */\n borderRadius?: MantineSize;\n\n /**\n * Context menu container className\n */\n className?: string;\n\n /**\n * Context menu container style; can be a function that accepts theme and returns a style object\n */\n style?: CSSProperties | ((theme: MantineTheme) => CSSProperties);\n\n /**\n * Context menu elements classNames; an object with `root`, `item` and `divider` keys and class names as values\n * @see https://mantine.dev/styles/styles-api/\n */\n classNames?: Partial<Record<'root' | 'item' | 'divider', string>>;\n\n /**\n * Context menu styles; can be an object with `root`, `item` and `divider` keys and `CSSProperties` as values,\n * or a function that accepts the current theme and returns a similarly structured object\n */\n styles?:\n | Partial<Record<'root' | 'item' | 'divider', CSSProperties>>\n | ((theme: MantineTheme) => Partial<Record<'root' | 'item' | 'divider', CSSProperties>>);\n};\n\nexport type ContextMenuProviderProps = ContextMenuOptions & {\n children: ReactNode;\n};\n\nexport type ContextMenuItemOptions = {\n /**\n * Unique key of the context menu item or divider\n */\n key: string;\n /**\n * Context menu item or divider className\n */\n className?: string;\n\n /**\n * Context menu item or divider style\n */\n style?: CSSProperties | ((theme: MantineTheme) => CSSProperties);\n} & (\n | ({\n /**\n * Optional context menu item icon\n */\n icon?: ReactNode;\n\n /**\n * Optional context menu item title; if not provided, one will be generated automatically by \"humanizing\" the key\n * @default humanize(key)\n */\n title?: ReactNode;\n\n /**\n * Optional context menu item color\n */\n color?: MantineColor;\n\n /**\n * Boolean indicating whether the context menu item is disabled\n */\n disabled?: boolean;\n } & (\n | {\n /**\n * Optional context menu item `onClick` handler; if not provided, a divider will be rendered instead\n */\n onClick: MouseEventHandler<HTMLButtonElement>;\n\n items?: never;\n }\n | {\n onClick?: never;\n\n /**\n * Optional items; if provided, a submenu will be rendered\n */\n items: ContextMenuItemOptions[];\n }\n ))\n | {\n icon?: never;\n title?: never;\n color?: never;\n disabled?: never;\n onClick?: never;\n items?: never;\n }\n);\n\nexport type ContextMenuContent = ContextMenuItemOptions[] | ((close: () => void) => JSX.Element);\n\nexport type ShowContextMenuFunction = (\n /**\n * Context menu content - either an array of context menu items\n * or a function that accepts a close callback and returns context menu content\n */\n content: ContextMenuContent,\n\n /**\n * Context menu options (overrides provider options)\n */\n options?: ContextMenuOptions\n) => MouseEventHandler;\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Utility function that returns a humanized version of a string, e.g. "camelCase" -> "Camel Case"
3
+ */
4
+ export function humanize(value) {
5
+ const str = value
6
+ .replace(/([a-z\d])([A-Z]+)/g, '$1 $2')
7
+ .replace(/\W|_/g, ' ')
8
+ .trim()
9
+ .toLowerCase();
10
+ return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
11
+ }
12
+ /**
13
+ * A very simple utility function that returns a concatenated string of non-empty class names
14
+ */
15
+ export function cs(...args) {
16
+ return args.filter(Boolean).join(' ');
17
+ }
18
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../package/utils.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,MAAM,GAAG,GAAG,KAAK;SACd,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,IAAI,EAAE;SACN,WAAW,EAAE,CAAC;IACjB,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,EAAE,CAAC,GAAG,IAAmC;IACvD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC","sourcesContent":["/**\n * Utility type that makes a property required\n */\nexport type WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\n/**\n * Utility type that makes a property optional\n */\nexport type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/**\n * Utility function that returns a humanized version of a string, e.g. \"camelCase\" -> \"Camel Case\"\n */\nexport function humanize(value: string) {\n const str = value\n .replace(/([a-z\\d])([A-Z]+)/g, '$1 $2')\n .replace(/\\W|_/g, ' ')\n .trim()\n .toLowerCase();\n return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;\n}\n\n/**\n * A very simple utility function that returns a concatenated string of non-empty class names\n */\nexport function cs(...args: (string | undefined | null)[]) {\n return args.filter(Boolean).join(' ');\n}\n"]}
@@ -7,5 +7,4 @@ export type ContextMenuInstanceOptions = {
7
7
  export type ContextMenuProps = ContextMenuOptions & ContextMenuInstanceOptions & {
8
8
  onHide: () => void;
9
9
  };
10
- export declare function ContextMenu({ x, y, content, zIndex, shadow, borderRadius, onHide, className, style, sx, classNames, styles, }: ContextMenuProps): import("react/jsx-runtime").JSX.Element;
11
- //# sourceMappingURL=ContextMenu.d.ts.map
10
+ export declare function ContextMenu({ x, y, content, zIndex, shadow, borderRadius, onHide, className, style, classNames, styles, }: ContextMenuProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { ContextMenuItemOptions } from './types';
2
+ export type ContextMenuDividerProps = Pick<ContextMenuItemOptions, 'className' | 'style'>;
3
+ export declare function ContextMenuDivider({ className, style }: ContextMenuDividerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,5 @@
1
1
  import { ContextMenuItemOptions } from './types';
2
- import { WithRequiredProperty } from './utils';
2
+ import { type WithRequiredProperty } from './utils';
3
3
  export declare function ContextMenuItem({ className, style, icon, title, color, disabled, onClick, onHide, items, }: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title'> & {
4
4
  onHide: () => void;
5
5
  }): import("react/jsx-runtime").JSX.Element;
6
- //# sourceMappingURL=ContextMenuItem.d.ts.map
@@ -1,3 +1,2 @@
1
1
  import { type ContextMenuProps } from './ContextMenu';
2
2
  export declare function ContextMenuPortal({ onHide, ...otherProps }: ContextMenuProps): import("react/jsx-runtime").JSX.Element;
3
- //# sourceMappingURL=ContextMenuPortal.d.ts.map
@@ -9,4 +9,3 @@ export declare function ContextMenuProvider({ zIndex, shadow, borderRadius, chil
9
9
  * Hook returning a function that shows a context menu.
10
10
  */
11
11
  export declare function useContextMenu(): ShowContextMenuFunction;
12
- //# sourceMappingURL=ContextMenuProvider.d.ts.map
@@ -2,5 +2,4 @@ export * from './ContextMenuDivider';
2
2
  export * from './ContextMenuItem';
3
3
  export * from './ContextMenuPortal';
4
4
  export * from './ContextMenuProvider';
5
- export { humanize } from './utils';
6
- //# sourceMappingURL=index.d.ts.map
5
+ export * from './utils';
@@ -1,4 +1,4 @@
1
- import type { ClassNames, MantineColor, MantineNumberSize, MantineShadow, Styles, Sx } from '@mantine/core';
1
+ import type { MantineColor, MantineShadow, MantineSize, MantineTheme } from '@mantine/core';
2
2
  import type { CSSProperties, MouseEventHandler, ReactNode } from 'react';
3
3
  export type ContextMenuOptions = {
4
4
  /**
@@ -15,30 +15,25 @@ export type ContextMenuOptions = {
15
15
  * Context menu border radius
16
16
  * @default 'xs'
17
17
  */
18
- borderRadius?: MantineNumberSize;
18
+ borderRadius?: MantineSize;
19
19
  /**
20
20
  * Context menu container className
21
21
  */
22
22
  className?: string;
23
23
  /**
24
- * Context menu container style
24
+ * Context menu container style; can be a function that accepts theme and returns a style object
25
25
  */
26
- style?: CSSProperties;
27
- /**
28
- * Context menu container sx
29
- * @see https://mantine.dev/styles/sx/
30
- */
31
- sx?: Sx | (Sx | undefined)[];
26
+ style?: CSSProperties | ((theme: MantineTheme) => CSSProperties);
32
27
  /**
33
28
  * Context menu elements classNames; an object with `root`, `item` and `divider` keys and class names as values
34
29
  * @see https://mantine.dev/styles/styles-api/
35
30
  */
36
- classNames?: ClassNames<'root' | 'item' | 'divider'>;
31
+ classNames?: Partial<Record<'root' | 'item' | 'divider', string>>;
37
32
  /**
38
33
  * Context menu styles; can be an object with `root`, `item` and `divider` keys and `CSSProperties` as values,
39
- * or a function that accepts the current theme and returns a styles object
34
+ * or a function that accepts the current theme and returns a similarly structured object
40
35
  */
41
- styles?: Styles<'root' | 'item' | 'divider', CSSProperties>;
36
+ styles?: Partial<Record<'root' | 'item' | 'divider', CSSProperties>> | ((theme: MantineTheme) => Partial<Record<'root' | 'item' | 'divider', CSSProperties>>);
42
37
  };
43
38
  export type ContextMenuProviderProps = ContextMenuOptions & {
44
39
  children: ReactNode;
@@ -52,15 +47,10 @@ export type ContextMenuItemOptions = {
52
47
  * Context menu item or divider className
53
48
  */
54
49
  className?: string;
55
- /**
56
- * Context menu item or divider sx
57
- * @see https://mantine.dev/styles/sx/
58
- */
59
- sx?: Sx | (Sx | undefined)[];
60
50
  /**
61
51
  * Context menu item or divider style
62
52
  */
63
- style?: CSSProperties;
53
+ style?: CSSProperties | ((theme: MantineTheme) => CSSProperties);
64
54
  } & (({
65
55
  /**
66
56
  * Optional context menu item icon
@@ -110,4 +100,3 @@ content: ContextMenuContent,
110
100
  * Context menu options (overrides provider options)
111
101
  */
112
102
  options?: ContextMenuOptions) => MouseEventHandler;
113
- //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Utility type that makes a property required
3
+ */
4
+ export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
5
+ [Property in Key]-?: Type[Property];
6
+ };
7
+ /**
8
+ * Utility type that makes a property optional
9
+ */
10
+ export type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
11
+ /**
12
+ * Utility function that returns a humanized version of a string, e.g. "camelCase" -> "Camel Case"
13
+ */
14
+ export declare function humanize(value: string): string;
15
+ /**
16
+ * A very simple utility function that returns a concatenated string of non-empty class names
17
+ */
18
+ export declare function cs(...args: (string | undefined | null)[]): string;
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "mantine-contextmenu",
3
- "version": "6.0.2",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "Enhance your Mantine UI applications usability with customizable context menus",
5
5
  "keywords": [
6
6
  "ui",
7
7
  "mantine",
8
- "mantine-v6",
9
8
  "context",
10
9
  "menu",
11
10
  "context-menu",
@@ -38,32 +37,70 @@
38
37
  "type": "github",
39
38
  "url": "https://github.com/sponsors/icflorescu"
40
39
  },
41
- "main": "dist/index.cjs",
42
- "module": "dist/index.mjs",
43
- "types": "dist/index.d.ts",
40
+ "main": "./dist/cjs/index.js",
41
+ "module": "./dist/esm/index.js",
42
+ "types": "./dist/types/index.d.ts",
43
+ "exports": {
44
+ ".": {
45
+ "import": {
46
+ "types": "./dist/types/index.d.ts",
47
+ "default": "./dist/esm/index.js"
48
+ },
49
+ "require": {
50
+ "types": "./dist/types/index.d.ts",
51
+ "default": "./dist/cjs/index.js"
52
+ }
53
+ },
54
+ "./styles.css": "./dist/css/styles.css",
55
+ "./styles.layer.css": "./dist/css/styles.layer.css"
56
+ },
44
57
  "files": [
45
- "dist",
46
- "README.md",
47
- "LICENSE"
58
+ "./dist",
59
+ "./README.md",
60
+ "./LICENSE"
48
61
  ],
49
62
  "scripts": {
50
- "dev": "rm -rf dist",
51
- "build": "rm -rf dist && NODE_NO_WARNINGS=1 node build.mjs && tsc --emitDeclarationOnly",
52
- "postbuild": "cp -f ../LICENSE LICENSE && cp -f ../README.md README.md",
53
- "lint": "eslint . --ext=.ts,.tsx && tsc --noEmit"
63
+ "dev": "next dev",
64
+ "build:package": "rm -rf dist; tsc -p package/tsconfig.esm.json; tsc -p package/tsconfig.cjs.json; postcss package/styles*.css --dir dist/css",
65
+ "build:docs": "next build",
66
+ "build": "yarn build:package && yarn build:docs",
67
+ "lint": "eslint .",
68
+ "format": "prettier --write ."
54
69
  },
55
70
  "devDependencies": {
56
- "@mantine/core": "^6.0.21",
57
- "@mantine/hooks": "^6.0.21",
71
+ "@ducanh2912/next-pwa": "^9.7.1",
72
+ "@mantine/code-highlight": "^7.1.3",
73
+ "@mantine/core": "^7.1.3",
74
+ "@mantine/hooks": "^7.1.3",
75
+ "@mantine/notifications": "^7.1.3",
76
+ "@tabler/icons-react": "^2.39.0",
77
+ "@types/lodash": "^4.14.199",
78
+ "@types/node": "^20.8.6",
58
79
  "@types/react": "^18.2.28",
59
80
  "@types/react-dom": "^18.2.13",
60
- "esbuild": "^0.19.4",
81
+ "@typescript-eslint/eslint-plugin": "^6.7.4",
82
+ "@typescript-eslint/parser": "^6.7.4",
83
+ "clsx": "^2.0.0",
84
+ "eslint": "^8.51.0",
85
+ "eslint-config-next": "^13.5.5",
86
+ "eslint-config-prettier": "^9.0.0",
87
+ "lodash": "^4.17.21",
88
+ "next": "13.5.5",
89
+ "postcss": "^8.4.31",
90
+ "postcss-cli": "^10.1.0",
91
+ "postcss-import": "^15.1.0",
92
+ "postcss-preset-mantine": "^1.9.0",
93
+ "postcss-simple-vars": "^7.0.1",
94
+ "prettier": "^3.0.3",
61
95
  "react": "^18.2.0",
62
- "typescript": "^5.2.2"
96
+ "react-dom": "^18.2.0",
97
+ "sharp": "^0.32.6",
98
+ "swr": "^2.2.4",
99
+ "typescript": "^5.2.2",
100
+ "webpack": "^5.89.0"
63
101
  },
64
102
  "peerDependencies": {
65
- "@mantine/core": ">=6 <=6.0.17 || >=6.0.19 < 7",
66
- "@mantine/hooks": ">=6 <=6.0.17 || >=6.0.19 < 7",
67
- "react": ">=18"
103
+ "@mantine/core": ">=7",
104
+ "@mantine/hooks": ">=7"
68
105
  }
69
106
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Ionuț-Cristian Florescu
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextMenu.d.ts","sourceRoot":"","sources":["../ContextMenu.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AActE,MAAM,MAAM,0BAA0B,GAAG;IACvC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAC/C,0BAA0B,GAAG;IAC3B,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEJ,wBAAgB,WAAW,CAAC,EAC1B,CAAC,EACD,CAAC,EACD,OAAO,EACP,MAAM,EACN,MAAM,EACN,YAAY,EACZ,MAAM,EACN,SAAS,EACT,KAAK,EACL,EAAE,EACF,UAAU,EACV,MAAM,GACP,EAAE,gBAAgB,2CAkElB"}
@@ -1,9 +0,0 @@
1
- import { type Sx } from '@mantine/core';
2
- import type { CSSProperties } from 'react';
3
- export type ContextMenuDividerProps = {
4
- className: string;
5
- sx: Sx | (Sx | undefined)[] | undefined;
6
- style: CSSProperties;
7
- };
8
- export declare function ContextMenuDivider({ className, sx, style }: ContextMenuDividerProps): import("react/jsx-runtime").JSX.Element;
9
- //# sourceMappingURL=ContextMenuDivider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextMenuDivider.d.ts","sourceRoot":"","sources":["../ContextMenuDivider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAS3C,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC;IACxC,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,uBAAuB,2CAGnF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextMenuItem.d.ts","sourceRoot":"","sources":["../ContextMenuItem.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAsB,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAuC/C,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,KAAK,EACL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,EACP,MAAM,EACN,KAAK,GACN,EAAE,oBAAoB,CAAC,IAAI,CAAC,sBAAsB,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,2CAoD7F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextMenuPortal.d.ts","sourceRoot":"","sources":["../ContextMenuPortal.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnE,wBAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,EAAE,gBAAgB,2CAU5E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextMenuProvider.d.ts","sourceRoot":"","sources":["../ContextMenuProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAsB,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIrG;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,MAAa,EACb,MAAa,EACb,YAAmB,EACnB,QAAQ,GACT,EAAE,wBAAwB,2CA+B1B;AAED;;GAEG;AACH,wBAAgB,cAAc,4BAE7B"}
package/dist/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var ne=Object.create;var k=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var o in t)k(e,o,{get:t[o],enumerable:!0})},G=(e,t,o,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of se(t))!ue.call(e,n)&&n!==o&&k(e,n,{get:()=>t[n],enumerable:!(u=re(t,n))||u.enumerable});return e};var de=(e,t,o)=>(o=e!=null?ne(ie(e)):{},G(t||!e||!e.__esModule?k(o,"default",{value:e,enumerable:!0}):o,e)),pe=e=>G(k({},"__esModule",{value:!0}),e);var Ce={};ae(Ce,{ContextMenuDivider:()=>W,ContextMenuItem:()=>L,ContextMenuPortal:()=>$,ContextMenuProvider:()=>me,humanize:()=>R,useContextMenu:()=>fe});module.exports=pe(Ce);var C=de(require("react"),1);var O=require("@mantine/core"),J=require("react/jsx-runtime"),le=(0,O.createStyles)(e=>({root:{height:1,background:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[1]}}));function W({className:e,sx:t,style:o}){let{cx:u,classes:n}=le();return(0,J.jsx)(O.Box,{className:u(n.root,e),sx:t,style:o})}var i=require("@mantine/core"),z=require("react");var a=require("@mantine/core"),Z=require("@mantine/hooks"),T=require("react");function R(e){let t=e.replace(/([a-z\d])([A-Z]+)/g,"$1 $2").replace(/\W|_/g," ").trim().toLowerCase();return`${t.charAt(0).toUpperCase()}${t.slice(1)}`}var I=require("react/jsx-runtime"),X={},ce=(0,a.createStyles)(e=>({root:{position:"fixed",border:`1px solid ${e.colorScheme==="dark"?e.colors.dark[4]:e.colors.gray[3]}`,overflow:"hidden",transition:"all .15s ease"}}));function B({x:e,y:t,content:o,zIndex:u,shadow:n,borderRadius:p,onHide:l,className:y,style:c,sx:r,classNames:s,styles:M}){let[w]=(0,Z.useResizeObserver)(),{width:S,height:b}=w.current?.getBoundingClientRect()||{width:0,height:0},x=0,P=0;typeof window<"u"&&({innerWidth:x,innerHeight:P}=window);let[,h]=(0,T.useState)(!1);(0,T.useEffect)(()=>{h(!0)},[]);let{cx:m,classes:D,theme:q}=ce(),{dir:j,spacing:ee}=q,H=typeof M=="function"?M(q,X,X):M,f=(0,a.px)(ee.md);return(0,I.jsx)(a.Paper,{ref:w,shadow:n,radius:p,className:m(D.root,y,s?.root),style:{...H?.root,...c},sx:[{zIndex:u,top:t+b+f>P?P-b-f:t,left:j==="ltr"?e+S+f>x?x-S-f:e:x-f-(e-S-f<0?S+f:e)},...(0,a.packSx)(r)],children:Array.isArray(o)?o.map(({key:N,className:F,sx:U,style:K,onClick:Y,items:_,title:te,...oe})=>Y||_?(0,I.jsx)(L,{className:m(s?.item,F),sx:U,style:{...H?.item,...K},title:te??R(N),onClick:Y,onHide:l,items:_,...oe},N):(0,I.jsx)(W,{className:m(s?.divider,F),sx:U,style:{...H?.divider,...K}},N)):o(l)})}var d=require("react/jsx-runtime"),xe=(0,i.createStyles)((e,{color:t})=>{let o=(0,i.px)(e.spacing.sm)/2;return{button:{width:"100%",display:"flex",alignItems:"center",paddingTop:o,paddingBottom:o,paddingLeft:e.spacing.sm,paddingRight:e.spacing.sm,color:t&&e.colors[t][6],transition:"background .15s ease","&[disabled]":{cursor:"not-allowed",color:e.colorScheme==="dark"?e.colors.dark[3]:e.colors.gray[5]},"&:hover:not([disabled])":{background:e.fn.rgba(t?e.colors[t][6]:e.colorScheme==="dark"?e.colors.dark[3]:e.colors.gray[4],t?e.colorScheme==="dark"?.15:.08:.25)},"&:active:not([disabled])":{background:e.fn.rgba(t?e.colors[t][6]:e.colorScheme==="dark"?e.colors.dark[3]:e.colors.gray[4],t?e.colorScheme==="dark"?.3:.2:.5)}},title:{whiteSpace:"nowrap",flexGrow:1}}});function L({className:e,style:t,icon:o,title:u,color:n,disabled:p,onClick:l,onHide:y,items:c}){let r=(0,z.useRef)(null),[s,M]=(0,z.useState)(null),w=l?m=>{y(),l(m)}:void 0,S=()=>{let{top:m,right:D}=r.current.getBoundingClientRect();M({x:D,y:m})},b=()=>{M(null)},x=c&&!p,{cx:P,classes:h}=xe({color:n});return(0,d.jsxs)("div",{onMouseOver:x?S:void 0,onMouseOut:x?b:void 0,children:[(0,d.jsxs)(i.UnstyledButton,{ref:r,className:P(h.button,e),style:t,disabled:p,onClick:w,children:[o&&(0,d.jsx)(i.Box,{fz:0,mr:"xs",children:o}),(0,d.jsx)(i.Text,{className:h.title,size:"sm",children:u}),c&&(0,d.jsx)(i.Box,{fz:10,mt:-2,ml:"xs",children:"\u25B6"})]}),s&&(0,d.jsx)(B,{content:c,onHide:y,...s})]})}var Q=require("@mantine/core"),v=require("@mantine/hooks");var A=require("react/jsx-runtime");function $({onHide:e,...t}){(0,v.useWindowEvent)("resize",e),(0,v.useWindowEvent)("scroll",e);let o=(0,v.useClickOutside)(e);return(0,A.jsx)(Q.Portal,{innerRef:o,children:(0,A.jsx)(B,{...t,onHide:e})})}var g=require("react");var E=require("react/jsx-runtime"),V=(0,g.createContext)(()=>()=>{});function me({zIndex:e=9999,shadow:t="sm",borderRadius:o="xs",children:u}){let[n,p]=(0,g.useState)(null),l=()=>{p(null)},y=(c,r)=>s=>{s.preventDefault(),s.stopPropagation(),p({x:s.clientX,y:s.clientY,content:c,zIndex:r?.zIndex||e,shadow:r?.shadow||t,borderRadius:r?.borderRadius||o,className:r?.className,style:r?.style,sx:r?.sx,classNames:r?.classNames,styles:r?.styles})};return(0,E.jsxs)(V.Provider,{value:y,children:[u,n&&(0,E.jsx)($,{onHide:l,...n})]})}function fe(){return(0,g.useContext)(V)}
2
- //# sourceMappingURL=index.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../index.ts", "../react-shim.mjs", "../ContextMenuDivider.tsx", "../ContextMenuItem.tsx", "../ContextMenu.tsx", "../utils.ts", "../ContextMenuPortal.tsx", "../ContextMenuProvider.tsx"],
4
- "sourcesContent": ["export * from './ContextMenuDivider';\nexport * from './ContextMenuItem';\nexport * from './ContextMenuPortal';\nexport * from './ContextMenuProvider';\nexport { humanize } from './utils';\n", "import * as React from 'react';\nexport { React };\n", "import { Box, createStyles, type Sx } from '@mantine/core';\nimport type { CSSProperties } from 'react';\n\nconst useStyles = createStyles((theme) => ({\n root: {\n height: 1,\n background: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[1],\n },\n}));\n\nexport type ContextMenuDividerProps = {\n className: string;\n sx: Sx | (Sx | undefined)[] | undefined;\n style: CSSProperties;\n};\n\nexport function ContextMenuDivider({ className, sx, style }: ContextMenuDividerProps) {\n const { cx, classes } = useStyles();\n return <Box className={cx(classes.root, className)} sx={sx} style={style} />;\n}\n", "import { Box, Text, UnstyledButton, createStyles, px, type MantineColor } from '@mantine/core';\nimport { MouseEventHandler, useRef, useState } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport { ContextMenuContent, ContextMenuItemOptions } from './types';\nimport { WithRequiredProperty } from './utils';\n\nconst useStyles = createStyles((theme, { color }: { color?: MantineColor }) => {\n const verticalPadding = px(theme.spacing.sm) / 2;\n return {\n button: {\n width: '100%',\n display: 'flex',\n alignItems: 'center',\n paddingTop: verticalPadding,\n paddingBottom: verticalPadding,\n paddingLeft: theme.spacing.sm,\n paddingRight: theme.spacing.sm,\n color: color && theme.colors[color][6],\n transition: 'background .15s ease',\n '&[disabled]': {\n cursor: 'not-allowed',\n color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],\n },\n '&:hover:not([disabled])': {\n background: theme.fn.rgba(\n color ? theme.colors[color][6] : theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[4],\n color ? (theme.colorScheme === 'dark' ? 0.15 : 0.08) : 0.25\n ),\n },\n '&:active:not([disabled])': {\n background: theme.fn.rgba(\n color ? theme.colors[color][6] : theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[4],\n color ? (theme.colorScheme === 'dark' ? 0.3 : 0.2) : 0.5\n ),\n },\n },\n title: {\n whiteSpace: 'nowrap',\n flexGrow: 1,\n },\n };\n});\n\nexport function ContextMenuItem({\n className,\n style,\n icon,\n title,\n color,\n disabled,\n onClick,\n onHide,\n items,\n}: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title'> & { onHide: () => void }) {\n const ref = useRef<HTMLButtonElement>(null);\n const [submenuPosition, setSubmenuPosition] = useState<{ x: number; y: number } | null>(null);\n\n const handleClick: MouseEventHandler<HTMLButtonElement> | undefined = onClick\n ? (e) => {\n onHide();\n onClick!(e);\n }\n : undefined;\n\n const showSubmenu = () => {\n const { top: y, right: x } = ref.current!.getBoundingClientRect();\n setSubmenuPosition({ x, y });\n };\n\n const hideSubmenu = () => {\n setSubmenuPosition(null);\n };\n\n const hasItemsAndIsNotDisabled = items && !disabled;\n const { cx, classes } = useStyles({ color });\n\n return (\n <div\n onMouseOver={hasItemsAndIsNotDisabled ? showSubmenu : undefined}\n onMouseOut={hasItemsAndIsNotDisabled ? hideSubmenu : undefined}\n >\n <UnstyledButton\n ref={ref}\n className={cx(classes.button, className)}\n style={style}\n disabled={disabled}\n onClick={handleClick}\n >\n {icon && (\n <Box fz={0} mr=\"xs\">\n {icon}\n </Box>\n )}\n <Text className={classes.title} size=\"sm\">\n {title}\n </Text>\n {items && (\n <Box fz={10} mt={-2} ml=\"xs\">\n \u25B6\n </Box>\n )}\n </UnstyledButton>\n {submenuPosition && <ContextMenu content={items as ContextMenuContent} onHide={onHide} {...submenuPosition} />}\n </div>\n );\n}\n", "import { Paper, createStyles, packSx, px } from '@mantine/core';\nimport { useResizeObserver } from '@mantine/hooks';\nimport { CSSProperties, useEffect, useState } from 'react';\nimport { ContextMenuDivider } from './ContextMenuDivider';\nimport { ContextMenuItem } from './ContextMenuItem';\nimport type { ContextMenuContent, ContextMenuOptions } from './types';\nimport { humanize } from './utils';\n\nconst EMPTY_OBJECT = {};\n\nconst useStyles = createStyles((theme) => ({\n root: {\n position: 'fixed',\n border: `1px solid ${theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[3]}`,\n overflow: 'hidden',\n transition: 'all .15s ease',\n },\n}));\n\nexport type ContextMenuInstanceOptions = {\n x: number;\n y: number;\n content: ContextMenuContent;\n};\n\nexport type ContextMenuProps = ContextMenuOptions &\n ContextMenuInstanceOptions & {\n onHide: () => void;\n };\n\nexport function ContextMenu({\n x,\n y,\n content,\n zIndex,\n shadow,\n borderRadius,\n onHide,\n className,\n style,\n sx,\n classNames,\n styles,\n}: ContextMenuProps) {\n const [paperRef] = useResizeObserver<HTMLDivElement>();\n const { width, height } = paperRef.current?.getBoundingClientRect() || { width: 0, height: 0 };\n\n let windowWidth = 0;\n let windowHeight = 0;\n if (typeof window !== 'undefined') ({ innerWidth: windowWidth, innerHeight: windowHeight } = window);\n\n // trigger a rerender to make sure that context menu is positioned correctly\n const [, setRendered] = useState(false);\n useEffect(() => {\n setRendered(true);\n }, []);\n\n const { cx, classes, theme } = useStyles();\n const { dir, spacing } = theme;\n const styleProperties = typeof styles === 'function' ? styles(theme, EMPTY_OBJECT, EMPTY_OBJECT) : styles;\n const mdSpacing = px(spacing.md);\n\n return (\n <Paper\n ref={paperRef}\n shadow={shadow}\n radius={borderRadius}\n className={cx(classes.root, className, classNames?.root)}\n style={{ ...styleProperties?.root, ...style } as CSSProperties}\n sx={[\n {\n zIndex,\n top: y + height + mdSpacing > windowHeight ? windowHeight - height - mdSpacing : y,\n left:\n dir === 'ltr'\n ? x + width + mdSpacing > windowWidth\n ? windowWidth - width - mdSpacing\n : x\n : windowWidth - mdSpacing - (x - width - mdSpacing < 0 ? width + mdSpacing : x),\n },\n ...packSx(sx),\n ]}\n >\n {Array.isArray(content)\n ? content.map(({ key, className, sx, style, onClick, items, title, ...otherOptions }) =>\n onClick || items ? (\n <ContextMenuItem\n key={key}\n className={cx(classNames?.item, className)}\n sx={sx}\n style={{ ...styleProperties?.item, ...style } as CSSProperties}\n title={title ?? humanize(key)}\n onClick={onClick}\n onHide={onHide}\n items={items}\n {...otherOptions}\n />\n ) : (\n <ContextMenuDivider\n key={key}\n className={cx(classNames?.divider, className)}\n sx={sx}\n style={{ ...styleProperties?.divider, ...style } as CSSProperties}\n />\n )\n )\n : content(onHide)}\n </Paper>\n );\n}\n", "export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\n/**\n * Utility function that returns a humanized version of a string, e.g. \"camelCase\" -> \"Camel Case\"\n */\nexport function humanize(value: string) {\n const str = value\n .replace(/([a-z\\d])([A-Z]+)/g, '$1 $2')\n .replace(/\\W|_/g, ' ')\n .trim()\n .toLowerCase();\n return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;\n}\n", "import { Portal } from '@mantine/core';\nimport { useClickOutside, useWindowEvent } from '@mantine/hooks';\nimport { ContextMenu, type ContextMenuProps } from './ContextMenu';\n\nexport function ContextMenuPortal({ onHide, ...otherProps }: ContextMenuProps) {\n useWindowEvent('resize', onHide);\n useWindowEvent('scroll', onHide);\n const portalInnerRef = useClickOutside<HTMLDivElement>(onHide);\n\n return (\n <Portal innerRef={portalInnerRef}>\n <ContextMenu {...otherProps} onHide={onHide} />\n </Portal>\n );\n}\n", "import { createContext, useContext, useState } from 'react';\nimport { ContextMenuInstanceOptions } from './ContextMenu';\nimport { ContextMenuPortal } from './ContextMenuPortal';\nimport type { ContextMenuOptions, ContextMenuProviderProps, ShowContextMenuFunction } from './types';\n\nconst MenuContext = createContext<ShowContextMenuFunction>(() => () => undefined);\n\n/**\n * Provider that allows to show a context menu anywhere in your application.\n * If you wrap your application with this provider, you can use the `useContextMenu` hook\n * anywhere in the component tree to access a function that shows the context menu.\n */\nexport function ContextMenuProvider({\n zIndex = 9999,\n shadow = 'sm',\n borderRadius = 'xs',\n children,\n}: ContextMenuProviderProps) {\n const [data, setData] = useState<(ContextMenuInstanceOptions & ContextMenuOptions) | null>(null);\n\n const destroy = () => {\n setData(null);\n };\n\n const showContextMenu: ShowContextMenuFunction = (content, options) => (e) => {\n e.preventDefault();\n e.stopPropagation();\n setData({\n x: e.clientX,\n y: e.clientY,\n content,\n zIndex: options?.zIndex || zIndex,\n shadow: options?.shadow || shadow,\n borderRadius: options?.borderRadius || borderRadius,\n className: options?.className,\n style: options?.style,\n sx: options?.sx,\n classNames: options?.classNames,\n styles: options?.styles,\n });\n };\n\n return (\n <MenuContext.Provider value={showContextMenu}>\n {children}\n {data && <ContextMenuPortal onHide={destroy} {...data} />}\n </MenuContext.Provider>\n );\n}\n\n/**\n * Hook returning a function that shows a context menu.\n */\nexport function useContextMenu() {\n return useContext(MenuContext);\n}\n"],
5
- "mappings": "ukBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,wBAAAE,EAAA,oBAAAC,EAAA,sBAAAC,EAAA,wBAAAC,GAAA,aAAAC,EAAA,mBAAAC,KAAA,eAAAC,GAAAR,ICAA,IAAAS,EAAuB,uBCAvB,IAAAC,EAA2C,yBAkBlCC,EAAA,6BAfHC,MAAY,gBAAcC,IAAW,CACzC,KAAM,CACJ,OAAQ,EACR,WAAYA,EAAM,cAAgB,OAASA,EAAM,OAAO,KAAK,CAAC,EAAIA,EAAM,OAAO,KAAK,CAAC,CACvF,CACF,EAAE,EAQK,SAASC,EAAmB,CAAE,UAAAC,EAAW,GAAAC,EAAI,MAAAC,CAAM,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T,OAAAC,EAAS,KACT,aAAAC,EAAe,KACf,SAAAC,CACF,EAA6B,CAC3B,GAAM,CAACC,EAAMC,CAAO,KAAI,YAAmE,IAAI,EAEzFC,EAAU,IAAM,CACpBD,EAAQ,IAAI,CACd,EAEME,EAA2C,CAACC,EAASC,IAAaC,GAAM,CAC5EA,EAAE,eAAe,EACjBA,EAAE,gBAAgB,EAClBL,EAAQ,CACN,EAAGK,EAAE,QACL,EAAGA,EAAE,QACL,QAAAF,EACA,OAAQC,GAAS,QAAUT,EAC3B,OAAQS,GAAS,QAAUR,EAC3B,aAAcQ,GAAS,cAAgBP,EACvC,UAAWO,GAAS,UACpB,MAAOA,GAAS,MAChB,GAAIA,GAAS,GACb,WAAYA,GAAS,WACrB,OAAQA,GAAS,MACnB,CAAC,CACH,EAEA,SACE,QAACX,EAAY,SAAZ,CAAqB,MAAOS,EAC1B,UAAAJ,EACAC,MAAQ,OAACO,EAAA,CAAkB,OAAQL,EAAU,GAAGF,EAAM,GACzD,CAEJ,CAKO,SAASQ,IAAiB,CAC/B,SAAO,cAAWd,CAAW,CAC/B",
6
- "names": ["package_exports", "__export", "ContextMenuDivider", "ContextMenuItem", "ContextMenuPortal", "ContextMenuProvider", "humanize", "useContextMenu", "__toCommonJS", "React", "import_core", "import_jsx_runtime", "useStyles", "theme", "ContextMenuDivider", "className", "sx", "style", "cx", "classes", "import_core", "import_react", "import_core", "import_hooks", "import_react", "humanize", "value", "str", "import_jsx_runtime", "EMPTY_OBJECT", "useStyles", "theme", "ContextMenu", "x", "y", "content", "zIndex", "shadow", "borderRadius", "onHide", "className", "style", "sx", "classNames", "styles", "paperRef", "width", "height", "windowWidth", "windowHeight", "setRendered", "cx", "classes", "dir", "spacing", "styleProperties", "mdSpacing", "key", "onClick", "items", "title", "otherOptions", "ContextMenuItem", "humanize", "ContextMenuDivider", "import_jsx_runtime", "useStyles", "theme", "color", "verticalPadding", "ContextMenuItem", "className", "style", "icon", "title", "disabled", "onClick", "onHide", "items", "ref", "submenuPosition", "setSubmenuPosition", "handleClick", "e", "showSubmenu", "y", "x", "hideSubmenu", "hasItemsAndIsNotDisabled", "cx", "classes", "ContextMenu", "import_core", "import_hooks", "import_jsx_runtime", "ContextMenuPortal", "onHide", "otherProps", "portalInnerRef", "ContextMenu", "import_react", "import_jsx_runtime", "MenuContext", "ContextMenuProvider", "zIndex", "shadow", "borderRadius", "children", "data", "setData", "destroy", "showContextMenu", "content", "options", "e", "ContextMenuPortal", "useContextMenu"]
7
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- import*as x from"react";import{Box as G,createStyles as J}from"@mantine/core";import{jsx as Z}from"react/jsx-runtime";var X=J(e=>({root:{height:1,background:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[1]}}));function D({className:e,sx:t,style:o}){let{cx:i,classes:s}=X();return Z(G,{className:i(s.root,e),sx:t,style:o})}import{Box as W,Text as se,UnstyledButton as ie,createStyles as ue,px as ae}from"@mantine/core";import{useRef as de,useState as pe}from"react";import{Paper as Q,createStyles as V,packSx as j,px as ee}from"@mantine/core";import{useResizeObserver as te}from"@mantine/hooks";import{useEffect as oe,useState as ne}from"react";function k(e){let t=e.replace(/([a-z\d])([A-Z]+)/g,"$1 $2").replace(/\W|_/g," ").trim().toLowerCase();return`${t.charAt(0).toUpperCase()}${t.slice(1)}`}import{jsx as O}from"react/jsx-runtime";var H={},re=V(e=>({root:{position:"fixed",border:`1px solid ${e.colorScheme==="dark"?e.colors.dark[4]:e.colors.gray[3]}`,overflow:"hidden",transition:"all .15s ease"}}));function P({x:e,y:t,content:o,zIndex:i,shadow:s,borderRadius:u,onHide:a,className:m,style:d,sx:n,classNames:r,styles:f}){let[M]=te(),{width:C,height:S}=M.current?.getBoundingClientRect()||{width:0,height:0},p=0,y=0;typeof window<"u"&&({innerWidth:p,innerHeight:y}=window);let[,g]=ne(!1);oe(()=>{g(!0)},[]);let{cx:l,classes:w,theme:R}=re(),{dir:U,spacing:K}=R,b=typeof f=="function"?f(R,H,H):f,c=ee(K.md);return O(Q,{ref:M,shadow:s,radius:u,className:l(w.root,m,r?.root),style:{...b?.root,...d},sx:[{zIndex:i,top:t+S+c>y?y-S-c:t,left:U==="ltr"?e+C+c>p?p-C-c:e:p-c-(e-C-c<0?C+c:e)},...j(n)],children:Array.isArray(o)?o.map(({key:h,className:I,sx:T,style:B,onClick:z,items:E,title:Y,..._})=>z||E?O(N,{className:l(r?.item,I),sx:T,style:{...b?.item,...B},title:Y??k(h),onClick:z,onHide:a,items:E,..._},h):O(D,{className:l(r?.divider,I),sx:T,style:{...b?.divider,...B}},h)):o(a)})}import{jsx as v,jsxs as L}from"react/jsx-runtime";var le=ue((e,{color:t})=>{let o=ae(e.spacing.sm)/2;return{button:{width:"100%",display:"flex",alignItems:"center",paddingTop:o,paddingBottom:o,paddingLeft:e.spacing.sm,paddingRight:e.spacing.sm,color:t&&e.colors[t][6],transition:"background .15s ease","&[disabled]":{cursor:"not-allowed",color:e.colorScheme==="dark"?e.colors.dark[3]:e.colors.gray[5]},"&:hover:not([disabled])":{background:e.fn.rgba(t?e.colors[t][6]:e.colorScheme==="dark"?e.colors.dark[3]:e.colors.gray[4],t?e.colorScheme==="dark"?.15:.08:.25)},"&:active:not([disabled])":{background:e.fn.rgba(t?e.colors[t][6]:e.colorScheme==="dark"?e.colors.dark[3]:e.colors.gray[4],t?e.colorScheme==="dark"?.3:.2:.5)}},title:{whiteSpace:"nowrap",flexGrow:1}}});function N({className:e,style:t,icon:o,title:i,color:s,disabled:u,onClick:a,onHide:m,items:d}){let n=de(null),[r,f]=pe(null),M=a?l=>{m(),a(l)}:void 0,C=()=>{let{top:l,right:w}=n.current.getBoundingClientRect();f({x:w,y:l})},S=()=>{f(null)},p=d&&!u,{cx:y,classes:g}=le({color:s});return L("div",{onMouseOver:p?C:void 0,onMouseOut:p?S:void 0,children:[L(ie,{ref:n,className:y(g.button,e),style:t,disabled:u,onClick:M,children:[o&&v(W,{fz:0,mr:"xs",children:o}),v(se,{className:g.title,size:"sm",children:i}),d&&v(W,{fz:10,mt:-2,ml:"xs",children:"\u25B6"})]}),r&&v(P,{content:d,onHide:m,...r})]})}import{Portal as ce}from"@mantine/core";import{useClickOutside as xe,useWindowEvent as A}from"@mantine/hooks";import{jsx as $}from"react/jsx-runtime";function q({onHide:e,...t}){A("resize",e),A("scroll",e);let o=xe(e);return $(ce,{innerRef:o,children:$(P,{...t,onHide:e})})}import{createContext as me,useContext as fe,useState as Ce}from"react";import{jsx as ye,jsxs as Me}from"react/jsx-runtime";var F=me(()=>()=>{});function Qe({zIndex:e=9999,shadow:t="sm",borderRadius:o="xs",children:i}){let[s,u]=Ce(null),a=()=>{u(null)},m=(d,n)=>r=>{r.preventDefault(),r.stopPropagation(),u({x:r.clientX,y:r.clientY,content:d,zIndex:n?.zIndex||e,shadow:n?.shadow||t,borderRadius:n?.borderRadius||o,className:n?.className,style:n?.style,sx:n?.sx,classNames:n?.classNames,styles:n?.styles})};return Me(F.Provider,{value:m,children:[i,s&&ye(q,{onHide:a,...s})]})}function Ve(){return fe(F)}export{D as ContextMenuDivider,N as ContextMenuItem,q as ContextMenuPortal,Qe as ContextMenuProvider,k as humanize,Ve as useContextMenu};
2
- //# sourceMappingURL=index.mjs.map