epic-designer-gold
Version:
基于vue3的设计器,可视化开发页面表单
1,442 lines (1,439 loc) • 45.1 kB
JavaScript
import { ref as V, reactive as ae, defineComponent as ie, openBlock as H, createBlock as q, unref as R, mergeProps as be, withCtx as T, renderSlot as K, getCurrentInstance as fe, inject as oe, watch as B, useAttrs as Re, provide as Z, shallowRef as Ue, computed as W, watchEffect as he, onUnmounted as $e, resolveComponent as Te, resolveDynamicComponent as Be, createVNode as Y, createCommentVNode as Ne, useSlots as Le, createElementBlock as Ee, Suspense as Pe, createElementVNode as k, Fragment as Je, renderList as ze, nextTick as de, effectScope as He, isRef as Ke, getCurrentScope as Ze, onScopeDispose as We, onMounted as Ae, normalizeClass as Ge, toRaw as Ie } from "vue";
import { p as z, f as Qe, d as ce, a as G, b as Fe, c as Ye, E as j, l as le, g as qe, e as Xe } from "./pluginManager-BCnrHPYv.js";
import { a as pe, u as Oe } from "./index-B1s67XDZ.js";
import { a as _e } from "./axios-CXDYiOMX.js";
function Lt(e, n) {
let r = null;
return (...s) => {
r && clearTimeout(r), r = setTimeout(() => {
e(...s);
}, n);
};
}
function Ve() {
const e = V({}), n = V({}), r = V(!1), s = V([]), c = ae({});
function a(p) {
return e.value[p];
}
function w(p, D) {
e.value[p] = D;
}
function g(p) {
delete e.value[p];
}
function m(p, D = !1) {
const I = Object.entries(z.publicMethods).reduce(
(C, [h, U]) => (C[h] = U.handler, C),
{}
);
try {
new Function(`const epic = this;${p}`).bind({
...I,
getComponent: a,
find: a,
defineExpose: N,
publicMethods: I,
pluginManager: z
})();
} catch (C) {
D && console.error("[epic:自定义函数]异常:", C);
}
}
function N(p) {
p != null && (n.value = p);
}
function O(p, ...D) {
if (!p || p.length === 0) {
console.warn("未提供任何动作");
return;
}
p.forEach((I) => {
const C = I.args ? JSON.parse(I.args) : D;
switch (I.type) {
case "public":
t(I, C);
break;
case "custom":
x(I, C);
break;
case "component":
d(I, C);
break;
default:
console.warn(`未知的动作类型: ${I.type}`);
break;
}
});
}
function t(p, D) {
var I;
try {
(I = z.publicMethods[p.methodName]) == null || I.handler(...D);
} catch (C) {
console.error(`[Epic:公共函数(${p.methodName})]执行异常:`, C);
}
}
function x(p, D) {
var I, C;
try {
(C = (I = n.value)[p.methodName]) == null || C.call(I, ...D);
} catch (h) {
console.error(`[Epic:自定义函数(${p.methodName})]执行异常:`, h);
}
}
function d(p, D) {
const I = p.componentId != null && a(p.componentId);
if (!I) {
console.warn(`[Epic:组件${p.componentId}]未找到`);
return;
}
try {
I[p.methodName](...D);
} catch (C) {
console.error(`[Epic:组件${p.componentId}函数(${p.methodName})]执行异常:`, C);
}
}
function S(p = !0) {
r.value = p;
}
function y(p) {
const D = Qe(p, () => !0);
s.value = D.map((I) => I.id);
}
function E(p, D = "default") {
if (c[D]) {
const I = c[D];
ce(p, I);
}
c[D] = p;
}
function M(p, D = "default") {
if (c[D]) {
ce(c[D], p, !1);
return;
}
c[D] = p;
}
return {
componentInstances: e,
funcs: n,
isDesignMode: r,
defaultComponentIds: s,
forms: c,
addFormData: E,
setFormData: M,
getComponentInstance: a,
// 简化查询函数, 推荐使用
find: a,
addComponentInstance: w,
removeComponentInstance: g,
setMethods: m,
doActions: O,
setDesignMode: S,
setDefaultComponentIds: y
};
}
function ke() {
const e = V([]), n = V([]), r = V(null);
let s = 0;
function c(m, N = "插入组件") {
const O = Date.now();
s + 150 > O || (s = O, r.value != null && (e.value.push(r.value), n.value.splice(0, n.value.length)), r.value = {
type: N,
componentSchema: JSON.stringify(m)
}, e.value.length > 60 && e.value.unshift());
}
function a() {
if (e.value.length === 0)
return !1;
const m = e.value.pop();
return r.value != null && n.value.push(r.value), r.value = m, JSON.parse(m.componentSchema);
}
function w() {
if (n.value.length === 0)
return !1;
const m = n.value.pop();
return r.value != null && e.value.push(r.value), r.value = m, JSON.parse(m.componentSchema);
}
function g() {
e.value = [], n.value = [], r.value = null;
}
return {
recordList: e,
undoList: n,
currentRecord: r,
push: c,
undo: a,
redo: w,
reset: g
};
}
const je = /* @__PURE__ */ ie({
__name: "dynamicFormItem",
props: {
hasFormItem: { type: Boolean },
formItemProps: {}
},
emits: ["updateFormItemRef"],
setup(e, { emit: n }) {
const r = z.getComponent("form-item"), s = e, c = n, a = V(), w = () => {
c("updateFormItemRef", a.value);
};
return (g, m) => s.hasFormItem ? (H(), q(R(r), be({
key: 0,
ref_key: "formItemRef",
ref: a,
onVnodeMounted: w
}, s.formItemProps), {
default: T(() => [
K(g.$slots, "default")
]),
_: 3
}, 16, ["onVnodeMounted"])) : K(g.$slots, "default", { key: 1 });
}
}), et = /* @__PURE__ */ ie({
name: "ENode",
__name: "node",
props: {
componentSchema: {},
modelValue: {},
ruleField: {},
resetFormData: { type: Boolean },
name: {},
dynamicId: {},
sourceDateUrl: {},
id: {}
},
emits: ["update:modelValue", "change", "update:dynamicId"],
setup(e, { emit: n }) {
const { proxy: r } = fe(), s = e, c = V(null);
let a = oe("formData", ae({}));
const w = oe("slots", {}), g = oe("pageManager", {}), m = oe("disabled", { value: !1 }), N = oe("ruleFieldPrefix", null), O = oe("resetFormData", !1);
let t = ae(G(s.componentSchema));
S();
async function x(o) {
if (["cascader", "checkbox", "select", "radio"].includes(o.type) && o.componentProps.dynamicId && s.sourceDateUrl) {
const u = (await _e({
// || "http://192.168.28.205:3000/dev-api/data-source
url: s.sourceDateUrl,
method: "get",
params: {
id: o.componentProps.dynamicId
},
headers: {
Authorization: "Bearer " + pe.get("Admin-Token"),
lang: pe.get("saas-locale") || "zh-CN",
//语言
zone: Intl.DateTimeFormat().resolvedOptions().timeZone
//时区
}
})).data.data;
let _ = await _e({
url: u.url,
method: u.method,
data: u.body ? JSON.parse(u.body) : {},
params: u.params ? JSON.parse(u.params) : {},
headers: {
...JSON.parse(u.headers),
Authorization: "Bearer " + pe.get("Admin-Token"),
lang: pe.get("saas-locale") || "zh-CN",
//语言
zone: Intl.DateTimeFormat().resolvedOptions().timeZone
//时区
}
});
if (u && (u != null && u.dataPath)) {
const Q = u.dataPath.split(".").reduce((te, re) => te[re], _.data);
o.componentProps.options = d(Q, u.dataKey, u.dataValue);
} else
o.componentProps.options = d(_.data, u.dataKey, u.dataValue);
return o;
}
return o;
}
function d(o, l, $) {
return o && Object.prototype.toString.call(o) === "[object Array]" ? o.map((u) => u.children && u.children.length ? {
label: u[l],
value: u[$] + "",
children: d(u.children, l, $)
} : {
label: u[l],
value: u[$] + ""
}) : [];
}
B(
() => s.componentSchema,
(o) => {
Fe(t, o, ["children"]) || (ce(t, G(o)), S());
},
{
deep: !0
}
);
function S() {
g.isDesignMode.value && typeof t.field == "string" && (t.field += "-design-mode");
}
(s.resetFormData || O) && (a = {});
const y = n, E = V(), M = V(), p = (o) => {
M.value = o;
}, D = Re();
Object.keys(D).length && Z("nodeAttrs", D);
const I = Ue(null), C = W(() => {
var o, l;
return (o = t.componentProps) != null && o.hidden ? !1 : typeof t.show == "boolean" ? t.show : ((l = t.show) == null ? void 0 : l.call(t, { values: a })) ?? !0;
}), h = W(() => {
var u;
const o = C.value && ((u = t.rules) == null ? void 0 : u.map((_) => ({
..._,
validator: _.validator && g.funcs.value[_.validator]
// 自定义校验函数
})));
let l = t.field;
s.ruleField ? l = s.ruleField : N && t.field && (l = G(N), l.push(t.field));
const $ = {
...t,
rules: o,
rule: o,
field: l
};
return $.children && delete $.children, $;
}), U = W(() => {
var $, u, _, J, Q;
const o = (($ = L.value) == null ? void 0 : $.bindModel) ?? "modelValue", l = {};
return t.on && Object.keys(t.on).forEach((te) => {
l[`on${Ye(te)}`] = (...re) => g.doActions(t.on[te], ...re);
}), t.type === "selectpage" && (t.componentProps.defaultData = {
value: a[t.field],
label: a[a[t.field]]
}), console.log("%c [ ]-309", "font-size:13px; background:pink; color:#bf2c9f;", {
...s,
...t.componentProps,
sourceDateUrl: s.sourceDateUrl,
// 为了避免禁用对超链接输入框点击的影响
disabled: s.componentSchema.type === "input" && s.componentSchema.componentProps && ((u = s.componentSchema.componentProps) != null && u.isLink) ? !1 : (m == null ? void 0 : m.value) || ((_ = t.componentProps) == null ? void 0 : _.disabled),
bindModel: o,
...l
}), {
...s,
...t.componentProps,
sourceDateUrl: s.sourceDateUrl,
// 为了避免禁用对超链接输入框点击的影响
disabled: s.componentSchema.type === "input" && s.componentSchema.componentProps && ((J = s.componentSchema.componentProps) != null && J.isLink) ? !1 : (m == null ? void 0 : m.value) || ((Q = t.componentProps) == null ? void 0 : Q.disabled),
bindModel: o,
...l
};
}), L = W(() => z.getComponentConfingByType(t.type) ?? null);
he(() => {
c.value = s.modelValue ?? a[t.field ?? ""];
}), B(
() => c.value,
() => {
c.value !== (s.modelValue ?? a[t.field ?? ""]) && i(c.value);
}
), B(
() => E.value,
() => {
A();
},
{ immediate: !0 }
);
function A() {
var l;
const o = E.value || r;
t.id && o && ((t.input || t.type === "table" && t.field || t.type === "card" && t.field && t.multiple) && (o.setValue = i, o.getValue = () => a[t.field] || s.modelValue), o.setAttr = ($, u) => (t.componentProps || (t.componentProps = {}), t.componentProps[$] = u), o.getAttr = ($) => t.componentProps[$], g.addComponentInstance(t.id, o), (l = L.value) != null && l.defaultSchema.input && t.noFormItem !== !0 && M.value && g.addComponentInstance(t.id + "formItem", M.value));
}
function v() {
var o;
t.id && (g.removeComponentInstance(t.id), (o = L.value) != null && o.defaultSchema.input && t.noFormItem !== !0 && g.removeComponentInstance(t.id + "formItem"));
}
async function ee() {
var l, $, u;
if (t = await x(t), typeof ((l = t.componentProps) == null ? void 0 : l.defaultValue) < "u") {
const _ = g.isDesignMode.value ? ($ = t.componentProps) == null ? void 0 : $.defaultValue : a[t.field] ?? ((u = t.componentProps) == null ? void 0 : u.defaultValue);
i(G(_));
}
if (t.type === "slot") {
const _ = t.slotName;
if (!_) return;
I.value = ie({
setup() {
return () => K(w, _, {
componentSchema: t,
model: a
});
}
});
return;
}
const o = z.getComponent(t.type);
if (!o) {
console.error(`组件${t.type}未注册`);
return;
}
if (typeof o == "function") {
const _ = await o();
I.value = _.default ?? _;
} else
I.value = o;
}
function f(o) {
console.log("%c [ v ]-462", "font-size:13px; background:pink; color:#bf2c9f;", o), Object.prototype.toString.call(o) === "[object Array]" ? o.forEach((l) => {
a[l.value] = l.label;
}) : a[o.value] = o.label, s.id ? j.emit("updateformData" + s.id, a) : j.emit("updateformData", a);
}
function i(o) {
y("update:modelValue", o), y("change", o), t.field && (a[t.field] = o), s.id ? j.emit("updateformData" + s.id, a) : j.emit("updateformData", a);
}
function P(o) {
y("update:dynamicId", o);
}
let F = null;
return B(
() => t,
async (o) => {
const l = JSON.stringify({
...o,
children: void 0,
componentProps: {
...o.componentProps,
options: null
}
});
if (l === F)
return !1;
F = l, ee();
},
{
immediate: !0,
deep: !0
}
), $e(v), (o, l) => {
var u;
const $ = Te("ENode");
return I.value && C.value ? (H(), q(je, {
key: 0,
hasFormItem: R(t).noFormItem !== !0 && ((u = L.value) == null ? void 0 : u.defaultSchema.input),
formItemProps: h.value,
onUpdateFormItemRef: p
}, {
default: T(() => [
(H(), q(Be(I.value), be({
ref_key: "componentInstance",
ref: E,
onVnodeMounted: A,
model: R(a),
sourceDateUrl: s.sourceDateUrl
}, { ...U.value }, {
[U.value.bindModel]: c.value,
["onUpdate:" + U.value.bindModel]: l[0] || (l[0] = (_) => c.value = _),
[`onUpdate:${U.value.bindModel}` || ""]: i,
"onUpdate:modelValueLabel": f,
"onUpdate:dynamicId": P
}), {
node: T((_) => [
Y($, be({
id: s.id
}, _, {
sourceDateUrl: s.sourceDateUrl
}), null, 16, ["id", "sourceDateUrl"])
]),
"edit-node": T(() => [
K(o.$slots, "edit-node")
]),
_: 3
}, 16, ["model", "sourceDateUrl"]))
]),
_: 3
}, 8, ["hasFormItem", "formItemProps"])) : Ne("", !0);
};
}
});
function tt() {
const e = V(!1), n = Ve(), r = V({});
function s() {
return new Promise((d) => {
if (e.value)
d();
else {
const S = B(e, () => {
S(), d();
});
}
});
}
async function c(d = "default") {
var y;
await s();
const S = (y = r.value) == null ? void 0 : y[d];
if (!S) throw new Error(`表单 [name=${d}] 不存在`);
return S;
}
async function a(d, S) {
const y = await c(d);
return G(await S(y));
}
async function w(d = "default") {
return await a(d, (S) => S.getData());
}
function g(d, S = "default", y = void 0) {
var E, M;
if (y && Object.keys(y).length) {
let p = function(h) {
let U = [];
return h.forEach((L) => {
L.children && (U = [...U, ...p(L.children)]), U.push(L);
}), U;
}, I = function(h) {
var L;
let U = p((L = y == null ? void 0 : y.schemas[0]) == null ? void 0 : L.children);
return Object.keys(h).forEach((A) => {
var f, i, P, F, o, l, $;
const v = U.find((u) => u.field === A), ee = ["datetimerange", "daterange", "monthrange", "dates"];
if ((v && (v == null ? void 0 : v.type) === "checkbox" || (v == null ? void 0 : v.type) === "select" && ((f = v == null ? void 0 : v.componentProps) != null && f.multiple) || (v == null ? void 0 : v.type) === "cascader" && !((P = (i = v == null ? void 0 : v.componentProps) == null ? void 0 : i.props) != null && P.multiple) || (v == null ? void 0 : v.type) === "date" && ee.includes((F = v == null ? void 0 : v.componentProps) == null ? void 0 : F.type)) && typeof h[A] == "string")
h[A] = (o = h[A]) == null ? void 0 : o.split(",");
else if ((v == null ? void 0 : v.type) === "cascader" && (($ = (l = v == null ? void 0 : v.componentProps) == null ? void 0 : l.props) != null && $.multiple) && typeof h[A] == "string")
h[A].indexOf(";") === -1 && h[A].indexOf(";") === -1 ? h[A][h[A]] : h[A].indexOf(";") > -1 ? h[A] = h[A].split(";").map((u) => u.split(",")) : h[A].indexOf(";") === -1 ? h[A] = h[A].split(",") : h[A].indexOf(";") > -1 ? h[A] = h[A].split(";").map((u) => u.split(",")) : h[A].indexOf(";") === -1 && (h[A] = h[A].split(","));
else if (((v == null ? void 0 : v.type) === "upload-image" || (v == null ? void 0 : v.type) === "upload-file") && typeof h[A] == "string") {
let u = [];
Object.entries(h).forEach(([_, J]) => {
h[A] === J && _ !== v.field && _.indexOf("@") > -1 && _.indexOf(A) > -1 && (u = _.split("@")[1].split(","));
}), h[A] = h[A].split(",").map((_, J) => ({
url: _,
name: u[J] || _
}));
} else (v == null ? void 0 : v.type) === "number" || (v == null ? void 0 : v.type) === "slider" ? h[A] = Number(h[A]) : (v == null ? void 0 : v.type) === "switch" && (h[A] = typeof h[A] == "boolean" ? h[A] : h[A].indexOf("true") > -1);
}), h;
}(d);
n.setFormData(I, S);
const C = (E = r.value) == null ? void 0 : E[S];
C == null || C.clearValidate();
} else {
n.setFormData(d, S);
const p = (M = r.value) == null ? void 0 : M[S];
p == null || p.clearValidate();
}
}
async function m(d = "default") {
return await a(d, async (S) => (await S.validate(), await S.getData()));
}
async function N(d) {
await s();
const S = {};
for (const y in r.value) {
const E = r.value[y];
E && (S[y] = G(await d(E)));
}
return S;
}
async function O() {
return await N((d) => d.getData());
}
function t(d) {
for (const S in d)
g(d[S], S);
}
async function x() {
return await N(async (d) => (await d.validate(), await d.getData()));
}
return {
ready: e,
pageManager: n,
forms: r,
getData: w,
setData: g,
validate: m,
getForms: O,
setForms: t,
validateAll: x,
getFormInstance: c
};
}
const nt = {
key: 0,
class: "epic-loading-box"
}, ot = { class: "epic-builder-main" }, st = { class: "epic-loading-box" }, rt = /* @__PURE__ */ ie({
__name: "builder",
props: {
pageSchema: {},
formData: {},
disabled: { type: Boolean },
sourceDateUrl: {},
id: {}
},
emits: ["change", "ready"],
setup(e, { expose: n, emit: r }) {
const s = le(() => import("./index-DgcFxYFp.js")), c = r, a = V([]), w = V({}), { ready: g, pageManager: m, forms: N, getData: O, setData: t, validate: x, getForms: d, setForms: S, validateAll: y, getFormInstance: E } = tt(), M = e, p = ae({
schemas: []
});
B(
() => M.pageSchema,
(f) => {
ce(p, f);
},
{
immediate: !0,
deep: !0
}
), B(
() => M.formData,
(f) => {
if (f) {
let i = L(f);
w.value = i, t(i);
}
},
{
immediate: !0,
deep: !0
}
);
function D(f) {
let i = [];
return f.forEach((P) => {
P.children && (i = [...i, ...D(P.children)]), i.push(P);
}), i;
}
function I(f, i) {
function P(o) {
return JSON.parse(JSON.stringify(o));
}
function F(o, l) {
if (o.type === "card" && o.multiple && o.field && Array.isArray(l[o.field]))
return l[o.field].map((u) => {
var J;
const _ = P({ ...o, multiple: !0 });
return _.children = (J = _.children) == null ? void 0 : J.map((Q) => F(Q, u)).flat(), _;
});
const $ = P(o);
return Array.isArray($.children) && ($.children = $.children.map((u) => F(u, l)).flat()), $;
}
return f.map((o) => F(o, i)).flat();
}
function C(f, i = "", P = { root: 0 }) {
const F = i || "root";
return i || (P.root = 0), P[F] === void 0 && (P[F] = 0), f.map((o) => {
o.field && (o.oldField = JSON.parse(JSON.stringify(o.field)));
const l = { ...o };
if (o.type === "card") {
const $ = o.field || "";
o.multiple ? (l.field = i ? `${i}.${$}[${P[F]}]` : `${$}[${P[F]}]`, P[F]++) : o.field && i && (l.field = `${i}.${$}`);
const u = l.field || i;
P[u] = 0;
} else o.field && i && (l.field = `${i}.${o.field}`);
return o.children && (l.children = C(o.children, l.field || i, P)), l;
});
}
function h(f, i, P = "", F = {}) {
const o = P || "root";
return F[o] === void 0 && (F[o] = 0), f.forEach((l) => {
const $ = l.field || "";
let u = P ? `${P}.${$}` : `${$}`;
l.type === "card" && l.multiple ? (typeof i[u][`${F[o]}`] == "object" ? Object.keys(i[u][`${F[o]}`]).forEach((_) => {
i[`${u}[${F[o]}].${_}`] = i[u][`${F[o]}`][_];
}) : i[`${u}[${F[o]}]`] = i[u][`${F[o]}`], l.children && (l.children = h(
l.children,
i,
`${u}[${F[o]}]` || P,
F
)), F[o]++) : l.children && (l.children = h(l.children, i, P, F));
}), F[o] = 0, i;
}
function U(f, i, P) {
let F = h(G(f), G(i));
return {
obj: C(f),
dataObj: F
};
}
function L(f) {
let i = D(M.pageSchema.schemas[0].children);
a.value = i.filter((l) => l.type === "card" && l.multiple);
const P = I(M.pageSchema.schemas[0].children, f);
let { obj: F, dataObj: o } = U(P, f, a.value);
return f = o, M.pageSchema.schemas[0].children = F, Object.keys(f).forEach((l) => {
var $, u, _, J, Q, te, re;
if (l.indexOf("@") < 0) {
const b = i.find((X) => X.field === l), Me = ["datetimerange", "daterange", "monthrange", "dates"];
if ((b && (b == null ? void 0 : b.type) === "checkbox" || (b == null ? void 0 : b.type) === "select" && (($ = b == null ? void 0 : b.componentProps) != null && $.multiple) || (b == null ? void 0 : b.type) === "cascader" && !((_ = (u = b == null ? void 0 : b.componentProps) == null ? void 0 : u.props) != null && _.multiple) || (b == null ? void 0 : b.type) === "date" && Me.includes((J = b == null ? void 0 : b.componentProps) == null ? void 0 : J.type)) && typeof f[l] == "string")
f[l] = (Q = f[l]) == null ? void 0 : Q.split(",");
else if ((b == null ? void 0 : b.type) === "cascader" && ((re = (te = b == null ? void 0 : b.componentProps) == null ? void 0 : te.props) != null && re.multiple) && typeof f[l] == "string")
f[l].indexOf(";") > -1 ? f[l] = f[l].split(";").map((X) => X.split(",")) : f[l] = f[l].split(","), f[l].indexOf(";") > -1 ? f[l] = f[l].split(";").map((X) => X.split(",")) : f[l] = f[l].split(",");
else if (((b == null ? void 0 : b.type) === "upload-image" || (b == null ? void 0 : b.type) === "upload-file") && typeof f[l] == "string") {
let X = [];
Object.entries(f).forEach(([ne, ye]) => {
f[l] === ye && ne !== b.field && ne.indexOf("@") > -1 && ne.indexOf(l) > -1 && (X = ne.split("@")[1].split(","));
}), f[l] = f[l].split(",").map((ne, ye) => ({
url: ne,
name: X[ye] || ne
}));
} else (b == null ? void 0 : b.type) === "number" || (b == null ? void 0 : b.type) === "slider" ? f[l] = Number(f[l]) : (b == null ? void 0 : b.type) === "switch" && (f[l] = typeof f[l] == "boolean" ? f[l] : f[l].indexOf("true") > -1);
}
}), f;
}
B(
() => p.script,
(f) => {
f && m.setMethods(f, !0);
},
{
immediate: !0
}
), Z("slots", Le()), Z("pageManager", m), Z("forms", N), Z("pageSchema", p), Z(
"disabled",
W(() => M.disabled)
);
const A = fe(), v = A == null ? void 0 : A.proxy;
function ee() {
de(() => {
g.value = !0, c("ready", m), v && m.addComponentInstance("builder", v);
});
}
return j.on("updateformData" + (M.id ? M.id : ""), (f) => {
c("change", f);
}), n({
ready: g,
pageManager: m,
getData: O,
setData: t,
validate: x,
getForms: d,
setForms: S,
validateAll: y,
getFormInstance: E
}), (f, i) => R(z).initialized.value ? (H(), q(Pe, {
key: 1,
onResolve: ee
}, {
default: T(() => [
k("div", ot, [
(H(!0), Ee(Je, null, ze(p.schemas, (P, F) => (H(), q(R(et), {
id: M.id,
key: F,
sourceDateUrl: M.sourceDateUrl,
componentSchema: P
}, null, 8, ["id", "sourceDateUrl", "componentSchema"]))), 128))
])
]),
fallback: T(() => [
k("div", st, [
Y(R(s))
])
]),
_: 1
})) : (H(), Ee("div", nt));
}
});
function xe(e) {
return Ze() ? (We(e), !0) : !1;
}
function lt(e) {
let n = 0, r, s;
const c = () => {
n -= 1, s && n <= 0 && (s.stop(), r = void 0, s = void 0);
};
return (...a) => (n += 1, s || (s = He(!0), r = s.run(() => e(...a))), xe(c), r);
}
function ue(e) {
return typeof e == "function" ? e() : R(e);
}
const at = typeof window < "u" && typeof document < "u";
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const it = (e) => typeof e < "u", ct = Object.prototype.toString, ut = (e) => ct.call(e) === "[object Object]", dt = () => {
};
function ft(e) {
return fe();
}
function pt(e, n = !0, r) {
ft() ? Ae(e, r) : n ? e() : de(e);
}
function mt(e = !1, n = {}) {
const {
truthyValue: r = !0,
falsyValue: s = !1
} = n, c = Ke(e), a = V(e);
function w(g) {
if (arguments.length)
return a.value = g, a.value;
{
const m = ue(r);
return a.value = a.value === m ? ue(s) : m, a.value;
}
}
return c ? w : [a, w];
}
function Jt(e, n, r) {
const s = B(e, (...c) => (de(() => s()), n(...c)), r);
return s;
}
const ve = at ? window : void 0;
function se(e) {
var n;
const r = ue(e);
return (n = r == null ? void 0 : r.$el) != null ? n : r;
}
function ht(...e) {
let n, r, s, c;
if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([r, s, c] = e, n = ve) : [n, r, s, c] = e, !n)
return dt;
Array.isArray(r) || (r = [r]), Array.isArray(s) || (s = [s]);
const a = [], w = () => {
a.forEach((O) => O()), a.length = 0;
}, g = (O, t, x, d) => (O.addEventListener(t, x, d), () => O.removeEventListener(t, x, d)), m = B(
() => [se(n), ue(c)],
([O, t]) => {
if (w(), !O)
return;
const x = ut(t) ? { ...t } : t;
a.push(
...r.flatMap((d) => s.map((S) => g(O, d, S, x)))
);
},
{ immediate: !0, flush: "post" }
), N = () => {
m(), w();
};
return xe(N), N;
}
function vt(e) {
return typeof e == "function" ? e : typeof e == "string" ? (n) => n.key === e : Array.isArray(e) ? (n) => e.includes(n.key) : () => !0;
}
function Ce(...e) {
let n, r, s = {};
e.length === 3 ? (n = e[0], r = e[1], s = e[2]) : e.length === 2 ? typeof e[1] == "object" ? (n = !0, r = e[0], s = e[1]) : (n = e[0], r = e[1]) : (n = !0, r = e[0]);
const {
target: c = ve,
eventName: a = "keydown",
passive: w = !1,
dedupe: g = !1
} = s, m = vt(n);
return ht(c, a, (O) => {
O.repeat && ue(g) || m(O) && r(O);
}, w);
}
function we(e, n, r = {}) {
return Ce(e, n, { ...r, eventName: "keydown" });
}
function Se(e, n, r = {}) {
return Ce(e, n, { ...r, eventName: "keyup" });
}
function gt() {
const e = V(!1), n = fe();
return n && Ae(() => {
e.value = !0;
}, n), e;
}
function yt(e) {
const n = gt();
return W(() => (n.value, !!e()));
}
function wt(e) {
return JSON.parse(JSON.stringify(e));
}
function St(e, n, r = {}) {
const { window: s = ve, ...c } = r;
let a;
const w = yt(() => s && "ResizeObserver" in s), g = () => {
a && (a.disconnect(), a = void 0);
}, m = W(() => {
const t = ue(e);
return Array.isArray(t) ? t.map((x) => se(x)) : [se(t)];
}), N = B(
m,
(t) => {
if (g(), w.value && s) {
a = new ResizeObserver(n);
for (const x of t)
x && a.observe(x, c);
}
},
{ immediate: !0, flush: "post" }
), O = () => {
g(), N();
};
return xe(O), {
isSupported: w,
stop: O
};
}
function zt(e, n = { width: 0, height: 0 }, r = {}) {
const { window: s = ve, box: c = "content-box" } = r, a = W(() => {
var t, x;
return (x = (t = se(e)) == null ? void 0 : t.namespaceURI) == null ? void 0 : x.includes("svg");
}), w = V(n.width), g = V(n.height), { stop: m } = St(
e,
([t]) => {
const x = c === "border-box" ? t.borderBoxSize : c === "content-box" ? t.contentBoxSize : t.devicePixelContentBoxSize;
if (s && a.value) {
const d = se(e);
if (d) {
const S = d.getBoundingClientRect();
w.value = S.width, g.value = S.height;
}
} else if (x) {
const d = Array.isArray(x) ? x : [x];
w.value = d.reduce((S, { inlineSize: y }) => S + y, 0), g.value = d.reduce((S, { blockSize: y }) => S + y, 0);
} else
w.value = t.contentRect.width, g.value = t.contentRect.height;
},
r
);
pt(() => {
const t = se(e);
t && (w.value = "offsetWidth" in t ? t.offsetWidth : n.width, g.value = "offsetHeight" in t ? t.offsetHeight : n.height);
});
const N = B(
() => se(e),
(t) => {
w.value = t ? n.width : 0, g.value = t ? n.height : 0;
}
);
function O() {
m(), N();
}
return {
width: w,
height: g,
stop: O
};
}
function Ht(e, n, r, s = {}) {
var c, a, w;
const {
clone: g = !1,
passive: m = !1,
eventName: N,
deep: O = !1,
defaultValue: t,
shouldEmit: x
} = s, d = fe(), S = r || (d == null ? void 0 : d.emit) || ((c = d == null ? void 0 : d.$emit) == null ? void 0 : c.bind(d)) || ((w = (a = d == null ? void 0 : d.proxy) == null ? void 0 : a.$emit) == null ? void 0 : w.bind(d == null ? void 0 : d.proxy));
let y = N;
n || (n = "modelValue"), y = y || `update:${n.toString()}`;
const E = (D) => g ? typeof g == "function" ? g(D) : wt(D) : D, M = () => it(e[n]) ? E(e[n]) : t, p = (D) => {
x ? x(D) && S(y, D) : S(y, D);
};
if (m) {
const D = M(), I = V(D);
let C = !1;
return B(
() => e[n],
(h) => {
C || (C = !0, I.value = E(h), de(() => C = !1));
}
), B(
I,
(h) => {
!C && (h !== e[n] || O) && p(h);
},
{ deep: O }
), I;
} else
return W({
get() {
return M();
},
set(D) {
p(D);
}
});
}
function Kt() {
const { isDark: e } = ge(), n = mt(e);
return {
isDark: e,
toggleDark: n
};
}
function Dt() {
const e = V(!1);
return Ae(() => {
bt(e), Et(e);
}), B(
() => e.value,
() => {
e.value ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark");
}
), {
isDark: e
};
}
function bt(e) {
var n = document.documentElement;
n && (n.classList.contains("dark") ? e.value = !0 : e.value = !1);
}
function Et(e) {
var n = document.querySelector("html"), r = new MutationObserver(function(s) {
for (var c of s)
if (c.type === "attributes" && c.attributeName === "class") {
const a = c.target;
new Array(...a.classList).includes("dark") ? e.value = !0 : e.value = !1;
}
});
r.observe(n, {
attributes: !0,
attributeFilter: ["class"]
}), $e(() => {
r.disconnect();
});
}
function At() {
const e = V(1), n = V(!1), { isDark: r } = Dt(), { pressSpace: s, pressShift: c, pressCtrl: a } = Ot();
return {
canvasScale: e,
pressSpace: s,
pressShift: c,
pressCtrl: a,
disabledZoom: n,
isDark: r
};
}
const ge = lt(At);
function Ot() {
const e = V(!1), n = V(!1), r = V(!1);
return we(" ", () => {
e.value = !0;
}), Se(" ", () => {
e.value = !1;
}), we("Shift", (s) => {
s.preventDefault(), n.value = !0;
}), Se("Shift", () => {
n.value = !1;
}), we("Control", (s) => {
s.preventDefault(), r.value = !0;
}), Se("Control", () => {
r.value = !1;
}), { pressSpace: e, pressShift: n, pressCtrl: r };
}
function Zt(e) {
const { pressSpace: n } = ge(), r = new Image(1, 1);
r.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
let s = 0, c = 0;
function a(m) {
var N;
n.value && (s = m.x, c = m.y, (N = m.dataTransfer) == null || N.setDragImage(document.createElement("div"), 0, 0));
}
function w(m) {
if (m.preventDefault(), !m.x || !m.y || !n.value)
return;
const N = m.x - s, O = m.y - c;
s = m.x, c = m.y, e.value && (e.value.scrollTop -= O, e.value.scrollLeft -= N);
}
function g() {
n.value = !1;
}
return { handleElementDragStart: a, handleElementDrag: w, handleElementDragEnd: g };
}
function Wt(e) {
const { pressCtrl: n, canvasScale: r, disabledZoom: s } = ge();
function c(a) {
if (!n.value || s.value)
return;
a.preventDefault();
let w = 0;
a.deltaY < 0 ? w = r.value + 0.05 : w = r.value - 0.05, !(w > 150 || w < 0.5) && (r.value = w);
}
return B(
() => r.value,
(a) => {
e.value && !s.value && (e.value.style.transform = `scale(${a})`);
}
), { handleZoom: c, canvasScale: r };
}
function Gt(e, n = 16.66) {
let r;
function s() {
c(), r = window.setInterval(e, n);
}
function c() {
window.clearInterval(r);
}
return {
startTimedQuery: s,
stopTimedQuery: c
};
}
const xt = { class: "min-w-750px rounded" }, It = { class: "h-full rounded" }, _t = /* @__PURE__ */ ie({
__name: "index",
setup(e, { expose: n }) {
const r = z.getComponent("monacoEditor"), s = z.getComponent("modal"), c = V(null), a = V(!1), w = V(!1), g = V({}), m = oe("pageSchema"), N = V(null), O = V("");
function t() {
w.value = !1;
}
function x() {
a.value = !1;
}
function d() {
a.value = !0, O.value = qe();
}
async function S() {
try {
let y = await N.value.validateAll();
if (!Object.keys(y).length) {
alert("请添加表单组件后再尝试!");
return;
}
Object.keys(y).length === 1 && (y = y.default), g.value = JSON.stringify(y, null, 2), de(() => {
var E;
(E = c.value) == null || E.setValue(g.value);
}), w.value = !0;
} catch (y) {
console.error(y);
}
}
return n({
handleOpen: d
}), (y, E) => (H(), q(R(s), {
modelValue: a.value,
"onUpdate:modelValue": E[1] || (E[1] = (M) => a.value = M),
title: "预览",
class: "w-900px",
width: "900px",
onClose: x,
onOk: S,
okText: "表单数据"
}, {
default: T(() => [
k("div", xt, [
(H(), q(R(rt), {
key: O.value,
ref_key: "kb",
ref: N,
"page-schema": R(m)
}, null, 8, ["page-schema"])),
Y(R(s), {
modelValue: w.value,
"onUpdate:modelValue": E[0] || (E[0] = (M) => w.value = M),
title: "表单数据",
class: "w-860px",
width: "860px",
onClose: t,
onOk: t
}, {
default: T(() => [
k("div", It, [
Y(R(r), {
ref_key: "monacoEditorRef",
ref: c,
autoToggleTheme: "",
readOnly: "",
class: "h-full editor",
"model-value": g.value
}, null, 8, ["model-value"])
])
]),
_: 1
}, 8, ["modelValue"])
])
]),
_: 1
}, 8, ["modelValue"]));
}
}), $t = {
key: 0,
class: "epic-loading-box"
}, Nt = { class: "epic-designer-main" }, Pt = { class: "epic-header-container" }, Ft = { class: "epic-loading-box" }, Qt = /* @__PURE__ */ ie({
__name: "designer",
props: {
disabledZoom: { type: Boolean, default: !1 },
hiddenHeader: { type: Boolean, default: !1 },
lockDefaultSchemaEdit: { type: Boolean, default: !1 },
formMode: { type: Boolean, default: !1 },
title: { default: "EpicDesigner默认项目" },
defaultSchema: {},
sourceCodeReadOnly: { type: Boolean },
source: { default: [] },
updateSourceId: {}
},
emits: [
"ready",
"save",
"reset",
"toggleDeviceMode",
"saveSourceData",
"deleteSourceData",
"updateSourceData"
],
setup(e, { expose: n, emit: r }) {
const { t: s } = Oe(), c = le(() => import("./index-IGxCNti8.js")), a = le(() => import("./index-WkZdU_zw.js")), w = le(() => import("./index-gdly69qM.js")), g = le(() => import("./index-Cln9MN7u.js")), m = le(() => import("./index-DgcFxYFp.js")), N = Ve(), O = ke(), t = e;
let x = {
schemas: [
{
type: "form",
id: "root",
label: s("page"),
children: [],
componentProps: {
name: s("form"),
style: {
padding: "16px"
}
}
}
// {
// type: "form",
// id: "root",
// label: "表单",
// children: [],
// componentProps: {
// style: {
// margin: "0px",
// },
// name: "default",
// labelWidth: "100px",
// labelLayout: "fixed",
// labelCol: {
// span: 5,
// },
// wrapperCol: {
// span: 19,
// },
// },
// },
],
script: `const { defineExpose, find } = epic;
function test (){
console.log('test')
}
// 通过defineExpose暴露的函数或者属性
defineExpose({
test
})`
};
he(() => {
if (t.defaultSchema) {
x = t.defaultSchema;
return;
}
t.source && z.setSourceData(t.source), t.formMode && (x.schemas = z.formSchemas);
}), N.setDesignMode(), N.setDefaultComponentIds(x.schemas);
const d = r, S = V(null), y = ae({
checkedNode: null,
hoverNode: null,
disableHover: !1,
matched: []
}), E = ae({
schemas: [],
script: x.script
}), { disabledZoom: M } = ge();
he(() => {
M.value = t.disabledZoom;
}), he(() => {
const i = E.script;
i && i !== "" && N.setMethods(i);
}), Z("pageSchema", E), Z("revoke", O), Z("pageManager", N), Z(
"designerProps",
W(() => t)
), Z("designer", {
setCheckedNode: D,
setHoverNode: I,
setDisableHover: h,
handleToggleDeviceMode: ee,
reset: A,
state: y
}), j.on("saveSourceData", (i) => {
d("saveSourceData", i);
}), j.on("deleteSourceData", (i) => {
d("deleteSourceData", i);
}), j.on("updateSourceData", (i) => {
d("updateSourceData", i);
});
function p() {
E.schemas = G(x.schemas), D(E.schemas[0]), O.push(E.schemas, "初始化撤销功能");
}
async function D(i = E.schemas[0]) {
y.checkedNode = i, y.matched = Xe(E.schemas, i.id);
}
async function I(i = null) {
var P;
if (!i || y.disableHover)
return y.hoverNode = null, !1;
if ((i == null ? void 0 : i.id) === ((P = y.hoverNode) == null ? void 0 : P.id))
return !1;
y.hoverNode = i;
}
function C() {
de(() => {
d("ready", { pageManager: N });
});
}
async function h(i = !1) {
y.disableHover = i;
}
function U(i) {
ce(E, G(i));
}
function L() {
return Ie(E);
}
function A() {
Fe(E.schemas, x.schemas) && E.script === x.script || (ce(E.schemas, x.schemas), E.script = x.script, D(E.schemas[0]), O.push(E.schemas, "重置操作"), d("reset", E));
}
function v() {
d("save", Ie(E));
}
function ee(i) {
d("toggleDeviceMode", i);
}
function f() {
S.value.handleOpen();
}
return p(), n({
revoke: O,
setData: U,
getData: L,
reset: A,
preview: f
}), (i, P) => R(z).initialized.value ? (H(), q(Pe, {
key: 1,
onResolve: C
}, {
default: T(() => [
k("div", Nt, [
k("div", Pt, [
K(i.$slots, "header", {}, () => [
t.hiddenHeader ? Ne("", !0) : (H(), q(R(c), {
key: 0,
onPreview: f,
onSave: v
}, {
header: T(() => [
K(i.$slots, "header-prefix")
]),
prefix: T(() => [
K(i.$slots, "header-prefix")
]),
title: T(() => [
K(i.$slots, "header-title")
]),
"right-prefix": T(() => [
K(i.$slots, "header-right-prefix")
]),
"right-action": T(() => [
K(i.$slots, "header-right-action")
]),
"right-suffix": T(() => [
K(i.$slots, "header-right-suffix")
]),
_: 3
}))
])
]),
k("div", {
class: Ge(["epic-split-view-container", { "hidden-header": i.hiddenHeader }])
}, [
Y(R(a)),
Y(R(w)),
Y(R(g))
], 2),
Y(_t, {
ref_key: "previewRef",
ref: S
}, null, 512)
])
]),
fallback: T(() => [
k("div", Ft, [
Y(R(m))
])
]),
_: 3
})) : (H(), Ee("div", $t));
}
}), Vt = {
component: async () => await import("./index-BLP-aOxR.js"),
defaultSchema: {
label: "代码编辑器",
type: "monacoEditor",
field: "monacoEditor",
icon: "epic-icon-write",
input: !0
},
config: {
attribute: [
{
label: "字段名",
type: "input",
field: "field"
},
{
label: "标题",
type: "input",
field: "label"
},
{
label: "默认值",
type: "monacoEditor",
field: "componentProps.defaultValue"
}
]
},
bindModel: "model-value"
}, { t: De } = Oe(), Ct = {
component: async () => await import("./index-DiDIFoTk.js"),
defaultSchema: {
label: De("page"),
type: "page",
componentProps: {},
children: []
},
config: {
attribute: [
{
label: De("pageName"),
type: "input",
componentProps: {
placeholder: De("pleaseEnter")
},
field: "componentProps.name"
}
]
}
}, { t: me } = Oe();
function Mt(e) {
e.component("EInputSize", async () => await import("./index-Cx7gKpkD.js")), e.component("EColEditor", async () => await import("./index-CpTA2IRB.js")), e.component("EActionEditor", async () => await import("./index-CvD6bD_0.js")), e.component("ERuleEditor", async () => await import("./index-arLwKBPE.js")), e.component("EOptionsEditor", async () => await import("./index-UJyLHIXT.js")), e.component("ENode", async () => await import("./index-DSujK9zM.js")), e.component("EDataSource", async () => await import("./index-B0OgKtuT.js")), e.component("EColumnEditor", async () => await import("./index-D-EiABAK.js")), e.component("PaddingMarginControl", async () => await import("./index-CdnV7DS4.js")), e.component("ESourceDataSelect", async () => await import("./index-DjPTgDpJ.js")), e.registerActivitybar({
id: "component_view",
title: me("component"),
icon: "icon--epic--extension-outline",
component: async () => await import("./index-CraRg8wh.js")
}), e.registerActivitybar({
id: "outline_view",
title: me("outline"),
icon: "icon--epic--account-tree-outline-rounded",
component: async () => await import("./outline-Ch5PHy3c.js")
}), e.registerRightSidebar({
id: "attribute_view",
title: me("attribute"),
component: async () => await import("./attributeView-BqtDAlQn.js")
}), e.registerRightSidebar({
id: "style_view",
title: me("style"),
component: async () => await import("./styleView-DWhRTeHv.js")
}), e.registerRightSidebar({
id: "event_view",
title: "事件",
component: async () => await import("./eventView-C2wKhfU_.js")
}), [Vt, Ct].forEach((r) => {
e.registerComponent(r);
});
}
Mt(z);
export {
et as _,
Gt as a,
St as b,
Zt as c,
zt as d,
Wt as e,
Lt as f,
Ht as g,
Kt as h,
rt as i,
Qt as j,
Ve as k,
ke as l,
Ot as m,
Dt as n,
bt as o,
At as p,
ge as u,
Jt as w
};