@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.
@@ -0,0 +1,401 @@
1
+ import { unref as J, isRef as Q, toRefs as Z, customRef as j, getCurrentScope as ee, onScopeDispose as te, ref as B, computed as x, watch as oe, defineComponent as I, inject as N, shallowRef as P, onMounted as X, onUnmounted as ne, openBlock as g, createElementBlock as w, normalizeStyle as A, withModifiers as re, createElementVNode as b, normalizeClass as ie, toDisplayString as le, createCommentVNode as $, createBlock as W, resolveDynamicComponent as se, normalizeProps as ae, guardReactiveProps as ue, triggerRef as M, provide as ce, Fragment as F, renderSlot as de, Teleport as fe, createVNode as pe, TransitionGroup as me, withCtx as ve, renderList as ye, mergeProps as he, defineAsyncComponent as ge, getCurrentInstance as Y } from "vue";
2
+ const z = 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 K = 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 r in o.value)
16
+ e[r] = j(() => ({
17
+ get() {
18
+ return o.value[r];
19
+ },
20
+ set(n) {
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[r] = n, o.value = p;
26
+ } else {
27
+ const p = { ...o.value, [r]: n };
28
+ Object.setPrototypeOf(p, Object.getPrototypeOf(o.value)), o.value = p;
29
+ }
30
+ else
31
+ o.value[r] = n;
32
+ }
33
+ }));
34
+ return e;
35
+ }
36
+ function Se(o) {
37
+ var i;
38
+ const e = h(o);
39
+ return (i = e == null ? void 0 : e.$el) != null ? i : e;
40
+ }
41
+ const q = K ? window : void 0;
42
+ function H(...o) {
43
+ let i, e, r, n;
44
+ if (typeof o[0] == "string" || Array.isArray(o[0]) ? ([e, r, n] = o, i = q) : [i, e, r, n] = o, !i)
45
+ return xe;
46
+ Array.isArray(e) || (e = [e]), Array.isArray(r) || (r = [r]);
47
+ const u = [], v = () => {
48
+ u.forEach((a) => a()), u.length = 0;
49
+ }, p = (a, s, c, f) => (a.addEventListener(s, c, f), () => a.removeEventListener(s, c, f)), m = oe(
50
+ () => [Se(i), h(n)],
51
+ ([a, s]) => {
52
+ if (v(), !a)
53
+ return;
54
+ const c = be(s) ? { ...s } : s;
55
+ u.push(
56
+ ...e.flatMap((f) => r.map((C) => p(a, f, C, c)))
57
+ );
58
+ },
59
+ { immediate: !0, flush: "post" }
60
+ ), l = () => {
61
+ m(), v();
62
+ };
63
+ return _e(l), l;
64
+ }
65
+ function Ee(o, i = {}) {
66
+ var e, r;
67
+ const {
68
+ pointerTypes: n,
69
+ preventDefault: u,
70
+ stopPropagation: v,
71
+ exact: p,
72
+ onMove: m,
73
+ onEnd: l,
74
+ onStart: a,
75
+ initialValue: s,
76
+ axis: c = "both",
77
+ draggingElement: f = q,
78
+ containerElement: C,
79
+ handle: L = o
80
+ } = i, y = B(
81
+ (e = h(s)) != null ? e : { x: 0, y: 0 }
82
+ ), _ = B(), S = (t) => n ? n.includes(t.pointerType) : !0, E = (t) => {
83
+ h(u) && t.preventDefault(), h(v) && t.stopPropagation();
84
+ }, D = (t) => {
85
+ var d;
86
+ if (!S(t) || h(p) && t.target !== h(o))
87
+ return;
88
+ const R = ((d = h(C)) != null ? d : h(o)).getBoundingClientRect(), V = {
89
+ x: t.clientX - R.left,
90
+ y: t.clientY - R.top
91
+ };
92
+ (a == null ? void 0 : a(V, t)) !== !1 && (_.value = V, E(t));
93
+ }, O = (t) => {
94
+ if (!S(t) || !_.value)
95
+ return;
96
+ let { x: d, y: k } = y.value;
97
+ (c === "x" || c === "both") && (d = t.clientX - _.value.x), (c === "y" || c === "both") && (k = t.clientY - _.value.y), y.value = {
98
+ x: d,
99
+ y: k
100
+ }, m == null || m(y.value, t), E(t);
101
+ }, T = (t) => {
102
+ S(t) && _.value && (_.value = void 0, l == null || l(y.value, t), E(t));
103
+ };
104
+ if (K) {
105
+ const t = { capture: (r = i.capture) != null ? r : !0 };
106
+ H(L, "pointerdown", D, t), H(f, "pointermove", O, t), H(f, "pointerup", T, 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 Me = { class: "title font-bold" }, ke = { 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__ */ I({
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
+ fullscreen: { type: Boolean },
136
+ title: {},
137
+ header: { type: Boolean, default: !0 },
138
+ footer: { type: Boolean, default: !1 },
139
+ closeable: { type: Boolean, default: !0 },
140
+ esc: { type: Boolean, default: !1 },
141
+ maskClosable: { type: Boolean, default: !1 },
142
+ draggable: { type: Boolean, default: !1 },
143
+ mode: { default: "dialog" }
144
+ },
145
+ emits: ["submit"],
146
+ setup(o, { emit: i }) {
147
+ const e = o, r = i, n = N(z);
148
+ let u = 0, v = 0;
149
+ const p = P(), m = P(), l = P(), { x: a, y: s } = Ee(l, {
150
+ initialValue: { x: 0, y: 0 }
151
+ });
152
+ function c() {
153
+ n == null || n.close(e.id);
154
+ }
155
+ function f(t) {
156
+ if (typeof t == "number")
157
+ return `${t}px`;
158
+ if (typeof t == "string")
159
+ return t;
160
+ }
161
+ const C = x(() => {
162
+ const t = {};
163
+ return e.mode === "dialog" && (t.justifyContent = "center"), e.mode === "drawer" && (t.justifyContent = "flex-end"), t;
164
+ }), L = x(() => {
165
+ const t = {};
166
+ return e.size && (t.width = f(e.sizes[e.size])), e.width && (t.width = f(e.width)), e.maxWidth && (t.maxWidth = f(e.maxWidth)), e.fullscreen && (t.maxWidth = "unset", t.width = "100%", t.position = "fixed", t.top = 0, t.left = 0, t.bottom = 0, t.right = 0), e.draggable && !e.fullscreen && e.mode === "dialog" && (t.transform = `translate3d(${a.value - u}px, ${s.value - v}px, 0px)`), t;
167
+ }), y = x(() => {
168
+ const t = {};
169
+ return e.draggable && !e.fullscreen && e.mode === "dialog" && (t.cursor = "move"), t;
170
+ }), _ = x(() => {
171
+ var d;
172
+ const t = {};
173
+ return e.maxHeight && (t.maxHeight = `calc(${(d = f(e.maxHeight)) == null ? void 0 : d.replace("%", "vh")} - 50px)`), e.mode === "drawer" && (t.maxHeight = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), e.fullscreen && (t.maxHeight = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), t;
174
+ });
175
+ function S() {
176
+ const t = m.value;
177
+ if (e.form && t) {
178
+ const d = t.querySelector(`form[name="${e.form}"]`);
179
+ d && d.dispatchEvent(new Event("submit"));
180
+ }
181
+ r("submit", {
182
+ open: n == null ? void 0 : n.open,
183
+ close: (d) => n == null ? void 0 : n.close(e.id, d)
184
+ });
185
+ }
186
+ function E() {
187
+ n == null || n.close(e.id);
188
+ }
189
+ function D() {
190
+ window && window.addEventListener("resize", () => {
191
+ M(p), M(m), u = m.value.offsetLeft, v = m.value.offsetTop;
192
+ });
193
+ }
194
+ function O() {
195
+ if (e.closeable && e.esc) {
196
+ const t = ({ key: d }) => {
197
+ d === "Escape" && (n == null || n.close(e.id), window.removeEventListener("keydown", t));
198
+ };
199
+ window.addEventListener("keydown", t);
200
+ }
201
+ }
202
+ function T() {
203
+ u = m.value.offsetLeft, v = m.value.offsetTop;
204
+ }
205
+ return X(() => {
206
+ O(), D();
207
+ }), ne(() => {
208
+ }), (t, d) => (g(), w("div", {
209
+ ref_key: "wrapperRef",
210
+ ref: p,
211
+ class: "modal-wrapper",
212
+ style: A(C.value),
213
+ onClick: d[0] || (d[0] = re((k) => t.maskClosable && c(), ["self"]))
214
+ }, [
215
+ b("div", {
216
+ ref_key: "contentRef",
217
+ ref: m,
218
+ class: ie(["modal-content", { [`${t.mode}-mode`]: !0 }]),
219
+ style: A(L.value)
220
+ }, [
221
+ t.header ? (g(), w("div", {
222
+ key: 0,
223
+ ref_key: "headerRef",
224
+ ref: l,
225
+ class: "modal-header",
226
+ style: A(y.value),
227
+ onMousedown: T
228
+ }, [
229
+ b("div", Me, le(t.title), 1),
230
+ b("div", ke, [
231
+ t.closeable ? (g(), w("div", {
232
+ key: 0,
233
+ class: "i-icon-park-outline:close block cursor-pointer",
234
+ onClick: c
235
+ })) : $("", !0)
236
+ ])
237
+ ], 36)) : $("", !0),
238
+ b("div", {
239
+ class: "modal-body",
240
+ style: A(_.value)
241
+ }, [
242
+ (g(), W(se(t.component), ae(ue(t.componentProps)), null, 16))
243
+ ], 4),
244
+ t.footer ? (g(), w("div", Ae, [
245
+ b("button", {
246
+ class: "submit-button",
247
+ form: t.form,
248
+ type: "submit",
249
+ onClick: S
250
+ }, " 确定 ", 8, Pe),
251
+ b("button", {
252
+ class: "cancel-button",
253
+ type: "button",
254
+ onClick: E
255
+ }, " 取消 ")
256
+ ])) : $("", !0)
257
+ ], 6)
258
+ ], 4));
259
+ }
260
+ });
261
+ const G = (o, i) => {
262
+ const e = o.__vccOpts || o;
263
+ for (const [r, n] of i)
264
+ e[r] = n;
265
+ return e;
266
+ }, ze = /* @__PURE__ */ G(Be, [["__scopeId", "data-v-33b22316"]]), Le = {
267
+ key: 0,
268
+ class: "modal-teleport"
269
+ }, De = {
270
+ name: "ModalProvider",
271
+ inheritAttrs: !0
272
+ }, Oe = /* @__PURE__ */ I({
273
+ ...De,
274
+ props: {
275
+ appendToBody: { type: [Boolean, String], default: !1 },
276
+ sizes: { default: () => ({
277
+ small: 520,
278
+ middle: 860,
279
+ large: 1190
280
+ }) },
281
+ maxWidth: { default: "80%" },
282
+ maxHeight: { default: "80%" }
283
+ },
284
+ setup(o, { expose: i }) {
285
+ const e = P([]), r = B(!1);
286
+ async function n(l, a, s) {
287
+ const c = ge(
288
+ () => Promise.resolve(l)
289
+ );
290
+ return new Promise((f) => {
291
+ e.value.push({
292
+ id: Math.random().toString(32).slice(2),
293
+ component: c,
294
+ props: a,
295
+ options: s,
296
+ resolve: f,
297
+ onSubmit: B(null)
298
+ }), M(e);
299
+ });
300
+ }
301
+ function u(l, a) {
302
+ const s = e.value.findIndex((f) => f.id === l);
303
+ if (s < 0)
304
+ return;
305
+ const c = e.value[s];
306
+ c == null || c.resolve(a), e.value.splice(s, 1), M(e);
307
+ }
308
+ function v() {
309
+ e.value.forEach((l) => {
310
+ l.resolve();
311
+ }), e.value = [], M(e);
312
+ }
313
+ function p(l) {
314
+ return e.value.find((a) => a.id === l);
315
+ }
316
+ function m(l, a) {
317
+ const s = e.value.find((c) => c.id === l);
318
+ console.log(a, 111), s && (s.onSubmit.value = a);
319
+ }
320
+ return ce(z, {
321
+ open: n,
322
+ close: u,
323
+ closeAll: v,
324
+ getElement: p,
325
+ addSubmitListener: m
326
+ }), i({
327
+ elements: e
328
+ }), X(() => {
329
+ r.value = !0;
330
+ }), (l, a) => (g(), w(F, null, [
331
+ de(l.$slots, "default", {}, void 0, !0),
332
+ r.value ? (g(), w("div", Le, [
333
+ (g(), W(fe, {
334
+ disabled: !l.appendToBody,
335
+ to: typeof l.appendToBody == "string" ? l.appendToBody : "body"
336
+ }, [
337
+ pe(me, { name: "modal-fade" }, {
338
+ default: ve(() => [
339
+ (g(!0), w(F, null, ye(e.value, (s) => (g(), W(ze, he({
340
+ id: s.id,
341
+ key: s.id,
342
+ component: s.component,
343
+ "component-props": s.props,
344
+ "max-height": l.maxHeight,
345
+ "max-width": l.maxWidth,
346
+ sizes: l.sizes
347
+ }, s.options, {
348
+ onSubmit: s.onSubmit.value
349
+ }), null, 16, ["id", "component", "component-props", "max-height", "max-width", "sizes", "onSubmit"]))), 128))
350
+ ]),
351
+ _: 1
352
+ })
353
+ ], 8, ["disabled", "to"]))
354
+ ])) : $("", !0)
355
+ ], 64));
356
+ }
357
+ });
358
+ const He = /* @__PURE__ */ G(Oe, [["__scopeId", "data-v-cec9e05a"]]);
359
+ function U(o, i) {
360
+ var r, n;
361
+ let e = o == null ? void 0 : o.parent;
362
+ for (; e && ((r = e == null ? void 0 : e.type) == null ? void 0 : r.name) !== i; )
363
+ e = e.parent;
364
+ return ((n = e == null ? void 0 : e.type) == null ? void 0 : n.name) === i ? e : null;
365
+ }
366
+ function We() {
367
+ const o = N(z), i = Y();
368
+ return {
369
+ open(e, r, n) {
370
+ if (!o)
371
+ throw new Error("Not Found Modal Provider Component");
372
+ return o.open(e, r || {}, n || {});
373
+ },
374
+ close(e) {
375
+ var u;
376
+ if (!o)
377
+ throw new Error("Not Found Modal Provider Component");
378
+ const r = U(i, "ModalContainer"), n = (u = r == null ? void 0 : r.props) == null ? void 0 : u.id;
379
+ if (!n)
380
+ throw new Error("Not Found Current Modal Container");
381
+ o.close(n, e);
382
+ },
383
+ closeAll() {
384
+ if (!o)
385
+ throw new Error("Not Found Modal Provider Component");
386
+ o.closeAll();
387
+ }
388
+ };
389
+ }
390
+ function Ne(o) {
391
+ var u;
392
+ const i = N(z), e = Y(), r = U(e, "ModalContainer"), n = (u = r == null ? void 0 : r.props) == null ? void 0 : u.id;
393
+ i && n && i.addSubmitListener(n, o);
394
+ }
395
+ export {
396
+ ze as ModalContainer,
397
+ z as ModalKey,
398
+ He as ModalProvider,
399
+ Ne as onSubmit,
400
+ We as useModal
401
+ };
@@ -0,0 +1,37 @@
1
+ import type { Component, Ref } from 'vue';
2
+ import type { useModal } from './hooks/use-modal';
3
+ export interface SizeOptions {
4
+ small: number;
5
+ middle: number;
6
+ large: number;
7
+ }
8
+ export interface OpenModalOptions {
9
+ closeable?: boolean;
10
+ esc?: boolean;
11
+ mask?: boolean;
12
+ maskClosable?: boolean;
13
+ title?: string;
14
+ header?: boolean;
15
+ footer?: boolean;
16
+ width?: number | string;
17
+ size?: 'large' | 'middle' | 'small';
18
+ fullscreen?: boolean;
19
+ draggable?: boolean;
20
+ form?: string;
21
+ mode?: 'dialog' | 'drawer';
22
+ }
23
+ export interface ModalElement extends OpenModalOptions {
24
+ id: string;
25
+ resolve: (data?: any) => void;
26
+ component: Component;
27
+ props: Record<string, any>;
28
+ options: OpenModalOptions;
29
+ onSubmit: Ref<((actions: ReturnType<typeof useModal>) => void) | null>;
30
+ }
31
+ export interface ModalActions {
32
+ open: (component: Component, props: Record<string, any>, options: OpenModalOptions) => Promise<any | void>;
33
+ close: (id: string, data?: any) => void;
34
+ closeAll: () => void;
35
+ getElement: (id: string) => ModalElement | undefined;
36
+ addSubmitListener: (id: string, fun: (modal: ReturnType<typeof useModal>) => void) => void;
37
+ }
@@ -0,0 +1,2 @@
1
+ import type { ComponentInternalInstance } from 'vue';
2
+ export declare function findContainer(ctx: ComponentInternalInstance | null, name: 'ModalContainer' | 'ModalProvider'): ComponentInternalInstance | null;
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- *,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }::backdrop{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }.i-icon-park-outline\:close{--un-icon:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 48 48' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='4' d='m8 8l32 32M8 40L40 8'/%3E%3C/svg%3E");-webkit-mask:var(--un-icon) no-repeat;mask:var(--un-icon) no-repeat;-webkit-mask-size:100% 100%;mask-size:100% 100%;background-color:currentColor;color:inherit;width:1em;height:1em}.fixed{position:fixed}.block{display:block}.flex{display:flex}.cursor-pointer{cursor:pointer}.resize{resize:both}.space-x-2>:not([hidden])~:not([hidden]){--un-space-x-reverse:0;margin-left:calc(.5rem * calc(1 - var(--un-space-x-reverse)));margin-right:calc(.5rem * var(--un-space-x-reverse))}.px{padding-left:1rem;padding-right:1rem}.font-bold{font-weight:700}.outline{outline-style:solid}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.ease{transition-timing-function:cubic-bezier(.4,0,.2,1)}.modal-wrapper[data-v-05b670ad]{z-index:1000;position:fixed;top:0;right:0;bottom:0;left:0;display:flex;justify-content:center;align-items:center;background:rgba(0,0,0,.3)}.modal-content[data-v-05b670ad]{background:#ffffff;border-radius:5px}.modal-header[data-v-05b670ad]{box-sizing:border-box;padding:10px;height:50px;display:flex;justify-content:space-between;align-items:center;border-bottom:solid 1px var(--color-border-1, #e8e8e8)}.modal-body[data-v-05b670ad]{padding:20px 10px;box-sizing:border-box;max-height:10vw;overflow:auto}.modal-footer[data-v-05b670ad]{box-sizing:border-box;height:50px;border-top:solid 1px var(--color-border-1, #e8e8e8);display:flex;justify-content:end;padding:10px}.modal-footer button[data-v-05b670ad]{height:28px;line-height:28px;width:80px;outline:none;border-color:transparent;font-size:14px;border-radius:4px;padding:0;box-sizing:content-box}.modal-footer button.submit-button[data-v-05b670ad]{color:#fff;background-color:rgb(var(--primary-6, 45, 106, 251))}.modal-footer button.submit-button[data-v-05b670ad]:hover{background-color:rgb(var(--primary-5, 28, 76, 207))}.modal-footer button.cancel-button[data-v-05b670ad]{color:rgb(var(--color-text-2, 78, 89, 105));background-color:var(--color-fill-1, #f5f5f5)}.modal-footer button.cancel-button[data-v-05b670ad]:hover{background-color:var(--color-fill-4, #c9cdd4)}.modal-fade-enter-active[data-v-171d9bdd],.modal-fade-leave-active[data-v-171d9bdd]{transition:all .5s ease}.modal-fade-enter-from[data-v-171d9bdd],.modal-fade-leave-to[data-v-171d9bdd]{opacity:0}
1
+ *,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }::backdrop{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }.i-icon-park-outline\:close{--un-icon:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 48 48' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='4' d='m8 8l32 32M8 40L40 8'/%3E%3C/svg%3E");-webkit-mask:var(--un-icon) no-repeat;mask:var(--un-icon) no-repeat;-webkit-mask-size:100% 100%;mask-size:100% 100%;background-color:currentColor;color:inherit;width:1em;height:1em}.fixed{position:fixed}.block{display:block}.flex{display:flex}.transform{transform:translate(var(--un-translate-x)) translateY(var(--un-translate-y)) translateZ(var(--un-translate-z)) rotate(var(--un-rotate)) rotateX(var(--un-rotate-x)) rotateY(var(--un-rotate-y)) rotate(var(--un-rotate-z)) skew(var(--un-skew-x)) skewY(var(--un-skew-y)) scaleX(var(--un-scale-x)) scaleY(var(--un-scale-y)) scaleZ(var(--un-scale-z))}.cursor-pointer{cursor:pointer}.resize{resize:both}.space-x-2>:not([hidden])~:not([hidden]){--un-space-x-reverse:0;margin-left:calc(.5rem * calc(1 - var(--un-space-x-reverse)));margin-right:calc(.5rem * var(--un-space-x-reverse))}.px{padding-left:1rem;padding-right:1rem}.font-bold{font-weight:700}.outline{outline-style:solid}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.ease{transition-timing-function:cubic-bezier(.4,0,.2,1)}.modal-wrapper[data-v-33b22316]{z-index:1000;position:fixed;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;background:rgba(0,0,0,.3)}.modal-content[data-v-33b22316]{background:#ffffff;border-radius:5px}.modal-header[data-v-33b22316]{box-sizing:border-box;padding:10px;height:50px;display:flex;justify-content:space-between;align-items:center;border-bottom:solid 1px var(--color-border-1, #e8e8e8)}.modal-body[data-v-33b22316]{padding:20px 10px;box-sizing:border-box;max-height:10vw;overflow:auto}.modal-footer[data-v-33b22316]{box-sizing:border-box;height:50px;border-top:solid 1px var(--color-border-1, #e8e8e8);display:flex;justify-content:end;padding:10px}.modal-footer button[data-v-33b22316]{height:28px;line-height:28px;width:80px;outline:none;border-color:transparent;font-size:14px;border-radius:4px;padding:0;box-sizing:content-box}.modal-footer button.submit-button[data-v-33b22316]{color:#fff;background-color:rgb(var(--primary-6, 45, 106, 251))}.modal-footer button.submit-button[data-v-33b22316]:hover{background-color:rgb(var(--primary-5, 28, 76, 207))}.modal-footer button.cancel-button[data-v-33b22316]{color:rgb(var(--color-text-2, 78, 89, 105));background-color:var(--color-fill-1, #f5f5f5)}.modal-footer button.cancel-button[data-v-33b22316]:hover{background-color:var(--color-fill-4, #c9cdd4)}.modal-fade-enter-active[data-v-cec9e05a],.modal-fade-leave-active[data-v-cec9e05a]{transition:opacity .5s ease}.modal-fade-enter-active[data-v-cec9e05a] .modal-content.drawer-mode,.modal-fade-leave-active[data-v-cec9e05a] .modal-content.drawer-mode{transition:transform .5s ease}.modal-fade-enter-from[data-v-cec9e05a],.modal-fade-leave-to[data-v-cec9e05a]{opacity:0}.modal-fade-enter-from[data-v-cec9e05a] .modal-content.drawer-mode,.modal-fade-leave-to[data-v-cec9e05a] .modal-content.drawer-mode{transform:translate3d(100%,0,0)}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gopowerteam/modal-render",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "author": {
6
6
  "name": "zhuchentong",
7
7
  "email": "2037630@gmail.com"
@@ -15,19 +15,29 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/gopowerteam/x-render/issues"
17
17
  },
18
+ "main": "./dist/cjs/index.cjs",
19
+ "module": "./dist/es/index.mjs",
20
+ "types": "./dist/es/index.d.ts",
18
21
  "exports": {
19
22
  ".": {
20
- "require": "./dist/index.cjs",
21
- "import": {
22
- "types": "./dist/index.d.ts",
23
- "default": "./dist/index.js"
24
- }
23
+ "types": "./dist/es/index.d.ts",
24
+ "import": "./dist/es/index.mjs",
25
+ "require": "./dist/cjs/index.cjs"
25
26
  },
26
- "./dist/": "./dist/"
27
+ "./es": {
28
+ "types": "./dist/es/index.d.ts",
29
+ "import": "./dist/es/index.mjs"
30
+ },
31
+ "./cjs": {
32
+ "types": "./dist/cjs/index.d.ts",
33
+ "require": "./dist/cjs/index.cjs"
34
+ },
35
+ "./dist/style.css": {
36
+ "require": "./dist/style.css",
37
+ "import": "./dist/style.css"
38
+ },
39
+ "./*": "./*"
27
40
  },
28
- "main": "./dist/index.cjs",
29
- "module": "./dist/index.js",
30
- "types": "./dist/index.d.ts",
31
41
  "files": [
32
42
  "dist",
33
43
  "README.md"
@@ -1 +0,0 @@
1
- export declare function onSubmit(callback: () => void): void;
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");const C=Symbol("__MODAL__");function O(o){return e.getCurrentScope()?(e.onScopeDispose(o),!0):!1}function g(o){return typeof o=="function"?o():e.unref(o)}const V=typeof window<"u"&&typeof document<"u",D=Object.prototype.toString,W=o=>D.call(o)==="[object Object]",T=()=>{};function F(o,s={}){if(!e.isRef(o))return e.toRefs(o);const t=Array.isArray(o.value)?Array.from({length:o.value.length}):{};for(const r in o.value)t[r]=e.customRef(()=>({get(){return o.value[r]},set(l){var d;if((d=g(s.replaceRef))!=null?d:!0)if(Array.isArray(o.value)){const m=[...o.value];m[r]=l,o.value=m}else{const m={...o.value,[r]:l};Object.setPrototypeOf(m,Object.getPrototypeOf(o.value)),o.value=m}else o.value[r]=l}}));return t}function H(o){var s;const t=g(o);return(s=t==null?void 0:t.$el)!=null?s:t}const R=V?window:void 0;function z(...o){let s,t,r,l;if(typeof o[0]=="string"||Array.isArray(o[0])?([t,r,l]=o,s=R):[s,t,r,l]=o,!s)return T;Array.isArray(t)||(t=[t]),Array.isArray(r)||(r=[r]);const d=[],y=()=>{d.forEach(u=>u()),d.length=0},m=(u,a,f,p)=>(u.addEventListener(a,f,p),()=>u.removeEventListener(a,f,p)),v=e.watch(()=>[H(s),g(l)],([u,a])=>{if(y(),!u)return;const f=W(a)?{...a}:a;d.push(...t.flatMap(p=>r.map(b=>m(u,p,b,f))))},{immediate:!0,flush:"post"}),c=()=>{v(),y()};return O(c),c}function I(o,s={}){var t,r;const{pointerTypes:l,preventDefault:d,stopPropagation:y,exact:m,onMove:v,onEnd:c,onStart:u,initialValue:a,axis:f="both",draggingElement:p=R,containerElement:b,handle:x=o}=s,h=e.ref((t=g(a))!=null?t:{x:0,y:0}),_=e.ref(),k=i=>l?l.includes(i.pointerType):!0,E=i=>{g(d)&&i.preventDefault(),g(y)&&i.stopPropagation()},M=i=>{var w;if(!k(i)||g(m)&&i.target!==g(o))return;const P=((w=g(b))!=null?w:g(o)).getBoundingClientRect(),N={x:i.clientX-P.left,y:i.clientY-P.top};(u==null?void 0:u(N,i))!==!1&&(_.value=N,E(i))},S=i=>{if(!k(i)||!_.value)return;let{x:w,y:B}=h.value;(f==="x"||f==="both")&&(w=i.clientX-_.value.x),(f==="y"||f==="both")&&(B=i.clientY-_.value.y),h.value={x:w,y:B},v==null||v(h.value,i),E(i)},n=i=>{k(i)&&_.value&&(_.value=void 0,c==null||c(h.value,i),E(i))};if(V){const i={capture:(r=s.capture)!=null?r:!0};z(x,"pointerdown",M,i),z(p,"pointermove",S,i),z(p,"pointerup",n,i)}return{...F(h),position:h,isDragging:e.computed(()=>!!_.value),style:e.computed(()=>`left:${h.value.x}px;top:${h.value.y}px;`)}}const X={class:"modal-container"},Y={class:"title font-bold"},q={class:"action"},K={key:1,class:"modal-footer space-x-2"},G=["form"],U={name:"ModalContainer",inheritAttrs:!0},J=e.defineComponent({...U,props:{id:{},form:{},component:{},componentProps:{},width:{},maxWidth:{},maxHeight:{},sizes:{},size:{default:"middle"},title:{},header:{type:Boolean,default:!0},footer:{type:Boolean,default:!1},closeable:{type:Boolean,default:!0},esc:{type:Boolean,default:!1},maskClosable:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1}},emits:["submit"],setup(o,{emit:s}){const t=o,r=s,l=e.inject(C);let d=0,y=0;const m=e.shallowRef(),v=e.shallowRef(),c=e.shallowRef(),{x:u,y:a}=I(c,{initialValue:{x:0,y:0}});function f(){l==null||l.close(t.id)}function p(n){if(typeof n=="number")return`${n}px`;if(typeof n=="string")return n}const b=e.computed(()=>{const n={};return t.size&&(n.width=p(t.sizes[t.size])),t.width&&(n.width=p(t.width)),t.maxWidth&&(n.maxWidth=p(t.maxWidth)),t.size==="fullscreen"&&(n.maxWidth="unset",n.position="fixed",n.top=0,n.left=0,n.bottom=0,n.right=0),t.draggable&&t.size!=="fullscreen"&&(n.transform=`translate(${u.value-d}px, ${a.value-y}px)`),n}),x=e.computed(()=>{const n={};return t.draggable&&t.size!=="fullscreen"&&(n.cursor="move"),n}),h=e.computed(()=>{var i;const n={};return t.maxHeight&&(n.maxHeight=`calc(${(i=p(t.maxWidth))==null?void 0:i.replace("%","vh")} - 50px)`),t.size==="fullscreen"&&(n.maxHeight="calc(100% - 50px)"),n});function _(){const n=v.value;if(t.form&&n){const i=n.querySelector(`form[name="${t.form}"]`);i&&i.dispatchEvent(new Event("submit"))}r("submit")}function k(){l==null||l.close(t.id)}function E(){window&&window.addEventListener("resize",()=>{e.triggerRef(m),e.triggerRef(v),d=v.value.offsetLeft,y=v.value.offsetTop})}function M(){if(t.closeable&&t.esc){const n=({key:i})=>{i==="Escape"&&(l==null||l.close(t.id),window.removeEventListener("keydown",n))};window.addEventListener("keydown",n)}}function S(){d=v.value.offsetLeft,y=v.value.offsetTop}return e.onMounted(()=>{M(),E()}),e.onUnmounted(()=>{}),(n,i)=>(e.openBlock(),e.createElementBlock("div",X,[e.createElementVNode("div",{ref_key:"wrapperRef",ref:m,class:"modal-wrapper",onClick:i[0]||(i[0]=e.withModifiers(w=>n.maskClosable&&f(),["self"]))},[e.createElementVNode("div",{ref_key:"contentRef",ref:v,class:"modal-content",style:e.normalizeStyle(b.value)},[n.header?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"headerRef",ref:c,class:"modal-header",style:e.normalizeStyle(x.value),onMousedown:S},[e.createElementVNode("div",Y,e.toDisplayString(n.title),1),e.createElementVNode("div",q,[n.closeable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"i-icon-park-outline:close block cursor-pointer",onClick:f})):e.createCommentVNode("",!0)])],36)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"modal-body",style:e.normalizeStyle(h.value)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.component),e.normalizeProps(e.guardReactiveProps(n.componentProps)),null,16))],4),n.footer?(e.openBlock(),e.createElementBlock("div",K,[e.createElementVNode("button",{class:"submit-button",form:n.form,type:"submit",onClick:_}," 确定 ",8,G),e.createElementVNode("button",{class:"cancel-button",type:"button",onClick:k}," 取消 ")])):e.createCommentVNode("",!0)],4)],512)]))}});const $=(o,s)=>{const t=o.__vccOpts||o;for(const[r,l]of s)t[r]=l;return t},L=$(J,[["__scopeId","data-v-05b670ad"]]),Q={key:0,class:"modal-teleport"},Z={name:"ModalProvider",inheritAttrs:!0},j=e.defineComponent({...Z,props:{appendToBody:{type:Boolean,default:!1},sizes:{default:()=>({small:520,middle:860,large:1190})},maxWidth:{default:"80%"},maxHeight:{default:"80%"}},setup(o,{expose:s}){const t=e.shallowRef([]),r=e.ref(!1);async function l(c,u,a){const f=e.defineAsyncComponent(()=>Promise.resolve(c));return new Promise(p=>{t.value.push({id:Math.random().toString(32).slice(2),component:f,props:u,options:a,resolve:p,onSubmit:e.ref(()=>{})}),e.triggerRef(t)})}function d(c,u){const a=t.value.findIndex(p=>p.id===c);if(a<0)return;const f=t.value[a];f==null||f.resolve(u),t.value.splice(a,1),e.triggerRef(t)}function y(){t.value.forEach(c=>{c.resolve()}),t.value=[],e.triggerRef(t)}function m(c){return t.value.find(u=>u.id===c)}function v(c,u){const a=t.value.find(f=>f.id===c);a&&(a.onSubmit.value=u)}return e.provide(C,{open:l,close:d,closeAll:y,getElement:m,addSubmitListener:v}),s({elements:t}),e.onMounted(()=>{r.value=!0}),(c,u)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(c.$slots,"default",{},void 0,!0),r.value?(e.openBlock(),e.createElementBlock("div",Q,[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!c.appendToBody,to:"body"},[e.createVNode(e.TransitionGroup,{name:"modal-fade"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,a=>(e.openBlock(),e.createBlock(L,e.mergeProps({id:a.id,key:a.id,component:a.component,"component-props":a.props,"max-height":c.maxHeight,"max-width":c.maxWidth,sizes:c.sizes},a.options,{onSubmit:a.onSubmit.value}),null,16,["id","component","component-props","max-height","max-width","sizes","onSubmit"]))),128))]),_:1})],8,["disabled"]))])):e.createCommentVNode("",!0)],64))}});const ee=$(j,[["__scopeId","data-v-171d9bdd"]]);function A(o,s){var r,l;let t=o==null?void 0:o.parent;for(;t&&((r=t==null?void 0:t.type)==null?void 0:r.name)!==s;)t=t.parent;return((l=t==null?void 0:t.type)==null?void 0:l.name)===s?t:null}function te(){const o=e.inject(C),s=e.getCurrentInstance();return{open(t,r,l){if(!o)throw new Error("Not Found Modal Provider Component");return o.open(t,r||{},l||{})},close(t){var d;if(!o)throw new Error("Not Found Modal Provider Component");const r=A(s,"ModalContainer"),l=(d=r==null?void 0:r.props)==null?void 0:d.id;if(!l)throw new Error("Not Found Current Modal Container");o.close(l,t)},closeAll(){if(!o)throw new Error("Not Found Modal Provider Component");o.closeAll()},onSubmit(t){const r=A(s,"ModalContainer");if(!(r==null?void 0:r.props.id))throw new Error("Not Found Current Modal Container")}}}function oe(o){var d;const s=e.inject(C),t=e.getCurrentInstance(),r=A(t,"ModalContainer"),l=(d=r==null?void 0:r.props)==null?void 0:d.id;s&&l&&s.addSubmitListener(l,o)}exports.ModalContainer=L;exports.ModalProvider=ee;exports.onSubmit=oe;exports.useModal=te;