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