1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import _extends from 'babel-runtime/helpers/extends';
import PropTypes from '../../_util/vue-types';
import warning from '../../_util/warning';
import BaseMixin from '../../_util/BaseMixin';
import { hasProp } from '../../_util/props-util';
import Track from './common/Track';
import createSlider from './common/createSlider';
import * as utils from './utils';
var Slider = {
name: 'Slider',
mixins: [BaseMixin],
props: {
defaultValue: PropTypes.number,
value: PropTypes.number,
disabled: PropTypes.bool,
autoFocus: PropTypes.bool,
tabIndex: PropTypes.number,
min: PropTypes.number,
max: PropTypes.number
},
data: function data() {
var defaultValue = this.defaultValue !== undefined ? this.defaultValue : this.min;
var value = this.value !== undefined ? this.value : defaultValue;
if (utils.isDev()) {
warning(!hasProp(this, 'minimumTrackStyle'), 'minimumTrackStyle will be deprecate, please use trackStyle instead.');
warning(!hasProp(this, 'maximumTrackStyle'), 'maximumTrackStyle will be deprecate, please use railStyle instead.');
}
return {
sValue: this.trimAlignValue(value),
dragging: false
};
},
mounted: function mounted() {
var _this = this;
this.$nextTick(function () {
var autoFocus = _this.autoFocus,
disabled = _this.disabled;
if (autoFocus && !disabled) {
_this.focus();
}
});
},
watch: {
value: {
handler: function handler(val) {
var min = this.min,
max = this.max;
this.setChangeValue(val, min, max);
},
deep: true
},
min: function min(val) {
var sValue = this.sValue,
max = this.max;
this.setChangeValue(sValue, val, max);
},
max: function max(val) {
var sValue = this.sValue,
min = this.min;
this.setChangeValue(sValue, min, val);
}
},
methods: {
setChangeValue: function setChangeValue(value, min, max) {
var minAmaxProps = {
min: min,
max: max
};
var newValue = value !== undefined ? value : this.sValue;
var nextValue = this.trimAlignValue(newValue, minAmaxProps);
if (nextValue === this.sValue) return;
this.setState({ sValue: nextValue });
if (utils.isValueOutOfRange(newValue, minAmaxProps)) {
this.$emit('change', nextValue);
}
},
onChange: function onChange(state) {
var isNotControlled = !hasProp(this, 'value');
if (isNotControlled) {
this.setState(state);
}
var changedValue = state.sValue;
this.$emit('change', changedValue);
},
onStart: function onStart(position) {
this.setState({ dragging: true });
var sValue = this.sValue;
this.$emit('beforeChange', sValue);
var value = this.calcValueByPos(position);
this.startValue = value;
this.startPosition = position;
if (value === sValue) return;
this.prevMovedHandleIndex = 0;
this.onChange({ sValue: value });
},
onEnd: function onEnd() {
this.setState({ dragging: false });
this.removeDocumentEvents();
this.$emit('afterChange', this.sValue);
},
onMove: function onMove(e, position) {
utils.pauseEvent(e);
var sValue = this.sValue;
var value = this.calcValueByPos(position);
if (value === sValue) return;
this.onChange({ sValue: value });
},
onKeyboard: function onKeyboard(e) {
var valueMutator = utils.getKeyboardValueMutator(e);
if (valueMutator) {
utils.pauseEvent(e);
var sValue = this.sValue;
var mutatedValue = valueMutator(sValue, this.$props);
var value = this.trimAlignValue(mutatedValue);
if (value === sValue) return;
this.onChange({ sValue: value });
}
},
getLowerBound: function getLowerBound() {
return this.min;
},
getUpperBound: function getUpperBound() {
return this.sValue;
},
trimAlignValue: function trimAlignValue(v) {
var nextProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (v === null) {
return null;
}
var mergedProps = _extends({}, this.$props, nextProps);
var val = utils.ensureValueInRange(v, mergedProps);
return utils.ensureValuePrecision(val, mergedProps);
},
getTrack: function getTrack(_ref) {
var prefixCls = _ref.prefixCls,
vertical = _ref.vertical,
included = _ref.included,
offset = _ref.offset,
minimumTrackStyle = _ref.minimumTrackStyle,
_trackStyle = _ref._trackStyle;
var h = this.$createElement;
return h(Track, {
'class': prefixCls + '-track',
attrs: { vertical: vertical,
included: included,
offset: 0,
length: offset
},
style: _extends({}, minimumTrackStyle, _trackStyle)
});
},
renderSlider: function renderSlider() {
var _this2 = this;
var prefixCls = this.prefixCls,
vertical = this.vertical,
included = this.included,
disabled = this.disabled,
minimumTrackStyle = this.minimumTrackStyle,
trackStyle = this.trackStyle,
handleStyle = this.handleStyle,
tabIndex = this.tabIndex,
min = this.min,
max = this.max,
handle = this.handle,
defaultHandle = this.defaultHandle;
var handleGenerator = handle || defaultHandle;
var sValue = this.sValue,
dragging = this.dragging;
var offset = this.calcOffset(sValue);
var handles = handleGenerator({
className: prefixCls + '-handle',
prefixCls: prefixCls,
vertical: vertical,
offset: offset,
value: sValue,
dragging: dragging,
disabled: disabled,
min: min,
max: max,
index: 0,
tabIndex: tabIndex,
style: handleStyle[0] || handleStyle,
directives: [{
name: 'ant-ref',
value: function value(h) {
return _this2.saveHandle(0, h);
}
}],
on: {
focus: this.onFocus,
blur: this.onBlur
}
});
var _trackStyle = trackStyle[0] || trackStyle;
return {
tracks: this.getTrack({
prefixCls: prefixCls,
vertical: vertical,
included: included,
offset: offset,
minimumTrackStyle: minimumTrackStyle,
_trackStyle: _trackStyle
}),
handles: handles
};
}
}
};
export default createSlider(Slider);