@octolo/js-contextmenu-react 0.1.0 → 0.4.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/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +2 -2
- package/package.json +7 -2
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAExF,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAExF,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAExF,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAExF,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAyBxE;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,IAAI,EACJ,UAA4B,EAC5B,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,EACT,EAAE,uBAAuB,+BA2BzB"}
|
package/dist/index.js
CHANGED
|
@@ -7,13 +7,23 @@ import { createContextMenu } from "@octolo/js-contextmenu";
|
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
function useContextMenu(options) {
|
|
9
9
|
const menuRef = useRef(null);
|
|
10
|
+
const lifecycleRef = useRef(0);
|
|
10
11
|
if (!menuRef.current) {
|
|
11
12
|
menuRef.current = createContextMenu(options);
|
|
12
13
|
}
|
|
13
14
|
useEffect(() => {
|
|
15
|
+
lifecycleRef.current += 1;
|
|
16
|
+
const mountedMenu = menuRef.current;
|
|
14
17
|
return () => {
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
const cleanupVersion = ++lifecycleRef.current;
|
|
19
|
+
queueMicrotask(() => {
|
|
20
|
+
if (lifecycleRef.current !== cleanupVersion || menuRef.current !== mountedMenu) return;
|
|
21
|
+
try {
|
|
22
|
+
mountedMenu?.destroy();
|
|
23
|
+
} finally {
|
|
24
|
+
menuRef.current = null;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
17
27
|
};
|
|
18
28
|
}, []);
|
|
19
29
|
return menuRef.current;
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n useEffect,\n useRef,\n type CSSProperties,\n type ReactNode\n} from \"react\";\nimport { createContextMenu } from \"@octolo/js-contextmenu\";\nimport type { ContextMenu, ContextMenuOptions, MenuItem } from \"@octolo/js-contextmenu\";\n\nexport type { MenuItem, ContextMenu, ContextMenuOptions } from \"@octolo/js-contextmenu\";\n\nexport function useContextMenu(options?: ContextMenuOptions): ContextMenu {\n const menuRef = useRef<ContextMenu | null>(null);\n if (!menuRef.current) {\n menuRef.current = createContextMenu(options);\n }\n useEffect(() => {\n return () => {\n menuRef.current?.destroy();\n
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,yBAAyB;
|
|
4
|
+
"sourcesContent": ["import {\n useEffect,\n useRef,\n type CSSProperties,\n type ReactNode\n} from \"react\";\nimport { createContextMenu } from \"@octolo/js-contextmenu\";\nimport type { ContextMenu, ContextMenuOptions, MenuItem } from \"@octolo/js-contextmenu\";\n\nexport type { MenuItem, ContextMenu, ContextMenuOptions } from \"@octolo/js-contextmenu\";\n\nexport function useContextMenu(options?: ContextMenuOptions): ContextMenu {\n const menuRef = useRef<ContextMenu | null>(null);\n const lifecycleRef = useRef(0);\n if (!menuRef.current) {\n menuRef.current = createContextMenu(options);\n }\n useEffect(() => {\n lifecycleRef.current += 1;\n const mountedMenu = menuRef.current;\n return () => {\n const cleanupVersion = ++lifecycleRef.current;\n queueMicrotask(() => {\n if (\n lifecycleRef.current !== cleanupVersion ||\n menuRef.current !== mountedMenu\n ) return;\n try {\n mountedMenu?.destroy();\n } finally {\n menuRef.current = null;\n }\n });\n };\n }, []);\n return menuRef.current;\n}\n\nexport interface ContextMenuTriggerProps {\n items: MenuItem[];\n data?: unknown;\n openEvents?: string[];\n options?: ContextMenuOptions;\n className?: string;\n style?: CSSProperties;\n children?: ReactNode;\n}\n\nexport function ContextMenuTrigger({\n items,\n data,\n openEvents = [\"contextmenu\"],\n options,\n className,\n style,\n children\n}: ContextMenuTriggerProps) {\n const host = useRef<HTMLDivElement>(null);\n const itemsRef = useRef(items);\n const dataRef = useRef(data);\n itemsRef.current = items;\n dataRef.current = data;\n\n useEffect(() => {\n const el = host.current;\n if (!el) return undefined;\n const menu = createContextMenu(options);\n const unbind = menu.attach(\n el,\n () => ({ items: itemsRef.current, data: dataRef.current }),\n { openEvents }\n );\n return () => {\n unbind();\n menu.destroy();\n };\n }, [options, openEvents]);\n\n return (\n <div ref={host} className={className} style={style}>\n {children}\n </div>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,yBAAyB;AAyE9B;AApEG,SAAS,eAAe,SAA2C;AACxE,QAAM,UAAU,OAA2B,IAAI;AAC/C,QAAM,eAAe,OAAO,CAAC;AAC7B,MAAI,CAAC,QAAQ,SAAS;AACpB,YAAQ,UAAU,kBAAkB,OAAO;AAAA,EAC7C;AACA,YAAU,MAAM;AACd,iBAAa,WAAW;AACxB,UAAM,cAAc,QAAQ;AAC5B,WAAO,MAAM;AACX,YAAM,iBAAiB,EAAE,aAAa;AACtC,qBAAe,MAAM;AACnB,YACE,aAAa,YAAY,kBACzB,QAAQ,YAAY,YACpB;AACF,YAAI;AACF,uBAAa,QAAQ;AAAA,QACvB,UAAE;AACA,kBAAQ,UAAU;AAAA,QACpB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,CAAC;AACL,SAAO,QAAQ;AACjB;AAYO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA,aAAa,CAAC,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4B;AAC1B,QAAM,OAAO,OAAuB,IAAI;AACxC,QAAM,WAAW,OAAO,KAAK;AAC7B,QAAM,UAAU,OAAO,IAAI;AAC3B,WAAS,UAAU;AACnB,UAAQ,UAAU;AAElB,YAAU,MAAM;AACd,UAAM,KAAK,KAAK;AAChB,QAAI,CAAC,GAAI,QAAO;AAChB,UAAM,OAAO,kBAAkB,OAAO;AACtC,UAAM,SAAS,KAAK;AAAA,MAClB;AAAA,MACA,OAAO,EAAE,OAAO,SAAS,SAAS,MAAM,QAAQ,QAAQ;AAAA,MACxD,EAAE,WAAW;AAAA,IACf;AACA,WAAO,MAAM;AACX,aAAO;AACP,WAAK,QAAQ;AAAA,IACf;AAAA,EACF,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SACE,oBAAC,SAAI,KAAK,MAAM,WAAsB,OACnC,UACH;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octolo/js-contextmenu-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "React wrapper for js-contextmenu.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/octolo/js-contextmenu.git",
|
|
8
|
+
"directory": "packages/react"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"types": "./dist/index.d.ts",
|
|
@@ -15,7 +20,7 @@
|
|
|
15
20
|
"dist"
|
|
16
21
|
],
|
|
17
22
|
"dependencies": {
|
|
18
|
-
"@octolo/js-contextmenu": "^0.
|
|
23
|
+
"@octolo/js-contextmenu": "^0.4.0"
|
|
19
24
|
},
|
|
20
25
|
"peerDependencies": {
|
|
21
26
|
"react": ">=18",
|