@octolo/js-contextmenu-vue 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,79 @@
1
+ import type { PropType } from "vue";
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): {
5
+ menu: import("vue").ShallowRef<ContextMenu | null, ContextMenu | null>;
6
+ open: (event: MouseEvent, items: MenuItem[], data?: unknown) => void;
7
+ close: () => void;
8
+ destroy: () => void;
9
+ ensure: () => ContextMenu;
10
+ };
11
+ type MixinHost = {
12
+ _jscm: ContextMenu | null;
13
+ };
14
+ /**
15
+ * Vue mixin compatible with the historical Octolo `CtxMenuOpen` API.
16
+ * Prefer `useContextMenu` in new code.
17
+ */
18
+ export declare const contextMenuMixin: {
19
+ data(): MixinHost;
20
+ beforeUnmount(this: MixinHost): void;
21
+ methods: {
22
+ CtxMenuOpen(this: MixinHost, event: MouseEvent, payload: {
23
+ menu: MenuItem[];
24
+ menu_data?: unknown;
25
+ listeners_open?: string[];
26
+ listeners_close?: string[];
27
+ }): void;
28
+ ContextualMenuClose(this: MixinHost): void;
29
+ };
30
+ };
31
+ export declare const ContextMenuTrigger: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
32
+ items: {
33
+ type: PropType<MenuItem[]>;
34
+ required: true;
35
+ };
36
+ data: {
37
+ type: PropType<unknown>;
38
+ required: false;
39
+ };
40
+ tag: {
41
+ type: StringConstructor;
42
+ default: string;
43
+ };
44
+ openEvents: {
45
+ type: PropType<string[]>;
46
+ default: () => string[];
47
+ };
48
+ options: {
49
+ type: PropType<ContextMenuOptions>;
50
+ required: false;
51
+ };
52
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
53
+ [key: string]: any;
54
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
55
+ items: {
56
+ type: PropType<MenuItem[]>;
57
+ required: true;
58
+ };
59
+ data: {
60
+ type: PropType<unknown>;
61
+ required: false;
62
+ };
63
+ tag: {
64
+ type: StringConstructor;
65
+ default: string;
66
+ };
67
+ openEvents: {
68
+ type: PropType<string[]>;
69
+ default: () => string[];
70
+ };
71
+ options: {
72
+ type: PropType<ContextMenuOptions>;
73
+ required: false;
74
+ };
75
+ }>> & Readonly<{}>, {
76
+ tag: string;
77
+ openEvents: string[];
78
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
79
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC,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;;kBAQpC,UAAU,SAAS,QAAQ,EAAE,SAAS,OAAO,KAAG,IAAI;iBAIvD,IAAI;mBAIF,IAAI;kBAbL,WAAW;EAqB/B;AAED,KAAK,SAAS,GAAG;IACf,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB;YACnB,SAAS;wBAKG,SAAS;;0BAMnB,SAAS,SACR,UAAU,WACR;YACP,IAAI,EAAE,QAAQ,EAAE,CAAC;YACjB,SAAS,CAAC,EAAE,OAAO,CAAC;YACpB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;YAC1B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;SAC5B,GACA,IAAI;kCAImB,SAAS,GAAG,IAAI;;CAI7C,CAAC;AAEF,eAAO,MAAM,kBAAkB;;cAGH,QAAQ,CAAC,QAAQ,EAAE,CAAC;;;;cACX,QAAQ,CAAC,OAAO,CAAC;;;;;;;;cAGjC,QAAQ,CAAC,MAAM,EAAE,CAAC;;;;cAGR,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;cAP/B,QAAQ,CAAC,QAAQ,EAAE,CAAC;;;;cACX,QAAQ,CAAC,OAAO,CAAC;;;;;;;;cAGjC,QAAQ,CAAC,MAAM,EAAE,CAAC;;;;cAGR,QAAQ,CAAC,kBAAkB,CAAC;;;;;;4EA2CzD,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ // src/index.ts
2
+ import { defineComponent, h, onBeforeUnmount, onMounted, shallowRef, watch } from "vue";
3
+ import { createContextMenu } from "@octolo/js-contextmenu";
4
+ function useContextMenu(options) {
5
+ const menu = shallowRef(null);
6
+ function ensure() {
7
+ if (!menu.value) menu.value = createContextMenu(options);
8
+ return menu.value;
9
+ }
10
+ function open(event, items, data) {
11
+ ensure().open(event, items, data);
12
+ }
13
+ function close() {
14
+ menu.value?.close();
15
+ }
16
+ function destroy() {
17
+ menu.value?.destroy();
18
+ menu.value = null;
19
+ }
20
+ onBeforeUnmount(destroy);
21
+ return { menu, open, close, destroy, ensure };
22
+ }
23
+ var contextMenuMixin = {
24
+ data() {
25
+ return {
26
+ _jscm: null
27
+ };
28
+ },
29
+ beforeUnmount() {
30
+ this._jscm?.destroy();
31
+ this._jscm = null;
32
+ },
33
+ methods: {
34
+ CtxMenuOpen(event, payload) {
35
+ if (!this._jscm) this._jscm = createContextMenu();
36
+ this._jscm.open(event, payload.menu, payload.menu_data);
37
+ },
38
+ ContextualMenuClose() {
39
+ this._jscm?.close();
40
+ }
41
+ }
42
+ };
43
+ var ContextMenuTrigger = defineComponent({
44
+ name: "ContextMenuTrigger",
45
+ props: {
46
+ items: { type: Array, required: true },
47
+ data: { type: null, required: false },
48
+ tag: { type: String, default: "div" },
49
+ openEvents: {
50
+ type: Array,
51
+ default: () => ["contextmenu"]
52
+ },
53
+ options: { type: Object, required: false }
54
+ },
55
+ setup(props, { slots, attrs }) {
56
+ const host = shallowRef(null);
57
+ let menu = null;
58
+ let unbind = null;
59
+ function release() {
60
+ unbind?.();
61
+ unbind = null;
62
+ menu?.destroy();
63
+ menu = null;
64
+ }
65
+ function bind() {
66
+ if (!host.value) return;
67
+ release();
68
+ menu = createContextMenu(props.options);
69
+ unbind = menu.attach(
70
+ host.value,
71
+ () => ({ items: props.items, data: props.data }),
72
+ { openEvents: props.openEvents }
73
+ );
74
+ }
75
+ onMounted(bind);
76
+ watch(() => [props.items, props.data, props.openEvents, props.options], bind, {
77
+ deep: true
78
+ });
79
+ onBeforeUnmount(release);
80
+ return () => h(
81
+ props.tag,
82
+ {
83
+ ...attrs,
84
+ ref: (el) => {
85
+ host.value = el instanceof HTMLElement ? el : null;
86
+ }
87
+ },
88
+ slots.default?.()
89
+ );
90
+ }
91
+ });
92
+ export {
93
+ ContextMenuTrigger,
94
+ contextMenuMixin,
95
+ useContextMenu
96
+ };
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import { defineComponent, h, onBeforeUnmount, onMounted, shallowRef, watch } from \"vue\";\nimport type { PropType } from \"vue\";\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) {\n const menu = shallowRef<ContextMenu | null>(null);\n\n function ensure(): ContextMenu {\n if (!menu.value) menu.value = createContextMenu(options);\n return menu.value;\n }\n\n function open(event: MouseEvent, items: MenuItem[], data?: unknown): void {\n ensure().open(event, items, data);\n }\n\n function close(): void {\n menu.value?.close();\n }\n\n function destroy(): void {\n menu.value?.destroy();\n menu.value = null;\n }\n\n onBeforeUnmount(destroy);\n\n return { menu, open, close, destroy, ensure };\n}\n\ntype MixinHost = {\n _jscm: ContextMenu | null;\n};\n\n/**\n * Vue mixin compatible with the historical Octolo `CtxMenuOpen` API.\n * Prefer `useContextMenu` in new code.\n */\nexport const contextMenuMixin = {\n data(): MixinHost {\n return {\n _jscm: null\n };\n },\n beforeUnmount(this: MixinHost) {\n this._jscm?.destroy();\n this._jscm = null;\n },\n methods: {\n CtxMenuOpen(\n this: MixinHost,\n event: MouseEvent,\n payload: {\n menu: MenuItem[];\n menu_data?: unknown;\n listeners_open?: string[];\n listeners_close?: string[];\n }\n ): void {\n if (!this._jscm) this._jscm = createContextMenu();\n this._jscm.open(event, payload.menu, payload.menu_data);\n },\n ContextualMenuClose(this: MixinHost): void {\n this._jscm?.close();\n }\n }\n};\n\nexport const ContextMenuTrigger = defineComponent({\n name: \"ContextMenuTrigger\",\n props: {\n items: { type: Array as PropType<MenuItem[]>, required: true },\n data: { type: null as unknown as PropType<unknown>, required: false },\n tag: { type: String, default: \"div\" },\n openEvents: {\n type: Array as PropType<string[]>,\n default: () => [\"contextmenu\"]\n },\n options: { type: Object as PropType<ContextMenuOptions>, required: false }\n },\n setup(props, { slots, attrs }) {\n const host = shallowRef<HTMLElement | null>(null);\n let menu: ContextMenu | null = null;\n let unbind: (() => void) | null = null;\n\n function release(): void {\n unbind?.();\n unbind = null;\n menu?.destroy();\n menu = null;\n }\n\n function bind(): void {\n if (!host.value) return;\n release();\n menu = createContextMenu(props.options);\n unbind = menu.attach(\n host.value,\n () => ({ items: props.items, data: props.data }),\n { openEvents: props.openEvents }\n );\n }\n\n onMounted(bind);\n watch(() => [props.items, props.data, props.openEvents, props.options], bind, {\n deep: true\n });\n onBeforeUnmount(release);\n\n return () =>\n h(\n props.tag,\n {\n ...attrs,\n ref: (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,MAAM;AAAA,IACpC,YAAY;AAAA,MACV,MAAM;AAAA,MACN,SAAS,MAAM,CAAC,aAAa;AAAA,IAC/B;AAAA,IACA,SAAS,EAAE,MAAM,QAAwC,UAAU,MAAM;AAAA,EAC3E;AAAA,EACA,MAAM,OAAO,EAAE,OAAO,MAAM,GAAG;AAC7B,UAAM,OAAO,WAA+B,IAAI;AAChD,QAAI,OAA2B;AAC/B,QAAI,SAA8B;AAElC,aAAS,UAAgB;AACvB,eAAS;AACT,eAAS;AACT,YAAM,QAAQ;AACd,aAAO;AAAA,IACT;AAEA,aAAS,OAAa;AACpB,UAAI,CAAC,KAAK,MAAO;AACjB,cAAQ;AACR,aAAO,kBAAkB,MAAM,OAAO;AACtC,eAAS,KAAK;AAAA,QACZ,KAAK;AAAA,QACL,OAAO,EAAE,OAAO,MAAM,OAAO,MAAM,MAAM,KAAK;AAAA,QAC9C,EAAE,YAAY,MAAM,WAAW;AAAA,MACjC;AAAA,IACF;AAEA,cAAU,IAAI;AACd,UAAM,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,MAAM,YAAY,MAAM,OAAO,GAAG,MAAM;AAAA,MAC5E,MAAM;AAAA,IACR,CAAC;AACD,oBAAgB,OAAO;AAEvB,WAAO,MACL;AAAA,MACE,MAAM;AAAA,MACN;AAAA,QACE,GAAG;AAAA,QACH,KAAK,CAAC,OAAgB;AACpB,eAAK,QAAQ,cAAc,cAAc,KAAK;AAAA,QAChD;AAAA,MACF;AAAA,MACA,MAAM,UAAU;AAAA,IAClB;AAAA,EACJ;AACF,CAAC;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@octolo/js-contextmenu-vue",
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": "Vue 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
+ "vue": ">=3.4"
22
+ },
23
+ "devDependencies": {
24
+ "vue": "^3.5.0"
25
+ },
26
+ "license": "MIT",
27
+ "sideEffects": false
28
+ }
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.