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

ng-reorder

v1.0.1

Published

Sort elements within a list by using drag-n-drop interface without any restrictions by direction

Downloads

190

Readme

NgReorder

This module provides a way to sort elements within a list by using drag-n-drop interface without any restrictions by direction.

see live example

Instalation

npm install ng-reorder

API

DragUnitDirective

Dragable element
selector: dragUnit

Inputs

| Input | Type | Default value | Description | | -------------- | ------- | --------------- | ---------------------------------------------------------------------------------- | | disabled | boolean | false | An element will not response for dragging while this property it's true |

Outputs

| Output | Type | Description | | ------------ | --------------------------- | ----------------------------------------------------------------------------- | | unitTaken: | EventEmitter<UnitTaken> | Emits when the dragging sequence successfully started and an element is taken | | unitMoved: | EventEmitter<UnitMoved> | Emits when an element is moved on a page while user is dragging it | | unitReleased:| EventEmitter<UnitReleased> | Emits when an element is being released |

DragCollectionDirective

Collection for dragable elements
selector: dragCollection

Inputs

| Input | Type | Default value | Description | | -------------- | ------- | ------------- | ------------------------------------------------------------------------------------- | | disabled | boolean | false | Dragging sequence will not starts at all when true |

Outputs

| Output | Type | Description | | ------------- | ------------------------------- | -------------------------------------------------- | | dropCompleted | EventEmitter<CollectionSorted> | Emits when drag-n-drop sequence is totaly comleted |

DragHandleDirective

An element which will start drag sequence in case whether you don't want to use the entire field of DragUnitDirective parent
selector: dragHandle

DragRegectorDirective

An element which will not start drag sequence in case whether you need to exclude some element from that(buttons, inputs, ect.)
selector: dragRejector

Interfaces

UnitTaken

| Data | Type | Description | | -------- |------------------------- | -------------- | | element | DragUnitDirective | Source element | | event | MouseEvent | TouchEvent | Native event |

UnitMoved

| Data | Type | Description | | -------- |------------------------- | ----------------------------------------------------------------------- | | element | DragUnitDirective | Source element | | distance | Point | Distance in pixels from the position where the source element was taken | | event | MouseEvent | TouchEvent | Native event |

UnitReleased

| Data | Type | Description | | -------- |------------------------- | -------------- | | element | DragUnitDirective | Source element | | event | MouseEvent | TouchEvent | Native event |

CollectionSorted

| Data | Type | Description | | ------------- | ----------------------- | -------------------------------------------------------------------- | | collection | DragCollectionDirective | Collection which contain the source element | | element | DragUnitDirective | Source element | | previousIndex | number | Origin index of the element in the collection | | currentIndex | number | New index of the element where it was moved to within the collection |

Point

| Data | Type | Description | | ---- | ------ | --------------------------- | | x | number | Pixel's amount along X-axis | | y | number | Pixel's amount along Y-axis |

Usage

  1. Register NgReorderModule in your app module or any module you'd like
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { NgReorderModule } from 'ng-reorder';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgReorderModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
import { Component } from '@angular/core';
import { CollectionSorted, reorderItems } from 'ng-reorder';

@Component({
	selector: 'my-app',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.scss']
})
export class AppComponent {

	test: Array<number>;

	k: number;

	constructor() {
		this.test = this.getTest(30);
	}

	private getTest(x: number): Array<number> {
		const j = new Array<number>();
		for (let i = 0; i < x; ++i) {
			j.push(i);
		}
		this.k = x;
		return j;
	}

	public sort(e: CollectionSorted) {
		this.test = reorderItems(this.test, e.previousIndex, e.currentIndex);
	}

	public add() {
		this.test.push(this.k++);
	}
	public remove() {
		this.test.pop();
		--this.k;
	}

}
  1. Use dragCollection directive for wrapper of collection of your elements (ul, ol, or just div for instance)
<div id="buttons">
	<button id="add" (click)="add()">add</button>
	<button id="remove" (click)="remove()">remove</button>
</div>

<ul id="collection" dragCollection (dropCompleted)="sort($event)">
	<li *ngFor="let item of test" dragUnit [value]=item>
		<div class="handle" dragHandle></div>
		<span>{{item}}</span>
        <!-- THIS ELEMENT WILL NOT RESPOND FOR DRAG-N-DROP -->
		<div class="rejector" dragRejector></div> 
	</li>
</ul>
  1. Style your elements
div#buttons {
    display: flex;
    justify-content: space-around;
}

div#buttons button {
    color: white;
    border: none;
    background: none;
    padding: 0.5em;
    cursor: pointer;
    font-family: sans-serif;
    text-transform: uppercase;
    min-width: 150px;
}

div#buttons button:focus {
    outline: none;
}

div#buttons button#add {
    background: #58c292;
}

div#buttons button#remove {
    background: #cd3a3a;
}

ul#collection {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    justify-content: space-evenly;
    margin: 1em 0;
    padding: 0;
}

ul#collection li.drag-unit {
    list-style: none;
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 4em;
    height: 4em;
    box-shadow: 0px 0px 2px #333;
    background-color: white;
    color: #333;
    text-align: center;
    margin: 0.5em;
    user-select: none;
    transition: box-shadow 250ms ease;
}

ul#collection.in-action li.drag-unit:not(.active) {
    transition: 300ms transform cubic-bezier(0.2, 0, 0.2, 1);
}

ul#collection.in-action .drag-unit.active {
    z-index: 2000;
    box-shadow: 0px 0px 4px #333;
}

ul#collection.in-action .drag-unit.dropped {
    box-shadow: 0px 0px #333;
    transition: transform 250ms cubic-bezier(0.5, 0, 0.2, 1), box-shadow 250ms ease;
    z-index: 2000;
}

.handle,
.rejector {
    width: 100%;
    height: 1em;
}

.handle {
    background: #58c292;
    cursor: move;
}

.rejector {
    background: #cd3a3a;
    cursor: not-allowed;
}

Credits

This project is based on Angular's Drag-and-drop module and I really want to thanks everyone Angular team member for creating this awesome framework.