UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

1,458 lines (1,446 loc) 45.6 kB
import { __decorate, __metadata } from 'tslib'; import { Platform, PlatformModule } from '@angular/cdk/platform'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, forwardRef, ChangeDetectorRef, ViewChild, Input, Output, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { fromEvent, merge, Subscription } from 'rxjs'; import { filter, tap, pluck, map, distinctUntilChanged, takeUntil } from 'rxjs/operators'; import { shallowCopyArray, silentEvent, ensureNumberInRange, getPrecision, getPercent, getElementOffset, arraysEqual, InputBoolean, InputNumber } from 'ng-zorro-antd/core'; import { CommonModule } from '@angular/common'; import { NzTooltipDirective, NzToolTipModule } from 'ng-zorro-antd/tooltip'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Alibaba.com All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ /** * @record */ function MarkObj() { } if (false) { /** @type {?|undefined} */ MarkObj.prototype.style; /** @type {?} */ MarkObj.prototype.label; } class Marks { } /** * Processed steps that would be passed to sub components. * @record */ function ExtendedMark() { } if (false) { /** @type {?} */ ExtendedMark.prototype.value; /** @type {?} */ ExtendedMark.prototype.offset; /** @type {?} */ ExtendedMark.prototype.config; } /** * Marks that would be rendered. * @record */ function DisplayedMark() { } if (false) { /** @type {?} */ DisplayedMark.prototype.active; /** @type {?} */ DisplayedMark.prototype.label; /** @type {?|undefined} */ DisplayedMark.prototype.style; } /** * Steps that would be rendered. * @record */ function DisplayedStep() { } if (false) { /** @type {?} */ DisplayedStep.prototype.active; /** @type {?|undefined} */ DisplayedStep.prototype.style; } /** * @record */ function SliderHandler() { } if (false) { /** @type {?} */ SliderHandler.prototype.offset; /** @type {?} */ SliderHandler.prototype.value; /** @type {?} */ SliderHandler.prototype.active; } /** * @param {?} value * @return {?} */ function isValueARange(value) { if (value instanceof Array) { return value.length === 2; } else { return false; } } /** * @param {?} config * @return {?} */ function isConfigAObject(config) { return config instanceof Object; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Alibaba.com All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ /** * @return {?} */ function getValueTypeNotMatchError() { return new Error(`The "nzRange" can't match the "ngModel"'s type, please check these properties: "nzRange", "ngModel", "nzDefaultValue".`); } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzSliderComponent { /** * @param {?} cdr * @param {?} platform */ constructor(cdr, platform) { this.cdr = cdr; this.platform = platform; this.nzDisabled = false; this.nzDots = false; this.nzIncluded = true; this.nzRange = false; this.nzVertical = false; this.nzDefaultValue = null; this.nzMarks = null; this.nzMax = 100; this.nzMin = 0; this.nzStep = 1; this.nzTooltipVisible = 'default'; this.nzTooltipPlacement = 'top'; this.nzOnAfterChange = new EventEmitter(); this.value = null; this.cacheSliderStart = null; this.cacheSliderLength = null; this.activeValueIndex = undefined; // Current activated handle's index ONLY for range=true // Current activated handle's index ONLY for range=true this.track = { offset: null, length: null }; // Track's offset and length // "steps" in array type with more data & FILTER out the invalid mark this.bounds = { lower: null, upper: null }; // now for nz-slider-step // now for nz-slider-step this.isDragging = false; // Current dragging state } /** * @return {?} */ ngOnInit() { this.handles = this.generateHandles(this.nzRange ? 2 : 1); this.sliderDOM = this.slider.nativeElement; this.marksArray = this.nzMarks ? this.generateMarkItems(this.nzMarks) : null; if (this.platform.isBrowser) { this.createDraggingObservables(); } this.toggleDragDisabled(this.nzDisabled); if (this.getValue() === null) { this.setValue(this.formatValue(null)); } } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { const { nzDisabled, nzMarks, nzRange } = changes; if (nzDisabled && !nzDisabled.firstChange) { this.toggleDragDisabled(nzDisabled.currentValue); } else if (nzMarks && !nzMarks.firstChange) { this.marksArray = this.nzMarks ? this.generateMarkItems(this.nzMarks) : null; } else if (nzRange && !nzRange.firstChange) { this.setValue(this.formatValue(null)); } } /** * @return {?} */ ngOnDestroy() { this.unsubscribeDrag(); } /** * @param {?} val * @return {?} */ writeValue(val) { this.setValue(val, true); } /** * @param {?} _value * @return {?} */ onValueChange(_value) { } /** * @return {?} */ onTouched() { } /** * @param {?} fn * @return {?} */ registerOnChange(fn) { this.onValueChange = fn; } /** * @param {?} fn * @return {?} */ registerOnTouched(fn) { this.onTouched = fn; } /** * @param {?} isDisabled * @return {?} */ setDisabledState(isDisabled) { this.nzDisabled = isDisabled; this.toggleDragDisabled(isDisabled); } /** * @private * @param {?} value * @param {?=} isWriteValue * @return {?} */ setValue(value, isWriteValue = false) { if (isWriteValue) { this.value = this.formatValue(value); this.updateTrackAndHandles(); } else if (!this.valuesEqual((/** @type {?} */ (this.value)), (/** @type {?} */ (value)))) { this.value = value; this.updateTrackAndHandles(); this.onValueChange(this.getValue(true)); } } /** * @private * @param {?=} cloneAndSort * @return {?} */ getValue(cloneAndSort = false) { if (cloneAndSort && this.value && isValueARange(this.value)) { return shallowCopyArray(this.value).sort((/** * @param {?} a * @param {?} b * @return {?} */ (a, b) => a - b)); } return (/** @type {?} */ (this.value)); } /** * Clone & sort current value and convert them to offsets, then return the new one. * @private * @param {?=} value * @return {?} */ getValueToOffset(value) { /** @type {?} */ let normalizedValue = value; if (typeof normalizedValue === 'undefined') { normalizedValue = this.getValue(true); } return isValueARange(normalizedValue) ? normalizedValue.map((/** * @param {?} val * @return {?} */ val => this.valueToOffset(val))) : this.valueToOffset(normalizedValue); } /** * Find the closest value to be activated (only for range = true). * @private * @param {?} pointerValue * @return {?} */ setActiveValueIndex(pointerValue) { /** @type {?} */ const value = this.getValue(); if (isValueARange(value)) { /** @type {?} */ let minimal = null; /** @type {?} */ let gap; /** @type {?} */ let activeIndex = -1; value.forEach((/** * @param {?} val * @param {?} index * @return {?} */ (val, index) => { gap = Math.abs(pointerValue - val); if (minimal === null || gap < (/** @type {?} */ (minimal))) { minimal = gap; activeIndex = index; } })); this.activeValueIndex = activeIndex; } } /** * @private * @param {?} pointerValue * @return {?} */ setActiveValue(pointerValue) { if (isValueARange((/** @type {?} */ (this.value)))) { /** @type {?} */ const newValue = shallowCopyArray((/** @type {?} */ (this.value))); newValue[(/** @type {?} */ (this.activeValueIndex))] = pointerValue; this.setValue(newValue); } else { this.setValue(pointerValue); } } /** * Update track and handles' position and length. * @private * @return {?} */ updateTrackAndHandles() { /** @type {?} */ const value = this.getValue(); /** @type {?} */ const offset = this.getValueToOffset(value); /** @type {?} */ const valueSorted = this.getValue(true); /** @type {?} */ const offsetSorted = this.getValueToOffset(valueSorted); /** @type {?} */ const boundParts = isValueARange(valueSorted) ? valueSorted : [0, valueSorted]; /** @type {?} */ const trackParts = isValueARange(offsetSorted) ? [offsetSorted[0], offsetSorted[1] - offsetSorted[0]] : [0, offsetSorted]; this.handles.forEach((/** * @param {?} handle * @param {?} index * @return {?} */ (handle, index) => { handle.offset = isValueARange(offset) ? offset[index] : offset; handle.value = isValueARange(value) ? value[index] : value || 0; })); [this.bounds.lower, this.bounds.upper] = boundParts; [this.track.offset, this.track.length] = trackParts; this.cdr.markForCheck(); } /** * @private * @param {?} value * @return {?} */ onDragStart(value) { this.toggleDragMoving(true); this.cacheSliderProperty(); this.setActiveValueIndex(value); this.setActiveValue(value); this.showHandleTooltip(this.nzRange ? this.activeValueIndex : 0); } /** * @private * @param {?} value * @return {?} */ onDragMove(value) { this.setActiveValue(value); this.cdr.markForCheck(); } /** * @private * @return {?} */ onDragEnd() { this.nzOnAfterChange.emit(this.getValue(true)); this.toggleDragMoving(false); this.cacheSliderProperty(true); this.hideAllHandleTooltip(); this.cdr.markForCheck(); } /** * Create user interactions handles. * @private * @return {?} */ createDraggingObservables() { /** @type {?} */ const sliderDOM = this.sliderDOM; /** @type {?} */ const orientField = this.nzVertical ? 'pageY' : 'pageX'; /** @type {?} */ const mouse = { start: 'mousedown', move: 'mousemove', end: 'mouseup', pluckKey: [orientField] }; /** @type {?} */ const touch = { start: 'touchstart', move: 'touchmove', end: 'touchend', pluckKey: ['touches', '0', orientField], filter: (/** * @param {?} e * @return {?} */ (e) => e instanceof TouchEvent) }; [mouse, touch].forEach((/** * @param {?} source * @return {?} */ source => { const { start, move, end, pluckKey, filter: filterFunc = (/** * @return {?} */ () => true) } = source; source.startPlucked$ = fromEvent(sliderDOM, start).pipe(filter(filterFunc), tap(silentEvent), pluck(...pluckKey), map((/** * @param {?} position * @return {?} */ (position) => this.findClosestValue(position)))); source.end$ = fromEvent(document, end); source.moveResolved$ = fromEvent(document, move).pipe(filter(filterFunc), tap(silentEvent), pluck(...pluckKey), distinctUntilChanged(), map((/** * @param {?} position * @return {?} */ (position) => this.findClosestValue(position))), distinctUntilChanged(), takeUntil(source.end$)); })); this.dragStart$ = merge((/** @type {?} */ (mouse.startPlucked$)), (/** @type {?} */ (touch.startPlucked$))); this.dragMove$ = merge((/** @type {?} */ (mouse.moveResolved$)), (/** @type {?} */ (touch.moveResolved$))); this.dragEnd$ = merge((/** @type {?} */ (mouse.end$)), (/** @type {?} */ (touch.end$))); } /** * @private * @param {?=} periods * @return {?} */ subscribeDrag(periods = ['start', 'move', 'end']) { if (periods.indexOf('start') !== -1 && this.dragStart$ && !this.dragStart_) { this.dragStart_ = this.dragStart$.subscribe(this.onDragStart.bind(this)); } if (periods.indexOf('move') !== -1 && this.dragMove$ && !this.dragMove_) { this.dragMove_ = this.dragMove$.subscribe(this.onDragMove.bind(this)); } if (periods.indexOf('end') !== -1 && this.dragEnd$ && !this.dragEnd_) { this.dragEnd_ = this.dragEnd$.subscribe(this.onDragEnd.bind(this)); } } /** * @private * @param {?=} periods * @return {?} */ unsubscribeDrag(periods = ['start', 'move', 'end']) { if (periods.indexOf('start') !== -1 && this.dragStart_) { this.dragStart_.unsubscribe(); this.dragStart_ = null; } if (periods.indexOf('move') !== -1 && this.dragMove_) { this.dragMove_.unsubscribe(); this.dragMove_ = null; } if (periods.indexOf('end') !== -1 && this.dragEnd_) { this.dragEnd_.unsubscribe(); this.dragEnd_ = null; } } /** * @private * @param {?} movable * @return {?} */ toggleDragMoving(movable) { /** @type {?} */ const periods = ['move', 'end']; if (movable) { this.isDragging = true; this.subscribeDrag(periods); } else { this.isDragging = false; this.unsubscribeDrag(periods); } } /** * @private * @param {?} disabled * @return {?} */ toggleDragDisabled(disabled) { if (disabled) { this.unsubscribeDrag(); } else { this.subscribeDrag(['start']); } } /** * @private * @param {?} position * @return {?} */ findClosestValue(position) { /** @type {?} */ const sliderStart = this.getSliderStartPosition(); /** @type {?} */ const sliderLength = this.getSliderLength(); /** @type {?} */ const ratio = ensureNumberInRange((position - sliderStart) / sliderLength, 0, 1); /** @type {?} */ const val = (this.nzMax - this.nzMin) * (this.nzVertical ? 1 - ratio : ratio) + this.nzMin; /** @type {?} */ const points = this.nzMarks === null ? [] : Object.keys(this.nzMarks).map(parseFloat); if (this.nzStep !== null && !this.nzDots) { /** @type {?} */ const closestOne = Math.round(val / this.nzStep) * this.nzStep; points.push(closestOne); } /** @type {?} */ const gaps = points.map((/** * @param {?} point * @return {?} */ point => Math.abs(val - point))); /** @type {?} */ const closest = points[gaps.indexOf(Math.min(...gaps))]; return this.nzStep === null ? closest : parseFloat(closest.toFixed(getPrecision(this.nzStep))); } /** * @private * @param {?} value * @return {?} */ valueToOffset(value) { return getPercent(this.nzMin, this.nzMax, value); } /** * @private * @return {?} */ getSliderStartPosition() { if (this.cacheSliderStart !== null) { return this.cacheSliderStart; } /** @type {?} */ const offset = getElementOffset(this.sliderDOM); return this.nzVertical ? offset.top : offset.left; } /** * @private * @return {?} */ getSliderLength() { if (this.cacheSliderLength !== null) { return this.cacheSliderLength; } /** @type {?} */ const sliderDOM = this.sliderDOM; return this.nzVertical ? sliderDOM.clientHeight : sliderDOM.clientWidth; } /** * Cache DOM layout/reflow operations for performance (may not necessary?) * @private * @param {?=} remove * @return {?} */ cacheSliderProperty(remove = false) { this.cacheSliderStart = remove ? null : this.getSliderStartPosition(); this.cacheSliderLength = remove ? null : this.getSliderLength(); } /** * @private * @param {?} value * @return {?} */ formatValue(value) { /** @type {?} */ let res = value; if (!this.assertValueValid((/** @type {?} */ (value)))) { res = this.nzDefaultValue === null ? (this.nzRange ? [this.nzMin, this.nzMax] : this.nzMin) : this.nzDefaultValue; } else { res = isValueARange((/** @type {?} */ (value))) ? ((/** @type {?} */ (value))).map((/** * @param {?} val * @return {?} */ val => ensureNumberInRange(val, this.nzMin, this.nzMax))) : ensureNumberInRange((/** @type {?} */ (value)), this.nzMin, this.nzMax); } return res; } /** * Check if value is valid and throw error if value-type/range not match. * @private * @param {?} value * @return {?} */ assertValueValid(value) { if (!Array.isArray(value) && isNaN(typeof value !== 'number' ? parseFloat(value) : value)) { return false; } return this.assertValueTypeMatch(value); } /** * Assert that if `this.nzRange` is `true`, value is also a range, vice versa. * @private * @param {?} value * @return {?} */ assertValueTypeMatch(value) { if (!value) { return true; } else if (isValueARange(value) !== this.nzRange) { throw getValueTypeNotMatchError(); } else { return true; } } /** * @private * @param {?} valA * @param {?} valB * @return {?} */ valuesEqual(valA, valB) { if (typeof valA !== typeof valB) { return false; } return isValueARange(valA) && isValueARange(valB) ? arraysEqual(valA, valB) : valA === valB; } /** * Show one handle's tooltip and hide others'. * @private * @param {?=} handleIndex * @return {?} */ showHandleTooltip(handleIndex = 0) { this.handles.forEach((/** * @param {?} handle * @param {?} index * @return {?} */ (handle, index) => { handle.active = index === handleIndex; })); } /** * @private * @return {?} */ hideAllHandleTooltip() { this.handles.forEach((/** * @param {?} handle * @return {?} */ handle => (handle.active = false))); } /** * @private * @param {?} amount * @return {?} */ generateHandles(amount) { return Array(amount) .fill(0) .map((/** * @return {?} */ () => ({ offset: null, value: null, active: false }))); } /** * @private * @param {?} marks * @return {?} */ generateMarkItems(marks) { /** @type {?} */ const marksArray = []; for (const key in marks) { /** @type {?} */ const mark = marks[key]; /** @type {?} */ const val = typeof key === 'number' ? key : parseFloat(key); if (val >= this.nzMin && val <= this.nzMax) { marksArray.push({ value: val, offset: this.valueToOffset(val), config: mark }); } } return marksArray.length ? marksArray : null; } } NzSliderComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-slider', exportAs: 'nzSlider', preserveWhitespaces: false, providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ () => NzSliderComponent)), multi: true } ], template: "<div #slider\n class=\"ant-slider\"\n [class.ant-slider-disabled]=\"nzDisabled\"\n [class.ant-slider-vertical]=\"nzVertical\"\n [class.ant-slider-with-marks]=\"marksArray\">\n <div class=\"ant-slider-rail\"></div>\n <nz-slider-track\n [nzVertical]=\"nzVertical\"\n [nzIncluded]=\"nzIncluded\"\n [nzOffset]=\"track.offset\"\n [nzLength]=\"track.length\"></nz-slider-track>\n <nz-slider-step\n *ngIf=\"marksArray\"\n [nzVertical]=\"nzVertical\"\n [nzLowerBound]=\"bounds.lower\"\n [nzUpperBound]=\"bounds.upper\"\n [nzMarksArray]=\"marksArray\"\n [nzIncluded]=\"nzIncluded\"></nz-slider-step>\n <nz-slider-handle\n *ngFor=\"let handle of handles\"\n [nzVertical]=\"nzVertical\"\n [nzOffset]=\"handle.offset\"\n [nzValue]=\"handle.value\"\n [nzActive]=\"handle.active\"\n [nzTipFormatter]=\"nzTipFormatter\"\n [nzTooltipVisible]=\"nzTooltipVisible\"\n [nzTooltipPlacement]=\"nzTooltipPlacement\"\n ></nz-slider-handle>\n <nz-slider-marks\n *ngIf=\"marksArray\"\n [nzVertical]=\"nzVertical\"\n [nzMin]=\"nzMin\"\n [nzMax]=\"nzMax\"\n [nzLowerBound]=\"bounds.lower\"\n [nzUpperBound]=\"bounds.upper\"\n [nzMarksArray]=\"marksArray\"\n [nzIncluded]=\"nzIncluded\"></nz-slider-marks>\n</div>" }] } ]; /** @nocollapse */ NzSliderComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: Platform } ]; NzSliderComponent.propDecorators = { slider: [{ type: ViewChild, args: ['slider', { static: true },] }], nzDisabled: [{ type: Input }], nzDots: [{ type: Input }], nzIncluded: [{ type: Input }], nzRange: [{ type: Input }], nzVertical: [{ type: Input }], nzDefaultValue: [{ type: Input }], nzMarks: [{ type: Input }], nzMax: [{ type: Input }], nzMin: [{ type: Input }], nzStep: [{ type: Input }], nzTooltipVisible: [{ type: Input }], nzTooltipPlacement: [{ type: Input }], nzTipFormatter: [{ type: Input }], nzOnAfterChange: [{ type: Output }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderComponent.prototype, "nzDisabled", void 0); __decorate([ InputBoolean(), __metadata("design:type", Boolean) ], NzSliderComponent.prototype, "nzDots", void 0); __decorate([ InputBoolean(), __metadata("design:type", Boolean) ], NzSliderComponent.prototype, "nzIncluded", void 0); __decorate([ InputBoolean(), __metadata("design:type", Boolean) ], NzSliderComponent.prototype, "nzRange", void 0); __decorate([ InputBoolean(), __metadata("design:type", Boolean) ], NzSliderComponent.prototype, "nzVertical", void 0); if (false) { /** @type {?} */ NzSliderComponent.prototype.slider; /** @type {?} */ NzSliderComponent.prototype.nzDisabled; /** @type {?} */ NzSliderComponent.prototype.nzDots; /** @type {?} */ NzSliderComponent.prototype.nzIncluded; /** @type {?} */ NzSliderComponent.prototype.nzRange; /** @type {?} */ NzSliderComponent.prototype.nzVertical; /** @type {?} */ NzSliderComponent.prototype.nzDefaultValue; /** @type {?} */ NzSliderComponent.prototype.nzMarks; /** @type {?} */ NzSliderComponent.prototype.nzMax; /** @type {?} */ NzSliderComponent.prototype.nzMin; /** @type {?} */ NzSliderComponent.prototype.nzStep; /** @type {?} */ NzSliderComponent.prototype.nzTooltipVisible; /** @type {?} */ NzSliderComponent.prototype.nzTooltipPlacement; /** @type {?} */ NzSliderComponent.prototype.nzTipFormatter; /** @type {?} */ NzSliderComponent.prototype.nzOnAfterChange; /** @type {?} */ NzSliderComponent.prototype.value; /** @type {?} */ NzSliderComponent.prototype.sliderDOM; /** @type {?} */ NzSliderComponent.prototype.cacheSliderStart; /** @type {?} */ NzSliderComponent.prototype.cacheSliderLength; /** @type {?} */ NzSliderComponent.prototype.activeValueIndex; /** @type {?} */ NzSliderComponent.prototype.track; /** @type {?} */ NzSliderComponent.prototype.handles; /** @type {?} */ NzSliderComponent.prototype.marksArray; /** @type {?} */ NzSliderComponent.prototype.bounds; /** @type {?} */ NzSliderComponent.prototype.isDragging; /** * @type {?} * @private */ NzSliderComponent.prototype.dragStart$; /** * @type {?} * @private */ NzSliderComponent.prototype.dragMove$; /** * @type {?} * @private */ NzSliderComponent.prototype.dragEnd$; /** * @type {?} * @private */ NzSliderComponent.prototype.dragStart_; /** * @type {?} * @private */ NzSliderComponent.prototype.dragMove_; /** * @type {?} * @private */ NzSliderComponent.prototype.dragEnd_; /** * @type {?} * @private */ NzSliderComponent.prototype.cdr; /** * @type {?} * @private */ NzSliderComponent.prototype.platform; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzSliderHandleComponent { /** * @param {?} sliderComponent * @param {?} cdr */ constructor(sliderComponent, cdr) { this.sliderComponent = sliderComponent; this.cdr = cdr; this.nzTooltipVisible = 'default'; this.nzActive = false; this.style = {}; this.hovers_ = new Subscription(); this.enterHandle = (/** * @return {?} */ () => { if (!this.sliderComponent.isDragging) { this.toggleTooltip(true); this.updateTooltipPosition(); this.cdr.detectChanges(); } }); this.leaveHandle = (/** * @return {?} */ () => { if (!this.sliderComponent.isDragging) { this.toggleTooltip(false); this.cdr.detectChanges(); } }); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { const { nzOffset, nzValue, nzActive, nzTooltipVisible } = changes; if (nzOffset) { this.updateStyle(); } if (nzValue) { this.updateTooltipTitle(); this.updateTooltipPosition(); } if (nzActive) { if (nzActive.currentValue) { this.toggleTooltip(true); } else { this.toggleTooltip(false); } } if (nzTooltipVisible && nzTooltipVisible.currentValue === 'always') { Promise.resolve().then((/** * @return {?} */ () => this.toggleTooltip(true, true))); } } /** * @return {?} */ ngOnDestroy() { this.hovers_.unsubscribe(); } /** * @private * @param {?} show * @param {?=} force * @return {?} */ toggleTooltip(show, force = false) { if (!force && (this.nzTooltipVisible !== 'default' || !this.tooltip)) { return; } if (show) { this.tooltip.show(); } else { this.tooltip.hide(); } } /** * @private * @return {?} */ updateTooltipTitle() { this.tooltipTitle = this.nzTipFormatter ? this.nzTipFormatter(this.nzValue) : `${this.nzValue}`; } /** * @private * @return {?} */ updateTooltipPosition() { if (this.tooltip) { Promise.resolve().then((/** * @return {?} */ () => this.tooltip.updatePosition())); } } /** * @private * @return {?} */ updateStyle() { this.style[this.nzVertical ? 'bottom' : 'left'] = `${this.nzOffset}%`; this.cdr.markForCheck(); } } NzSliderHandleComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-slider-handle', exportAs: 'nzSliderHandle', preserveWhitespaces: false, template: "<div nz-tooltip\n *ngIf=\"nzTipFormatter !== null && nzTooltipVisible !== 'never'\"\n class=\"ant-slider-handle\"\n [ngStyle]=\"style\"\n [nzTitle]=\"tooltipTitle\"\n [nzTrigger]=\"null\"\n [nzPlacement]=\"nzTooltipPlacement\"></div>\n<div *ngIf=\"nzTipFormatter === null || nzTooltipVisible === 'never'\"\n class=\"ant-slider-handle\"\n [ngStyle]=\"style\"></div>\n", host: { '(mouseenter)': 'enterHandle()', '(mouseleave)': 'leaveHandle()' } }] } ]; /** @nocollapse */ NzSliderHandleComponent.ctorParameters = () => [ { type: NzSliderComponent }, { type: ChangeDetectorRef } ]; NzSliderHandleComponent.propDecorators = { tooltip: [{ type: ViewChild, args: [NzTooltipDirective, { static: false },] }], nzVertical: [{ type: Input }], nzOffset: [{ type: Input }], nzValue: [{ type: Input }], nzTooltipVisible: [{ type: Input }], nzTooltipPlacement: [{ type: Input }], nzTipFormatter: [{ type: Input }], nzActive: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderHandleComponent.prototype, "nzActive", void 0); if (false) { /** @type {?} */ NzSliderHandleComponent.prototype.tooltip; /** @type {?} */ NzSliderHandleComponent.prototype.nzVertical; /** @type {?} */ NzSliderHandleComponent.prototype.nzOffset; /** @type {?} */ NzSliderHandleComponent.prototype.nzValue; /** @type {?} */ NzSliderHandleComponent.prototype.nzTooltipVisible; /** @type {?} */ NzSliderHandleComponent.prototype.nzTooltipPlacement; /** @type {?} */ NzSliderHandleComponent.prototype.nzTipFormatter; /** @type {?} */ NzSliderHandleComponent.prototype.nzActive; /** @type {?} */ NzSliderHandleComponent.prototype.tooltipTitle; /** @type {?} */ NzSliderHandleComponent.prototype.style; /** * @type {?} * @private */ NzSliderHandleComponent.prototype.hovers_; /** @type {?} */ NzSliderHandleComponent.prototype.enterHandle; /** @type {?} */ NzSliderHandleComponent.prototype.leaveHandle; /** * @type {?} * @private */ NzSliderHandleComponent.prototype.sliderComponent; /** * @type {?} * @private */ NzSliderHandleComponent.prototype.cdr; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzSliderMarksComponent { constructor() { this.nzLowerBound = null; this.nzUpperBound = null; this.nzVertical = false; this.nzIncluded = false; } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.nzMarksArray) { this.buildMarks(); } if (changes.nzMarksArray || changes.nzLowerBound || changes.nzUpperBound) { this.togglePointActive(); } } /** * @param {?} _index * @param {?} mark * @return {?} */ trackById(_index, mark) { return mark.value; } /** * @private * @return {?} */ buildMarks() { /** @type {?} */ const range = this.nzMax - this.nzMin; this.marks = this.nzMarksArray.map((/** * @param {?} mark * @return {?} */ mark => { const { value, offset, config } = mark; /** @type {?} */ const style = this.getMarkStyles(value, range, config); /** @type {?} */ const label = isConfigAObject(config) ? config.label : config; return { label, offset, style, value, config, active: false }; })); } /** * @private * @param {?} value * @param {?} range * @param {?} config * @return {?} */ getMarkStyles(value, range, config) { /** @type {?} */ let style; if (this.nzVertical) { style = { marginBottom: '-50%', bottom: `${((value - this.nzMin) / range) * 100}%` }; } else { style = { transform: `translate3d(-50%, 0, 0)`, left: `${((value - this.nzMin) / range) * 100}%` }; } if (isConfigAObject(config) && config.style) { style = Object.assign({}, style, config.style); } return style; } /** * @private * @return {?} */ togglePointActive() { if (this.marks && this.nzLowerBound !== null && this.nzUpperBound !== null) { this.marks.forEach((/** * @param {?} mark * @return {?} */ mark => { /** @type {?} */ const value = mark.value; /** @type {?} */ const isActive = (!this.nzIncluded && value === this.nzUpperBound) || (this.nzIncluded && value <= (/** @type {?} */ (this.nzUpperBound)) && value >= (/** @type {?} */ (this.nzLowerBound))); mark.active = isActive; })); } } } NzSliderMarksComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, preserveWhitespaces: false, selector: 'nz-slider-marks', exportAs: 'nzSliderMarks', template: "<div class=\"ant-slider-mark\">\n <span\n class=\"ant-slider-mark-text\"\n *ngFor=\"let attr of marks; trackBy: trackById\"\n [class.ant-slider-mark-active]=\"attr.active\"\n [ngStyle]=\"attr.style\"\n [innerHTML]=\"attr.label\">\n </span>\n</div>" }] } ]; NzSliderMarksComponent.propDecorators = { nzLowerBound: [{ type: Input }], nzUpperBound: [{ type: Input }], nzMarksArray: [{ type: Input }], nzMin: [{ type: Input }], nzMax: [{ type: Input }], nzVertical: [{ type: Input }], nzIncluded: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderMarksComponent.prototype, "nzVertical", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderMarksComponent.prototype, "nzIncluded", void 0); if (false) { /** @type {?} */ NzSliderMarksComponent.prototype.nzLowerBound; /** @type {?} */ NzSliderMarksComponent.prototype.nzUpperBound; /** @type {?} */ NzSliderMarksComponent.prototype.nzMarksArray; /** @type {?} */ NzSliderMarksComponent.prototype.nzMin; /** @type {?} */ NzSliderMarksComponent.prototype.nzMax; /** @type {?} */ NzSliderMarksComponent.prototype.nzVertical; /** @type {?} */ NzSliderMarksComponent.prototype.nzIncluded; /** @type {?} */ NzSliderMarksComponent.prototype.marks; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzSliderStepComponent { constructor() { this.nzLowerBound = null; this.nzUpperBound = null; this.nzVertical = false; this.nzIncluded = false; } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.nzMarksArray) { this.buildSteps(); } if (changes.nzMarksArray || changes.nzLowerBound || changes.nzUpperBound) { this.togglePointActive(); } } /** * @param {?} _index * @param {?} step * @return {?} */ trackById(_index, step) { return step.value; } /** * @private * @return {?} */ buildSteps() { /** @type {?} */ const orient = this.nzVertical ? 'bottom' : 'left'; this.steps = this.nzMarksArray.map((/** * @param {?} mark * @return {?} */ mark => { const { value, offset, config } = mark; return { value, offset, config, active: false, style: { [orient]: `${offset}%` } }; })); } /** * @private * @return {?} */ togglePointActive() { if (this.steps && this.nzLowerBound !== null && this.nzUpperBound !== null) { this.steps.forEach((/** * @param {?} step * @return {?} */ step => { /** @type {?} */ const value = step.value; /** @type {?} */ const isActive = (!this.nzIncluded && value === this.nzUpperBound) || (this.nzIncluded && value <= (/** @type {?} */ (this.nzUpperBound)) && value >= (/** @type {?} */ (this.nzLowerBound))); step.active = isActive; })); } } } NzSliderStepComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-slider-step', exportAs: 'nzSliderStep', preserveWhitespaces: false, template: "<div class=\"ant-slider-step\">\n <span\n class=\"ant-slider-dot\"\n *ngFor=\"let mark of steps; trackBy: trackById\"\n [class.ant-slider-dot-active]=\"mark.active\"\n [ngStyle]=\"mark.style\">\n </span>\n</div>" }] } ]; NzSliderStepComponent.propDecorators = { nzLowerBound: [{ type: Input }], nzUpperBound: [{ type: Input }], nzMarksArray: [{ type: Input }], nzVertical: [{ type: Input }], nzIncluded: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderStepComponent.prototype, "nzVertical", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderStepComponent.prototype, "nzIncluded", void 0); if (false) { /** @type {?} */ NzSliderStepComponent.prototype.nzLowerBound; /** @type {?} */ NzSliderStepComponent.prototype.nzUpperBound; /** @type {?} */ NzSliderStepComponent.prototype.nzMarksArray; /** @type {?} */ NzSliderStepComponent.prototype.nzVertical; /** @type {?} */ NzSliderStepComponent.prototype.nzIncluded; /** @type {?} */ NzSliderStepComponent.prototype.steps; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function NzSliderTrackStyle() { } if (false) { /** @type {?|undefined} */ NzSliderTrackStyle.prototype.bottom; /** @type {?|undefined} */ NzSliderTrackStyle.prototype.height; /** @type {?|undefined} */ NzSliderTrackStyle.prototype.left; /** @type {?|undefined} */ NzSliderTrackStyle.prototype.width; /** @type {?|undefined} */ NzSliderTrackStyle.prototype.visibility; } class NzSliderTrackComponent { constructor() { this.nzVertical = false; this.nzIncluded = false; this.style = {}; } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.nzIncluded) { this.style.visibility = this.nzIncluded ? 'visible' : 'hidden'; } if (changes.nzVertical || changes.nzOffset || changes.nzLength) { if (this.nzVertical) { this.style.bottom = `${this.nzOffset}%`; this.style.height = `${this.nzLength}%`; this.style.left = null; this.style.width = null; } else { this.style.left = `${this.nzOffset}%`; this.style.width = `${this.nzLength}%`; this.style.bottom = null; this.style.height = null; } } } } NzSliderTrackComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-slider-track', exportAs: 'nzSliderTrack', preserveWhitespaces: false, template: "<div class=\"ant-slider-track\" [ngStyle]=\"style\"></div>" }] } ]; NzSliderTrackComponent.propDecorators = { nzOffset: [{ type: Input }], nzLength: [{ type: Input }], nzVertical: [{ type: Input }], nzIncluded: [{ type: Input }] }; __decorate([ InputNumber(), __metadata("design:type", Number) ], NzSliderTrackComponent.prototype, "nzOffset", void 0); __decorate([ InputNumber(), __metadata("design:type", Number) ], NzSliderTrackComponent.prototype, "nzLength", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderTrackComponent.prototype, "nzVertical", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSliderTrackComponent.prototype, "nzIncluded", void 0); if (false) { /** @type {?} */ NzSliderTrackComponent.prototype.nzOffset; /** @type {?} */ NzSliderTrackComponent.prototype.nzLength; /** @type {?} */ NzSliderTrackComponent.prototype.nzVertical; /** @type {?} */ NzSliderTrackComponent.prototype.nzIncluded; /** @type {?} */ NzSliderTrackComponent.prototype.style; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzSliderModule { } NzSliderModule.decorators = [ { type: NgModule, args: [{ exports: [ NzSliderComponent, NzSliderTrackComponent, NzSliderHandleComponent, NzSliderStepComponent, NzSliderMarksComponent ], declarations: [ NzSliderComponent, NzSliderTrackComponent, NzSliderHandleComponent, NzSliderStepComponent, NzSliderMarksComponent ], imports: [CommonModule, PlatformModule, NzToolTipModule] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { Marks, NzSliderComponent, NzSliderHandleComponent, NzSliderMarksComponent, NzSliderModule, NzSliderStepComponent, NzSliderTrackComponent, isConfigAObject, isValueARange }; //# sourceMappingURL=ng-zorro-antd-slider.js.map