@octolo/js-contextmenu-react 0.0.0-stage → 0.1.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.
@@ -0,0 +1,15 @@
1
+ import { type CSSProperties, type ReactNode } from "react";
2
+ import type { ContextMenu, ContextMenuOptions, MenuItem } from "@octolo/js-contextmenu";
3
+ export type { MenuItem, ContextMenu, ContextMenuOptions } from "@octolo/js-contextmenu";
4
+ export declare function useContextMenu(options?: ContextMenuOptions): ContextMenu;
5
+ export interface ContextMenuTriggerProps {
6
+ items: MenuItem[];
7
+ data?: unknown;
8
+ openEvents?: string[];
9
+ options?: ContextMenuOptions;
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ children?: ReactNode;
13
+ }
14
+ export declare function ContextMenuTrigger({ items, data, openEvents, options, className, style, children }: ContextMenuTriggerProps): import("react").JSX.Element;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,CAYxE;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 ADDED
@@ -0,0 +1,55 @@
1
+ // src/index.tsx
2
+ import {
3
+ useEffect,
4
+ useRef
5
+ } from "react";
6
+ import { createContextMenu } from "@octolo/js-contextmenu";
7
+ import { jsx } from "react/jsx-runtime";
8
+ function useContextMenu(options) {
9
+ const menuRef = useRef(null);
10
+ if (!menuRef.current) {
11
+ menuRef.current = createContextMenu(options);
12
+ }
13
+ useEffect(() => {
14
+ return () => {
15
+ menuRef.current?.destroy();
16
+ menuRef.current = null;
17
+ };
18
+ }, []);
19
+ return menuRef.current;
20
+ }
21
+ function ContextMenuTrigger({
22
+ items,
23
+ data,
24
+ openEvents = ["contextmenu"],
25
+ options,
26
+ className,
27
+ style,
28
+ children
29
+ }) {
30
+ const host = useRef(null);
31
+ const itemsRef = useRef(items);
32
+ const dataRef = useRef(data);
33
+ itemsRef.current = items;
34
+ dataRef.current = data;
35
+ useEffect(() => {
36
+ const el = host.current;
37
+ if (!el) return void 0;
38
+ const menu = createContextMenu(options);
39
+ const unbind = menu.attach(
40
+ el,
41
+ () => ({ items: itemsRef.current, data: dataRef.current }),
42
+ { openEvents }
43
+ );
44
+ return () => {
45
+ unbind();
46
+ menu.destroy();
47
+ };
48
+ }, [options, openEvents]);
49
+ return /* @__PURE__ */ jsx("div", { ref: host, className, style, children });
50
+ }
51
+ export {
52
+ ContextMenuTrigger,
53
+ useContextMenu
54
+ };
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 menuRef.current = null;\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;AA4D9B;AAvDG,SAAS,eAAe,SAA2C;AACxE,QAAM,UAAU,OAA2B,IAAI;AAC/C,MAAI,CAAC,QAAQ,SAAS;AACpB,YAAQ,UAAU,kBAAkB,OAAO;AAAA,EAC7C;AACA,YAAU,MAAM;AACd,WAAO,MAAM;AACX,cAAQ,SAAS,QAAQ;AACzB,cAAQ,UAAU;AAAA,IACpB;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
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@octolo/js-contextmenu-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "React wrapper for js-contextmenu.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "@octolo/js-contextmenu": "^0.1.0"
19
+ },
20
+ "peerDependencies": {
21
+ "react": ">=18",
22
+ "react-dom": ">=18"
23
+ },
24
+ "devDependencies": {
25
+ "@types/react": "^19.3.0",
26
+ "@types/react-dom": "^19.3.0",
27
+ "react": "^19.0.0",
28
+ "react-dom": "^19.0.0"
29
+ },
30
+ "license": "MIT",
31
+ "sideEffects": false
32
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.