@vaadin/context-menu 24.4.0-dev.b3e1d14600 → 24.5.0-alpha1

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.
Files changed (37) hide show
  1. package/README.md +0 -1
  2. package/package.json +11 -11
  3. package/src/lit/renderer-directives.d.ts +1 -1
  4. package/src/lit/renderer-directives.js +1 -1
  5. package/src/vaadin-context-menu-item.d.ts +1 -1
  6. package/src/vaadin-context-menu-item.js +1 -1
  7. package/src/vaadin-context-menu-list-box.d.ts +1 -1
  8. package/src/vaadin-context-menu-list-box.js +1 -1
  9. package/src/vaadin-context-menu-mixin.d.ts +1 -1
  10. package/src/vaadin-context-menu-mixin.js +6 -3
  11. package/src/vaadin-context-menu-overlay.d.ts +1 -1
  12. package/src/vaadin-context-menu-overlay.js +1 -1
  13. package/src/vaadin-context-menu.d.ts +1 -1
  14. package/src/vaadin-context-menu.js +1 -1
  15. package/src/vaadin-contextmenu-event.js +1 -1
  16. package/src/vaadin-contextmenu-items-mixin.d.ts +1 -1
  17. package/src/vaadin-contextmenu-items-mixin.js +2 -1
  18. package/src/vaadin-lit-context-menu-item.js +1 -1
  19. package/src/vaadin-lit-context-menu-list-box.js +1 -1
  20. package/src/vaadin-lit-context-menu-overlay.js +1 -1
  21. package/src/vaadin-lit-context-menu.js +2 -2
  22. package/src/vaadin-menu-overlay-mixin.d.ts +1 -1
  23. package/src/vaadin-menu-overlay-mixin.js +1 -1
  24. package/src/vaadin-menu-overlay-styles.d.ts +1 -1
  25. package/src/vaadin-menu-overlay-styles.js +1 -1
  26. package/theme/lumo/vaadin-context-menu-item-styles.d.ts +6 -0
  27. package/theme/lumo/vaadin-context-menu-list-box-styles.d.ts +5 -0
  28. package/theme/lumo/vaadin-context-menu-overlay-styles.d.ts +4 -0
  29. package/theme/lumo/vaadin-context-menu.d.ts +4 -0
  30. package/theme/lumo/vaadin-lit-context-menu.d.ts +4 -0
  31. package/theme/material/vaadin-context-menu-item-styles.d.ts +5 -0
  32. package/theme/material/vaadin-context-menu-list-box-styles.d.ts +4 -0
  33. package/theme/material/vaadin-context-menu-overlay-styles.d.ts +2 -0
  34. package/theme/material/vaadin-context-menu.d.ts +4 -0
  35. package/theme/material/vaadin-lit-context-menu.d.ts +4 -0
  36. package/web-types.json +152 -0
  37. package/web-types.lit.json +90 -0
package/README.md CHANGED
@@ -5,7 +5,6 @@ A web component that can be attached to any component to display a context menu.
5
5
  [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/components/context-menu)
6
6
 
