ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1,605 lines (1,593 loc) • 48.4 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { RIGHT_ARROW, UP_ARROW, LEFT_ARROW, DOWN_ARROW } from '@angular/cdk/keycodes';
import { Platform, PlatformModule } from '@angular/cdk/platform';
import { Injectable, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, ViewChild, Input, EventEmitter, forwardRef, ViewChildren, Output, NgModule } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { InputBoolean, ensureNumberInRange, silentEvent, getPrecision, getPercent, getElementOffset, InputNumber, arraysEqual } from 'ng-zorro-antd/core/util';
import { fromEvent, merge } from 'rxjs';
import { filter, tap, pluck, map, distinctUntilChanged, takeUntil } from 'rxjs/operators';
import { NzTooltipDirective, NzToolTipModule } from 'ng-zorro-antd/tooltip';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* Generated from: slider.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSliderService {
constructor() {
this.isDragging = false;
}
}
NzSliderService.decorators = [
{ type: Injectable }
];
if (false) {
/** @type {?} */
NzSliderService.prototype.isDragging;
}
/**
* @fileoverview added by tsickle
* Generated from: handle.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSliderHandleComponent {
/**
* @param {?} sliderService
* @param {?} cdr
*/
constructor(sliderService, cdr) {
this.sliderService = sliderService;
this.cdr = cdr;
this.tooltipVisible = 'default';
this.active = false;
this.style = {};
this.enterHandle = (/**
* @return {?}
*/
() => {
if (!this.sliderService.isDragging) {
this.toggleTooltip(true);
this.updateTooltipPosition();
this.cdr.detectChanges();
}
});
this.leaveHandle = (/**
* @return {?}
*/
() => {
if (!this.sliderService.isDragging) {
this.toggleTooltip(false);
this.cdr.detectChanges();
}
});
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
const { offset, value, active, tooltipVisible } = changes;
if (offset) {
this.updateStyle();
}
if (value) {
this.updateTooltipTitle();
this.updateTooltipPosition();
}
if (active) {
if (active.currentValue) {
this.toggleTooltip(true);
}
else {
this.toggleTooltip(false);
}
}
if ((tooltipVisible === null || tooltipVisible === void 0 ? void 0 : tooltipVisible.currentValue) === 'always') {
Promise.resolve().then((/**
* @return {?}
*/
() => this.toggleTooltip(true, true)));
}
}
/**
* @return {?}
*/
focus() {
this.handleEl.nativeElement.focus();
}
/**
* @private
* @param {?} show
* @param {?=} force
* @return {?}
*/
toggleTooltip(show, force = false) {
if (!force && (this.tooltipVisible !== 'default' || !this.tooltip)) {
return;
}
if (show) {
this.tooltip.show();
}
else {
this.tooltip.hide();
}
}
/**
* @private
* @return {?}
*/
updateTooltipTitle() {
this.tooltipTitle = this.tooltipFormatter ? this.tooltipFormatter(this.value) : `${this.value}`;
}
/**
* @private
* @return {?}
*/
updateTooltipPosition() {
if (this.tooltip) {
Promise.resolve().then((/**
* @return {?}
*/
() => this.tooltip.updatePosition()));
}
}
/**
* @private
* @return {?}
*/
updateStyle() {
this.style = {
[this.vertical ? 'bottom' : 'left']: `${this.offset}%`,
transform: this.vertical ? 'translateY(50%)' : 'translateX(-50%)'
};
this.cdr.markForCheck();
}
}
NzSliderHandleComponent.decorators = [
{ type: Component, args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-slider-handle',
exportAs: 'nzSliderHandle',
preserveWhitespaces: false,
template: `
<div
#handle
class="ant-slider-handle"
tabindex="0"
nz-tooltip
[ngStyle]="style"
[nzTooltipTitle]="tooltipFormatter === null || tooltipVisible === 'never' ? null : tooltipTitle"
[nzTooltipTrigger]="null"
[nzTooltipPlacement]="tooltipPlacement"
></div>
`,
host: {
'(mouseenter)': 'enterHandle()',
'(mouseleave)': 'leaveHandle()'
}
}] }
];
/** @nocollapse */
NzSliderHandleComponent.ctorParameters = () => [
{ type: NzSliderService },
{ type: ChangeDetectorRef }
];
NzSliderHandleComponent.propDecorators = {
handleEl: [{ type: ViewChild, args: ['handle', { static: false },] }],
tooltip: [{ type: ViewChild, args: [NzTooltipDirective, { static: false },] }],
vertical: [{ type: Input }],
offset: [{ type: Input }],
value: [{ type: Input }],
tooltipVisible: [{ type: Input }],
tooltipPlacement: [{ type: Input }],
tooltipFormatter: [{ type: Input }],
active: [{ type: Input }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderHandleComponent.prototype, "active", void 0);
if (false) {
/** @type {?} */
NzSliderHandleComponent.ngAcceptInputType_active;
/** @type {?} */
NzSliderHandleComponent.prototype.handleEl;
/** @type {?} */
NzSliderHandleComponent.prototype.tooltip;
/** @type {?} */
NzSliderHandleComponent.prototype.vertical;
/** @type {?} */
NzSliderHandleComponent.prototype.offset;
/** @type {?} */
NzSliderHandleComponent.prototype.value;
/** @type {?} */
NzSliderHandleComponent.prototype.tooltipVisible;
/** @type {?} */
NzSliderHandleComponent.prototype.tooltipPlacement;
/** @type {?} */
NzSliderHandleComponent.prototype.tooltipFormatter;
/** @type {?} */
NzSliderHandleComponent.prototype.active;
/** @type {?} */
NzSliderHandleComponent.prototype.tooltipTitle;
/** @type {?} */
NzSliderHandleComponent.prototype.style;
/** @type {?} */
NzSliderHandleComponent.prototype.enterHandle;
/** @type {?} */
NzSliderHandleComponent.prototype.leaveHandle;
/**
* @type {?}
* @private
*/
NzSliderHandleComponent.prototype.sliderService;
/**
* @type {?}
* @private
*/
NzSliderHandleComponent.prototype.cdr;
}
/**
* @fileoverview added by tsickle
* Generated from: slider.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSliderComponent {
/**
* @param {?} sliderService
* @param {?} cdr
* @param {?} platform
*/
constructor(sliderService, cdr, platform) {
this.sliderService = sliderService;
this.cdr = cdr;
this.platform = platform;
this.nzDisabled = false;
this.nzDots = false;
this.nzIncluded = true;
this.nzRange = false;
this.nzVertical = false;
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
}
/**
* @return {?}
*/
ngOnInit() {
this.handles = generateHandlers(this.nzRange ? 2 : 1);
this.marksArray = this.nzMarks ? this.generateMarkItems(this.nzMarks) : null;
this.bindDraggingHandlers();
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);
}
/**
* Event handler is only triggered when a slider handler is focused.
* @param {?} e
* @return {?}
*/
onKeyDown(e) {
/** @type {?} */
const code = e.keyCode;
/** @type {?} */
const isIncrease = code === RIGHT_ARROW || code === UP_ARROW;
/** @type {?} */
const isDecrease = code === LEFT_ARROW || code === DOWN_ARROW;
if (!(isIncrease || isDecrease)) {
return;
}
e.preventDefault();
/** @type {?} */
const step = isDecrease ? -this.nzStep : this.nzStep;
/** @type {?} */
const newVal = this.nzRange ? ((/** @type {?} */ (this.value)))[(/** @type {?} */ (this.activeValueIndex))] + step : ((/** @type {?} */ (this.value))) + step;
this.setActiveValue(ensureNumberInRange(newVal, this.nzMin, this.nzMax));
}
/**
* @private
* @param {?} value
* @param {?=} isWriteValue
* @return {?}
*/
setValue(value, isWriteValue = false) {
if (isWriteValue) {
this.value = this.formatValue(value);
this.updateTrackAndHandles();
}
else if (!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 && isValueRange(this.value)) {
return [...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 isValueRange(normalizedValue) ? normalizedValue.map((/**
* @param {?} val
* @return {?}
*/
val => this.valueToOffset(val))) : this.valueToOffset(normalizedValue);
}
/**
* Find the closest value to be activated.
* @private
* @param {?} pointerValue
* @return {?}
*/
setActiveValueIndex(pointerValue) {
/** @type {?} */
const value = this.getValue();
if (isValueRange(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;
this.handlerComponents.toArray()[activeIndex].focus();
}
else {
this.handlerComponents.toArray()[0].focus();
}
}
/**
* @private
* @param {?} pointerValue
* @return {?}
*/
setActiveValue(pointerValue) {
if (isValueRange((/** @type {?} */ (this.value)))) {
/** @type {?} */
const newValue = [...((/** @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 = isValueRange(valueSorted) ? valueSorted : [0, valueSorted];
/** @type {?} */
const trackParts = isValueRange(offsetSorted) ? [offsetSorted[0], offsetSorted[1] - offsetSorted[0]] : [0, offsetSorted];
this.handles.forEach((/**
* @param {?} handle
* @param {?} index
* @return {?}
*/
(handle, index) => {
handle.offset = isValueRange(offset) ? offset[index] : offset;
handle.value = isValueRange(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 {?}
*/
bindDraggingHandlers() {
if (!this.platform.isBrowser) {
return;
}
/** @type {?} */
const sliderDOM = this.slider.nativeElement;
/** @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.sliderService.isDragging = true;
this.subscribeDrag(periods);
}
else {
this.sliderService.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 !== 0 && !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.slider.nativeElement);
return this.nzVertical ? offset.top : offset.left;
}
/**
* @private
* @return {?}
*/
getSliderLength() {
if (this.cacheSliderLength !== null) {
return this.cacheSliderLength;
}
/** @type {?} */
const sliderDOM = this.slider.nativeElement;
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) {
if (!value) {
return this.nzRange ? [this.nzMin, this.nzMax] : this.nzMin;
}
else if (assertValueValid(value, this.nzRange)) {
return isValueRange(value)
? value.map((/**
* @param {?} val
* @return {?}
*/
val => ensureNumberInRange(val, this.nzMin, this.nzMax)))
: ensureNumberInRange(value, this.nzMin, this.nzMax);
}
else {
return this.nzDefaultValue ? this.nzDefaultValue : this.nzRange ? [this.nzMin, this.nzMax] : this.nzMin;
}
}
/**
* 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 {?} 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
},
NzSliderService
],
host: {
'(keydown)': 'onKeyDown($event)'
},
template: `
<div
#slider
class="ant-slider"
[class.ant-slider-disabled]="nzDisabled"
[class.ant-slider-vertical]="nzVertical"
[class.ant-slider-with-marks]="marksArray"
>
<div class="ant-slider-rail"></div>
<nz-slider-track [vertical]="nzVertical" [included]="nzIncluded" [offset]="track.offset" [length]="track.length"></nz-slider-track>
<nz-slider-step
*ngIf="marksArray"
[vertical]="nzVertical"
[lowerBound]="bounds.lower"
[upperBound]="bounds.upper"
[marksArray]="marksArray"
[included]="nzIncluded"
></nz-slider-step>
<nz-slider-handle
*ngFor="let handle of handles"
[vertical]="nzVertical"
[offset]="handle.offset"
[value]="handle.value"
[active]="handle.active"
[tooltipFormatter]="nzTipFormatter"
[tooltipVisible]="nzTooltipVisible"
[tooltipPlacement]="nzTooltipPlacement"
></nz-slider-handle>
<nz-slider-marks
*ngIf="marksArray"
[vertical]="nzVertical"
[min]="nzMin"
[max]="nzMax"
[lowerBound]="bounds.lower"
[upperBound]="bounds.upper"
[marksArray]="marksArray"
[included]="nzIncluded"
></nz-slider-marks>
</div>
`
}] }
];
/** @nocollapse */
NzSliderComponent.ctorParameters = () => [
{ type: NzSliderService },
{ type: ChangeDetectorRef },
{ type: Platform }
];
NzSliderComponent.propDecorators = {
slider: [{ type: ViewChild, args: ['slider', { static: true },] }],
handlerComponents: [{ type: ViewChildren, args: [NzSliderHandleComponent,] }],
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);
__decorate([
InputNumber(),
__metadata("design:type", Object)
], NzSliderComponent.prototype, "nzMax", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Object)
], NzSliderComponent.prototype, "nzMin", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Object)
], NzSliderComponent.prototype, "nzStep", void 0);
if (false) {
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzDisabled;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzDots;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzIncluded;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzRange;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzVertical;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzMax;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzMin;
/** @type {?} */
NzSliderComponent.ngAcceptInputType_nzStep;
/** @type {?} */
NzSliderComponent.prototype.slider;
/** @type {?} */
NzSliderComponent.prototype.handlerComponents;
/** @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.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 {?}
* @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.sliderService;
/**
* @type {?}
* @private
*/
NzSliderComponent.prototype.cdr;
/**
* @type {?}
* @private
*/
NzSliderComponent.prototype.platform;
}
/**
* @return {?}
*/
function getValueTypeNotMatchError() {
return new Error(`The "nzRange" can't match the "ngModel"'s type, please check these properties: "nzRange", "ngModel", "nzDefaultValue".`);
}
/**
* @param {?} value
* @return {?}
*/
function isValueRange(value) {
if (value instanceof Array) {
return value.length === 2;
}
else {
return false;
}
}
/**
* @param {?} amount
* @return {?}
*/
function generateHandlers(amount) {
return Array(amount)
.fill(0)
.map((/**
* @return {?}
*/
() => ({ offset: null, value: null, active: false })));
}
/**
* Check if value is valid and throw error if value-type/range not match.
* @param {?} value
* @param {?=} isRange
* @return {?}
*/
function assertValueValid(value, isRange) {
if ((!isValueRange(value) && isNaN(value)) || (isValueRange(value) && value.some((/**
* @param {?} v
* @return {?}
*/
v => isNaN(v))))) {
return false;
}
return assertValueTypeMatch(value, isRange);
}
/**
* Assert that if `this.nzRange` is `true`, value is also a range, vice versa.
* @param {?} value
* @param {?=} isRange
* @return {?}
*/
function assertValueTypeMatch(value, isRange = false) {
if (isValueRange(value) !== isRange) {
throw getValueTypeNotMatchError();
}
return true;
}
/**
* @param {?} valA
* @param {?} valB
* @return {?}
*/
function valuesEqual(valA, valB) {
if (typeof valA !== typeof valB) {
return false;
}
return isValueRange(valA) && isValueRange(valB) ? arraysEqual(valA, valB) : valA === valB;
}
/**
* @fileoverview added by tsickle
* Generated from: marks.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSliderMarksComponent {
constructor() {
this.lowerBound = null;
this.upperBound = null;
this.vertical = false;
this.included = false;
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
const { marksArray, lowerBound, upperBound } = changes;
if (marksArray) {
this.buildMarks();
}
if (marksArray || lowerBound || upperBound) {
this.togglePointActive();
}
}
/**
* @param {?} _index
* @param {?} mark
* @return {?}
*/
trackById(_index, mark) {
return mark.value;
}
/**
* @private
* @return {?}
*/
buildMarks() {
/** @type {?} */
const range = this.max - this.min;
this.marks = this.marksArray.map((/**
* @param {?} mark
* @return {?}
*/
mark => {
const { value, offset, config } = mark;
/** @type {?} */
const style = this.getMarkStyles(value, range, config);
/** @type {?} */
const label = isConfigObject(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.vertical) {
style = {
marginBottom: '-50%',
bottom: `${((value - this.min) / range) * 100}%`
};
}
else {
style = {
transform: `translate3d(-50%, 0, 0)`,
left: `${((value - this.min) / range) * 100}%`
};
}
if (isConfigObject(config) && config.style) {
style = Object.assign(Object.assign({}, style), config.style);
}
return style;
}
/**
* @private
* @return {?}
*/
togglePointActive() {
if (this.marks && this.lowerBound !== null && this.upperBound !== null) {
this.marks.forEach((/**
* @param {?} mark
* @return {?}
*/
mark => {
/** @type {?} */
const value = mark.value;
/** @type {?} */
const isActive = (!this.included && value === this.upperBound) || (this.included && value <= (/** @type {?} */ (this.upperBound)) && value >= (/** @type {?} */ (this.lowerBound)));
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">
<span
class="ant-slider-mark-text"
*ngFor="let attr of marks; trackBy: trackById"
[class.ant-slider-mark-active]="attr.active"
[ngStyle]="attr.style"
[innerHTML]="attr.label"
>
</span>
</div>
`
}] }
];
NzSliderMarksComponent.propDecorators = {
lowerBound: [{ type: Input }],
upperBound: [{ type: Input }],
marksArray: [{ type: Input }],
min: [{ type: Input }],
max: [{ type: Input }],
vertical: [{ type: Input }],
included: [{ type: Input }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderMarksComponent.prototype, "vertical", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderMarksComponent.prototype, "included", void 0);
if (false) {
/** @type {?} */
NzSliderMarksComponent.ngAcceptInputType_vertical;
/** @type {?} */
NzSliderMarksComponent.ngAcceptInputType_included;
/** @type {?} */
NzSliderMarksComponent.prototype.lowerBound;
/** @type {?} */
NzSliderMarksComponent.prototype.upperBound;
/** @type {?} */
NzSliderMarksComponent.prototype.marksArray;
/** @type {?} */
NzSliderMarksComponent.prototype.min;
/** @type {?} */
NzSliderMarksComponent.prototype.max;
/** @type {?} */
NzSliderMarksComponent.prototype.vertical;
/** @type {?} */
NzSliderMarksComponent.prototype.included;
/** @type {?} */
NzSliderMarksComponent.prototype.marks;
}
/**
* @param {?} config
* @return {?}
*/
function isConfigObject(config) {
return typeof config !== 'string';
}
/**
* @fileoverview added by tsickle
* Generated from: step.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSliderStepComponent {
constructor() {
this.lowerBound = null;
this.upperBound = null;
this.vertical = false;
this.included = false;
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.marksArray) {
this.buildSteps();
}
if (changes.marksArray || changes.lowerBound || changes.upperBound) {
this.togglePointActive();
}
}
/**
* @param {?} _index
* @param {?} step
* @return {?}
*/
trackById(_index, step) {
return step.value;
}
/**
* @private
* @return {?}
*/
buildSteps() {
/** @type {?} */
const orient = this.vertical ? 'bottom' : 'left';
this.steps = this.marksArray.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.lowerBound !== null && this.upperBound !== null) {
this.steps.forEach((/**
* @param {?} step
* @return {?}
*/
step => {
/** @type {?} */
const value = step.value;
/** @type {?} */
const isActive = (!this.included && value === this.upperBound) || (this.included && value <= (/** @type {?} */ (this.upperBound)) && value >= (/** @type {?} */ (this.lowerBound)));
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">
<span
class="ant-slider-dot"
*ngFor="let mark of steps; trackBy: trackById"
[class.ant-slider-dot-active]="mark.active"
[ngStyle]="mark.style"
>
</span>
</div>
`
}] }
];
NzSliderStepComponent.propDecorators = {
lowerBound: [{ type: Input }],
upperBound: [{ type: Input }],
marksArray: [{ type: Input }],
vertical: [{ type: Input }],
included: [{ type: Input }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderStepComponent.prototype, "vertical", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderStepComponent.prototype, "included", void 0);
if (false) {
/** @type {?} */
NzSliderStepComponent.ngAcceptInputType_vertical;
/** @type {?} */
NzSliderStepComponent.ngAcceptInputType_included;
/** @type {?} */
NzSliderStepComponent.prototype.lowerBound;
/** @type {?} */
NzSliderStepComponent.prototype.upperBound;
/** @type {?} */
NzSliderStepComponent.prototype.marksArray;
/** @type {?} */
NzSliderStepComponent.prototype.vertical;
/** @type {?} */
NzSliderStepComponent.prototype.included;
/** @type {?} */
NzSliderStepComponent.prototype.steps;
}
/**
* @fileoverview added by tsickle
* Generated from: track.component.ts
* @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.vertical = false;
this.included = false;
this.style = {};
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.included) {
this.style.visibility = this.included ? 'visible' : 'hidden';
}
if (changes.vertical || changes.offset || changes.length) {
if (this.vertical) {
this.style.bottom = `${this.offset}%`;
this.style.height = `${this.length}%`;
this.style.left = null;
this.style.width = null;
}
else {
this.style.left = `${this.offset}%`;
this.style.width = `${this.length}%`;
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 = {
offset: [{ type: Input }],
length: [{ type: Input }],
vertical: [{ type: Input }],
included: [{ type: Input }]
};
__decorate([
InputNumber(),
__metadata("design:type", Number)
], NzSliderTrackComponent.prototype, "offset", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Number)
], NzSliderTrackComponent.prototype, "length", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderTrackComponent.prototype, "vertical", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSliderTrackComponent.prototype, "included", void 0);
if (false) {
/** @type {?} */
NzSliderTrackComponent.ngAcceptInputType_offset;
/** @type {?} */
NzSliderTrackComponent.ngAcceptInputType_length;
/** @type {?} */
NzSliderTrackComponent.ngAcceptInputType_vertical;
/** @type {?} */
NzSliderTrackComponent.ngAcceptInputType_included;
/** @type {?} */
NzSliderTrackComponent.prototype.offset;
/** @type {?} */
NzSliderTrackComponent.prototype.length;
/** @type {?} */
NzSliderTrackComponent.prototype.vertical;
/** @type {?} */
NzSliderTrackComponent.prototype.included;
/** @type {?} */
NzSliderTrackComponent.prototype.style;
}
/**
* @fileoverview added by tsickle
* Generated from: slider.module.ts
* @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
* Generated from: typings.ts
* @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 NzMarkObj() { }
if (false) {
/** @type {?|undefined} */
NzMarkObj.prototype.style;
/** @type {?} */
NzMarkObj.prototype.label;
}
class NzMarks {
}
/**
* Processed steps that would be passed to sub components.
* @record
*/
function NzExtendedMark() { }
if (false) {
/** @type {?} */
NzExtendedMark.prototype.value;
/** @type {?} */
NzExtendedMark.prototype.offset;
/** @type {?} */
NzExtendedMark.prototype.config;
}
/**
* Marks that would be rendered.
* @record
*/
function NzDisplayedMark() { }
if (false) {
/** @type {?} */
NzDisplayedMark.prototype.active;
/** @type {?} */
NzDisplayedMark.prototype.label;
/** @type {?|undefined} */
NzDisplayedMark.prototype.style;
}
/**
* Steps that would be rendered.
* @record
*/
function NzDisplayedStep() { }
if (false) {
/** @type {?} */
NzDisplayedStep.prototype.active;
/** @type {?|undefined} */
NzDisplayedStep.prototype.style;
}
/**
* @record
*/
function NzSliderHandler() { }
if (false) {
/** @type {?} */
NzSliderHandler.prototype.offset;
/** @type {?} */
NzSliderHandler.prototype.value;
/** @type {?} */
NzSliderHandler.prototype.active;
}
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-zorro-antd-slider.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzMarks, NzSliderComponent, NzSliderModule, NzSliderHandleComponent as ɵNzSliderHandleComponent, NzSliderMarksComponent as ɵNzSliderMarksComponent, NzSliderService as ɵNzSliderService, NzSliderStepComponent as ɵNzSliderStepComponent, NzSliderTrackComponent as ɵNzSliderTrackComponent };
//# sourceMappingURL=ng-zorro-antd-slider.js.map