@vaadin/vaadin-context-menu 22.0.0-alpha6 → 22.0.0-beta1

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.
@@ -1,4 +1,6 @@
1
- import './vaadin-context-menu-styles.js';
2
- import '@vaadin/vaadin-item/theme/lumo/vaadin-item.js';
3
- import '@vaadin/vaadin-list-box/theme/lumo/vaadin-list-box.js';
4
- import '../../src/vaadin-context-menu.js';
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import '@vaadin/context-menu/theme/lumo/vaadin-context-menu.js';
@@ -1,4 +1,6 @@
1
- import './vaadin-context-menu-styles.js';
2
- import '@vaadin/vaadin-item/theme/material/vaadin-item.js';
3
- import '@vaadin/vaadin-list-box/theme/material/vaadin-list-box.js';
4
- import '../../src/vaadin-context-menu.js';
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import '@vaadin/context-menu/theme/material/vaadin-context-menu.js';
@@ -1,2 +1 @@
1
1
  export * from './src/vaadin-context-menu.js';
2
- export * from './src/interfaces';
@@ -1,43 +0,0 @@
1
- import { ContextMenuElement } from '../src/vaadin-context-menu.js';
2
-
3
- export interface ContextMenuItem {
4
- text?: string;
5
- component?: string | HTMLElement;
6
- disabled?: boolean;
7
- checked?: boolean;
8
- theme?: string | string[];
9
- children?: ContextMenuItem[];
10
- }
11
-
12
- export interface ContextMenuRendererContext {
13
- target: HTMLElement;
14
- detail?: { sourceEvent: Event };
15
- }
16
-
17
- export type ContextMenuRenderer = (
18
- root: HTMLElement,
19
- contextMenu?: ContextMenuElement,
20
- context?: ContextMenuRendererContext
21
- ) => void;
22
-
23
- /**
24
- * Fired when the `opened` property changes.
25
- */
26
- export type ContextMenuOpenedChangedEvent = CustomEvent<{ value: boolean }>;
27
-
28
- /**
29
- * Fired when an item is selected when the context menu is populated using the `items` API.
30
- */
31
- export type ContextMenuItemSelectedEvent = CustomEvent<{ value: ContextMenuItem }>;
32
-
33
- export interface ContextMenuElementEventMap {
34
- 'opened-changed': ContextMenuOpenedChangedEvent;
35
-
36
- 'item-selected': ContextMenuItemSelectedEvent;
37
-
38
- 'close-all-menus': Event;
39
-
40
- 'items-outside-click': Event;
41
- }
42
-
43
- export interface ContextMenuEventMap extends HTMLElementEventMap, ContextMenuElementEventMap {}
@@ -1,113 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
7
- import { OverlayElement } from '@vaadin/vaadin-overlay/src/vaadin-overlay.js';
8
-
9
- registerStyles(
10
- 'vaadin-context-menu-overlay',
11
- css`
12
- :host {
13
- align-items: flex-start;
14
- justify-content: flex-start;
15
- }
16
-
17
- :host([right-aligned]),
18
- :host([end-aligned]) {
19
- align-items: flex-end;
20
- }
21
-
22
- :host([bottom-aligned]) {
23
- justify-content: flex-end;
24
- }
25
-
26
- [part='overlay'] {
27
- background-color: #fff;
28
- }
29
- `,
30
- { moduleId: 'vaadin-context-menu-overlay-styles' }
31
- );
32
-
33
- /**
34
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
35
- *
36
- * @extends OverlayElement
37
- * @protected
38
- */
39
- class ContextMenuOverlayElement extends OverlayElement {
40
- static get is() {
41
- return 'vaadin-context-menu-overlay';
42
- }
43
-
44
- static get properties() {
45
- return {
46
- /**
47
- * @protected
48
- */
49
- parentOverlay: {
50
- type: Object,
51
- readOnly: true
52
- }
53
- };
54
- }
55
-
56
- static get observers() {
57
- return ['_themeChanged(theme)'];
58
- }
59
-
60
- ready() {
61
- super.ready();
62
-
63
- this.addEventListener('keydown', (e) => {
64
- if (!e.defaultPrevented && e.composedPath()[0] === this.$.overlay && [38, 40].indexOf(e.keyCode) > -1) {
65
- const child = this.getFirstChild();
66
- if (child && Array.isArray(child.items) && child.items.length) {
67
- e.preventDefault();
68
- if (e.keyCode === 38) {
69
- child.items[child.items.length - 1].focus();
70
- } else {
71
- child.focus();
72
- }
73
- }
74
- }
75
- });
76
- }
77
-
78
- getFirstChild() {
79
- return this.content.querySelector(':not(style):not(slot)');
80
- }
81
-
82
- _themeChanged() {
83
- this.close();
84
- }
85
-
86
- getBoundaries() {
87
- // Measure actual overlay and content sizes
88
- const overlayRect = this.getBoundingClientRect();
89
- const contentRect = this.$.overlay.getBoundingClientRect();
90
-
91
- // Maximum x and y values are imposed by content size and overlay limits.
92
- let yMax = overlayRect.bottom - contentRect.height;
93
-
94
- // Adjust constraints to ensure bottom-aligned applies to sub-menu.
95
- const parent = this.parentOverlay;
96
- if (parent && parent.hasAttribute('bottom-aligned')) {
97
- const parentStyle = getComputedStyle(parent);
98
- yMax = yMax - parseFloat(parentStyle.bottom) - parseFloat(parentStyle.height);
99
- }
100
-
101
- return {
102
- xMax: overlayRect.right - contentRect.width,
103
- xMin: overlayRect.left + contentRect.width,
104
- yMax,
105
- left: overlayRect.left,
106
- right: overlayRect.right,
107
- top: overlayRect.top,
108
- width: contentRect.width
109
- };
110
- }
111
- }
112
-
113
- customElements.define(ContextMenuOverlayElement.is, ContextMenuOverlayElement);
@@ -1,103 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { register, prevent } from '@polymer/polymer/lib/utils/gestures.js';
7
-
8
- register({
9
- name: 'vaadin-contextmenu',
10
- deps: ['touchstart', 'touchmove', 'touchend', 'contextmenu'],
11
- flow: {
12
- start: ['touchstart', 'contextmenu'],
13
- end: ['contextmenu']
14
- },
15
-
16
- emits: ['vaadin-contextmenu'],
17
-
18
- info: {
19
- sourceEvent: null,
20
- _ios:
21
- (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) ||
22
- (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
23
- },
24
-
25
- reset: function () {
26
- this.info.sourceEvent = null;
27
- this._cancelTimer();
28
- this.info.touchJob = null;
29
- this.info.touchStartCoords = null;
30
- },
31
-
32
- _cancelTimer: function () {
33
- if (this._timerId) {
34
- clearTimeout(this._timerId);
35
- delete this._fired;
36
- }
37
- },
38
-
39
- touchstart: function (e) {
40
- this.info.sourceEvent = e;
41
- this.info.touchStartCoords = {
42
- x: e.changedTouches[0].clientX,
43
- y: e.changedTouches[0].clientY
44
- };
45
-
46
- // After timeout event is already retargeted to the parent element in case there is one.
47
- // So we are assigning the target synchronously on event dispatched.
48
- const t = e.composedPath()[0] || e.target;
49
-
50
- this._timerId = setTimeout(() => {
51
- const ct = e.changedTouches[0];
52
- if (!e.shiftKey) {
53
- if (this.info._ios) {
54
- this._fired = true;
55
- this.fire(t, ct.clientX, ct.clientY);
56
- }
57
-
58
- // needed to prevent any 'tap' gesture events from firing
59
- // which could potentially cancel/close the overlay.
60
- prevent('tap');
61
- }
62
- }, 500); // default setting for Android and iOS.
63
- },
64
-
65
- touchmove: function (e) {
66
- const moveThreshold = 15;
67
- const touchStartCoords = this.info.touchStartCoords;
68
- if (
69
- Math.abs(touchStartCoords.x - e.changedTouches[0].clientX) > moveThreshold ||
70
- Math.abs(touchStartCoords.y - e.changedTouches[0].clientY) > moveThreshold
71
- ) {
72
- this._cancelTimer();
73
- }
74
- },
75
-
76
- touchend: function (e) {
77
- if (this._fired) {
78
- e.preventDefault();
79
- }
80
- this._cancelTimer();
81
- },
82
-
83
- contextmenu: function (e) {
84
- if (!e.shiftKey) {
85
- this.info.sourceEvent = e;
86
- this.fire(e.target, e.clientX, e.clientY);
87
- prevent('tap');
88
- }
89
- },
90
-
91
- fire: function (target, x, y) {
92
- // NOTE(web-padawan): the code below is copied from `Polymer.Gestures._fire`,
93
- // which is not exported from `gestures.js` module for Polymer 3.
94
- const sourceEvent = this.info.sourceEvent;
95
- const ev = new Event('vaadin-contextmenu', { bubbles: true, cancelable: true, composed: true });
96
- ev.detail = { x, y, sourceEvent };
97
- target.dispatchEvent(ev);
98
- // forward `preventDefault` in a clean way
99
- if (ev.defaultPrevented && sourceEvent && sourceEvent.preventDefault) {
100
- sourceEvent.preventDefault();
101
- }
102
- }
103
- });
@@ -1,74 +0,0 @@
1
- import { ItemElement } from '@vaadin/vaadin-item/src/vaadin-item.js';
2
-
3
- import { ListBoxElement } from '@vaadin/vaadin-list-box/src/vaadin-list-box.js';
4
-
5
- import { ContextMenuElement } from './vaadin-context-menu.js';
6
-
7
- import { ContextMenuItem, ContextMenuRendererContext } from './interfaces';
8
-
9
- /**
10
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
11
- *
12
- * @protected
13
- */
14
- declare class ContextMenuItemElement extends ItemElement {}
15
-
16
- declare global {
17
- interface HTMLElementTagNameMap {
18
- 'vaadin-context-menu-item': ContextMenuItemElement;
19
- 'vaadin-context-menu-list-box': ContextMenuListBoxElement;
20
- }
21
- }
22
-
23
- /**
24
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
25
- *
26
- * @protected
27
- */
28
- declare class ContextMenuListBoxElement extends ListBoxElement {}
29
-
30
- declare function ItemsMixin<T extends new (...args: any[]) => {}>(base: T): T & ItemsMixinConstructor;
31
-
32
- interface ItemsMixinConstructor {
33
- new (...args: any[]): ItemsMixin;
34
- }
35
-
36
- interface ItemsMixin {
37
- readonly __isRTL: boolean;
38
-
39
- /**
40
- * Defines a (hierarchical) menu structure for the component.
41
- * If a menu item has a non-empty `children` set, a sub-menu with the child items is opened
42
- * next to the parent menu on mouseover, tap or a right arrow keypress.
43
- *
44
- * The items API can't be used together with a renderer!
45
- *
46
- * #### Example
47
- *
48
- * ```javascript
49
- * contextMenu.items = [
50
- * {text: 'Menu Item 1', theme: 'primary', children:
51
- * [
52
- * {text: 'Menu Item 1-1', checked: true},
53
- * {text: 'Menu Item 1-2'}
54
- * ]
55
- * },
56
- * {component: 'hr'},
57
- * {text: 'Menu Item 2', children:
58
- * [
59
- * {text: 'Menu Item 2-1'},
60
- * {text: 'Menu Item 2-2', disabled: true}
61
- * ]
62
- * },
63
- * {text: 'Menu Item 3', disabled: true}
64
- * ];
65
- * ```
66
- */
67
- items: ContextMenuItem[] | undefined;
68
-
69
- __forwardFocus(): void;
70
-
71
- __itemsRenderer(root: HTMLElement, menu: ContextMenuElement, context: ContextMenuRendererContext): void;
72
- }
73
-
74
- export { ItemsMixin, ItemsMixinConstructor };