@sveltia/ui 0.13.1 → 0.13.2
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,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-nested-ternary */
|
|
2
2
|
|
|
3
3
|
import { generateElementId } from '@sveltia/utils/element';
|
|
4
|
+
import { sleep } from '@sveltia/utils/misc';
|
|
4
5
|
import { get, writable } from 'svelte/store';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -127,6 +128,18 @@ class Popup {
|
|
|
127
128
|
}
|
|
128
129
|
});
|
|
129
130
|
|
|
131
|
+
this.anchorElement.addEventListener('transitionstart', () => {
|
|
132
|
+
if (this.anchorElement.closest('.hiding, .hidden, [hidden]')) {
|
|
133
|
+
this.hideImmediately();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
new IntersectionObserver(([entry]) => {
|
|
138
|
+
if (!entry.isIntersecting && get(this.open)) {
|
|
139
|
+
this.hideImmediately();
|
|
140
|
+
}
|
|
141
|
+
}).observe(this.anchorElement);
|
|
142
|
+
|
|
130
143
|
// Close the popup when the backdrop, a menu item or an option is clicked
|
|
131
144
|
this.popupElement.addEventListener('click', (event) => {
|
|
132
145
|
event.stopPropagation();
|
|
@@ -188,6 +201,16 @@ class Popup {
|
|
|
188
201
|
this.observer.unobserve(this.positionBaseElement);
|
|
189
202
|
this.observer.observe(this.positionBaseElement);
|
|
190
203
|
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Hide the popup immediately (when the anchor is being hidden).
|
|
207
|
+
*/
|
|
208
|
+
async hideImmediately() {
|
|
209
|
+
this.popupElement.hidden = true;
|
|
210
|
+
this.open.set(false);
|
|
211
|
+
await sleep(50);
|
|
212
|
+
this.popupElement.hidden = false;
|
|
213
|
+
}
|
|
191
214
|
}
|
|
192
215
|
|
|
193
216
|
/**
|