├── .editorconfig ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── angular.json ├── assets └── readme-gif.gif ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── ng-package.json ├── package-lock.json ├── package.json ├── public_api.ts ├── src ├── app │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.ts │ ├── app.module.ts │ └── treetable │ │ ├── component │ │ ├── treetable.component.html │ │ ├── treetable.component.scss │ │ ├── treetable.component.spec.ts │ │ └── treetable.component.ts │ │ ├── decorators │ │ ├── required.decorator.spec.ts │ │ └── required.decorator.ts │ │ ├── default.options.ts │ │ ├── mocks │ │ ├── mockSearchableTree.ts │ │ ├── mockTree.ts │ │ ├── mockTreeAsArrayOfNodes.ts │ │ ├── mockTreeTableTree.ts │ │ └── models.ts │ │ ├── models.ts │ │ ├── services │ │ ├── converter │ │ │ ├── converter.service.spec.ts │ │ │ └── converter.service.ts │ │ ├── tree │ │ │ ├── tree.service.spec.ts │ │ │ └── tree.service.ts │ │ └── validator │ │ │ ├── validator.service.spec.ts │ │ │ └── validator.service.ts │ │ └── treetable.module.ts ├── assets │ └── .gitkeep ├── browserslist ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── styles.scss ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8.10.0" 4 | 5 | services: 6 | - xvfb 7 | 8 | script: 9 | - ng lint 10 | - ng build --prod 11 | - ng test --watch=false 12 | 13 | before_install: 14 | - export CHROME_BIN=chromium-browser 15 | - export DISPLAY=:99.0 16 | 17 | before_script: npm rebuild node-sass; 18 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at marco.levrero@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ɯλrv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular Material TreeTable Component 2 | 3 | [![Build Status](https://travis-ci.com/mlrv/ng-material-treetable.svg?branch=master)](https://travis-ci.com/mlrv/ng-material-tree-table) 4 | [![Licence](https://img.shields.io/npm/l/ng-dynamic-component.svg?maxAge=2592000)](https://github.com/mlrv/ng-material-treetable/LICENSE) 5 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) 6 | [![Npm](https://img.shields.io/npm/v/ng-material-treetable.svg?maxAge=2592000)](https://badge.fury.io/js/ng-material-treetable) 7 | 8 | 9 | A simple, customisable, and easy to use Angular Material TreeTable component. 10 | 11 | ![Gif Demo](assets/readme-gif.gif) 12 | 13 | [Live Demo](http://ng-material-treetable.surge.sh/) 14 | 15 | [StackBlitz Demo](https://stackblitz.com/edit/angular-qnlruj) 16 | 17 | --- 18 | 19 | ## Table of Contents 20 | 21 | 1. [Installation](#installation) 22 | 1. [Data Format](#data-format) 23 | 1. [Options](#options) 24 | 1. [Events](#events) 25 | 26 | ## Installation 27 | 28 | Simply install the package through `npm` 29 | 30 | ``` 31 | npm i ng-material-treetable --save 32 | ``` 33 | 34 | Make sure you have the angular material packages installed 35 | 36 | ``` 37 | npm i @angular/material @angular/cdk @angular/animations --save 38 | ``` 39 | 40 | import the main module 41 | 42 | ```typescript 43 | import { TreetableModule } from 'ng-material-treetable'; 44 | 45 | @NgModule({ 46 | ... 47 | imports: [ 48 | ... 49 | TreetableModule 50 | ], 51 | ... 52 | }) 53 | export class AppModule { } 54 | ``` 55 | 56 | and use the component in your template 57 | 58 | ```html 59 | 60 | ``` 61 | 62 | Finally, make sure you import the required material icons font in your `styles.css` 63 | 64 | ```css 65 | @import url('https://fonts.googleapis.com/css?family=Roboto:400,700|Material+Icons'); 66 | ``` 67 | 68 | ## Data Format 69 | 70 | The tree object that's rendered by the component can either be a `Node` or a `Node[]` where `Node` is the following interface 71 | 72 | ```typescript 73 | import { Node } from 'ng-material-treetable'; 74 | 75 | interface Node { 76 | value: T; 77 | children: Node[]; 78 | } 79 | ``` 80 | 81 | Here's a simple example. 82 | 83 | 84 | ```javascript 85 | { 86 | value: { 87 | name: 'Reports', 88 | owner: 'Eric', 89 | protected: true, 90 | backup: true 91 | }, 92 | children: [ 93 | { 94 | value: { 95 | name: 'Charts', 96 | owner: 'Stephanie', 97 | protected: false, 98 | backup: true 99 | }, 100 | children: [] 101 | }, 102 | { 103 | value: { 104 | name: 'Sales', 105 | owner: 'Virginia', 106 | protected: false, 107 | backup: true 108 | }, 109 | children: [] 110 | }, 111 | { 112 | value: { 113 | name: 'US', 114 | owner: 'Alison', 115 | protected: true, 116 | backup: false 117 | }, 118 | children: [ 119 | { 120 | value: { 121 | name: 'California', 122 | owner: 'Claire', 123 | protected: false, 124 | backup: false 125 | }, 126 | children: [] 127 | }, 128 | { 129 | value: { 130 | name: 'Washington', 131 | owner: 'Colin', 132 | protected: false, 133 | backup: true 134 | }, 135 | children: [ 136 | { 137 | value: { 138 | name: 'Domestic', 139 | owner: 'Oliver', 140 | protected: true, 141 | backup: false 142 | }, 143 | children: [] 144 | }, 145 | { 146 | value: { 147 | name: 'International', 148 | owner: 'Oliver', 149 | protected: true, 150 | backup: true 151 | }, 152 | children: [] 153 | } 154 | ] 155 | } 156 | ] 157 | } 158 | ] 159 | } 160 | ``` 161 | 162 | ## Options 163 | 164 | > Work in Progress... 165 | 166 | An `option` input property can be used to customise the component 167 | 168 | ```typescript 169 | import { Node, Options } from 'ng-material-treetable'; 170 | ``` 171 | 172 | --- 173 | 174 | ```html 175 | 178 | 179 | ``` 180 | 181 | | Name | Description | Type | Default | 182 | |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|---------| 183 | | `verticalSeparator` | If `true`, separates table columns with vertical lines. | `boolean` | `true` | 184 | | `capitalisedHeader` | If `true`, capitalise the first letter of each column header. | `boolean` | - | 185 | | `highlightRowOnHover` | If `true`, hovering the mouse over a row highlights its background. | `boolean` | `true` | 186 | | `customColumnOrder` | By default, the columns are ordered following the array generated by calling `Object.keys()` on the nodes of the tree object; this option can be used to specify a custom order. Note that `customColumnOrder` needs to be an array containing all the keys present in the node object. | `Array` | - | 187 | | `elevation` | Sets the elevation of the card element wrapping the tree component. | `number` | `5` | 188 | 189 | ### customColumnOrder 190 | 191 | Given a tree data type like 192 | 193 | ```typescript 194 | interface Person { 195 | name: string; 196 | age: number; 197 | married: boolean; 198 | } 199 | 200 | const tree: Node = ... 201 | ``` 202 | 203 | a custom column order can be specified with the following `options` object 204 | 205 | ```typescript 206 | const opts: Options = { 207 | customColumnOrder: ['married', 'age', 'name'] 208 | } 209 | ``` 210 | 211 | an incomplete or incorrect `customColumnOrder` value will result in an error 212 | 213 | ```typescript 214 | customColumnOrder: ['married', 'age'] // 'name' missing 215 | customColumnOrder: ['married', 'age', 'name', 'surname'] // 'surname' is not a valid key 216 | ``` 217 | 218 | ## Events 219 | 220 | > Work in Progress... 221 | 222 | | Name | Description | Type | 223 | |---------------|------------------------------------------------------------------------------------------|-----------| 224 | | `nodeClicked` | Whenever a node is expanded or collapsed, emits an event with the new status of the node | `Node` | 225 | 226 | ### nodeClicked 227 | 228 | ```html 229 | 232 | 233 | ``` 234 | 235 | --- 236 | 237 | ```typescript 238 | logToggledNode(node: Node): void { 239 | console.log(node); 240 | } 241 | ``` 242 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "tree-table": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": { 12 | "@schematics/angular:component": { 13 | "styleext": "scss" 14 | } 15 | }, 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/tree-table", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "src/tsconfig.app.json", 25 | "assets": [ 26 | "src/favicon.ico", 27 | "src/assets" 28 | ], 29 | "styles": [ 30 | "src/styles.scss" 31 | ], 32 | "scripts": [ 33 | { 34 | "input": "node_modules/document-register-element/build/document-register-element.js" 35 | } 36 | ] 37 | }, 38 | "configurations": { 39 | "production": { 40 | "fileReplacements": [ 41 | { 42 | "replace": "src/environments/environment.ts", 43 | "with": "src/environments/environment.prod.ts" 44 | } 45 | ], 46 | "optimization": true, 47 | "outputHashing": "all", 48 | "sourceMap": false, 49 | "extractCss": true, 50 | "namedChunks": false, 51 | "aot": true, 52 | "extractLicenses": true, 53 | "vendorChunk": false, 54 | "buildOptimizer": true, 55 | "budgets": [ 56 | { 57 | "type": "initial", 58 | "maximumWarning": "2mb", 59 | "maximumError": "5mb" 60 | } 61 | ] 62 | } 63 | } 64 | }, 65 | "serve": { 66 | "builder": "@angular-devkit/build-angular:dev-server", 67 | "options": { 68 | "browserTarget": "tree-table:build" 69 | }, 70 | "configurations": { 71 | "production": { 72 | "browserTarget": "tree-table:build:production" 73 | } 74 | } 75 | }, 76 | "extract-i18n": { 77 | "builder": "@angular-devkit/build-angular:extract-i18n", 78 | "options": { 79 | "browserTarget": "tree-table:build" 80 | } 81 | }, 82 | "test": { 83 | "builder": "@angular-devkit/build-angular:karma", 84 | "options": { 85 | "main": "src/test.ts", 86 | "polyfills": "src/polyfills.ts", 87 | "tsConfig": "src/tsconfig.spec.json", 88 | "karmaConfig": "src/karma.conf.js", 89 | "styles": [ 90 | "src/styles.scss" 91 | ], 92 | "scripts": [], 93 | "assets": [ 94 | "src/favicon.ico", 95 | "src/assets" 96 | ] 97 | } 98 | }, 99 | "lint": { 100 | "builder": "@angular-devkit/build-angular:tslint", 101 | "options": { 102 | "tsConfig": [ 103 | "src/tsconfig.app.json", 104 | "src/tsconfig.spec.json" 105 | ], 106 | "exclude": [ 107 | "**/node_modules/**" 108 | ] 109 | } 110 | } 111 | } 112 | }, 113 | "tree-table-e2e": { 114 | "root": "e2e/", 115 | "projectType": "application", 116 | "prefix": "", 117 | "architect": { 118 | "e2e": { 119 | "builder": "@angular-devkit/build-angular:protractor", 120 | "options": { 121 | "protractorConfig": "e2e/protractor.conf.js", 122 | "devServerTarget": "tree-table:serve" 123 | }, 124 | "configurations": { 125 | "production": { 126 | "devServerTarget": "tree-table:serve:production" 127 | } 128 | } 129 | }, 130 | "lint": { 131 | "builder": "@angular-devkit/build-angular:tslint", 132 | "options": { 133 | "tsConfig": "e2e/tsconfig.e2e.json", 134 | "exclude": [ 135 | "**/node_modules/**" 136 | ] 137 | } 138 | } 139 | } 140 | } 141 | }, 142 | "defaultProject": "tree-table" 143 | } -------------------------------------------------------------------------------- /assets/readme-gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlrv/ng-material-treetable/2b58ceee7ee91dccaf06eced9d972290e2b6878f/assets/readme-gif.gif -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to tree-table!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/ng-packagr/ng-package.schema.json", 3 | "lib": { 4 | "entryFile": "public_api.ts" 5 | }, 6 | "whitelistedNonPeerDependencies": [ 7 | "fp-ts", 8 | "lodash-es" 9 | ] 10 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-material-treetable", 3 | "description": "A customisable Angular Material TreeTable component", 4 | "version": "0.5.5", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "packagr": "ng-packagr -p ng-package.json", 13 | "postinstall": "npm rebuild node-sass" 14 | }, 15 | "author": { 16 | "name": "Marco Levrero", 17 | "url": "https://github.com/mlrv" 18 | }, 19 | "license": "MIT", 20 | "private": false, 21 | "dependencies": { 22 | "fp-ts": "^1.13.0", 23 | "lodash-es": "^4.17.15" 24 | }, 25 | "devDependencies": { 26 | "@angular-devkit/build-angular": "^0.12.2", 27 | "@angular/animations": "^7.2.1", 28 | "@angular/cdk": "^7.2.1", 29 | "@angular/cli": "^7.2.2", 30 | "@angular/common": "^7.2.1", 31 | "@angular/compiler": "^7.2.1", 32 | "@angular/compiler-cli": "^7.2.1", 33 | "@angular/core": "^7.2.1", 34 | "@angular/elements": "^7.0.2", 35 | "@angular/flex-layout": "^7.0.0-beta.21", 36 | "@angular/forms": "^7.2.1", 37 | "@angular/material": "^7.0.2", 38 | "@angular/platform-browser": "^7.2.1", 39 | "@angular/platform-browser-dynamic": "^7.2.1", 40 | "@types/jasmine": "~2.8.8", 41 | "@types/jasminewd2": "~2.0.3", 42 | "@types/lodash-es": "^4.17.3", 43 | "@types/node": "^8.10.39", 44 | "@types/uuid": "^3.4.4", 45 | "codelyzer": "~4.5.0", 46 | "core-js": "^2.5.4", 47 | "document-register-element": "^1.7.2", 48 | "jasmine-core": "~2.99.1", 49 | "jasmine-spec-reporter": "~4.2.1", 50 | "karma": "~3.0.0", 51 | "karma-chrome-launcher": "~2.2.0", 52 | "karma-coverage-istanbul-reporter": "~2.0.1", 53 | "karma-jasmine": "^1.1.2", 54 | "karma-jasmine-html-reporter": "^0.2.2", 55 | "karma-phantomjs-launcher": "^1.0.4", 56 | "ng-packagr": "^4.4.0", 57 | "phantomjs-prebuilt": "^2.1.16", 58 | "protractor": "~5.4.0", 59 | "puppeteer": "^1.20.0", 60 | "rxjs": "~6.3.3", 61 | "ts-node": "~7.0.0", 62 | "tsickle": "^0.33.1", 63 | "tslint": "~5.11.0", 64 | "typescript": "~3.1.1", 65 | "uuid": "^3.3.2", 66 | "webpack-dev-server": "^3.1.14", 67 | "zone.js": "~0.8.26" 68 | }, 69 | "keywords": [ 70 | "angular", 71 | "ng", 72 | "material", 73 | "angular 2", 74 | "angular 4", 75 | "angular 5", 76 | "angular 6", 77 | "angular 7", 78 | "angular material", 79 | "material design", 80 | "tree", 81 | "treetable", 82 | "tree-table" 83 | ] 84 | } 85 | -------------------------------------------------------------------------------- /public_api.ts: -------------------------------------------------------------------------------- 1 | export * from './src/app/treetable/treetable.module'; 2 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Angular Material TreeTable Component

4 |
5 |
6 | 13 | 20 |
21 |
22 | 23 |

Tree as Single Root Node

24 | 25 | 26 |

Tree as Array of Nodes

27 | 28 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | h1 { 2 | font-family: Arial, Helvetica, sans-serif 3 | } 4 | 5 | .title { 6 | display: flex; 7 | align-items: center; 8 | justify-content: space-between; 9 | padding: 0px 10px 10px 10px; 10 | } -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Node } from './treetable/models'; 3 | import { mockTree } from './treetable/mocks/mockTree'; 4 | import { mockTreeAsArrayOfNodes } from './treetable/mocks/mockTreeAsArrayOfNodes'; 5 | import { Folder, Task } from './treetable/mocks/models'; 6 | 7 | @Component({ 8 | selector: 'app-root', 9 | templateUrl: './app.component.html', 10 | styleUrls: ['./app.component.scss'] 11 | }) 12 | export class AppComponent { 13 | singleRootTree: Node = mockTree; 14 | arrayOfNodesTree: Node[] = mockTreeAsArrayOfNodes; 15 | } 16 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 3 | import { AppComponent } from './app.component'; 4 | import { TreetableModule } from './treetable/treetable.module'; 5 | 6 | @NgModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | imports: [ 11 | BrowserAnimationsModule, 12 | TreetableModule 13 | ], 14 | providers: [], 15 | bootstrap: [AppComponent] 16 | }) 17 | export class AppModule { } 18 | -------------------------------------------------------------------------------- /src/app/treetable/component/treetable.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
8 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
6 | {{options.capitalisedHeader ? (column | titlecase) : column}} 7 | 9 |
10 |
11 |
12 | 13 | {{element.isExpanded ? 'keyboard_arrow_down' : 'keyboard_arrow_right'}} 14 | 15 |
{{element.value[column]}}
16 |
17 |
18 |
19 | {{element.value[column]}} 20 |
21 |
29 | -------------------------------------------------------------------------------- /src/app/treetable/component/treetable.component.scss: -------------------------------------------------------------------------------- 1 | table { 2 | width: 100%; 3 | } 4 | 5 | .value-cell { 6 | display: flex; 7 | align-items: center; 8 | } 9 | 10 | mat-icon { 11 | cursor: pointer; 12 | } 13 | 14 | .highlight-on-hover:hover { 15 | background-color: #f0f0f5; 16 | } 17 | 18 | td[class*=' mat-column']{ 19 | width: 10vw; 20 | min-width: 10vw;; 21 | max-width: 10vw; 22 | } 23 | 24 | .mat-cell, .mat-header-cell { 25 | padding: 10px; 26 | } 27 | 28 | .vertical-separator { 29 | border-left: 1px solid #f0f0f5; 30 | } 31 | 32 | td div { 33 | word-break: break-all; 34 | } -------------------------------------------------------------------------------- /src/app/treetable/component/treetable.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | import { TreetableComponent } from './treetable.component'; 3 | import { MatTableModule } from '@angular/material/table'; 4 | import { MatIconModule } from '@angular/material/icon'; 5 | import { mockSearchableTree } from '../mocks/mockSearchableTree'; 6 | import * as _ from 'lodash-es'; 7 | 8 | describe('TreetableComponent', () => { 9 | let component: TreetableComponent; 10 | let fixture: ComponentFixture>; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ 15 | TreetableComponent 16 | ], 17 | imports: [ 18 | MatTableModule, 19 | MatIconModule 20 | ] 21 | }) 22 | .compileComponents(); 23 | })); 24 | 25 | beforeEach(() => { 26 | fixture = TestBed.createComponent(TreetableComponent); 27 | component = fixture.componentInstance; 28 | component.tree = _.cloneDeep(mockSearchableTree); 29 | fixture.detectChanges(); 30 | }); 31 | 32 | it('should create', () => { 33 | expect(component).toBeTruthy(); 34 | }); 35 | 36 | it('should emit an event when a node is clicked', () => { 37 | const clickedNode = (component as any).treeTable[0]; 38 | component.nodeClicked.subscribe(n => expect(n).toBe(clickedNode)); 39 | component.onNodeClick(clickedNode); 40 | }); 41 | 42 | }); 43 | -------------------------------------------------------------------------------- /src/app/treetable/component/treetable.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input, Output, ElementRef } from '@angular/core'; 2 | import { Node, TreeTableNode, Options, SearchableNode } from '../models'; 3 | import { TreeService } from '../services/tree/tree.service'; 4 | import { MatTableDataSource } from '@angular/material'; 5 | import { ValidatorService } from '../services/validator/validator.service'; 6 | import { ConverterService } from '../services/converter/converter.service'; 7 | import { defaultOptions } from '../default.options'; 8 | import { flatMap, defaults } from 'lodash-es'; 9 | import { Required } from '../decorators/required.decorator'; 10 | import { Subject } from 'rxjs'; 11 | 12 | @Component({ 13 | selector: 'ng-treetable, treetable', // 'ng-treetable' is currently being deprecated 14 | templateUrl: './treetable.component.html', 15 | styleUrls: ['./treetable.component.scss'] 16 | }) 17 | export class TreetableComponent implements OnInit { 18 | @Input() @Required tree: Node | Node[]; 19 | @Input() options: Options = {}; 20 | @Output() nodeClicked: Subject> = new Subject(); 21 | private searchableTree: SearchableNode[]; 22 | private treeTable: TreeTableNode[]; 23 | displayedColumns: string[]; 24 | dataSource: MatTableDataSource>; 25 | 26 | constructor( 27 | private treeService: TreeService, 28 | private validatorService: ValidatorService, 29 | private converterService: ConverterService, 30 | elem: ElementRef 31 | ) { 32 | const tagName = elem.nativeElement.tagName.toLowerCase(); 33 | if (tagName === 'ng-treetable') { 34 | console.warn(`DEPRECATION WARNING: \n The 'ng-treetable' selector is being deprecated. Please use the new 'treetable' selector`); 35 | } 36 | } 37 | 38 | ngOnInit() { 39 | this.tree = Array.isArray(this.tree) ? this.tree : [this.tree]; 40 | this.options = this.parseOptions(defaultOptions); 41 | const customOrderValidator = this.validatorService.validateCustomOrder(this.tree[0], this.options.customColumnOrder); 42 | if (this.options.customColumnOrder && !customOrderValidator.valid) { 43 | throw new Error(` 44 | Properties ${customOrderValidator.xor.map(x => `'${x}'`).join(', ')} incorrect or missing in customColumnOrder` 45 | ); 46 | } 47 | this.displayedColumns = this.options.customColumnOrder 48 | ? this.options.customColumnOrder 49 | : this.extractNodeProps(this.tree[0]); 50 | this.searchableTree = this.tree.map(t => this.converterService.toSearchableTree(t)); 51 | const treeTableTree = this.searchableTree.map(st => this.converterService.toTreeTableTree(st)); 52 | this.treeTable = flatMap(treeTableTree, this.treeService.flatten); 53 | this.dataSource = this.generateDataSource(); 54 | } 55 | 56 | extractNodeProps(tree: Node & { value: { [k: string]: any } }): string[] { 57 | return Object.keys(tree.value).filter(x => typeof tree.value[x] !== 'object'); 58 | } 59 | 60 | generateDataSource(): MatTableDataSource> { 61 | return new MatTableDataSource(this.treeTable.filter(x => x.isVisible)); 62 | } 63 | 64 | formatIndentation(node: TreeTableNode, step: number = 5): string { 65 | return ' '.repeat(node.depth * step); 66 | } 67 | 68 | formatElevation(): string { 69 | return `mat-elevation-z${this.options.elevation}`; 70 | } 71 | 72 | onNodeClick(clickedNode: TreeTableNode): void { 73 | clickedNode.isExpanded = !clickedNode.isExpanded; 74 | this.treeTable.forEach(el => { 75 | el.isVisible = this.searchableTree.every(st => { 76 | return this.treeService.searchById(st, el.id). 77 | fold([], n => n.pathToRoot) 78 | .every(p => this.treeTable.find(x => x.id === p.id).isExpanded); 79 | }); 80 | }); 81 | this.dataSource = this.generateDataSource(); 82 | this.nodeClicked.next(clickedNode); 83 | } 84 | 85 | // Overrides default options with those specified by the user 86 | parseOptions(defaultOpts: Options): Options { 87 | return defaults(this.options, defaultOpts); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/app/treetable/decorators/required.decorator.spec.ts: -------------------------------------------------------------------------------- 1 | import { Required } from './required.decorator'; 2 | 3 | describe('RequiredDecorator', () => { 4 | 5 | it('should create', () => { 6 | expect(Required).toBeTruthy(); 7 | }); 8 | 9 | it('should throw an error when a required property is not defined', () => { 10 | const target: any = {}; 11 | const property = 'requiredProp'; 12 | const errorMessage = `Input '${property}' is required. Have you forgotten to add [${property}] = ... in your template?`; 13 | Required(target, property); 14 | expect(() => target.requiredProp).toThrowError(errorMessage); 15 | }); 16 | 17 | it('should not throw an error when a required property is defined', () => { 18 | const target: any = {}; 19 | const property = 'requiredProp'; 20 | Required(target, property); 21 | target.requiredProp = true; 22 | expect(target.requiredProp).toEqual(true); 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/treetable/decorators/required.decorator.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Decorator that sets an Input() propertiy as required, will 3 | * throw an error if the property is not specified in the template. 4 | * I.e. @Input() @Required myProp: number; 5 | */ 6 | export function Required(target: Object, property: string): void { 7 | Object.defineProperty(target, property, { 8 | get() { 9 | throw new Error(`Input '${property}' is required. Have you forgotten to add [${property}] = ... in your template?`); 10 | }, 11 | set(value) { 12 | Object.defineProperty(target, property, { 13 | value, 14 | writable: true, 15 | configurable: true 16 | }); 17 | }, 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /src/app/treetable/default.options.ts: -------------------------------------------------------------------------------- 1 | import { Options } from './models'; 2 | 3 | export const defaultOptions: Options = { 4 | verticalSeparator: true, 5 | highlightRowOnHover: true, 6 | elevation: 5 7 | }; 8 | -------------------------------------------------------------------------------- /src/app/treetable/mocks/mockSearchableTree.ts: -------------------------------------------------------------------------------- 1 | import { SearchableNode } from '../models'; 2 | import { Folder } from './models'; 3 | 4 | export const mockSearchableTree: SearchableNode = { 5 | id: '1', 6 | value: { 7 | name: 'Reports', 8 | owner: 'Eric', 9 | protected: true, 10 | backup: true 11 | }, 12 | children: [ 13 | { 14 | id: '11', 15 | value: { 16 | name: 'Charts', 17 | owner: 'Stephanie', 18 | protected: false, 19 | backup: true 20 | }, 21 | children: [] 22 | }, 23 | { 24 | id: '12', 25 | value: { 26 | name: 'Sales', 27 | owner: 'Virginia', 28 | protected: false, 29 | backup: true 30 | }, 31 | children: [] 32 | }, 33 | { 34 | id: '13', 35 | value: { 36 | name: 'US', 37 | owner: 'Alison', 38 | protected: true, 39 | backup: false 40 | }, 41 | children: [ 42 | { 43 | id: '131', 44 | value: { 45 | name: 'California', 46 | owner: 'Claire', 47 | protected: false, 48 | backup: false 49 | }, 50 | children: [] 51 | }, 52 | { 53 | id: '132', 54 | value: { 55 | name: 'Washington', 56 | owner: 'Colin', 57 | protected: false, 58 | backup: true 59 | }, 60 | children: [ 61 | { 62 | id: '1321', 63 | value: { 64 | name: 'Domestic', 65 | owner: 'Oliver', 66 | protected: true, 67 | backup: false 68 | }, 69 | children: [] 70 | }, 71 | { 72 | id: '1322', 73 | value: { 74 | name: 'International', 75 | owner: 'Oliver', 76 | protected: true, 77 | backup: true 78 | }, 79 | children: [] 80 | } 81 | ] 82 | } 83 | ] 84 | } 85 | ] 86 | }; 87 | -------------------------------------------------------------------------------- /src/app/treetable/mocks/mockTree.ts: -------------------------------------------------------------------------------- 1 | import { Node } from '../models'; 2 | import { Folder } from './models'; 3 | 4 | export const mockTree: Node = { 5 | value: { 6 | name: 'Reports', 7 | owner: 'Eric', 8 | protected: true, 9 | backup: true 10 | }, 11 | children: [ 12 | { 13 | value: { 14 | name: 'Charts', 15 | owner: 'Stephanie', 16 | protected: false, 17 | backup: true 18 | }, 19 | children: [] 20 | }, 21 | { 22 | value: { 23 | name: 'Sales', 24 | owner: 'Virginia', 25 | protected: false, 26 | backup: true 27 | }, 28 | children: [] 29 | }, 30 | { 31 | value: { 32 | name: 'US', 33 | owner: 'Alison', 34 | protected: true, 35 | backup: false 36 | }, 37 | children: [ 38 | { 39 | value: { 40 | name: 'California', 41 | owner: 'Claire', 42 | protected: false, 43 | backup: false 44 | }, 45 | children: [] 46 | }, 47 | { 48 | value: { 49 | name: 'Washington', 50 | owner: 'Colin', 51 | protected: false, 52 | backup: true 53 | }, 54 | children: [ 55 | { 56 | value: { 57 | name: 'Domestic', 58 | owner: 'Oliver', 59 | protected: true, 60 | backup: false 61 | }, 62 | children: [] 63 | }, 64 | { 65 | value: { 66 | name: 'International', 67 | owner: 'Oliver', 68 | protected: true, 69 | backup: true 70 | }, 71 | children: [] 72 | } 73 | ] 74 | } 75 | ] 76 | } 77 | ] 78 | }; 79 | 80 | -------------------------------------------------------------------------------- /src/app/treetable/mocks/mockTreeAsArrayOfNodes.ts: -------------------------------------------------------------------------------- 1 | import { Node } from '../models'; 2 | import { Task } from './models'; 3 | 4 | export const mockTreeAsArrayOfNodes: Node[] = [ 5 | { 6 | value: { 7 | name: 'Tasks for Sprint 1', 8 | completed: true, 9 | owner: 'Marco' 10 | }, 11 | children: [ 12 | { 13 | value: { 14 | name: 'Complete feature #123', 15 | completed: true, 16 | owner: 'Marco' 17 | }, 18 | children: [] 19 | }, 20 | { 21 | value: { 22 | name: 'Update documentation', 23 | completed: true, 24 | owner: 'Jane' 25 | }, 26 | children: [ 27 | { 28 | value: { 29 | name: 'Proofread documentation', 30 | completed: true, 31 | owner: 'Bob' 32 | }, 33 | children: [] 34 | } 35 | ] 36 | } 37 | ] 38 | }, 39 | { 40 | value: { 41 | name: 'Tasks for Sprint 2', 42 | completed: false, 43 | owner: 'Erika', 44 | }, 45 | children: [ 46 | { 47 | value: { 48 | name: 'Fix bug #567', 49 | completed: false, 50 | owner: 'Marco' 51 | }, 52 | children: [] 53 | }, 54 | { 55 | value: { 56 | name: 'Speak with clients', 57 | completed: true, 58 | owner: 'James' 59 | }, 60 | children: [] 61 | } 62 | ] 63 | } 64 | ]; 65 | 66 | -------------------------------------------------------------------------------- /src/app/treetable/mocks/mockTreeTableTree.ts: -------------------------------------------------------------------------------- 1 | import { TreeTableNode } from '../models'; 2 | import { Folder } from './models'; 3 | 4 | export const mockTreeTableTree: TreeTableNode = { 5 | value: { 6 | name: 'Reports', 7 | owner: 'Eric', 8 | protected: true, 9 | backup: true 10 | }, 11 | children: [ 12 | { 13 | value: { 14 | name: 'Charts', 15 | owner: 'Stephanie', 16 | protected: false, 17 | backup: true 18 | }, 19 | children: [], 20 | id: '34e8b657-cbde-4ab7-888f-0c95e1e73dee', 21 | depth: 1, 22 | isExpanded: true, 23 | isVisible: true 24 | }, 25 | { 26 | value: { 27 | name: 'Sales', 28 | owner: 'Virginia', 29 | protected: false, 30 | backup: true 31 | }, 32 | children: [], 33 | id: '1c25d8e7-7c5d-4af4-8552-0425fe999fdc', 34 | depth: 1, 35 | isExpanded: true, 36 | isVisible: true 37 | }, 38 | { 39 | value: { 40 | name: 'US', 41 | owner: 'Alison', 42 | protected: true, 43 | backup: false 44 | }, 45 | children: [ 46 | { 47 | value: { 48 | name: 'California', 49 | owner: 'Claire', 50 | protected: false, 51 | backup: false 52 | }, 53 | children: [], 54 | id: '36faef50-fc12-4ea0-a330-3222b67fa49e', 55 | depth: 2, 56 | isExpanded: true, 57 | isVisible: true 58 | }, 59 | { 60 | value: { 61 | name: 'Washington', 62 | owner: 'Colin', 63 | protected: false, 64 | backup: true 65 | }, 66 | children: [ 67 | { 68 | value: { 69 | name: 'Domestic', 70 | owner: 'Oliver', 71 | protected: true, 72 | backup: false 73 | }, 74 | children: [], 75 | id: '2b0085e4-0d5c-45a9-a505-7706e1cfbc67', 76 | depth: 3, 77 | isExpanded: true, 78 | isVisible: true 79 | }, 80 | { 81 | value: { 82 | name: 'International', 83 | owner: 'Oliver', 84 | protected: true, 85 | backup: true 86 | }, 87 | children: [], 88 | id: '6dfb3d53-3062-44a6-9be9-e86051a2b071', 89 | depth: 3, 90 | isExpanded: true, 91 | isVisible: true 92 | } 93 | ], 94 | id: '554eea5b-e7f9-460e-95af-f7a68138fc7a', 95 | depth: 2, 96 | isExpanded: true, 97 | isVisible: true 98 | } 99 | ], 100 | id: 'c52f0131-1280-49cf-813f-57b607544220', 101 | depth: 1, 102 | isExpanded: true, 103 | isVisible: true 104 | } 105 | ], 106 | id: '20ed5fcc-d4f2-4aa3-b5a2-57d9a91057a7', 107 | depth: 0, 108 | isExpanded: true, 109 | isVisible: true 110 | }; 111 | -------------------------------------------------------------------------------- /src/app/treetable/mocks/models.ts: -------------------------------------------------------------------------------- 1 | export interface Folder { 2 | name: string; 3 | owner: string; 4 | protected: boolean; 5 | backup: boolean; 6 | } 7 | 8 | export interface Task { 9 | name: string; 10 | completed: boolean; 11 | owner: string; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/app/treetable/models.ts: -------------------------------------------------------------------------------- 1 | export interface Node { 2 | value: T; 3 | children: Node[]; 4 | } 5 | 6 | export interface SearchableNode extends Node { 7 | id: string; 8 | children: SearchableNode[]; 9 | } 10 | 11 | export interface TreeTableNode extends SearchableNode { 12 | depth: number; 13 | isVisible: boolean; 14 | isExpanded: boolean; 15 | children: TreeTableNode[]; 16 | } 17 | 18 | export interface NodeInTree extends SearchableNode { 19 | pathToRoot: SearchableNode[]; 20 | } 21 | 22 | export interface Options { 23 | verticalSeparator?: boolean; 24 | capitalisedHeader?: boolean; 25 | highlightRowOnHover?: boolean; 26 | customColumnOrder?: Array & string[]; 27 | elevation?: number; 28 | } 29 | -------------------------------------------------------------------------------- /src/app/treetable/services/converter/converter.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { ConverterService } from './converter.service'; 3 | import { SearchableNode, TreeTableNode } from '../../models'; 4 | import { mockSearchableTree } from '../../mocks/mockSearchableTree'; 5 | import { mockTree } from '../../mocks/mockTree'; 6 | import { mockTreeTableTree } from '../../mocks/mockTreeTableTree'; 7 | import * as _ from 'lodash-es'; 8 | 9 | describe('ConverterService', () => { 10 | beforeEach(() => TestBed.configureTestingModule({})); 11 | 12 | it('should be created', () => { 13 | const service: ConverterService = TestBed.get(ConverterService); 14 | expect(service).toBeTruthy(); 15 | }); 16 | 17 | it('should convert a basic tree into a searchable tree', () => { 18 | const service: ConverterService = TestBed.get(ConverterService); 19 | expect(instanceOfSearchableNode(mockTree)).toBe(false); 20 | expect(instanceOfSearchableNode(service.toSearchableTree(mockTree))).toBe(true); 21 | }); 22 | 23 | it('should convert a searchable tree into a treetable tree', () => { 24 | const service: ConverterService = TestBed.get(ConverterService); 25 | expect(instanceOfSearchableNode(mockSearchableTree)).toBe(true); 26 | expect(instanceOfTreeTableNodee(mockSearchableTree)).toBe(false); 27 | expect(instanceOfSearchableNode(service.toTreeTableTree(mockSearchableTree))).toBe(true); 28 | }); 29 | 30 | it('should do nothing to trees that are already of the required type', () => { 31 | const service: ConverterService = TestBed.get(ConverterService); 32 | expect(instanceOfSearchableNode(mockSearchableTree)).toBe(true); 33 | expect(instanceOfSearchableNode(service.toSearchableTree(mockSearchableTree))).toBe(true); 34 | }); 35 | 36 | it('should clone the trees', () => { 37 | const service: ConverterService = TestBed.get(ConverterService); 38 | expect(mockSearchableTree !== service.toSearchableTree(mockSearchableTree)).toBe(true); 39 | expect(_.isEqual(mockSearchableTree, service.toSearchableTree(mockSearchableTree))).toBe(true); 40 | expect(mockTreeTableTree !== service.toTreeTableTree(mockTreeTableTree)).toBe(true); 41 | expect(_.isEqual(mockTreeTableTree, service.toTreeTableTree(mockTreeTableTree))).toBe(true); 42 | }); 43 | 44 | }); 45 | 46 | export function instanceOfSearchableNode(object: any): object is SearchableNode { 47 | return 'id' in object; 48 | } 49 | 50 | export function instanceOfTreeTableNodee(object: any): object is TreeTableNode { 51 | return 'depth' in object && 'isVisible' in object && 'isExpanded' in object; 52 | } 53 | -------------------------------------------------------------------------------- /src/app/treetable/services/converter/converter.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { TreeService } from '../tree/tree.service'; 3 | import { Node, SearchableNode, TreeTableNode } from '../../models'; 4 | import { cloneDeep } from 'lodash-es'; 5 | const uuidv4 = require('uuid/v4'); 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class ConverterService { 11 | 12 | constructor(private treeService: TreeService) { } 13 | 14 | /** 15 | * Clone a Node object and convert it to a SearchableNode 16 | * @param tree the node to be converted 17 | */ 18 | toSearchableTree(tree: Node): SearchableNode { 19 | const treeClone = cloneDeep(tree) as SearchableNode; 20 | this.treeService.traverse(treeClone, (node: SearchableNode) => { 21 | node.id = node.id ? node.id : uuidv4(); 22 | }); 23 | return treeClone; 24 | } 25 | 26 | /** 27 | * Clone a SearchableNode object and convert it to a TreeTableNode 28 | * @param tree the node to be converted 29 | */ 30 | toTreeTableTree(tree: SearchableNode): TreeTableNode { 31 | const treeClone = cloneDeep(tree) as TreeTableNode; 32 | this.treeService.traverse(treeClone, (node: TreeTableNode) => { 33 | node.depth = this.treeService.getNodeDepth(treeClone, node); 34 | node.isExpanded = true; 35 | node.isVisible = true; 36 | }); 37 | return treeClone; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/app/treetable/services/tree/tree.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { TreeService } from './tree.service'; 3 | import * as _ from 'lodash-es'; 4 | import { mockSearchableTree } from '../../mocks/mockSearchableTree'; 5 | import { Folder } from '../../mocks/models'; 6 | import { some, none } from 'fp-ts/lib/Option'; 7 | import { SearchableNode, NodeInTree } from '../../models'; 8 | 9 | describe('TreeService', () => { 10 | beforeEach(() => TestBed.configureTestingModule({})); 11 | 12 | it('should be created', () => { 13 | const service: TreeService = TestBed.get(TreeService); 14 | expect(service).toBeTruthy(); 15 | }); 16 | 17 | it('should search for a node in a tree and return it warapped in Option<> if present', () => { 18 | const service: TreeService = TestBed.get(TreeService); 19 | const tree = _.cloneDeep(mockSearchableTree); 20 | const expectedNode = tree.children[0]; 21 | const expectedPathToRoot = [tree]; 22 | const id = expectedNode.id; 23 | expect(service.searchById(tree, id)).toEqual(some({ 24 | ...expectedNode, 25 | pathToRoot: expectedPathToRoot 26 | })); 27 | }); 28 | 29 | it('should search for a node in a tree and return none if not present', () => { 30 | const service: TreeService = TestBed.get(TreeService); 31 | const tree = _.cloneDeep(mockSearchableTree); 32 | const id = '00000'; 33 | expect(service.searchById(tree, id)).toEqual(none); 34 | }); 35 | 36 | it('should traverse a tree and apply a function to all nodes', () => { 37 | const service: TreeService = TestBed.get(TreeService); 38 | const tree = _.cloneDeep(mockSearchableTree); 39 | service.traverse(tree, node => node.value.name = node.value.name.toUpperCase()); 40 | const compareNode = (originalNode: SearchableNode, newNode: NodeInTree) => { 41 | return newNode.value.name === originalNode.value.name.toUpperCase(); 42 | }; 43 | service.traverse(mockSearchableTree, n => { 44 | expect(compareNode(n, service.searchById(tree, n.id).fold(null, x => x) as NodeInTree)).toBe(true); 45 | }); 46 | }); 47 | 48 | it('should correctly flatten a tree', () => { 49 | const service: TreeService = TestBed.get(TreeService); 50 | const tree = _.cloneDeep(mockSearchableTree); 51 | const expectedFlattenedTree = [ 52 | tree, 53 | tree.children[0], 54 | tree.children[1], 55 | tree.children[2], 56 | tree.children[2].children[0], 57 | tree.children[2].children[1], 58 | tree.children[2].children[1].children[0], 59 | tree.children[2].children[1].children[1] 60 | ]; 61 | expect(service.flatten(tree)).toEqual(expectedFlattenedTree); 62 | }); 63 | 64 | it('should return the depth of a node that\'s in the tree', () => { 65 | const service: TreeService = TestBed.get(TreeService); 66 | const tree = _.cloneDeep(mockSearchableTree); 67 | const firstLevelNode = tree.children[0]; 68 | const secondLevelNode = tree.children[2].children[0]; 69 | const thirdLevelNode = tree.children[2].children[1].children[0]; 70 | expect(service.getNodeDepth(tree, tree)).toEqual(0); 71 | expect(service.getNodeDepth(tree, firstLevelNode)).toEqual(1); 72 | expect(service.getNodeDepth(tree, secondLevelNode)).toEqual(2); 73 | expect(service.getNodeDepth(tree, thirdLevelNode)).toEqual(3); 74 | }); 75 | 76 | it('should return a depth of -1 when the node is not in the tree', () => { 77 | const service: TreeService = TestBed.get(TreeService); 78 | const tree = _.cloneDeep(mockSearchableTree); 79 | const node: SearchableNode = { 80 | id: '0000', 81 | value: { 82 | name: 'name', 83 | backup: true, 84 | owner: 'owner', 85 | protected: false 86 | }, 87 | children: [] 88 | }; 89 | expect(service.getNodeDepth(tree, node)).toEqual(-1); 90 | }); 91 | 92 | }); 93 | -------------------------------------------------------------------------------- /src/app/treetable/services/tree/tree.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Node, SearchableNode, NodeInTree } from '../../models'; 3 | import { cloneDeep } from 'lodash-es'; 4 | import { Option, some, none } from 'fp-ts/lib/Option'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | export class TreeService { 10 | 11 | /** 12 | * Traverse a tree data structure and applies the provided @param f function 13 | * to all nodes 14 | * @param root the tree to be traversed 15 | * @param f the function to be applied to all nodes 16 | * N.B. this function modifies the existing tree 17 | */ 18 | traverse>(root: K, f: (node: K) => void): void { 19 | this._traverse(root, (node: K) => { 20 | f(node); 21 | return true; 22 | }); 23 | } 24 | 25 | /** 26 | * Search a tree for a node with the provided @param id 27 | * @param root the tree to be searched 28 | * @param id the id of the node to be retrieved 29 | */ 30 | searchById>(root: K, id: string): Option> { 31 | let matchingNode: K; 32 | const pathToRoot: {[k: string]: K} = {}; 33 | this._traverse(root, (node: K) => { 34 | node.children.forEach(child => { 35 | pathToRoot[child.id] = node; 36 | }); 37 | if (node.id === id) { 38 | matchingNode = node; 39 | } 40 | return node.id !== id; 41 | }); 42 | return matchingNode ? some({ 43 | id: matchingNode.id, 44 | value: matchingNode.value, 45 | children: matchingNode.children, 46 | pathToRoot: this.buildPath(id, pathToRoot) 47 | }) : none; 48 | } 49 | 50 | /** 51 | * Internal function that can be used to traverse or search the tree 52 | * @param root the tree to be scanned 53 | * @param f an optional function to be applied to all nodes 54 | */ 55 | private _traverse>(root: K, f: (node: K) => boolean): void { 56 | if (!f(root)) { 57 | return; 58 | } 59 | root.children.forEach(c => this._traverse(c, f)); 60 | } 61 | 62 | /** 63 | * Given a @param root tree and a @param node node, calculate the 64 | * depth of the node in the tree 65 | * @param root the tree 66 | * @param node the node we want to calculate the depth of 67 | */ 68 | getNodeDepth>(root: K, node: K): number { 69 | return this.searchById(root, node.id).fold(-1, n => n.pathToRoot.length); 70 | } 71 | 72 | /** 73 | * Flatten a @param root tree into a list of its nodes 74 | * @param root the tree to be flattened 75 | */ 76 | flatten>(root: K): K[] { 77 | const result = [cloneDeep(root)]; 78 | for (let i = 0; i < result.length; i++) { 79 | const node = result[i]; 80 | if (node.children) { 81 | result.splice(result.indexOf(node) + 1, 0, ...node.children as K[]); 82 | } 83 | } 84 | return result; 85 | } 86 | 87 | /** 88 | * Internal function used to build the pathToRoot of a node in a tree 89 | * @param id the id of the node 90 | * @param pathMap the pathMap returned by searchById 91 | */ 92 | private buildPath>(id: string, pathMap: {[k: string]: K}): K[] { 93 | const pathToRoot = []; 94 | let key = id; 95 | while (key) { 96 | if (pathMap[key]) { 97 | pathToRoot.push(pathMap[key]); 98 | key = pathMap[key].id; 99 | } else { 100 | key = null; 101 | } 102 | } 103 | return pathToRoot; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/app/treetable/services/validator/validator.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { ValidatorService } from './validator.service'; 3 | import { mockSearchableTree } from '../../mocks/mockSearchableTree'; 4 | import { Folder } from '../../mocks/models'; 5 | 6 | describe('ValidatorService', () => { 7 | 8 | beforeEach(() => TestBed.configureTestingModule({})); 9 | 10 | it('should be created', () => { 11 | const service: ValidatorService = TestBed.get(ValidatorService); 12 | expect(service).toBeTruthy(); 13 | }); 14 | 15 | it('should correctly process valid customColumnOrders', () => { 16 | const service: ValidatorService = TestBed.get(ValidatorService); 17 | const validCustomOrder: Array = ['backup', 'owner', 'protected', 'name']; 18 | expect(service.validateCustomOrder(mockSearchableTree, validCustomOrder)).toEqual({ 19 | valid: true, 20 | xor: [] 21 | }); 22 | }); 23 | 24 | it('should correctly process invalid customColumnOrders with missing properties', () => { 25 | const service: ValidatorService = TestBed.get(ValidatorService); 26 | const invalidCustomOrder: Array = ['backup', 'owner', 'protected']; 27 | expect(service.validateCustomOrder(mockSearchableTree, invalidCustomOrder)).toEqual({ 28 | valid: false, 29 | xor: ['name'] 30 | }); 31 | }); 32 | 33 | it('should correctly process invalid customColumnOrders with incorrect properties', () => { 34 | const service: ValidatorService = TestBed.get(ValidatorService); 35 | const invalidCustomOrder: any = ['backup', 'owner', 'protected', 'name', 'notAValidProperty']; 36 | expect(service.validateCustomOrder(mockSearchableTree, invalidCustomOrder)).toEqual({ 37 | valid: false, 38 | xor: ['notAValidProperty'] 39 | }); 40 | }); 41 | 42 | it('should correctly process invalid customColumnOrders with incorrect and missing properties', () => { 43 | const service: ValidatorService = TestBed.get(ValidatorService); 44 | const invalidCustomOrder: any = ['backup', 'protected', 'name', 'notAValidProperty']; 45 | expect(service.validateCustomOrder(mockSearchableTree, invalidCustomOrder)).toEqual({ 46 | valid: false, 47 | xor: ['owner', 'notAValidProperty'] 48 | }); 49 | }); 50 | 51 | }); 52 | -------------------------------------------------------------------------------- /src/app/treetable/services/validator/validator.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Node } from '../../models'; 3 | import { isEmpty, xor } from 'lodash-es'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class ValidatorService { 9 | 10 | validateCustomOrder>(node: K, customColumnOrder: Array & string[]): { valid: boolean, xor: string[] } { 11 | const xorN = xor(Object.keys(node.value), customColumnOrder); 12 | return { 13 | valid: isEmpty(xorN), 14 | xor: xorN 15 | }; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/app/treetable/treetable.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | import { MatTableModule } from '@angular/material/table'; 4 | import { MatIconModule } from '@angular/material/icon'; 5 | import { TreetableComponent } from './component/treetable.component'; 6 | export { Node, Options} from './models'; 7 | 8 | @NgModule({ 9 | declarations: [ 10 | TreetableComponent 11 | ], 12 | imports: [ 13 | CommonModule, 14 | MatTableModule, 15 | MatIconModule 16 | ], 17 | exports: [ 18 | TreetableComponent 19 | ] 20 | }) 21 | export class TreetableModule { } 22 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlrv/ng-material-treetable/2b58ceee7ee91dccaf06eced9d972290e2b6878f/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlrv/ng-material-treetable/2b58ceee7ee91dccaf06eced9d972290e2b6878f/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | TreeTable 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | // Set the CHROME_BIN 4 | process.env.CHROME_BIN = require('puppeteer').executablePath(); 5 | 6 | module.exports = function (config) { 7 | config.set({ 8 | basePath: '', 9 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 10 | plugins: [ 11 | require('karma-jasmine'), 12 | require('karma-chrome-launcher'), 13 | require('karma-jasmine-html-reporter'), 14 | require('karma-coverage-istanbul-reporter'), 15 | require('@angular-devkit/build-angular/plugins/karma') 16 | ], 17 | client: { 18 | clearContext: false // leave Jasmine Spec Runner output visible in browser 19 | }, 20 | coverageIstanbulReporter: { 21 | dir: require('path').join(__dirname, '../coverage'), 22 | reports: ['html', 'lcovonly'], 23 | fixWebpackSourcePaths: true 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['ChromeHeadlessNoSandbox'], 31 | customLaunchers: { 32 | ChromeHeadlessNoSandbox: { 33 | base: 'ChromeHeadless', 34 | flags: ['--no-sandbox'] 35 | } 36 | }, 37 | singleRun: false 38 | }); 39 | }; 40 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** 38 | * If the application will be indexed by Google Search, the following is required. 39 | * Googlebot uses a renderer based on Chrome 41. 40 | * https://developers.google.com/search/docs/guides/rendering 41 | **/ 42 | // import 'core-js/es6/array'; 43 | 44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 45 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 46 | 47 | /** IE10 and IE11 requires the following for the Reflect API. */ 48 | // import 'core-js/es6/reflect'; 49 | 50 | /** 51 | * Web Animations `@angular/platform-browser/animations` 52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 54 | **/ 55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 56 | 57 | /** 58 | * By default, zone.js will patch all possible macroTask and DomEvents 59 | * user can disable parts of macroTask/DomEvents patch by setting following flags 60 | */ 61 | 62 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 63 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 64 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 65 | 66 | /* 67 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 68 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 69 | */ 70 | // (window as any).__Zone_enable_cross_context_check = true; 71 | 72 | /*************************************************************************************************** 73 | * Zone JS is required by default for Angular itself. 74 | */ 75 | import 'zone.js/dist/zone'; // Included with Angular CLI. 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | @import "~@angular/material/prebuilt-themes/indigo-pink.css"; 2 | @import url( 'https://fonts.googleapis.com/css?family=Roboto:400,700|Material+Icons'); 3 | 4 | body { 5 | padding: 0px 10px 10px 10px; 6 | } -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [ 6 | "node" 7 | ] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "node_modules/@types" 15 | ], 16 | "lib": [ 17 | "es2018", 18 | "dom" 19 | ], 20 | "noImplicitAny": true, 21 | "alwaysStrict": true, 22 | "allowSyntheticDefaultImports": true, 23 | "esModuleInterop": true 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "interface-over-type-literal": true, 25 | "label-position": true, 26 | "max-line-length": [ 27 | true, 28 | 140 29 | ], 30 | "member-access": false, 31 | "member-ordering": [ 32 | true, 33 | { 34 | "order": [ 35 | "static-field", 36 | "instance-field", 37 | "static-method", 38 | "instance-method" 39 | ] 40 | } 41 | ], 42 | "no-arg": true, 43 | "no-bitwise": true, 44 | "no-console": [ 45 | true, 46 | "debug", 47 | "info", 48 | "time", 49 | "timeEnd", 50 | "trace" 51 | ], 52 | "no-construct": true, 53 | "no-debugger": true, 54 | "no-duplicate-super": true, 55 | "no-empty": false, 56 | "no-empty-interface": true, 57 | "no-eval": true, 58 | "no-inferrable-types": [ 59 | true, 60 | "ignore-params" 61 | ], 62 | "no-misused-new": true, 63 | "no-non-null-assertion": true, 64 | "no-redundant-jsdoc": true, 65 | "no-shadowed-variable": true, 66 | "no-string-literal": false, 67 | "no-string-throw": true, 68 | "no-switch-case-fall-through": true, 69 | "no-trailing-whitespace": true, 70 | "no-unnecessary-initializer": true, 71 | "no-unused-expression": true, 72 | "no-use-before-declare": true, 73 | "no-var-keyword": true, 74 | "object-literal-sort-keys": false, 75 | "one-line": [ 76 | true, 77 | "check-open-brace", 78 | "check-catch", 79 | "check-else", 80 | "check-whitespace" 81 | ], 82 | "prefer-const": true, 83 | "quotemark": [ 84 | true, 85 | "single" 86 | ], 87 | "radix": true, 88 | "semicolon": [ 89 | true, 90 | "always" 91 | ], 92 | "triple-equals": [ 93 | true, 94 | "allow-null-check" 95 | ], 96 | "typedef-whitespace": [ 97 | true, 98 | { 99 | "call-signature": "nospace", 100 | "index-signature": "nospace", 101 | "parameter": "nospace", 102 | "property-declaration": "nospace", 103 | "variable-declaration": "nospace" 104 | } 105 | ], 106 | "unified-signatures": true, 107 | "variable-name": false, 108 | "whitespace": [ 109 | true, 110 | "check-branch", 111 | "check-decl", 112 | "check-operator", 113 | "check-separator", 114 | "check-type" 115 | ], 116 | "no-output-on-prefix": true, 117 | "use-input-property-decorator": true, 118 | "use-output-property-decorator": true, 119 | "use-host-property-decorator": true, 120 | "no-input-rename": true, 121 | "no-output-rename": true, 122 | "use-life-cycle-interface": true, 123 | "use-pipe-transform-interface": true, 124 | "component-class-suffix": true, 125 | "directive-class-suffix": true 126 | } 127 | } 128 | --------------------------------------------------------------------------------