ng2-material-select
Advanced tools
Comparing version 0.0.9 to 0.1.0
@@ -1,2 +0,2 @@ | ||
export declare const Ng2Select: any; | ||
export declare const Ng2SelectModule: any; | ||
export { Ng2SelectModule } from './dist/src/ng2-select.module'; | ||
export { Ng2Select } from './dist/src/ng2-select'; |
"use strict"; | ||
var components = require('./ng2-select.bundle.js'); | ||
exports.Ng2Select = components.Ng2Select; | ||
exports.Ng2SelectModule = components.Ng2SelectModule; | ||
var ng2_select_module_1 = require('./dist/src/ng2-select.module'); | ||
exports.Ng2SelectModule = ng2_select_module_1.Ng2SelectModule; | ||
var ng2_select_1 = require('./dist/src/ng2-select'); | ||
exports.Ng2Select = ng2_select_1.Ng2Select; | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ import { ControlValueAccessor } from '@angular/forms'; |
"use strict"; | ||
var equal = require('equals'); | ||
var SelectAccessor = (function () { | ||
function SelectAccessor() { | ||
const equal = require('equals'); | ||
class SelectAccessor { | ||
constructor() { | ||
this.selected = []; | ||
this._value = undefined; | ||
} | ||
Object.defineProperty(SelectAccessor.prototype, "value", { | ||
get: function () { | ||
return this.multiple ? this.selected : this.options[this._value]; | ||
}, | ||
set: function (value) { | ||
this._value = value; | ||
this._onChangeCallback(this.value); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
get value() { | ||
return this.multiple ? this.selected : this.options[this._value]; | ||
} | ||
; | ||
SelectAccessor.prototype.onTouched = function (value) { | ||
set value(value) { | ||
this._value = value; | ||
this._onChangeCallback(this.value); | ||
} | ||
onTouched(value) { | ||
this._onTouchedCallback(value); | ||
}; | ||
SelectAccessor.prototype.writeValue = function (value) { | ||
} | ||
writeValue(value) { | ||
this._value = this.multiple ? this.selected : this.findIndexValue(value); | ||
}; | ||
SelectAccessor.prototype.findIndexValue = function (value) { | ||
var identifyBy = this.identifyBy; | ||
} | ||
findIndexValue(value) { | ||
const identifyBy = this.identifyBy; | ||
if (identifyBy) { | ||
@@ -32,19 +28,18 @@ if (!value || !value.hasOwnProperty(identifyBy)) { | ||
} | ||
value = this.options.filter(function (item) { return item[identifyBy] === value[identifyBy]; })[0]; | ||
value = this.options.filter(item => item[identifyBy] === value[identifyBy])[0]; | ||
} | ||
return this.options.findIndex(function (item) { return equal(item, value); }); | ||
}; | ||
SelectAccessor.prototype.identify = function (value) { | ||
var identifyBy = this.identifyBy; | ||
return this.options.findIndex(item => equal(item, value)); | ||
} | ||
identify(value) { | ||
const identifyBy = this.identifyBy; | ||
return identifyBy && value ? value[identifyBy] : undefined; | ||
}; | ||
SelectAccessor.prototype.registerOnChange = function (fn) { | ||
} | ||
registerOnChange(fn) { | ||
this._onChangeCallback = fn; | ||
}; | ||
SelectAccessor.prototype.registerOnTouched = function (fn) { | ||
} | ||
registerOnTouched(fn) { | ||
this._onTouchedCallback = fn; | ||
}; | ||
return SelectAccessor; | ||
}()); | ||
} | ||
} | ||
exports.SelectAccessor = SelectAccessor; | ||
//# sourceMappingURL=accessor.js.map |
export declare function Selectable(): (target: any) => void; |
"use strict"; | ||
function Selectable() { | ||
return function (target) { | ||
var toggle = function (item) { | ||
const toggle = function (item) { | ||
if (this.multiple === false) { | ||
@@ -9,3 +9,3 @@ return; | ||
if (this.isSelected(item)) { | ||
this.selected = this.selected.filter(function (value) { return value !== item; }); | ||
this.selected = this.selected.filter(value => value !== item); | ||
} | ||
@@ -17,3 +17,3 @@ else { | ||
Object.assign(target.prototype, { | ||
toggle: toggle | ||
toggle | ||
}); | ||
@@ -20,0 +20,0 @@ }; |
@@ -0,0 +0,0 @@ import { EventEmitter } from '@angular/core'; |
"use strict"; | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -16,16 +11,15 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var core_1 = require('@angular/core'); | ||
var selectable_1 = require('./decorators/selectable'); | ||
var forms_1 = require('@angular/forms'); | ||
var ng2_material_dropdown_1 = require('ng2-material-dropdown'); | ||
var accessor_1 = require('./accessor'); | ||
var CUSTOM_SELECT_VALUE_ACCESSOR = { | ||
const core_1 = require('@angular/core'); | ||
const selectable_1 = require('./decorators/selectable'); | ||
const forms_1 = require('@angular/forms'); | ||
const ng2_material_dropdown_1 = require('ng2-material-dropdown'); | ||
const accessor_1 = require('./accessor'); | ||
const CUSTOM_SELECT_VALUE_ACCESSOR = { | ||
provide: forms_1.NG_VALUE_ACCESSOR, | ||
useExisting: core_1.forwardRef(function () { return Ng2Select; }), | ||
useExisting: core_1.forwardRef(() => Ng2Select), | ||
multi: true | ||
}; | ||
var Ng2Select = (function (_super) { | ||
__extends(Ng2Select, _super); | ||
function Ng2Select() { | ||
_super.apply(this, arguments); | ||
let Ng2Select = class Ng2Select extends accessor_1.SelectAccessor { | ||
constructor() { | ||
super(...arguments); | ||
this.options = []; | ||
@@ -35,3 +29,3 @@ this.multiple = false; | ||
} | ||
Ng2Select.prototype.getSelectedValue = function () { | ||
getSelectedValue() { | ||
if (this.multiple && this.selected.length === 1) { | ||
@@ -41,22 +35,18 @@ return this.displayValue(this.selected[0]); | ||
else { | ||
var index = this.options.indexOf(this.value); | ||
const index = this.options.indexOf(this.value); | ||
return index >= 0 ? this.displayValue(this.options[index]) : undefined; | ||
} | ||
}; | ||
Ng2Select.prototype.displayValue = function (item) { | ||
} | ||
displayValue(item) { | ||
return this.displayBy ? item[this.displayBy] : item; | ||
}; | ||
Object.defineProperty(Ng2Select.prototype, "placeholderDisplay", { | ||
get: function () { | ||
if (this.multiple && this.selected.length > 1) { | ||
return this.selected.length + " items selected"; | ||
} | ||
else { | ||
return this.getSelectedValue() || this.placeholder; | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Ng2Select.prototype.isSelected = function (item) { | ||
} | ||
get placeholderDisplay() { | ||
if (this.multiple && this.selected.length > 1) { | ||
return `${this.selected.length} items selected`; | ||
} | ||
else { | ||
return this.getSelectedValue() || this.placeholder; | ||
} | ||
} | ||
isSelected(item) { | ||
if (this.multiple) { | ||
@@ -68,64 +58,62 @@ return this.selected.indexOf(item) >= 0; | ||
} | ||
}; | ||
Ng2Select.prototype.ngOnInit = function () { | ||
var _this = this; | ||
var state = this.dropdown.state; | ||
state.onItemClicked.subscribe(function (item) { | ||
if (_this.multiple) { | ||
_this.toggle(item.value); | ||
} | ||
ngOnInit() { | ||
const state = this.dropdown.state; | ||
state.onItemClicked.subscribe(item => { | ||
if (this.multiple) { | ||
this.toggle(item.value); | ||
} | ||
_this.value = _this.multiple ? _this.selected : _this.options.indexOf(item.value); | ||
_this.onChange.emit(_this.value); | ||
this.value = this.multiple ? this.selected : this.options.indexOf(item.value); | ||
this.onChange.emit(this.value); | ||
}); | ||
this.dropdown.onShow.subscribe(function () { | ||
if (!_this.value) { | ||
this.dropdown.onShow.subscribe(() => { | ||
if (!this.value) { | ||
return; | ||
} | ||
var index = _this.findIndexValue(_this.value); | ||
var item = _this.dropdown.menu.items.toArray()[index]; | ||
_this.dropdown.state.select(item, false); | ||
const index = this.findIndexValue(this.value); | ||
const item = this.dropdown.menu.items.toArray()[index]; | ||
this.dropdown.state.select(item, false); | ||
}); | ||
console.log(this.selected); | ||
}; | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], Ng2Select.prototype, "placeholder", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Array) | ||
], Ng2Select.prototype, "options", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], Ng2Select.prototype, "displayBy", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], Ng2Select.prototype, "identifyBy", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Boolean) | ||
], Ng2Select.prototype, "multiple", void 0); | ||
__decorate([ | ||
core_1.Output(), | ||
__metadata('design:type', core_1.EventEmitter) | ||
], Ng2Select.prototype, "onChange", void 0); | ||
__decorate([ | ||
core_1.ViewChild(ng2_material_dropdown_1.Ng2Dropdown), | ||
__metadata('design:type', Object) | ||
], Ng2Select.prototype, "dropdown", void 0); | ||
Ng2Select = __decorate([ | ||
core_1.Component({ | ||
selector: 'ng2-select', | ||
providers: [CUSTOM_SELECT_VALUE_ACCESSOR], | ||
styles: [require('./style.scss').toString()], | ||
template: require('./template.html') | ||
}), | ||
selectable_1.Selectable(), | ||
__metadata('design:paramtypes', []) | ||
], Ng2Select); | ||
return Ng2Select; | ||
}(accessor_1.SelectAccessor)); | ||
} | ||
}; | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], Ng2Select.prototype, "placeholder", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Array) | ||
], Ng2Select.prototype, "options", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], Ng2Select.prototype, "displayBy", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], Ng2Select.prototype, "identifyBy", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Boolean) | ||
], Ng2Select.prototype, "multiple", void 0); | ||
__decorate([ | ||
core_1.Output(), | ||
__metadata('design:type', core_1.EventEmitter) | ||
], Ng2Select.prototype, "onChange", void 0); | ||
__decorate([ | ||
core_1.ViewChild(ng2_material_dropdown_1.Ng2Dropdown), | ||
__metadata('design:type', Object) | ||
], Ng2Select.prototype, "dropdown", void 0); | ||
Ng2Select = __decorate([ | ||
core_1.Component({ | ||
selector: 'ng2-select', | ||
providers: [CUSTOM_SELECT_VALUE_ACCESSOR], | ||
styles: [require('./style.scss').toString()], | ||
template: require('./template.html') | ||
}), | ||
selectable_1.Selectable(), | ||
__metadata('design:paramtypes', []) | ||
], Ng2Select); | ||
exports.Ng2Select = Ng2Select; | ||
//# sourceMappingURL=ng2-select.js.map |
export declare class Ng2SelectModule { | ||
} |
@@ -11,29 +11,26 @@ "use strict"; | ||
}; | ||
var core_1 = require('@angular/core'); | ||
var ng2_select_1 = require('./ng2-select'); | ||
var forms_1 = require('@angular/forms'); | ||
var common_1 = require('@angular/common'); | ||
var ng2_material_dropdown_1 = require('ng2-material-dropdown'); | ||
var Ng2SelectModule = (function () { | ||
function Ng2SelectModule() { | ||
} | ||
Ng2SelectModule = __decorate([ | ||
core_1.NgModule({ | ||
imports: [ | ||
common_1.CommonModule, | ||
forms_1.ReactiveFormsModule, | ||
ng2_material_dropdown_1.Ng2DropdownModule | ||
], | ||
declarations: [ | ||
ng2_select_1.Ng2Select | ||
], | ||
exports: [ | ||
ng2_select_1.Ng2Select | ||
] | ||
}), | ||
__metadata('design:paramtypes', []) | ||
], Ng2SelectModule); | ||
return Ng2SelectModule; | ||
}()); | ||
const core_1 = require('@angular/core'); | ||
const ng2_select_1 = require('./ng2-select'); | ||
const forms_1 = require('@angular/forms'); | ||
const common_1 = require('@angular/common'); | ||
const ng2_material_dropdown_1 = require('ng2-material-dropdown'); | ||
let Ng2SelectModule = class Ng2SelectModule { | ||
}; | ||
Ng2SelectModule = __decorate([ | ||
core_1.NgModule({ | ||
imports: [ | ||
common_1.CommonModule, | ||
forms_1.ReactiveFormsModule, | ||
ng2_material_dropdown_1.Ng2DropdownModule | ||
], | ||
declarations: [ | ||
ng2_select_1.Ng2Select | ||
], | ||
exports: [ | ||
ng2_select_1.Ng2Select | ||
] | ||
}), | ||
__metadata('design:paramtypes', []) | ||
], Ng2SelectModule); | ||
exports.Ng2SelectModule = Ng2SelectModule; | ||
//# sourceMappingURL=ng2-select.module.js.map |
@@ -1,3 +0,2 @@ | ||
const components = require('./ng2-select.bundle.js'); | ||
export const Ng2Select = components.Ng2Select; | ||
export const Ng2SelectModule = components.Ng2SelectModule; | ||
export { Ng2SelectModule } from './dist/src/ng2-select.module'; | ||
export { Ng2Select } from './dist/src/ng2-select'; |
{ | ||
"name": "ng2-material-select", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "Angular 2 material-like Select Component", | ||
@@ -84,8 +84,7 @@ "scripts": { | ||
"homepage": "https://github.com/Gbuomprisco/ng2-material-select", | ||
"main": "./dist/index.js", | ||
"main": "./dist/ng2-select.bundle.js", | ||
"files": [ | ||
"dist", | ||
"index.js", | ||
"index.ts" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
174037
22
2051