BaseInputInner.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode } from "vue";
  3. var __rest = this && this.__rest || function (s, e) {
  4. var t = {};
  5. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  8. }
  9. return t;
  10. };
  11. import { defineComponent, shallowRef } from 'vue';
  12. import PropTypes from './vue-types';
  13. const BaseInputInner = defineComponent({
  14. compatConfig: {
  15. MODE: 3
  16. },
  17. // inheritAttrs: false,
  18. props: {
  19. disabled: PropTypes.looseBool,
  20. type: PropTypes.string,
  21. value: PropTypes.any,
  22. tag: {
  23. type: String,
  24. default: 'input'
  25. },
  26. size: PropTypes.string,
  27. onChange: Function,
  28. onInput: Function,
  29. onBlur: Function,
  30. onFocus: Function,
  31. onKeydown: Function,
  32. onCompositionstart: Function,
  33. onCompositionend: Function,
  34. onKeyup: Function,
  35. onPaste: Function,
  36. onMousedown: Function
  37. },
  38. emits: ['change', 'input', 'blur', 'keydown', 'focus', 'compositionstart', 'compositionend', 'keyup', 'paste', 'mousedown'],
  39. setup(props, _ref) {
  40. let {
  41. expose
  42. } = _ref;
  43. const inputRef = shallowRef(null);
  44. const focus = () => {
  45. if (inputRef.value) {
  46. inputRef.value.focus();
  47. }
  48. };
  49. const blur = () => {
  50. if (inputRef.value) {
  51. inputRef.value.blur();
  52. }
  53. };
  54. const setSelectionRange = (start, end, direction) => {
  55. var _a;
  56. (_a = inputRef.value) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end, direction);
  57. };
  58. const select = () => {
  59. var _a;
  60. (_a = inputRef.value) === null || _a === void 0 ? void 0 : _a.select();
  61. };
  62. expose({
  63. focus,
  64. blur,
  65. input: inputRef,
  66. setSelectionRange,
  67. select,
  68. getSelectionStart: () => {
  69. var _a;
  70. return (_a = inputRef.value) === null || _a === void 0 ? void 0 : _a.selectionStart;
  71. },
  72. getSelectionEnd: () => {
  73. var _a;
  74. return (_a = inputRef.value) === null || _a === void 0 ? void 0 : _a.selectionEnd;
  75. },
  76. getScrollTop: () => {
  77. var _a;
  78. return (_a = inputRef.value) === null || _a === void 0 ? void 0 : _a.scrollTop;
  79. }
  80. });
  81. return () => {
  82. const {
  83. tag: Tag,
  84. value
  85. } = props,
  86. restProps = __rest(props, ["tag", "value"]);
  87. return _createVNode(Tag, _objectSpread(_objectSpread({}, restProps), {}, {
  88. "ref": inputRef,
  89. "value": value
  90. }), null);
  91. };
  92. }
  93. });
  94. export default BaseInputInner;