Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VTextField.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Styles
  6. // Extensions
  7. // Components
  8. // Mixins
  9. // Directives
  10. // Utilities
  11. require('../../../src/stylus/components/_text-fields.styl');
  12. var _VInput = require('../VInput');
  13. var _VInput2 = _interopRequireDefault(_VInput);
  14. var _VCounter = require('../VCounter');
  15. var _VCounter2 = _interopRequireDefault(_VCounter);
  16. var _VLabel = require('../VLabel');
  17. var _VLabel2 = _interopRequireDefault(_VLabel);
  18. var _maskable = require('../../mixins/maskable');
  19. var _maskable2 = _interopRequireDefault(_maskable);
  20. var _loadable = require('../../mixins/loadable');
  21. var _loadable2 = _interopRequireDefault(_loadable);
  22. var _ripple = require('../../directives/ripple');
  23. var _ripple2 = _interopRequireDefault(_ripple);
  24. var _helpers = require('../../util/helpers');
  25. var _console = require('../../util/console');
  26. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27. var dirtyTypes = ['color', 'file', 'time', 'date', 'datetime-local', 'week', 'month'];
  28. /* @vue/component */
  29. exports.default = _VInput2.default.extend({
  30. name: 'v-text-field',
  31. directives: { Ripple: _ripple2.default },
  32. mixins: [_maskable2.default, _loadable2.default],
  33. inheritAttrs: false,
  34. props: {
  35. appendOuterIcon: String,
  36. /** @deprecated */
  37. appendOuterIconCb: Function,
  38. autofocus: Boolean,
  39. box: Boolean,
  40. browserAutocomplete: String,
  41. clearable: Boolean,
  42. clearIcon: {
  43. type: String,
  44. default: '$vuetify.icons.clear'
  45. },
  46. clearIconCb: Function,
  47. color: {
  48. type: String,
  49. default: 'primary'
  50. },
  51. counter: [Boolean, Number, String],
  52. flat: Boolean,
  53. fullWidth: Boolean,
  54. label: String,
  55. outline: Boolean,
  56. placeholder: String,
  57. prefix: String,
  58. prependInnerIcon: String,
  59. /** @deprecated */
  60. prependInnerIconCb: Function,
  61. reverse: Boolean,
  62. singleLine: Boolean,
  63. solo: Boolean,
  64. soloInverted: Boolean,
  65. suffix: String,
  66. type: {
  67. type: String,
  68. default: 'text'
  69. }
  70. },
  71. data: function data() {
  72. return {
  73. badInput: false,
  74. initialValue: null,
  75. internalChange: false,
  76. isClearing: false
  77. };
  78. },
  79. computed: {
  80. classes: function classes() {
  81. return {
  82. 'v-text-field': true,
  83. 'v-text-field--full-width': this.fullWidth,
  84. 'v-text-field--prefix': this.prefix,
  85. 'v-text-field--single-line': this.isSingle,
  86. 'v-text-field--solo': this.isSolo,
  87. 'v-text-field--solo-inverted': this.soloInverted,
  88. 'v-text-field--solo-flat': this.flat,
  89. 'v-text-field--box': this.box,
  90. 'v-text-field--enclosed': this.isEnclosed,
  91. 'v-text-field--reverse': this.reverse,
  92. 'v-text-field--outline': this.hasOutline,
  93. 'v-text-field--placeholder': this.placeholder
  94. };
  95. },
  96. counterValue: function counterValue() {
  97. return (this.internalValue || '').toString().length;
  98. },
  99. directivesInput: function directivesInput() {
  100. return [];
  101. },
  102. // TODO: Deprecate
  103. hasOutline: function hasOutline() {
  104. return this.outline || this.textarea;
  105. },
  106. internalValue: {
  107. get: function get() {
  108. return this.lazyValue;
  109. },
  110. set: function set(val) {
  111. if (this.mask && val !== this.lazyValue) {
  112. this.lazyValue = this.unmaskText(this.maskText(this.unmaskText(val)));
  113. this.setSelectionRange();
  114. } else {
  115. this.lazyValue = val;
  116. this.$emit('input', this.lazyValue);
  117. }
  118. }
  119. },
  120. isDirty: function isDirty() {
  121. return this.lazyValue != null && this.lazyValue.toString().length > 0 || this.badInput;
  122. },
  123. isEnclosed: function isEnclosed() {
  124. return this.box || this.isSolo || this.hasOutline || this.fullWidth;
  125. },
  126. isLabelActive: function isLabelActive() {
  127. return this.isDirty || dirtyTypes.includes(this.type);
  128. },
  129. isSingle: function isSingle() {
  130. return this.isSolo || this.singleLine;
  131. },
  132. isSolo: function isSolo() {
  133. return this.solo || this.soloInverted;
  134. },
  135. labelPosition: function labelPosition() {
  136. var offset = this.prefix && !this.labelValue ? this.prefixWidth : 0;
  137. return !this.$vuetify.rtl !== !this.reverse ? {
  138. left: 'auto',
  139. right: offset
  140. } : {
  141. left: offset,
  142. right: 'auto'
  143. };
  144. },
  145. showLabel: function showLabel() {
  146. return this.hasLabel && (!this.isSingle || !this.isLabelActive && !this.placeholder && !this.prefixLabel);
  147. },
  148. labelValue: function labelValue() {
  149. return !this.isSingle && Boolean(this.isFocused || this.isLabelActive || this.placeholder || this.prefixLabel);
  150. },
  151. prefixWidth: function prefixWidth() {
  152. if (!this.prefix && !this.$refs.prefix) return;
  153. return this.$refs.prefix.offsetWidth;
  154. },
  155. prefixLabel: function prefixLabel() {
  156. return this.prefix && !this.value;
  157. }
  158. },
  159. watch: {
  160. isFocused: function isFocused(val) {
  161. // Sets validationState from validatable
  162. this.hasColor = val;
  163. if (val) {
  164. this.initialValue = this.lazyValue;
  165. } else if (this.initialValue !== this.lazyValue) {
  166. this.$emit('change', this.lazyValue);
  167. }
  168. },
  169. value: function value(val) {
  170. var _this = this;
  171. if (this.mask && !this.internalChange) {
  172. var masked = this.maskText(this.unmaskText(val));
  173. this.lazyValue = this.unmaskText(masked);
  174. // Emit when the externally set value was modified internally
  175. String(val) !== this.lazyValue && this.$nextTick(function () {
  176. _this.$refs.input.value = masked;
  177. _this.$emit('input', _this.lazyValue);
  178. });
  179. } else this.lazyValue = val;
  180. }
  181. },
  182. mounted: function mounted() {
  183. this.autofocus && this.onFocus();
  184. },
  185. methods: {
  186. /** @public */
  187. focus: function focus() {
  188. this.onFocus();
  189. },
  190. /** @public */
  191. blur: function blur() {
  192. this.$refs.input ? this.$refs.input.blur() : this.onBlur();
  193. },
  194. clearableCallback: function clearableCallback() {
  195. var _this2 = this;
  196. this.internalValue = null;
  197. this.$nextTick(function () {
  198. return _this2.$refs.input.focus();
  199. });
  200. },
  201. genAppendSlot: function genAppendSlot() {
  202. var slot = [];
  203. if (this.$slots['append-outer']) {
  204. slot.push(this.$slots['append-outer']);
  205. } else if (this.appendOuterIcon) {
  206. slot.push(this.genIcon('appendOuter'));
  207. }
  208. return this.genSlot('append', 'outer', slot);
  209. },
  210. genPrependInnerSlot: function genPrependInnerSlot() {
  211. var slot = [];
  212. if (this.$slots['prepend-inner']) {
  213. slot.push(this.$slots['prepend-inner']);
  214. } else if (this.prependInnerIcon) {
  215. slot.push(this.genIcon('prependInner'));
  216. }
  217. return this.genSlot('prepend', 'inner', slot);
  218. },
  219. genIconSlot: function genIconSlot() {
  220. var slot = [];
  221. if (this.$slots['append']) {
  222. slot.push(this.$slots['append']);
  223. } else if (this.appendIcon) {
  224. slot.push(this.genIcon('append'));
  225. }
  226. return this.genSlot('append', 'inner', slot);
  227. },
  228. genInputSlot: function genInputSlot() {
  229. var input = _VInput2.default.options.methods.genInputSlot.call(this);
  230. var prepend = this.genPrependInnerSlot();
  231. prepend && input.children.unshift(prepend);
  232. return input;
  233. },
  234. genClearIcon: function genClearIcon() {
  235. if (!this.clearable) return null;
  236. var icon = !this.isDirty ? false : 'clear';
  237. if (this.clearIconCb) (0, _console.deprecate)(':clear-icon-cb', '@click:clear', this);
  238. return this.genSlot('append', 'inner', [this.genIcon(icon, !this.$listeners['click:clear'] && this.clearIconCb || this.clearableCallback, false)]);
  239. },
  240. genCounter: function genCounter() {
  241. if (this.counter === false || this.counter == null) return null;
  242. var max = this.counter === true ? this.$attrs.maxlength : this.counter;
  243. return this.$createElement(_VCounter2.default, {
  244. props: {
  245. dark: this.dark,
  246. light: this.light,
  247. max: max,
  248. value: this.counterValue
  249. }
  250. });
  251. },
  252. genDefaultSlot: function genDefaultSlot() {
  253. return [this.genTextFieldSlot(), this.genClearIcon(), this.genIconSlot(), this.genProgress()];
  254. },
  255. genLabel: function genLabel() {
  256. if (!this.showLabel) return null;
  257. var data = {
  258. props: {
  259. absolute: true,
  260. color: this.validationState,
  261. dark: this.dark,
  262. disabled: this.disabled,
  263. focused: !this.isSingle && (this.isFocused || !!this.validationState),
  264. left: this.labelPosition.left,
  265. light: this.light,
  266. right: this.labelPosition.right,
  267. value: this.labelValue
  268. }
  269. };
  270. if (this.$attrs.id) data.props.for = this.$attrs.id;
  271. return this.$createElement(_VLabel2.default, data, this.$slots.label || this.label);
  272. },
  273. genInput: function genInput() {
  274. var listeners = Object.assign({}, this.$listeners);
  275. delete listeners['change']; // Change should not be bound externally
  276. var data = {
  277. style: {},
  278. domProps: {
  279. value: this.maskText(this.lazyValue)
  280. },
  281. attrs: _extends({
  282. 'aria-label': (!this.$attrs || !this.$attrs.id) && this.label
  283. }, this.$attrs, {
  284. autofocus: this.autofocus,
  285. disabled: this.disabled,
  286. readonly: this.readonly,
  287. type: this.type
  288. }),
  289. on: Object.assign(listeners, {
  290. blur: this.onBlur,
  291. input: this.onInput,
  292. focus: this.onFocus,
  293. keydown: this.onKeyDown
  294. }),
  295. ref: 'input'
  296. };
  297. if (this.placeholder) data.attrs.placeholder = this.placeholder;
  298. if (this.mask) data.attrs.maxlength = this.masked.length;
  299. if (this.browserAutocomplete) data.attrs.autocomplete = this.browserAutocomplete;
  300. return this.$createElement('input', data);
  301. },
  302. genMessages: function genMessages() {
  303. if (this.hideDetails) return null;
  304. return this.$createElement('div', {
  305. staticClass: 'v-text-field__details'
  306. }, [_VInput2.default.options.methods.genMessages.call(this), this.genCounter()]);
  307. },
  308. genTextFieldSlot: function genTextFieldSlot() {
  309. return this.$createElement('div', {
  310. staticClass: 'v-text-field__slot'
  311. }, [this.genLabel(), this.prefix ? this.genAffix('prefix') : null, this.genInput(), this.suffix ? this.genAffix('suffix') : null]);
  312. },
  313. genAffix: function genAffix(type) {
  314. return this.$createElement('div', {
  315. 'class': 'v-text-field__' + type,
  316. ref: type
  317. }, this[type]);
  318. },
  319. onBlur: function onBlur(e) {
  320. this.isFocused = false;
  321. // Reset internalChange state
  322. // to allow external change
  323. // to persist
  324. this.internalChange = false;
  325. this.$emit('blur', e);
  326. },
  327. onClick: function onClick() {
  328. if (this.isFocused || this.disabled) return;
  329. this.$refs.input.focus();
  330. },
  331. onFocus: function onFocus(e) {
  332. if (!this.$refs.input) return;
  333. if (document.activeElement !== this.$refs.input) {
  334. return this.$refs.input.focus();
  335. }
  336. if (!this.isFocused) {
  337. this.isFocused = true;
  338. this.$emit('focus', e);
  339. }
  340. },
  341. onInput: function onInput(e) {
  342. this.internalChange = true;
  343. this.mask && this.resetSelections(e.target);
  344. this.internalValue = e.target.value;
  345. this.badInput = e.target.validity && e.target.validity.badInput;
  346. },
  347. onKeyDown: function onKeyDown(e) {
  348. this.internalChange = true;
  349. if (e.keyCode === _helpers.keyCodes.enter) this.$emit('change', this.internalValue);
  350. this.$emit('keydown', e);
  351. },
  352. onMouseDown: function onMouseDown(e) {
  353. // Prevent input from being blurred
  354. if (e.target !== this.$refs.input) {
  355. e.preventDefault();
  356. e.stopPropagation();
  357. }
  358. _VInput2.default.options.methods.onMouseDown.call(this, e);
  359. },
  360. onMouseUp: function onMouseUp(e) {
  361. if (this.hasMouseDown) this.focus();
  362. _VInput2.default.options.methods.onMouseUp.call(this, e);
  363. }
  364. }
  365. });
  366. //# sourceMappingURL=VTextField.js.map