BaseInput.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { P as i, _ as f } from "./index2.js";
  2. import { defineComponent as O, shallowRef as w, createVNode as h, ref as b, watch as k, computed as S } from "vue";
  3. var z = function(n, u) {
  4. var o = {};
  5. for (var t in n) Object.prototype.hasOwnProperty.call(n, t) && u.indexOf(t) < 0 && (o[t] = n[t]);
  6. if (n != null && typeof Object.getOwnPropertySymbols == "function") for (var r = 0, t = Object.getOwnPropertySymbols(n); r < t.length; r++)
  7. u.indexOf(t[r]) < 0 && Object.prototype.propertyIsEnumerable.call(n, t[r]) && (o[t[r]] = n[t[r]]);
  8. return o;
  9. };
  10. const K = O({
  11. compatConfig: {
  12. MODE: 3
  13. },
  14. // inheritAttrs: false,
  15. props: {
  16. disabled: i.looseBool,
  17. type: i.string,
  18. value: i.any,
  19. tag: {
  20. type: String,
  21. default: "input"
  22. },
  23. size: i.string,
  24. onChange: Function,
  25. onInput: Function,
  26. onBlur: Function,
  27. onFocus: Function,
  28. onKeydown: Function,
  29. onCompositionstart: Function,
  30. onCompositionend: Function,
  31. onKeyup: Function,
  32. onPaste: Function,
  33. onMousedown: Function
  34. },
  35. emits: ["change", "input", "blur", "keydown", "focus", "compositionstart", "compositionend", "keyup", "paste", "mousedown"],
  36. setup(n, u) {
  37. let {
  38. expose: o
  39. } = u;
  40. const t = w(null);
  41. return o({
  42. focus: () => {
  43. t.value && t.value.focus();
  44. },
  45. blur: () => {
  46. t.value && t.value.blur();
  47. },
  48. input: t,
  49. setSelectionRange: (l, c, d) => {
  50. var v;
  51. (v = t.value) === null || v === void 0 || v.setSelectionRange(l, c, d);
  52. },
  53. select: () => {
  54. var l;
  55. (l = t.value) === null || l === void 0 || l.select();
  56. },
  57. getSelectionStart: () => {
  58. var l;
  59. return (l = t.value) === null || l === void 0 ? void 0 : l.selectionStart;
  60. },
  61. getSelectionEnd: () => {
  62. var l;
  63. return (l = t.value) === null || l === void 0 ? void 0 : l.selectionEnd;
  64. },
  65. getScrollTop: () => {
  66. var l;
  67. return (l = t.value) === null || l === void 0 ? void 0 : l.scrollTop;
  68. }
  69. }), () => {
  70. const {
  71. tag: l,
  72. value: c
  73. } = n, d = z(n, ["tag", "value"]);
  74. return h(l, f(f({}, d), {}, {
  75. ref: t,
  76. value: c
  77. }), null);
  78. };
  79. }
  80. });
  81. function $(n) {
  82. const u = n.getBoundingClientRect(), o = document.documentElement;
  83. return {
  84. left: u.left + (window.scrollX || o.scrollLeft) - (o.clientLeft || document.body.clientLeft || 0),
  85. top: u.top + (window.scrollY || o.scrollTop) - (o.clientTop || document.body.clientTop || 0)
  86. };
  87. }
  88. function M(n) {
  89. return Object.keys(n).reduce((u, o) => {
  90. const t = n[o];
  91. return typeof t == "undefined" || t === null || (u += `${o}: ${n[o]};`), u;
  92. }, "");
  93. }
  94. var L = function(n, u) {
  95. var o = {};
  96. for (var t in n) Object.prototype.hasOwnProperty.call(n, t) && u.indexOf(t) < 0 && (o[t] = n[t]);
  97. if (n != null && typeof Object.getOwnPropertySymbols == "function") for (var r = 0, t = Object.getOwnPropertySymbols(n); r < t.length; r++)
  98. u.indexOf(t[r]) < 0 && Object.prototype.propertyIsEnumerable.call(n, t[r]) && (o[t[r]] = n[t[r]]);
  99. return o;
  100. };
  101. const A = O({
  102. compatConfig: {
  103. MODE: 3
  104. },
  105. inheritAttrs: !1,
  106. props: {
  107. disabled: i.looseBool,
  108. type: i.string,
  109. value: i.any,
  110. lazy: i.bool.def(!0),
  111. tag: {
  112. type: String,
  113. default: "input"
  114. },
  115. size: i.string,
  116. style: i.oneOfType([String, Object]),
  117. class: i.string
  118. },
  119. emits: ["change", "input", "blur", "keydown", "focus", "compositionstart", "compositionend", "keyup", "paste", "mousedown"],
  120. setup(n, u) {
  121. let {
  122. emit: o,
  123. attrs: t,
  124. expose: r
  125. } = u;
  126. const a = w(null), y = b(), s = b(!1);
  127. k([() => n.value, s], () => {
  128. s.value || (y.value = n.value);
  129. }, {
  130. immediate: !0
  131. });
  132. const l = (e) => {
  133. o("change", e);
  134. }, c = (e) => {
  135. s.value = !0, e.target.composing = !0, o("compositionstart", e);
  136. }, d = (e) => {
  137. s.value = !1, e.target.composing = !1, o("compositionend", e);
  138. const p = document.createEvent("HTMLEvents");
  139. p.initEvent("input", !0, !0), e.target.dispatchEvent(p), l(e);
  140. }, v = (e) => {
  141. if (s.value && n.lazy) {
  142. y.value = e.target.value;
  143. return;
  144. }
  145. o("input", e);
  146. }, _ = (e) => {
  147. o("blur", e);
  148. }, C = (e) => {
  149. o("focus", e);
  150. }, E = () => {
  151. a.value && a.value.focus();
  152. }, F = () => {
  153. a.value && a.value.blur();
  154. }, P = (e) => {
  155. o("keydown", e);
  156. }, j = (e) => {
  157. o("keyup", e);
  158. }, T = (e, p, g) => {
  159. var m;
  160. (m = a.value) === null || m === void 0 || m.setSelectionRange(e, p, g);
  161. }, B = () => {
  162. var e;
  163. (e = a.value) === null || e === void 0 || e.select();
  164. };
  165. r({
  166. focus: E,
  167. blur: F,
  168. input: S(() => {
  169. var e;
  170. return (e = a.value) === null || e === void 0 ? void 0 : e.input;
  171. }),
  172. setSelectionRange: T,
  173. select: B,
  174. getSelectionStart: () => {
  175. var e;
  176. return (e = a.value) === null || e === void 0 ? void 0 : e.getSelectionStart();
  177. },
  178. getSelectionEnd: () => {
  179. var e;
  180. return (e = a.value) === null || e === void 0 ? void 0 : e.getSelectionEnd();
  181. },
  182. getScrollTop: () => {
  183. var e;
  184. return (e = a.value) === null || e === void 0 ? void 0 : e.getScrollTop();
  185. }
  186. });
  187. const R = (e) => {
  188. o("mousedown", e);
  189. }, x = (e) => {
  190. o("paste", e);
  191. }, I = S(() => n.style && typeof n.style != "string" ? M(n.style) : n.style);
  192. return () => {
  193. const {
  194. style: e,
  195. lazy: p
  196. } = n, g = L(n, ["style", "lazy"]);
  197. return h(K, f(f(f({}, g), t), {}, {
  198. style: I.value,
  199. onInput: v,
  200. onChange: l,
  201. onBlur: _,
  202. onFocus: C,
  203. ref: a,
  204. value: y.value,
  205. onCompositionstart: c,
  206. onCompositionend: d,
  207. onKeyup: j,
  208. onKeydown: P,
  209. onPaste: x,
  210. onMousedown: R
  211. }), null);
  212. };
  213. }
  214. });
  215. export {
  216. A as B,
  217. $ as g
  218. };