@gopowerteam/modal-render 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,404 +0,0 @@
1
- import { unref as J, isRef as Q, toRefs as Z, customRef as j, getCurrentScope as ee, onScopeDispose as te, ref as $, computed as x, watch as oe, defineComponent as X, inject as R, shallowRef as A, onMounted as Y, onUnmounted as ne, openBlock as g, createElementBlock as b, createElementVNode as w, normalizeStyle as z, withModifiers as re, normalizeClass as ie, toDisplayString as se, createCommentVNode as P, createBlock as N, resolveDynamicComponent as le, normalizeProps as ae, guardReactiveProps as ue, triggerRef as S, provide as de, Fragment as I, renderSlot as ce, Teleport as fe, createVNode as pe, TransitionGroup as me, withCtx as ve, renderList as ye, mergeProps as he, defineAsyncComponent as ge, getCurrentInstance as K } from "vue";
2
- const B = Symbol("__MODAL__");
3
- function _e(o) {
4
- return ee() ? (te(o), !0) : !1;
5
- }
6
- function h(o) {
7
- return typeof o == "function" ? o() : J(o);
8
- }
9
- const q = typeof window < "u" && typeof document < "u", we = Object.prototype.toString, be = (o) => we.call(o) === "[object Object]", xe = () => {
10
- };
11
- function Ce(o, i = {}) {
12
- if (!Q(o))
13
- return Z(o);
14
- const e = Array.isArray(o.value) ? Array.from({ length: o.value.length }) : {};
15
- for (const n in o.value)
16
- e[n] = j(() => ({
17
- get() {
18
- return o.value[n];
19
- },
20
- set(r) {
21
- var u;
22
- if ((u = h(i.replaceRef)) != null ? u : !0)
23
- if (Array.isArray(o.value)) {
24
- const p = [...o.value];
25
- p[n] = r, o.value = p;
26
- } else {
27
- const p = { ...o.value, [n]: r };
28
- Object.setPrototypeOf(p, Object.getPrototypeOf(o.value)), o.value = p;
29
- }
30
- else
31
- o.value[n] = r;
32
- }
33
- }));
34
- return e;
35
- }
36
- function Ee(o) {
37
- var i;
38
- const e = h(o);
39
- return (i = e == null ? void 0 : e.$el) != null ? i : e;
40
- }
41
- const G = q ? window : void 0;
42
- function W(...o) {
43
- let i, e, n, r;
44
- if (typeof o[0] == "string" || Array.isArray(o[0]) ? ([e, n, r] = o, i = G) : [i, e, n, r] = o, !i)
45
- return xe;
46
- Array.isArray(e) || (e = [e]), Array.isArray(n) || (n = [n]);
47
- const u = [], v = () => {
48
- u.forEach((a) => a()), u.length = 0;
49
- }, p = (a, s, d, c) => (a.addEventListener(s, d, c), () => a.removeEventListener(s, d, c)), m = oe(
50
- () => [Ee(i), h(r)],
51
- ([a, s]) => {
52
- if (v(), !a)
53
- return;
54
- const d = be(s) ? { ...s } : s;
55
- u.push(
56
- ...e.flatMap((c) => n.map((C) => p(a, c, C, d)))
57
- );
58
- },
59
- { immediate: !0, flush: "post" }
60
- ), l = () => {
61
- m(), v();
62
- };
63
- return _e(l), l;
64
- }
65
- function Me(o, i = {}) {
66
- var e, n;
67
- const {
68
- pointerTypes: r,
69
- preventDefault: u,
70
- stopPropagation: v,
71
- exact: p,
72
- onMove: m,
73
- onEnd: l,
74
- onStart: a,
75
- initialValue: s,
76
- axis: d = "both",
77
- draggingElement: c = G,
78
- containerElement: C,
79
- handle: L = o
80
- } = i, y = $(
81
- (e = h(s)) != null ? e : { x: 0, y: 0 }
82
- ), _ = $(), E = (t) => r ? r.includes(t.pointerType) : !0, M = (t) => {
83
- h(u) && t.preventDefault(), h(v) && t.stopPropagation();
84
- }, D = (t) => {
85
- var f;
86
- if (!E(t) || h(p) && t.target !== h(o))
87
- return;
88
- const V = ((f = h(C)) != null ? f : h(o)).getBoundingClientRect(), F = {
89
- x: t.clientX - V.left,
90
- y: t.clientY - V.top
91
- };
92
- (a == null ? void 0 : a(F, t)) !== !1 && (_.value = F, M(t));
93
- }, O = (t) => {
94
- if (!E(t) || !_.value)
95
- return;
96
- let { x: f, y: k } = y.value;
97
- (d === "x" || d === "both") && (f = t.clientX - _.value.x), (d === "y" || d === "both") && (k = t.clientY - _.value.y), y.value = {
98
- x: f,
99
- y: k
100
- }, m == null || m(y.value, t), M(t);
101
- }, H = (t) => {
102
- E(t) && _.value && (_.value = void 0, l == null || l(y.value, t), M(t));
103
- };
104
- if (q) {
105
- const t = { capture: (n = i.capture) != null ? n : !0 };
106
- W(L, "pointerdown", D, t), W(c, "pointermove", O, t), W(c, "pointerup", H, t);
107
- }
108
- return {
109
- ...Ce(y),
110
- position: y,
111
- isDragging: x(() => !!_.value),
112
- style: x(
113
- () => `left:${y.value.x}px;top:${y.value.y}px;`
114
- )
115
- };
116
- }
117
- const Se = { class: "modal-container fixed inset-0" }, ke = { class: "title font-bold" }, ze = { class: "action" }, Ae = {
118
- key: 1,
119
- class: "modal-footer space-x-2"
120
- }, Pe = ["form"], $e = {
121
- name: "ModalContainer",
122
- inheritAttrs: !0
123
- }, Be = /* @__PURE__ */ X({
124
- ...$e,
125
- props: {
126
- id: {},
127
- form: {},
128
- component: {},
129
- componentProps: {},
130
- width: {},
131
- maxWidth: {},
132
- maxHeight: {},
133
- sizes: {},
134
- size: { default: "middle" },
135
- title: {},
136
- header: { type: Boolean, default: !0 },
137
- footer: { type: Boolean, default: !1 },
138
- closeable: { type: Boolean, default: !0 },
139
- esc: { type: Boolean, default: !1 },
140
- maskClosable: { type: Boolean, default: !1 },
141
- draggable: { type: Boolean, default: !1 },
142
- mode: { default: "dialog" }
143
- },
144
- emits: ["submit"],
145
- setup(o, { emit: i }) {
146
- const e = o, n = i, r = R(B);
147
- let u = 0, v = 0;
148
- const p = A(), m = A(), l = A(), { x: a, y: s } = Me(l, {
149
- initialValue: { x: 0, y: 0 }
150
- });
151
- function d() {
152
- r == null || r.close(e.id);
153
- }
154
- function c(t) {
155
- if (typeof t == "number")
156
- return `${t}px`;
157
- if (typeof t == "string")
158
- return t;
159
- }
160
- const C = x(() => {
161
- const t = {};
162
- return e.mode === "dialog" && (t.justifyContent = "center"), e.mode === "drawer" && (t.justifyContent = "flex-end"), t;
163
- }), L = x(() => {
164
- const t = {};
165
- return e.size && (t.width = c(e.sizes[e.size])), e.width && (t.width = c(e.width)), e.maxWidth && (t.maxWidth = c(e.maxWidth)), e.size === "fullscreen" && (t.maxWidth = "unset", t.position = "fixed", t.top = 0, t.left = 0, t.bottom = 0, t.right = 0), e.draggable && e.size !== "fullscreen" && e.mode === "dialog" && (t.transform = `translate3d(${a.value - u}px, ${s.value - v}px, 0px)`), t;
166
- }), y = x(() => {
167
- const t = {};
168
- return e.draggable && e.size !== "fullscreen" && e.mode === "dialog" && (t.cursor = "move"), t;
169
- }), _ = x(() => {
170
- var f;
171
- const t = {};
172
- return e.maxHeight && (t.maxHeight = `calc(${(f = c(e.maxHeight)) == null ? void 0 : f.replace("%", "vh")} - 50px)`), e.mode === "drawer" && (t.maxHeight = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), e.size === "fullscreen" && (t.maxHeight = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), t;
173
- });
174
- function E() {
175
- const t = m.value;
176
- if (e.form && t) {
177
- const f = t.querySelector(`form[name="${e.form}"]`);
178
- f && f.dispatchEvent(new Event("submit"));
179
- }
180
- n("submit");
181
- }
182
- function M() {
183
- r == null || r.close(e.id);
184
- }
185
- function D() {
186
- window && window.addEventListener("resize", () => {
187
- S(p), S(m), u = m.value.offsetLeft, v = m.value.offsetTop;
188
- });
189
- }
190
- function O() {
191
- if (e.closeable && e.esc) {
192
- const t = ({ key: f }) => {
193
- f === "Escape" && (r == null || r.close(e.id), window.removeEventListener("keydown", t));
194
- };
195
- window.addEventListener("keydown", t);
196
- }
197
- }
198
- function H() {
199
- u = m.value.offsetLeft, v = m.value.offsetTop;
200
- }
201
- return Y(() => {
202
- O(), D();
203
- }), ne(() => {
204
- }), (t, f) => (g(), b("div", Se, [
205
- w("div", {
206
- ref_key: "wrapperRef",
207
- ref: p,
208
- class: "modal-wrapper",
209
- style: z(C.value),
210
- onClick: f[0] || (f[0] = re((k) => t.maskClosable && d(), ["self"]))
211
- }, [
212
- w("div", {
213
- ref_key: "contentRef",
214
- ref: m,
215
- class: ie(["modal-content", { [`${t.mode}-mode`]: !0 }]),
216
- style: z(L.value)
217
- }, [
218
- t.header ? (g(), b("div", {
219
- key: 0,
220
- ref_key: "headerRef",
221
- ref: l,
222
- class: "modal-header",
223
- style: z(y.value),
224
- onMousedown: H
225
- }, [
226
- w("div", ke, se(t.title), 1),
227
- w("div", ze, [
228
- t.closeable ? (g(), b("div", {
229
- key: 0,
230
- class: "i-icon-park-outline:close block cursor-pointer",
231
- onClick: d
232
- })) : P("", !0)
233
- ])
234
- ], 36)) : P("", !0),
235
- w("div", {
236
- class: "modal-body",
237
- style: z(_.value)
238
- }, [
239
- (g(), N(le(t.component), ae(ue(t.componentProps)), null, 16))
240
- ], 4),
241
- t.footer ? (g(), b("div", Ae, [
242
- w("button", {
243
- class: "submit-button",
244
- form: t.form,
245
- type: "submit",
246
- onClick: E
247
- }, " 确定 ", 8, Pe),
248
- w("button", {
249
- class: "cancel-button",
250
- type: "button",
251
- onClick: M
252
- }, " 取消 ")
253
- ])) : P("", !0)
254
- ], 6)
255
- ], 4)
256
- ]));
257
- }
258
- });
259
- const U = (o, i) => {
260
- const e = o.__vccOpts || o;
261
- for (const [n, r] of i)
262
- e[n] = r;
263
- return e;
264
- }, Le = /* @__PURE__ */ U(Be, [["__scopeId", "data-v-581eba51"]]), De = {
265
- key: 0,
266
- class: "modal-teleport"
267
- }, Oe = {
268
- name: "ModalProvider",
269
- inheritAttrs: !0
270
- }, He = /* @__PURE__ */ X({
271
- ...Oe,
272
- props: {
273
- appendToBody: { type: Boolean, default: !1 },
274
- sizes: { default: () => ({
275
- small: 520,
276
- middle: 860,
277
- large: 1190
278
- }) },
279
- maxWidth: { default: "80%" },
280
- maxHeight: { default: "80%" }
281
- },
282
- setup(o, { expose: i }) {
283
- const e = A([]), n = $(!1);
284
- async function r(l, a, s) {
285
- const d = ge(
286
- () => Promise.resolve(l)
287
- );
288
- return new Promise((c) => {
289
- e.value.push({
290
- id: Math.random().toString(32).slice(2),
291
- component: d,
292
- props: a,
293
- options: s,
294
- resolve: c,
295
- onSubmit: $(() => {
296
- })
297
- }), S(e);
298
- });
299
- }
300
- function u(l, a) {
301
- const s = e.value.findIndex((c) => c.id === l);
302
- if (s < 0)
303
- return;
304
- const d = e.value[s];
305
- d == null || d.resolve(a), e.value.splice(s, 1), S(e);
306
- }
307
- function v() {
308
- e.value.forEach((l) => {
309
- l.resolve();
310
- }), e.value = [], S(e);
311
- }
312
- function p(l) {
313
- return e.value.find((a) => a.id === l);
314
- }
315
- function m(l, a) {
316
- const s = e.value.find((d) => d.id === l);
317
- s && (s.onSubmit.value = a);
318
- }
319
- return de(B, {
320
- open: r,
321
- close: u,
322
- closeAll: v,
323
- getElement: p,
324
- addSubmitListener: m
325
- }), i({
326
- elements: e
327
- }), Y(() => {
328
- n.value = !0;
329
- }), (l, a) => (g(), b(I, null, [
330
- ce(l.$slots, "default", {}, void 0, !0),
331
- n.value ? (g(), b("div", De, [
332
- (g(), N(fe, {
333
- disabled: !l.appendToBody,
334
- to: "body"
335
- }, [
336
- pe(me, { name: "modal-fade" }, {
337
- default: ve(() => [
338
- (g(!0), b(I, null, ye(e.value, (s) => (g(), N(Le, he({
339
- id: s.id,
340
- key: s.id,
341
- component: s.component,
342
- "component-props": s.props,
343
- "max-height": l.maxHeight,
344
- "max-width": l.maxWidth,
345
- sizes: l.sizes
346
- }, s.options, {
347
- onSubmit: s.onSubmit.value
348
- }), null, 16, ["id", "component", "component-props", "max-height", "max-width", "sizes", "onSubmit"]))), 128))
349
- ]),
350
- _: 1
351
- })
352
- ], 8, ["disabled"]))
353
- ])) : P("", !0)
354
- ], 64));
355
- }
356
- });
357
- const Ne = /* @__PURE__ */ U(He, [["__scopeId", "data-v-1ef03c20"]]);
358
- function T(o, i) {
359
- var n, r;
360
- let e = o == null ? void 0 : o.parent;
361
- for (; e && ((n = e == null ? void 0 : e.type) == null ? void 0 : n.name) !== i; )
362
- e = e.parent;
363
- return ((r = e == null ? void 0 : e.type) == null ? void 0 : r.name) === i ? e : null;
364
- }
365
- function Te() {
366
- const o = R(B), i = K();
367
- return {
368
- open(e, n, r) {
369
- if (!o)
370
- throw new Error("Not Found Modal Provider Component");
371
- return o.open(e, n || {}, r || {});
372
- },
373
- close(e) {
374
- var u;
375
- if (!o)
376
- throw new Error("Not Found Modal Provider Component");
377
- const n = T(i, "ModalContainer"), r = (u = n == null ? void 0 : n.props) == null ? void 0 : u.id;
378
- if (!r)
379
- throw new Error("Not Found Current Modal Container");
380
- o.close(r, e);
381
- },
382
- closeAll() {
383
- if (!o)
384
- throw new Error("Not Found Modal Provider Component");
385
- o.closeAll();
386
- },
387
- onSubmit(e) {
388
- const n = T(i, "ModalContainer");
389
- if (!(n == null ? void 0 : n.props.id))
390
- throw new Error("Not Found Current Modal Container");
391
- }
392
- };
393
- }
394
- function Re(o) {
395
- var u;
396
- const i = R(B), e = K(), n = T(e, "ModalContainer"), r = (u = n == null ? void 0 : n.props) == null ? void 0 : u.id;
397
- i && r && i.addSubmitListener(r, o);
398
- }
399
- export {
400
- Le as ModalContainer,
401
- Ne as ModalProvider,
402
- Re as onSubmit,
403
- Te as useModal
404
- };
File without changes