@melt-ui/svelte
Advanced tools
Comparing version 0.18.4 to 0.19.0
import { createFocusTrap, usePortal } from '../../internal/actions'; | ||
import { addEventListener, builder, createElHelpers, effect, generateId, isBrowser, noop, sleep, styleToString, } from '../../internal/helpers'; | ||
import { addEventListener, builder, createElHelpers, effect, generateId, isBrowser, last, noop, sleep, styleToString, } from '../../internal/helpers'; | ||
import { removeScroll } from '../../internal/helpers/scroll'; | ||
@@ -12,2 +12,3 @@ import { get, writable } from 'svelte/store'; | ||
}; | ||
const openDialogIds = writable([]); | ||
export function createDialog(args = {}) { | ||
@@ -23,2 +24,13 @@ const withDefaults = { ...defaults, ...args }; | ||
const open = writable(false); | ||
effect([open], ([$open]) => { | ||
// Prevent double clicks from closing multiple dialogs | ||
sleep(100).then(() => { | ||
if ($open) { | ||
openDialogIds.update((prev) => [...prev, ids.content]); | ||
} | ||
else { | ||
openDialogIds.update((prev) => prev.filter((id) => id !== ids.content)); | ||
} | ||
}); | ||
}); | ||
const trigger = builder(name('trigger'), { | ||
@@ -79,4 +91,7 @@ stores: open, | ||
e.preventDefault(); | ||
e.stopImmediatePropagation(); | ||
const $options = get(options); | ||
if ($options.closeOnOutsideClick) { | ||
const $openDialogIds = get(openDialogIds); | ||
const isLast = last($openDialogIds) === ids.content; | ||
if ($options.closeOnOutsideClick && isLast) { | ||
open.set(false); | ||
@@ -132,5 +147,6 @@ } | ||
}); | ||
effect([open, options], ([$open, $options]) => { | ||
effect([open, options, openDialogIds], ([$open, $options, $openDialogIds]) => { | ||
const unsubs = []; | ||
if ($options.closeOnEscape && $open) { | ||
const isLast = last($openDialogIds) === ids.content; | ||
if ($options.closeOnEscape && $open && isLast) { | ||
unsubs.push(addEventListener(document, 'keydown', (e) => { | ||
@@ -137,0 +153,0 @@ if (e.key === 'Escape') { |
{ | ||
"name": "@melt-ui/svelte", | ||
"version": "0.18.4", | ||
"version": "0.19.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "exports": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
392588
9678