Skip to content

Commit 12b0c66

Browse files
committed
go v0.1.4
1 parent 9a8cdb8 commit 12b0c66

File tree

4 files changed

+32
-74
lines changed

4 files changed

+32
-74
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"name": "angular-split",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Angular (2+) UI library to split views.",
55
"main": "dist/index.js",
66
"typings": "src/index.ts",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"lint": "tslint --force \"src/**/*.ts\"",
10-
"build": "rimraf dist && tsc --outDir dist",
11-
"build.aot": "rimraf dist && ngc -p tsconfig.aot.json"
10+
"build": "rimraf dist && tsc"
1211
},
1312
"repository": {
1413
"type": "git",

src/split.component.ts

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Component, ChangeDetectorRef, Input, Output, HostBinding, ElementRef,
2-
ChangeDetectionStrategy, EventEmitter, Renderer, OnDestroy } from '@angular/core';
1+
import { Component, ChangeDetectorRef, Input, Output, HostBinding, ElementRef, SimpleChanges,
2+
ChangeDetectionStrategy, EventEmitter, Renderer, OnDestroy, OnChanges } from '@angular/core';
33

44
import { SplitAreaDirective } from './splitArea.directive';
55

@@ -27,23 +27,13 @@ interface Point {
2727
display: flex;
2828
flex-wrap: nowrap;
2929
justify-content: flex-start;
30-
background: red;
31-
}
32-
33-
/deep/ split-area {
34-
flex-grow: 0;
35-
flex-shrink: 0;
36-
overflow-x: hidden;
37-
overflow-y: auto;
38-
background: blue;
39-
height: /*100px;*/100%;
4030
}
4131
4232
split-gutter {
4333
flex-grow: 0;
4434
flex-shrink: 0;
4535
flex-basis: 10px;
46-
height: /*100px;*/100%;
36+
height: 100%;
4737
background-color: #eeeeee;
4838
background-position: 50%;
4939
background-repeat: no-repeat;
@@ -53,30 +43,20 @@ interface Point {
5343
<ng-content></ng-content>
5444
<template ngFor let-area [ngForOf]="areas" let-index="index" let-last="last">
5545
<split-gutter *ngIf="last === false"
56-
[order]="index*2+1"
57-
[direction]="direction"
58-
[size]="_gutterSize"
59-
[disabled]="_disabled"
60-
(mousedown)="startDragging($event, index*2+1)"
61-
(touchstart)="startDragging($event, index*2+1)"></split-gutter>
46+
[order]="index*2+1"
47+
[direction]="direction"
48+
[size]="_gutterSize"
49+
[disabled]="_disabled"
50+
(mousedown)="startDragging($event, index*2+1)"
51+
(touchstart)="startDragging($event, index*2+1)"></split-gutter>
6252
</template>`,
6353
})
64-
export class SplitComponent implements OnDestroy {
54+
export class SplitComponent implements OnChanges, OnDestroy {
6555
@Input() direction: string = 'horizontal';
6656
@Input() width: number;
6757
@Input() height: number;
68-
69-
_gutterSize: number = 10;
70-
@Input() set gutterSize(v: number) {
71-
this._gutterSize = v;
72-
this.refresh();
73-
}
74-
75-
_disabled: boolean = false;
76-
@Input() set disabled(v: boolean) {
77-
this._disabled = v;
78-
this.refresh();
79-
}
58+
@Input() gutterSize: number = 10;
59+
@Input() disabled: boolean = false;
8060

8161
@Output() dragStart = new EventEmitter<Array<number>>(false);
8262
@Output() dragProgress = new EventEmitter<Array<number>>(false);
@@ -112,6 +92,12 @@ export class SplitComponent implements OnDestroy {
11292
private elementRef: ElementRef,
11393
private renderer: Renderer) {}
11494

95+
public ngOnChanges(changes: SimpleChanges) {
96+
if(changes['gutterSize'] || changes['disabled']) {
97+
this.refresh();
98+
}
99+
}
100+
115101
public addArea(component: SplitAreaDirective, orderUser: number | null, sizeUser: number | null, minPixel: number) {
116102
this.areas.push({
117103
component,
@@ -150,13 +136,9 @@ export class SplitComponent implements OnDestroy {
150136
private refresh() {
151137
this.stopDragging();
152138

153-
// ORDERS
154-
155-
// soit toutes les areas ont une prop order et on les utilise, soit on utilise uniquement leur position
139+
// ORDERS: set css 'order' property depending on user input or added order
156140
const nbCorrectOrder = this.areas.filter(a => !isNaN(a.orderUser)).length;
157-
158141
if(nbCorrectOrder === this.areas.length) {
159-
// on sort le tableau par rapport aux prop orderUser
160142
this.areas.sort((a, b) => +a.orderUser - +b.orderUser);
161143
}
162144

@@ -165,7 +147,7 @@ export class SplitComponent implements OnDestroy {
165147
a.component.setStyle('order', a.order);
166148
});
167149

168-
// SIZES
150+
// SIZES: set css 'flex-basis' property depending on user input or equal sizes
169151
const totalSize = this.areas.map(a => a.sizeUser).reduce((acc, s) => acc + s, 0);
170152
const nbCorrectSize = this.areas.filter(a => !isNaN(a.sizeUser) && a.sizeUser >= this.minPercent).length;
171153

@@ -181,14 +163,14 @@ export class SplitComponent implements OnDestroy {
181163
}
182164

183165
private refreshStyleSizes() {
184-
const f = this._gutterSize * this.nbGutters / this.areas.length;
166+
const f = this.gutterSize * this.nbGutters / this.areas.length;
185167
this.areas.forEach(a => a.component.setStyle('flex-basis', `calc( ${ a.size }% - ${ f }px )`));
186168
}
187169

188170
public startDragging(startEvent: MouseEvent, gutterOrder: number) {
189171
startEvent.preventDefault();
190172

191-
if(this._disabled) {
173+
if(this.disabled) {
192174
return;
193175
}
194176

src/splitArea.directive.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { Directive, Input, ElementRef, Renderer, OnInit, OnDestroy } from '@angu
33
import { SplitComponent } from './split.component';
44

55
@Directive({
6-
selector: 'split-area'
6+
selector: 'split-area',
7+
host: {
8+
'flex-grow': '0',
9+
'flex-shrink': '0',
10+
'overflow-x': 'hidden',
11+
'overflow-y': 'auto',
12+
'height': '100%'
13+
}
714
})
815
export class SplitAreaDirective implements OnInit, OnDestroy {
916

tsconfig.aot.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)