Skip to content

Commit

Permalink
Feat: First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rajesh-froiden committed Sep 28, 2016
0 parents commit 4d7d01e
Show file tree
Hide file tree
Showing 21 changed files with 1,405 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .config/bundle-system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env node
'use strict';

/*eslint no-console: 0, no-sync: 0*/

// System.js bundler
// simple and yet reusable system.js bundler
// bundles, minifies and gzips

const fs = require('fs');
const del = require('del');
const path = require('path');
const zlib = require('zlib');
const async = require('async');
const Builder = require('systemjs-builder');

const pkg = require('../package.json');
const name = pkg.name;
const targetFolder = path.resolve('./bundles');

async.waterfall([
cleanBundlesFolder,
getSystemJsBundleConfig,
buildSystemJs({minify: false, sourceMaps: true, mangle: false}),
getSystemJsBundleConfig,
buildSystemJs({minify: true, sourceMaps: true, mangle: false}),
gzipSystemJsBundle
], err => {
if (err) {
throw err;
}
});

function getSystemJsBundleConfig(cb) {
const config = {
baseURL: '..',
transpiler: 'typescript',
typescriptOptions: {
module: 'cjs'
},
map: {
typescript: path.resolve('node_modules/typescript/lib/typescript.js'),
'@angular/core': path.resolve('node_modules/@angular/core/index.js'),
'@angular/common': path.resolve('node_modules/@angular/common/index.js'),
'@angular/compiler': path.resolve('node_modules/@angular/compiler/index.js'),
'@angular/platform-browser': path.resolve('node_modules/@angular/platform-browser/index.js'),
'@angular/platform-browser-dynamic': path.resolve('node_modules/@angular/platform-browser-dynamic/'),
rxjs: path.resolve('node_modules/rxjs')
},
paths: {
'*': '*.js'
}
};

config.meta = ['@angular/common','@angular/compiler','@angular/core',
'@angular/platform-browser','@angular/platform-browser-dynamic', 'rxjs'].reduce((memo, currentValue) => {
memo[path.resolve(`node_modules/${currentValue}/*`)] = {build: false};
return memo;
}, {});
config.meta.moment = {build: false};
return cb(null, config);
}

function cleanBundlesFolder(cb) {
return del(targetFolder)
.then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
cb();
});
}

function buildSystemJs(options) {
return (config, cb) => {
const minPostFix = options && options.minify ? '.min' : '';
const fileName = `${name}${minPostFix}.js`;
const dest = path.resolve(__dirname, targetFolder, fileName);
const builder = new Builder();

console.log('Bundling system.js file:', fileName, options);
builder.config(config);
return builder
.bundle([name, name].join('/'), dest, options)
.then(() => cb())
.catch(cb);
};
}

function gzipSystemJsBundle(cb) {
const files = fs
.readdirSync(path.resolve(targetFolder))
.map(file => path.resolve(targetFolder, file))
.filter(file => fs.statSync(file).isFile())
.filter(file => path.extname(file) !== 'gz');

return async.eachSeries(files, (file, gzipcb) => {
process.nextTick(() => {
console.log('Gzipping ', file);
const gzip = zlib.createGzip({level: 9});
const inp = fs.createReadStream(file);
const out = fs.createWriteStream(`${file}.gz`);

inp.on('end', () => gzipcb());
inp.on('error', err => gzipcb(err));
return inp.pipe(gzip).pipe(out);
});
}, cb);
}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
/node_modules
npm-debug.log

# type script artifacts
/typings

# WebStorm
.idea
.vscode

# ignore build and dist for now
/bundles
/demo-build
/dist
/coverage
/ts


/components/**/*.js
/components/**/*.js.map
/components/**/*.d.ts
angular2-select.js
angular2-select.js.map
angular2-select.d.ts

/logs

factories

/**/*.metadata.json
25 changes: 25 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.idea
gulp-tasks
logs

# typings
typings

# testing
karma.conf.js
test.bundle.js
coverage

# demo build
demo
demo-build
webpack.config.js

#typescript sources
*.ts
*.js.map
!*.d.ts
/components/**/*.ts
!/components/**/*.d.ts

factories
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: node_js
node_js:
- "6"

