BaseInputInner.js 3.0 KB

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