npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dialogs.svelte

v0.1.3

Published

A Svelte component for custom, promise-based alert, confirm, and prompt dialogs

Readme

dialogs.svelte

Promise-based alert, confirm, and prompt dialogs for Svelte 5 – with a drop‑in provider component that lets you fully customize their UI using Svelte Snippets while keeping a simple imperative API.

Features

  • Drop‑in replacement for native alert/confirm/prompt returning promises.
  • Customizable content via Svelte 5 Snippets ({#snippet ...}) per dialog type or per individual call.
  • Queueing: multiple calls are serialized; only one dialog is visible at a time.
  • Keyboard: Escape resolves (alert: void, confirm: false, prompt: null).
  • Automatic focus handling (first button or input field).
  • Fallback to native dialogs when no provider is present – works even outside layout.

Installation

pnpm add dialogs.svelte
# or
npm install dialogs.svelte

or, You can copy the component directly into your project:

Open src/lib/dialogs.svelte
(Copying the component makes it easier to customize styles and other aspects.)

Quick Start

Wrap a layout (or page) with the Dialogs component and provide snippets for any dialogs you want to customize. Omit a snippet to use a default minimal version.

<!-- +layout.svelte -->
<script lang="ts">
	import Dialogs from 'dialogs.svelte';
	let nameInput = $state('');
</script>

<Dialogs>
	<!-- Your app -->
	<slot />

	{#snippet alert(message, ok)}
		<div class="alert">
			<p>{message}</p>
			<button onclick={ok}>OK</button>
		</div>
	{/snippet}

	{#snippet confirm(message, ok, cancel)}
		<div class="confirm">
			<p>{message}</p>
			<button onclick={ok}>OK</button>
			<button onclick={cancel}>Cancel</button>
		</div>
	{/snippet}

	{#snippet prompt(message, defaultValue, ok, cancel)}
		<div class="prompt">
			<p>{message}</p>
			<input
				bind:value={nameInput}
				{@attach defaultValue
					? (el) => {
							if (defaultValue) {
								nameInput = defaultValue;
								el.value = defaultValue;
								el.setSelectionRange(0, defaultValue.length);
							}
						}
					: undefined}
			/>
			<button
				onclick={() => {
					ok(nameInput);
					nameInput = '';
				}}>OK</button
			>
			<button onclick={cancel}>Cancel</button>
		</div>
	{/snippet}
</Dialogs>

<style>
	.alert,
	.confirm,
	.prompt {
		background: #fff;
		padding: 1rem 2rem 2rem;
		border-radius: 1rem;
	}
</style>

Use the dialogs from any descendant component:

<script lang="ts">
	import { useDialogs } from 'dialogs.svelte';
	const { alert, confirm, prompt } = useDialogs();

	async function run() {
		await alert('Hello');
		const ok = await confirm('Are you sure?');
		if (!ok) return;
		const name = await prompt('Your name?', 'Alice');
		console.log({ name });
	}
</script>

<button onclick={run}>Do stuff</button>

If you call useDialogs() outside of a provider, it falls back to the native blocking dialogs automatically.

Contributing

  1. Clone & install: pnpm install
  2. Dev server: pnpm dev
  3. Run checks: pnpm check / pnpm test
  4. Open a PR with a concise description + before/after behavior.

License

MIT