@vaadin/context-menu 23.1.0-beta1 → 23.1.0-beta2

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/lit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/lit.js ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/context-menu",
3
- "version": "23.1.0-beta1",
3
+ "version": "23.1.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,6 +22,8 @@
22
22
  "files": [
23
23
  "src",
24
24
  "theme",
25
+ "lit.js",
26
+ "lit.d.ts",
25
27
  "vaadin-*.d.ts",
26
28
  "vaadin-*.js"
27
29
  ],
@@ -35,19 +37,20 @@
35
37
  "dependencies": {
36
38
  "@open-wc/dedupe-mixin": "^1.3.0",
37
39
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/component-base": "23.1.0-beta1",
39
- "@vaadin/item": "23.1.0-beta1",
40
- "@vaadin/list-box": "23.1.0-beta1",
41
- "@vaadin/vaadin-lumo-styles": "23.1.0-beta1",
42
- "@vaadin/vaadin-material-styles": "23.1.0-beta1",
43
- "@vaadin/vaadin-overlay": "23.1.0-beta1",
44
- "@vaadin/vaadin-themable-mixin": "23.1.0-beta1"
40
+ "@vaadin/component-base": "23.1.0-beta2",
41
+ "@vaadin/item": "23.1.0-beta2",
42
+ "@vaadin/list-box": "23.1.0-beta2",
43
+ "@vaadin/lit-renderer": "23.1.0-beta2",
44
+ "@vaadin/vaadin-lumo-styles": "23.1.0-beta2",
45
+ "@vaadin/vaadin-material-styles": "23.1.0-beta2",
46
+ "@vaadin/vaadin-overlay": "23.1.0-beta2",
47
+ "@vaadin/vaadin-themable-mixin": "23.1.0-beta2"
45
48
  },
46
49
  "devDependencies": {
47
50
  "@esm-bundle/chai": "^4.3.4",
48
- "@vaadin/polymer-legacy-adapter": "23.1.0-beta1",
51
+ "@vaadin/polymer-legacy-adapter": "23.1.0-beta2",
49
52
  "@vaadin/testing-helpers": "^0.3.2",
50
53
  "sinon": "^13.0.2"
51
54
  },
52
- "gitHead": "8be43cf83102a6b9ccf309687446e590ce0164e8"
55
+ "gitHead": "f11f9245a0b5e6bf912725a501c27c24b74e7c8d"
53
56
  }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { TemplateResult } from 'lit';
