mantine-contextmenu 6.0.3 → 7.0.0-alpha.2

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 (58) hide show
  1. package/README.md +31 -31
  2. package/dist/cjs/ContextMenu.js +64 -0
  3. package/dist/cjs/ContextMenu.js.map +1 -0
  4. package/dist/cjs/ContextMenuDivider.js +17 -0
  5. package/dist/cjs/ContextMenuDivider.js.map +1 -0
  6. package/dist/cjs/ContextMenuItem.js +58 -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 +23 -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 +16 -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 +38 -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 +46 -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 +7 -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 +12 -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 -3
  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} +2 -2
  42. package/dist/{types.d.ts → types/types.d.ts} +33 -19
  43. package/dist/{utils.d.ts → types/utils.d.ts} +0 -4
  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.map +0 -1
@@ -0,0 +1,38 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Paper, px, useDirection, useMantineTheme } from '@mantine/core';
4
+ import { useResizeObserver } from '@mantine/hooks';
5
+ import clsx from 'clsx';
6
+ import { ContextMenuDivider } from './ContextMenuDivider';
7
+ import { ContextMenuItem } from './ContextMenuItem';
8
+ import { humanize } from './utils';
9
+ export function ContextMenu({ x, y, content, zIndex, shadow, borderRadius, onHide, className, style, classNames, styles, }) {
10
+ const [paperRef] = useResizeObserver();
11
+ const { width, height } = paperRef.current?.getBoundingClientRect() || { width: 0, height: 0 };
12
+ let windowWidth = 0;
13
+ let windowHeight = 0;
14
+ if (typeof window !== 'undefined')
15
+ ({ innerWidth: windowWidth, innerHeight: windowHeight } = window);
16
+ const { dir } = useDirection();
17
+ const theme = useMantineTheme();
18
+ const resolvedStyle = typeof style === 'function' ? style(theme) : style;
19
+ const resolvedStyles = typeof styles === 'function' ? styles(theme) : styles;
20
+ const mdSpacing = px(theme.spacing.md);
21
+ return (_jsx(Paper, { ref: paperRef, shadow: shadow, radius: borderRadius, className: clsx('mantine-contextmenu', className, classNames?.root), style: {
22
+ ...resolvedStyles?.root,
23
+ ...resolvedStyle,
24
+ zIndex,
25
+ top: y + height + mdSpacing > windowHeight ? windowHeight - height - mdSpacing : y,
26
+ left: dir === 'ltr'
27
+ ? x + width + mdSpacing > windowWidth
28
+ ? windowWidth - width - mdSpacing
29
+ : x
30
+ : windowWidth - mdSpacing - (x - width - mdSpacing < 0 ? width + mdSpacing : x),
31
+ }, children: Array.isArray(content)
32
+ ? content.map(({ key, className, style, onClick, items, title, ...otherOptions }) => {
33
+ const resolvedItemStyle = typeof style === 'function' ? style(theme) : style;
34
+ return onClick || items ? (_jsx(ContextMenuItem, { className: clsx(classNames?.item, className), style: { ...resolvedStyles?.item, ...resolvedItemStyle }, title: title ?? humanize(key), onClick: onClick, onHide: onHide, items: items, ...otherOptions }, key)) : (_jsx(ContextMenuDivider, { className: clsx(classNames?.divider, className), style: { ...resolvedStyles?.divider, ...resolvedItemStyle } }, key));
35
+ })
36
+ : content(onHide) }));
37
+ }
38
+ //# sourceMappingURL=ContextMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../package/ContextMenu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D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K,KACR,YAAY,IAPX,GAAG,CAQR,CACH,CAAC,CAAC,CAAC,CACF,KAAC,kBAAkB,IAEjB,SAAS,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,EAC/C,KAAK,EAAE,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,iBAAiB,EAAE,IAFtD,GAAG,CAGR,CACH,CAAC;YACJ,CAAC,CAAC;YACJ,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GACb,CACT,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Paper, px, useDirection, useMantineTheme } from '@mantine/core';\nimport { useResizeObserver } from '@mantine/hooks';\nimport clsx from 'clsx';\nimport { ContextMenuDivider } from './ContextMenuDivider';\nimport { ContextMenuItem } from './ContextMenuItem';\nimport type { ContextMenuContent, ContextMenuOptions } from './types';\nimport { humanize } from './utils';\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 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 const { dir } = useDirection();\n const theme = useMantineTheme();\n const resolvedStyle = typeof style === 'function' ? style(theme) : style;\n const resolvedStyles = typeof styles === 'function' ? styles(theme) : styles;\n const mdSpacing = px(theme.spacing.md) as number;\n\n return (\n <Paper\n ref={paperRef}\n shadow={shadow}\n radius={borderRadius}\n className={clsx('mantine-contextmenu', className, classNames?.root)}\n style={{\n ...resolvedStyles?.root,\n ...resolvedStyle,\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 >\n {Array.isArray(content)\n ? content.map(({ key, className, style, onClick, items, title, ...otherOptions }) => {\n const resolvedItemStyle = typeof style === 'function' ? style(theme) : style;\n return onClick || items ? (\n <ContextMenuItem\n key={key}\n className={clsx(classNames?.item, className)}\n style={{ ...resolvedStyles?.item, ...resolvedItemStyle }}\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={clsx(classNames?.divider, className)}\n style={{ ...resolvedStyles?.divider, ...resolvedItemStyle }}\n />\n );\n })\n : content(onHide)}\n </Paper>\n );\n}\n"]}
@@ -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 clsx from 'clsx';
5
+ export function ContextMenuDivider({ className, style }) {
6
+ const theme = useMantineTheme();
7
+ return (_jsx(Box, { className: clsx('mantine-contextmenu-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;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,MAAM,UAAU,kBAAkB,CAAC,EAAE,SAAS,EAAE,KAAK,EAA2B;IAC9E,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,OAAO,CACL,KAAC,GAAG,IACF,SAAS,EAAE,IAAI,CAAC,6BAA6B,EAAE,SAAS,CAAC,EACzD,KAAK,EAAE,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GACzD,CACH,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Box, useMantineTheme } from '@mantine/core';\nimport clsx from 'clsx';\nimport type { ContextMenuItemOptions } from './types';\n\nexport type ContextMenuDividerProps = Pick<ContextMenuItemOptions, 'className' | 'style'>;\n\nexport function ContextMenuDivider({ className, style }: ContextMenuDividerProps) {\n const theme = useMantineTheme();\n return (\n <Box\n className={clsx('mantine-contextmenu-divider', className)}\n style={typeof style === 'function' ? style(theme) : style}\n />\n );\n}\n"]}
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Box, UnstyledButton, parseThemeColor, rgba, useMantineTheme } from '@mantine/core';
4
+ import clsx from 'clsx';
5
+ import { useRef, useState } from 'react';
6
+ import { ContextMenu } from './ContextMenu';
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 ? parseThemeColor({ color, theme }).value : undefined;
27
+ if (color === 'red')
28
+ console.log(parsedColor);
29
+ return (_jsxs("div", { onMouseOver: hasItemsAndIsNotDisabled ? showSubmenu : undefined, onMouseOut: hasItemsAndIsNotDisabled ? hideSubmenu : undefined, children: [_jsxs(UnstyledButton, { ref: ref, style: {
30
+ '--mantine-contextmenu-item-button-color': parsedColor ? parsedColor : 'var(--mantine-color-text)',
31
+ '--mantine-contextmenu-item-button-hover-bg-color-light': parsedColor
32
+ ? rgba(parsedColor, 0.08)
33
+ : rgba(colors.gray[4], 0.25),
34
+ '--mantine-contextmenu-item-button-hover-bg-color-dark': parsedColor
35
+ ? rgba(parsedColor, 0.15)
36
+ : rgba(colors.dark[3], 0.25),
37
+ '--mantine-contextmenu-item-button-pressed-bg-color-light': parsedColor
38
+ ? rgba(parsedColor, 0.2)
39
+ : rgba(colors.gray[4], 0.5),
40
+ '--mantine-contextmenu-item-button-pressed-bg-color-dark': parsedColor
41
+ ? rgba(parsedColor, 0.3)
42
+ : rgba(colors.dark[3], 0.5),
43
+ ...(typeof style === 'function' ? style(theme) : style),
44
+ }, className: clsx('mantine-contextmenu-item-button', className), disabled: disabled, onClick: handleClick, children: [icon && (_jsx(Box, { fz: 0, mr: "xs", mt: -2, children: icon })), _jsx("div", { className: "mantine-contextmenu-item-button-title", children: title }), items && (_jsx(Box, { fz: 10, mt: -2, ml: "xs", children: "\u25B6" }))] }), submenuPosition && _jsx(ContextMenu, { content: items, onHide: onHide, ...submenuPosition })] }));
45
+ }
46
+ //# 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,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAA0B,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,UAAU,eAAe,CAAC,EAC9B,SAAS,EACT,KAAK,EACL,IAAI,EACJ,K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AAK,GAAO,EACnE,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, parseThemeColor, rgba, useMantineTheme } from '@mantine/core';\nimport clsx from 'clsx';\nimport { useRef, useState, type MouseEventHandler } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport type { ContextMenuContent, ContextMenuItemOptions, WithRequiredProperty } from './types';\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 ? parseThemeColor({ color, theme }).value : undefined;\n if (color === 'red') console.log(parsedColor);\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-contextmenu-item-button-color': parsedColor ? parsedColor : 'var(--mantine-color-text)',\n '--mantine-contextmenu-item-button-hover-bg-color-light': parsedColor\n ? rgba(parsedColor, 0.08)\n : rgba(colors.gray[4], 0.25),\n '--mantine-contextmenu-item-button-hover-bg-color-dark': parsedColor\n ? rgba(parsedColor, 0.15)\n : rgba(colors.dark[3], 0.25),\n '--mantine-contextmenu-item-button-pressed-bg-color-light': parsedColor\n ? rgba(parsedColor, 0.2)\n : rgba(colors.gray[4], 0.5),\n '--mantine-contextmenu-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={clsx('mantine-contextmenu-item-button', className)}\n disabled={disabled}\n onClick={handleClick}\n >\n {icon && (\n <Box fz={0} mr=\"xs\" mt={-2}>\n {icon}\n </Box>\n )}\n <div className=\"mantine-contextmenu-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,7 @@
1
+ export * from './ContextMenuDivider';
2
+ export * from './ContextMenuItem';
3
+ export * from './ContextMenuPortal';
4
+ export * from './ContextMenuProvider';
5
+ export * from './types';
6
+ export * from './utils';
7
+ //# 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;AACxB,cAAc,SAAS,CAAC","sourcesContent":["export * from './ContextMenuDivider';\nexport * from './ContextMenuItem';\nexport * from './ContextMenuPortal';\nexport * from './ContextMenuProvider';\nexport * from './types';\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\n/**\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 * Context menu options\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\n/**\n * Context menu provider props\n */\nexport type ContextMenuProviderProps = ContextMenuOptions & {\n children: ReactNode;\n};\n\n/**\n * Context menu item options\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\n/**\n * Context menu content - either an array of context menu items or a function that accepts a close callback and returns context menu content\n */\nexport type ContextMenuContent = ContextMenuItemOptions[] | ((close: () => void) => JSX.Element);\n\n/**\n * Context menu hook return value\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,12 @@
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
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../package/utils.ts"],"names":[],"mappings":"AAAA;;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","sourcesContent":["/**\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"]}
@@ -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 type { 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,4 @@
1
- import { ContextMenuItemOptions } from './types';
2
- import { WithRequiredProperty } from './utils';
1
+ import type { ContextMenuItemOptions, WithRequiredProperty } from './types';
3
2
  export declare function ContextMenuItem({ className, style, icon, title, color, disabled, onClick, onHide, items, }: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title'> & {
4
3
  onHide: () => void;
5
4
  }): 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,5 @@ 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 './types';
6
+ export * from './utils';
@@ -1,5 +1,18 @@
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
+ /**
4
+ * Utility type that makes a property required
5
+ */
6
+ export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
7
+ [Property in Key]-?: Type[Property];
8
+ };
9
+ /**
10
+ * Utility type that makes a property optional
11
+ */
12
+ export type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
13
+ /**
14
+ * Context menu options
15
+ */
3
16
  export type ContextMenuOptions = {
4
17
  /**
5
18
  * zIndex of context menu
@@ -15,34 +28,35 @@ export type ContextMenuOptions = {
15
28
  * Context menu border radius
16
29
  * @default 'xs'
17
30
  */
18
- borderRadius?: MantineNumberSize;
31
+ borderRadius?: MantineSize;
19
32
  /**
20
33
  * Context menu container className
21
34
  */
22
35
  className?: string;
23
36
  /**
24
- * Context menu container style
37
+ * Context menu container style; can be a function that accepts theme and returns a style object
25
38
  */
26
- style?: CSSProperties;
27
- /**
28
- * Context menu container sx
29
- * @see https://mantine.dev/styles/sx/
30
- */
31
- sx?: Sx | (Sx | undefined)[];
39
+ style?: CSSProperties | ((theme: MantineTheme) => CSSProperties);
32
40
  /**
33
41
  * Context menu elements classNames; an object with `root`, `item` and `divider` keys and class names as values
34
42
  * @see https://mantine.dev/styles/styles-api/
35
43
  */
36
- classNames?: ClassNames<'root' | 'item' | 'divider'>;
44
+ classNames?: Partial<Record<'root' | 'item' | 'divider', string>>;
37
45
  /**
38
46
  * 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
47
+ * or a function that accepts the current theme and returns a similarly structured object
40
48
  */
41
- styles?: Styles<'root' | 'item' | 'divider', CSSProperties>;
49
+ styles?: Partial<Record<'root' | 'item' | 'divider', CSSProperties>> | ((theme: MantineTheme) => Partial<Record<'root' | 'item' | 'divider', CSSProperties>>);
42
50
  };
51
+ /**
52
+ * Context menu provider props
53
+ */
43
54
  export type ContextMenuProviderProps = ContextMenuOptions & {
44
55
  children: ReactNode;
45
56
  };
57
+ /**
58
+ * Context menu item options
59
+ */
46
60
  export type ContextMenuItemOptions = {
47
61
  /**
48
62
  * Unique key of the context menu item or divider
@@ -52,15 +66,10 @@ export type ContextMenuItemOptions = {
52
66
  * Context menu item or divider className
53
67
  */
54
68
  className?: string;
55
- /**
56
- * Context menu item or divider sx
57
- * @see https://mantine.dev/styles/sx/
58
- */
59
- sx?: Sx | (Sx | undefined)[];
60
69
  /**
61
70
  * Context menu item or divider style
62
71
  */
63
- style?: CSSProperties;
72
+ style?: CSSProperties | ((theme: MantineTheme) => CSSProperties);
64
73
  } & (({
65
74
  /**
66
75
  * Optional context menu item icon
@@ -99,7 +108,13 @@ export type ContextMenuItemOptions = {
99
108
  onClick?: never;
100
109
  items?: never;
101
110
  });
111
+ /**
112
+ * Context menu content - either an array of context menu items or a function that accepts a close callback and returns context menu content
113
+ */
102
114
  export type ContextMenuContent = ContextMenuItemOptions[] | ((close: () => void) => JSX.Element);
115
+ /**
116
+ * Context menu hook return value
117
+ */
103
118
  export type ShowContextMenuFunction = (
104
119
  /**
105
120
  * Context menu content - either an array of context menu items
@@ -110,4 +125,3 @@ content: ContextMenuContent,
110
125
  * Context menu options (overrides provider options)
111
126
  */
112
127
  options?: ContextMenuOptions) => MouseEventHandler;
113
- //# sourceMappingURL=types.d.ts.map
@@ -1,8 +1,4 @@
1
- export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
2
- [Property in Key]-?: Type[Property];
3
- };
4
1
  /**
5
2
  * Utility function that returns a humanized version of a string, e.g. "camelCase" -> "Camel Case"
6
3
  */
7
4
  export declare function humanize(value: string): string;
8
- //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "mantine-contextmenu",
3
- "version": "6.0.3",
3
+ "version": "7.0.0-alpha.2",
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.2",
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.8.0",
82
+ "@typescript-eslint/parser": "^6.8.0",
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