@imengyu/vue3-context-menu 1.1.2 → 1.1.4
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.CN.md +51 -3
- package/README.md +53 -3
- package/examples/index.html +3 -2
- package/examples/views/BasicComponent.vue +1 -1
- package/examples/views/BasicCustomize.vue +1 -1
- package/examples/views/BasicUseage.vue +16 -2
- package/index.d.ts +22 -2
- package/lib/vue3-context-menu.common.js +81 -38
- package/lib/vue3-context-menu.common.js.map +1 -1
- package/lib/vue3-context-menu.css +1 -1
- package/lib/vue3-context-menu.umd.js +81 -38
- package/lib/vue3-context-menu.umd.js.map +1 -1
- package/lib/vue3-context-menu.umd.min.js +1 -1
- package/lib/vue3-context-menu.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/ContextMenu.vue +1 -0
- package/src/ContextMenuDefine.ts +4 -1
- package/src/ContextMenuGroup.vue +1 -0
- package/src/ContextMenuItem.vue +43 -13
- package/src/ContextSubMenu.vue +17 -3
- package/CHANGELOG.md +0 -28
package/README.CN.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
### ❗ 重大升级
|
|
19
19
|
|
|
20
|
-
版本 1.1.0
|
|
20
|
+
版本 1.1.0 做了很大升级,如果您从之前的版本升级过来,可能会存在与之前版本不兼容的情况,你需要参考文档修改菜单的数据格式。如果出现问题,请安装 1.0.9 版本。
|
|
21
21
|
|
|
22
22
|
## 安装
|
|
23
23
|
|
|
@@ -121,9 +121,46 @@ methods: {
|
|
|
121
121
|
|
|
122
122
|
## 菜单图标
|
|
123
123
|
|
|
124
|
-
菜单组件不提供任何图标,如果您想添加图标,推荐使用 [iconfont](http://iconfont.cn)
|
|
124
|
+
菜单组件不提供任何图标,如果您想添加图标,推荐使用 [iconfont](http://iconfont.cn) 图标库。
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
### 字体图标
|
|
127
|
+
|
|
128
|
+
使用 iconfont 图标库,导入字体后填写 `MenuItem` 的 `icon` 属性,即可在菜单项前面显示图标。
|
|
129
|
+
|
|
130
|
+
* 如果字体名称不一样,可用 `MenuItem` 或者 `MenuOptions` 的 `iconFontClass` 属性指定其他字体。
|
|
131
|
+
* 默认使用 `<i>` 元素来显示图标。
|
|
132
|
+
|
|
133
|
+
### SVG 图标
|
|
134
|
+
|
|
135
|
+
支持使用 svg symbol 来显示图标:
|
|
136
|
+
|
|
137
|
+
```html
|
|
138
|
+
<svg viewBox="0 0 80 20" xmlns="http://www.w3.org/2000/svg">
|
|
139
|
+
<!-- Your icon -->
|
|
140
|
+
<symbol id="icon-multiply" viewBox="0 0 1024 1024">
|
|
141
|
+
<path d="M512 64C264.608 64 64 264.608 64 512c0 247.36 200.608 448 448 448 247.36 0 448-200.64 448-448 0-247.392-200.64-448-448-448z m158.4 651.552L512 557.312l-158.4 158.24-45.312-45.248L466.688 512l-158.304-158.4 45.312-45.312L512 466.688l158.4-158.4 45.28 45.312L557.312 512l158.368 158.4-45.28 45.152z" fill="#F74A21"></path>
|
|
142
|
+
</symbol>
|
|
143
|
+
</svg>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
this.$contextmenu({
|
|
148
|
+
items: [
|
|
149
|
+
{
|
|
150
|
+
label: "Item with svg icon",
|
|
151
|
+
svgIcon: "#icon-multiply",
|
|
152
|
+
svgProps: {
|
|
153
|
+
fill: '#f60',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
//...省略
|
|
158
|
+
} as MenuOptions);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
> 注:使用 iconfont 库导出的图标库,会附带 `iconfont.js` ,你只需要在 html 中引入这个js,他会自动为你导入所有的 svg symbol,你可直接复制图标名称使用。
|
|
162
|
+
|
|
163
|
+
### 自定义渲染
|
|
127
164
|
|
|
128
165
|
你也可以通过菜单的插槽来完全自定义渲染图标,如:
|
|
129
166
|
|
|
@@ -219,6 +256,8 @@ import '你的样式css文件路径.css'
|
|
|
219
256
|
| 属性名 | 描述 | 类型 |
|
|
220
257
|
| :----: | :----: | :----: |
|
|
221
258
|
| theme | 菜单主题 | `'light' 'dark'` |
|
|
259
|
+
| isOpen | 指示当前菜单子菜单是否处于打开状态 | `boolean` |
|
|
260
|
+
| hasChildren | 指示当前菜单是否有子级菜单 | `boolean` |
|
|
222
261
|
| onClick | 自定义元素的点击事件回调,它用于菜单内部事件处理,当自定义渲染时,请回调此函数,否则菜单无法正常响应事件 | - |
|
|
223
262
|
| onMouseEnter | 自定义元素的鼠标移入事件回调,它用于菜单内部事件处理,当自定义渲染时,请回调此函数,否则菜单无法正常响应事件 | - |
|
|
224
263
|
| ... | 其他参数与 `MenuItem` 一致 | - |
|
|
@@ -235,6 +274,9 @@ import '你的样式css文件路径.css'
|
|
|
235
274
|
| :----: | :----: | :----: | :----: |
|
|
236
275
|
| label | 菜单项名称 | `string` | — |
|
|
237
276
|
| icon | 菜单项图标 | `string` | — |
|
|
277
|
+
| iconFontClass | 自定义图标字体类名 | `string` | — | `iconfont` |
|
|
278
|
+
| svgIcon | 菜单项图标 svg,仅在 icon 为空时有效 | `string` | — | — |
|
|
279
|
+
| svgProps | 当使用 svg 图标时,自定义 svg 标签属性 | `SVGAttributes` | — | — |
|
|
238
280
|
| disabled | 是否禁用菜单项 | `boolean` | `false` |
|
|
239
281
|
| clickableWhenHasChildren | 指定当本菜单下有子菜单时,点击当前菜单是否触发点击事件 | `boolean` | `false` |
|
|
240
282
|
| clickClose | 点击当前菜单项是否自动关闭整个菜单 | `boolean` | `true` |
|
|
@@ -268,6 +310,9 @@ import '你的样式css文件路径.css'
|
|
|
268
310
|
| :----: | :----: | :----: | :----: |
|
|
269
311
|
| label | 菜单项名称 | `string` | — |
|
|
270
312
|
| icon | 菜单项图标 | `string` | — |
|
|
313
|
+
| iconFontClass | 自定义图标字体类名 | `string` | — | `iconfont` |
|
|
314
|
+
| svgIcon | 菜单项图标 svg,仅在 icon 为空时有效 | `string` | — | — |
|
|
315
|
+
| svgProps | 当使用 svg 图标时,自定义 svg 标签属性 | `SVGAttributes` | — | — |
|
|
271
316
|
| disabled | 是否禁用菜单项 | `boolean` | `false` |
|
|
272
317
|
| clickableWhenHasChildren | 指定当本菜单下有子菜单时,点击当前菜单是否触发点击事件 | `boolean` | `false` |
|
|
273
318
|
| adjustSubMenuPosition | 是否在子菜单超出屏幕后进行自动调整 | `boolean` | `true` |
|
|
@@ -335,6 +380,9 @@ import '你的样式css文件路径.css'
|
|
|
335
380
|
| :----: | :----: | :----: | :----: | :----: |
|
|
336
381
|
| label | 菜单项名称,可传入VNode | `string` or `VNode` or `((label: string) => VNode)` | — | — |
|
|
337
382
|
| icon | 菜单项图标,可传入VNode | `string` or `VNode` or `((icon: string) => VNode)` | — | — |
|
|
383
|
+
| iconFontClass | 自定义图标字体类名 | `string` | — | `iconfont` |
|
|
384
|
+
| svgIcon | 菜单项图标 svg,仅在 icon 为空时有效 | `string` | — | — |
|
|
385
|
+
| svgProps | 当使用 svg 图标时,自定义 svg 标签属性 | `SVGAttributes` | — | — |
|
|
338
386
|
| disabled | 是否禁用菜单项 | `boolean` | — | `false` |
|
|
339
387
|
| adjustSubMenuPosition | 是否在子菜单超出屏幕后进行自动调整 | `boolean` | — | `true` |
|
|
340
388
|
| clickableWhenHasChildren | 指定当本菜单下有子菜单时,点击当前菜单是否触发点击事件 | `boolean` | — | `false` |
|
package/README.md
CHANGED
|
@@ -122,11 +122,50 @@ methods: {
|
|
|
122
122
|
|
|
123
123
|
## Menu icon
|
|
124
124
|
|
|
125
|
-
The menu component does not provide any icons. If you want to add an icon, it is recommended to use [iconfont](http://iconfont.cn) Icon library.
|
|
125
|
+
The menu component does not provide any icons. If you want to add an icon, it is recommended to use [iconfont](http://iconfont.cn) Icon library.
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
### Font icon
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
Use iconfont library: After importing, fill in the `icon` attribute of `MenuItem` to display the icon in front of the menu item.
|
|
130
|
+
|
|
131
|
+
* If the font names are different, you can specify other fonts by writing the `iconFontClass` attribute of `MenuItem` or `MenuOptions`.
|
|
132
|
+
* By default, the `<i>` element is used to display icons
|
|
133
|
+
|
|
134
|
+
### SVG Icon
|
|
135
|
+
|
|
136
|
+
Support the use of svg `<symbol>` to display icons:
|
|
137
|
+
|
|
138
|
+
```html
|
|
139
|
+
<svg viewBox="0 0 80 20" xmlns="http://www.w3.org/2000/svg">
|
|
140
|
+
<!-- Your icon -->
|
|
141
|
+
<symbol id="icon-multiply" viewBox="0 0 1024 1024">
|
|
142
|
+
<path d="M512 64C264.608 64 64 264.608 64 512c0 247.36 200.608 448 448 448 247.36 0 448-200.64 448-448 0-247.392-200.64-448-448-448z m158.4 651.552L512 557.312l-158.4 158.24-45.312-45.248L466.688 512l-158.304-158.4 45.312-45.312L512 466.688l158.4-158.4 45.28 45.312L557.312 512l158.368 158.4-45.28 45.152z" fill="#F74A21"></path>
|
|
143
|
+
</symbol>
|
|
144
|
+
</svg>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
//Function mode
|
|
149
|
+
this.$contextmenu({
|
|
150
|
+
items: [
|
|
151
|
+
{
|
|
152
|
+
label: "Item with svg icon",
|
|
153
|
+
svgIcon: "#icon-multiply",
|
|
154
|
+
svgProps: {
|
|
155
|
+
fill: '#f60',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
//...
|
|
160
|
+
} as MenuOptions);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
//Component mode
|
|
165
|
+
<context-menu-item label="Item with svg icon" svgIcon="#icon-multiply" :svgProps="{ fill: '#f60' }" />
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Customize icon
|
|
130
169
|
|
|
131
170
|
You can also completely customize the rendering icon through the slot of the menu, such as:
|
|
132
171
|
|
|
@@ -219,6 +258,8 @@ Menu component.
|
|
|
219
258
|
| Property | Description | Type |
|
|
220
259
|
| :----: | :----: | :----: |
|
|
221
260
|
| theme | Menu theme | `'light' 'dark'` |
|
|
261
|
+
| isOpen | This value indicates whether the current menu submenu is open | `boolean` |
|
|
262
|
+
| hasChildren | This value indicates whether the current menu has submenus | `boolean` |
|
|
222
263
|
| onClick | Define the click event callback of the element, which is used for the internal event processing of the menu. When rendering item with slot, please call this function back, otherwise the menu cannot respond to the event normally | - |
|
|
223
264
|
| onMouseEnter | Mouse in event callback of custom element. When rendering item with slot, please call this function back, otherwise the menu cannot respond to the event normally | - |
|
|
224
265
|
| ... | Other arguments are same with `MenuItem` | - |
|
|
@@ -235,6 +276,9 @@ Menu item component.
|
|
|
235
276
|
| :----: | :----: | :----: | :----: |
|
|
236
277
|
| label | The label of menu. | `string` | — |
|
|
237
278
|
| icon | The icon for menu item. | `string` | — |
|
|
279
|
+
| iconFontClass | Custom icon library font class name. | `string` | — | `iconfont` |
|
|
280
|
+
| svgIcon | Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty. | `string` | — | — |
|
|
281
|
+
| svgProps | The user-defined attribute of the svg tag, which is valid when using `svgIcon`. | `SVGAttributes` | — | — |
|
|
238
282
|
| disabled | Disable menu item? | `boolean` | `false` |
|
|
239
283
|
| clickableWhenHasChildren | When there are subitems in this item, is it allowed to trigger its own click event? | `boolean` | `false` |
|
|
240
284
|
| clickClose | Should close menu when Click this menu item ? | `boolean` | `true` |
|
|
@@ -268,6 +312,9 @@ Submenu component.
|
|
|
268
312
|
| :----: | :----: | :----: | :----: |
|
|
269
313
|
| label | The label of menu. | `string` | — |
|
|
270
314
|
| icon | The icon for menu item. | `string` | — |
|
|
315
|
+
| iconFontClass | Custom icon library font class name. | `string` | — | `iconfont` |
|
|
316
|
+
| svgIcon | Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty. | `string` | — | — |
|
|
317
|
+
| svgProps | The user-defined attribute of the svg tag, which is valid when using `svgIcon`. | `SVGAttributes` | — | — |
|
|
271
318
|
| disabled | Disable menu item? | `boolean` | `false` |
|
|
272
319
|
| clickableWhenHasChildren | When there are subitems in this item, is it allowed to trigger its own click event? | `boolean` | `false` |
|
|
273
320
|
| adjustSubMenuPosition | Specifies should submenu adjust it position when the menu exceeds the screen.| `boolean` | `true` |
|
|
@@ -335,6 +382,9 @@ Menu separator component.
|
|
|
335
382
|
| :----: | :----: | :----: | :----: | :----: |
|
|
336
383
|
| label | The label of menu. | `string` or `VNode` or `((label: string) => VNode)` | — | — |
|
|
337
384
|
| icon | The icon for menu item. | `string` or `VNode` or `((icon: string) => VNode)` | — | — |
|
|
385
|
+
| iconFontClass | Custom icon library font class name. | `string` | — | `iconfont` |
|
|
386
|
+
| svgIcon | Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty. | `string` | — | — |
|
|
387
|
+
| svgProps | The user-defined attribute of the svg tag, which is valid when using `svgIcon`. | `SVGAttributes` | — | — |
|
|
338
388
|
| disabled | Disable menu item? | `boolean` | — | `false` |
|
|
339
389
|
| adjustSubMenuPosition | Specifies should submenu adjust it position when the menu exceeds the screen. | `boolean` | — | `true` |
|
|
340
390
|
| clickableWhenHasChildren | When there are subitems in this item, is it allowed to trigger its own click event? | `boolean` | — | `false` |
|
package/examples/index.html
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
7
7
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
|
8
8
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
9
|
-
<
|
|
10
|
-
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
|
|
9
|
+
<script src="https://imengyu.top/static/iconfont-small-test.js"></script>
|
|
11
10
|
</head>
|
|
12
11
|
<body>
|
|
13
12
|
<noscript>
|
|
@@ -16,5 +15,7 @@
|
|
|
16
15
|
<a href="https://github.com/imengyu/vue3-context-menu"><img style="position: absolute; top: 0; left: 0; border: 0; z-index: 100" src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png"></a>
|
|
17
16
|
<div id="app"></div>
|
|
18
17
|
<!-- built files will be auto injected -->
|
|
18
|
+
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
|
|
19
|
+
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css">
|
|
19
20
|
</body>
|
|
20
21
|
</html>
|
|
@@ -91,7 +91,7 @@ export default defineComponent({
|
|
|
91
91
|
hljs: {
|
|
92
92
|
highlightAll: () => void
|
|
93
93
|
}
|
|
94
|
-
}).hljs
|
|
94
|
+
}).hljs?.highlightAll?.();
|
|
95
95
|
},
|
|
96
96
|
methods: {
|
|
97
97
|
test() {
|
|
@@ -140,7 +140,6 @@ export default defineComponent({
|
|
|
140
140
|
alert("You click Print");
|
|
141
141
|
}
|
|
142
142
|
},
|
|
143
|
-
|
|
144
143
|
{ label: "View source", icon: "icon-terminal" },
|
|
145
144
|
{ label: "Inspect" }
|
|
146
145
|
],
|
|
@@ -206,6 +205,21 @@ export default defineComponent({
|
|
|
206
205
|
},
|
|
207
206
|
]
|
|
208
207
|
},
|
|
208
|
+
{
|
|
209
|
+
label: 'Item with icon',
|
|
210
|
+
icon: "icon-reload-1",
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
label: "Item with svg icon",
|
|
214
|
+
svgIcon: "#icon-clock",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
label: "Item with svg icon",
|
|
218
|
+
svgIcon: "#icon-multiply",
|
|
219
|
+
svgProps: {
|
|
220
|
+
fill: '#f60',
|
|
221
|
+
},
|
|
222
|
+
},
|
|
209
223
|
],
|
|
210
224
|
iconFontClass: 'iconfont',
|
|
211
225
|
customClass: "class-a",
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { App, Slot, VNode } from "vue";
|
|
1
|
+
import { App, Slot, SVGAttributes, VNode } from "vue";
|
|
2
2
|
|
|
3
3
|
declare module 'vue3-context-menu' {
|
|
4
4
|
}
|
|
@@ -44,7 +44,7 @@ export declare interface MenuOptions {
|
|
|
44
44
|
*/
|
|
45
45
|
customClass ?: string,
|
|
46
46
|
/**
|
|
47
|
-
* Custom icon library font class name.
|
|
47
|
+
* Custom icon library font class name. (global)
|
|
48
48
|
*/
|
|
49
49
|
iconFontClass ?: string,
|
|
50
50
|
/**
|
|
@@ -73,6 +73,18 @@ export declare interface MenuItem {
|
|
|
73
73
|
* The icon for menu item.
|
|
74
74
|
*/
|
|
75
75
|
icon ?: string|VNode|((icon: string) => VNode),
|
|
76
|
+
/**
|
|
77
|
+
* Custom icon library font class name.
|
|
78
|
+
*/
|
|
79
|
+
iconFontClass ?: string,
|
|
80
|
+
/**
|
|
81
|
+
* Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty.
|
|
82
|
+
*/
|
|
83
|
+
svgIcon ?: string,
|
|
84
|
+
/**
|
|
85
|
+
* The user-defined attribute of the svg tag, which is valid when using `svgIcon`.
|
|
86
|
+
*/
|
|
87
|
+
svgProps ?: SVGAttributes,
|
|
76
88
|
/**
|
|
77
89
|
* Disable menu item?
|
|
78
90
|
*/
|
|
@@ -125,6 +137,14 @@ export declare interface MenuItemRenderData extends Omit<MenuItem, 'children'|'c
|
|
|
125
137
|
* Global theme
|
|
126
138
|
*/
|
|
127
139
|
theme: 'light'|'dark',
|
|
140
|
+
/**
|
|
141
|
+
* This value indicates whether the current menu submenu is open
|
|
142
|
+
*/
|
|
143
|
+
isOpen: boolean,
|
|
144
|
+
/**
|
|
145
|
+
* This value indicates whether the current menu has submenus
|
|
146
|
+
*/
|
|
147
|
+
hasChildren: boolean,
|
|
128
148
|
/**
|
|
129
149
|
* Click event callback of custom element, which is used for menu internal event
|
|
130
150
|
*/
|