mantine-contextmenu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-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.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Mantine ContextMenu
2
+
3
+ ![Publish NPM & deploy docs workflow](https://github.com/icflorescu/mantine-contextmenu/actions/workflows/publish-and-deploy.yml/badge.svg)
4
+ [![NPM version][npm-image]][npm-url]
5
+ [![License][license-image]][license-url]
6
+ [![Stars][stars-image]][stars-url]
7
+ [![Last commit][last-commit-image]][repo-url]
8
+ [![Closed issues][closed-issues-image]][closed-issues-url]
9
+ [![Downloads][downloads-image]][npm-url]
10
+ [![Language][language-image]][repo-url]
11
+
12
+ A "dark-theme aware" **context-menu** for your Mantine UI applications.
13
+
14
+ <!-- [![Mantine ContextMenu](https://user-images.githubusercontent.com/...png)](https://icflorescu.github.io/mantine-contextmenu/) -->
15
+
16
+ ## Full documentation and examples
17
+
18
+ Visit [icflorescu.github.io/mantine-contextmenu](https://icflorescu.github.io/mantine-contextmenu/) to view the full documentation and learn how to use it by browsing a comprehensive list of examples.
19
+
20
+ ## Quickstart
21
+
22
+ Install the package and its dependencies:
23
+
24
+ ```sh
25
+ npm i @mantine/core @mantine/hooks @emotion/react mantine-contextmenu
26
+ ```
27
+
28
+ Wrap your application in the `ContextMenuProvider` components:
29
+
30
+ ```tsx
31
+ import { MantineProvider } from '@mantine/core';
32
+ import { ContextMenuProvider } from 'mantine-contextmenu';
33
+
34
+ function App() {
35
+ return (
36
+ <MantineProvider>
37
+ <ContextMenuProvider>
38
+ {/* your app code here... */}
39
+ </ContextMenuProvider>
40
+ </MantineProvider>
41
+ );
42
+ }
43
+ ```
44
+
45
+ Use the `useContextMenu` hook in your code:
46
+
47
+ ```ts
48
+ // @todo add example here...
49
+ ```
50
+
51
+ Have a look at the available [type definitions](https://icflorescu.github.io/mantine-contextmenu/type-definitions) and make sure to browse the list of [usage examples](https://icflorescu.github.io/mantine-contextmenu/examples/basic-usage).
52
+
53
+ ## Code contributors
54
+
55
+ [![Contributors list](https://contrib.rocks/image?repo=icflorescu/mantine-contextmenu)](https://github.com/icflorescu/mantine-contextmenu/graphs/contributors)
56
+
57
+ Want to [become a code contributor](https://icflorescu.github.io/mantine-contextmenu/contribute-and-support)?
58
+
59
+ ## Sponsor the project
60
+
61
+ If you find this package useful, please consider ❤️ [sponsoring my work](https://github.com/sponsors/icflorescu). Your sponsorship will help me dedicate more time to maintaining the project and will encourage me to add new features and fix existing bugs. If you're a company using Mantine ContextMenu in a commercial project, you can also [hire my services](https://github.com/icflorescu).
62
+
63
+ ## Other means of support
64
+
65
+ If you find this package useful, please 🙏 star the repository, 💕 [tweet about it](https://twitter.com/share?text=Check%20out%20the%20missing%20context-menu%20for%20Mantine%20UI%20applications!&url=https%3A%2F%2Fgithub.com%2Ficflorescu%2Fmantine-contextmenu&hashtags=react%2Cmantine%2Cui%2Ccontextmenu%2Cfrontend%2Copensource&via=icflorescu), 👍 [endorse me on LinkedIn](https://www.linkedin.com/in/icflorescu) or consider hiring my services.
66
+
67
+ The more stars this repository gets, the more visibility it gains among the Mantine users community. The more
68
+ users it gets, the more chances that some of those users will become active code contributors willing to put
69
+ their effort into bringing new features to life and/or fixing bugs.
70
+
71
+ As the repository gain awareness, my chances of getting hired to work on Mantine-based projects will increase,
72
+ which in turn will help maintain my vested interest in keeping the project alive.
73
+
74
+ ## Hiring the author
75
+
76
+ If you want to hire my services, don’t hesitate to drop me a line at the email address listed in my [GitHub profile](https://github.com/icflorescu).
77
+ I’m currently getting a constant flow of approaches, some of them relevant, others not so relevant.
78
+ Mentioning “Mantine ContextMenu” in your text would help me prioritize your message.
79
+
80
+ ## License
81
+
82
+ The [MIT License](https://github.com/icflorescu/mantine-contextmenu/blob/master/LICENSE).
83
+
84
+ [npm-url]: https://npmjs.org/package/mantine-contextmenu
85
+ [repo-url]: https://github.com/icflorescu/mantine-contextmenu
86
+ [stars-url]: https://github.com/icflorescu/mantine-contextmenu/stargazers
87
+ [closed-issues-url]: https://github.com/icflorescu/mantine-contextmenu/issues?q=is%3Aissue+is%3Aclosed
88
+ [license-url]: LICENSE
89
+ [npm-image]: https://img.shields.io/npm/v/mantine-contextmenu.svg?style=flat-square
90
+ [license-image]: http://img.shields.io/npm/l/mantine-contextmenu.svg?style=flat-square
91
+ [downloads-image]: http://img.shields.io/npm/dm/mantine-contextmenu.svg?style=flat-square
92
+ [stars-image]: https://img.shields.io/github/stars/icflorescu/mantine-contextmenu?style=flat-square
93
+ [last-commit-image]: https://img.shields.io/github/last-commit/icflorescu/mantine-contextmenu?style=flat-square
94
+ [closed-issues-image]: https://img.shields.io/github/issues-closed-raw/icflorescu/mantine-contextmenu?style=flat-square
95
+ [language-image]: https://img.shields.io/github/languages/top/icflorescu/mantine-contextmenu?style=flat-square
@@ -0,0 +1,12 @@
1
+ import { ContextMenuItemOptions, ContextMenuOptions } from './types';
2
+ export type ContextMenuInstanceOptions = {
3
+ x: number;
4
+ y: number;
5
+ items: ContextMenuItemOptions[];
6
+ };
7
+ type ContextMenuProps = ContextMenuOptions & ContextMenuInstanceOptions & {
8
+ onHide: () => void;
9
+ };
10
+ export declare function ContextMenu({ x, y, items, zIndex, shadow, borderRadius, onHide }: ContextMenuProps): JSX.Element;
11
+ export {};
12
+ //# sourceMappingURL=ContextMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenu.d.ts","sourceRoot":"","sources":["../ContextMenu.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAYrE,MAAM,MAAM,0BAA0B,GAAG;IACvC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,sBAAsB,EAAE,CAAC;CACjC,CAAC;AAEF,KAAK,gBAAgB,GAAG,kBAAkB,GACxC,0BAA0B,GAAG;IAC3B,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEJ,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,gBAAgB,eAmDlG"}
@@ -0,0 +1,2 @@
1
+ export default function ContextMenuDivider(): JSX.Element;
2
+ //# sourceMappingURL=ContextMenuDivider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuDivider.d.ts","sourceRoot":"","sources":["../ContextMenuDivider.tsx"],"names":[],"mappings":"AASA,MAAM,CAAC,OAAO,UAAU,kBAAkB,gBAGzC"}
@@ -0,0 +1,4 @@
1
+ import { ContextMenuItemOptions } from './types';
2
+ import { WithRequiredProperty } from './utils';
3
+ export default function ContextMenuItem({ icon, title, color, disabled, onClick, }: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title' | 'onClick'>): JSX.Element;
4
+ //# sourceMappingURL=ContextMenuItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuItem.d.ts","sourceRoot":"","sources":["../ContextMenuItem.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AA0C/C,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,IAAI,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,GACR,EAAE,oBAAoB,CAAC,IAAI,CAAC,sBAAsB,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC,eAUhF"}
@@ -0,0 +1,12 @@
1
+ import type { ContextMenuProviderProps, ShowContextMenuFunction } from './types';
2
+ /**
3
+ * Provider that allows to show a context menu anywhere in your application.
4
+ * If you wrap your application with this provider, you can use the `useContextMenu` hook
5
+ * anywhere in the component tree to access a function that shows the context menu.
6
+ */
7
+ export declare function ContextMenuProvider({ zIndex, shadow, borderRadius, children, }: ContextMenuProviderProps): JSX.Element;
8
+ /**
9
+ * Hook returning a function that shows a context menu.
10
+ */
11
+ export declare function useContextMenu(): ShowContextMenuFunction;
12
+ //# sourceMappingURL=ContextMenuProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenuProvider.d.ts","sourceRoot":"","sources":["../ContextMenuProvider.tsx"],"names":[],"mappings":"AAEA,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,eAyB1B;AAED;;GAEG;AACH,wBAAgB,cAAc,4BAE7B"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var q=Object.create;var g=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var X=(e,t)=>{for(var o in t)g(e,o,{get:t[o],enumerable:!0})},I=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of U(t))!K.call(e,n)&&n!==o&&g(e,n,{get:()=>t[n],enumerable:!(i=F(t,n))||i.enumerable});return e};var Y=(e,t,o)=>(o=e!=null?q(A(e)):{},I(t||!e||!e.__esModule?g(o,"default",{value:e,enumerable:!0}):o,e)),Z=e=>I(g({},"__esModule",{value:!0}),e);var j={};X(j,{ContextMenuProvider:()=>Q,humanize:()=>k,useContextMenu:()=>V});module.exports=Z(j);var p=Y(require("react"),1);var m=require("react");var x=require("@mantine/core"),s=require("@mantine/hooks");var z=require("@mantine/core"),R=require("react/jsx-runtime"),_=(0,z.createStyles)(e=>({root:{height:1,background:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[1]}}));function h(){let{classes:e}=_();return(0,R.jsx)("div",{className:e.root})}var r=require("@mantine/core"),C=require("react/jsx-runtime"),G=(0,r.createStyles)((e,{color:t})=>{let o=(0,r.px)(e.spacing.sm)/2;return{root:{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)}},icon:{fontSize:0,marginRight:e.spacing.xs},title:{whiteSpace:"nowrap"}}});function O({icon:e,title:t,color:o,disabled:i,onClick:n}){let{classes:a}=G({color:o});return(0,C.jsxs)(r.UnstyledButton,{className:a.root,disabled:i,onClick:n,children:[e&&(0,C.jsx)(r.Box,{className:a.icon,children:e}),(0,C.jsx)(r.Text,{className:a.title,size:"sm",children:t})]})}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)}`}var w=require("react/jsx-runtime"),J=(0,x.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 T({x:e,y:t,items:o,zIndex:i,shadow:n,borderRadius:a,onHide:l}){(0,s.useWindowEvent)("resize",l),(0,s.useWindowEvent)("scroll",l);let v=(0,s.useClickOutside)(l),{ref:P,width:d,height:u}=(0,s.useElementSize)(),B=(0,s.useMergedRef)(v,P),M=0,b=0;typeof window<"u"&&({innerWidth:M,innerHeight:b}=window);let{classes:H,theme:{dir:W,spacing:D}}=J(),c=(0,x.px)(D.md),L=f=>y=>{l(),f(y)};return(0,w.jsx)(x.Paper,{ref:B,shadow:n,radius:a,className:H.root,sx:{zIndex:i,top:t+u+c>b?b-u-c:t,left:W==="ltr"?e+d+c>M?M-d-c:e:M-c-(e-d-c<0?d+c:e)},children:o.map(({key:f,onClick:y,title:N,...$})=>y?(0,w.jsx)(O,{title:N??k(f),onClick:L(y),...$},f):(0,w.jsx)(h,{},f))})}var S=require("react/jsx-runtime"),E=(0,m.createContext)(()=>()=>{});function Q({zIndex:e=9999,shadow:t="sm",borderRadius:o="xs",children:i}){let[n,a]=(0,m.useState)(null),l=()=>{a(null)},v=(P,d)=>u=>{u.preventDefault(),a({x:u.clientX,y:u.clientY,items:P,zIndex:d?.zIndex||e,shadow:d?.shadow||t,borderRadius:d?.borderRadius||o})};return(0,S.jsxs)(E.Provider,{value:v,children:[i,n&&(0,S.jsx)(T,{onHide:l,...n})]})}function V(){return(0,m.useContext)(E)}
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../index.ts", "../react-shim.mjs", "../ContextMenuProvider.tsx", "../ContextMenu.tsx", "../ContextMenuDivider.tsx", "../ContextMenuItem.tsx", "../utils.ts"],
4
+ "sourcesContent": ["export * from './ContextMenuProvider';\nexport { humanize } from './utils';\n", "import * as React from 'react';\nexport { React };\n", "import { createContext, useContext, useState } from 'react';\nimport { ContextMenu, ContextMenuInstanceOptions } from './ContextMenu';\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 = (items, options) => (e) => {\n e.preventDefault();\n setData({\n x: e.clientX,\n y: e.clientY,\n items,\n zIndex: options?.zIndex || zIndex,\n shadow: options?.shadow || shadow,\n borderRadius: options?.borderRadius || borderRadius,\n });\n };\n\n return (\n <MenuContext.Provider value={showContextMenu}>\n {children}\n {data && <ContextMenu 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", "import { Paper, createStyles, px } from '@mantine/core';\nimport { useClickOutside, useElementSize, useMergedRef, useWindowEvent } from '@mantine/hooks';\nimport { MouseEventHandler } from 'react';\nimport ContextMenuDivider from './ContextMenuDivider';\nimport ContextMenuItem from './ContextMenuItem';\nimport { ContextMenuItemOptions, ContextMenuOptions } from './types';\nimport { humanize } from './utils';\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 items: ContextMenuItemOptions[];\n};\n\ntype ContextMenuProps = ContextMenuOptions &\n ContextMenuInstanceOptions & {\n onHide: () => void;\n };\n\nexport function ContextMenu({ x, y, items, zIndex, shadow, borderRadius, onHide }: ContextMenuProps) {\n useWindowEvent('resize', onHide);\n useWindowEvent('scroll', onHide);\n\n const clickOutsideRef = useClickOutside<HTMLDivElement>(onHide);\n const { ref: sizeRef, width, height } = useElementSize();\n const ref = useMergedRef(clickOutsideRef, sizeRef);\n\n let windowWidth = 0;\n let windowHeight = 0;\n if (typeof window !== 'undefined') ({ innerWidth: windowWidth, innerHeight: windowHeight } = window);\n\n const {\n classes,\n theme: { dir, spacing },\n } = useStyles();\n\n const mdSpacing = px(spacing.md);\n\n const handleClick: (onClick: MouseEventHandler<HTMLButtonElement>) => MouseEventHandler<HTMLButtonElement> =\n (onClick) => (e) => {\n onHide();\n onClick(e);\n };\n\n return (\n <Paper\n ref={ref}\n shadow={shadow}\n radius={borderRadius}\n className={classes.root}\n sx={{\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 {items.map(({ key, onClick, title, ...otherOptions }) =>\n onClick ? (\n <ContextMenuItem key={key} title={title ?? humanize(key)} onClick={handleClick(onClick)} {...otherOptions} />\n ) : (\n <ContextMenuDivider key={key} />\n )\n )}\n </Paper>\n );\n}\n", "import { createStyles } from '@mantine/core';\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 default function ContextMenuDivider() {\n const { classes } = useStyles();\n return <div className={classes.root} />;\n}\n", "import { Box, Text, UnstyledButton, createStyles, px, type MantineColor } from '@mantine/core';\nimport { 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 root: {\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 icon: {\n fontSize: 0,\n marginRight: theme.spacing.xs,\n },\n title: {\n whiteSpace: 'nowrap',\n },\n };\n});\n\nexport default function ContextMenuItem({\n icon,\n title,\n color,\n disabled,\n onClick,\n}: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title' | 'onClick'>) {\n const { classes } = useStyles({ color });\n return (\n <UnstyledButton className={classes.root} disabled={disabled} onClick={onClick}>\n {icon && <Box className={classes.icon}>{icon}</Box>}\n <Text className={classes.title} size=\"sm\">\n {title}\n </Text>\n </UnstyledButton>\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"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,aAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAuB,sBCAvB,IAAAC,EAAoD,iBCApD,IAAAC,EAAwC,yBACxCC,EAA8E,0BCD9E,IAAAC,EAA6B,yBAWpBC,EAAA,6BATHC,KAAY,gBAAcC,IAAW,CACzC,KAAM,CACJ,OAAQ,EACR,WAAYA,EAAM,cAAgB,OAASA,EAAM,OAAO,KAAK,CAAC,EAAIA,EAAM,OAAO,KAAK,CAAC,CACvF,CACF,EAAE,EAEa,SAARC,GAAsC,CAC3C,GAAM,CAAE,QAAAC,CAAQ,EAAIH,EAAU,EAC9B,SAAO,OAAC,OAAI,UAAWG,EAAQ,KAAM,CACvC,CCZA,IAAAC,EAA+E,yBAqD3EC,EAAA,6BAjDEC,KAAY,gBAAa,CAACC,EAAO,CAAE,MAAAC,CAAM,IAAgC,CAC7E,IAAMC,KAAkB,MAAGF,EAAM,QAAQ,EAAE,EAAI,EAC/C,MAAO,CACL,KAAM,CACJ,MAAO,OACP,QAAS,OACT,WAAY,SACZ,WAAYE,EACZ,cAAeA,EACf,YAAaF,EAAM,QAAQ,GAC3B,aAAcA,EAAM,QAAQ,GAC5B,MAAOC,GAASD,EAAM,OAAOC,CAAK,EAAE,CAAC,EACrC,WAAY,uBACZ,cAAe,CACb,OAAQ,cACR,MAAOD,EAA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AG,QAASH,EAAYC,CAAO,EAAI,GAAGI,GAAvEF,CAAqF,KAE3G,OAACK,EAAA,GAAwBL,CAAK,CAElC,EACF,CAEJ,CD3CI,IAAAM,EAAA,6BAhCEC,KAAc,iBAAuC,IAAM,IAAG,EAAY,EAOzE,SAASC,EAAoB,CAClC,OAAAC,EAAS,KACT,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,EAAOC,IAAaC,GAAM,CAC1EA,EAAE,eAAe,EACjBL,EAAQ,CACN,EAAGK,EAAE,QACL,EAAGA,EAAE,QACL,MAAAF,EACA,OAAQC,GAAS,QAAUT,EAC3B,OAAQS,GAAS,QAAUR,EAC3B,aAAcQ,GAAS,cAAgBP,CACzC,CAAC,CACH,EAEA,SACE,QAACJ,EAAY,SAAZ,CAAqB,MAAOS,EAC1B,UAAAJ,EACAC,MAAQ,OAACO,EAAA,CAAY,OAAQL,EAAU,GAAGF,EAAM,GACnD,CAEJ,CAKO,SAASQ,GAAiB,CAC/B,SAAO,cAAWd,CAAW,CAC/B",
6
+ "names": ["package_exports", "__export", "ContextMenuProvider", "humanize", "useContextMenu", "__toCommonJS", "React", "import_react", "import_core", "import_hooks", "import_core", "import_jsx_runtime", "useStyles", "theme", "ContextMenuDivider", "classes", "import_core", "import_jsx_runtime", "useStyles", "theme", "color", "verticalPadding", "ContextMenuItem", "icon", "title", "disabled", "onClick", "classes", "humanize", "value", "str", "import_jsx_runtime", "useStyles", "theme", "ContextMenu", "x", "y", "items", "zIndex", "shadow", "borderRadius", "onHide", "clickOutsideRef", "sizeRef", "width", "height", "ref", "windowWidth", "windowHeight", "classes", "dir", "spacing", "mdSpacing", "handleClick", "onClick", "e", "key", "title", "otherOptions", "ContextMenuItem", "humanize", "ContextMenuDivider", "import_jsx_runtime", "MenuContext", "ContextMenuProvider", "zIndex", "shadow", "borderRadius", "children", "data", "setData", "destroy", "showContextMenu", "items", "options", "e", "ContextMenu", "useContextMenu"]
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ContextMenuProvider';
2
+ export { humanize } from './utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import*as c from"react";import{createContext as G,useContext as J,useState as Q}from"react";import{Paper as U,createStyles as A,px as K}from"@mantine/core";import{useClickOutside as X,useElementSize as Y,useMergedRef as Z,useWindowEvent as S}from"@mantine/hooks";import{createStyles as E}from"@mantine/core";import{jsx as H}from"react/jsx-runtime";var B=E(e=>({root:{height:1,background:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[1]}}));function M(){let{classes:e}=B();return H("div",{className:e.root})}import{Box as W,Text as D,UnstyledButton as L,createStyles as N,px as $}from"@mantine/core";import{jsx as w,jsxs as F}from"react/jsx-runtime";var q=N((e,{color:t})=>{let o=$(e.spacing.sm)/2;return{root:{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)}},icon:{fontSize:0,marginRight:e.spacing.xs},title:{whiteSpace:"nowrap"}}});function y({icon:e,title:t,color:o,disabled:l,onClick:i}){let{classes:n}=q({color:o});return F(L,{className:n.root,disabled:l,onClick:i,children:[e&&w(W,{className:n.icon,children:e}),w(D,{className:n.title,size:"sm",children:t})]})}function g(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 k}from"react/jsx-runtime";var _=A(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 v({x:e,y:t,items:o,zIndex:l,shadow:i,borderRadius:n,onHide:a}){S("resize",a),S("scroll",a);let m=X(a),{ref:f,width:r,height:d}=Y(),b=Z(m,f),p=0,C=0;typeof window<"u"&&({innerWidth:p,innerHeight:C}=window);let{classes:h,theme:{dir:O,spacing:I}}=_(),s=K(I.md),z=u=>x=>{a(),u(x)};return k(U,{ref:b,shadow:i,radius:n,className:h.root,sx:{zIndex:l,top:t+d+s>C?C-d-s:t,left:O==="ltr"?e+r+s>p?p-r-s:e:p-s-(e-r-s<0?r+s:e)},children:o.map(({key:u,onClick:x,title:R,...T})=>x?k(y,{title:R??g(u),onClick:z(x),...T},u):k(M,{},u))})}import{jsx as V,jsxs as j}from"react/jsx-runtime";var P=G(()=>()=>{});function Se({zIndex:e=9999,shadow:t="sm",borderRadius:o="xs",children:l}){let[i,n]=Q(null),a=()=>{n(null)},m=(f,r)=>d=>{d.preventDefault(),n({x:d.clientX,y:d.clientY,items:f,zIndex:r?.zIndex||e,shadow:r?.shadow||t,borderRadius:r?.borderRadius||o})};return j(P.Provider,{value:m,children:[l,i&&V(v,{onHide:a,...i})]})}function ve(){return J(P)}export{Se as ContextMenuProvider,g as humanize,ve as useContextMenu};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../react-shim.mjs", "../ContextMenuProvider.tsx", "../ContextMenu.tsx", "../ContextMenuDivider.tsx", "../ContextMenuItem.tsx", "../utils.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { createContext, useContext, useState } from 'react';\nimport { ContextMenu, ContextMenuInstanceOptions } from './ContextMenu';\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 = (items, options) => (e) => {\n e.preventDefault();\n setData({\n x: e.clientX,\n y: e.clientY,\n items,\n zIndex: options?.zIndex || zIndex,\n shadow: options?.shadow || shadow,\n borderRadius: options?.borderRadius || borderRadius,\n });\n };\n\n return (\n <MenuContext.Provider value={showContextMenu}>\n {children}\n {data && <ContextMenu 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", "import { Paper, createStyles, px } from '@mantine/core';\nimport { useClickOutside, useElementSize, useMergedRef, useWindowEvent } from '@mantine/hooks';\nimport { MouseEventHandler } from 'react';\nimport ContextMenuDivider from './ContextMenuDivider';\nimport ContextMenuItem from './ContextMenuItem';\nimport { ContextMenuItemOptions, ContextMenuOptions } from './types';\nimport { humanize } from './utils';\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 items: ContextMenuItemOptions[];\n};\n\ntype ContextMenuProps = ContextMenuOptions &\n ContextMenuInstanceOptions & {\n onHide: () => void;\n };\n\nexport function ContextMenu({ x, y, items, zIndex, shadow, borderRadius, onHide }: ContextMenuProps) {\n useWindowEvent('resize', onHide);\n useWindowEvent('scroll', onHide);\n\n const clickOutsideRef = useClickOutside<HTMLDivElement>(onHide);\n const { ref: sizeRef, width, height } = useElementSize();\n const ref = useMergedRef(clickOutsideRef, sizeRef);\n\n let windowWidth = 0;\n let windowHeight = 0;\n if (typeof window !== 'undefined') ({ innerWidth: windowWidth, innerHeight: windowHeight } = window);\n\n const {\n classes,\n theme: { dir, spacing },\n } = useStyles();\n\n const mdSpacing = px(spacing.md);\n\n const handleClick: (onClick: MouseEventHandler<HTMLButtonElement>) => MouseEventHandler<HTMLButtonElement> =\n (onClick) => (e) => {\n onHide();\n onClick(e);\n };\n\n return (\n <Paper\n ref={ref}\n shadow={shadow}\n radius={borderRadius}\n className={classes.root}\n sx={{\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 {items.map(({ key, onClick, title, ...otherOptions }) =>\n onClick ? (\n <ContextMenuItem key={key} title={title ?? humanize(key)} onClick={handleClick(onClick)} {...otherOptions} />\n ) : (\n <ContextMenuDivider key={key} />\n )\n )}\n </Paper>\n );\n}\n", "import { createStyles } from '@mantine/core';\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 default function ContextMenuDivider() {\n const { classes } = useStyles();\n return <div className={classes.root} />;\n}\n", "import { Box, Text, UnstyledButton, createStyles, px, type MantineColor } from '@mantine/core';\nimport { 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 root: {\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 icon: {\n fontSize: 0,\n marginRight: theme.spacing.xs,\n },\n title: {\n whiteSpace: 'nowrap',\n },\n };\n});\n\nexport default function ContextMenuItem({\n icon,\n title,\n color,\n disabled,\n onClick,\n}: WithRequiredProperty<Omit<ContextMenuItemOptions, 'key'>, 'title' | 'onClick'>) {\n const { classes } = useStyles({ color });\n return (\n <UnstyledButton className={classes.root} disabled={disabled} onClick={onClick}>\n {icon && <Box className={classes.icon}>{icon}</Box>}\n <Text className={classes.title} size=\"sm\">\n {title}\n </Text>\n </UnstyledButton>\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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,EAAI,GAAGK,GAAvEF,CAAqF,EAE3GhC,EAACqC,EAAA,GAAwBL,CAAK,CAElC,EACF,CAEJ,CD3CI,OAEW,OAAAM,EAFX,QAAAC,MAAA,oBAhCJ,IAAMC,EAAcC,EAAuC,IAAM,IAAG,EAAY,EAOzE,SAASC,GAAoB,CAClC,OAAAC,EAAS,KACT,OAAAC,EAAS,KACT,aAAAC,EAAe,KACf,SAAAC,CACF,EAA6B,CAC3B,GAAM,CAACC,EAAMC,CAAO,EAAIC,EAAmE,IAAI,EAEzFC,EAAU,IAAM,CACpBF,EAAQ,IAAI,CACd,EAEMG,EAA2C,CAACC,EAAOC,IAAaC,GAAM,CAC1EA,EAAE,eAAe,EACjBN,EAAQ,CACN,EAAGM,EAAE,QACL,EAAGA,EAAE,QACL,MAAAF,EACA,OAAQC,GAAS,QAAUV,EAC3B,OAAQU,GAAS,QAAUT,EAC3B,aAAcS,GAAS,cAAgBR,CACzC,CAAC,CACH,EAEA,OACEN,EAACC,EAAY,SAAZ,CAAqB,MAAOW,EAC1B,UAAAL,EACAC,GAAQT,EAACiB,EAAA,CAAY,OAAQL,EAAU,GAAGH,EAAM,GACnD,CAEJ,CAKO,SAASS,IAAiB,CAC/B,OAAOC,EAAWjB,CAAW,CAC/B",
6
+ "names": ["React", "createContext", "useContext", "useState", "Paper", "createStyles", "px", "useClickOutside", "useElementSize", "useMergedRef", "useWindowEvent", "createStyles", "jsx", "useStyles", "theme", "ContextMenuDivider", "classes", "Box", "Text", "UnstyledButton", "createStyles", "px", "jsx", "jsxs", "useStyles", "theme", "color", "verticalPadding", "ContextMenuItem", "icon", "title", "disabled", "onClick", "classes", "humanize", "value", "str", "jsx", "useStyles", "createStyles", "theme", "ContextMenu", "x", "y", "items", "zIndex", "shadow", "borderRadius", "onHide", "useWindowEvent", "clickOutsideRef", "useClickOutside", "sizeRef", "width", "height", "useElementSize", "ref", "useMergedRef", "windowWidth", "windowHeight", "classes", "dir", "spacing", "mdSpacing", "px", "handleClick", "onClick", "e", "Paper", "key", "title", "otherOptions", "ContextMenuItem", "humanize", "ContextMenuDivider", "jsx", "jsxs", "MenuContext", "createContext", "ContextMenuProvider", "zIndex", "shadow", "borderRadius", "children", "data", "setData", "useState", "destroy", "showContextMenu", "items", "options", "e", "ContextMenu", "useContextMenu", "useContext"]
7
+ }
@@ -0,0 +1,66 @@
1
+ import type { MantineColor, MantineNumberSize, MantineShadow } from '@mantine/core';
2
+ import type { MouseEventHandler, ReactNode } from 'react';
3
+ export type ContextMenuOptions = {
4
+ /**
5
+ * zIndex of context menu
6
+ * @default 9999
7
+ */
8
+ zIndex?: number;
9
+ /**
10
+ * Context menu shadow
11
+ * @default 'sm'
12
+ */
13
+ shadow?: MantineShadow;
14
+ /**
15
+ * Context menu border radius
16
+ * @default 'xs'
17
+ */
18
+ borderRadius?: MantineNumberSize;
19
+ };
20
+ export type ContextMenuProviderProps = ContextMenuOptions & {
21
+ children: ReactNode;
22
+ };
23
+ export type ContextMenuItemOptions = {
24
+ /**
25
+ * Unique key of the context menu item
26
+ */
27
+ key: string;
28
+ } & ({
29
+ /**
30
+ * Optional context menu item icon
31
+ */
32
+ icon?: ReactNode;
33
+ /**
34
+ * Optional context menu item title; if not provided, one will be generated automatically by "humanizing" the key
35
+ * @default humanize(key)
36
+ */
37
+ title?: ReactNode;
38
+ /**
39
+ * Optional context menu item color
40
+ */
41
+ color?: MantineColor;
42
+ /**
43
+ * Boolean indicating whether the context menu item is disabled
44
+ */
45
+ disabled?: boolean;
46
+ /**
47
+ * Optional context menu item `onClick` handler; if not provided, a divider will be rendered instead
48
+ */
49
+ onClick: MouseEventHandler<HTMLButtonElement>;
50
+ } | {
51
+ icon?: never;
52
+ title?: never;
53
+ color?: never;
54
+ disabled?: never;
55
+ onClick?: never;
56
+ });
57
+ export type ShowContextMenuFunction = (
58
+ /**
59
+ * Context menu items
60
+ */
61
+ items: ContextMenuItemOptions[],
62
+ /**
63
+ * Context menu options (overrides provider options)
64
+ */
65
+ options?: ContextMenuOptions) => MouseEventHandler;
66
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,CACA;IACE;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;CAC/C,GACD;IACE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,CACJ,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;AACpC;;GAEG;AACH,KAAK,EAAE,sBAAsB,EAAE;AAE/B;;GAEG;AACH,OAAO,CAAC,EAAE,kBAAkB,KACzB,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
2
+ [Property in Key]-?: Type[Property];
3
+ };
4
+ /**
5
+ * Utility function that returns a humanized version of a string, e.g. "camelCase" -> "Camel Case"
6
+ */
7
+ export declare function humanize(value: string): string;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,CAAC,IAAI,EAAE,GAAG,SAAS,MAAM,IAAI,IAAI,IAAI,GAAG;KACrE,QAAQ,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,UAOrC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "mantine-contextmenu",
3
+ "version": "1.0.0",
4
+ "description": "ContextMenu for Mantine UI",
5
+ "keywords": [
6
+ "ui",
7
+ "mantine",
8
+ "datatable",
9
+ "datagrid",
10
+ "async",
11
+ "sorting",
12
+ "pagination",
13
+ "context menu",
14
+ "react",
15
+ "typescript"
16
+ ],
17
+ "repository": "icflorescu/mantine-contextmenu",
18
+ "homepage": "https://icflorescu.github.io/mantine-contextmenu/",
19
+ "bugs": {
20
+ "url": "https://github.com/icflorescu/mantine-contextmenu/issues"
21
+ },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Ionut-Cristian Florescu",
25
+ "email": "ionut.florescu@gmail.com",
26
+ "url": "https://github.com/icflorescu"
27
+ },
28
+ "main": "dist/index.cjs",
29
+ "module": "dist/index.mjs",
30
+ "types": "dist/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "dev": "rm -rf dist",
38
+ "build": "rm -rf dist && NODE_NO_WARNINGS=1 node build.mjs && tsc --emitDeclarationOnly",
39
+ "postbuild": "cp -f ../LICENSE LICENSE && cp -f ../README.md README.md",
40
+ "lint": "eslint . --ext=.ts,.tsx && tsc --noEmit"
41
+ },
42
+ "devDependencies": {
43
+ "@mantine/core": "^6.0.6",
44
+ "@mantine/hooks": "^6.0.6",
45
+ "@tabler/icons-react": "^2.14.0",
46
+ "@types/react": "^18.0.33",
47
+ "@types/react-dom": "^18.0.11",
48
+ "esbuild": "^0.17.15",
49
+ "react": "^18.2.0",
50
+ "typescript": "^5.0.4"
51
+ },
52
+ "peerDependencies": {
53
+ "@mantine/core": "^6.0.5",
54
+ "@mantine/hooks": "^6.0.5",
55
+ "react": "^18.2.0"
56
+ }
57
+ }