Skip to content

Commit 78bdeb5

Browse files
committed
feat: support auto scrolling when dragging
1 parent bc52e27 commit 78bdeb5

File tree

8 files changed

+365
-59
lines changed

8 files changed

+365
-59
lines changed

package-lock.json

+284-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "angular-draggable-droppable",
3-
"version": "4.2.0",
3+
"version": "4.3.0",
44
"description": "Drag and drop for angular 6.0+",
55
"scripts": {
66
"start": "concurrently --raw \"ng serve --open\" \"npm run test:watch\"",
77
"build:demo": "ng build --prod",
8-
"build:lib": "copyfiles package.json projects/angular-draggable-droppable && ng build angular-draggable-droppable && npm run copyfiles",
8+
"build:lib": "copyfiles package.json projects/angular-draggable-droppable && ng build angular-draggable-droppable && rollup -c rollup.config.js && npm run copyfiles",
99
"build:clean": "rm -rf dist",
1010
"copyfiles": "copyfiles CHANGELOG.md README.md LICENSE dist/angular-draggable-droppable",
1111
"test": "npm run lint && ng test angular-draggable-droppable --watch=false --code-coverage && npm run build:lib && npm run build:clean",
@@ -77,6 +77,10 @@
7777
"ng-packagr": "^4.1.1",
7878
"prettier": "^1.14.2",
7979
"pretty-quick": "^1.6.0",
80+
"rollup": "^1.7.0",
81+
"rollup-plugin-commonjs": "^9.2.1",
82+
"rollup-plugin-node-resolve": "^4.0.1",
83+
"rollup-plugin-terser": "^4.0.4",
8084
"rxjs": "^6.3.2",
8185
"sinon": "^6.3.3",
8286
"sinon-chai": "^3.2.0",
@@ -96,5 +100,8 @@
96100
"commitizen": {
97101
"path": "node_modules/cz-conventional-changelog"
98102
}
103+
},
104+
"dependencies": {
105+
"dom-autoscroller": "^2.3.4"
99106
}
100107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'dom-autoscroller';

projects/angular-draggable-droppable/ng-package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
"dest": "../../dist/angular-draggable-droppable",
44
"lib": {
55
"entryFile": "src/public_api.ts"
6-
}
6+
},
7+
"whitelistedNonPeerDependencies": [
8+
"tslib",
9+
"dom-autoscroller"
10+
]
711
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from 'rxjs/operators';
3131
import { CurrentDragData, DraggableHelper } from './draggable-helper.provider';
3232
import { DOCUMENT } from '@angular/common';
33+
import autoScroll from 'dom-autoscroller';
3334
import { DraggableScrollContainerDirective } from './draggable-scroll-container.directive';
3435

3536
export interface Coordinates {
@@ -207,6 +208,8 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
207208

208209
private timeLongPress: TimeLongPress = { timerBegin: 0, timerEnd: 0 };
209210

211+
private scroller: { destroy: () => void };
212+
210213
/**
211214
* @hidden
212215
*/
@@ -349,6 +352,20 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
349352
this.dragStart.next({ cancelDrag$ });
350353
});
351354

355+
this.scroller = autoScroll(
356+
[
357+
this.scrollContainer
358+
? this.scrollContainer.elementRef.nativeElement
359+
: this.document.defaultView
360+
],
361+
{
362+
margin: 20,
363+
autoScroll() {
364+
return true;
365+
}
366+
}
367+
);
368+
352369
this.renderer.addClass(
353370
this.element.nativeElement,
354371
this.dragActiveClass
@@ -441,6 +458,7 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
441458
})
442459
)
443460
.subscribe(({ x, y, dragCancelled }) => {
461+
this.scroller.destroy();
444462
this.zone.run(() => {
445463
this.dragEnd.next({ x, y, dragCancelled });
446464
});

projects/angular-draggable-droppable/tsconfig.lib.json

+4-9
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
"experimentalDecorators": true,
1313
"importHelpers": true,
1414
"types": [],
15-
"lib": [
16-
"dom",
17-
"es2015"
18-
]
15+
"lib": ["dom", "es2015"],
16+
"noImplicitAny": false
1917
},
2018
"angularCompilerOptions": {
2119
"annotateForClosureCompiler": true,
@@ -25,9 +23,6 @@
2523
"strictInjectionParameters": true,
2624
"enableResourceInlining": true
2725
},
28-
"exclude": [
29-
"src/test.ts",
30-
"src/test-utils.ts",
31-
"**/*.spec.ts"
32-
]
26+
"include": ["custom-typings.d.ts", "src/**/*.ts"],
27+
"exclude": ["src/test.ts", "src/test-utils.ts", "**/*.spec.ts"]
3328
}

rollup.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import resolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import { terser } from 'rollup-plugin-terser';
4+
5+
const input =
6+
'dist/angular-draggable-droppable/bundles/angular-draggable-droppable.umd.js';
7+
8+
// bundle dom-autoscroller lib so it's not a breaking change for systemjs users
9+
const base = {
10+
input,
11+
output: {
12+
file: input,
13+
format: 'umd',
14+
name: 'angular-draggable-droppable',
15+
sourcemap: true,
16+
globals: {
17+
rxjs: 'rxjs',
18+
'rxjs/operators': 'rxjs.operators',
19+
'@angular/core': 'ng.core',
20+
'@angular/common': 'ng.common'
21+
}
22+
},
23+
plugins: [resolve({ module: true }), commonjs()],
24+
external: ['@angular/core', '@angular/common', 'rxjs', 'rxjs/operators']
25+
};
26+
27+
export default [
28+
base,
29+
{
30+
...base,
31+
output: {
32+
...base.output,
33+
file: base.output.file.replace('.js', '.min.js')
34+
},
35+
plugins: [...base.plugins, terser()]
36+
}
37+
];

src/tsconfig.app.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
},
77
"exclude": [
88
"src/test.ts",
9-
"**/*.spec.ts"
9+
"**/*.spec.ts",
10+
"../projects/**/*.spec.ts"
11+
],
12+
"include": [
13+
"**/*.ts",
14+
"../projects/angular-draggable-droppable/custom-typings.d.ts",
15+
"../projects/src/**/*.ts"
1016
]
1117
}

0 commit comments

Comments
 (0)