Skip to content

Commit 3dfdaaf

Browse files
author
Xie, Ziyu
committed
Pre-release v2.0.0-beta.0
New directive: ngResizable
1 parent 050e3f7 commit 3dfdaaf

28 files changed

+765
-182
lines changed

README.md

Lines changed: 77 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ Angular directive (for version >= 4.x ) that makes the DOM element draggable.
1010

1111
## Table of contents
1212
1. [Getting Started](#getting-started)
13+
2. [Latest Update](#latest-update)
1314
3. [Installation](#installation)
14-
4. [Usage](#usage)
15+
4. [Draggable](#draggable)
16+
4. [Resizable](#resizable)
1517
5. [API](#api)
1618
6. [Events](#events)
1719

1820
# Getting Started
19-
angular2-draggable is an angular (ver >= 4.x) directive that makes the DOM element draggable. (Note that: It's different from drag-and-drop)
21+
angular2-draggable has angular (ver >= 4.x) directives that make the DOM element draggable and resizable.
22+
+ `ngDraggable`
23+
+ `ngResizable`
2024

2125
# Latest Update
26+
+ 2018.06.25: 2.0.0-beta.0
27+
+ New: `ngResizable` directive which you can use to make the element resizable! More resizable options are planning. Refer to [demo](https://xieziyu.github.io/angular2-draggable/#/resizable/default)
28+
2229
+ 2018.05.23: 1.4.2
2330
+ Changes: expose boundsCheck() method.
2431

@@ -55,50 +62,12 @@ angular2-draggable is an angular (ver >= 4.x) directive that makes the DOM eleme
5562
+ Provide `[scale]` option: to fix scaling issue [#31](https://github.com/xieziyu/angular2-draggable/issues/31)
5663
+ Provide `[preventDefaultEvent]` option: whether to prevent default mouse or touch event. (default: true)
5764

58-
+ 2017.12.20: 1.1.0-beta.0
59-
60-
+ Provide `[zIndex]` and `[zIndexMoving]` to control z-index property.
61-
+ Provide `[bounds]`, `(edge)` and `[inBounds]` to do boundary check and limit element staying in the bounds.
62-
+ Update [demo](https://xieziyu.github.io/angular2-draggable) page.
63-
64-
65-
+ 2017.09.19: Fix an issue when dragging with touch.
66-
67-
+ 2017.08.26: Fix an issue: clicking before dragging leading to unexpected offset ([PR #12](https://github.com/xieziyu/angular2-draggable/pull/12) by [bmartinson13](https://github.com/bmartinson13))
68-
69-
+ 2017.07.24: Fix cross-browser compatibility issues.
70-
71-
+ 2017.07.05: Publish `UMD` bundle
72-
7365
# Installation
7466
```
7567
npm install angular2-draggable --save
7668
```
7769

78-
# How to use it with:
79-
+ `SystemJS`: For example: angular `quickstart`. You need to modify `systemjs.config.js` file just like:
80-
81-
```javascript
82-
{
83-
map: {
84-
// ...
85-
86-
// angular2-draggable
87-
'angular2-draggable': 'npm:angular2-draggable',
88-
},
89-
packages: {
90-
// other packages ...
91-
92-
//angular2-draggable
93-
'angular2-draggable': {
94-
defaultExtension: 'js',
95-
main: 'bundles/angular2-draggable.umd.min.js'
96-
}
97-
}
98-
}
99-
```
100-
101-
# Usage
70+
# Draggable
10271
Please refer to the [demo](https://xieziyu.github.io/angular2-draggable) page.
10372

10473
1. Firstly, import `AngularDraggableModule` in your app module (or any other proper angular module):
@@ -133,55 +102,90 @@ Please refer to the [demo](https://xieziyu.github.io/angular2-draggable) page.
133102
</div>
134103
```
135104

105+
# Resizable
106+
Please refer to the [demo](https://xieziyu.github.io/angular2-draggable/#/resizable/default) page.
107+
108+
Besides of importing `AngularDraggableModule`, you need to import `resizable.min.css` in your project. If you use `angular-cli`, you can add this in `angular.json`:
109+
110+
```diff
111+
"styles": [
112+
...
113+
+ "node_modules/angular2-draggable/css/resizable.min.css"
114+
]
115+
```
116+
117+
Then you can use `ngResizable` directive to make the element resizable:
118+
```html
119+
<div ngResizable> I'm now resizable </div>
120+
121+
<div [ngResizable]="false"> Resizable is disabled now </div>
122+
123+
<div ngResizable [rzHandles]="'n,e,s,w,se,sw,ne,nw'"> Each side is resizable </div>
124+
```
125+
126+
Well you can use both directives concurrently if you wish:
127+
```html
128+
<div ngDraggable ngResizable> I'm now draggable and resizable </div>
129+
```
130+
136131
# API
137132

138133
## Directive:
139-
`ngDraggable` directive support following input porperties:
140-
+ `ngDraggable`: boolean. You can toggle the draggable capability by setting `true`/`false` to `ngDraggable`
134+
+ `ngDraggable` directive support following input porperties:
135+
+ `ngDraggable`: boolean. You can toggle the draggable capability by setting `true`/`false` to `ngDraggable`
136+
137+
+ `handle`: HTMLElement. Use template variable to refer to the handle element. Then only the handle element is draggable.
141138

142-
+ `handle`: HTMLElement. Use template variable to refer to the handle element. Then only the handle element is draggable.
139+
+ `zIndex`: string. Use it to set z-index property when element is not moving.
143140

144-
+ `zIndex`: string. Use it to set z-index property when element is not moving.
141+
+ `zIndexMoving`: string. Use it to set z-index property when element is moving.
145142

146-
+ `zIndexMoving`: string. Use it to set z-index property when element is moving.
143+
+ `bounds`: HTMLElemnt. Use it to set the boundary.
147144

148-
+ `bounds`: HTMLElemnt. Use it to set the boundary.
145+
+ `inBounds`: boolean, default is `false`. Use it make element stay in the bounds.
149146

150-
+ `inBounds`: boolean, default is `false`. Use it make element stay in the bounds.
147+
+ `outOfBounds`: { top: boolean; bottom: boolean; right: boolean; left: boolean }, default are `false`. Set it to allow element get out of bounds from the direction. Refer to [demo](https://xieziyu.github.io/angular2-draggable/#/usage/boundary)
151148

152-
+ `outOfBounds`: { top: boolean; bottom: boolean; right: boolean; left: boolean }, default are `false`. Set it to allow element get out of bounds from the direction. Refer to [demo](https://xieziyu.github.io/angular2-draggable/#/usage/boundary)
149+
+ `position`: IPosition: `{ x: number, y: number }`, default is `{ x:0, y:0 }`. Use it to set initial position offset.
153150

154-
+ `position`: IPosition: `{ x: number, y: number }`, default is `{ x:0, y:0 }`. Use it to set initial position offset.
151+
+ `gridSize`: number, default is `1`. Use it for snapping to grid. Refer to [demo](https://xieziyu.github.io/angular2-draggable/#/advance/snap-grid).
155152

156-
+ `gridSize`: number, default is `1`. Use it for snapping to grid. Refer to [demo](https://xieziyu.github.io/angular2-draggable/#/advance/snap-grid).
153+
+ `ngResizable` directive support following input porperties:
154+
+ `ngResizable`: boolean. You can disable the resizable capability by setting it to `false`.
155+
156+
+ `rzHandles`: Default is `"e,s,se"`. Which handles can be used for resizing. Optional types: `"n,e,s,w,se,sw,ne,nw"`.
157157

158158
## CSS:
159-
When `ngDraggable` is enabled on some element, `ng-draggable` class is automatically assigned to it. You can use it to customize the pointer style. For example:
159+
+ When `ngDraggable` is enabled on some element, `ng-draggable` class is automatically assigned to it. You can use it to customize the pointer style. For example:
160160

161-
```css
162-
.ng-draggable {
163-
cursor: move;
164-
}
165-
```
161+
```css
162+
.ng-draggable {
163+
cursor: move;
164+
}
165+
```
166+
167+
+ When `ngResizable` is enabled on some element, `ng-resizable` class is automatically assigned to it. And handle elements will be created with `ng-resizable-handle`. You can customize the handle style.
166168
167169
# Events
170+
+ `ngDraggable` directive:
171+
1. Support `started` and `stopped` events. The `nativeElement` of the host would be emitted.
172+
2. Support `edge` events only when `[bounds]` is set. It would emit the result of the boundary check.
173+
3. `(movingOffset)` event emitter: emit position offset when moving
174+
4. `(endOffset)` event emitter: emit position offset when stop moving
175+
176+
+ Simple example:
177+
+ html:
178+
```html
179+
<div ngDraggable
180+
(started)="onDragBegin($event)"
181+
(stopped)="onDragEnd($event)"
182+
(movingOffset)="onMoving($event)"
183+
(endOffset)="onMoveEnd($event)">
184+
Drag me!
185+
</div>
186+
```
168187
169-
1. Support `started` and `stopped` events. The `nativeElement` of the host would be emitted.
170-
2. Support `edge` events only when `[bounds]` is set. It would emit the result of the boundary check.
171-
3. `(movingOffset)` event emitter: emit position offset when moving
172-
4. `(endOffset)` event emitter: emit position offset when stop moving
173-
174-
+ Simple example:
175-
+ html:
176-
```html
177-
<div ngDraggable
178-
(started)="onDragBegin($event)"
179-
(stopped)="onDragEnd($event)"
180-
(movingOffset)="onMoving($event)"
181-
(endOffset)="onMoveEnd($event)">
182-
Drag me!
183-
</div>
184-
```
188+
+ `ngResizable` directive: on-going
185189
186190
# Demo
187191
You can clone this repo to your working copy and then launch the demo page in your local machine:

angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"styles": [
3030
"src/scss/styles.scss",
3131
"src/prism-darcula.css",
32-
"node_modules/font-awesome/css/font-awesome.css"
32+
"node_modules/font-awesome/css/font-awesome.css",
33+
"dist/angular2-draggable/css/resizable.min.css"
3334
],
3435
"scripts": [
3536
"node_modules/marked/lib/marked.js",

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"lint": "ng lint",
1010
"e2e": "ng e2e",
1111
"build:lib": "ng build angular2-draggable",
12+
"build:css": "node scripts/build-scss.js",
1213
"build:prod": "ng build angular2-draggable --prod",
1314
"update:md": "cpr README.md dist/angular2-draggable/README.md -o",
14-
"dist": "run-s build:prod update:md",
15-
"release": "run-s build:prod update:md build:doc",
16-
"demo": "run-s build:lib start",
15+
"dist": "run-s build:prod build:css update:md",
16+
"release": "run-s build:prod build:css update:md build:doc",
17+
"demo": "run-s build:lib build:css start",
1718
"build:doc": "run-s build compodoc",
1819
"compodoc": "compodoc -p projects/angular2-draggable/tsconfig.lib.json -d dist/docs/api-doc --theme stripe",
1920
"serve:doc": "compodoc -p projects/angular2-draggable/tsconfig.lib.json -s"

projects/angular2-draggable/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-draggable",
3-
"version": "0.0.1",
3+
"version": "2.0.0-beta.0",
44
"peerDependencies": {
55
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
66
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"

projects/angular2-draggable/src/lib/angular-draggable.directive.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,7 @@ import {
44
EventEmitter, OnChanges, SimpleChanges
55
} from '@angular/core';
66

7-
export interface IPosition {
8-
x: number;
9-
y: number;
10-
}
11-
12-
class Position implements IPosition {
13-
constructor(public x: number, public y: number) { }
14-
15-
static fromEvent(e: MouseEvent | TouchEvent) {
16-
if (e instanceof MouseEvent) {
17-
return new Position(e.clientX, e.clientY);
18-
} else {
19-
return new Position(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
20-
}
21-
}
22-
23-
static isIPosition(obj): obj is IPosition {
24-
return !!obj && ('x' in obj) && ('y' in obj);
25-
}
26-
27-
add(p: IPosition) {
28-
this.x += p.x;
29-
this.y += p.y;
30-
return this;
31-
}
32-
33-
subtract(p: IPosition) {
34-
this.x -= p.x;
35-
this.y -= p.y;
36-
return this;
37-
}
38-
39-
reset() {
40-
this.x = 0;
41-
this.y = 0;
42-
return this;
43-
}
44-
45-
set(p: IPosition) {
46-
this.x = p.x;
47-
this.y = p.y;
48-
return this;
49-
}
50-
}
7+
import { IPosition, Position } from './models/position';
518

529
@Directive({
5310
selector: '[ngDraggable]',
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { NgModule } from '@angular/core';
22
import { AngularDraggableDirective } from './angular-draggable.directive';
3+
import { AngularResizableDirective } from './angular-resizable.directive';
34

45
@NgModule({
56
imports: [
67
],
78
declarations: [
8-
AngularDraggableDirective
9+
AngularDraggableDirective,
10+
AngularResizableDirective
911
],
1012
exports: [
11-
AngularDraggableDirective
13+
AngularDraggableDirective,
14+
AngularResizableDirective
1215
]
1316
})
1417
export class AngularDraggableModule { }

0 commit comments

Comments
 (0)