epic-designer-cjh
Version:
基于vue3的设计器,可视化开发页面表单
661 lines (660 loc) • 21 kB
JavaScript
import { getCurrentInstance as se, createTextVNode as Te, Fragment as ae, Comment as Se, defineComponent as _, toRef as Re, computed as Oe, h as M, Teleport as Ie, onMounted as ue, onBeforeUnmount as ce, renderSlot as Be, ref as N, watch as Fe } from "vue";
import { u as Ce } from "./use-false-until-truthy-cceb153b.js";
import { c as Me } from "./index-f636e660.js";
import { a as De, o as X } from "./delegate-6e021bb9.js";
function Ae(e) {
return e.composedPath()[0] || null;
}
function ft() {
return se() !== null;
}
const ht = typeof window < "u", ke = (typeof window > "u" ? !1 : /iPad|iPhone|iPod/.test(navigator.platform) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1) && // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
!window.MSStream;
function vt() {
return ke;
}
function U(e, t, n = "default") {
const r = t[n];
if (r === void 0)
throw new Error(`[vueuc/${e}]: slot[${n}] is empty.`);
return r();
}
function L(e, t = !0, n = []) {
return e.forEach((r) => {
if (r !== null) {
if (typeof r != "object") {
(typeof r == "string" || typeof r == "number") && n.push(Te(String(r)));
return;
}
if (Array.isArray(r)) {
L(r, t, n);
return;
}
if (r.type === ae) {
if (r.children === null)
return;
Array.isArray(r.children) && L(r.children, t, n);
} else
r.type !== Se && n.push(r);
}
}), n;
}
function pt(e, t, n = "default") {
const r = t[n];
if (r === void 0)
throw new Error(`[vueuc/${e}]: slot[${n}] is empty.`);
const i = L(r());
if (i.length === 1)
return i[0];
throw new Error(`[vueuc/${e}]: slot[${n}] should have exactly one child.`);
}
function $e(e, t) {
console.error(`[vdirs/${e}]: ${t}`);
}
class Pe {
constructor() {
this.elementZIndex = /* @__PURE__ */ new Map(), this.nextZIndex = 2e3;
}
get elementCount() {
return this.elementZIndex.size;
}
ensureZIndex(t, n) {
const { elementZIndex: r } = this;
if (n !== void 0) {
t.style.zIndex = `${n}`, r.delete(t);
return;
}
const { nextZIndex: i } = this;
r.has(t) && r.get(t) + 1 === this.nextZIndex || (t.style.zIndex = `${i}`, r.set(t, i), this.nextZIndex = i + 1, this.squashState());
}
unregister(t, n) {
const { elementZIndex: r } = this;
r.has(t) ? r.delete(t) : n === void 0 && $e("z-index-manager/unregister-element", "Element not found when unregistering."), this.squashState();
}
squashState() {
const { elementCount: t } = this;
t || (this.nextZIndex = 2e3), this.nextZIndex - t > 2500 && this.rearrange();
}
rearrange() {
const t = Array.from(this.elementZIndex.entries());
t.sort((n, r) => n[1] - r[1]), this.nextZIndex = 2e3, t.forEach((n) => {
const r = n[0], i = this.nextZIndex++;
`${i}` !== r.style.zIndex && (r.style.zIndex = `${i}`);
});
}
}
const $ = new Pe(), y = "@@ziContext", He = {
mounted(e, t) {
const { value: n = {} } = t, { zIndex: r, enabled: i } = n;
e[y] = {
enabled: !!i,
initialized: !1
}, i && ($.ensureZIndex(e, r), e[y].initialized = !0);
},
updated(e, t) {
const { value: n = {} } = t, { zIndex: r, enabled: i } = n, o = e[y].enabled;
i && !o && ($.ensureZIndex(e, r), e[y].initialized = !0), e[y].enabled = !!i;
},
unmounted(e, t) {
if (!e[y].initialized)
return;
const { value: n = {} } = t, { zIndex: r } = n;
$.unregister(e, r);
}
}, bt = He;
function G(e, t) {
console.error(`[vueuc/${e}]: ${t}`);
}
function J(e) {
return typeof e == "string" ? document.querySelector(e) : e();
}
const gt = _({
name: "LazyTeleport",
props: {
to: {
type: [String, Object],
default: void 0
},
disabled: Boolean,
show: {
type: Boolean,
required: !0
}
},
setup(e) {
return {
showTeleport: Ce(Re(e, "show")),
mergedTo: Oe(() => {
const { to: t } = e;
return t ?? "body";
})
};
},
render() {
return this.showTeleport ? this.disabled ? U("lazy-teleport", this.$slots) : M(Ie, {
disabled: this.disabled,
to: this.mergedTo
}, U("lazy-teleport", this.$slots)) : null;
}
});
var x = [], Le = function() {
return x.some(function(e) {
return e.activeTargets.length > 0;
});
}, Ze = function() {
return x.some(function(e) {
return e.skippedTargets.length > 0;
});
}, K = "ResizeObserver loop completed with undelivered notifications.", _e = function() {
var e;
typeof ErrorEvent == "function" ? e = new ErrorEvent("error", {
message: K
}) : (e = document.createEvent("Event"), e.initEvent("error", !1, !1), e.message = K), window.dispatchEvent(e);
}, T;
(function(e) {
e.BORDER_BOX = "border-box", e.CONTENT_BOX = "content-box", e.DEVICE_PIXEL_CONTENT_BOX = "device-pixel-content-box";
})(T || (T = {}));
var m = function(e) {
return Object.freeze(e);
}, Ve = function() {
function e(t, n) {
this.inlineSize = t, this.blockSize = n, m(this);
}
return e;
}(), le = function() {
function e(t, n, r, i) {
return this.x = t, this.y = n, this.width = r, this.height = i, this.top = this.y, this.left = this.x, this.bottom = this.top + this.height, this.right = this.left + this.width, m(this);
}
return e.prototype.toJSON = function() {
var t = this, n = t.x, r = t.y, i = t.top, o = t.right, u = t.bottom, l = t.left, d = t.width, c = t.height;
return { x: n, y: r, top: i, right: o, bottom: u, left: l, width: d, height: c };
}, e.fromRect = function(t) {
return new e(t.x, t.y, t.width, t.height);
}, e;
}(), V = function(e) {
return e instanceof SVGElement && "getBBox" in e;
}, de = function(e) {
if (V(e)) {
var t = e.getBBox(), n = t.width, r = t.height;
return !n && !r;
}
var i = e, o = i.offsetWidth, u = i.offsetHeight;
return !(o || u || e.getClientRects().length);
}, Y = function(e) {
var t;
if (e instanceof Element)
return !0;
var n = (t = e == null ? void 0 : e.ownerDocument) === null || t === void 0 ? void 0 : t.defaultView;
return !!(n && e instanceof n.Element);
}, We = function(e) {
switch (e.tagName) {
case "INPUT":
if (e.type !== "image")
break;
case "VIDEO":
case "AUDIO":
case "EMBED":
case "OBJECT":
case "CANVAS":
case "IFRAME":
case "IMG":
return !0;
}
return !1;
}, w = typeof window < "u" ? window : {}, B = /* @__PURE__ */ new WeakMap(), Q = /auto|scroll/, qe = /^tb|vertical/, Ne = /msie|trident/i.test(w.navigator && w.navigator.userAgent), f = function(e) {
return parseFloat(e || "0");
}, z = function(e, t, n) {
return e === void 0 && (e = 0), t === void 0 && (t = 0), n === void 0 && (n = !1), new Ve((n ? t : e) || 0, (n ? e : t) || 0);
}, j = m({
devicePixelContentBoxSize: z(),
borderBoxSize: z(),
contentBoxSize: z(),
contentRect: new le(0, 0, 0, 0)
}), fe = function(e, t) {
if (t === void 0 && (t = !1), B.has(e) && !t)
return B.get(e);
if (de(e))
return B.set(e, j), j;
var n = getComputedStyle(e), r = V(e) && e.ownerSVGElement && e.getBBox(), i = !Ne && n.boxSizing === "border-box", o = qe.test(n.writingMode || ""), u = !r && Q.test(n.overflowY || ""), l = !r && Q.test(n.overflowX || ""), d = r ? 0 : f(n.paddingTop), c = r ? 0 : f(n.paddingRight), b = r ? 0 : f(n.paddingBottom), g = r ? 0 : f(n.paddingLeft), S = r ? 0 : f(n.borderTopWidth), h = r ? 0 : f(n.borderRightWidth), A = r ? 0 : f(n.borderBottomWidth), k = r ? 0 : f(n.borderLeftWidth), s = g + c, a = d + b, v = k + h, p = S + A, R = l ? e.offsetHeight - p - e.clientHeight : 0, W = u ? e.offsetWidth - v - e.clientWidth : 0, ye = i ? s + v : 0, ze = i ? a + p : 0, O = r ? r.width : f(n.width) - ye - W, I = r ? r.height : f(n.height) - ze - R, Ee = O + s + W + v, we = I + a + R + p, q = m({
devicePixelContentBoxSize: z(Math.round(O * devicePixelRatio), Math.round(I * devicePixelRatio), o),
borderBoxSize: z(Ee, we, o),
contentBoxSize: z(O, I, o),
contentRect: new le(g, d, O, I)
});
return B.set(e, q), q;
}, he = function(e, t, n) {
var r = fe(e, n), i = r.borderBoxSize, o = r.contentBoxSize, u = r.devicePixelContentBoxSize;
switch (t) {
case T.DEVICE_PIXEL_CONTENT_BOX:
return u;
case T.BORDER_BOX:
return i;
default:
return o;
}
}, Xe = function() {
function e(t) {
var n = fe(t);
this.target = t, this.contentRect = n.contentRect, this.borderBoxSize = m([n.borderBoxSize]), this.contentBoxSize = m([n.contentBoxSize]), this.devicePixelContentBoxSize = m([n.devicePixelContentBoxSize]);
}
return e;
}(), ve = function(e) {
if (de(e))
return 1 / 0;
for (var t = 0, n = e.parentNode; n; )
t += 1, n = n.parentNode;
return t;
}, Ue = function() {
var e = 1 / 0, t = [];
x.forEach(function(u) {
if (u.activeTargets.length !== 0) {
var l = [];
u.activeTargets.forEach(function(c) {
var b = new Xe(c.target), g = ve(c.target);
l.push(b), c.lastReportedSize = he(c.target, c.observedBox), g < e && (e = g);
}), t.push(function() {
u.callback.call(u.observer, l, u.observer);
}), u.activeTargets.splice(0, u.activeTargets.length);
}
});
for (var n = 0, r = t; n < r.length; n++) {
var i = r[n];
i();
}
return e;
}, ee = function(e) {
x.forEach(function(n) {
n.activeTargets.splice(0, n.activeTargets.length), n.skippedTargets.splice(0, n.skippedTargets.length), n.observationTargets.forEach(function(i) {
i.isActive() && (ve(i.target) > e ? n.activeTargets.push(i) : n.skippedTargets.push(i));
});
});
}, Ge = function() {
var e = 0;
for (ee(e); Le(); )
e = Ue(), ee(e);
return Ze() && _e(), e > 0;
}, P, pe = [], Je = function() {
return pe.splice(0).forEach(function(e) {
return e();
});
}, Ke = function(e) {
if (!P) {
var t = 0, n = document.createTextNode(""), r = { characterData: !0 };
new MutationObserver(function() {
return Je();
}).observe(n, r), P = function() {
n.textContent = "".concat(t ? t-- : t++);
};
}
pe.push(e), P();
}, Ye = function(e) {
Ke(function() {
requestAnimationFrame(e);
});
}, D = 0, Qe = function() {
return !!D;
}, je = 250, et = { attributes: !0, characterData: !0, childList: !0, subtree: !0 }, te = [
"resize",
"load",
"transitionend",
"animationend",
"animationstart",
"animationiteration",
"keyup",
"keydown",
"mouseup",
"mousedown",
"mouseover",
"mouseout",
"blur",
"focus"
], ne = function(e) {
return e === void 0 && (e = 0), Date.now() + e;
}, H = !1, tt = function() {
function e() {
var t = this;
this.stopped = !0, this.listener = function() {
return t.schedule();
};
}
return e.prototype.run = function(t) {
var n = this;
if (t === void 0 && (t = je), !H) {
H = !0;
var r = ne(t);
Ye(function() {
var i = !1;
try {
i = Ge();
} finally {
if (H = !1, t = r - ne(), !Qe())
return;
i ? n.run(1e3) : t > 0 ? n.run(t) : n.start();
}
});
}
}, e.prototype.schedule = function() {
this.stop(), this.run();
}, e.prototype.observe = function() {
var t = this, n = function() {
return t.observer && t.observer.observe(document.body, et);
};
document.body ? n() : w.addEventListener("DOMContentLoaded", n);
}, e.prototype.start = function() {
var t = this;
this.stopped && (this.stopped = !1, this.observer = new MutationObserver(this.listener), this.observe(), te.forEach(function(n) {
return w.addEventListener(n, t.listener, !0);
}));
}, e.prototype.stop = function() {
var t = this;
this.stopped || (this.observer && this.observer.disconnect(), te.forEach(function(n) {
return w.removeEventListener(n, t.listener, !0);
}), this.stopped = !0);
}, e;
}(), Z = new tt(), re = function(e) {
!D && e > 0 && Z.start(), D += e, !D && Z.stop();
}, nt = function(e) {
return !V(e) && !We(e) && getComputedStyle(e).display === "inline";
}, rt = function() {
function e(t, n) {
this.target = t, this.observedBox = n || T.CONTENT_BOX, this.lastReportedSize = {
inlineSize: 0,
blockSize: 0
};
}
return e.prototype.isActive = function() {
var t = he(this.target, this.observedBox, !0);
return nt(this.target) && (this.lastReportedSize = t), this.lastReportedSize.inlineSize !== t.inlineSize || this.lastReportedSize.blockSize !== t.blockSize;
}, e;
}(), it = function() {
function e(t, n) {
this.activeTargets = [], this.skippedTargets = [], this.observationTargets = [], this.observer = t, this.callback = n;
}
return e;
}(), F = /* @__PURE__ */ new WeakMap(), ie = function(e, t) {
for (var n = 0; n < e.length; n += 1)
if (e[n].target === t)
return n;
return -1;
}, C = function() {
function e() {
}
return e.connect = function(t, n) {
var r = new it(t, n);
F.set(t, r);
}, e.observe = function(t, n, r) {
var i = F.get(t), o = i.observationTargets.length === 0;
ie(i.observationTargets, n) < 0 && (o && x.push(i), i.observationTargets.push(new rt(n, r && r.box)), re(1), Z.schedule());
}, e.unobserve = function(t, n) {
var r = F.get(t), i = ie(r.observationTargets, n), o = r.observationTargets.length === 1;
i >= 0 && (o && x.splice(x.indexOf(r), 1), r.observationTargets.splice(i, 1), re(-1));
}, e.disconnect = function(t) {
var n = this, r = F.get(t);
r.observationTargets.slice().forEach(function(i) {
return n.unobserve(t, i.target);
}), r.activeTargets.splice(0, r.activeTargets.length);
}, e;
}(), ot = function() {
function e(t) {
if (arguments.length === 0)
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
if (typeof t != "function")
throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
C.connect(this, t);
}
return e.prototype.observe = function(t, n) {
if (arguments.length === 0)
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
if (!Y(t))
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
C.observe(this, t, n);
}, e.prototype.unobserve = function(t) {
if (arguments.length === 0)
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
if (!Y(t))
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
C.unobserve(this, t);
}, e.prototype.disconnect = function() {
C.disconnect(this);
}, e.toString = function() {
return "function ResizeObserver () { [polyfill code] }";
}, e;
}();
class st {
constructor() {
this.handleResize = this.handleResize.bind(this), this.observer = new (typeof window < "u" && window.ResizeObserver || ot)(this.handleResize), this.elHandlersMap = /* @__PURE__ */ new Map();
}
handleResize(t) {
for (const n of t) {
const r = this.elHandlersMap.get(n.target);
r !== void 0 && r(n);
}
}
registerHandler(t, n) {
this.elHandlersMap.set(t, n), this.observer.observe(t);
}
unregisterHandler(t) {
this.elHandlersMap.has(t) && (this.elHandlersMap.delete(t), this.observer.unobserve(t));
}
}
const oe = new st(), xt = _({
name: "ResizeObserver",
props: {
onResize: Function
},
setup(e) {
let t = !1;
const n = se().proxy;
function r(i) {
const { onResize: o } = e;
o !== void 0 && o(i);
}
ue(() => {
const i = n.$el;
if (i === void 0) {
G("resize-observer", "$el does not exist.");
return;
}
if (i.nextElementSibling !== i.nextSibling && i.nodeType === 3 && i.nodeValue !== "") {
G("resize-observer", "$el can not be observed (it may be a text node).");
return;
}
i.nextElementSibling !== null && (oe.registerHandler(i.nextElementSibling, r), t = !0);
}), ce(() => {
t && oe.unregisterHandler(n.$el.nextElementSibling);
});
},
render() {
return Be(this.$slots, "default");
}
});
function be(e) {
return e instanceof HTMLElement;
}
function ge(e) {
for (let t = 0; t < e.childNodes.length; t++) {
const n = e.childNodes[t];
if (be(n) && (me(n) || ge(n)))
return !0;
}
return !1;
}
function xe(e) {
for (let t = e.childNodes.length - 1; t >= 0; t--) {
const n = e.childNodes[t];
if (be(n) && (me(n) || xe(n)))
return !0;
}
return !1;
}
function me(e) {
if (!at(e))
return !1;
try {
e.focus({ preventScroll: !0 });
} catch {
}
return document.activeElement === e;
}
function at(e) {
if (e.tabIndex > 0 || e.tabIndex === 0 && e.getAttribute("tabIndex") !== null)
return !0;
if (e.getAttribute("disabled"))
return !1;
switch (e.nodeName) {
case "A":
return !!e.href && e.rel !== "ignore";
case "INPUT":
return e.type !== "hidden" && e.type !== "file";
case "BUTTON":
case "SELECT":
case "TEXTAREA":
return !0;
default:
return !1;
}
}
let E = [];
const mt = _({
name: "FocusTrap",
props: {
disabled: Boolean,
active: Boolean,
autoFocus: {
type: Boolean,
default: !0
},
onEsc: Function,
initialFocusTo: String,
finalFocusTo: String,
returnFocusOnDeactivated: {
type: Boolean,
default: !0
}
},
setup(e) {
const t = Me(), n = N(null), r = N(null);
let i = !1, o = !1;
const u = typeof document > "u" ? null : document.activeElement;
function l() {
return E[E.length - 1] === t;
}
function d(s) {
var a;
s.code === "Escape" && l() && ((a = e.onEsc) === null || a === void 0 || a.call(e, s));
}
ue(() => {
Fe(() => e.active, (s) => {
s ? (g(), De("keydown", document, d)) : (X("keydown", document, d), i && S());
}, {
immediate: !0
});
}), ce(() => {
X("keydown", document, d), i && S();
});
function c(s) {
if (!o && l()) {
const a = b();
if (a === null || a.contains(Ae(s)))
return;
h("first");
}
}
function b() {
const s = n.value;
if (s === null)
return null;
let a = s;
for (; a = a.nextSibling, !(a === null || a instanceof Element && a.tagName === "DIV"); )
;
return a;
}
function g() {
var s;
if (!e.disabled) {
if (E.push(t), e.autoFocus) {
const { initialFocusTo: a } = e;
a === void 0 ? h("first") : (s = J(a)) === null || s === void 0 || s.focus({ preventScroll: !0 });
}
i = !0, document.addEventListener("focus", c, !0);
}
}
function S() {
var s;
if (e.disabled || (document.removeEventListener("focus", c, !0), E = E.filter((v) => v !== t), l()))
return;
const { finalFocusTo: a } = e;
a !== void 0 ? (s = J(a)) === null || s === void 0 || s.focus({ preventScroll: !0 }) : e.returnFocusOnDeactivated && u instanceof HTMLElement && (o = !0, u.focus({ preventScroll: !0 }), o = !1);
}
function h(s) {
if (l() && e.active) {
const a = n.value, v = r.value;
if (a !== null && v !== null) {
const p = b();
if (p == null || p === v) {
o = !0, a.focus({ preventScroll: !0 }), o = !1;
return;
}
o = !0;
const R = s === "first" ? ge(p) : xe(p);
o = !1, R || (o = !0, a.focus({ preventScroll: !0 }), o = !1);
}
}
}
function A(s) {
if (o)
return;
const a = b();
a !== null && (s.relatedTarget !== null && a.contains(s.relatedTarget) ? h("last") : h("first"));
}
function k(s) {
o || (s.relatedTarget !== null && s.relatedTarget === n.value ? h("last") : h("first"));
}
return {
focusableStartRef: n,
focusableEndRef: r,
focusableStyle: "position: absolute; height: 0; width: 0;",
handleStartFocus: A,
handleEndFocus: k
};
},
render() {
const { default: e } = this.$slots;
if (e === void 0)
return null;
if (this.disabled)
return e();
const { active: t, focusableStyle: n } = this;
return M(ae, null, [
M("div", {
"aria-hidden": "true",
tabindex: t ? "0" : "-1",
ref: "focusableStartRef",
style: n,
onFocus: this.handleStartFocus
}),
e(),
M("div", {
"aria-hidden": "true",
style: n,
ref: "focusableEndRef",
tabindex: t ? "0" : "-1",
onFocus: this.handleEndFocus
})
]);
}
});
export {
mt as F,
gt as L,
xt as V,
ke as a,
U as b,
pt as c,
Ae as g,
ft as h,
ht as i,
oe as r,
vt as u,
bt as z
};