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

selectable-area

v1.0.0

Published

Selection Area for html elements, defined by user.

Downloads

1

Readme

Selection Area

npm version

Simple JavaScript seletion area to any DOM container element.

Installation

Install with npm

npm install selection-area

Install with yarn

yarn add selection-area

From Source Code

Clone or download zipped source code into node_modules project folder.

git clone https://github.com/lucasmenendez/selection-area.git <project>/node_modules/selection-area

Including SelectionArea

Import dist version:

<script src="/node_modules/webproletarian/dist/selection-area.js"></script>

Or import with ES6 import:

import { SelectionArea } from 'selection-area';

Demo

Checkout the demo here.

Documentation

Table of Contents

Area

Area class includes all required functions to emulate the area behaviour. Constructor initializes main params of area Element and stores area DOM Element ID

Parameters

  • id string Area Element DOM ID
  • x number Initial area position on x axis, default 0 (optional, default 0)
  • y number Initial area position on y axis, default 0 (optional, default 0)

instance

Instance function creates DOM Element for selection area, assings the ID provided and sets default style to it. The function receives container Element, append created area to it and stores both of them into the current instance.

Parameters
  • parent Element Container Element to append selection area

resize

Recalculates current area dimensions and call uptdate to reset current DOM Element.

Parameters
  • x number Current cursor position on x axis
  • y number Current cursor position on y axis

move

Recalculates current area DOM Element position based en current cursor position.

Parameters
  • posx number Current cursor position on x axis
  • posy number Current cursor position on y axis

destroy

Deletes current DOM Element from parent container.

isOver

Calculates if target Element dimensions and current selection area DOM Element dimensions intersects in any side.

Parameters
  • target Element Target DOM Element to check if area is over it

Returns any Boolean with intersection result

SelectionArea

SelectionArea class listen mouse movements to create and adapt a selection area checking if intersects with any target child element and returns the content of defined property of that childs.

Parameters

  • config Object Config object
    • config.container Element DOM Element to make selectable
    • config.targetSelector string DOM selector of selectables childs
    • config.areaId string? DOM ID for selection area to define styles
    • config.property string? Property to get from selected childs
    • config.callback function? Function to call when selection ends

Examples

import { SelectionArea } from 'selection-area';

let container = document.querySelector('.parent');
let targetSelector = '.child';
let callback = selection => {
     if (selection.length == 0) console.warn("empty selection");
     else console.log(selection);
}

let selectable = new Selectable({ container, targetSelector, callback });

onSelect

Function stores user callback to invoke it when selection ends.

Parameters
  • callback function Function defined as callback by user

checkConfig

Function that checks if all required configuration are provided as param, extract whole configurayions inside it and stores into current instance.

Parameters
  • config Onject Configuration object definition

listenMouse

Sets custom listeners to mouse down, move and up events.

initArea

initArea funtion clears current selection, creates new area with ID provided and instances it into current container.

Parameters

updateArea

updateArea captures current mouse position and updates current selection area with that position, resizing area and moving it.

Parameters

removeArea

removeArea extract selected items, destroy current selection area and invokes callback passing values of selected items.

Parameters

checkIntersections

checkIntersecionts iterates over all posible targets and checks if current selection area intersects with each of them. Stores all included values of user defined child property.