-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng2-tree): add stylus, webpack-dev-server support
- Loading branch information
Showing
12 changed files
with
145 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
.idea/ | ||
build/ | ||
build/ | ||
typings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,69 @@ | ||
import {Input} from "angular2/core"; | ||
import {Component} from "angular2/core"; | ||
import {Input, Component} from "angular2/core"; | ||
import {CORE_DIRECTIVES} from "angular2/common"; | ||
|
||
@Component({ | ||
selector: 'ng2-tree', | ||
template: ` | ||
selector: 'ng2-tree', | ||
template: ` | ||
<ul class="tree"> | ||
<li> | ||
<span class="folding" (click)="switchFolding($event, tree)" [ngClass]="foldingType(tree)"></span><span class="node-value">{{tree.value}}</span> | ||
<span class="folding" (click)="switchFolding($event, tree)" [ngClass]="foldingType(tree)"></span> | ||
<span class="node-value">{{tree.value}}</span> | ||
<ng2-tree *ngFor="#child of tree.children" [tree]="child"></ng2-tree> | ||
</li> | ||
</ul> | ||
`, | ||
directives: [Ng2Tree, CORE_DIRECTIVES] | ||
`, | ||
directives: [Ng2Tree, CORE_DIRECTIVES] | ||
}) | ||
export class Ng2Tree { | ||
@Input() | ||
private tree:any; | ||
private static COMPONENT_TAG_NAME: string = 'NG2-TREE'; | ||
private static FOLDING_NODE_EXPANDED: string = 'node-expanded'; | ||
private static FOLDING_NODE_COLLAPSED: string = 'node-collapsed'; | ||
private static FOLDING_NODE_LEAF: string = 'node-leaf'; | ||
|
||
private switchFolding($event: any, tree: any): void { | ||
this.handleFoldingType($event.target.parentNode, tree); | ||
} | ||
|
||
private foldingType(node: any): any { | ||
if (node.foldingType) { | ||
return node.foldingType; | ||
} | ||
@Input() | ||
private tree: any; | ||
|
||
if (node.children) { | ||
node.foldingType = 'node-expanded'; | ||
return 'node-expanded'; | ||
private switchFolding($event: any, tree: any): void { | ||
this.handleFoldingType($event.target.parentNode, tree); | ||
} | ||
|
||
node.foldingType = 'leaf'; | ||
return 'leaf'; | ||
} | ||
private foldingType(node: any): any { | ||
if (node.foldingType) { | ||
return node.foldingType; | ||
} | ||
|
||
if (node.children) { | ||
node.foldingType = Ng2Tree.FOLDING_NODE_EXPANDED; | ||
} else { | ||
node.foldingType = Ng2Tree.FOLDING_NODE_LEAF; | ||
} | ||
|
||
private nextFoldingType(node: any): string { | ||
if (node.foldingType === 'node-expanded') { | ||
return 'node-collapsed'; | ||
return node.foldingType; | ||
} | ||
|
||
return 'node-expanded'; | ||
} | ||
private nextFoldingType(node: any): string { | ||
if (node.foldingType === Ng2Tree.FOLDING_NODE_EXPANDED) { | ||
return Ng2Tree.FOLDING_NODE_COLLAPSED; | ||
} | ||
|
||
private handleFoldingType(parent: any, node: any) { | ||
if (node.foldingType === 'leaf') { | ||
return; | ||
} | ||
|
||
let display = 'block'; | ||
if (node.foldingType === 'node-expanded') { | ||
display = 'none'; | ||
return Ng2Tree.FOLDING_NODE_EXPANDED; | ||
} | ||
|
||
node.foldingType = this.nextFoldingType(node); | ||
for (let element of parent.childNodes) { | ||
if (element.nodeName === 'NG2-TREE') { | ||
element.style.display = display; | ||
} | ||
private handleFoldingType(parent: any, node: any) { | ||
if (node.foldingType === Ng2Tree.FOLDING_NODE_LEAF) { | ||
return; | ||
} | ||
|
||
let display = 'block'; | ||
if (node.foldingType === Ng2Tree.FOLDING_NODE_EXPANDED) { | ||
display = 'none'; | ||
} | ||
|
||
node.foldingType = this.nextFoldingType(node); | ||
for (let element of parent.childNodes) { | ||
if (element.nodeName === Ng2Tree.COMPONENT_TAG_NAME) { | ||
element.style.display = display; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
folding-color = orange | ||
node-value-color = green |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<app>Loading...</app> | ||
|
||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@import colors | ||
|
||
node-expanded-symbol = '[-]' | ||
node-collapsed-symbol = '[+]' | ||
leaf-node-symbol = '\25cf' //black circle | ||
|
||
.tree | ||
font-family: monospace | ||
|
||
li | ||
padding: 3px 0 | ||
list-style: none | ||
|
||
.folding | ||
cursor: pointer | ||
padding: 0 5px 0 5px | ||
font-weight: bold | ||
color: folding-color | ||
|
||
&.node-expanded | ||
&:after | ||
content: node-expanded-symbol | ||
|
||
&.node-collapsed | ||
&:after | ||
content: node-collapsed-symbol | ||
|
||
|
||
&.node-leaf | ||
cursor: default | ||
|
||
&:after | ||
content: leaf-node-symbol | ||
|
||
.node-value | ||
font-weight: bold | ||
color: node-value-color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"ambientDependencies": { | ||
"require": "registry:dt/require#2.1.20+20160316155526", | ||
"source-map": "registry:dt/source-map#0.0.0+20160317120654", | ||
"uglify-js": "registry:dt/uglify-js#2.6.1+20160316155526", | ||
"webpack": "registry:dt/webpack#1.12.9+20160321060707" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters