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-draggable-han

v1.0.8

Published

Angular draggable module

Downloads

261

Readme

NgDraggable

Angular module that provides the ability to drag the element. It also limits the area where the element is dragging, or provides a directive that occurs when it is dragged over other elements.

한국어

DEMO

Usage

  1. Install ng-draggable-han package.

    yarn add ng-draggable-han
  2. Import DraggableModule to @NgModule.

    import { DraggableModule } from 'ng-draggable-han';
       
    @NgModule({
    	imports : [..., DraggableModule]
    })
       
  3. Add directive to template. For example, DraggableDirective is used by:

    <div class="box" ngDraggable (dragStart)="onDragStart($event)"></div>
  4. Add event handler.

    class SomeComponent {
    	onDragStart (event : DragEvent) {
    		// do something
    	}
    }

Common Interfaces

Position

Represents the coordinates of x, y.

interface Position {
	x : number;
	y : number;
}

Boundaries

Use to limit the area where MobableDirective can move.

interface Boundaries {
	minX : number;
	maxX : number;
	minY : number;
	maxY : number;
}

DragEvent

Represent drag event, emitted by DraggableDirective.

interface DragEvent {
	start : Position; // position of starting drag
	current : Position; // position of current drag
	target : HTMLElement; // dragging HTMLElement

	movement : Position; // offsets while drag
}

SortEvent

Represent sort event, emitted by SortableAreaDirective. Targets are MovableDirective.

interface SortEvent {
	currentIndex : number; // index of starting drag element
	newIndex : number; // index of sort target
}

Directives

DraggableDirective ([ngDraggable])

Adds the ability to respond to the drag by the element.

<div ngDraggable>react drag event</div>
  • Properties

    • @Input() ngMovable : boolean : Switch of drag interaction. (default: true)

      <div ngDraggable>default : true</div>
      <div [ngDraggable]="false">disabled</div>
      <div [ngDraggable]="someFlag">set by flag</div>
    • isDragging : boolean : Represents element is dragging now. This flag used to set dragging CSS class.

  • Methods

    • clientRect() : DOMRect : Returns DOMRect of element. (internally use getBoundingClientRect())
  • Events

    • dragStart : DragEvent : Drag start event

    • dragMove : DragEvent : Drag move event

    • dragEnd : DragEvent : Drag end event

MovableDirective ([ngMovable])

The MovableDirective adds the ability for the element to move in response to the drag, but the element with this directive does not move directly. You must use MovebleHelperDirective to display the element during dragging.

<div class="moveBox" ngMovable>
	<span>inner text</span>
	<ng-template ngMovableHelper></ng-template>
</div>
  • Properties

    • ngMovable : boolean : Switch of drag interaction, (default : true)

      <div ngMovable>default : true</div>
      <div [ngMovable]="false">disabled</div>
      <div [ngMovable]="someFlag">set by flag</div>
    • @Input() reset : boolean : Switch of resetting position. If set, returns to original position. (true : true)

  • Methods

    • setMovementBoundaries (boundaries : Boundaries) : Restrict moving area of MovableDirective. Called by MovableAreaDirective.
  • CSS Classes

    • dragging : Added to original/replica element during dragging.

    • dragSource : Added to original element during dragging.

    • dragDummy : Added to replica element during dragging.

    The replication element does not exist in the lower layer of the original element or parent element because it uses @angular/cdk/overlay. The replication element is rendered to the <body>.

tip : DragEvent in DraggableDirective can also be received in MovableAreaDirective. So it's possible to use it as follows.

<div ngMovableArea (dragEnd)="doSomething()">
	<div ngMovable></div>
</div>

MovableHelperDirective ([ngMovableHelper])

Use to display replicas on the screen while the MovableDirective Element is being dragged.

MovableAreaDirective ([ngMovableArea])

Limits the area where the MovableDirective element can move. The MovableDirective element cannot be moved out of the MovableAreaDirective element.

<div class="area" ngMovableArea>
	<div class="box" ngMovable [reset]="false">
		<ng-template ngMovableHelper></ng-template>
	</div>
</div>

SortableAreaDirective ([ngSortableArea])

When the MovableDirective element moves over another MovableDirective element, a SortEvent event occurs.

<div class="area sortable" ngSortableArea (sort)="sort($event)">
	<div class="box" ngMovable *ngFor="let box of sortableList">
		<span>{{ box }}</span>
		<ng-template ngMovableHelper></ng-template>
	</div>
</div>
export class AppComponent {
	title = 'ng-draggable';

	public sortableList : any[] = ['box 1', 'box 2', 'box 3', 'box 4'];

	sort (event : SortEvent) {
		const current = this.sortableList[event.currentIndex];
		const swapWith = this.sortableList[event.newIndex];

		this.sortableList[event.newIndex] = current;
		this.sortableList[event.currentIndex] = swapWith;
	}
}
  • Events

    • sort : SortEvent : Represent emitting sort condition.