@octolo/js-contextmenu-vue 0.0.0-stage → 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/README.md +12 -2
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +7 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @octolo/js-contextmenu-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vue integration for `@octolo/js-contextmenu`, providing the `useContextMenu`
|
|
4
|
+
composable, a `ContextMenuTrigger` component and the legacy `contextMenuMixin`.
|
|
5
|
+
|
|
6
|
+
The mixin's `CtxMenuOpen(event, payload)` opens directly from the supplied event
|
|
7
|
+
and uses `payload.menu` and `payload.menu_data`. The legacy
|
|
8
|
+
`listeners_open` and `listeners_close` payload fields remain accepted for
|
|
9
|
+
source compatibility but are ignored. Use `ContextMenuTrigger` with
|
|
10
|
+
`openEvents`, or bind events with the core `menu.attach()` API, to configure
|
|
11
|
+
event-based opening.
|
|
12
|
+
|
|
13
|
+
For new Vue code, prefer `ContextMenuTrigger` or `useContextMenu`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
/** @deprecated Accepted for source compatibility; this mixin ignores it. */
|
|
26
|
+
listeners_open?: string[];
|
|
27
|
+
/** @deprecated Accepted for source compatibility; this mixin ignores it. */
|
|
28
|
+
listeners_close?: string[];
|
|
29
|
+
}): void;
|
|
30
|
+
ContextualMenuClose(this: MixinHost): void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare const ContextMenuTrigger: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
34
|
+
items: {
|
|
35
|
+
type: PropType<MenuItem[]>;
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
data: {
|
|
39
|
+
type: PropType<unknown>;
|
|
40
|
+
required: false;
|
|
41
|
+
};
|
|
42
|
+
tag: {
|
|
43
|
+
type: StringConstructor;
|
|
44
|
+
default: string;
|
|
45
|
+
};
|
|
46
|
+
openEvents: {
|
|
47
|
+
type: PropType<string[]>;
|
|
48
|
+
default: () => string[];
|
|
49
|
+
};
|
|
50
|
+
options: {
|
|
51
|
+
type: PropType<ContextMenuOptions>;
|
|
52
|
+
required: false;
|
|
53
|
+
};
|
|
54
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
57
|
+
items: {
|
|
58
|
+
type: PropType<MenuItem[]>;
|
|
59
|
+
required: true;
|
|
60
|
+
};
|
|
61
|
+
data: {
|
|
62
|
+
type: PropType<unknown>;
|
|
63
|
+
required: false;
|
|
64
|
+
};
|
|
65
|
+
tag: {
|
|
66
|
+
type: StringConstructor;
|
|
67
|
+
default: string;
|
|
68
|
+
};
|
|
69
|
+
openEvents: {
|
|
70
|
+
type: PropType<string[]>;
|
|
71
|
+
default: () => string[];
|
|
72
|
+
};
|
|
73
|
+
options: {
|
|
74
|
+
type: PropType<ContextMenuOptions>;
|
|
75
|
+
required: false;
|
|
76
|
+
};
|
|
77
|
+
}>> & Readonly<{}>, {
|
|
78
|
+
tag: string;
|
|
79
|
+
openEvents: string[];
|
|
80
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
81
|
+
//# 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,4EAA4E;YAC5E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;YAC1B,4EAA4E;YAC5E,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 /** @deprecated Accepted for source compatibility; this mixin ignores it. */\n listeners_open?: string[];\n /** @deprecated Accepted for source compatibility; this mixin ignores it. */\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: (el: unknown) => {\n host.value = el instanceof HTMLElement ? el : null;\n }\n },\n slots.default?.()\n );\n }\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB,GAAG,iBAAiB,WAAW,YAAY,aAAa;AAElF,SAAS,yBAAyB;AAK3B,SAAS,eAAe,SAA8B;AAC3D,QAAM,OAAO,WAA+B,IAAI;AAEhD,WAAS,SAAsB;AAC7B,QAA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;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,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octolo/js-contextmenu-vue",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Vue wrapper for js-contextmenu.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/octolo/js-contextmenu.git",
|
|
8
|
+
"directory": "packages/vue"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@octolo/js-contextmenu": "^0.4.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"vue": ">=3.4"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"vue": "^3.5.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"sideEffects": false
|
|
33
|
+
}
|