@dsplce-co/vue-modal 0.2.0 → 0.4.0

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.d.ts CHANGED
@@ -3,30 +3,76 @@ import { Component } from 'vue';
3
3
  import { ComponentCustomProps } from 'vue';
4
4
  import { ComponentOptionsMixin } from 'vue';
5
5
  import { ComponentProvideOptions } from 'vue';
6
+ import { ComputedRef } from 'vue';
6
7
  import { DefineComponent } from 'vue';
7
8
  import { MaybeRefOrGetter } from 'vue';
8
9
  import { Plugin as Plugin_2 } from 'vue';
9
10
  import { PublicProps } from 'vue';
10
11
  import { VNodeProps } from 'vue';
11
12
 
13
+ declare const __VLS_component: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, HTMLDivElement>;
14
+
15
+ declare function __VLS_template(): {
16
+ attrs: Partial<{}>;
17
+ slots: {
18
+ default?(_: {}): any;
19
+ };
20
+ refs: {};
21
+ rootEl: HTMLDivElement;
22
+ };
23
+
24
+ declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
25
+
12
26
  declare type __VLS_WithTemplateSlots<T, S> = T & {
13
27
  new (): {
14
28
  $slots: S;
15
29
  };
16
30
  };
17
31
 
32
+ declare type __VLS_WithTemplateSlots_2<T, S> = T & {
33
+ new (): {
34
+ $slots: S;
35
+ };
36
+ };
37
+
38
+ declare type MaybeReactive<R> = {
39
+ [K in keyof R]: MaybeRefOrGetter<R[K]>;
40
+ };
41
+
42
+ declare type MaybeReactivePropsOf<C> = MaybeReactive<PropsOf<C>>;
43
+
18
44
  /**
19
45
  * Teleport-like component for displaying active modal
20
46
  */