7
7
  [![npm version](https://badgen.net/npm/v/@vaadin/context-menu)](https://www.npmjs.com/package/@vaadin/context-menu)
8
- [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
9
8
 
10
9
  ```html
11
10
  <vaadin-context-menu>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/context-menu",
3
- "version": "24.4.0-dev.b3e1d14600",
3
+ "version": "24.5.0-alpha1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -41,15 +41,15 @@
41
41
  "dependencies": {
42
42
  "@open-wc/dedupe-mixin": "^1.3.0",
43
43
  "@polymer/polymer": "^3.0.0",
44
- "@vaadin/a11y-base": "24.4.0-dev.b3e1d14600",
45
- "@vaadin/component-base": "24.4.0-dev.b3e1d14600",
46
- "@vaadin/item": "24.4.0-dev.b3e1d14600",
47
- "@vaadin/list-box": "24.4.0-dev.b3e1d14600",
48
- "@vaadin/lit-renderer": "24.4.0-dev.b3e1d14600",
49
- "@vaadin/overlay": "24.4.0-dev.b3e1d14600",
50
- "@vaadin/vaadin-lumo-styles": "24.4.0-dev.b3e1d14600",
51
- "@vaadin/vaadin-material-styles": "24.4.0-dev.b3e1d14600",
52
- "@vaadin/vaadin-themable-mixin": "24.4.0-dev.b3e1d14600",
44
+ "@vaadin/a11y-base": "24.5.0-alpha1",
45
+ "@vaadin/component-base": "24.5.0-alpha1",
46
+ "@vaadin/item": "24.5.0-alpha1",
47
+ "@vaadin/list-box": "24.5.0-alpha1",
48
+ "@vaadin/lit-renderer": "24.5.0-alpha1",
49
+ "@vaadin/overlay": "24.5.0-alpha1",
50
+ "@vaadin/vaadin-lumo-styles": "24.5.0-alpha1",
51
+ "@vaadin/vaadin-material-styles": "24.5.0-alpha1",
52
+ "@vaadin/vaadin-themable-mixin": "24.5.0-alpha1",
53
53
  "lit": "^3.0.0"
54
54
  },
55
55
  "devDependencies": {
@@ -61,5 +61,5 @@
61
61
  "web-types.json",
62
62
  "web-types.lit.json"
63
63
  ],
64
- "gitHead": "502d4f5b03f770a83d270d98078cde230254dd0e"
64
+ "gitHead": "57806caac5468532a3b4e3dbdda730cd0fca193a"
65
65
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { DirectiveResult } from 'lit/directive.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { directive } from 'lit/directive.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ListMixin } from '@vaadin/a11y-base/src/list-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
@@ -209,8 +209,11 @@ export const ContextMenuMixin = (superClass) =>
209
209
  * @private
210
210
  */
211
211
  _onOverlayOpened(e) {
212
- this._setOpened(e.detail.value);
213
- this.__alignOverlayPosition();
212
+ const opened = e.detail.value;
213
+ this._setOpened(opened);
214
+ if (opened) {
215
+ this.__alignOverlayPosition();
216
+ }
214
217
  }
215
218
 
216
219
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-contextmenu-event.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-context-menu-item.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
@@ -178,6 +178,7 @@ export const ItemsMixin = (superClass) =>
178
178
  // Support menu-bar / context-menu item
179
179
  if (component._hasVaadinItemMixin) {
180
180
  component.setAttribute('role', 'menuitem');
181
+ component.tabIndex = -1;
181
182
  }
182
183
 
183
184
  if (component.localName === 'hr') {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css, html, LitElement } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css, html, LitElement } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, LitElement } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-contextmenu-event.js';
@@ -21,7 +21,7 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
21
21
  *
22
22
  * ## Disclaimer
23
23
  *
24
- * This component is an experiment not intended for publishing to npm.
24
+ * This component is an experiment and not yet a part of Vaadin platform.
25
25
  * There is no ETA regarding specific Vaadin version where it'll land.
26
26
  * Feel free to try this code in your apps as per Apache 2.0 license.
27
27
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { getClosestElement } from '@vaadin/component-base/src/dom-utils.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -0,0 +1,6 @@
1
+ import '@vaadin/vaadin-lumo-styles/color.js';
2
+ import '@vaadin/vaadin-lumo-styles/font-icons.js';
3
+ import '@vaadin/vaadin-lumo-styles/sizing.js';
4
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
5
+ declare const contextMenuItem: import("lit").CSSResult;
6
+ export { contextMenuItem };
@@ -0,0 +1,5 @@
1
+ import '@vaadin/vaadin-lumo-styles/color.js';
2
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
3
+ import '@vaadin/vaadin-lumo-styles/style.js';
4
+ declare const contextMenuListBox: import("lit").CSSResult;
5
+ export { contextMenuListBox };
@@ -0,0 +1,4 @@
1
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
2
+ import '@vaadin/vaadin-lumo-styles/style.js';
3
+ declare const contextMenuOverlay: import("lit").CSSResult;
4
+ export { contextMenuOverlay };
@@ -0,0 +1,4 @@
1
+ import './vaadin-context-menu-item-styles.js';
2
+ import './vaadin-context-menu-list-box-styles.js';
3
+ import './vaadin-context-menu-overlay-styles.js';
4
+ import '../../src/vaadin-context-menu.js';
@@ -0,0 +1,4 @@
1
+ import './vaadin-context-menu-item-styles.js';
2
+ import './vaadin-context-menu-list-box-styles.js';
3
+ import './vaadin-context-menu-overlay-styles.js';
4
+ import '../../src/vaadin-lit-context-menu.js';
@@ -0,0 +1,5 @@
1
+ import '@vaadin/vaadin-material-styles/font-icons.js';
2
+ import '@vaadin/vaadin-material-styles/color.js';
3
+ import '@vaadin/vaadin-material-styles/typography.js';
4
+ declare const contextMenuItem: import("lit").CSSResult;
5
+ export { contextMenuItem };
@@ -0,0 +1,4 @@
1
+ import '@vaadin/vaadin-material-styles/color.js';
2
+ import '@vaadin/vaadin-material-styles/typography.js';
3
+ declare const contextMenuListBox: import("lit").CSSResult;
4
+ export { contextMenuListBox };
@@ -0,0 +1,2 @@
1
+ declare const contextMenuOverlay: import("lit").CSSResult;
2
+ export { contextMenuOverlay };
@@ -0,0 +1,4 @@
1
+ import './vaadin-context-menu-item-styles.js';
2
+ import './vaadin-context-menu-list-box-styles.js';
3
+ import './vaadin-context-menu-overlay-styles.js';
4
+ import '../../src/vaadin-context-menu.js';
@@ -0,0 +1,4 @@
1
+ import './vaadin-context-menu-item-styles.js';
2
+ import './vaadin-context-menu-list-box-styles.js';
3
+ import './vaadin-context-menu-overlay-styles.js';
4
+ import '../../src/vaadin-lit-context-menu.js';
package/web-types.json ADDED
@@ -0,0 +1,152 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/context-menu",
4
+ "version": "24.5.0-alpha1",
5
+ "description-markup": "markdown",
6
+ "contributions": {
7
+ "html": {
8
+ "elements": [
9
+ {
10
+ "name": "vaadin-context-menu",
11
+ "description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha1/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API, in addition `<vaadin-context-menu-overlay>`, the following\ninternal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha1/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha1/#/elements/vaadin-list-box).\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
12
+ "attributes": [
13
+ {
14
+ "name": "selector",
15
+ "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
16
+ "value": {
17
+ "type": [
18
+ "string",
19
+ "null",
20
+ "undefined"
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "name": "open-on",
26
+ "description": "Event name to listen for opening the context menu.",
27
+ "value": {
28
+ "type": [
29
+ "string"
30
+ ]
31
+ }
32
+ },
33
+ {
34
+ "name": "close-on",
35
+ "description": "Event name to listen for closing the context menu.",
36
+ "value": {
37
+ "type": [
38
+ "string"
39
+ ]
40
+ }
41
+ },
42
+ {
43
+ "name": "overlay-class",
44
+ "description": "A space-delimited list of CSS class names to set on the overlay element.\nThis property does not affect other CSS class names set manually via JS.\n\nNote, if the CSS class name was set with this property, clearing it will\nremove it from the overlay, even if the same class name was also added\nmanually, e.g. by using `classList.add()` in the `renderer` function.",
45
+ "value": {
46
+ "type": [
47
+ "string",
48
+ "null",
49
+ "undefined"
50
+ ]
51
+ }
52
+ },
53
+ {
54
+ "name": "theme",
55
+ "description": "The theme variants to apply to the component.",
56
+ "value": {
57
+ "type": [
58
+ "string",
59
+ "null",
60
+ "undefined"
61
+ ]
62
+ }
63
+ }
64
+ ],
65
+ "js": {
66
+ "properties": [
67
+ {
68
+ "name": "items",
69
+ "description": "Defines a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nThe items API can't be used together with a renderer!\n\n#### Example\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n```",
70
+ "value": {
71
+ "type": [
72
+ "Array.<ContextMenuItem>",
73
+ "undefined"
74
+ ]
75
+ }
76
+ },
77
+ {
78
+ "name": "selector",
79
+ "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
80
+ "value": {
81
+ "type": [
82
+ "string",
83
+ "null",
84
+ "undefined"
85
+ ]
86
+ }
87
+ },
88
+ {
89
+ "name": "openOn",
90
+ "description": "Event name to listen for opening the context menu.",
91
+ "value": {
92
+ "type": [
93
+ "string"
94
+ ]
95
+ }
96
+ },
97
+ {
98
+ "name": "listenOn",
99
+ "description": "The target element that's listened to for context menu opening events.\nBy default the vaadin-context-menu listens to the target's `vaadin-contextmenu`\nevents.",
100
+ "value": {
101
+ "type": [
102
+ "HTMLElement"
103
+ ]
104
+ }
105
+ },
106
+ {
107
+ "name": "closeOn",
108
+ "description": "Event name to listen for closing the context menu.",
109
+ "value": {
110
+ "type": [
111
+ "string"
112
+ ]
113
+ }
114
+ },
115
+ {
116
+ "name": "renderer",
117
+ "description": "Custom function for rendering the content of the menu overlay.\nReceives three arguments:\n\n- `root` The root container DOM element. Append your content to it.\n- `contextMenu` The reference to the `<vaadin-context-menu>` element.\n- `context` The object with the menu context, contains:\n - `context.target` the target of the menu opening event,\n - `context.detail` the menu opening event detail.",
118
+ "value": {
119
+ "type": [
120
+ "ContextMenuRenderer",
121
+ "undefined"
122
+ ]
123
+ }
124
+ },
125
+ {
126
+ "name": "overlayClass",
127
+ "description": "A space-delimited list of CSS class names to set on the overlay element.\nThis property does not affect other CSS class names set manually via JS.\n\nNote, if the CSS class name was set with this property, clearing it will\nremove it from the overlay, even if the same class name was also added\nmanually, e.g. by using `classList.add()` in the `renderer` function.",
128
+ "value": {
129
+ "type": [
130
+ "string",
131
+ "null",
132
+ "undefined"
133
+ ]
134
+ }
135
+ }
136
+ ],
137
+ "events": [
138
+ {
139
+ "name": "item-selected",
140
+ "description": "Fired when an item is selected when the context menu is populated using the `items` API."
141
+ },
142
+ {
143
+ "name": "opened-changed",
144
+ "description": "Fired when the `opened` property changes."
145
+ }
146
+ ]
147
+ }
148
+ }
149
+ ]
150
+ }
151
+ }
152
+ }
@@ -0,0 +1,90 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/context-menu",
4
+ "version": "24.5.0-alpha1",
5
+ "description-markup": "markdown",
6
+ "framework": "lit",
7
+ "framework-config": {
8
+ "enable-when": {
9
+ "node-packages": [
10
+ "lit"
11
+ ]
12
+ }
13
+ },
14
+ "contributions": {
15
+ "html": {
16
+ "elements": [
17
+ {
18
+ "name": "vaadin-context-menu",
19
+ "description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha1/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API, in addition `<vaadin-context-menu-overlay>`, the following\ninternal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha1/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha1/#/elements/vaadin-list-box).\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
20
+ "extension": true,
21
+ "attributes": [
22
+ {
23
+ "name": ".items",
24
+ "description": "Defines a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nThe items API can't be used together with a renderer!\n\n#### Example\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n```",
25
+ "value": {
26
+ "kind": "expression"
27
+ }
28
+ },
29
+ {
30
+ "name": ".selector",
31
+ "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
32
+ "value": {
33
+ "kind": "expression"
34
+ }
35
+ },
36
+ {
37
+ "name": ".openOn",
38
+ "description": "Event name to listen for opening the context menu.",
39
+ "value": {
40
+ "kind": "expression"
41
+ }
42
+ },
43
+ {
44
+ "name": ".listenOn",
45
+ "description": "The target element that's listened to for context menu opening events.\nBy default the vaadin-context-menu listens to the target's `vaadin-contextmenu`\nevents.",
46
+ "value": {
47
+ "kind": "expression"
48
+ }
49
+ },
50
+ {
51
+ "name": ".closeOn",
52
+ "description": "Event name to listen for closing the context menu.",
53
+ "value": {
54
+ "kind": "expression"
55
+ }
56
+ },
57
+ {
58
+ "name": ".renderer",
59
+ "description": "Custom function for rendering the content of the menu overlay.\nReceives three arguments:\n\n- `root` The root container DOM element. Append your content to it.\n- `contextMenu` The reference to the `<vaadin-context-menu>` element.\n- `context` The object with the menu context, contains:\n - `context.target` the target of the menu opening event,\n - `context.detail` the menu opening event detail.",
60
+ "value": {
61
+ "kind": "expression"
62
+ }
63
+ },
64
+ {
65
+ "name": ".overlayClass",
66
+ "description": "A space-delimited list of CSS class names to set on the overlay element.\nThis property does not affect other CSS class names set manually via JS.\n\nNote, if the CSS class name was set with this property, clearing it will\nremove it from the overlay, even if the same class name was also added\nmanually, e.g. by using `classList.add()` in the `renderer` function.",
67
+ "value": {
68
+ "kind": "expression"
69
+ }
70
+ },
71
+ {
72
+ "name": "@item-selected",
73
+ "description": "Fired when an item is selected when the context menu is populated using the `items` API.",
74
+ "value": {
75
+ "kind": "expression"
76
+ }
77
+ },
78
+ {
79
+ "name": "@opened-changed",
80
+ "description": "Fired when the `opened` property changes.",
81
+ "value": {
82
+ "kind": "expression"
83
+ }
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ }
89
+ }
90
+ }