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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mypolis.eu/action-controller

v4.1.0

Published

`@mypolis.eu/action-controller` is a lightweight TypeScript library that brings declarative event handling to your web components. It allows you to connect DOM events to methods on LitElement-based controllers using simple HTML data-action attributes.

Readme

@mypolis.eu/action-controller

@mypolis.eu/action-controller is a lightweight TypeScript library that brings declarative event handling to your web components. It allows you to connect DOM events to methods on LitElement-based controllers using simple HTML data-action attributes.

Features

  • Declarative Event Handling: Define actions directly in your HTML using data-action attributes.

  • LitElement Based: Controllers are extensions of LitElement, allowing you to use all Lit features like reactive properties and efficient rendering.

  • Automatic Registration: Easily register your controller classes as custom elements.

  • Dynamic Content Ready: Uses a MutationObserver to automatically bind actions to new elements added to the DOM and clean up when they are removed.

  • Scoped Actions: Actions are scoped to the controller that defines them, ensuring clean component encapsulation.

  • DOM Query Helpers: Includes query and queryAll utilities for accessing elements within your controller's scope, often used with data-target attributes.

Installation

You'll also need to install lit as it's a peer dependency.

npm install @mypolis.eu/action-controller lit

# or

yarn add @mypolis.eu/action-controller lit

# or

pnpm add @mypolis.eu/action-controller lit

Core Concepts

Controllers

Controllers are custom elements that extend the Controller class (which itself extends LitElement). They encapsulate the behavior and state related to a piece of UI. The Controller base class handles the setup of action listeners.

Actions

Actions link DOM events on elements within a controller's template to methods on that controller instance. They are defined using the data-action attribute.

Syntax: data-action="eventType->controllerTagName#methodName eventType2->controllerTagName#methodName2 ..."

  • eventType: The name of the DOM event (e.g., click, input, custom-event).

  • controllerTagName: The tag name of the controller custom element (e.g., my-greeter). This must match the tag name of the controller component where the data-action attribute is placed.

  • methodName: The name of the method to call on the controller instance.

Registration

Controllers are registered as custom elements using the @customElement decorator from lit/decorators.js. This decorator requires you to explicitly provide the custom element's tag name (e.g., @customElement("my-example-controller")).

Targets

"Targets" are specific elements within a controller's view that you might want to reference directly in your controller's logic. You can identify these elements using data-target attributes (or any other selector) and access them using the query and queryAll helper functions.

Usage

// dialog-trigger.ts

import {customElement} from "lit/decorators.js";
import {Controller, target} from "@mypolis.eu/action-controller";
import type {SlDialog} from "@shoelace-style/shoelace";

@customElement("dialog-trigger")
export class DialogTrigger extends Controller {
	@target dialog!: SlDialog;

	open() {
		this.dialog.show();
	}

	close() {
		this.dialog.hide();
	}
}

// index.html

<dialog-trigger>
	<sl-dialog
		data-error="default"
		data-target="dialog-trigger.dialog"
	>
		<header>
			<h4>Algo Correu Mal</h4>
			<sl-button
				size="small"
				title="Cancelar"
				data-action="click->dialog-trigger#close"
				circle
			>
				<sl-icon
					library="lucide"
					name="x"
				></sl-icon>
			</sl-button>
		</header>
		<div>
			<p>
				Lamentamos, mas ocorreu um erro inesperado. Por favor, tente novamente dentro de momentos. Se a situação
				persistir, não hesite em contactar o nosso suporte.
			</p>
		</div>
		<button
			data-action="click->dialog-trigger#close"
			style="width: 100%"
		>
			Fechar
		</button>
	</sl-dialog>
</dialog-trigger>