21
- export declare const ModalCollector: __VLS_WithTemplateSlots<DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, {
47
+ export declare const ModalCollector: __VLS_WithTemplateSlots<DefineComponent< {
48
+ /**
49
+ * Duration of the overlay animation
50
+ * @default 0.5s
51
+ */
52
+ transitionDuration?: string;
53
+ }, {
54
+ payload: ComputedRef<Record<PropertyKey, unknown>>;
55
+ component: ComputedRef<Component | null>;
56
+ close: () => void;
57
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{
58
+ /**
59
+ * Duration of the overlay animation
60
+ * @default 0.5s
61
+ */
62
+ transitionDuration?: string;
63
+ }> & Readonly<{}>, {
64
+ transitionDuration: string;
65
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>, {
22
66
  default?(_: {
23
67
  component: Component | null;
24
- payload: MaybeRefOrGetter<Record<PropertyKey, unknown>>;
68
+ payload: Record<PropertyKey, unknown>;
25
69
  close: () => void;
26
70
  }): any;
27
71
  }>;
28
72
 
29
- declare type OpenFn<C extends Component> = RequiredProps<PropsOf<C>> extends never ? (payload?: PropsOf<C>) => void : (payload: PropsOf<C>) => void;
73
+ export declare const ModalOverlay: __VLS_WithTemplateSlots_2<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
74
+
75
+ declare type OpenFn<C extends Component> = RequiredProps<PropsOf<C>> extends never ? (payload?: MaybeReactivePropsOf<C>) => void : (payload: MaybeReactivePropsOf<C>) => void;
30
76
 
31
77
  declare type PropsOf<C> = C extends new (...args: any) => {
32
78
  $props: infer P;
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("._vue-modal__overlay_17xh1_2{display:flex;justify-content:center;align-items:center;position:fixed;inset:0;z-index:10000;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);background-color:#00000040}._fade-enter-active_g101b_2,._fade-leave-active_g101b_3{transition:opacity .5s ease}._fade-enter-from_g101b_7,._fade-leave-to_g101b_8{opacity:0}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- import { inject as F, watch as P, toRef as G, readonly as q, ref as K, customRef as H, getCurrentScope as J, onScopeDispose as Q, computed as $, toValue as d, unref as j, shallowRef as _, defineComponent as I, h as U, createElementBlock as X, openBlock as k, normalizeClass as Y, renderSlot as W, createBlock as S, Teleport as Z, createVNode as R, Transition as x, withCtx as b, createCommentVNode as ee, resolveDynamicComponent as te, mergeProps as oe } from "vue";
3
- const D = /* @__PURE__ */ Symbol("State");
4
- function V() {
5
- const e = F(D);
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("._vue-modal__overlay_17xh1_2{display:flex;justify-content:center;align-items:center;position:fixed;inset:0;z-index:10000;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);background-color:#00000040}._fade-enter-active_slnnl_2,._fade-leave-active_slnnl_3{transition:opacity var(--v379fe401) ease}._fade-enter-from_slnnl_7,._fade-leave-to_slnnl_8{opacity:0}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ import { inject as F, watch as P, toRef as G, readonly as q, ref as K, customRef as x, getCurrentScope as H, onScopeDispose as J, computed as M, toValue as d, unref as D, shallowRef as _, defineComponent as j, h as Q, createElementBlock as U, openBlock as k, normalizeClass as X, renderSlot as I, useCssVars as Y, createBlock as S, Teleport as Z, createVNode as R, Transition as ee, withCtx as C, createCommentVNode as te, resolveDynamicComponent as oe, mergeProps as ne } from "vue";
3
+ const V = /* @__PURE__ */ Symbol("State");
4
+ function W() {
5
+ const e = F(V);
6
6
  if (!e)
7
7
  throw new Error("VueModal plugin was not initalized, make sure to include it in the plugins list");
8
8
  return e;
9
9
  }
10
- function Ee(e) {
11
- const { activeModal: o } = V();
10
+ function Se(e) {
11
+ const { activeModal: o } = W();
12
12
  return {
13
13
  open: (l) => {
14
14
  o.component.value = e, o.payload.value = l ?? null;
@@ -18,22 +18,22 @@ function Ee(e) {
18
18
  }
19
19
  };
20
20
  }
21
- function ne(e, o) {
22
- return J() ? (Q(e, o), !0) : !1;
21
+ function le(e, o) {
22
+ return H() ? (J(e, o), !0) : !1;
23
23
  }
24
- const le = typeof window < "u" && typeof document < "u";
24
+ const re = typeof window < "u" && typeof document < "u";
25
25
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
26
- const re = Object.prototype.toString, se = (e) => re.call(e) === "[object Object]", p = () => {
26
+ const se = Object.prototype.toString, ae = (e) => se.call(e) === "[object Object]", m = () => {
27
27
  };
28
- function ae(...e) {
28
+ function ue(...e) {
29
29
  if (e.length !== 1) return G(...e);
30
30
  const o = e[0];
31
- return typeof o == "function" ? q(H(() => ({
31
+ return typeof o == "function" ? q(x(() => ({
32
32
  get: o,
33
- set: p
33
+ set: m
34
34
  }))) : K(o);
35
35
  }
36
- function C(e) {
36
+ function O(e) {
37
37
  return Array.isArray(e) ? e : [e];
38
38
  }
39
39
  function ce(e, o, n) {
@@ -42,153 +42,153 @@ function ce(e, o, n) {
42
42
  immediate: !0
43
43
  });
44
44
  }
45
- const B = le ? window : void 0;
45
+ const B = re ? window : void 0;
46
46
  function y(e) {
47
47
  var o;
48
48
  const n = d(e);
49
49
  return (o = n?.$el) !== null && o !== void 0 ? o : n;
50
50
  }
51
51
  function w(...e) {
52
- const o = (t, l, s, c) => (t.addEventListener(l, s, c), () => t.removeEventListener(l, s, c)), n = $(() => {
53
- const t = C(d(e[0])).filter((l) => l != null);
52
+ const o = (t, l, a, r) => (t.addEventListener(l, a, r), () => t.removeEventListener(l, a, r)), n = M(() => {
53
+ const t = O(d(e[0])).filter((l) => l != null);
54
54
  return t.every((l) => typeof l != "string") ? t : void 0;
55
55
  });
56
56
  return ce(() => {
57
57
  var t, l;
58
58
  return [
59
- (t = (l = n.value) === null || l === void 0 ? void 0 : l.map((s) => y(s))) !== null && t !== void 0 ? t : [B].filter((s) => s != null),
60
- C(d(n.value ? e[1] : e[0])),
61
- C(j(n.value ? e[2] : e[1])),
59
+ (t = (l = n.value) === null || l === void 0 ? void 0 : l.map((a) => y(a))) !== null && t !== void 0 ? t : [B].filter((a) => a != null),
60
+ O(d(n.value ? e[1] : e[0])),
61
+ O(D(n.value ? e[2] : e[1])),
62
62
  d(n.value ? e[3] : e[2])
63
63
  ];
64
- }, ([t, l, s, c], f, u) => {
65
- if (!t?.length || !l?.length || !s?.length) return;
66
- const h = se(c) ? { ...c } : c, M = t.flatMap((v) => l.flatMap((g) => s.map((m) => o(v, g, m, h))));
67
- u(() => {
68
- M.forEach((v) => v());
64
+ }, ([t, l, a, r], f, c) => {
65
+ if (!t?.length || !l?.length || !a?.length) return;
66
+ const h = ae(r) ? { ...r } : r, $ = t.flatMap((v) => l.flatMap((g) => a.map((p) => o(v, g, p, h))));
67
+ c(() => {
68
+ $.forEach((v) => v());
69
69
  });
70
70
  }, { flush: "post" });
71
71
  }
72
- function ue(e, o, n = {}) {
73
- const { window: t = B, ignore: l = [], capture: s = !0, detectIframe: c = !1, controls: f = !1 } = n;
72
+ function ie(e, o, n = {}) {
73
+ const { window: t = B, ignore: l = [], capture: a = !0, detectIframe: r = !1, controls: f = !1 } = n;
74
74
  if (!t) return f ? {
75
- stop: p,
76
- cancel: p,
77
- trigger: p
78
- } : p;
79
- let u = !0;
80
- const h = (r) => d(l).some((a) => {
81
- if (typeof a == "string") return Array.from(t.document.querySelectorAll(a)).some((i) => i === r.target || r.composedPath().includes(i));
75
+ stop: m,
76
+ cancel: m,
77
+ trigger: m
78
+ } : m;
79
+ let c = !0;
80
+ const h = (s) => d(l).some((u) => {
81
+ if (typeof u == "string") return Array.from(t.document.querySelectorAll(u)).some((i) => i === s.target || s.composedPath().includes(i));
82
82
  {
83
- const i = y(a);
84
- return i && (r.target === i || r.composedPath().includes(i));
83
+ const i = y(u);
84
+ return i && (s.target === i || s.composedPath().includes(i));
85
85
  }
86
86
  });
87
- function M(r) {
88
- const a = d(r);
89
- return a && a.$.subTree.shapeFlag === 16;
87
+ function $(s) {
88
+ const u = d(s);
89
+ return u && u.$.subTree.shapeFlag === 16;
90
90
  }
91
- function v(r, a) {
92
- const i = d(r), E = i.$.subTree && i.$.subTree.children;
93
- return E == null || !Array.isArray(E) ? !1 : E.some((L) => L.el === a.target || a.composedPath().includes(L.el));
91
+ function v(s, u) {
92
+ const i = d(s), E = i.$.subTree && i.$.subTree.children;
93
+ return E == null || !Array.isArray(E) ? !1 : E.some((L) => L.el === u.target || u.composedPath().includes(L.el));
94
94
  }
95
- const g = (r) => {
96
- const a = y(e);
97
- if (r.target != null && !(!(a instanceof Element) && M(e) && v(e, r)) && !(!a || a === r.target || r.composedPath().includes(a))) {
98
- if ("detail" in r && r.detail === 0 && (u = !h(r)), !u) {
99
- u = !0;
95
+ const g = (s) => {
96
+ const u = y(e);
97
+ if (s.target != null && !(!(u instanceof Element) && $(e) && v(e, s)) && !(!u || u === s.target || s.composedPath().includes(u))) {
98
+ if ("detail" in s && s.detail === 0 && (c = !h(s)), !c) {
99
+ c = !0;
100
100
  return;
101
101
  }
102
- o(r);
102
+ o(s);
103
103
  }
104
104
  };
105
- let m = !1;
105
+ let p = !1;
106
106
  const z = [
107
- w(t, "click", (r) => {
108
- m || (m = !0, setTimeout(() => {
109
- m = !1;
110
- }, 0), g(r));
107
+ w(t, "click", (s) => {
108
+ p || (p = !0, setTimeout(() => {
109
+ p = !1;
110
+ }, 0), g(s));
111
111
  }, {
112
112
  passive: !0,
113
- capture: s
113
+ capture: a
114
114
  }),
115
- w(t, "pointerdown", (r) => {
116
- const a = y(e);
117
- u = !h(r) && !!(a && !r.composedPath().includes(a));
115
+ w(t, "pointerdown", (s) => {
116
+ const u = y(e);
117
+ c = !h(s) && !!(u && !s.composedPath().includes(u));
118
118
  }, { passive: !0 }),
119
- c && w(t, "blur", (r) => {
119
+ r && w(t, "blur", (s) => {
120
120
  setTimeout(() => {
121
- var a;
121
+ var u;
122
122
  const i = y(e);
123
- ((a = t.document.activeElement) === null || a === void 0 ? void 0 : a.tagName) === "IFRAME" && !i?.contains(t.document.activeElement) && o(r);
123
+ ((u = t.document.activeElement) === null || u === void 0 ? void 0 : u.tagName) === "IFRAME" && !i?.contains(t.document.activeElement) && o(s);
124
124
  }, 0);
125
125
  }, { passive: !0 })
126
- ].filter(Boolean), A = () => z.forEach((r) => r());
126
+ ].filter(Boolean), A = () => z.forEach((s) => s());
127
127
  return f ? {
128
128
  stop: A,
129
129
  cancel: () => {
130
- u = !1;
130
+ c = !1;
131
131
  },
132
- trigger: (r) => {
133
- u = !0, g(r), u = !1;
132
+ trigger: (s) => {
133
+ c = !0, g(s), c = !1;
134
134
  }
135
135
  } : A;
136
136
  }
137
- function O(e) {
137
+ function b(e) {
138
138
  return typeof Window < "u" && e instanceof Window ? e.document.documentElement : typeof Document < "u" && e instanceof Document ? e.documentElement : e;
139
139
  }
140
140
  const T = /* @__PURE__ */ new WeakMap();
141
- function ie(e, o = !1) {
141
+ function de(e, o = !1) {
142
142
  const n = _(o);
143
143
  let t = "";
144
- P(ae(e), (c) => {
145
- const f = O(d(c));
144
+ P(ue(e), (r) => {
145
+ const f = b(d(r));
146
146
  if (f) {
147
- const u = f;
148
- if (T.get(u) || T.set(u, u.style.overflow), u.style.overflow !== "hidden" && (t = u.style.overflow), u.style.overflow === "hidden") return n.value = !0;
149
- if (n.value) return u.style.overflow = "hidden";
147
+ const c = f;
148
+ if (T.get(c) || T.set(c, c.style.overflow), c.style.overflow !== "hidden" && (t = c.style.overflow), c.style.overflow === "hidden") return n.value = !0;
149
+ if (n.value) return c.style.overflow = "hidden";
150
150
  }
151
151
  }, { immediate: !0 });
152
152
  const l = () => {
153
- const c = O(d(e));
154
- !c || n.value || (c.style.overflow = "hidden", n.value = !0);
155
- }, s = () => {
156
- const c = O(d(e));
157
- !c || !n.value || (c.style.overflow = t, T.delete(c), n.value = !1);
153
+ const r = b(d(e));
154
+ !r || n.value || (r.style.overflow = "hidden", n.value = !0);
155
+ }, a = () => {
156
+ const r = b(d(e));
157
+ !r || !n.value || (r.style.overflow = t, T.delete(r), n.value = !1);
158
158
  };
159
- return ne(s), $({
159
+ return le(a), M({
160
160
  get() {
161
161
  return n.value;
162
162
  },
163
- set(c) {
164
- c ? l() : s();
163
+ set(r) {
164
+ r ? l() : a();
165
165
  }
166
166
  });
167
167
  }
168
- const de = /* @__PURE__ */ I((e, { slots: o, emit: n }) => {
168
+ const fe = /* @__PURE__ */ j((e, { slots: o, emit: n }) => {
169
169
  const t = _();
170
- return ue(t, (l) => {
170
+ return ie(t, (l) => {
171
171
  n("trigger", l);
172
172
  }, e.options), () => {
173
- if (o.default) return U(e.as || "div", { ref: t }, o.default());
173
+ if (o.default) return Q(e.as || "div", { ref: t }, o.default());
174
174
  };
175
175
  }, {
176
176
  name: "OnClickOutside",
177
177
  props: ["as", "options"],
178
178
  emits: ["trigger"]
179
179
  });
180
- function fe() {
180
+ function ve() {
181
181
  let e = !1;
182
182
  const o = _(!1);
183
183
  return (n, t) => {
184
184
  if (o.value = t.value, e) return;
185
185
  e = !0;
186
- const l = ie(n, t.value);
187
- P(o, (s) => l.value = s);
186
+ const l = de(n, t.value);
187
+ P(o, (a) => l.value = a);
188
188
  };
189
189
  }
190
- fe();
191
- const ve = {
190
+ ve();
191
+ const pe = {
192
192
  "vue-modal__overlay": "_vue-modal__overlay_17xh1_2"
193
193
  }, N = (e, o) => {
194
194
  const n = e.__vccOpts || e;
@@ -196,62 +196,72 @@ const ve = {
196
196
  n[t] = l;
197
197
  return n;
198
198
  }, me = {};
199
- function pe(e, o) {
200
- return k(), X("div", {
201
- class: Y(e.$style["vue-modal__overlay"])
199
+ function ye(e, o) {
200
+ return k(), U("div", {
201
+ class: X(e.$style["vue-modal__overlay"])
202
202
  }, [
203
- W(e.$slots, "default")
203
+ I(e.$slots, "default")
204
204
  ], 2);
205
205
  }
206
- const ye = {
207
- $style: ve
208
- }, _e = /* @__PURE__ */ N(me, [["render", pe], ["__cssModules", ye]]), he = {}, ge = /* @__PURE__ */ I({
209
- ...he,
206
+ const _e = {
207
+ $style: pe
208
+ }, he = /* @__PURE__ */ N(me, [["render", ye], ["__cssModules", _e]]), ge = {}, ke = /* @__PURE__ */ j({
209
+ ...ge,
210
210
  __name: "ModalCollector",
211
- setup(e) {
212
- const { activeModal: o } = V(), n = $(() => o.payload.value ?? {}), t = $(() => o.component.value), l = () => {
213
- o.payload.value = null, o.component.value = null;
211
+ props: {
212
+ transitionDuration: { default: "0.5s" }
213
+ },
214
+ setup(e, { expose: o }) {
215
+ Y((r) => ({
216
+ v379fe401: r.transitionDuration
217
+ }));
218
+ const { activeModal: n } = W(), t = M(() => n.payload.value ?? {}), l = M(() => n.component.value), a = () => {
219
+ n.payload.value = null, n.component.value = null;
214
220
  };
215
- return w(document, "keydown", (s) => {
216
- s.key === "Escape" && l();
217
- }), (s, c) => (k(), S(Z, { to: "body" }, [
218
- W(s.$slots, "default", {
219
- component: t.value,
220
- payload: n.value,
221
- close: l
221
+ return w(document, "keydown", (r) => {
222
+ r.key === "Escape" && a();
223
+ }), o({
224
+ payload: t,
225
+ component: l,
226
+ close: a
227
+ }), (r, f) => (k(), S(Z, { to: "body" }, [
228
+ I(r.$slots, "default", {
229
+ component: l.value,
230
+ payload: t.value,
231
+ close: a
222
232
  }, () => [
223
- R(x, {
224
- "enter-active-class": s.$style["fade-enter-active"],
225
- "leave-active-class": s.$style["fade-leave-active"],
226
- "enter-from-class": s.$style["fade-enter-from"],
227
- "leave-to-class": s.$style["fade-leave-to"]
233
+ R(ee, {
234
+ "enter-active-class": r.$style["fade-enter-active"],
235
+ "leave-active-class": r.$style["fade-leave-active"],
236
+ "enter-from-class": r.$style["fade-enter-from"],
237
+ "leave-to-class": r.$style["fade-leave-to"]
228
238
  }, {
229
- default: b(() => [
230
- t.value !== null ? (k(), S(_e, { key: 0 }, {
231
- default: b(() => [
232
- R(j(de), { onTrigger: l }, {
233
- default: b(() => [
234
- (k(), S(te(t.value), oe(n.value, { onClose: l }), null, 16))
239
+ default: C(() => [
240
+ l.value !== null ? (k(), S(he, { key: 0 }, {
241
+ default: C(() => [
242
+ R(D(fe), { onTrigger: a }, {
243
+ default: C(() => [
244
+ (k(), S(oe(l.value), ne(t.value, { onClose: a }), null, 16))
235
245
  ]),
236
246
  _: 1
237
247
  })
238
248
  ]),
239
249
  _: 1
240
- })) : ee("", !0)
250
+ })) : te("", !0)
241
251
  ]),
242
252
  _: 1
243
253
  }, 8, ["enter-active-class", "leave-active-class", "enter-from-class", "leave-to-class"])
244
254
  ])
245
255
  ]));
246
256
  }
247
- }), ke = {
248
- "fade-enter-active": "_fade-enter-active_g101b_2",
249
- "fade-leave-active": "_fade-leave-active_g101b_3",
250
- "fade-enter-from": "_fade-enter-from_g101b_7",
251
- "fade-leave-to": "_fade-leave-to_g101b_8"
252
- }, we = {
253
- $style: ke
254
- }, Se = /* @__PURE__ */ N(ge, [["__cssModules", we]]);
257
+ }), we = {
258
+ "fade-enter-active": "_fade-enter-active_slnnl_2",
259
+ "fade-leave-active": "_fade-leave-active_slnnl_3",
260
+ "fade-enter-from": "_fade-enter-from_slnnl_7",
261
+ "fade-leave-to": "_fade-leave-to_slnnl_8"
262
+ }, Me = {
263
+ $style: we
264
+ }, Ce = /* @__PURE__ */ N(ke, [["__cssModules", Me]]);
255
265
  function $e() {
256
266
  return {
257
267
  activeModal: {
@@ -260,11 +270,12 @@ function $e() {
260
270
  }
261
271
  };
262
272
  }
263
- const be = (e) => {
264
- e.provide(D, $e());
273
+ const Oe = (e) => {
274
+ e.provide(V, $e());
265
275
  };
266
276
  export {
267
- Se as ModalCollector,
268
- be as VueModalPlugin,
269
- Ee as useModal
277
+ Ce as ModalCollector,
278
+ he as ModalOverlay,
279
+ Oe as VueModalPlugin,
280
+ Se as useModal
270
281
  };
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@dsplce-co/vue-modal",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Utility library for displaying modals in Vue",
5
+ "repository": {
6
+ "url": "https://github.com/dsplce-co/vue-modal"
7
+ },
5
8
  "files": [
6
9
  "dist"
7
10
  ],
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.cjs"
14
+ "import": "./dist/index.mjs"
13
15
  }
14
16
  },
15
17
  "keywords": [],
package/dist/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("._vue-modal__overlay_17xh1_2{display:flex;justify-content:center;align-items:center;position:fixed;inset:0;z-index:10000;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);background-color:#00000040}._fade-enter-active_g101b_2,._fade-leave-active_g101b_3{transition:opacity .5s ease}._fade-enter-from_g101b_7,._fade-leave-to_g101b_8{opacity:0}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),E=Symbol("State");function V(){const e=t.inject(E);if(!e)throw new Error("VueModal plugin was not initalized, make sure to include it in the plugins list");return e}function R(e){const{activeModal:n}=V();return{open:r=>{n.component.value=e,n.payload.value=r??null},close:()=>{n.component.value=null,n.payload.value=null}}}function B(e,n){return t.getCurrentScope()?(t.onScopeDispose(e,n),!0):!1}const A=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const L=Object.prototype.toString,j=e=>L.call(e)==="[object Object]",m=()=>{};function I(...e){if(e.length!==1)return t.toRef(...e);const n=e[0];return typeof n=="function"?t.readonly(t.customRef(()=>({get:n,set:m}))):t.ref(n)}function M(e){return Array.isArray(e)?e:[e]}function W(e,n,l){return t.watch(e,n,{...l,immediate:!0})}const O=A?window:void 0;function y(e){var n;const l=t.toValue(e);return(n=l?.$el)!==null&&n!==void 0?n:l}function g(...e){const n=(o,r,c,s)=>(o.addEventListener(r,c,s),()=>o.removeEventListener(r,c,s)),l=t.computed(()=>{const o=M(t.toValue(e[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return W(()=>{var o,r;return[(o=(r=l.value)===null||r===void 0?void 0:r.map(c=>y(c)))!==null&&o!==void 0?o:[O].filter(c=>c!=null),M(t.toValue(l.value?e[1]:e[0])),M(t.unref(l.value?e[2]:e[1])),t.toValue(l.value?e[3]:e[2])]},([o,r,c,s],f,i)=>{if(!o?.length||!r?.length||!c?.length)return;const h=j(s)?{...s}:s,w=o.flatMap(v=>r.flatMap(_=>c.map(p=>n(v,_,p,h))));i(()=>{w.forEach(v=>v())})},{flush:"post"})}function D(e,n,l={}){const{window:o=O,ignore:r=[],capture:c=!0,detectIframe:s=!1,controls:f=!1}=l;if(!o)return f?{stop:m,cancel:m,trigger:m}:m;let i=!0;const h=a=>t.toValue(r).some(u=>{if(typeof u=="string")return Array.from(o.document.querySelectorAll(u)).some(d=>d===a.target||a.composedPath().includes(d));{const d=y(u);return d&&(a.target===d||a.composedPath().includes(d))}});function w(a){const u=t.toValue(a);return u&&u.$.subTree.shapeFlag===16}function v(a,u){const d=t.toValue(a),k=d.$.subTree&&d.$.subTree.children;return k==null||!Array.isArray(k)?!1:k.some(b=>b.el===u.target||u.composedPath().includes(b.el))}const _=a=>{const u=y(e);if(a.target!=null&&!(!(u instanceof Element)&&w(e)&&v(e,a))&&!(!u||u===a.target||a.composedPath().includes(u))){if("detail"in a&&a.detail===0&&(i=!h(a)),!i){i=!0;return}n(a)}};let p=!1;const P=[g(o,"click",a=>{p||(p=!0,setTimeout(()=>{p=!1},0),_(a))},{passive:!0,capture:c}),g(o,"pointerdown",a=>{const u=y(e);i=!h(a)&&!!(u&&!a.composedPath().includes(u))},{passive:!0}),s&&g(o,"blur",a=>{setTimeout(()=>{var u;const d=y(e);((u=o.document.activeElement)===null||u===void 0?void 0:u.tagName)==="IFRAME"&&!d?.contains(o.document.activeElement)&&n(a)},0)},{passive:!0})].filter(Boolean),C=()=>P.forEach(a=>a());return f?{stop:C,cancel:()=>{i=!1},trigger:a=>{i=!0,_(a),i=!1}}:C}function S(e){return typeof Window<"u"&&e instanceof Window?e.document.documentElement:typeof Document<"u"&&e instanceof Document?e.documentElement:e}const $=new WeakMap;function N(e,n=!1){const l=t.shallowRef(n);let o="";t.watch(I(e),s=>{const f=S(t.toValue(s));if(f){const i=f;if($.get(i)||$.set(i,i.style.overflow),i.style.overflow!=="hidden"&&(o=i.style.overflow),i.style.overflow==="hidden")return l.value=!0;if(l.value)return i.style.overflow="hidden"}},{immediate:!0});const r=()=>{const s=S(t.toValue(e));!s||l.value||(s.style.overflow="hidden",l.value=!0)},c=()=>{const s=S(t.toValue(e));!s||!l.value||(s.style.overflow=o,$.delete(s),l.value=!1)};return B(c),t.computed({get(){return l.value},set(s){s?r():c()}})}const q=t.defineComponent((e,{slots:n,emit:l})=>{const o=t.shallowRef();return D(o,r=>{l("trigger",r)},e.options),()=>{if(n.default)return t.h(e.as||"div",{ref:o},n.default())}},{name:"OnClickOutside",props:["as","options"],emits:["trigger"]});function z(){let e=!1;const n=t.shallowRef(!1);return(l,o)=>{if(n.value=o.value,e)return;e=!0;const r=N(l,o.value);t.watch(n,c=>r.value=c)}}z();const F={"vue-modal__overlay":"_vue-modal__overlay_17xh1_2"},T=(e,n)=>{const l=e.__vccOpts||e;for(const[o,r]of n)l[o]=r;return l},G={};function K(e,n){return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(e.$style["vue-modal__overlay"])},[t.renderSlot(e.$slots,"default")],2)}const x={$style:F},H=T(G,[["render",K],["__cssModules",x]]),J={},Q=t.defineComponent({...J,__name:"ModalCollector",setup(e){const{activeModal:n}=V(),l=t.computed(()=>n.payload.value??{}),o=t.computed(()=>n.component.value),r=()=>{n.payload.value=null,n.component.value=null};return g(document,"keydown",c=>{c.key==="Escape"&&r()}),(c,s)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.renderSlot(c.$slots,"default",{component:o.value,payload:l.value,close:r},()=>[t.createVNode(t.Transition,{"enter-active-class":c.$style["fade-enter-active"],"leave-active-class":c.$style["fade-leave-active"],"enter-from-class":c.$style["fade-enter-from"],"leave-to-class":c.$style["fade-leave-to"]},{default:t.withCtx(()=>[o.value!==null?(t.openBlock(),t.createBlock(H,{key:0},{default:t.withCtx(()=>[t.createVNode(t.unref(q),{onTrigger:r},{default:t.withCtx(()=>[(t.openBlock(),t.createBlock(t.resolveDynamicComponent(o.value),t.mergeProps(l.value,{onClose:r}),null,16))]),_:1})]),_:1})):t.createCommentVNode("",!0)]),_:1},8,["enter-active-class","leave-active-class","enter-from-class","leave-to-class"])])]))}}),U={"fade-enter-active":"_fade-enter-active_g101b_2","fade-leave-active":"_fade-leave-active_g101b_3","fade-enter-from":"_fade-enter-from_g101b_7","fade-leave-to":"_fade-leave-to_g101b_8"},X={$style:U},Y=T(Q,[["__cssModules",X]]);function Z(){return{activeModal:{component:t.shallowRef(null),payload:t.shallowRef(null)}}}const ee=e=>{e.provide(E,Z())};exports.ModalCollector=Y;exports.VueModalPlugin=ee;exports.useModal=R;