@vaadin/overlay 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.
package/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  <vaadin-overlay> is a Web Component meant for internal use in Vaadin components.
4
4
 
5
5
  [![npm version](https://badgen.net/npm/v/@vaadin/overlay)](https://www.npmjs.com/package/@vaadin/overlay)
6
- [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
7
6
 
8
7
  ## License
9
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/overlay",
3
- "version": "24.4.0-dev.b3e1d14600",
3
+ "version": "24.5.0-alpha1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,11 +36,11 @@
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/a11y-base": "24.4.0-dev.b3e1d14600",
40
- "@vaadin/component-base": "24.4.0-dev.b3e1d14600",
41
- "@vaadin/vaadin-lumo-styles": "24.4.0-dev.b3e1d14600",
42
- "@vaadin/vaadin-material-styles": "24.4.0-dev.b3e1d14600",
43
- "@vaadin/vaadin-themable-mixin": "24.4.0-dev.b3e1d14600",
39
+ "@vaadin/a11y-base": "24.5.0-alpha1",
40
+ "@vaadin/component-base": "24.5.0-alpha1",
41
+ "@vaadin/vaadin-lumo-styles": "24.5.0-alpha1",
42
+ "@vaadin/vaadin-material-styles": "24.5.0-alpha1",
43
+ "@vaadin/vaadin-themable-mixin": "24.5.0-alpha1",
44
44
  "lit": "^3.0.0"
45
45
  },
46
46
  "devDependencies": {
@@ -48,5 +48,5 @@
48
48
  "@vaadin/testing-helpers": "^0.6.0",
49
49
  "sinon": "^13.0.2"
50
50
  },
51
- "gitHead": "502d4f5b03f770a83d270d98078cde230254dd0e"
51
+ "gitHead": "57806caac5468532a3b4e3dbdda730cd0fca193a"
52
52
  }
@@ -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 { LitElement } from 'lit';
@@ -14,7 +14,7 @@ import { OverlayMixin } from './vaadin-overlay-mixin.js';
14
14
  *
15
15
  * ## Disclaimer
16
16
  *
17
- * This component is an experiment not intended for publishing to npm.
17
+ * This component is an experiment and not yet a part of Vaadin platform.
18
18
  * There is no ETA regarding specific Vaadin version where it'll land.
19
19
  * Feel free to try this code in your apps as per Apache 2.0 license.
20
20
  */
@@ -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 { html, LitElement } from 'lit';
@@ -16,7 +16,7 @@ import { overlayStyles } from './vaadin-overlay-styles.js';
16
16
  *
17
17
  * ## Disclaimer
18
18
  *
19
- * This component is an experiment not intended for publishing to npm.
19
+ * This component is an experiment and not yet a part of Vaadin platform.
20
20
  * There is no ETA regarding specific Vaadin version where it'll land.
21
21
  * Feel free to try this code in your apps as per Apache 2.0 license.
22
22
  */
@@ -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 { Constructor } from '@open-wc/dedupe-mixin';
@@ -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 { AriaModalController } from '@vaadin/a11y-base/src/aria-modal-controller.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 type { Constructor } from '@open-wc/dedupe-mixin';
@@ -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 { afterNextRender } from '@polymer/polymer/lib/utils/render-status.js';
@@ -220,12 +220,13 @@ export const OverlayMixin = (superClass) =>
220
220
  this._oldOwner = owner;
221
221
 
222
222
  const rendererChanged = this._oldRenderer !== renderer;
223
+ const hasOldRenderer = this._oldRenderer !== undefined;
223
224
  this._oldRenderer = renderer;
224
225
 
225
226
  const openedChanged = this._oldOpened !== opened;
226
227
  this._oldOpened = opened;
227
228
 
228
- if (rendererChanged) {
229
+ if (rendererChanged && hasOldRenderer) {
229
230
  this.innerHTML = '';
230
231
  // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
231
232
  // When clearing the rendered content, this part needs to be manually disposed of.
@@ -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 { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,9 +1,10 @@
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 { getAncestorRootNodes } from '@vaadin/component-base/src/dom-utils.js';
7
+ import { observeMove } from './vaadin-overlay-utils.js';
7
8
 
8
9
  const PROP_NAMES_VERTICAL = {
9
10
  start: 'top',
@@ -146,17 +147,25 @@ export const PositionMixin = (superClass) =>
146
147
 
147
148
  /** @private */
148
149
  __addUpdatePositionEventListeners() {
149
- window.addEventListener('resize', this._updatePosition);
150
+ window.visualViewport.addEventListener('resize', this._updatePosition);
151
+ window.visualViewport.addEventListener('scroll', this.__onScroll, true);
150
152
 
151
153
  this.__positionTargetAncestorRootNodes = getAncestorRootNodes(this.positionTarget);
152
154
  this.__positionTargetAncestorRootNodes.forEach((node) => {
153
155
  node.addEventListener('scroll', this.__onScroll, true);
154
156
  });
157
+
158
+ if (this.positionTarget) {
159
+ this.__observePositionTargetMove = observeMove(this.positionTarget, () => {
160
+ this._updatePosition();
161
+ });
162
+ }
155
163
  }
156
164
 
157
165
  /** @private */
158
166
  __removeUpdatePositionEventListeners() {
159
- window.removeEventListener('resize', this._updatePosition);
167
+ window.visualViewport.removeEventListener('resize', this._updatePosition);
168
+ window.visualViewport.removeEventListener('scroll', this.__onScroll, true);
160
169
 
161
170
  if (this.__positionTargetAncestorRootNodes) {
162
171
  this.__positionTargetAncestorRootNodes.forEach((node) => {
@@ -164,6 +173,11 @@ export const PositionMixin = (superClass) =>
164
173
  });
165
174
  this.__positionTargetAncestorRootNodes = null;
166
175
  }
176
+
177
+ if (this.__observePositionTargetMove) {
178
+ this.__observePositionTargetMove();
179
+ this.__observePositionTargetMove = null;
180
+ }
167
181
  }
168
182
 
169
183
  /** @private */
@@ -204,18 +218,25 @@ export const PositionMixin = (superClass) =>
204
218
  /** @private */
205
219
  __onScroll(e) {
206
220
  // If the scroll event occurred inside the overlay, ignore it.
207
- if (!this.contains(e.target)) {
208
- this._updatePosition();
221
+ if (e.target instanceof Node && this.contains(e.target)) {
222
+ return;
209
223
  }
224
+
225
+ this._updatePosition();
210
226
  }
211
227
 
212
228
  _updatePosition() {
213
- if (!this.positionTarget || !this.opened) {
229
+ if (!this.positionTarget || !this.opened || !this.__margins) {
214
230
  return;
215
231
  }
216
232
 
217
233
  const targetRect = this.positionTarget.getBoundingClientRect();
218
234
 
235
+ if (targetRect.width === 0 && targetRect.height === 0 && this.opened) {
236
+ this.opened = false;
237
+ return;
238
+ }
239
+
219
240
  // Detect the desired alignment and update the layout accordingly
220
241
  const shouldAlignStartVertically = this.__shouldAlignStartVertically(targetRect);
221
242
  this.style.justifyContent = shouldAlignStartVertically ? 'flex-start' : 'flex-end';
@@ -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 { Constructor } from '@open-wc/dedupe-mixin';
@@ -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
 
@@ -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 { css } from 'lit';
@@ -39,7 +39,8 @@ export const overlayStyles = css`
39
39
  }
40
40
 
41
41
  :host([hidden]),
42
- :host(:not([opened]):not([closing])) {
42
+ :host(:not([opened]):not([closing])),
43
+ :host(:not([opened]):not([closing])) [part='overlay'] {
43
44
  display: none !important;
44
45
  }
45
46
 
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+
7
+ /**
8
+ * Observe moving an element around on a page.
9
+ *
10
+ * Based on the idea from https://samthor.au/2021/observing-dom/ as implemented in Floating UI
11
+ * https://github.com/floating-ui/floating-ui/blob/58ed169/packages/dom/src/autoUpdate.ts#L45
12
+ */
13
+ export function observeMove(element: HTMLElement, callback: () => void): () => void;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+
7
+ /**
8
+ * Observe moving an element around on a page.
9
+ *
10
+ * Based on the idea from https://samthor.au/2021/observing-dom/ as implemented in Floating UI
11
+ * https://github.com/floating-ui/floating-ui/blob/58ed169/packages/dom/src/autoUpdate.ts#L45
12
+ *
13
+ * @param {HTMLElement} element
14
+ * @param {Function} callback
15
+ * @return {Function}
16
+ */
17
+ export function observeMove(element, callback) {
18
+ let io = null;
19
+
20
+ const root = document.documentElement;
21
+
22
+ function cleanup() {
23
+ io && io.disconnect();
24
+ io = null;
25
+ }
26
+
27
+ function refresh(skip = false, threshold = 1) {
28
+ cleanup();
29
+
30
+ const { left, top, width, height } = element.getBoundingClientRect();
31
+
32
+ if (!skip) {
33
+ callback();
34
+ }
35
+
36
+ if (!width || !height) {
37
+ return;
38
+ }
39
+
40
+ const insetTop = Math.floor(top);
41
+ const insetRight = Math.floor(root.clientWidth - (left + width));
42
+ const insetBottom = Math.floor(root.clientHeight - (top + height));
43
+ const insetLeft = Math.floor(left);
44
+
45
+ const rootMargin = `${-insetTop}px ${-insetRight}px ${-insetBottom}px ${-insetLeft}px`;
46
+
47
+ const options = {
48
+ rootMargin,
49
+ threshold: Math.max(0, Math.min(1, threshold)) || 1,
50
+ };
51
+
52
+ let isFirstUpdate = true;
53
+
54
+ function handleObserve(entries) {
55
+ let ratio = entries[0].intersectionRatio;
56
+
57
+ if (ratio !== threshold) {
58
+ if (!isFirstUpdate) {
59
+ return refresh();
60
+ }
61
+
62
+ // It's possible for the watched element to not be at perfect 1.0 visibility when we create
63
+ // the IntersectionObserver. This has a couple of causes:
64
+ // - elements being on partial pixels
65
+ // - elements being hidden offscreen (e.g., <html> has `overflow: hidden`)
66
+ // - delays: if your DOM change occurs due to e.g., page resize, you can see elements
67
+ // behind their actual position
68
+ //
69
+ // In all of these cases, refresh but with this lower ratio of threshold. When the element
70
+ // moves beneath _that_ new value, the user will get notified.
71
+ if (ratio === 0.0) {
72
+ ratio = 0.0000001; // Just needs to be non-zero
73
+ }
74
+
75
+ refresh(false, ratio);
76
+ }
77
+
78
+ isFirstUpdate = false;
79
+ }
80
+
81
+ io = new IntersectionObserver(handleObserve, options);
82
+
83
+ io.observe(element);
84
+ }
85
+
86
+ refresh(true);
87
+
88
+ return cleanup;
89
+ }
@@ -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 { DirMixin } from '@vaadin/component-base/src/dir-mixin.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 { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import './vaadin-overlay-styles.js';
2
+ import '../../src/vaadin-overlay.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import './vaadin-overlay-styles.js';
2
+ import '../../src/vaadin-overlay.js';