@pictogrammers/components 0.5.26 → 0.5.27

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pictogrammers/components",
3
3
  "type": "module",
4
- "version": "0.5.26",
4
+ "version": "0.5.27",
5
5
  "license": "MIT",
6
6
  "author": "Austin Andrews",
7
7
  "scripts": {
@@ -63,7 +63,9 @@ export default class PgOverlayMenu extends PgOverlay {
63
63
  }
64
64
  });
65
65
  }, {
66
+ // @ts-ignore
66
67
  trackVisibility: true,
68
+ delay: 100,
67
69
  root: null, // Defaults to the browser viewport
68
70
  threshold: 0 // Triggers as soon as even 1 pixel enters or leaves
69
71
  });
@@ -77,18 +77,26 @@ export default class PgOverlaySelectMenu extends PgOverlay {
77
77
  this.$overlay.style.setProperty('--pg-overlay-menu-_y', `${y}px`);
78
78
  // Focus
79
79
  this.$menu.focus(index);
80
- // Overlay
81
- const observer = new IntersectionObserver((entries) => {
82
- entries.forEach(entry => {
83
- console.log(entry.intersectionRatio);
84
- //this.$overlay.classList.toggle('no-offset', entry.intersectionRatio < 1);
85
- // entry.isIntersecting will be false if it is entirely outside the viewport
86
- if (!entry.isIntersecting) {
87
- console.log('Element is completely outside the viewport');
88
- } else {
89
- console.log('Element is at least partially inside the viewport');
90
- }
91
- });
80
+ // Keep the menu fully within the viewport once its real size is known
81
+ const observer = new IntersectionObserver(([entry]) => {
82
+ observer.disconnect();
83
+ if (entry.intersectionRatio === 1) {
84
+ return;
85
+ }
86
+ const { top, bottom } = entry.boundingClientRect;
87
+ const viewportHeight = entry.rootBounds?.height ?? window.innerHeight;
88
+ let offset = 0;
89
+ if (bottom > viewportHeight) {
90
+ offset = viewportHeight - bottom;
91
+ }
92
+ // Prefer keeping the top edge visible over the bottom if it can't fully fit
93
+ if (top + offset < 0) {
94
+ offset = -top;
95
+ }
96
+ if (offset !== 0) {
97
+ y += offset;
98
+ this.$overlay.style.setProperty('--pg-overlay-menu-_y', `${y}px`);
99
+ }
92
100
  }, {
93
101
  root: null, // Defaults to the browser viewport
94
102
  threshold: 1 // Triggers as soon as even 1 pixel enters or leaves