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 🙏

© 2024 – Pkg Stats / Ryan Hefner

extended-click-outside

v1.1.1

Published

Extended click outside utility for web-applications

Downloads

27

Readme

extended-click-outside v1.1.1


Brief annotation

"extended-click-outside" is an utility that can help developers with outer click-events handlers registration. To create a handler, it is enough to pass a valid selector to its "init" instance method. Selector also can be an object of type element reference from different frameworks and libraries. This utility can automatically extract element from given references. Different ways of configuration will help to create customized handlers for specific needs. Such hanlders often used with form controls and interactive shells to specify their properties and behavior depending on their state inactivity. An important feature is that one DOM-element can have only single "extended-click-outside" listener. This is done to prevent the web-application from being overloaded with excess handlers. Utility works correctly in jsdom-environment, so it can be useful in web-applications.

Installation with npm

npm install --save extended-click-outside

Installation with yarn

yarn install --production extended-click-outside

Importing

import ExtendedClickOutside from "extended-click-outside"

Importing types

import ExtendedClickOutside from "extended-click-outside/types"

Table of contents

Simple example

Creating extended click outside handler on "div" element.

import ExtendedClickOutside from "extended-click-outside";

const extendedClickOutside = new ExtendedClickOutside();
const div = document.querySelector("div");
const handler = () => console.log("extended-click-outside: handler");

extendedClickOutside.init(div, handler);

Example with config

Creating disposal handler on "div" element with "capture" flag.

import ExtendedClickOutside from "extended-click-outside";

const extendedClickOutside = new ExtendedClickOutside();
const div = document.querySelector("div");
const handler = () => console.log("extended-click-outside: disposal handler");
const config = {
  once: true,
  capture: true,
};

extendedClickOutside.init(div, handler, config);

Example with framework

Creating handler on React DOMRef.

import { useRef, useEffect } from "react";
import ExtendedClickOutside from "extended-click-outside";

export default function ComponentWithRef() {
  const simpleRef = useRef();
  const extendedClickOutside = new ExtendedClickOutside();
  const handler = () => console.log("extended-click-outside: DOMRef handler");

  useEffect(() => {
    extendedClickOutside.init(simpleRef, handler);
  }, []);

  return (
    <div className="with-ref">
      <h3 ref={simpleRef}>Simple DOMRef</h3>
    </div>
  );
}

Removal of handler

Removal of registered handler from element.

import ExtendedClickOutside from "extended-click-outside";

const extendedClickOutside = new ExtendedClickOutside();
const div = document.querySelector("div");

// Setting of handler...

extendedClickOutside.remove(div, true);

// Second argument works like "useWarnings" flag in config.

Removal of all handlers

Removal of all registered handlers from all elements.

import ExtendedClickOutside from "extended-click-outside";

const extendedClickOutside = new ExtendedClickOutside();
const div = document.querySelector("div");
const span = document.querySelector("span");

// Setting of handlers...

extendedClickOutside.removeAllListeners();

Quantity information

Getting information about the quantuty of handlers.

import ExtendedClickOutside from "extended-click-outside";

const extendedClickOutside = new ExtendedClickOutside();
const div = document.querySelector("div");
const span = document.querySelector("span");
const handler = () => console.log("extended-click-outside: handler");

extendedClickOutside.init(div, handler);
extendedClickOutside.init(span, handler, {
  useWarnings: true,
});

const quantity = extendedClickOutside.getClickOutsidesCount();
const snapshotsList = extendedClickOutside.getCurrentSnapshots();

Config list

Config name | Config type | Config appointment | Config values ------------|-------------|--------------------|-------------- blockKeys|Array|List of keys combined with "click" event to block the listener.|"alt", "ctrl", "shift"| capture|Boolean|Event "capture" flag in event listener.|—| once|Boolean|Registers disposable handler for element.|—| selfOnly|Boolean|Handler will be registered only on current element (except children).|—| useWarnings|Boolean|Usefull internal warnings will be shown in console.|—|

License

MIT