@wentools/overlay 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/popover.svelte +15 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wentools/overlay",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Svelte 5 popover, dropdown menu, and tooltip components with CSS custom property theming",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -225,20 +225,7 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
225
225
  actualPosition = newPosition
226
226
  }
227
227
 
228
- // Ignore click-outside for one frame after opening, so a programmatic open
229
- // from pointerdown isn't immediately closed by the click from the same tap
230
- let ignoreClickOutside = false
231
-
232
- $effect(() => {
233
- if (open) {
234
- ignoreClickOutside = true
235
- requestAnimationFrame(() => { ignoreClickOutside = false })
236
- }
237
- })
238
-
239
228
  const handleClickOutside = (event: MouseEvent) => {
240
- if (!open || !closeOnClickOutside || ignoreClickOutside) return
241
-
242
229
  const target = event.target as Node
243
230
  if (
244
231
  popoverElement &&
@@ -250,6 +237,21 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
250
237
  }
251
238
  }
252
239
 
240
+ // Defer adding the click-outside listener by one frame after opening, so a
241
+ // programmatic open from pointerdown isn't closed by the click from the same tap
242
+ $effect(() => {
243
+ if (!open || !closeOnClickOutside) return
244
+
245
+ const rafId = requestAnimationFrame(() => {
246
+ document.addEventListener('click', handleClickOutside)
247
+ })
248
+
249
+ return () => {
250
+ cancelAnimationFrame(rafId)
251
+ document.removeEventListener('click', handleClickOutside)
252
+ }
253
+ })
254
+
253
255
  const handleKeydown = (event: KeyboardEvent) => {
254
256
  if (!open || !closeOnEscape) return
255
257
 
@@ -271,11 +273,6 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
271
273
  onMount(() => {
272
274
  const cleanup: (() => void)[] = []
273
275
 
274
- if (closeOnClickOutside) {
275
- document.addEventListener('click', handleClickOutside)
276
- cleanup.push(() => document.removeEventListener('click', handleClickOutside))
277
- }
278
-
279
276
  if (closeOnEscape) {
280
277
  document.addEventListener('keydown', handleKeydown)
281
278
  cleanup.push(() => document.removeEventListener('keydown', handleKeydown))