jenesius-vue-modal
Version:
The progressive and simple modal system for Vue.js v3
985 lines (984 loc) • 31.2 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".modal-container{position:fixed;left:0;top:0;height:100%;width:100%;display:flex;align-items:center;justify-content:center;background-color:#3e3e3e21;cursor:pointer}.modal-item{cursor:default}.modal-list-enter-active,.modal-list-leave-active,.modal-list-enter-active .modal-item,.modal-list-leave-active .modal-item{transition:all .2s ease}.modal-list-enter-from,.modal-list-leave-to{opacity:0!important}.modal-list-enter-from .modal-item,.modal-list-leave-to .modal-item{transform:translateY(-60px)}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
import { reactive as W, watch as H, ref as x, computed as J, markRaw as ie, getCurrentInstance as ae, defineComponent as ue, onMounted as Z, withDirectives as se, openBlock as U, createElementBlock as ce, withModifiers as le, createBlock as de, resolveDynamicComponent as fe, unref as T, mergeProps as he, toHandlers as me, vShow as ve, h as G, TransitionGroup as ge } from "vue";
/*!
* jenesius-vue-modal v1.11.9
* (c) 2024 Jenesius
* @license MIT
*/
var D = function(n, e) {
return D = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
t.__proto__ = r;
} || function(t, r) {
for (var i in r)
Object.prototype.hasOwnProperty.call(r, i) && (t[i] = r[i]);
}, D(n, e);
};
function pe(n, e) {
if (typeof e != "function" && e !== null)
throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
D(n, e);
function t() {
this.constructor = n;
}
n.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
}
function _(n, e, t, r) {
function i(o) {
return o instanceof t ? o : new t(function(l) {
l(o);
});
}
return new (t || (t = Promise))(function(o, l) {
function f(a) {
try {
s(r.next(a));
} catch (u) {
l(u);
}
}
function c(a) {
try {
s(r.throw(a));
} catch (u) {
l(u);
}
}
function s(a) {
a.done ? o(a.value) : i(a.value).then(f, c);
}
s((r = r.apply(n, e || [])).next());
});
}
function F(n, e) {
var t = { label: 0, sent: function() {
if (o[0] & 1)
throw o[1];
return o[1];
}, trys: [], ops: [] }, r, i, o, l;
return l = { next: f(0), throw: f(1), return: f(2) }, typeof Symbol == "function" && (l[Symbol.iterator] = function() {
return this;
}), l;
function f(s) {
return function(a) {
return c([s, a]);
};
}
function c(s) {
if (r)
throw new TypeError("Generator is already executing.");
for (; l && (l = 0, s[0] && (t = 0)), t; )
try {
if (r = 1, i && (o = s[0] & 2 ? i.return : s[0] ? i.throw || ((o = i.return) && o.call(i), 0) : i.next) && !(o = o.call(i, s[1])).done)
return o;
switch (i = 0, o && (s = [s[0] & 2, o.value]), s[0]) {
case 0:
case 1:
o = s;
break;
case 4:
return t.label++, { value: s[1], done: !1 };
case 5:
t.label++, i = s[1], s = [0];
continue;
case 7:
s = t.ops.pop(), t.trys.pop();
continue;
default:
if (o = t.trys, !(o = o.length > 0 && o[o.length - 1]) && (s[0] === 6 || s[0] === 2)) {
t = 0;
continue;
}
if (s[0] === 3 && (!o || s[1] > o[0] && s[1] < o[3])) {
t.label = s[1];
break;
}
if (s[0] === 6 && t.label < o[1]) {
t.label = o[1], o = s;
break;
}
if (o && t.label < o[2]) {
t.label = o[2], t.ops.push(s);
break;
}
o[2] && t.ops.pop(), t.trys.pop();
continue;
}
s = e.call(n, t);
} catch (a) {
s = [6, a], i = 0;
} finally {
r = o = 0;
}
if (s[0] & 5)
throw s[1];
return { value: s[0] ? s[1] : void 0, done: !0 };
}
}
var m = (
/** @class */
function(n) {
pe(e, n);
function e(t, r) {
r === void 0 && (r = null);
var i = n.call(this) || this;
return i.isModalError = !0, i.message = t, i.details = r, i;
}
return e.Undefined = function(t) {
return new e("Modal with id: ".concat(t, " not founded. The modal window may have been closed earlier."));
}, e.UndefinedGuardName = function(t) {
return new e("Guard's name ".concat(t, " is not declaration."));
}, e.NextReject = function(t) {
return new e("Guard returned false. Modal navigation was stopped. Modal id ".concat(t));
}, e.GuardDeclarationType = function(t) {
return new e("Guard's type should be a function. Provided:", t);
}, e.RejectedByBeforeEach = function() {
return new e("The opening of the modal was stopped in beforeEach");
}, e.ConfigurationType = function(t) {
return new e("Configuration type must be an Object. Provided", t);
}, e.ConfigurationUndefinedParam = function(t, r) {
return new e("In configuration founded unknown parameter: ".concat(t, ". Available are ").concat(r.join(", "), " "));
}, e.QueueNoEmpty = function() {
return new e("Modal's queue is not empty. Probably some modal reject closing by onClose hook.");
}, e.EmptyModalQueue = function() {
return new e("Modal queue is empty.");
}, e.NotInitialized = function(t) {
return new e("Modal Container not found. Put container from jenesius-vue-modal in App's template. Namespace: ".concat(t, ". Check documentation for more information https://modal.jenesius.com/docs.html/installation#getting-started."));
}, e.ModalComponentNotProvided = function() {
return new e("The first parameter(VueComponent) was not specified.");
}, e.DuplicatedRouterIntegration = function() {
return new e("useModalRouter.init should escaped only once.");
}, e.ModalRouterIntegrationNotInitialized = function() {
return new e("The integration was not initialized. Please, use useModalRouter.init(router). For more information: https://modal.jenesius.com/docs.html/integration-vue-router#installation");
}, e.ModalEventNameMustBeString = function(t) {
return new e("Event name must be a string. Provided: ".concat(t));
}, e.ModalNotFoundByID = function(t) {
return new e("Modal with ID ".concat(t, " was not found."));
}, e.ModalNotExistsInStore = function(t) {
return new e("Provided name(".concat(t, ") don't exist in the store. Has the given name been added to the store?"));
}, e;
}(Error)
), S = (
/** @class */
function() {
function n() {
this.state = /* @__PURE__ */ new Map(), n.instance = this;
}
return n.prototype.getByName = function(e) {
return e === void 0 && (e = n.DEFAULT_NAMESPACE), this.state.has(e) || this.state.set(e, {
queue: W([]),
initialized: !1
}), this.state.get(e);
}, n.prototype.forceClean = function() {
this.state.forEach(function(e) {
e.queue.splice(0, e.queue.length);
});
}, n.DEFAULT_NAMESPACE = "default", n;
}()
), V = function() {
var n = new S(), e = {
scrollLock: !0,
animation: "modal-list",
backgroundClose: !0,
escClose: !0,
store: {},
skipInitCheck: !1,
draggable: !1,
appear: !0,
singleShow: !1,
beforeEach: function() {
}
}, t = n.getByName().queue;
return H(function() {
return t;
}, function() {
e.scrollLock && (t.length ? document.body.style.overflowY = "hidden" : document.body.style.overflowY = "auto");
}, { deep: !0 }), {
namespaceStore: n,
configuration: e
};
}();
function y(n) {
return V.namespaceStore.getByName(n);
}
var p = V.configuration;
function Ce(n) {
return !!n && typeof n == "object" && !!n.component;
}
function K(n) {
var e = {
backgroundClose: p.backgroundClose,
isRoute: !1,
namespace: S.DEFAULT_NAMESPACE,
draggable: p.draggable
};
return n.backgroundClose !== void 0 && (e.backgroundClose = n.backgroundClose), n.isRoute && (e.isRoute = n.isRoute), n.namespace && (e.namespace = n.namespace), n.draggable !== void 0 && (e.draggable = n.draggable), e;
}
function Y(n) {
n === void 0 && (n = {});
var e = {
background: !1,
esc: !1
};
return Object.assign(e, n);
}
function ee(n) {
return n || (n = {}), n;
}
function q(n, e) {
e === void 0 && (e = {});
var t = O.STORE.get(n);
if (!t)
return Promise.reject(m.ModalNotFoundByID(n));
var r = y(t.namespace), i = r.queue.findIndex(function(l) {
return l.id === n;
});
if (i === -1)
return Promise.reject(m.Undefined(n));
var o = w.get(n, "close").map(function(l) {
return be(l, n, Y(e));
});
return ne(o).then(function() {
r.queue.splice(i, 1);
}).then(function() {
w.get(n, "destroy").forEach(function(l) {
return l(Y(e));
});
}).then(function() {
w.delete(n);
});
}
var O = (
/** @class */
function() {
function n(e, t, r) {
var i = this;
this.events = W({}), this.backgroundClose = !0, this.isRoute = !1, this.id = n.modalId++, this.component = e, this.props = x(t), this.closed = J(function() {
return !y(r.namespace).queue.includes(i);
}), e.beforeModalClose && w.add(this.id, "close", e.beforeModalClose);
var o = K(r);
this.backgroundClose = o.backgroundClose, this.isRoute = o.isRoute, this.namespace = o.namespace, this.draggable = o.draggable, n.STORE.set(this.id, this);
}
return n.prototype.close = function() {
return q(this.id);
}, Object.defineProperty(n.prototype, "onclose", {
/**
* @description Hook for handling modal closing
* */
set: function(e) {
w.add(this.id, "close", e);
},
enumerable: !1,
configurable: !0
}), Object.defineProperty(n.prototype, "ondestroy", {
/**
* @description Hook for handling modal closing
* */
set: function(e) {
w.add(this.id, "destroy", e);
},
enumerable: !1,
configurable: !0
}), n.prototype.on = function(e, t) {
var r = this;
return Array.isArray(this.events[e]) || (this.events[e] = []), this.events[e].push(t), function() {
var i = r.events[e].indexOf(t);
i !== -1 && r.events[e].splice(i, 1);
};
}, n.STORE = /* @__PURE__ */ new Map(), n.modalId = 0, n.EVENT_PROMPT = "jenesius-vue-modal:____P____R____O____M____P____T", n;
}()
);
function te(n) {
return O.STORE.get(n);
}
var ye = {
store: {},
add: function(n, e, t) {
var r, i;
if (typeof t != "function")
throw m.GuardDeclarationType(t);
this.store[n] || (this.store[n] = (r = {}, r[e] = [], r)), this.store[n][e] || (this.store[n][e] = []), (i = this.store[n][e]) === null || i === void 0 || i.push(t);
},
get: function(n, e) {
return n in this.store ? e in this.store[n] ? this.store[n][e] || [] : [] : [];
},
delete: function(n) {
n in this.store && delete this.store[n];
}
};
const w = ye;
function ne(n) {
return n.reduce(function(e, t) {
return e.then(function() {
return t();
});
}, Promise.resolve());
}
function be(n, e, t) {
return function() {
return new Promise(function(r, i) {
var o, l = function(f) {
f === void 0 && (f = !0), f === !1 && i(m.NextReject(e)), r();
};
Promise.resolve(n.call((o = te(e)) === null || o === void 0 ? void 0 : o.instance, t)).then(l).catch(function(f) {
return i(f);
});
});
};
}
function we(n) {
return n = ee(n), ne(y(n.namespace).queue.map(function(e) {
return function() {
return e.close();
};
}));
}
function re(n) {
var e = y(n), t = e.queue;
if (t.length !== 0)
return t[t.length - 1];
}
function De(n) {
n = ee(n);
var e = re(n.namespace);
return e ? e.close() : Promise.resolve();
}
function _e(n, e, t) {
return _(this, void 0, void 0, function() {
var r, i, o, l, f;
return F(this, function(c) {
switch (c.label) {
case 0:
if (r = K(t), i = y(r.namespace), r.namespace === S.DEFAULT_NAMESPACE && !i.initialized && !p.skipInitCheck)
throw m.NotInitialized(r.namespace);
return [4, p.beforeEach()];
case 1:
if (c.sent() === !1)
throw m.RejectedByBeforeEach();
if (typeof n != "string")
return [3, 5];
if (o = Ee(n), !o)
throw m.ModalNotExistsInStore(n);
return Ce(o) ? (n = o.component, Object.assign(r, o), l = o.beforeEach, l ? [4, o.beforeEach()] : [3, 3]) : [3, 4];
case 2:
l = c.sent() === !1, c.label = 3;
case 3:
if (l)
throw m.RejectedByBeforeEach();
return [3, 5];
case 4:
n = o, c.label = 5;
case 5:
if (!n)
throw m.ModalComponentNotProvided();
return f = new O(n, e, r), i.queue.push(ie(f)), [2, f];
}
});
});
}
function oe(n, e, t) {
return e === void 0 && (e = {}), t === void 0 && (t = {}), Promise.resolve().then(function() {
return _e(n, e, t);
});
}
function Fe(n, e, t) {
return e === void 0 && (e = {}), t === void 0 && (t = {}), we({
namespace: t.namespace
}).then(function() {
var r = y(t.namespace);
if (r.queue.length)
throw m.QueueNoEmpty();
}).then(function() {
return oe(n, e, t);
});
}
function Be(n) {
if (typeof n != "object")
throw m.ConfigurationType(n);
Object.assign(p, n);
}
function qe(n) {
var e, t, r, i = ae(), o = String(((e = i == null ? void 0 : i.props) === null || e === void 0 ? void 0 : e.modalId) || ((t = i == null ? void 0 : i.props) === null || t === void 0 ? void 0 : t["modal-id"]) || ((r = i == null ? void 0 : i.attrs) === null || r === void 0 ? void 0 : r.modalId)), l = o.replace(/[^0-9]/g, "");
w.add(Number(l), "close", n);
}
function Le(n, e, t) {
return e === void 0 && (e = {}), t === void 0 && (t = {}), _(this, void 0, void 0, function() {
var r, i, o = this;
return F(this, function(l) {
switch (l.label) {
case 0:
return [4, oe(n, e, t)];
case 1:
return r = l.sent(), i = !1, [2, new Promise(function(f) {
r.on(O.EVENT_PROMPT, function(c) {
return _(o, void 0, void 0, function() {
return F(this, function(s) {
return i = !0, [2, r.close().then(function() {
return f(c);
}).catch(function() {
return i = !1;
})];
});
});
}), r.ondestroy = function() {
i || f(null);
};
})];
}
});
});
}
function Ee(n) {
return p.store[n] || void 0;
}
function Me(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
var B = { exports: {} }, j, Q;
function ke() {
if (Q)
return j;
Q = 1;
var n = 1e3, e = n * 60, t = e * 60, r = t * 24, i = r * 7, o = r * 365.25;
j = function(a, u) {
u = u || {};
var d = typeof a;
if (d === "string" && a.length > 0)
return l(a);
if (d === "number" && isFinite(a))
return u.long ? c(a) : f(a);
throw new Error(
"val is not a non-empty string or a valid number. val=" + JSON.stringify(a)
);
};
function l(a) {
if (a = String(a), !(a.length > 100)) {
var u = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
a
);
if (u) {
var d = parseFloat(u[1]), g = (u[2] || "ms").toLowerCase();
switch (g) {
case "years":
case "year":
case "yrs":
case "yr":
case "y":
return d * o;
case "weeks":
case "week":
case "w":
return d * i;
case "days":
case "day":
case "d":
return d * r;
case "hours":
case "hour":
case "hrs":
case "hr":
case "h":
return d * t;
case "minutes":
case "minute":
case "mins":
case "min":
case "m":
return d * e;
case "seconds":
case "second":
case "secs":
case "sec":
case "s":
return d * n;
case "milliseconds":
case "millisecond":
case "msecs":
case "msec":
case "ms":
return d;
default:
return;
}
}
}
}
function f(a) {
var u = Math.abs(a);
return u >= r ? Math.round(a / r) + "d" : u >= t ? Math.round(a / t) + "h" : u >= e ? Math.round(a / e) + "m" : u >= n ? Math.round(a / n) + "s" : a + "ms";
}
function c(a) {
var u = Math.abs(a);
return u >= r ? s(a, u, r, "day") : u >= t ? s(a, u, t, "hour") : u >= e ? s(a, u, e, "minute") : u >= n ? s(a, u, n, "second") : a + " ms";
}
function s(a, u, d, g) {
var E = u >= d * 1.5;
return Math.round(a / d) + " " + g + (E ? "s" : "");
}
return j;
}
function Se(n) {
t.debug = t, t.default = t, t.coerce = c, t.disable = o, t.enable = i, t.enabled = l, t.humanize = ke(), t.destroy = s, Object.keys(n).forEach((a) => {
t[a] = n[a];
}), t.names = [], t.skips = [], t.formatters = {};
function e(a) {
let u = 0;
for (let d = 0; d < a.length; d++)
u = (u << 5) - u + a.charCodeAt(d), u |= 0;
return t.colors[Math.abs(u) % t.colors.length];
}
t.selectColor = e;
function t(a) {
let u, d = null, g, E;
function v(...h) {
if (!v.enabled)
return;
const C = v, M = Number(/* @__PURE__ */ new Date()), P = M - (u || M);
C.diff = P, C.prev = u, C.curr = M, u = M, h[0] = t.coerce(h[0]), typeof h[0] != "string" && h.unshift("%O");
let b = 0;
h[0] = h[0].replace(/%([a-zA-Z%])/g, (k, R) => {
if (k === "%%")
return "%";
b++;
const N = t.formatters[R];
if (typeof N == "function") {
const I = h[b];
k = N.call(C, I), h.splice(b, 1), b--;
}
return k;
}), t.formatArgs.call(C, h), (C.log || t.log).apply(C, h);
}
return v.namespace = a, v.useColors = t.useColors(), v.color = t.selectColor(a), v.extend = r, v.destroy = t.destroy, Object.defineProperty(v, "enabled", {
enumerable: !0,
configurable: !1,
get: () => d !== null ? d : (g !== t.namespaces && (g = t.namespaces, E = t.enabled(a)), E),
set: (h) => {
d = h;
}
}), typeof t.init == "function" && t.init(v), v;
}
function r(a, u) {
const d = t(this.namespace + (typeof u > "u" ? ":" : u) + a);
return d.log = this.log, d;
}
function i(a) {
t.save(a), t.namespaces = a, t.names = [], t.skips = [];
let u;
const d = (typeof a == "string" ? a : "").split(/[\s,]+/), g = d.length;
for (u = 0; u < g; u++)
d[u] && (a = d[u].replace(/\*/g, ".*?"), a[0] === "-" ? t.skips.push(new RegExp("^" + a.slice(1) + "$")) : t.names.push(new RegExp("^" + a + "$")));
}
function o() {
const a = [
...t.names.map(f),
...t.skips.map(f).map((u) => "-" + u)
].join(",");
return t.enable(""), a;
}
function l(a) {
if (a[a.length - 1] === "*")
return !0;
let u, d;
for (u = 0, d = t.skips.length; u < d; u++)
if (t.skips[u].test(a))
return !1;
for (u = 0, d = t.names.length; u < d; u++)
if (t.names[u].test(a))
return !0;
return !1;
}
function f(a) {
return a.toString().substring(2, a.toString().length - 2).replace(/\.\*\?$/, "*");
}
function c(a) {
return a instanceof Error ? a.stack || a.message : a;
}
function s() {
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
}
return t.enable(t.load()), t;
}
var Pe = Se;
(function(n, e) {
e.formatArgs = r, e.save = i, e.load = o, e.useColors = t, e.storage = l(), e.destroy = (() => {
let c = !1;
return () => {
c || (c = !0, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."));
};
})(), e.colors = [
"#0000CC",
"#0000FF",
"#0033CC",
"#0033FF",
"#0066CC",
"#0066FF",
"#0099CC",
"#0099FF",
"#00CC00",
"#00CC33",
"#00CC66",
"#00CC99",
"#00CCCC",
"#00CCFF",
"#3300CC",
"#3300FF",
"#3333CC",
"#3333FF",
"#3366CC",
"#3366FF",
"#3399CC",
"#3399FF",
"#33CC00",
"#33CC33",
"#33CC66",
"#33CC99",
"#33CCCC",
"#33CCFF",
"#6600CC",
"#6600FF",
"#6633CC",
"#6633FF",
"#66CC00",
"#66CC33",
"#9900CC",
"#9900FF",
"#9933CC",
"#9933FF",
"#99CC00",
"#99CC33",
"#CC0000",
"#CC0033",
"#CC0066",
"#CC0099",
"#CC00CC",
"#CC00FF",
"#CC3300",
"#CC3333",
"#CC3366",
"#CC3399",
"#CC33CC",
"#CC33FF",
"#CC6600",
"#CC6633",
"#CC9900",
"#CC9933",
"#CCCC00",
"#CCCC33",
"#FF0000",
"#FF0033",
"#FF0066",
"#FF0099",
"#FF00CC",
"#FF00FF",
"#FF3300",
"#FF3333",
"#FF3366",
"#FF3399",
"#FF33CC",
"#FF33FF",
"#FF6600",
"#FF6633",
"#FF9900",
"#FF9933",
"#FFCC00",
"#FFCC33"
];
function t() {
return typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs) ? !0 : typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/) ? !1 : typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
}
function r(c) {
if (c[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + c[0] + (this.useColors ? "%c " : " ") + "+" + n.exports.humanize(this.diff), !this.useColors)
return;
const s = "color: " + this.color;
c.splice(1, 0, s, "color: inherit");
let a = 0, u = 0;
c[0].replace(/%[a-zA-Z%]/g, (d) => {
d !== "%%" && (a++, d === "%c" && (u = a));
}), c.splice(u, 0, s);
}
e.log = console.debug || console.log || (() => {
});
function i(c) {
try {
c ? e.storage.setItem("debug", c) : e.storage.removeItem("debug");
} catch {
}
}
function o() {
let c;
try {
c = e.storage.getItem("debug");
} catch {
}
return !c && typeof process < "u" && "env" in process && (c = process.env.DEBUG), c;
}
function l() {
try {
return localStorage;
} catch {
}
}
n.exports = Pe(e);
const { formatters: f } = n.exports;
f.j = function(c) {
try {
return JSON.stringify(c);
} catch (s) {
return "[UnexpectedJSONParseError]: " + s.message;
}
};
})(B, B.exports);
var Re = B.exports;
const Ae = /* @__PURE__ */ Me(Re);
function Ne(n) {
return Ae("jenesius-vue-modal:".concat(n));
}
const Oe = ["onPointerdown"], X = /* @__PURE__ */ ue({
__name: "WidgetModalContainerItem",
props: {
id: {},
show: { type: Boolean }
},
setup(n) {
const e = Ne("modal-item"), t = n, r = te(t.id), i = x(), o = x();
function l() {
if (r.backgroundClose)
return q(r.id, { background: !0 }).catch(() => {
});
}
H(() => o.value, (c) => {
var s;
if (r.instance = c, e(`Modal(${r.id}) instance is saved.`), r.draggable) {
const a = `[modalid=_modal_${t.id}]`, u = typeof r.draggable == "string" ? r.draggable : a;
e(`The modal window is movable(${u}).`), i.value ? (e("Finding an item to drag: %s", u), f(
(s = i.value) == null ? void 0 : s.querySelector(a),
i.value.querySelector(u)
)) : e("The modal container is not mounted. Modal id %d.", r.id);
}
}), Z(() => {
e(`Modal(${r.id}) is mounted`);
});
function f(c, s) {
if (!s) {
e("draggable item not found.");
return;
}
if (!c) {
e("HTML modal is not founded.");
return;
}
s.addEventListener("pointerdown", (a) => {
var k;
const u = (k = c.getAttribute("style")) == null ? void 0 : k.match(/transform: translate\((.*)px,\s*(.*)px\)/), d = u == null ? void 0 : u[1], g = u == null ? void 0 : u[2];
let E = typeof d == "string" ? Number.parseInt(d) : 0, v = typeof g == "string" ? Number.parseInt(g) : 0;
const { clientX: h, clientY: C } = a, M = h, P = C;
e(`movement started at (${P}, ${P})`), document.addEventListener("pointermove", b, { passive: !0 }), document.addEventListener("pointerup", L, { once: !0 });
function b(R) {
const { clientX: N, clientY: I } = R, $ = E + N - M, z = v + I - P;
e(`move at (${$}, ${z})`), c.style.transform = `translate(${$}px,${z}px)`;
}
function L(R) {
e("movement completed"), document.removeEventListener("pointermove", b), R.preventDefault();
}
});
}
return (c, s) => se((U(), ce("div", {
class: "widget__modal-container__item modal-container",
onPointerdown: le(l, ["self", "stop"]),
ref_key: "modalContainerRef",
ref: i
}, [
(U(), de(fe(T(r).component), he(T(r).props.value, {
class: "modal-item widget__modal-wrap",
modalId: `_modal_${c.id}`,
ref_key: "modalRef",
ref: o
}, me(T(r).events)), null, 16, ["modalId"]))
], 40, Oe)), [
[ve, c.show]
]);
}
});
function Ie(n) {
n === void 0 && (n = S.DEFAULT_NAMESPACE);
var e = S.instance.getByName(n);
e.initialized = !0, n === S.DEFAULT_NAMESPACE && document.addEventListener("keyup", function(t) {
if (p.escClose && (t.key === "Escape" || t.code === "Escape")) {
var r = re(n);
if (!r)
return;
q(r.id, { esc: !0 }).catch(function() {
});
}
});
}
const $e = {
props: {
namespace: String
},
setup(n) {
return Z(() => {
Ie(n.namespace);
}), () => {
const e = y(n.namespace);
return G(ge, { name: p.animation, tag: "div", appear: p.appear }, {
default: () => e.queue.map((t, r, i) => G(X, {
key: t.id,
id: t.id,
show: p.singleShow === !0 ? r === i.length - 1 : !0
}))
});
};
},
components: { WidgetContainerModalItem: X }
};
var A = {
router: null
};
function Te(n) {
var e = this;
if (A.router)
throw m.DuplicatedRouterIntegration();
A.router = n;
function t(r) {
for (var i = r.matched.length - 1; i >= 0; i--) {
var o = r.matched[i].components, l = Object.values(o).find(function(f) {
return f._isModal;
});
if (l)
return l;
}
return null;
}
n.beforeEach(function(r, i) {
return _(e, void 0, void 0, function() {
var o, l, f;
return F(this, function(c) {
switch (c.label) {
case 0:
return c.trys.push([0, 3, , 4]), o = t(i), o && !(!((f = (l = o.getModalObject()) === null || l === void 0 ? void 0 : l.closed) === null || f === void 0) && f.value) ? [4, o.close(!0)] : [3, 2];
case 1:
c.sent(), c.label = 2;
case 2:
return [3, 4];
case 3:
return c.sent(), [2, !1];
case 4:
return [
2
/*return*/
];
}
});
});
}), n.afterEach(function(r) {
return _(e, void 0, void 0, function() {
var i;
return F(this, function(o) {
switch (o.label) {
case 0:
return i = t(r), i ? [4, i.initialize()] : [3, 2];
case 1:
o.sent(), o.label = 2;
case 2:
return [
2
/*return*/
];
}
});
});
});
}
function je(n) {
var e = null, t = !1;
function r() {
return _(this, void 0, void 0, function() {
return F(this, function(i) {
switch (i.label) {
case 0:
if (!A.router)
throw m.ModalRouterIntegrationNotInitialized();
return t = !1, e = null, [4, Fe(n, J(function() {
var o;
return (o = A.router) === null || o === void 0 ? void 0 : o.currentRoute.value.params;
}), { isRoute: !0 })];
case 1:
return e = i.sent(), e.onclose = function() {
var o;
t || (o = A.router) === null || o === void 0 || o.back();
}, [
2
/*return*/
];
}
});
});
}
return {
getModalObject: function() {
return e;
},
/**
Флаг, использующийся для определения того, что данная компонента -
обёртка модального окна
*/
_isModal: !0,
close: function(i) {
return i === void 0 && (i = !1), _(this, void 0, void 0, function() {
return F(this, function(o) {
switch (o.label) {
case 0:
return t = i, e ? [4, e.close()] : [3, 2];
case 1:
return [2, o.sent()];
case 2:
return [
2
/*return*/
];
}
});
});
},
initialize: r,
/**
* Мнимая обёртка. Для того, чтобы рендеринг запускался.
* -----
* (19.02.2022)
* Try to change null to RouterView, using this way we can use children
* in router configuration.
* */
setup: function() {
return function() {
return null;
};
}
};
}
je.init = Te;
var ze = y().queue;
function Ue(n) {
return y(n).queue;
}
export {
O as Modal,
q as closeById,
we as closeModal,
Be as config,
$e as container,
Ee as getComponentFromStore,
re as getCurrentModal,
Ue as getQueueByNamespace,
ze as modalQueue,
qe as onBeforeModalClose,
Fe as openModal,
De as popModal,
Le as promptModal,
oe as pushModal,
je as useModalRouter
};
//# sourceMappingURL=jenesius-vue-modal.es.js.map