@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
1,383 lines (1,382 loc) • 44.8 kB
JavaScript
var Ae = Object.defineProperty;
var Xe = (e, t, n) => t in e ? Ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
var Y = (e, t, n) => Xe(e, typeof t != "symbol" ? t + "" : t, n);
import { ref as o, computed as b, createVNode as d, Fragment as ae, defineComponent as ge, watch as X, nextTick as ce, onBeforeMount as Ye, onMounted as pe, onUnmounted as ye, watchEffect as Ue, Teleport as qe, Transition as Ke, shallowRef as Je, render as re, h as Ze, cloneVNode as Ge, createApp as Qe, mergeProps as we, reactive as U, getCurrentInstance as _e } from "vue";
import { LocaleService as J } from "../locale/index.esm.js";
import { isMobilePhone as et, getMaxZIndex as me } from "../common/index.esm.js";
import "../property-panel/index.esm.js";
const tt = {
width: { Type: Number, default: 400 },
type: { Type: String, default: "info" },
title: { Type: String, default: "" },
detail: { Type: String, default: "" },
okButtonText: { Type: String, default: "确定" },
showOkButton: { Type: Boolean, default: !0 },
showCancelButton: { Type: Boolean, default: !0 },
cancelButtonText: { Type: String, default: "取消" },
exceptionInfo: { Type: Object, default: null },
promptEditorType: { Type: String, default: "text-area" },
buttons: { type: Object, default: [] }
};
function de() {
return new DOMException("The request is not allowed", "NotAllowedError");
}
async function nt(e) {
if (!navigator.clipboard)
throw de();
return navigator.clipboard.writeText(e);
}
async function at(e) {
const t = document.createElement("span");
t.textContent = e, t.style.whiteSpace = "pre", t.style.webkitUserSelect = "auto", t.style.userSelect = "all", document.body.appendChild(t);
const n = window.getSelection(), a = window.document.createRange();
n == null || n.removeAllRanges(), a.selectNode(t), n == null || n.addRange(a);
let u = !1;
try {
u = window.document.execCommand("copy");
} finally {
n == null || n.removeAllRanges(), window.document.body.removeChild(t);
}
if (!u)
throw de();
}
async function lt(e) {
try {
await nt(e);
} catch (t) {
try {
await at(e);
} catch (n) {
throw n || t || de();
}
}
}
function ot() {
async function e(t) {
await lt(t);
}
return { onCopy: e };
}
function st(e, t, n, a) {
const u = o(14), v = o(140), r = o(""), i = o(a.value.length), s = b(() => a.value), g = b(() => ({
"font-size": `${u.value}px`,
height: "100%"
}));
function x(p) {
if (p.currentTarget) {
const T = p.currentTarget.value || "";
i.value = T.length;
}
}
return () => d(ae, null, [d("textarea", {
title: "promptMessage",
name: "promptMessage",
class: "form-control",
style: g.value,
rows: "4",
maxlength: v.value,
onInput: (p) => x(p)
}, [s.value]), d("span", {
class: "textarea-wordcount",
title: r.value,
style: "position: absolute; bottom: 76px; right: 32px; cursor: pointer; text-align: right;"
}, [i.value + " / " + v.value])]);
}
function ut(e, t, n, a) {
const u = st(e, t, n, a), v = /* @__PURE__ */ new Map([["text-area", u]]);
function r(i) {
return v.get(i) || null;
}
return { getEditorRender: r };
}
function it() {
const e = o(!1), t = o("复制成功");
return {
feedbackStyle: b(() => {
const a = {
position: "absolute",
left: "50%",
top: "50%",
"min-width": "100px",
height: "40px",
background: "#303C53",
"line-height": "40px",
"text-align": "center",
"margin-left": "-30px",
"margin-top": "-50px",
"border-radius": "10px",
"box-shadow": "0px 2px 8px 0px",
color: "#fff",
transition: "all .3s ease",
padding: "0 10px"
};
return a.opacity = e.value ? "0.8" : "0", a.display = e.value ? "" : "none", a;
}),
feedbackMessage: t,
toShowFeedback: e
};
}
function rt(e, t) {
const n = t.getEditorRender(e.promptEditorType);
return () => n && n();
}
function ct(e, t) {
function n(w) {
if (w == null)
return 0;
let k = 0;
for (let R = 0; R < w.length; R++) {
const z = w.charCodeAt(R);
z >= 0 && z <= 128 ? k++ : k = k + 2;
}
return k;
}
function a(w, k) {
if (w !== "" && w !== void 0 && w !== null) {
w = "" + w;
const R = w.length;
let z = "", E = 0;
for (let B = 0; B < R; B++) {
const H = w.charAt(B);
if (E++, encodeURI(H).length > 4 && E++, z = z.concat(H), E >= k)
return z = z.concat("..."), z;
}
if (E < k)
return w;
}
return "";
}
const u = b(() => !!e.value && !!e.value.date), v = b(() => {
const w = e.value && e.value.date || "";
return `${t.exception.happend} : ${w}`;
}), r = b(() => !!e.value && !!e.value.detail), i = b(() => e.value ? n(e.value.detail) > 160 : !1), s = o(!1), g = b(() => s.value ? t.exception.collapse : t.exception.expand), x = b(() => {
const w = t.exception.detail + " : " + (e.value && e.value.detail) || "";
return s.value ? w : a(w, 160);
}), p = b(() => ({
bottom: s.value ? 0 : "2px"
}));
function T() {
s.value = !s.value;
}
return () => d("div", {
class: "toast-msg-detail",
style: "max-height: calc(100vh - 200px);overflow: auto;"
}, [u.value && d("div", null, [v.value]), r.value && d("div", {
class: "exception_wrap"
}, [d("div", {
class: "exception_error_msg"
}, [d("div", {
innerHTML: x.value
}, null), i.value && d("span", {
class: "exception_toggle_detail",
style: p.value,
onClick: T
}, [g.value])])])]);
}
function dt(e) {
return () => d("p", {
class: "toast-msg-detail",
innerHTML: e.value,
style: "max-height: calc(100vh - 200px);overflow: auto;"
}, null);
}
function vt(e, t, n, a, u) {
const v = o(e.exceptionInfo), r = b(() => {
const k = t.value === "question" ? "warning" : t.value, R = {
"f-icon": !0
}, z = `f-icon-${k}`;
return R[z] = !0, R;
}), i = b(() => n.value || v.value && v.value.message), s = b(() => a.value), g = b(() => !!a.value), x = b(() => !!v.value);
function p() {
return x.value ? ct(v, u) : g.value ? dt(s) : () => null;
}
const T = p(), w = b(() => u.locale === "en" ? {
wordBreak: "keep-all",
overflowWrap: "break-word"
} : {});
return () => d(ae, null, [d("div", {
class: "float-left modal-tips-iconwrap"
}, [d("span", {
class: r.value
}, null)]), d("div", {
class: "modal-tips-content"
}, [d("p", {
class: "toast-msg-title",
innerHTML: i.value,
style: w.value
}, null), T()])]);
}
function ft(e, t, n, a) {
const {
onCopy: u
} = t, {
toShowFeedback: v
} = n, r = o(a.exception.copySuccess || "复制成功"), i = o(a.exception.copy || "复制详细信息"), s = o(e.exceptionInfo || {
date: "",
message: "",
detail: ""
}), g = b(() => s.value && s.value.detail || "");
function x(p) {
u(g.value).catch((T) => {
r.value = a.exception.copyFailed || "复制失败";
}).finally(() => {
v.value = !0, setTimeout(() => {
v.value = !1;
}, 700);
});
}
return () => d("span", {
class: "copy-exception-info"
}, [d("span", {
onClick: x,
style: "cursor: pointer;"
}, [i.value])]);
}
function ht(e, t, n, a, u) {
const v = o(e.type), r = o(e.buttons), i = o(e.exceptionInfo), s = o(u.ok || e.okButtonText), g = o(u.cancel || e.cancelButtonText), x = o(e.showCancelButton), p = o(e.showOkButton), T = b(() => !!(r.value && r.value.length)), w = b(() => !!(i.value && i.value.detail)), k = b(() => !(r.value && r.value.length) && (p.value || x.value)), R = ft(e, n, a, u);
s.value === "关闭" ? s.value = u.close : s.value === "知道了" && (s.value = u.exception.roger);
function z(B) {
v.value === "question" && t.emit("reject"), t.emit("close");
}
function E(B) {
v.value === "question" && t.emit("accept"), t.emit("close");
}
return () => d("div", {
class: "modal-footer"
}, [w.value && R(), k.value && x.value && d("button", {
type: "button",
class: "btn btn-secondary btn-lg",
onClick: z
}, [g.value]), k.value && p.value && d("button", {
type: "button",
class: "btn btn-primary btn-lg",
onClick: E
}, [s.value]), T.value && r.value.length && r.value.map((B) => d("button", {
type: "button",
onClick: B.handle,
class: B.class
}, [B.iconClass && d("span", {
class: B.iconClass
}, null), B.text]))]);
}
function mt(e) {
const { getLocaleValue: t } = J, n = J.getLocale();
function a(u, v, r) {
return v === r ? t(u) : v;
}
return {
yes: a("messageBox.yes") || "是",
no: a("messageBox.no") || "否",
close: a("messageBox.close") || "关闭",
ok: a("messageBox.ok", e.okButtonText, "确定") || "确定",
cancel: a("messageBox.cancel", e.cancelButtonText, "取消") || "取消",
title: a("messageBox.title") || "系统提示",
errorTitle: a("messageBox.errorTitle") || "错误提示",
exception: {
expand: a("messageBox.exception.expand") || "展开",
collapse: a("messageBox.exception.collapse") || "收起",
happend: a("messageBox.exception.happend") || "发生时间",
detail: a("messageBox.exception.detail") || "详细信息",
copy: a("messageBox.exception.copy") || "复制详细信息",
copySuccess: a("messageBox.exception.copySuccess") || "复制成功",
copyFailed: a("messageBox.exception.copyFailed") || "复制失败",
roger: a("messageBox.exception.roger") || "知道了"
},
locale: n
};
}
const ee = /* @__PURE__ */ ge({
name: "FMessageBox",
props: tt,
emits: ["accept", "reject", "close"],
setup(e, t) {
const n = mt(e), a = o(e.type), u = o(e.title), v = o(e.detail), r = b(() => {
const E = {
"modal-tips": !0,
"d-flex": !0,
"flex-row": !0
}, B = `messager-type-${a.value}`;
return E[B] = !0, E;
}), i = b(() => {
const E = {
cursor: "default"
};
return a.value === "prompt" ? E.padding = "0.5rem 0.5rem 1rem 1.5rem" : a.value === "error" && (E.padding = "0.5rem 1.5rem 1rem 1.5rem"), E;
}), s = ot(), g = ut(e, a, u, v), x = it(), {
feedbackStyle: p,
feedbackMessage: T
} = x;
T.value = n.exception.copySuccess;
function w() {
return d("div", {
style: p.value
}, [T.value]);
}
function k() {
switch (a.value) {
case "prompt":
return rt(e, g);
default:
return vt(e, a, u, v, n);
}
}
const R = k(), z = ht(e, t, s, x, n);
return () => d("div", {
class: "farris-messager"
}, [!e.exceptionInfo && d("div", {
style: "height: 30px;width: 100%;position: absolute;",
class: "messager-draggable"
}, null), d("section", {
class: r.value,
style: i.value
}, [R()]), z(), w()]);
}
}), gt = {
/**
* 允许点击遮罩关闭对话框
*/
allowClickMaskToClose: { type: Boolean, default: !1 },
/**
* 关闭对话框前事件, 是个函数,返回true或者false
*/
beforeClose: { type: Function, default: () => !0 },
/**
* 自定义类
*/
class: { type: String, default: "" },
/**
* 自定义遮罩类
*/
maskClass: { type: String, default: "" },
/**
* 模态框标题
*/
title: { type: String, default: "" },
/**
* 模态框宽度
*/
width: { type: Number, default: 500 },
/**
* 模态框高度
*/
height: { type: Number, default: 320 },
/**
* 自定义按钮列表
*/
buttons: {
type: Array,
default: []
},
/**
* 是否展示模态框
*/
modelValue: { type: Boolean, default: !1 },
/**
* 是否模态
*/
mask: { type: Boolean, default: !0 },
/**
* 是否展示头部
*/
showHeader: { type: Boolean, default: !0 },
/**
* 是否展示默认按钮
*/
showButtons: { type: Boolean, default: !0 },
/**
* 是否启用自适应样式
*/
fitContent: { type: Boolean, default: !0 },
/**
* 是否展示右上角按钮
*/
showCloseButton: { type: Boolean, default: !0 },
showMaxButton: { type: Boolean, default: !1 },
minHeight: { type: Number },
maxHeight: { type: Number },
minWidth: { type: Number },
maxWidth: { type: Number },
containment: { type: Object, default: null },
resizeable: { type: Boolean, default: !1 },
draggable: { type: Boolean, default: !1 },
dragHandle: { type: Object, default: null },
closedCallback: { type: Function, default: null },
openedCallback: { type: Function, default: null },
// 窗口打开后的回调函数
resizeHandle: { type: Function, default: null },
render: { type: Function, default: null },
acceptCallback: { type: Function, default: null },
rejectCallback: { type: Function, default: null },
enableEsc: { type: Boolean, default: !0 },
enableEnter: { type: Boolean, default: !1 },
dialogType: { type: String, default: "" },
src: { type: String, default: "" },
footerHeight: { type: Number, default: 60 },
host: { type: Object, default: "body" },
isMessager: { type: Boolean, default: !1 },
maximized: { type: Boolean, default: !1 }
};
class L {
constructor(t, n) {
this.x = t, this.y = n;
}
static getTransformInfo(t) {
const a = window.getComputedStyle(t).getPropertyValue("transform").replace(/[^-\d,]/g, "").split(",");
if (a.length >= 6) {
const u = parseInt(a[4], 10), v = parseInt(a[5], 10);
return { x: u, y: v };
}
return { x: 0, y: 0 };
}
static fromEvent(t, n = null) {
if (this.isMouseEvent(t))
return new L(t.clientX, t.clientY);
if (n === null || t.changedTouches.length === 1)
return new L(t.changedTouches[0].clientX, t.changedTouches[0].clientY);
for (let a = 0; a < t.changedTouches.length; a++)
if (t.changedTouches[a].target === n)
return new L(t.changedTouches[a].clientX, t.changedTouches[a].clientY);
}
static isMouseEvent(t) {
return Object.prototype.toString.apply(t).indexOf("MouseEvent") === 8;
}
static isIPosition(t) {
return !!t && "x" in t && "y" in t;
}
static getCurrent(t) {
const n = new L(0, 0);
if (window) {
const a = window.getComputedStyle(t);
if (a) {
const u = parseInt(a.getPropertyValue("left"), 10), v = parseInt(a.getPropertyValue("top"), 10);
n.x = isNaN(u) ? 0 : u, n.y = isNaN(v) ? 0 : v;
}
return n;
}
return null;
}
static copy(t) {
return new L(0, 0).set(t);
}
get value() {
return { x: this.x, y: this.y };
}
add(t) {
return this.x += t.x, this.y += t.y, this;
}
subtract(t) {
return this.x -= t.x, this.y -= t.y, this;
}
multiply(t) {
this.x *= t, this.y *= t;
}
divide(t) {
this.x /= t, this.y /= t;
}
reset() {
return this.x = 0, this.y = 0, this;
}
set(t) {
return this.x = t.x, this.y = t.y, this;
}
}
class q {
constructor(t, n) {
this.width = t, this.height = n;
}
static getCurrent(t) {
const n = new q(0, 0);
if (window) {
const a = window.getComputedStyle(t);
return a && (n.width = parseInt(a.getPropertyValue("width"), 10), n.height = parseInt(a.getPropertyValue("height"), 10)), n;
}
return null;
}
static copy(t) {
return new q(0, 0).set(t);
}
set(t) {
return this.width = t.width, this.height = t.height, this;
}
}
function pt(e, t) {
const n = o(), a = o(), u = o(), v = o(), r = o(), i = o(), s = o(), g = o(), x = o(), p = o(), T = o(), w = o(e.resizeable), k = o(), R = o(e.draggable), z = o(!1);
function E() {
const c = a.value || document.body, f = window.getComputedStyle(c);
if (!f || !n.value)
return;
const S = L.getTransformInfo(n.value), M = {};
s.value && (M.deltaL = n.value.offsetLeft - s.value.x, M.deltaT = n.value.offsetTop - s.value.y);
const j = f.getPropertyValue("position");
M.width = c.clientWidth, M.height = c.clientHeight, M.pr = parseInt(f.getPropertyValue("padding-right"), 10), M.pb = parseInt(f.getPropertyValue("padding-bottom"), 10), M.position = f.getPropertyValue("position"), j === "static" && (c.style.position = "relative"), M.translateX = S.x, M.translateY = S.y, p.value = M;
}
function B(c) {
if (n.value) {
v.value = q.getCurrent(n.value), r.value = L.getCurrent(n.value), i.value = v.value ? q.copy(v.value) : null, s.value = r.value ? L.copy(r.value) : null, E();
const f = c.target.getAttribute("type") || "";
g.value = {
n: !!f.match(/n/),
s: !!f.match(/s/),
w: !!f.match(/w/),
e: !!f.match(/e/)
};
}
}
function H() {
var c, f, S, M;
if (n.value) {
const j = n.value;
g.value && ((g.value.n || g.value.s) && ((c = i.value) != null && c.height) && (j.style.height = i.value.height + "px"), (g.value.w || g.value.e) && ((f = i.value) != null && f.width) && (j.style.width = i.value.width + "px"), s.value && ((S = s.value) != null && S.x && (j.style.left = s.value.x + "px"), (M = s.value) != null && M.y && (j.style.top = s.value.y + "px")));
}
}
function V() {
const c = e.minHeight ? e.minHeight : 1, f = e.minWidth ? e.minWidth : 1;
i.value && s.value && g.value && v.value && (i.value.height < c && (i.value.height = c, g.value.n && r.value && (s.value.y = r.value.y + (v.value.height - c))), i.value.width < f && (i.value.width = f, g.value.w && r.value && (s.value.x = r.value.x + (v.value.width - f))), e.maxHeight && i.value.height > e.maxHeight && (i.value.height = e.maxHeight, r.value && g.value.n && (s.value.y = r.value.y + (v.value.height - e.maxHeight))), e.maxWidth && i.value.width > e.maxWidth && (i.value.width = e.maxWidth, g.value.w && r.value && (s.value.x = r.value.x + (v.value.width - e.maxWidth))));
}
function $() {
if (a.value) {
const c = p.value;
if (s.value && i.value && g.value && v.value) {
const f = c.width - c.pr - c.deltaL - c.translateX - s.value.x, S = c.height - c.pb - c.deltaT - c.translateY - s.value.y;
g.value.n && s.value.y + c.translateY < 0 && r.value && (s.value.y = -c.translateY, i.value.height = v.value.height + r.value.y + c.translateY), g.value.w && s.value.x + c.translateX < 0 && r.value && (s.value.x = -c.translateX, i.value.width = v.value.width + r.value.x + c.translateX), i.value.width > f && (i.value.width = f), i.value.height > S && (i.value.height = S);
}
}
}
function W(c) {
if (!u.value || !v.value || !r.value || !g.value)
return;
c.subtract(u.value);
const f = c.x, S = c.y;
g.value.n ? (s.value.y = r.value.y + S, i.value.height = v.value.height - S) : g.value.s && (i.value.height = v.value.height + S), g.value.e ? i.value.width = v.value.width + f : g.value.w && (i.value.width = v.value.width - f, s.value.x = r.value.x + f), $(), V(), H();
}
function m(c) {
if (!x.value)
return;
const f = L.fromEvent(c);
f && W(f);
}
function h() {
if (n.value) {
const {
width: c,
height: f,
x: S,
y: M
} = n.value.getBoundingClientRect(), j = L.getTransformInfo(n.value);
return {
size: {
width: c,
height: f
},
position: {
x: S - j.x,
y: M - j.y
}
};
}
return null;
}
function C(c) {
if (n.value) {
const f = h();
T.value = f;
}
u.value = void 0, v.value = null, r.value = null, i.value = null, s.value = null, g.value = null, x.value = null, document.removeEventListener("mousemove", m), document.removeEventListener("mouseup", C);
}
function F() {
document.addEventListener("mousemove", m), document.addEventListener("mouseup", C);
}
function O(c) {
c instanceof MouseEvent && c.button === 2 || R.value && (document.body.click(), c.stopPropagation(), c.preventDefault(), u.value = L.fromEvent(c), x.value = c.target, B(c), F());
}
function P(c) {
return n.value = c, w.value && d(ae, null, [d("div", {
class: "fv-resizable-handle fv-resizable-n",
type: "n",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-e",
type: "e",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-s",
type: "s",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-w",
type: "w",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-ne",
type: "ne",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-se fv-resizable-diagonal",
type: "se",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-sw",
type: "sw",
onMousedown: (f) => O(f)
}, null), d("div", {
class: "fv-resizable-handle fv-resizable-nw",
type: "nw",
onMousedown: (f) => O(f)
}, null)]);
}
function G(c = !0) {
document.body.click();
const f = a.value || document.body, S = q.getCurrent(f), M = n.value;
c && M && (k.value = h(), k.value.transform = M.style.transform), S && M && (i.value = S, i.value.height -= 14, i.value.width -= 14, M.style.height = i.value.height + "px", M.style.width = i.value.width + "px", M.style.left = "7px", M.style.top = "7px", M.style.transform = "", T.value = {
size: i.value,
position: {
x: 0,
y: 0
}
}, R.value = !1, z.value = !0);
}
function le() {
var c, f;
if (document.body.click(), k.value) {
const S = {
width: k.value.size.width || 0,
height: k.value.size.height || 0
}, M = {
x: (window.innerWidth - S.width) / 2,
y: (window.innerHeight - S.height) / 2
};
(c = i.value) == null || c.set(S), (f = s.value) == null || f.set(M);
const j = n.value;
j.style.height = S.height + "px", j.style.width = S.width + "px", j.style.left = `${M.x}px`, j.style.top = `${M.y}px`, j.style.transform = "", T.value = {
size: S,
position: M
}, R.value = e.draggable, z.value = !1;
}
}
function Q() {
if (n.value) {
const c = q.getCurrent(n.value);
if (c) {
const {
width: f,
height: S
} = c;
n.value.style.left = `${(window.innerWidth - f) / 2}px`, n.value.style.top = `${(window.innerHeight - S) / 2}px`, n.value.style.transform = "";
}
}
}
function K() {
const c = () => {
z.value ? G(!1) : Q(), document.body.click();
};
return window.addEventListener("resize", c), () => {
window.removeEventListener("resize", c);
};
}
const oe = K();
return {
renderResizeBar: P,
boundingElement: a,
resizedEventParam: T,
maximize: G,
restore: le,
allowDrag: R,
isMaximized: z,
unWindowResizeHandle: oe,
moveToCenter: Q
};
}
function yt(e, t, n) {
const a = o(), u = o(e.draggable), v = o(e.lockAxis), r = o(), i = o(), s = o(!1), g = o(new L(0, 0)), x = o(new L(0, 0)), p = o(new L(0, 0)), T = o(new L(0, 0));
X(() => n.value, (m) => {
r.value.style.cursor = m ? "move" : "default";
});
function w(m, h) {
if (h.tagName === "BUTTON")
return !1;
if (h === m)
return !0;
for (const C in h.children)
if (Object.prototype.hasOwnProperty.call(h.children, C) && w(m, h.children[C]))
return !0;
return !1;
}
function k() {
var F, O;
let m = p.value.x + x.value.x, h = p.value.y + x.value.y;
v.value === "x" ? (m = ((F = g.value) == null ? void 0 : F.x) || 0, p.value.x = 0) : v.value === "y" && (h = ((O = g.value) == null ? void 0 : O.y) || 0, p.value.y = 0);
const C = `translate3d(${Math.round(m)}px, ${Math.round(h)}px, 0px)`;
a.value && (a.value.style.transform = C), T.value.x = m, T.value.y = h;
}
function R() {
if (!i.value || !a.value)
return null;
const m = i.value.getBoundingClientRect(), h = a.value.getBoundingClientRect(), C = {
top: m.top < h.top,
right: m.right > h.right,
bottom: m.bottom > h.bottom,
left: m.left < h.left
};
return C.top || (p.value.y -= h.top - m.top), C.bottom || (p.value.y -= h.bottom - m.bottom), C.right || (p.value.x -= h.right - m.right), C.left || (p.value.x -= h.left - m.left), k(), C;
}
function z(m) {
m && (g.value && m.subtract(g.value), p.value.set(m), k(), R());
}
function E(m) {
s.value && u.value && (m.stopPropagation(), m.preventDefault(), z(L.fromEvent(m, r.value)));
}
function B() {
var m;
s.value && (s.value = !1, x.value.add(p.value), p.value.reset(), (m = a.value) == null || m.classList.remove("ng-dragging"), t.emit("stopMove"), document.removeEventListener("mousemove", E), document.removeEventListener("mouseup", B));
}
function H() {
!s.value && r.value && (s.value = !0, r.value.classList.add("ng-dragging"), document.addEventListener("mousemove", E), document.addEventListener("mouseup", B));
}
function V() {
if (a.value) {
const m = L.getTransformInfo(a.value);
x.value.set(m);
return;
}
x.value.reset();
}
function $(m) {
if (!n.value || m instanceof MouseEvent && m.button === 2)
return;
const h = m.target || m.srcElement;
r.value !== void 0 && h && !w(h, r.value) || u.value !== !1 && (document.body.click(), m.stopPropagation(), m.preventDefault(), g.value = L.fromEvent(m, a.value), V(), H());
}
function W(m, h, C) {
if (u.value && h) {
if (m)
r.value = m;
else if (e.dragHandle) {
if (e.dragHandle instanceof HTMLElement)
r.value = e.dragHandle;
else if (typeof e.dragHandle == "string") {
const F = h.querySelector(e.dragHandle);
F && (r.value = F);
}
}
a.value = h, i.value = C, r.value ? (r.value.classList.add("ng-draggable"), r.value.addEventListener("mousedown", $)) : u.value = !1;
}
}
return {
registerDraggle: W,
resetTranslate: V
};
}
function xe(e, t) {
if (e) {
const n = (a) => {
a.key.toLowerCase() === e.toLowerCase() && t({ event: a, key: e });
};
return document.addEventListener("keydown", n), () => {
document.removeEventListener("keydown", n);
};
}
}
function wt(e, t) {
const n = o(e.enableEsc);
let a = null;
return n.value ? (a = xe("Escape", (u) => {
t.emit("esc", { event: u.event, type: "esc" });
}), {
remove: a
}) : null;
}
function xt(e, t) {
const n = o(e.enableEnter);
let a = null;
return n.value ? (a = xe("Enter", (u) => {
t.emit("enter", { event: u.event, type: "enter" });
}), {
remove: a
}) : null;
}
const Z = /* @__PURE__ */ ge({
name: "FModal",
props: gt,
emits: ["update:modelValue", "accept", "cancel", "closed", "resize", "esc", "enter", "stopMove"],
setup(e, t) {
const n = o(e.width || 300), a = o(e.height || 200), u = o(e.modelValue), v = o(""), r = o(e.class), i = o(e.fitContent), s = o(e.showHeader), g = o(""), x = o(e.showCloseButton), p = o(e.showMaxButton), T = o(!1), w = o(e.dialogType), k = o(e.src), R = o(""), z = o(e.showButtons), E = o(e.title), B = o(e.containment || null), H = o();
E.value === "错误提示" && (E.value = J.getLocaleValue("messageBox.errorTitle"));
const V = o(!1);
function $(l, y) {
const I = y ? "accept" : "cancel";
Promise.resolve().then(() => {
var D;
return (D = e.beforeClose) == null ? void 0 : D.call(e, {
closeType: I
});
}).then((D) => {
D && (u.value = !1, t.emit("update:modelValue", !1), y != null && t.emit(y ? "accept" : "cancel"), t.emit("closed", l));
});
}
const W = [{
name: "cancel",
text: J.getLocaleValue("messageBox.cancel") || "取消",
class: "btn btn-secondary",
handle: (l) => {
$(l, !1);
}
}, {
name: "accept",
text: J.getLocaleValue("messageBox.ok") || "确定",
class: "btn btn-primary",
handle: (l) => {
$(l, !0);
}
}], m = o(e.buttons && e.buttons.length ? e.buttons : W), h = b(() => !!g.value), C = b(() => !!z.value && !!m.value), F = o(), O = o(), P = o(e.maximized || !1), {
renderResizeBar: G,
maximize: le,
restore: Q,
boundingElement: K,
resizedEventParam: oe,
allowDrag: c,
unWindowResizeHandle: f,
moveToCenter: S
} = pt(e), {
registerDraggle: M
} = yt(e, t, c);
function j() {
return !!document.querySelectorAll(".farris-modal").length && document.body.classList.contains("modal-open");
}
function Me() {
const l = document.querySelectorAll(".farris-modal").length;
(!l || l - 1 <= 0) && document.body.classList.remove("modal-open"), H.value && H.value.classList.remove("show");
}
X(() => e.title, (l, y) => {
l !== y && (E.value = l);
}), X(() => e.modelValue, (l, y) => {
l !== y && (u.value = l, u.value && e.draggable && ce(() => {
O.value && !B.value && (B.value = O.value.parentElement, K.value = B.value, M(F.value, O.value, K.value), S());
}), l || (B.value && (B.value = null), Me())), u.value ? V.value = j() : (P.value = !1, c.value = e.draggable);
}), X(() => e.showHeader, (l, y) => {
l !== y && (s.value = l);
}), X(() => e.showButtons, (l, y) => {
l !== y && (z.value = l);
}), X(() => oe.value, (l, y) => {
const I = l || {}, D = y || {};
JSON.stringify(I) !== JSON.stringify(D) && t.emit("resize", {
newSize: l,
oldSize: y,
isMaximized: P.value
});
}), X([() => e.width, () => e.height], (l, y) => {
(l[0] !== y[0] || l[1] !== y[1]) && (n.value = l[0] || 500, a.value = l[1] || 600);
}), X(() => e.class, (l, y) => {
r.value = l;
});
const _ = b(() => (u.value && document.body.classList.add("modal-open"), u.value)), Be = b(() => {
var I;
const l = {
modal: !0,
"farris-modal": !0,
fade: !0
};
l["f-modal-fitContent"] = !!i.value, l.show = !!_.value;
const y = (I = e.maskClass) == null ? void 0 : I.split(" ");
return y == null || y.reduce((D, A) => (D[A] = !0, D), l), l;
}), ke = b(() => {
var I;
const l = {
"modal-dialog": !0
}, y = (I = r.value) == null ? void 0 : I.split(" ");
return y == null || y.reduce((D, A) => (D[A] = !0, D), l), l;
}), ve = () => et() && !e.isMessager, Te = b(() => {
const l = document.documentElement.clientWidth, y = document.documentElement.clientHeight;
if (P.value)
return {
position: "fixed",
top: "0px",
left: "0px",
width: "100vw",
height: "100vh",
margin: "0"
};
const I = Math.min(n.value, l), D = i.value ? "auto" : `${Math.min(a.value, y - 10)}px`, A = {
position: "absolute",
top: `${(window.innerHeight - parseInt(D === "auto" ? "0" : D)) / 2}px`,
left: `${(window.innerWidth - I) / 2}px`,
width: `${I}px`,
height: D
};
return ve() && (A.top = "0px", A.left = "0px", A.width = `${window.innerWidth}px`, A.height = `${window.innerHeight}px`), e.mask || (A.pointerEvents = "auto"), A;
}), fe = o(me() || 1050), Ee = b(() => {
const l = {
display: "block",
overflow: "hidden"
};
return e.mask || (l.pointerEvents = "none", l.backgroundColor = "transparent"), V.value && (l.backgroundColor = "transparent"), l.zIndex = fe.value, l;
}), ze = b(() => ({
"modal-content": !0,
"modal-content-has-header": s.value,
"is-mobile": ve()
})), Se = b(() => {
const l = {
display: s.value ? "" : "none"
};
return l["pointer-events"] = c.value ? "auto" : "none", l;
}), Re = b(() => ({
"f-icon": !0,
modal_maximize: !0,
modalrevert: P.value
})), He = b(() => ({
"modal-body": !0,
"f-utils-flex-column": w.value === "iframe",
"f-utils-fill": !0
}));
function Oe() {
return {
height: `${e.footerHeight || 60}px`
};
}
const Ie = b(() => {
const l = {
textAlgin: R.value
}, y = Oe();
return Object.assign(l, y);
});
function se(l) {
if (l == null || l.stopPropagation(), P.value) {
P.value = !1, Q();
return;
}
le(), P.value = !0;
}
async function Le(l, y) {
l.handle && await l.handle(y, l) && t.emit("closed", y);
}
function je(l) {
l.width && (n.value = l.width), l.height && (a.value = l.height), l.buttons && (m.value = l.buttons), l.title && (E.value = l.title);
}
let ue = null, ie = null;
Ye(() => {
V.value = j();
}), pe(() => {
O.value && !B.value && (B.value = O.value.parentElement, K.value = B.value, M(F.value, O.value, K.value)), _.value && document.body.classList.add("modal-open"), ue = wt(e, t), ie = xt(e, t);
}), ye(() => {
f && f(), ue && ue.remove(), ie && ie.remove();
}), t.expose({
modalElementRef: O,
updateModalOptions: je,
close: $,
maxDialog: se,
isMaximized: P,
disableButtons: (l, y = !0) => {
m.value.forEach((I) => {
I.name && l.includes(I.name) && (I.disabled = y);
});
}
});
function Fe() {
return d("ul", null, [T.value && d("li", {
class: "f-btn-icon f-bare"
}, [d("span", {
class: "f-icon modal_minimize"
}, null)]), p.value && d("li", {
onClick: se,
class: "f-btn-icon f-bare",
style: "pointer-events: auto;"
}, [d("span", {
class: Re.value
}, null)]), x.value && d("li", {
class: "f-btn-icon f-bare",
onClick: (l) => $(l, !1),
style: "pointer-events: auto;"
}, [d("span", {
class: "f-icon modal_close"
}, null)])]);
}
function De() {
return d("div", {
class: "modal-footer",
style: Ie.value
}, [m.value && m.value.map((l) => {
const y = o(l.disabled);
return d("button", {
name: l.name,
style: l.styles,
type: "button",
disabled: y.value,
class: l.class + (l.iconClass ? " btn-icontext" : ""),
onClick: (I) => {
Le(l, I);
}
}, [!!l.iconClass && d("i", {
class: l.iconClass
}, null), l.text]);
})]);
}
function he(l) {
p.value && se();
}
function We() {
return d(ae, null, [P.value && d("div", {
class: "modal-header",
style: "position: absolute;background: transparent;height: 45px;width: 100%;",
onDblclick: (l) => he()
}, null), d("div", {
ref: F,
class: "modal-header",
style: Se.value,
onDblclick: (l) => he()
}, [t.slots.headerTemplate ? t.slots.headerTemplate() : d("div", {
class: "modal-title"
}, [h.value && d("span", {
class: g.value,
style: "margin-right: 8px"
}, null), d("span", {
class: "modal-title-label"
}, [E.value])]), d("div", {
class: "actions"
}, [Fe()])])]);
}
function Pe() {
return t.slots.footerTemplate ? t.slots.footerTemplate() : C.value && De();
}
function Ne(l) {
if (l.stopPropagation(), e.allowClickMaskToClose) {
if (l.target !== H.value)
return;
$(l, !1);
}
}
function Ve() {
var l, y;
return d("div", {
id: v.value,
class: ke.value,
style: Te.value,
ref: O
}, [d("div", {
class: ze.value
}, [s.value && We(), d("div", {
class: He.value
}, [(y = (l = t.slots).default) == null ? void 0 : y.call(l), w.value === "iframe" && d("iframe", {
title: v.value,
class: "f-utils-fill",
width: "100%",
frameborder: "0",
src: k.value
}, null)]), Pe()]), !i.value && O.value && !P.value && G(O.value)]);
}
function $e(l) {
return l || "body";
}
return Ue(() => {
_.value && (fe.value = me() || 1050);
}), () => d(qe, {
to: $e(e.host)
}, {
default: () => [_.value && d(Ke, {
name: "fade",
appear: !0
}, {
default: () => [d("div", {
ref: H,
class: Be.value,
style: Ee.value,
onClick: Ne
}, [Ve()])]
})]
});
}
});
function be(e) {
if (e.content && e.content.render)
return e.content.render;
if (e.render && typeof e.render == "function")
return e.render;
}
function bt(e) {
const t = document.createElement("div");
t.style.display = "contents";
const n = Qe({
setup(a, u) {
ye(() => {
document.body.removeChild(t);
});
const v = o(), r = o(e.class || ""), i = o(!!e.showButtons), s = o(!!e.showHeader), g = o(e.showCloseButton == null ? !0 : e.showCloseButton), x = o(!0), p = o(e.title || ""), T = e.acceptCallback || (() => {
}), w = e.rejectCallback || (() => {
}), k = e.closedCallback || ((H) => {
}), R = e.resizeHandle || ((H) => {
}), z = e.stopMoveHandle || ((H) => {
}), E = be(e), B = (H) => {
x.value = !1, n.unmount(), k(H);
};
return pe(() => {
}), u.expose({
modalRef: v
}), () => d(Z, {
ref: v,
class: r.value,
modelValue: x.value,
"onUpdate:modelValue": (H) => x.value = H,
title: p.value,
width: e.width,
height: e.height,
buttons: e.buttons,
"show-header": s.value,
"show-buttons": i.value,
"show-close-button": g.value,
"show-max-button": !1,
onAccept: T,
onCancel: w,
fitContent: e.fitContent == null ? !0 : e.fitContent,
onClosed: B,
onResize: R,
onStopMove: z
}, {
default: () => [E && E(n)]
});
}
});
return document.body.appendChild(t), n.use(J.i18n), n.mount(t), n;
}
class Ce {
// private activeModalInstance = computed(() => {
// return this.modalRefs[this.activeModalIndex.value];
// });
constructor(t) {
Y(this, "appContext", null);
Y(this, "modalRef", o());
Y(this, "activeModalIndex", o(0));
Y(this, "modalRefs", {});
Y(this, "isUseEscCloseModal", o(!1));
this.app = t, this.appContext = t ? t._context : null;
}
getCurrentModal() {
return this.modalRefs[this.activeModalIndex.value];
}
adaptToWindow(t, n) {
const {
width: a,
height: u
} = {
width: window.innerWidth,
height: window.innerHeight
};
return a < t && (t = a - 14), u < n && (n = u - 14), {
width: t,
height: n
};
}
static show(t) {
const n = Object.assign({
title: "",
showButtons: !0,
showHeader: !0
}, t);
return bt(n);
}
close(t) {
var n, a;
t ? (a = t.value) == null || a.close() : (n = this.getCurrentModal()) == null || n.close();
}
open(t) {
const n = document.createDocumentFragment();
t.showMaxButton && t.fitContent && (t.showMaxButton = !1);
const a = Je(Object.assign({
title: "",
showButtons: !0,
showHeader: !0,
maximized: !1
}, t)), u = o(!0), v = a.value.acceptCallback || (() => {
}), r = a.value.rejectCallback || (() => {
}), i = a.value.closedCallback || ((h, C) => {
}), s = a.value.openedCallback || ((h) => {
}), g = a.value.resizeHandle || ((h) => {
}), x = t.stopMoveHandle || ((h) => {
});
let p;
const T = be(a.value), w = (h) => {
var F;
u.value = !1;
const C = (F = h == null ? void 0 : h.target) == null ? void 0 : F.classList.contains("modal_close");
i(h, this.isUseEscCloseModal.value ? "esc" : C ? "icon" : "button");
}, k = (h) => {
w(h), p && ce(() => {
if (this.modalRefs[this.activeModalIndex.value] && delete this.modalRefs[this.activeModalIndex.value], re(null, n), p = null, this.modalRef.value = null, this.modalRefs) {
const C = Object.keys(this.modalRefs).map((F) => Number(F));
C.length > 0 ? this.activeModalIndex.value = Math.max(...C) : this.activeModalIndex.value = 0;
}
this.isUseEscCloseModal.value = !1;
});
}, R = (h) => {
var C;
this.isUseEscCloseModal.value = !0, (C = this.getCurrentModal()) == null || C.close(h == null ? void 0 : h.event);
}, {
width: z,
height: E
} = a.value, B = this.adaptToWindow(z || 500, E || 320);
Object.assign(a.value, B);
const H = o(), V = () => d(Z, we({
ref: H,
modelValue: u.value,
"onUpdate:modelValue": (h) => u.value = h
}, a.value, {
isMessager: a.value.class && a.value.class.indexOf("modal-message") > -1,
onAccept: v,
onCancel: r,
onClosed: k,
onResize: g,
onEsc: R,
onStopMove: x,
maximized: a.value.maximized
}), {
default: () => [T && T(this.app)]
});
p = ((h) => {
const C = Ze(V, h);
return C.appContext = this.appContext, re(C, n), C;
})({
...a.value
// 'onUpdate:modelValue': onUpdateModelValue,
}), this.activeModalIndex.value++;
const W = this.activeModalIndex.value;
this.modalRefs[W] = H.value;
const m = (h) => {
a.value = {
...a.value,
...h
}, p && re(Ge(p, {
...a
}), n);
};
return ce(() => {
this.modalRefs[W] = H.value, this.modalRef.value = H.value, s(new Event("opened"));
}), {
update: m,
destroy: k,
modalRef: this.modalRef,
close: () => {
this.modalRefs[W] && this.modalRefs[W].close();
},
disableButtons: (h, C = !0) => {
this.modalRefs[W] && this.modalRefs[W].disableButtons(h, C);
}
};
}
}
const te = Symbol("FModalService");
Z.install = (e) => {
e.component(Z.name, Z);
const t = new Ce(e);
e.provide(te, t), e.provide("FModalService", t);
};
const N = class N {
static show(t) {
const n = U({
...t
}), a = !1, u = n.type === "error" || n.type === "prompt", v = n.type === "error" ? "错误提示" : n.type === "prompt" && n.title || "", r = n.acceptCallback || (() => {
}), i = n.rejectCallback || (() => {
}), s = _e();
let g = null;
if (s && s.appContext) {
const {
provides: w
} = s.appContext;
te in w && (g = w[te]);
}
g || (g = N.app._context.provides[te]);
let x = null, p = g || new Ce(N.app);
const T = () => {
x && (x == null || x.destroy(), p = null);
};
return x = p == null ? void 0 : p.open({
class: "modal-message modal-message-type-info",
title: v,
showButtons: a,
showHeader: u,
width: n.width || 400,
fitContent: !0,
showMaxButton: !1,
draggable: !0,
dragHandle: ".messager-draggable",
render: () => d(ee, we(n, {
onAccept: r,
onReject: i,
onClose: T
}), null)
}), p == null ? void 0 : p.getCurrentModal();
}
static info(t, n) {
const a = U({
type: "info",
title: t,
detail: n,
okButtonText: "知道了",
showCancelButton: !1
});
N.show(a);
}
static warning(t, n) {
const a = U({
type: "warning",
title: t,
detail: n,
okButtonText: "知道了",
showCancelButton: !1
});
N.show(a);
}
static success(t, n) {
const a = U({
type: "success",
title: t,
detail: n,
okButtonText: "关闭",
showCancelButton: !1
});
N.show(a);
}
static error(t, n, a) {
const u = U({
width: 500,
type: "error",
okButtonText: "关闭",
showCancelButton: !1,
exceptionInfo: {
date: a,
message: t,
detail: n
}
});
N.show(u);
}
static prompt(t, n) {
const a = U({
type: "prompt",
title: t,
detail: n,
okButtonText: "确定",
cancelButtonText: "取消"
});
N.show(a);
}
static question(t, n, a, u) {
const v = U({
type: "question",
title: t,
detail: n,
okButtonText: "确定",
cancelButtonText: "取消",
acceptCallback: a,
rejectCallback: u
});
N.show(v);
}
};
Y(N, "app", null);
let ne = N;
ee.install = (e) => {
e.component(ee.name, ee), ne.app = e, e.provide("FMessageBoxService", ne);
};
export {
ee as FMessageBox,
ne as FMessageBoxService,
ee as default,
tt as messageBoxProps
};