项目原始demo,不改动
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.
 
 
 
 

527 Zeilen
20 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. require("../../../src/components/VSlider/VSlider.sass");
  7. var _VInput = _interopRequireDefault(require("../VInput"));
  8. var _transitions = require("../transitions");
  9. var _mixins = _interopRequireDefault(require("../../util/mixins"));
  10. var _loadable = _interopRequireDefault(require("../../mixins/loadable"));
  11. var _clickOutside = _interopRequireDefault(require("../../directives/click-outside"));
  12. var _helpers = require("../../util/helpers");
  13. var _console = require("../../util/console");
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  16. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  17. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  18. var _default2 = (0, _mixins.default)(_VInput.default, _loadable.default
  19. /* @vue/component */
  20. ).extend({
  21. name: 'v-slider',
  22. directives: {
  23. ClickOutside: _clickOutside.default
  24. },
  25. mixins: [_loadable.default],
  26. props: {
  27. disabled: Boolean,
  28. inverseLabel: Boolean,
  29. max: {
  30. type: [Number, String],
  31. default: 100
  32. },
  33. min: {
  34. type: [Number, String],
  35. default: 0
  36. },
  37. step: {
  38. type: [Number, String],
  39. default: 1
  40. },
  41. thumbColor: String,
  42. thumbLabel: {
  43. type: [Boolean, String],
  44. default: undefined,
  45. validator: function validator(v) {
  46. return typeof v === 'boolean' || v === 'always';
  47. }
  48. },
  49. thumbSize: {
  50. type: [Number, String],
  51. default: 32
  52. },
  53. tickLabels: {
  54. type: Array,
  55. default: function _default() {
  56. return [];
  57. }
  58. },
  59. ticks: {
  60. type: [Boolean, String],
  61. default: false,
  62. validator: function validator(v) {
  63. return typeof v === 'boolean' || v === 'always';
  64. }
  65. },
  66. tickSize: {
  67. type: [Number, String],
  68. default: 2
  69. },
  70. trackColor: String,
  71. trackFillColor: String,
  72. value: [Number, String],
  73. vertical: Boolean
  74. },
  75. data: function data() {
  76. return {
  77. app: null,
  78. oldValue: null,
  79. keyPressed: 0,
  80. isFocused: false,
  81. isActive: false,
  82. noClick: false
  83. };
  84. },
  85. computed: {
  86. classes: function classes() {
  87. return _objectSpread({}, _VInput.default.options.computed.classes.call(this), {
  88. 'v-input__slider': true,
  89. 'v-input__slider--vertical': this.vertical,
  90. 'v-input__slider--inverse-label': this.inverseLabel
  91. });
  92. },
  93. internalValue: {
  94. get: function get() {
  95. return this.lazyValue;
  96. },
  97. set: function set(val) {
  98. val = isNaN(val) ? this.minValue : val; // Round value to ensure the
  99. // entire slider range can
  100. // be selected with step
  101. var value = this.roundValue(Math.min(Math.max(val, this.minValue), this.maxValue));
  102. if (value === this.lazyValue) return;
  103. this.lazyValue = value;
  104. this.$emit('input', value);
  105. }
  106. },
  107. trackTransition: function trackTransition() {
  108. return this.keyPressed >= 2 ? 'none' : '';
  109. },
  110. minValue: function minValue() {
  111. return parseFloat(this.min);
  112. },
  113. maxValue: function maxValue() {
  114. return parseFloat(this.max);
  115. },
  116. stepNumeric: function stepNumeric() {
  117. return this.step > 0 ? parseFloat(this.step) : 0;
  118. },
  119. inputWidth: function inputWidth() {
  120. var value = (this.roundValue(this.internalValue) - this.minValue) / (this.maxValue - this.minValue) * 100;
  121. return value;
  122. },
  123. trackFillStyles: function trackFillStyles() {
  124. var _ref;
  125. var startDir = this.vertical ? 'bottom' : 'left';
  126. var endDir = this.vertical ? 'top' : 'right';
  127. var valueDir = this.vertical ? 'height' : 'width';
  128. var start = this.$vuetify.rtl ? 'auto' : '0';
  129. var end = this.$vuetify.rtl ? '0' : 'auto';
  130. var value = this.disabled ? "calc(".concat(this.inputWidth, "% - 10px)") : "".concat(this.inputWidth, "%");
  131. return _ref = {
  132. transition: this.trackTransition
  133. }, _defineProperty(_ref, startDir, start), _defineProperty(_ref, endDir, end), _defineProperty(_ref, valueDir, value), _ref;
  134. },
  135. trackStyles: function trackStyles() {
  136. var _ref2;
  137. var startDir = this.vertical ? this.$vuetify.rtl ? 'bottom' : 'top' : this.$vuetify.rtl ? 'left' : 'right';
  138. var endDir = this.vertical ? 'height' : 'width';
  139. var start = '0px';
  140. var end = this.disabled ? "calc(".concat(100 - this.inputWidth, "% - 10px)") : "calc(".concat(100 - this.inputWidth, "%)");
  141. return _ref2 = {
  142. transition: this.trackTransition
  143. }, _defineProperty(_ref2, startDir, start), _defineProperty(_ref2, endDir, end), _ref2;
  144. },
  145. showTicks: function showTicks() {
  146. return this.tickLabels.length > 0 || !!(!this.disabled && this.stepNumeric && this.ticks);
  147. },
  148. numTicks: function numTicks() {
  149. return Math.ceil((this.maxValue - this.minValue) / this.stepNumeric);
  150. },
  151. showThumbLabel: function showThumbLabel() {
  152. return !this.disabled && !!(this.thumbLabel || this.$scopedSlots['thumb-label']);
  153. },
  154. computedTrackColor: function computedTrackColor() {
  155. if (this.disabled) return undefined;
  156. if (this.trackColor) return this.trackColor;
  157. if (this.isDark) return this.validationState;
  158. return this.validationState || 'primary lighten-3';
  159. },
  160. computedTrackFillColor: function computedTrackFillColor() {
  161. if (this.disabled) return undefined;
  162. if (this.trackFillColor) return this.trackFillColor;
  163. return this.validationState || this.computedColor;
  164. },
  165. computedThumbColor: function computedThumbColor() {
  166. if (this.thumbColor) return this.thumbColor;
  167. return this.validationState || this.computedColor;
  168. }
  169. },
  170. watch: {
  171. min: function min(val) {
  172. var parsed = parseFloat(val);
  173. parsed > this.internalValue && this.$emit('input', parsed);
  174. },
  175. max: function max(val) {
  176. var parsed = parseFloat(val);
  177. parsed < this.internalValue && this.$emit('input', parsed);
  178. },
  179. value: {
  180. handler: function handler(v) {
  181. this.internalValue = v;
  182. }
  183. }
  184. },
  185. // If done in as immediate in
  186. // value watcher, causes issues
  187. // with vue-test-utils
  188. beforeMount: function beforeMount() {
  189. this.internalValue = this.value;
  190. },
  191. mounted: function mounted() {
  192. // Without a v-app, iOS does not work with body selectors
  193. this.app = document.querySelector('[data-app]') || (0, _console.consoleWarn)('Missing v-app or a non-body wrapping element with the [data-app] attribute', this);
  194. },
  195. methods: {
  196. genDefaultSlot: function genDefaultSlot() {
  197. var children = [this.genLabel()];
  198. var slider = this.genSlider();
  199. this.inverseLabel ? children.unshift(slider) : children.push(slider);
  200. children.push(this.genProgress());
  201. return children;
  202. },
  203. genSlider: function genSlider() {
  204. return this.$createElement('div', {
  205. class: _objectSpread({
  206. 'v-slider': true,
  207. 'v-slider--horizontal': !this.vertical,
  208. 'v-slider--vertical': this.vertical,
  209. 'v-slider--focused': this.isFocused,
  210. 'v-slider--active': this.isActive,
  211. 'v-slider--disabled': this.disabled,
  212. 'v-slider--readonly': this.readonly
  213. }, this.themeClasses),
  214. directives: [{
  215. name: 'click-outside',
  216. value: this.onBlur
  217. }],
  218. on: {
  219. click: this.onSliderClick
  220. }
  221. }, this.genChildren());
  222. },
  223. genChildren: function genChildren() {
  224. return [this.genInput(), this.genTrackContainer(), this.genSteps(), this.genThumbContainer(this.internalValue, this.inputWidth, this.isActive, this.isFocused, this.onThumbMouseDown, this.onFocus, this.onBlur)];
  225. },
  226. genInput: function genInput() {
  227. return this.$createElement('input', {
  228. attrs: _objectSpread({
  229. value: this.internalValue,
  230. id: this.computedId,
  231. disabled: this.disabled,
  232. readonly: true,
  233. tabindex: -1
  234. }, this.$attrs)
  235. });
  236. },
  237. genTrackContainer: function genTrackContainer() {
  238. var children = [this.$createElement('div', this.setBackgroundColor(this.computedTrackColor, {
  239. staticClass: 'v-slider__track-background',
  240. style: this.trackStyles
  241. })), this.$createElement('div', this.setBackgroundColor(this.computedTrackFillColor, {
  242. staticClass: 'v-slider__track-fill',
  243. style: this.trackFillStyles
  244. }))];
  245. return this.$createElement('div', {
  246. staticClass: 'v-slider__track-container',
  247. ref: 'track'
  248. }, children);
  249. },
  250. genSteps: function genSteps() {
  251. var _this = this;
  252. if (!this.step || !this.showTicks) return null;
  253. var tickSize = parseFloat(this.tickSize);
  254. var range = (0, _helpers.createRange)(this.numTicks + 1);
  255. var direction = this.vertical ? 'bottom' : this.$vuetify.rtl ? 'right' : 'left';
  256. var offsetDirection = this.vertical ? this.$vuetify.rtl ? 'left' : 'right' : 'top';
  257. if (this.vertical) range.reverse();
  258. var ticks = range.map(function (index) {
  259. var _style;
  260. var children = [];
  261. if (_this.tickLabels[index]) {
  262. children.push(_this.$createElement('div', {
  263. staticClass: 'v-slider__tick-label'
  264. }, _this.tickLabels[index]));
  265. }
  266. var width = index * (100 / _this.numTicks);
  267. var filled = _this.$vuetify.rtl ? 100 - _this.inputWidth < width : width < _this.inputWidth;
  268. return _this.$createElement('span', {
  269. key: index,
  270. staticClass: 'v-slider__tick',
  271. class: {
  272. 'v-slider__tick--filled': filled
  273. },
  274. style: (_style = {
  275. width: "".concat(tickSize, "px"),
  276. height: "".concat(tickSize, "px")
  277. }, _defineProperty(_style, direction, "calc(".concat(width, "% - ").concat(tickSize / 2, "px)")), _defineProperty(_style, offsetDirection, "calc(50% - ".concat(tickSize / 2, "px)")), _style)
  278. }, children);
  279. });
  280. return this.$createElement('div', {
  281. staticClass: 'v-slider__ticks-container',
  282. class: {
  283. 'v-slider__ticks-container--always-show': this.ticks === 'always' || this.tickLabels.length > 0
  284. }
  285. }, ticks);
  286. },
  287. genThumbContainer: function genThumbContainer(value, valueWidth, isActive, isFocused, onDrag, onFocus, onBlur) {
  288. var ref = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'thumb';
  289. var children = [this.genThumb()];
  290. var thumbLabelContent = this.genThumbLabelContent(value);
  291. this.showThumbLabel && children.push(this.genThumbLabel(thumbLabelContent));
  292. return this.$createElement('div', this.setTextColor(this.computedThumbColor, {
  293. ref: ref,
  294. key: ref,
  295. staticClass: 'v-slider__thumb-container',
  296. class: {
  297. 'v-slider__thumb-container--active': isActive,
  298. 'v-slider__thumb-container--focused': isFocused,
  299. 'v-slider__thumb-container--show-label': this.showThumbLabel
  300. },
  301. style: this.getThumbContainerStyles(valueWidth),
  302. attrs: _objectSpread({
  303. role: 'slider',
  304. tabindex: this.disabled || this.readonly ? -1 : this.$attrs.tabindex ? this.$attrs.tabindex : 0,
  305. 'aria-label': this.label,
  306. 'aria-valuemin': this.min,
  307. 'aria-valuemax': this.max,
  308. 'aria-valuenow': this.internalValue,
  309. 'aria-readonly': String(this.readonly),
  310. 'aria-orientation': this.vertical ? 'vertical' : 'horizontal'
  311. }, this.$attrs),
  312. on: {
  313. focus: onFocus,
  314. blur: onBlur,
  315. keydown: this.onKeyDown,
  316. keyup: this.onKeyUp,
  317. touchstart: onDrag,
  318. mousedown: onDrag
  319. }
  320. }), children);
  321. },
  322. genThumbLabelContent: function genThumbLabelContent(value) {
  323. return this.$scopedSlots['thumb-label'] ? this.$scopedSlots['thumb-label']({
  324. value: value
  325. }) : [this.$createElement('span', [String(value)])];
  326. },
  327. genThumbLabel: function genThumbLabel(content) {
  328. var size = (0, _helpers.convertToUnit)(this.thumbSize);
  329. var transform = this.vertical ? "translateY(20%) translateY(".concat(Number(this.thumbSize) / 3 - 1, "px) translateX(55%) rotate(135deg)") : "translateY(-20%) translateY(-12px) translateX(-50%) rotate(45deg)";
  330. return this.$createElement(_transitions.VScaleTransition, {
  331. props: {
  332. origin: 'bottom center'
  333. }
  334. }, [this.$createElement('div', {
  335. staticClass: 'v-slider__thumb-label-container',
  336. directives: [{
  337. name: 'show',
  338. value: this.isFocused || this.isActive || this.thumbLabel === 'always'
  339. }]
  340. }, [this.$createElement('div', this.setBackgroundColor(this.computedThumbColor, {
  341. staticClass: 'v-slider__thumb-label',
  342. style: {
  343. height: size,
  344. width: size,
  345. transform: transform
  346. }
  347. }), [this.$createElement('div', content)])])]);
  348. },
  349. genThumb: function genThumb() {
  350. return this.$createElement('div', this.setBackgroundColor(this.computedThumbColor, {
  351. staticClass: 'v-slider__thumb'
  352. }));
  353. },
  354. getThumbContainerStyles: function getThumbContainerStyles(width) {
  355. var direction = this.vertical ? 'top' : 'left';
  356. var value = this.$vuetify.rtl ? 100 - width : width;
  357. value = this.vertical ? 100 - value : value;
  358. return _defineProperty({
  359. transition: this.trackTransition
  360. }, direction, "".concat(value, "%"));
  361. },
  362. onThumbMouseDown: function onThumbMouseDown(e) {
  363. e.preventDefault();
  364. this.oldValue = this.internalValue;
  365. this.keyPressed = 2;
  366. this.isActive = true;
  367. var mouseUpOptions = _helpers.passiveSupported ? {
  368. passive: true,
  369. capture: true
  370. } : true;
  371. var mouseMoveOptions = _helpers.passiveSupported ? {
  372. passive: true
  373. } : false;
  374. if ('touches' in e) {
  375. this.app.addEventListener('touchmove', this.onMouseMove, mouseMoveOptions);
  376. (0, _helpers.addOnceEventListener)(this.app, 'touchend', this.onSliderMouseUp, mouseUpOptions);
  377. } else {
  378. this.app.addEventListener('mousemove', this.onMouseMove, mouseMoveOptions);
  379. (0, _helpers.addOnceEventListener)(this.app, 'mouseup', this.onSliderMouseUp, mouseUpOptions);
  380. }
  381. this.$emit('start', this.internalValue);
  382. },
  383. onSliderMouseUp: function onSliderMouseUp(e) {
  384. e.stopPropagation();
  385. this.keyPressed = 0;
  386. var mouseMoveOptions = _helpers.passiveSupported ? {
  387. passive: true
  388. } : false;
  389. this.app.removeEventListener('touchmove', this.onMouseMove, mouseMoveOptions);
  390. this.app.removeEventListener('mousemove', this.onMouseMove, mouseMoveOptions);
  391. this.$emit('end', this.internalValue);
  392. if (!(0, _helpers.deepEqual)(this.oldValue, this.internalValue)) {
  393. this.$emit('change', this.internalValue);
  394. this.noClick = true;
  395. }
  396. this.isActive = false;
  397. },
  398. onMouseMove: function onMouseMove(e) {
  399. var _this$parseMouseMove = this.parseMouseMove(e),
  400. value = _this$parseMouseMove.value;
  401. this.internalValue = value;
  402. },
  403. onKeyDown: function onKeyDown(e) {
  404. if (this.disabled || this.readonly) return;
  405. var value = this.parseKeyDown(e, this.internalValue);
  406. if (value == null) return;
  407. this.internalValue = value;
  408. this.$emit('change', value);
  409. },
  410. onKeyUp: function onKeyUp() {
  411. this.keyPressed = 0;
  412. },
  413. onSliderClick: function onSliderClick(e) {
  414. if (this.noClick) {
  415. this.noClick = false;
  416. return;
  417. }
  418. var thumb = this.$refs.thumb;
  419. thumb.focus();
  420. this.onMouseMove(e);
  421. this.$emit('change', this.internalValue);
  422. },
  423. onBlur: function onBlur(e) {
  424. this.isFocused = false;
  425. this.$emit('blur', e);
  426. },
  427. onFocus: function onFocus(e) {
  428. this.isFocused = true;
  429. this.$emit('focus', e);
  430. },
  431. parseMouseMove: function parseMouseMove(e) {
  432. var start = this.vertical ? 'top' : 'left';
  433. var length = this.vertical ? 'height' : 'width';
  434. var click = this.vertical ? 'clientY' : 'clientX';
  435. var _this$$refs$track$get = this.$refs.track.getBoundingClientRect(),
  436. trackStart = _this$$refs$track$get[start],
  437. trackLength = _this$$refs$track$get[length];
  438. var clickOffset = 'touches' in e ? e.touches[0][click] : e[click]; // Can we get rid of any here?
  439. // It is possible for left to be NaN, force to number
  440. var clickPos = Math.min(Math.max((clickOffset - trackStart) / trackLength, 0), 1) || 0;
  441. if (this.vertical) clickPos = 1 - clickPos;
  442. if (this.$vuetify.rtl) clickPos = 1 - clickPos;
  443. var isInsideTrack = clickOffset >= trackStart && clickOffset <= trackStart + trackLength;
  444. var value = parseFloat(this.min) + clickPos * (this.maxValue - this.minValue);
  445. return {
  446. value: value,
  447. isInsideTrack: isInsideTrack
  448. };
  449. },
  450. parseKeyDown: function parseKeyDown(e, value) {
  451. if (this.disabled) return;
  452. var pageup = _helpers.keyCodes.pageup,
  453. pagedown = _helpers.keyCodes.pagedown,
  454. end = _helpers.keyCodes.end,
  455. home = _helpers.keyCodes.home,
  456. left = _helpers.keyCodes.left,
  457. right = _helpers.keyCodes.right,
  458. down = _helpers.keyCodes.down,
  459. up = _helpers.keyCodes.up;
  460. if (![pageup, pagedown, end, home, left, right, down, up].includes(e.keyCode)) return;
  461. e.preventDefault();
  462. var step = this.stepNumeric || 1;
  463. var steps = (this.maxValue - this.minValue) / step;
  464. if ([left, right, down, up].includes(e.keyCode)) {
  465. this.keyPressed += 1;
  466. var increase = this.$vuetify.rtl ? [left, up] : [right, up];
  467. var direction = increase.includes(e.keyCode) ? 1 : -1;
  468. var multiplier = e.shiftKey ? 3 : e.ctrlKey ? 2 : 1;
  469. value = value + direction * step * multiplier;
  470. } else if (e.keyCode === home) {
  471. value = this.minValue;
  472. } else if (e.keyCode === end) {
  473. value = this.maxValue;
  474. } else {
  475. var _direction = e.keyCode === pagedown ? 1 : -1;
  476. value = value - _direction * step * (steps > 100 ? steps / 10 : 10);
  477. }
  478. return value;
  479. },
  480. roundValue: function roundValue(value) {
  481. if (!this.stepNumeric) return value; // Format input value using the same number
  482. // of decimals places as in the step prop
  483. var trimmedStep = this.step.toString().trim();
  484. var decimals = trimmedStep.indexOf('.') > -1 ? trimmedStep.length - trimmedStep.indexOf('.') - 1 : 0;
  485. var offset = this.minValue % this.stepNumeric;
  486. var newValue = Math.round((value - offset) / this.stepNumeric) * this.stepNumeric + offset;
  487. return parseFloat(Math.min(newValue, this.maxValue).toFixed(decimals));
  488. }
  489. }
  490. });
  491. exports.default = _default2;
  492. //# sourceMappingURL=VSlider.js.map