ActionButton.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { c_ as b, B as p, _ as i, cT as y, e as O } from "./index2.js";
  2. import { shallowRef as s, onBeforeUnmount as m, defineComponent as P, onMounted as R, createVNode as T } from "vue";
  3. const x = () => {
  4. const n = s(!1);
  5. return m(() => {
  6. n.value = !0;
  7. }), n;
  8. }, A = {
  9. type: {
  10. type: String
  11. },
  12. actionFn: Function,
  13. close: Function,
  14. autofocus: Boolean,
  15. prefixCls: String,
  16. buttonProps: O(),
  17. emitEvent: Boolean,
  18. quitOnNullishReturnValue: Boolean
  19. };
  20. function d(n) {
  21. return !!(n && n.then);
  22. }
  23. const N = P({
  24. compatConfig: {
  25. MODE: 3
  26. },
  27. name: "ActionButton",
  28. props: A,
  29. setup(n, g) {
  30. let {
  31. slots: B
  32. } = g;
  33. const l = s(!1), c = s(), u = s(!1);
  34. let f;
  35. const v = x();
  36. R(() => {
  37. n.autofocus && (f = setTimeout(() => {
  38. var e, t;
  39. return (t = (e = b(c.value)) === null || e === void 0 ? void 0 : e.focus) === null || t === void 0 ? void 0 : t.call(e);
  40. }));
  41. }), m(() => {
  42. clearTimeout(f);
  43. });
  44. const a = function() {
  45. for (var e, t = arguments.length, o = new Array(t), r = 0; r < t; r++)
  46. o[r] = arguments[r];
  47. (e = n.close) === null || e === void 0 || e.call(n, ...o);
  48. }, h = (e) => {
  49. d(e) && (u.value = !0, e.then(function() {
  50. v.value || (u.value = !1), a(...arguments), l.value = !1;
  51. }, (t) => (v.value || (u.value = !1), l.value = !1, Promise.reject(t))));
  52. }, C = (e) => {
  53. const {
  54. actionFn: t
  55. } = n;
  56. if (l.value)
  57. return;
  58. if (l.value = !0, !t) {
  59. a();
  60. return;
  61. }
  62. let o;
  63. if (n.emitEvent) {
  64. if (o = t(e), n.quitOnNullishReturnValue && !d(o)) {
  65. l.value = !1, a(e);
  66. return;
  67. }
  68. } else if (t.length)
  69. o = t(n.close), l.value = !1;
  70. else if (o = t(), !o) {
  71. a();
  72. return;
  73. }
  74. h(o);
  75. };
  76. return () => {
  77. const {
  78. type: e,
  79. prefixCls: t,
  80. buttonProps: o
  81. } = n;
  82. return T(p, i(i(i({}, y(e)), {}, {
  83. onClick: C,
  84. loading: u.value,
  85. prefixCls: t
  86. }, o), {}, {
  87. ref: c
  88. }), B);
  89. };
  90. }
  91. });
  92. export {
  93. N as A
  94. };