123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- import { EventEmitter, Input, Output } from '@angular/core';
- import { deepCopy, isArray, isPresent, isString, isTrueProperty, isUndefined } from './util';
- import { Ion } from '../components/ion';
- import { TimeoutDebouncer } from './debouncer';
- var BaseInput = (function (_super) {
- __extends(BaseInput, _super);
- function BaseInput(config, elementRef, renderer, name, _defaultValue, _form, _item, _ngControl) {
- var _this = _super.call(this, config, elementRef, renderer, name) || this;
- _this._defaultValue = _defaultValue;
- _this._form = _form;
- _this._item = _item;
- _this._ngControl = _ngControl;
- _this._isFocus = false;
- _this._disabled = false;
- _this._debouncer = new TimeoutDebouncer(0);
- _this._init = false;
- _this._initModel = false;
- /**
- * @output {Range} Emitted when the range selector drag starts.
- */
- _this.ionFocus = new EventEmitter();
- /**
- * @output {Range} Emitted when the range value changes.
- */
- _this.ionChange = new EventEmitter();
- /**
- * @output {Range} Emitted when the range selector drag ends.
- */
- _this.ionBlur = new EventEmitter();
- _form && _form.register(_this);
- _this._value = deepCopy(_this._defaultValue);
- if (_item) {
- (void 0) /* assert */;
- _this.id = name + '-' + _item.registerInput(name);
- _this._labelId = _item.labelId;
- _this._item.setElementClass('item-' + name, true);
- }
- // If the user passed a ngControl we need to set the valueAccessor
- if (_ngControl) {
- _ngControl.valueAccessor = _this;
- }
- return _this;
- }
- Object.defineProperty(BaseInput.prototype, "disabled", {
- /**
- * @input {boolean} If true, the user cannot interact with this element.
- */
- get: function () {
- return this._disabled;
- },
- set: function (val) {
- this.setDisabledState(val);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(BaseInput.prototype, "value", {
- get: function () {
- return this._value;
- },
- set: function (val) {
- if (this._writeValue(val)) {
- this.onChange();
- this._fireIonChange();
- }
- },
- enumerable: true,
- configurable: true
- });
- // 1. Updates the value
- // 2. Calls _inputUpdated()
- // 3. Dispatch onChange events
- BaseInput.prototype.setValue = function (val) {
- this.value = val;
- };
- /**
- * @hidden
- */
- BaseInput.prototype.setDisabledState = function (isDisabled) {
- this._disabled = isDisabled = isTrueProperty(isDisabled);
- this._item && this._item.setElementClass("item-" + this._componentName + "-disabled", isDisabled);
- };
- /**
- * @hidden
- */
- BaseInput.prototype.writeValue = function (val) {
- if (this._writeValue(val)) {
- if (this._initModel) {
- this._fireIonChange();
- }
- else if (this._init) {
- // ngModel fires the first time too late, we need to skip the first ngModel update
- this._initModel = true;
- }
- }
- };
- /**
- * @hidden
- */
- BaseInput.prototype._writeValue = function (val) {
- (void 0) /* assert */;
- if (isUndefined(val)) {
- return false;
- }
- var normalized = (val === null)
- ? deepCopy(this._defaultValue)
- : this._inputNormalize(val);
- var notUpdate = isUndefined(normalized) || !this._inputShouldChange(normalized);
- if (notUpdate) {
- return false;
- }
- (void 0) /* console.debug */;
- this._value = normalized;
- if (this._init) {
- this._inputUpdated();
- }
- return true;
- };
- /**
- * @hidden
- */
- BaseInput.prototype._fireIonChange = function () {
- var _this = this;
- if (this._init) {
- this._debouncer.debounce(function () {
- (void 0) /* assert */;
- _this.ionChange.emit(_this._inputChangeEvent());
- _this._initModel = true;
- });
- }
- };
- /**
- * @hidden
- */
- BaseInput.prototype.registerOnChange = function (fn) {
- this._onChanged = fn;
- };
- /**
- * @hidden
- */
- BaseInput.prototype.registerOnTouched = function (fn) {
- this._onTouched = fn;
- };
- /**
- * @hidden
- */
- BaseInput.prototype._initialize = function () {
- if (this._init) {
- (void 0) /* assert */;
- return;
- }
- this._init = true;
- if (isPresent(this._value)) {
- this._inputUpdated();
- }
- };
- /**
- * @hidden
- */
- BaseInput.prototype._fireFocus = function () {
- if (this._isFocus) {
- return;
- }
- (void 0) /* console.debug */;
- this._form && this._form.setAsFocused(this);
- this._setFocus(true);
- this.ionFocus.emit(this);
- };
- /**
- * @hidden
- */
- BaseInput.prototype._fireBlur = function () {
- if (!this._isFocus) {
- return;
- }
- (void 0) /* console.debug */;
- this._form && this._form.unsetAsFocused(this);
- this._setFocus(false);
- this._fireTouched();
- this.ionBlur.emit(this);
- };
- /**
- * @hidden
- */
- BaseInput.prototype._fireTouched = function () {
- this._onTouched && this._onTouched();
- };
- /**
- * @hidden
- */
- BaseInput.prototype._setFocus = function (isFocused) {
- (void 0) /* assert */;
- (void 0) /* assert */;
- (void 0) /* assert */;
- this._isFocus = isFocused;
- var item = this._item;
- if (item) {
- item.setElementClass('input-has-focus', isFocused);
- item.setElementClass('item-input-has-focus', isFocused);
- }
- this._inputUpdated();
- };
- /**
- * @hidden
- */
- BaseInput.prototype.onChange = function () {
- this._onChanged && this._onChanged(this._inputNgModelEvent());
- };
- /**
- * @hidden
- */
- BaseInput.prototype.isFocus = function () {
- return this._isFocus;
- };
- /**
- * @hidden
- */
- BaseInput.prototype.hasValue = function () {
- var val = this._value;
- if (!isPresent(val)) {
- return false;
- }
- if (isArray(val) || isString(val)) {
- return val.length > 0;
- }
- return true;
- };
- /**
- * @hidden
- */
- BaseInput.prototype.focusNext = function () {
- this._form && this._form.tabFocus(this);
- };
- /**
- * @hidden
- */
- BaseInput.prototype.ngOnDestroy = function () {
- (void 0) /* assert */;
- var form = this._form;
- form && form.deregister(this);
- this._init = false;
- };
- /**
- * @hidden
- */
- BaseInput.prototype.ngAfterContentInit = function () {
- this._initialize();
- };
- /**
- * @hidden
- */
- BaseInput.prototype.initFocus = function () {
- var ele = this._elementRef.nativeElement.querySelector('button');
- ele && ele.focus();
- };
- /**
- * @hidden
- */
- BaseInput.prototype._inputNormalize = function (val) {
- return val;
- };
- /**
- * @hidden
- */
- BaseInput.prototype._inputShouldChange = function (val) {
- return this._value !== val;
- };
- /**
- * @hidden
- */
- BaseInput.prototype._inputChangeEvent = function () {
- return this;
- };
- /**
- * @hidden
- */
- BaseInput.prototype._inputNgModelEvent = function () {
- return this._value;
- };
- /**
- * @hidden
- */
- BaseInput.prototype._inputUpdated = function () {
- (void 0) /* assert */;
- var item = this._item;
- if (item) {
- setControlCss(item, this._ngControl);
- // TODO remove all uses of input-has-value in v4
- var hasValue = this.hasValue();
- item.setElementClass('input-has-value', hasValue);
- item.setElementClass('item-input-has-value', hasValue);
- }
- };
- BaseInput.propDecorators = {
- 'ionFocus': [{ type: Output },],
- 'ionChange': [{ type: Output },],
- 'ionBlur': [{ type: Output },],
- 'disabled': [{ type: Input },],
- };
- return BaseInput;
- }(Ion));
- export { BaseInput };
- function setControlCss(element, control) {
- if (!control) {
- return;
- }
- element.setElementClass('ng-untouched', control.untouched);
- element.setElementClass('ng-touched', control.touched);
- element.setElementClass('ng-pristine', control.pristine);
- element.setElementClass('ng-dirty', control.dirty);
- element.setElementClass('ng-valid', control.valid);
- element.setElementClass('ng-invalid', !control.valid);
- }
- //# sourceMappingURL=base-input.js.map
|