SModal.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. var Q = Object.defineProperty, U = Object.defineProperties;
  2. var Z = Object.getOwnPropertyDescriptors;
  3. var G = Object.getOwnPropertySymbols;
  4. var x = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
  5. var z = (e, l, t) => l in e ? Q(e, l, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[l] = t, H = (e, l) => {
  6. for (var t in l || (l = {}))
  7. x.call(l, t) && z(e, t, l[t]);
  8. if (G)
  9. for (var t of G(l))
  10. j.call(l, t) && z(e, t, l[t]);
  11. return e;
  12. }, P = (e, l) => U(e, Z(l));
  13. import { unref as ee, isRef as te, toRefs as le, customRef as ne, getCurrentScope as oe, onScopeDispose as ae, ref as r, computed as _, watch as D, defineComponent as re, watchEffect as ue, resolveComponent as se, openBlock as L, createBlock as I, mergeProps as ie, createSlots as de, withCtx as W, createElementVNode as X, toDisplayString as ce, createVNode as fe, normalizeStyle as ve, resolveDynamicComponent as pe, renderSlot as J, createElementBlock as ye, createCommentVNode as me } from "vue";
  14. import he from "./ModalHeader.js";
  15. import { l as ge, aJ as Se } from "./index2.js";
  16. function be(e) {
  17. return oe() ? (ae(e), !0) : !1;
  18. }
  19. function i(e) {
  20. return typeof e == "function" ? e() : ee(e);
  21. }
  22. const q = typeof window != "undefined" && typeof document != "undefined";
  23. typeof WorkerGlobalScope != "undefined" && globalThis instanceof WorkerGlobalScope;
  24. const we = Object.prototype.toString, Ce = (e) => we.call(e) === "[object Object]", ke = () => {
  25. };
  26. function Me(e, l = {}) {
  27. if (!te(e))
  28. return le(e);
  29. const t = Array.isArray(e.value) ? Array.from({ length: e.value.length }) : {};
  30. for (const o in e.value)
  31. t[o] = ne(() => ({
  32. get() {
  33. return e.value[o];
  34. },
  35. set(u) {
  36. var d;
  37. if ((d = i(l.replaceRef)) != null ? d : !0)
  38. if (Array.isArray(e.value)) {
  39. const c = [...e.value];
  40. c[o] = u, e.value = c;
  41. } else {
  42. const c = P(H({}, e.value), { [o]: u });
  43. Object.setPrototypeOf(c, Object.getPrototypeOf(e.value)), e.value = c;
  44. }
  45. else
  46. e.value[o] = u;
  47. }
  48. }));
  49. return t;
  50. }
  51. const K = q ? window : void 0;
  52. function Be(e) {
  53. var l;
  54. const t = i(e);
  55. return (l = t == null ? void 0 : t.$el) != null ? l : t;
  56. }
  57. function V(...e) {
  58. let l, t, o, u;
  59. if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([t, o, u] = e, l = K) : [l, t, o, u] = e, !l)
  60. return ke;
  61. Array.isArray(t) || (t = [t]), Array.isArray(o) || (o = [o]);
  62. const d = [], p = () => {
  63. d.forEach((s) => s()), d.length = 0;
  64. }, c = (s, v, f, g) => (s.addEventListener(v, f, g), () => s.removeEventListener(v, f, g)), h = D(
  65. () => [Be(l), i(u)],
  66. ([s, v]) => {
  67. if (p(), !s)
  68. return;
  69. const f = Ce(v) ? H({}, v) : v;
  70. d.push(
  71. ...t.flatMap((g) => o.map((O) => c(s, g, O, f)))
  72. );
  73. },
  74. { immediate: !0, flush: "post" }
  75. ), b = () => {
  76. h(), p();
  77. };
  78. return be(b), b;
  79. }
  80. function Oe(e, l = {}) {
  81. var t, o;
  82. const {
  83. pointerTypes: u,
  84. preventDefault: d,
  85. stopPropagation: p,
  86. exact: c,
  87. onMove: h,
  88. onEnd: b,
  89. onStart: s,
  90. initialValue: v,
  91. axis: f = "both",
  92. draggingElement: g = K,
  93. containerElement: O,
  94. handle: C = e,
  95. buttons: Y = [0]
  96. } = l, S = r(
  97. (t = i(v)) != null ? t : { x: 0, y: 0 }
  98. ), y = r(), R = (n) => u ? u.includes(n.pointerType) : !0, A = (n) => {
  99. i(d) && n.preventDefault(), i(p) && n.stopPropagation();
  100. }, F = (n) => {
  101. var k;
  102. if (!i(Y).includes(n.button) || i(l.disabled) || !R(n) || i(c) && n.target !== i(e))
  103. return;
  104. const m = i(O), M = (k = m == null ? void 0 : m.getBoundingClientRect) == null ? void 0 : k.call(m), a = i(e).getBoundingClientRect(), w = {
  105. x: n.clientX - (m ? a.left - M.left + m.scrollLeft : a.left),
  106. y: n.clientY - (m ? a.top - M.top + m.scrollTop : a.top)
  107. };
  108. (s == null ? void 0 : s(w, n)) !== !1 && (y.value = w, A(n));
  109. }, E = (n) => {
  110. if (i(l.disabled) || !R(n) || !y.value)
  111. return;
  112. const k = i(O), m = i(e).getBoundingClientRect();
  113. let { x: M, y: a } = S.value;
  114. (f === "x" || f === "both") && (M = n.clientX - y.value.x, k && (M = Math.min(Math.max(0, M), k.scrollWidth - m.width))), (f === "y" || f === "both") && (a = n.clientY - y.value.y, k && (a = Math.min(Math.max(0, a), k.scrollHeight - m.height))), S.value = {
  115. x: M,
  116. y: a
  117. }, h == null || h(S.value, n), A(n);
  118. }, T = (n) => {
  119. i(l.disabled) || !R(n) || y.value && (y.value = void 0, b == null || b(S.value, n), A(n));
  120. };
  121. if (q) {
  122. const n = { capture: (o = l.capture) != null ? o : !0 };
  123. V(C, "pointerdown", F, n), V(g, "pointermove", E, n), V(g, "pointerup", T, n);
  124. }
  125. return P(H({}, Me(S)), {
  126. position: S,
  127. isDragging: _(() => !!y.value),
  128. style: _(
  129. () => `left:${S.value.x}px;top:${S.value.y}px;`
  130. )
  131. });
  132. }
  133. const Re = re({
  134. name: "SModal",
  135. props: {
  136. centered: {
  137. type: Boolean,
  138. default: !0
  139. },
  140. maskClosable: {
  141. type: Boolean,
  142. default: !0
  143. },
  144. mask: {
  145. type: Boolean,
  146. default: !0
  147. },
  148. topStyle: {
  149. type: String,
  150. default: ""
  151. },
  152. closable: {
  153. type: Boolean,
  154. default: !0
  155. },
  156. destroyOnClose: {
  157. type: Boolean,
  158. default: !1
  159. },
  160. keyboardOpen: {
  161. type: Boolean,
  162. default: !0
  163. },
  164. title: {
  165. type: String,
  166. default: ""
  167. },
  168. value: {
  169. type: Boolean,
  170. default: !1
  171. },
  172. haveFooter: {
  173. type: Boolean,
  174. default: !0
  175. },
  176. width: {
  177. type: [String, Number],
  178. default: "60vw"
  179. },
  180. boxHeight: {
  181. type: [String, Number],
  182. default: 60
  183. },
  184. bodyStyle: {
  185. type: Object,
  186. default() {
  187. return {
  188. overflowX: "hidden",
  189. overflowY: "auto"
  190. };
  191. }
  192. },
  193. showFullScreen: {
  194. type: Boolean,
  195. default: !0
  196. }
  197. },
  198. setup(e, { attrs: l, emit: t }) {
  199. const o = r("modalTitleRef"), u = r(), { x: d, y: p, isDragging: c } = Oe(u), h = r(0), b = r(0), s = r(!1), v = r(0), f = r(0), g = r(0), O = r(0), C = r({ left: 0, right: 0, top: 0, bottom: 0 }), Y = _(() => ({
  200. transform: `translate(${v.value}px, ${f.value}px)`
  201. }));
  202. D([d, p], () => {
  203. var a, w;
  204. if (!s.value) {
  205. h.value = d.value, b.value = p.value;
  206. const B = document.body.getBoundingClientRect(), $ = (w = (a = u.value) == null ? void 0 : a.getBoundingClientRect()) != null ? w : { width: 0, height: 0 };
  207. C.value.right = B.width - $.width, C.value.bottom = B.height - $.height, g.value = v.value, O.value = f.value;
  208. }
  209. s.value = !0;
  210. }), D(c, () => {
  211. c || (s.value = !1);
  212. }), ue(() => {
  213. s.value && (v.value = g.value + Math.min(Math.max(C.value.left, d.value), C.value.right) - h.value, f.value = O.value + Math.min(Math.max(C.value.top, p.value), C.value.bottom) - b.value);
  214. });
  215. const S = r(null), y = r(null), R = r(!1), A = r(), F = (a = 0, w = 0, B = 0) => {
  216. let $ = document.body.offsetHeight, N = 0;
  217. a + w + B + 85 >= $ ? N = $ - w - B - 82 : N = a, A.value = Object.assign(
  218. {
  219. height: `${N}px`
  220. },
  221. e.bodyStyle
  222. );
  223. }, E = r(e.width), T = r(), n = () => {
  224. E.value = "100vw", o.value = "", T.value = "s-full-modal", v.value = 0, f.value = 0;
  225. }, k = () => {
  226. E.value = e.width, o.value = "modalTitleRef", T.value = "";
  227. }, m = () => {
  228. t("update:value", !1), t("handCancel");
  229. }, M = () => {
  230. T.value = "", o.value = "modalTitleRef", E.value = e.width, t("afterClose");
  231. };
  232. return D(
  233. () => e.value,
  234. (a) => {
  235. a ? R.value = !0 : R.value = !1;
  236. },
  237. { deep: !0 }
  238. ), D(
  239. () => S.value,
  240. (a) => {
  241. if (a) {
  242. const w = a, B = (y == null ? void 0 : y.value) || null, $ = u.value;
  243. d.value = h.value, p.value = b.value, F(
  244. w.clientHeight,
  245. $.clientHeight,
  246. (B == null ? void 0 : B.clientHeight) || 0
  247. );
  248. }
  249. },
  250. { deep: !0 }
  251. ), {
  252. modalTitleRefS: o,
  253. isOpen: R,
  254. modalTitleRef: u,
  255. computeBodyStyle: A,
  256. modalWidth: E,
  257. fullModal: T,
  258. transformStyle: Y,
  259. handleFullScreen: n,
  260. handleReduction: k,
  261. closeModal: m,
  262. handleAfterClose: M,
  263. bodySlot: S,
  264. footerSlot: y,
  265. transformX: v,
  266. transformY: f,
  267. dragRect: C,
  268. startedDrag: s,
  269. isDragging: c,
  270. computeWindowStyle: F,
  271. startX: h,
  272. startY: b,
  273. preTransformX: g,
  274. preTransformY: O,
  275. x: d,
  276. y: p,
  277. attrs: l,
  278. listeners: t
  279. };
  280. },
  281. components: {
  282. ModalHeader: he
  283. }
  284. }), $e = { class: "modalHeader" }, Ae = { ref: "bodySlot" }, Ee = {
  285. key: 0,
  286. ref: "footerSlot"
  287. };
  288. function Te(e, l, t, o, u, d) {
  289. const p = se("ModalHeader"), c = Se;
  290. return L(), I(c, ie({
  291. open: e.isOpen,
  292. "body-style": e.computeBodyStyle,
  293. width: e.modalWidth,
  294. centered: e.centered,
  295. onCancel: e.closeModal,
  296. afterClose: e.handleAfterClose,
  297. destroyOnClose: e.destroyOnClose,
  298. keyboard: e.keyboardOpen,
  299. style: e.topStyle,
  300. maskClosable: e.maskClosable,
  301. mask: e.mask,
  302. "wrap-class-name": "s-modal " + e.fullModal
  303. }, e.attrs), de({
  304. title: W(() => [
  305. X("div", $e, [
  306. X("div", {
  307. ref: e.modalTitleRefS,
  308. class: "draggableTitle"
  309. }, ce(e.title), 513),
  310. fe(p, {
  311. width: e.modalWidth,
  312. showFullScreen: e.showFullScreen,
  313. onFullScreen: e.handleFullScreen,
  314. onReduction: e.handleReduction
  315. }, null, 8, ["width", "showFullScreen", "onFullScreen", "onReduction"])
  316. ])
  317. ]),
  318. modalRender: W(({ originVNode: h }) => [
  319. X("div", {
  320. style: ve(e.transformStyle)
  321. }, [
  322. (L(), I(pe(h)))
  323. ], 4)
  324. ]),
  325. default: W(() => [
  326. X("div", Ae, [
  327. J(e.$slots, "default", {}, void 0, !0)
  328. ], 512)
  329. ]),
  330. _: 2
  331. }, [
  332. e.haveFooter ? {
  333. name: "footer",
  334. fn: W(() => [
  335. e.$slots.footer ? (L(), ye("div", Ee, [
  336. J(e.$slots, "footer", {}, void 0, !0)
  337. ], 512)) : me("", !0)
  338. ]),
  339. key: "0"
  340. } : void 0
  341. ]), 1040, ["open", "body-style", "width", "centered", "onCancel", "afterClose", "destroyOnClose", "keyboard", "style", "maskClosable", "mask", "wrap-class-name"]);
  342. }
  343. const Xe = /* @__PURE__ */ ge(Re, [["render", Te], ["__scopeId", "data-v-fa6e7164"]]);
  344. export {
  345. Xe as default
  346. };