-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathswing-stack-component.ts
78 lines (66 loc) · 2.73 KB
/
swing-stack-component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
declare var require: any;
import {Component, Input, ContentChildren, QueryList,
AfterContentInit, EventEmitter } from '@angular/core';
import { Direction, ThrowEvent, DragEvent, Stack, Card, StackConfig } from './swing';
import {SwingCardComponent} from './swing-card-component';
const Swing = require('swing');
@Component({
selector: '[swing-stack]',
template: `
<ng-content></ng-content>
`,
outputs: [
'throwout',
'throwoutend',
'throwoutleft',
'throwoutright',
'throwoutup',
'throwoutdown',
'throwin',
'throwinend',
'dragstart',
'dragmove',
'dragend',
]
})
export class SwingStackComponent implements AfterContentInit {
@Input() stackConfig: StackConfig;
throwout: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwoutend: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwoutleft: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwoutright: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwoutup: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwoutdown: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwin: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
throwinend: EventEmitter<ThrowEvent> = new EventEmitter<ThrowEvent>();
dragstart: EventEmitter<DragEvent> = new EventEmitter<DragEvent>();
dragmove: EventEmitter<DragEvent> = new EventEmitter<DragEvent>();
dragend: EventEmitter<DragEvent> = new EventEmitter<DragEvent>();
cards: SwingCardComponent[];
stack: Stack;
constructor() {
this.cards = [];
}
addCard(card: SwingCardComponent, prepend: boolean = false) {
this.cards.push(card);
if (this.stack) {
this.stack.createCard(card.getNativeElement(), prepend);
}
}
ngAfterContentInit() {
this.stack = Swing.Stack(this.stackConfig || {});
this.cards.forEach((c) => this.stack.createCard(c.getNativeElement(), c.prepend));
// Hook various events
this.stack.on('throwout', $event => this.throwout.emit($event));
this.stack.on('throwoutend', $event => this.throwoutend.emit($event));
this.stack.on('throwoutleft', $event => this.throwoutleft.emit($event));
this.stack.on('throwoutright', $event => this.throwoutright.emit($event));
this.stack.on('throwin', $event => this.throwin.emit($event));
this.stack.on('throwinend', $event => this.throwinend.emit($event));
this.stack.on('dragstart', $event => this.dragstart.emit($event));
this.stack.on('dragmove', $event => this.dragmove.emit($event));
this.stack.on('dragend', $event => this.dragend.emit($event));
this.stack.on('throwoutup', $event => this.throwoutup.emit($event));
this.stack.on('throwoutdown', $event => this.throwoutdown.emit($event));
}
}