7
+ import { DirectiveResult } from 'lit/directive.js';
8
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
9
+ import { ContextMenu, ContextMenuRendererContext } from '../vaadin-context-menu.js';
10
+
11
+ export type ContextMenuLitRenderer = (context: ContextMenuRendererContext, menu: ContextMenu) => TemplateResult;
12
+
13
+ export class ContextMenuRendererDirective extends LitRendererDirective<ContextMenu, ContextMenuLitRenderer> {
14
+ /**
15
+ * Adds the renderer callback to the context-menu.
16
+ */
17
+ addRenderer(): void;
18
+
19
+ /**
20
+ * Runs the renderer callback on the context-menu.
21
+ */
22
+ runRenderer(): void;
23
+
24
+ /**
25
+ * Removes the renderer callback from the context-menu.
26
+ */
27
+ removeRenderer(): void;
28
+ }
29
+
30
+ /**
31
+ * A Lit directive for populating the content of the context-menu.
32
+ *
33
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the context-menu
34
+ * via the `renderer` property. The renderer is called once to populate the content when assigned
35
+ * and whenever a single dependency or an array of dependencies changes.
36
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
37
+ *
38
+ * Dependencies can be a single value or an array of values.
39
+ * Values are checked against previous values with strict equality (`===`),
40
+ * so the check won't detect nested property changes inside objects or arrays.
41
+ * When dependencies are provided as an array, each item is checked against the previous value
42
+ * at the same index with strict equality. Nested arrays are also checked only by strict
43
+ * equality.
44
+ *
45
+ * Example of usage:
46
+ * ```js
47
+ * `<vaadin-context-menu
48
+ * ${contextMenuRenderer((context, menu) => html`...`)}
49
+ * ></vaadin-context-menu>`
50
+ * ```
51
+ *
52
+ * @param renderer the renderer callback that returns a Lit template.
53
+ * @param dependencies a single dependency or an array of dependencies
54
+ * which trigger a re-render when changed.
55
+ */
56
+ export declare function contextMenuRenderer(
57
+ renderer: ContextMenuLitRenderer,
58
+ dependencies?: unknown,
59
+ ): DirectiveResult<typeof ContextMenuRendererDirective>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { directive } from 'lit/directive.js';
7
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
8
+
9
+ export class ContextMenuRendererDirective extends LitRendererDirective {
10
+ /**
11
+ * Adds the renderer callback to the context-menu.
12
+ */
13
+ addRenderer() {
14
+ this.element.renderer = (root, contextMenu, context) => {
15
+ this.renderRenderer(root, context, contextMenu);
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Runs the renderer callback on the context-menu.
21
+ */
22
+ runRenderer() {
23
+ this.element.requestContentUpdate();
24
+ }
25
+
26
+ /**
27
+ * Removes the renderer callback from the context-menu.
28
+ */
29
+ removeRenderer() {
30
+ this.element.renderer = null;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * A Lit directive for populating the content of the context-menu.
36
+ *
37
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the context-menu
38
+ * via the `renderer` property. The renderer is called once to populate the content when assigned
39
+ * and whenever a single dependency or an array of dependencies changes.
40
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
41
+ *
42
+ * Dependencies can be a single value or an array of values.
43
+ * Values are checked against previous values with strict equality (`===`),
44
+ * so the check won't detect nested property changes inside objects or arrays.
45
+ * When dependencies are provided as an array, each item is checked against the previous value
46
+ * at the same index with strict equality. Nested arrays are also checked only by strict
47
+ * equality.
48
+ *
49
+ * Example of usage:
50
+ * ```js
51
+ * `<vaadin-context-menu
52
+ * ${contextMenuRenderer((context, menu) => html`...`)}
53
+ * ></vaadin-context-menu>`
54
+ * ```
55
+ *
56
+ * @param renderer the renderer callback that returns a Lit template.
57
+ * @param dependencies a single dependency or an array of dependencies
58
+ * which trigger a re-render when changed.
59
+ */
60
+ export const contextMenuRenderer = directive(ContextMenuRendererDirective);
@@ -274,7 +274,7 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
274
274
  */
275
275
  listenOn: {
276
276
  type: Object,
277
- value: function () {
277
+ value() {
278
278
  return this;
279
279
  },
280
280
  },
@@ -430,12 +430,12 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
430
430
 
431
431
  /** @private */
432
432
  _setListenOnUserSelect(value) {
433
- // note: these styles don't seem to work in Firefox on iOS.
433
+ // Note: these styles don't seem to work in Firefox on iOS.
434
434
  this.listenOn.style.webkitTouchCallout = value;
435
435
  this.listenOn.style.webkitUserSelect = value; // Chrome, Safari, Firefox
436
436
  this.listenOn.style.userSelect = value;
437
437
 
438
- // note: because user-selection is disabled on the overlay
438
+ // Note: because user-selection is disabled on the overlay
439
439
  // before opening the menu the text could be already selected
440
440
  // so we need to clear that selection
441
441
  document.getSelection().removeAllRanges();
@@ -20,21 +20,21 @@ register({
20
20
  sourceEvent: null,
21
21
  },
22
22
 
23
- reset: function () {
23
+ reset() {
24
24
  this.info.sourceEvent = null;
25
25
  this._cancelTimer();
26
26
  this.info.touchJob = null;
27
27
  this.info.touchStartCoords = null;
28
28
  },
29
29
 
30
- _cancelTimer: function () {
30
+ _cancelTimer() {
31
31
  if (this._timerId) {
32
32
  clearTimeout(this._timerId);
33
33
  delete this._fired;
34
34
  }
35
35
  },
36
36
 
37
- touchstart: function (e) {
37
+ touchstart(e) {
38
38
  this.info.sourceEvent = e;
39
39
  this.info.touchStartCoords = {
40
40
  x: e.changedTouches[0].clientX,
@@ -53,14 +53,14 @@ register({
53
53
  this.fire(t, ct.clientX, ct.clientY);
54
54
  }
55
55
 
56
- // needed to prevent any 'tap' gesture events from firing
56
+ // Needed to prevent any 'tap' gesture events from firing
57
57
  // which could potentially cancel/close the overlay.
58
58
  prevent('tap');
59
59
  }
60
- }, 500); // default setting for Android and iOS.
60
+ }, 500); // Default setting for Android and iOS.
61
61
  },
62
62
 
63
- touchmove: function (e) {
63
+ touchmove(e) {
64
64
  const moveThreshold = 15;
65
65
  const touchStartCoords = this.info.touchStartCoords;
66
66
  if (
@@ -71,14 +71,14 @@ register({
71
71
  }
72
72
  },
73
73
 
74
- touchend: function (e) {
74
+ touchend(e) {
75
75
  if (this._fired) {
76
76
  e.preventDefault();
77
77
  }
78
78
  this._cancelTimer();
79
79
  },
80
80
 
81
- contextmenu: function (e) {
81
+ contextmenu(e) {
82
82
  if (!e.shiftKey) {
83
83
  this.info.sourceEvent = e;
84
84
  this.fire(e.target, e.clientX, e.clientY);
@@ -86,14 +86,14 @@ register({
86
86
  }
87
87
  },
88
88
 
89
- fire: function (target, x, y) {
89
+ fire(target, x, y) {
90
90
  // NOTE(web-padawan): the code below is copied from `Polymer.Gestures._fire`,
91
91
  // which is not exported from `gestures.js` module for Polymer 3.
92
92
  const sourceEvent = this.info.sourceEvent;
93
93
  const ev = new Event('vaadin-contextmenu', { bubbles: true, cancelable: true, composed: true });
94
94
  ev.detail = { x, y, sourceEvent };
95
95
  target.dispatchEvent(ev);
96
- // forward `preventDefault` in a clean way
96
+ // Forward `preventDefault` in a clean way
97
97
  if (ev.defaultPrevented && sourceEvent && sourceEvent.preventDefault) {
98
98
  sourceEvent.preventDefault();
99
99
  }
@@ -139,7 +139,7 @@ export const ItemsMixin = (superClass) =>
139
139
  __forwardFocus() {
140
140
  const overlay = this.$.overlay;
141
141
  const child = overlay.getFirstChild();
142
- // if parent item is not focused, do not focus submenu
142
+ // If parent item is not focused, do not focus submenu
143
143
  if (overlay.parentOverlay) {
144
144
  const parent = overlay.parentOverlay.querySelector('[expanded]');
145
145
  if (parent && parent.hasAttribute('focused') && child) {