#before_install: npm i -g npm@latest

script:
- npm test

after_success:
- ./node_modules/.bin/codecov -f coverage/coverage-final.json

addons:
# sauce labs tunel connector (read more https://docs.travis-ci.com/user/sauce-connect/ )
sauce_connect: true
firefox: "42.0"
apt:
sources:
- ubuntu-toolchain-r-test
# required by node-gyp to build some packages
packages:
- g++-4.8
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<a name="2.0.0"></a>
# [2.0.0](https://github.com/Froiden/angular2-select) (2016-09-23)


22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015-2016 Froiden Technology Pvt Ltd. Jaipur <[email protected]>
Copyright (c) 2015-2016 Froiden Technology Pvt Ltd. Jaipur

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Native UI Select Angular2 component ([demo](http://valor-software.com/ng2-select/))
## ng2-select [![npm version](https://badge.fury.io/js/ng2-select.svg)](http://badge.fury.io/js/ng2-select) [![npm downloads](https://img.shields.io/npm/dm/ng2-select.svg)](https://npmjs.org/ng2-select)

Follow me [![twitter](https://img.shields.io/twitter/follow/valorkin.svg?style=social&label=%20valorkin)](https://twitter.com/valorkin) to be notified about new releases.

[![Angular 2 Style Guide](https://mgechev.github.io/angular2-style-guide/images/badge.svg)](https://github.com/mgechev/angular2-style-guide)
[![Code Climate](https://codeclimate.com/github/valor-software/ng2-select/badges/gpa.svg)](https://codeclimate.com/github/valor-software/ng2-select)
[![Build Status](https://travis-ci.org/valor-software/ng2-select.svg?branch=master)](https://travis-ci.org/valor-software/ng2-select)
[![Join the chat at https://gitter.im/valor-software/ng2-bootstrap](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/valor-software/ng2-bootstrap?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![devDependency Status](https://david-dm.org/valor-software/ng2-select/dev-status.svg)](https://david-dm.org/valor-software/ng2-select#info=devDependencies)
[![Throughput Graph](https://graphs.waffle.io/valor-software/ng2-select/throughput.svg)](https://waffle.io/valor-software/ng2-select/metrics)



## Quick start

1. A recommended way to install ***ng2-select*** is through [npm](https://www.npmjs.com/search?q=ng2-select) package manager using the following command:

`npm i ng2-select --save`

2. Include `ng2-select.css` in your project

3. More information regarding of using ***ng2-select*** is located in
[demo](http://valor-software.github.io/ng2-select/) and [demo sources](https://github.com/valor-software/ng2-select/tree/master/demo).

## API

### Properties

- `items` - (`Array<any>`) - Array of items from which to select. Should be an array of objects with `id` and `text` properties.
As convenience, you may also pass an array of strings, in which case the same string is used for both the ID and the text.
Items may be nested by adding a `children` property to any item, whose value should be another array of items. Items that have children may omit having an ID.
If `items` are specified, all items are expected to be available locally and all selection operations operate on this local array only.
If omitted, items are not available locally, and the `query` option should be provided to fetch data.
- `active` (`?Array<any>`) - selection data to set. This should be an object with `id` and `text` properties in the case of input type 'Single',
or an array of such objects otherwise. This option is mutually exclusive with value.
- `allowClear` (`?boolean=false`) (*not yet supported*) - Set to `true` to allow the selection to be cleared. This option only applies to single-value inputs.
- `placeholder` (`?string=''`) - Placeholder text to display when the element has no focus and selected items.
- `disabled` (`?boolean=false`) - When `true`, it specifies that the component should be disabled.
- `multiple` - (`?boolean=false`) - Mode of this component. If set `true` user can select more than one option.
This option only applies to single-value inputs, as multiple-value inputs don't have the search input in the dropdown to begin with.

### Events

- `data` - it fires during all events of this component; returns `Array<any>` - current selected data
- `selected` - it fires after a new option selected; returns object with `id` and `text` properties that describes a new option.
- `removed` - it fires after an option removed; returns object with `id` and `text` properties that describes a removed option.
- `typed` - it fires after changing of search input; returns `string` with that value.

# Troubleshooting

Please follow this guidelines when reporting bugs and feature requests:

1. Use [GitHub Issues](https://github.com/valor-software/ng2-select/issues) board to report bugs and feature requests (not our email address)
2. Please **always** write steps to reproduce the error. That way we can focus on fixing the bug, not scratching our heads trying to reproduce it.

Thanks for understanding!

### License

The MIT License (see the [LICENSE](https://github.com/valor-software/ng2-select/blob/master/LICENSE) file for the full text)
2 changes: 2 additions & 0 deletions angular2-select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './components/select/select';
export { SelectModule } from './components/select.module';
16 changes: 16 additions & 0 deletions components/select.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from "@angular/http";

import { SelectComponent } from './select/select';
import { HighlightPipe } from './select/select-pipes';
import { OffClickDirective } from './select/off-click';

@NgModule({
imports: [CommonModule, FormsModule, HttpModule ],
declarations: [SelectComponent, HighlightPipe, OffClickDirective],
exports: [SelectComponent, HighlightPipe, OffClickDirective]
})
export class SelectModule {
}
1 change: 1 addition & 0 deletions components/select/.baseDir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Ignore this file. See https://github.com/grunt-ts/grunt-ts/issues/77
3 changes: 3 additions & 0 deletions components/select/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function escapeRegexp(queryToEscape:string):string {
return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
}
23 changes: 23 additions & 0 deletions components/select/off-click.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Directive, HostListener, Input, OnInit, OnDestroy } from '@angular/core';

@Directive({
selector: '[offClick]'
})

export class OffClickDirective implements OnInit, OnDestroy {
/* tslint:disable */
@Input('offClick') public offClickHandler: any;
/* tslint:enable */
@HostListener('click', ['$event']) public onClick($event: MouseEvent): void {
$event.stopPropagation();
}

public ngOnInit(): any {
setTimeout(() => {document.addEventListener('click', this.offClickHandler);}, 0);
}

public ngOnDestroy(): any {
document.removeEventListener('click', this.offClickHandler);
}

}
40 changes: 40 additions & 0 deletions components/select/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Usage
```typescript
import {SELECT_DIRECTIVES} from 'ng2-select/ng2-select';
```

### Annotations
```typescript
// class Select
@Component({
selector: 'ng-select',
properties: [
'allowClear',
'placeholder',
'items',
'multiple',
'showSearchInputInDropdown']
})
```

### Select properties

- `items` - (`Array<any>`) - Array of items from which to select. Should be an array of objects with `id` and `text` properties.
As convenience, you may also pass an array of strings, in which case the same string is used for both the ID and the text.
Items may be nested by adding a `children` property to any item, whose value should be another array of items. Items that have children may omit having an ID.
If `items` are specified, all items are expected to be available locally and all selection operations operate on this local array only.
If omitted, items are not available locally, and the `query` option should be provided to fetch data.
- `active` (`?Array<any>`) - Initial selection data to set. This should be an object with `id` and `text` properties in the case of input type 'Single',
or an array of such objects otherwise. This option is mutually exclusive with value.
- `allowClear` (`?boolean=false`) (*not yet supported*) - Set to `true` to allow the selection to be cleared. This option only applies to single-value inputs.
- `placeholder` (`?string=''`) - Placeholder text to display when the element has no focus and selected items.
- `disabled` (`?boolean=false`) - When `true`, it specifies that the component should be disabled.
- `multiple` - (`?boolean=false`) - Mode of this component. If set `true` user can select more than one option.
This option only applies to single-value inputs, as multiple-value inputs don't have the search input in the dropdown to begin with.

### Select events

- `data` - it fires during all events of this component; returns `Array<any>` - current selected data
- `selected` - it fires after a new option selected; returns object with `id` and `text` properties that describes a new option.
- `removed` - it fires after an option removed; returns object with `id` and `text` properties that describes a removed option.
- `typed` - it fires after changing of search input; returns `string` with that value.
7 changes: 7 additions & 0 deletions components/select/select-interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface OptionsBehavior {
first():any;
last():any;
prev():any;
next():any;
filter(query:RegExp):any;
}
Loading

0 comments on commit 4d7d01e

Please sign in to comment.