tdesign-vue
Version:
606 lines (598 loc) • 21.5 kB
JavaScript
/**
* tdesign v1.15.0
* (c) 2026 tdesign
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var helper = require('../_chunks/dep-4009cfe4.js');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var utils_event = require('../utils/event.js');
var slider_props = require('./props.js');
var inputNumber_index = require('../input-number/index.js');
var slider_sliderMark = require('./slider-mark.js');
var slider_sliderButton = require('./slider-button.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../_chunks/dep-9c5b91d3.js');
require('../_chunks/dep-9a74c2be.js');
require('../_chunks/dep-689d381f.js');
require('../_chunks/dep-3b2292ce.js');
require('../_chunks/dep-10fcb46d.js');
require('../_chunks/dep-803744d9.js');
require('../_chunks/dep-ba7f5924.js');
require('../_chunks/dep-84027b7f.js');
require('../_chunks/dep-49400b00.js');
require('../_chunks/dep-f1081d8e.js');
require('@vue/composition-api');
require('../input-number/input-number.js');
require('tdesign-icons-vue');
require('../button/index.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('vue');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/setStyle.js');
require('../_common/js/utils/helper.js');
require('../_chunks/dep-721fcdf6.js');
require('../_chunks/dep-591b87f1.js');
require('../_chunks/dep-a2217d56.js');
require('../_chunks/dep-268c68b1.js');
require('../utils/dom.js');
require('raf');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('@babel/runtime/helpers/readOnlyError');
require('../_chunks/dep-2c592e99.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../config.js');
require('../_chunks/dep-8eddb350.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-0c37520c.js');
require('../_chunks/dep-c13dcbfd.js');
require('dayjs');
require('../_chunks/dep-6f4e680e.js');
require('../_chunks/dep-bb0ececf.js');
require('../_chunks/dep-6eba4d23.js');
require('../_chunks/dep-010db548.js');
require('../_chunks/dep-8d206316.js');
require('../_chunks/dep-2bc87cc8.js');
require('../_chunks/dep-f77d6ad5.js');
require('../_chunks/dep-9dae8101.js');
require('../_chunks/dep-7c84d9a0.js');
require('../_chunks/dep-733a2279.js');
require('../_chunks/dep-d844c9ed.js');
require('../_chunks/dep-c05a9033.js');
require('../_chunks/dep-efe55b82.js');
require('../_chunks/dep-7da70ee1.js');
require('../_chunks/dep-124386d4.js');
require('../_chunks/dep-f5b14344.js');
require('../_chunks/dep-36c2788b.js');
require('../_chunks/dep-fa353fbb.js');
require('../_chunks/dep-d66ab3a4.js');
require('../_chunks/dep-d4d8c513.js');
require('../_common/js/global-config/t.js');
require('../_chunks/dep-97fef2be.js');
require('../_chunks/dep-0b47afa3.js');
require('../_chunks/dep-d7516e38.js');
require('../_chunks/dep-74be1050.js');
require('../_chunks/dep-7fbd94e9.js');
require('../_chunks/dep-56f568d3.js');
require('../_chunks/dep-82ce56ef.js');
require('../_chunks/dep-4e96e31a.js');
require('../_chunks/dep-17ce3e74.js');
require('../_chunks/dep-a7198720.js');
require('../_chunks/dep-1e173c2b.js');
require('../_chunks/dep-c9ce9427.js');
require('../_chunks/dep-edb55477.js');
require('../utils/withInstall.js');
require('../button/props.js');
require('../utils/ripple.js');
require('../input/index.js');
require('../input/input.js');
require('../input/props.js');
require('../_common/js/log/log.js');
require('../input/input-group.js');
require('../utils/map-props.js');
require('../input-number/props.js');
require('../input-number/useInputNumber.js');
require('../hooks/useCommonClassName.js');
require('../config-provider/useConfig.js');
require('../hooks/useVModel.js');
require('../_common/js/input-number/number.js');
require('../_common/js/input-number/large-number.js');
require('../hooks/useFormDisabled.js');
require('../hooks/useGlobalIcon.js');
require('../tooltip/index.js');
require('../tooltip/tooltip.js');
require('../tooltip/props.js');
require('../popup/props.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/container.js');
require('../popup/utils.js');
require('../_chunks/dep-ee4e645f.js');
require('../_chunks/dep-0ea9f257.js');
require('../_common/js/slider/utils.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default["default"](e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("slider");
var _Slider = utils_mixins["default"](classPrefixMixins).extend({
name: "TSlider",
model: {
prop: "value",
event: "change"
},
props: _objectSpread({}, slider_props["default"]),
components: {
TSliderMark: slider_sliderMark["default"],
TInputNumber: inputNumber_index.InputNumber
},
provide: function provide() {
return {
slider: this
};
},
data: function data() {
return {
firstValue: 0,
secondValue: 0,
prevValue: 0,
dragging: false,
sliderSize: 1,
inputDecimalPlaces: 0,
inputFormat: null,
inputPlaceholder: "",
inputTheme: "column",
showSteps: false,
formDisabled: void 0
};
},
computed: {
tDisabled: function tDisabled() {
return this.formDisabled || this.disabled;
},
containerClass: function containerClass() {
return ["".concat(this.componentName, "__container"), {
"is-vertical": this.vertical
}];
},
sliderClass: function sliderClass() {
return ["".concat(this.componentName), _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({
"is-vertical": this.vertical
}, "".concat(this.componentName, "--with-input"), this.inputNumberProps), "".concat(this.componentName, "--vertical"), this.vertical), "".concat(this.classPrefix, "-is-disabled"), this.tDisabled)];
},
sliderRailClass: function sliderRailClass() {
return ["".concat(this.componentName, "__rail"), _defineProperty__default["default"]({
"show-input": this.inputNumberProps
}, "".concat(this.classPrefix, "-is-disabled"), this.tDisabled)];
},
sliderNumberClass: function sliderNumberClass() {
return ["".concat(this.componentName, "__input"), {
"is-vertical": this.vertical
}];
},
vertical: function vertical() {
return this.layout === "vertical";
},
rangeDiff: function rangeDiff() {
return this.max - this.min;
},
steps: function steps() {
var _this = this;
var min = this.min,
max = this.max,
rangeDiff = this.rangeDiff,
step = this.step;
if (!this.showSteps || min > max) return [];
if (this.step === 0) {
console.warn("[Element Warn][Slider]step should not be 0.");
return [];
}
var stepCount = rangeDiff / step;
var stepWidth = 100 * step / rangeDiff;
var result = [];
for (var i = 1; i < stepCount; i++) {
result.push(i * stepWidth);
}
if (this.range) {
return result.filter(function (step2) {
return step2 < 100 * (_this.minValue - min) / rangeDiff || step2 > 100 * (_this.maxValue - min) / rangeDiff;
});
}
return result.filter(function (step2) {
return step2 > 100 * (_this.firstValue - min) / rangeDiff;
});
},
markList: function markList() {
var _this2 = this;
if (!this.marks) {
return [];
}
var legalMarks = [];
Object.keys(this.marks).map(parseFloat).sort(function (a, b) {
return a - b;
}).filter(function (point) {
return point <= _this2.max && point >= _this2.min;
}).forEach(function (point) {
var item = {
point: point,
position: (point - _this2.min) * 100 / _this2.rangeDiff,
mark: _this2.marks[point]
};
legalMarks.push(item);
});
return legalMarks;
},
minValue: function minValue() {
return Math.min(this.firstValue, this.secondValue);
},
maxValue: function maxValue() {
return Math.max(this.firstValue, this.secondValue);
},
barSize: function barSize() {
var diff = this.range ? this.maxValue - this.minValue : this.prevValue - this.min;
return "".concat(100 * diff / this.rangeDiff, "%");
},
barStart: function barStart() {
return this.range ? "".concat(100 * (this.minValue - this.min) / this.rangeDiff, "%") : "0%";
},
precision: function precision() {
var precisions = [this.min, this.max, this.step].map(function (item) {
var decimalArr = "".concat(item).split(".");
return decimalArr[1] ? decimalArr[1].length : 0;
});
return Math.max.apply(null, precisions);
},
runwayStyle: function runwayStyle() {
return this.vertical ? {
height: "100%"
} : {};
},
barStyle: function barStyle() {
return this.vertical ? {
height: this.barSize,
bottom: this.barStart
} : {
width: this.barSize,
left: this.barStart
};
},
calcInputNumberProps: function calcInputNumberProps() {
var defaultInputNumberProps = {
placeholder: "",
theme: "column"
};
if (_typeof__default["default"](this.inputNumberProps) === "object") {
return _objectSpread(_objectSpread({}, defaultInputNumberProps), this.inputNumberProps);
}
return defaultInputNumberProps;
}
},
watch: {
value: function value(newVal) {
if (this.dragging === true) return;
if (Array.isArray(newVal) && this.range) {
var _newVal = _slicedToArray__default["default"](newVal, 2);
this.firstValue = _newVal[0];
this.secondValue = _newVal[1];
} else {
this.prevValue = newVal;
}
},
dragging: function dragging(newVal) {
if (newVal === false) {
this.init();
}
}
},
mounted: function mounted() {
this.init();
},
beforeDestroy: function beforeDestroy() {
window.removeEventListener("resize", this.resetSize);
},
methods: {
init: function init() {
var valuetext;
var min = this.min,
max = this.max,
value = this.value;
if (this.range) {
if (Array.isArray(value)) {
var _value$, _value$2;
this.firstValue = Math.max(min || 0, (_value$ = value[0]) !== null && _value$ !== void 0 ? _value$ : 0);
this.secondValue = Math.min(max || 100, (_value$2 = value[1]) !== null && _value$2 !== void 0 ? _value$2 : 0);
} else {
this.firstValue = min || 0;
this.secondValue = max || 100;
}
valuetext = "".concat(this.firstValue, "-").concat(this.secondValue);
} else {
if (typeof this.value !== "number") {
this.prevValue = min;
} else {
this.prevValue = Math.min(max, Math.max(min, value));
}
valuetext = String(this.prevValue);
}
this.$el.setAttribute("aria-valuetext", valuetext);
this.resetSize();
window.addEventListener("resize", this.resetSize);
},
valueChanged: function valueChanged() {
var _this3 = this;
if (this.range) {
return ![this.minValue, this.maxValue].every(function (item, index) {
return item === _this3.prevValue[index];
});
}
return this.value !== this.prevValue;
},
setValues: function setValues(value) {
var _ref3 = [this.min, this.max],
min = _ref3[0],
max = _ref3[1];
if (min > max) {
console.warn("[Slider] max should be greater than min.");
return;
}
if (this.range && Array.isArray(value)) {
var _ref4 = [Math.min.apply(Math, _toConsumableArray__default["default"](value)), Math.max.apply(Math, _toConsumableArray__default["default"](value))],
firstValue = _ref4[0],
secondValue = _ref4[1];
if (firstValue > max) firstValue = this.firstValue;
if (firstValue < min) firstValue = min;
if (secondValue < min) secondValue = this.secondValue;
if (secondValue > max) secondValue = max;
return [firstValue, secondValue];
}
var prevValue = value;
if (prevValue < min) prevValue = min;
if (prevValue > max) prevValue = max;
return prevValue;
},
setPosition: function setPosition(percent) {
var targetValue = percent * this.rangeDiff / 100;
targetValue = this.min + targetValue;
if (!this.range) {
this.$refs.button1.setPosition(percent);
return;
}
var button;
if (Math.abs(this.minValue - targetValue) < Math.abs(this.maxValue - targetValue)) {
button = this.firstValue < this.secondValue ? "button1" : "button2";
} else {
button = this.firstValue > this.secondValue ? "button1" : "button2";
}
this.$refs[button].setPosition(percent);
},
onSliderClick: function onSliderClick(event) {
if (this.tDisabled || this.dragging) {
return;
}
this.resetSize();
var value = 0;
if (this.vertical) {
var sliderOffsetBottom = this.$refs.slider.getBoundingClientRect().bottom;
value = (sliderOffsetBottom - event.clientY) / this.sliderSize * 100;
this.setPosition(value);
} else {
var sliderOffsetLeft = this.$refs.slider.getBoundingClientRect().left;
value = (event.clientX - sliderOffsetLeft) / this.sliderSize * 100;
this.setPosition(value);
}
},
resetSize: function resetSize() {
if (this.$refs.slider) {
this.sliderSize = this.$refs.slider["client".concat(this.vertical ? "Height" : "Width")];
}
},
emitChange: function emitChange(value) {
var changeValue = value;
if (changeValue === void 0) {
if (this.range) {
changeValue = [this.firstValue, this.secondValue];
} else {
changeValue = this.prevValue;
}
}
var fixValue = this.setValues(changeValue);
utils_event.emitEvent(this, "change", fixValue);
},
emitChangeEnd: function emitChangeEnd() {
utils_event.emitEvent(this, "change-end", this.value);
},
getStopStyle: function getStopStyle(position) {
return this.vertical ? {
top: "calc(".concat(100 - position, "% - 1px)")
} : {
left: "".concat(position, "%")
};
},
changeValue: function changeValue(point) {
if (this.tDisabled || this.dragging) {
return;
}
this.resetSize();
var value = Number(point / this.rangeDiff * 100);
this.setPosition(value);
this.emitChange(point);
},
renderMask: function renderMask() {
var _this4 = this;
var h = this.$createElement;
if (this.markList.length) {
return h("div", [h("div", {
"class": "".concat(this.componentName, "__stops")
}, [this.markList.map(function (item, index) {
if (item.position === 0 || item.position === 100) return null;
return h("div", {
"class": ["".concat(_this4.componentName, "__stop"), "".concat(_this4.componentName, "__mark-stop")],
"style": _this4.getStopStyle(item.position),
"key": index
});
})]), h("div", {
"class": "".concat(this.componentName, "__mark")
}, [this.markList.map(function (item, key) {
return h("t-slider-mark", {
"attrs": {
"mark": item.mark,
"point": item.point
},
"key": key,
"style": _this4.getStopStyle(item.position),
"on": {
"change-value": _this4.changeValue
}
});
})])]);
}
},
renderInputButton: function renderInputButton() {
var _this5 = this;
var h = this.$createElement;
var max = this.max,
min = this.min,
sliderNumberClass = this.sliderNumberClass,
range = this.range;
return h("div", {
"class": ["".concat(this.componentName, "__input-container"), {
"is-vertical": this.vertical
}]
}, [h("t-input-number", helper.helper([{
"class": sliderNumberClass,
"attrs": {
"value": range ? this.firstValue : this.prevValue,
"step": this.step,
"disabled": this.tDisabled,
"min": min,
"max": max
},
"ref": "input",
"on": {
"change": function change(v) {
_this5.range ? _this5.emitChange([v, _this5.secondValue]) : _this5.emitChange(v);
}
}
}, {
"props": this.calcInputNumberProps
}])), range && h("div", {
"class": "".concat(this.componentName, "__center-line")
}), range && h("t-input-number", helper.helper([{
"class": this.sliderNumberClass,
"attrs": {
"value": this.secondValue,
"step": this.step,
"disabled": this.tDisabled,
"min": min,
"max": max
},
"ref": "input",
"on": {
"input": function input(v) {
_this5.emitChange([_this5.firstValue, v]);
}
}
}, {
"props": this.calcInputNumberProps
}]))]);
}
},
render: function render() {
var _this6 = this;
var h = arguments[0];
var min = this.min,
max = this.max,
layout = this.layout,
disabled = this.disabled,
vertical = this.vertical,
range = this.range;
var buttonGroup = this.inputNumberProps && this.renderInputButton();
var masks = this.renderMask();
return h("div", {
"class": this.containerClass
}, [h("div", {
"class": this.sliderClass,
"attrs": {
"role": "slider",
"aria-valuemin": min,
"aria-valuemax": max,
"aria-orientation": layout,
"aria-disabled": disabled,
"tooltip-props": this.tooltipProps
}
}, [h("div", {
"class": this.sliderRailClass,
"style": this.runwayStyle,
"on": {
"click": this.onSliderClick
},
"ref": "slider"
}, [h("div", {
"class": "".concat(this.componentName, "__track"),
"style": this.barStyle
}), h(slider_sliderButton["default"], {
"attrs": {
"vertical": vertical,
"value": range ? this.firstValue : this.prevValue,
"disabled": this.tDisabled,
"label": this.label,
"range": this.range,
"position": "start",
"tooltip-props": this.tooltipProps
},
"ref": "button1",
"on": {
"input": function input(v) {
range ? _this6.emitChange([v, _this6.secondValue]) : _this6.emitChange(v);
},
"mouseup": this.emitChangeEnd
}
}), this.range && h(slider_sliderButton["default"], {
"attrs": {
"vertical": vertical,
"value": this.secondValue,
"disabled": this.tDisabled,
"range": this.range,
"position": "end",
"label": this.label,
"tooltip-props": this.tooltipProps
},
"ref": "button2",
"on": {
"input": function input(v) {
_this6.emitChange([_this6.firstValue, v]);
},
"mouseup": this.emitChangeEnd
}
}), this.showSteps && h("div", {
"class": "".concat(this.componentName, "__stops")
}, [this.steps.map(function (item, key) {
if (item.position === 0 || item.position === 100) return null;
return h("div", {
"class": "".concat(_this6.componentName, "__stop"),
"key": key,
"style": _this6.getStopStyle(item)
});
})]), masks])]), buttonGroup]);
}
});
exports["default"] = _Slider;
//# sourceMappingURL=slider.js.map