UNPKG

epic-designer-gold

Version:

基于vue3的设计器,可视化开发页面表单

1,428 lines (1,425 loc) 44.1 kB
import { ref as C, reactive as re, defineComponent as le, openBlock as H, createBlock as Y, unref as R, mergeProps as be, withCtx as T, renderSlot as K, getCurrentInstance as ue, inject as te, 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 Q, createCommentVNode as Ne, useSlots as Le, createElementBlock as Ee, Suspense as Fe, createElementVNode as X, Fragment as Je, renderList as ze, nextTick as ce, 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 J, f as Qe, d as ae, a as G, b as Ve, c as Ye, E as k, l as se, 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 s = null; return (...r) => { s && clearTimeout(s), s = setTimeout(() => { e(...r); }, n); }; } function Ce() { const e = C({}), n = C({}), s = C(!1), r = C([]), c = re({}); function i(p) { return e.value[p]; } function w(p, D) { e.value[p] = D; } function g(p) { delete e.value[p]; } function h(p, D = !1) { const I = Object.entries(J.publicMethods).reduce( (M, [m, U]) => (M[m] = U.handler, M), {} ); try { new Function(`const epic = this;${p}`).bind({ ...I, getComponent: i, find: i, defineExpose: N, publicMethods: I, pluginManager: J })(); } catch (M) { D && console.error("[epic:自定义函数]异常:", M); } } function N(p) { p != null && (n.value = p); } function O(p, ...D) { if (!p || p.length === 0) { console.warn("未提供任何动作"); return; } p.forEach((I) => { const M = I.args ? JSON.parse(I.args) : D; switch (I.type) { case "public": t(I, M); break; case "custom": x(I, M); break; case "component": d(I, M); break; default: console.warn(`未知的动作类型: ${I.type}`); break; } }); } function t(p, D) { var I; try { (I = J.publicMethods[p.methodName]) == null || I.handler(...D); } catch (M) { console.error(`[Epic:公共函数(${p.methodName})]执行异常:`, M); } } function x(p, D) { var I, M; try { (M = (I = n.value)[p.methodName]) == null || M.call(I, ...D); } catch (m) { console.error(`[Epic:自定义函数(${p.methodName})]执行异常:`, m); } } function d(p, D) { const I = p.componentId != null && i(p.componentId); if (!I) { console.warn(`[Epic:组件${p.componentId}]未找到`); return; } try { I[p.methodName](...D); } catch (M) { console.error(`[Epic:组件${p.componentId}函数(${p.methodName})]执行异常:`, M); } } function S(p = !0) { s.value = p; } function y(p) { const D = Qe(p, () => !0); r.value = D.map((I) => I.id); } function E(p, D = "default") { if (c[D]) { const I = c[D]; ae(p, I); } c[D] = p; } function P(p, D = "default") { if (c[D]) { ae(c[D], p, !1); return; } c[D] = p; } return { componentInstances: e, funcs: n, isDesignMode: s, defaultComponentIds: r, forms: c, addFormData: E, setFormData: P, getComponentInstance: i, // 简化查询函数, 推荐使用 find: i, addComponentInstance: w, removeComponentInstance: g, setMethods: h, doActions: O, setDesignMode: S, setDefaultComponentIds: y }; } function ke() { const e = C([]), n = C([]), s = C(null); let r = 0; function c(h, N = "插入组件") { const O = Date.now(); r + 150 > O || (r = O, s.value != null && (e.value.push(s.value), n.value.splice(0, n.value.length)), s.value = { type: N, componentSchema: JSON.stringify(h) }, e.value.length > 60 && e.value.unshift()); } function i() { if (e.value.length === 0) return !1; const h = e.value.pop(); return s.value != null && n.value.push(s.value), s.value = h, JSON.parse(h.componentSchema); } function w() { if (n.value.length === 0) return !1; const h = n.value.pop(); return s.value != null && e.value.push(s.value), s.value = h, JSON.parse(h.componentSchema); } function g() { e.value = [], n.value = [], s.value = null; } return { recordList: e, undoList: n, currentRecord: s, push: c, undo: i, redo: w, reset: g }; } const je = /* @__PURE__ */ le({ __name: "dynamicFormItem", props: { hasFormItem: { type: Boolean }, formItemProps: {} }, emits: ["updateFormItemRef"], setup(e, { emit: n }) { const s = J.getComponent("form-item"), r = e, c = n, i = C(), w = () => { c("updateFormItemRef", i.value); }; return (g, h) => r.hasFormItem ? (H(), Y(R(s), be({ key: 0, ref_key: "formItemRef", ref: i, onVnodeMounted: w }, r.formItemProps), { default: T(() => [ K(g.$slots, "default") ]), _: 3 }, 16, ["onVnodeMounted"])) : K(g.$slots, "default", { key: 1 }); } }), et = /* @__PURE__ */ le({ 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: s } = ue(), r = e, c = C(null); let i = te("formData", re({})); const w = te("slots", {}), g = te("pageManager", {}), h = te("disabled", { value: !1 }), N = te("ruleFieldPrefix", null), O = te("resetFormData", !1); let t = re(G(r.componentSchema)); S(); async function x(o) { if (["cascader", "checkbox", "select", "radio"].includes(o.type) && o.componentProps.dynamicId && r.sourceDateUrl) { const u = (await _e({ // || "http://192.168.28.205:3000/dev-api/data-source url: r.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 oe = u.dataPath.split(".").reduce((de, fe) => de[fe], _.data); o.componentProps.options = d(oe, 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( () => r.componentSchema, (o) => { Ve(t, o, ["children"]) || (ae(t, G(o)), S()); }, { deep: !0 } ); function S() { g.isDesignMode.value && typeof t.field == "string" && (t.field += "-design-mode"); } (r.resetFormData || O) && (i = {}); const y = n, E = C(), P = C(), p = (o) => { P.value = o; }, D = Re(); Object.keys(D).length && Z("nodeAttrs", D); const I = Ue(null), M = 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: i })) ?? !0; }), m = W(() => { var u; const o = M.value && ((u = t.rules) == null ? void 0 : u.map((_) => ({ ..._, validator: _.validator && g.funcs.value[_.validator] // 自定义校验函数 }))); let l = t.field; r.ruleField ? l = r.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; const o = (($ = L.value) == null ? void 0 : $.bindModel) ?? "modelValue", l = {}; return t.on && Object.keys(t.on).forEach((_) => { l[`on${Ye(_)}`] = (...z) => g.doActions(t.on[_], ...z); }), { ...r, ...t.componentProps, disabled: (h == null ? void 0 : h.value) || ((u = t.componentProps) == null ? void 0 : u.disabled), bindModel: o, ...l }; }), L = W(() => J.getComponentConfingByType(t.type) ?? null); he(() => { c.value = r.modelValue ?? i[t.field ?? ""]; }), B( () => c.value, () => { c.value !== (r.modelValue ?? i[t.field ?? ""]) && a(c.value); } ), B( () => E.value, () => { A(); }, { immediate: !0 } ); function A() { var l; const o = E.value || s; t.id && o && ((t.input || t.type === "table" && t.field || t.type === "card" && t.field && t.multiple) && (o.setValue = a, o.getValue = () => i[t.field] || r.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 && P.value && g.addComponentInstance(t.id + "formItem", P.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 j() { 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 : i[t.field] ?? ((u = t.componentProps) == null ? void 0 : u.defaultValue); a(G(_)); } if (t.type === "slot") { const _ = t.slotName; if (!_) return; I.value = le({ setup() { return () => K(w, _, { componentSchema: t, model: i }); } }); return; } const o = J.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) { Object.prototype.toString.call(o), Object.prototype.toString.call(o) === "[object Array]" ? o.forEach((l) => { i[l.value] = l.label; }) : i[o.value] = o.label, r.id ? k.emit("updateformData" + r.id, i) : k.emit("updateformData", i); } function a(o) { y("update:modelValue", o), y("change", o), t.field && (i[t.field] = o), r.id ? k.emit("updateformData" + r.id, i) : k.emit("updateformData", i); } function F(o) { y("update:dynamicId", o); } let V = null; return B( () => t, async (o) => { const l = JSON.stringify({ ...o, children: void 0, componentProps: { ...o.componentProps, options: null } }); if (l === V) return !1; V = l, j(); }, { immediate: !0, deep: !0 } ), $e(v), (o, l) => { var u; const $ = Te("ENode"); return I.value && M.value ? (H(), Y(je, { key: 0, hasFormItem: R(t).noFormItem !== !0 && ((u = L.value) == null ? void 0 : u.defaultSchema.input), formItemProps: m.value, onUpdateFormItemRef: p }, { default: T(() => [ (H(), Y(Be(I.value), be({ ref_key: "componentInstance", ref: E, onVnodeMounted: A, model: R(i) }, { ...U.value }, { [U.value.bindModel]: c.value, ["onUpdate:" + U.value.bindModel]: l[0] || (l[0] = (_) => c.value = _), [`onUpdate:${U.value.bindModel}` || ""]: a, "onUpdate:modelValueLabel": f, "onUpdate:dynamicId": F }), { node: T((_) => [ Q($, be({ id: r.id }, _, { sourceDateUrl: r.sourceDateUrl }), null, 16, ["id", "sourceDateUrl"]) ]), "edit-node": T(() => [ K(o.$slots, "edit-node") ]), _: 3 }, 16, ["model"])) ]), _: 3 }, 8, ["hasFormItem", "formItemProps"])) : Ne("", !0); }; } }); function tt() { const e = C(!1), n = Ce(), s = C({}); function r() { return new Promise((d) => { if (e.value) d(); else { const S = B(e, () => { S(), d(); }); } }); } async function c(d = "default") { var y; await r(); const S = (y = s.value) == null ? void 0 : y[d]; if (!S) throw new Error(`表单 [name=${d}] 不存在`); return S; } async function i(d, S) { const y = await c(d); return G(await S(y)); } async function w(d = "default") { return await i(d, (S) => S.getData()); } function g(d, S = "default", y = void 0) { var E, P; if (y && Object.keys(y).length) { let p = function(m) { let U = []; return m.forEach((L) => { L.children && (U = [...U, ...p(L.children)]), U.push(L); }), U; }, I = function(m) { var L; let U = p((L = y == null ? void 0 : y.schemas[0]) == null ? void 0 : L.children); return Object.keys(m).forEach((A) => { var f, a, F, V, o, l, $; const v = U.find((u) => u.field === A), j = ["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" && !((F = (a = v == null ? void 0 : v.componentProps) == null ? void 0 : a.props) != null && F.multiple) || (v == null ? void 0 : v.type) === "date" && j.includes((V = v == null ? void 0 : v.componentProps) == null ? void 0 : V.type)) && typeof m[A] == "string") m[A] = (o = m[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 m[A] == "string") m[A].indexOf(";") === -1 && m[A].indexOf(";") === -1 ? m[A][m[A]] : m[A].indexOf(";") > -1 ? m[A] = m[A].split(";").map((u) => u.split(",")) : m[A].indexOf(";") === -1 ? m[A] = m[A].split(",") : m[A].indexOf(";") > -1 ? m[A] = m[A].split(";").map((u) => u.split(",")) : m[A].indexOf(";") === -1 && (m[A] = m[A].split(",")); else if (((v == null ? void 0 : v.type) === "upload-image" || (v == null ? void 0 : v.type) === "upload-file") && typeof m[A] == "string") { let u = []; Object.entries(m).forEach(([_, z]) => { m[A] === z && _ !== v.field && _.indexOf("@") > -1 && _.indexOf(A) > -1 && (u = _.split("@")[1].split(",")); }), m[A] = m[A].split(",").map((_, z) => ({ url: _, name: u[z] || _ })); } else (v == null ? void 0 : v.type) === "number" || (v == null ? void 0 : v.type) === "slider" ? m[A] = Number(m[A]) : (v == null ? void 0 : v.type) === "switch" && (m[A] = typeof m[A] == "boolean" ? m[A] : m[A].indexOf("true") > -1); }), m; }(d); n.setFormData(I, S); const M = (E = s.value) == null ? void 0 : E[S]; M == null || M.clearValidate(); } else { n.setFormData(d, S); const p = (P = s.value) == null ? void 0 : P[S]; p == null || p.clearValidate(); } } async function h(d = "default") { return await i(d, async (S) => (await S.validate(), await S.getData())); } async function N(d) { await r(); const S = {}; for (const y in s.value) { const E = s.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: s, getData: w, setData: g, validate: h, 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__ */ le({ __name: "builder", props: { pageSchema: {}, formData: {}, disabled: { type: Boolean }, sourceDateUrl: {}, id: {} }, emits: ["change", "ready"], setup(e, { expose: n, emit: s }) { const r = se(() => import("./index-DgcFxYFp.js")), c = s, i = C([]), w = C({}), { ready: g, pageManager: h, forms: N, getData: O, setData: t, validate: x, getForms: d, setForms: S, validateAll: y, getFormInstance: E } = tt(), P = e, p = re({ schemas: [] }); B( () => P.pageSchema, (f) => { ae(p, f); }, { immediate: !0, deep: !0 } ), B( () => P.formData, (f) => { if (f) { let a = L(f); w.value = a, t(a), c("change", a); } }, { immediate: !0, deep: !0 } ); function D(f) { let a = []; return f.forEach((F) => { F.children && (a = [...a, ...D(F.children)]), a.push(F); }), a; } function I(f, a) { function F(o) { return JSON.parse(JSON.stringify(o)); } function V(o, l) { if (o.type === "card" && o.multiple && o.field && Array.isArray(l[o.field])) return l[o.field].map((u) => { var z; const _ = F({ ...o, multiple: !0 }); return _.children = (z = _.children) == null ? void 0 : z.map((oe) => V(oe, u)).flat(), _; }); const $ = F(o); return Array.isArray($.children) && ($.children = $.children.map((u) => V(u, l)).flat()), $; } return f.map((o) => V(o, a)).flat(); } function M(f, a = "", F = { root: 0 }) { const V = a || "root"; return a || (F.root = 0), F[V] === void 0 && (F[V] = 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 = a ? `${a}.${$}[${F[V]}]` : `${$}[${F[V]}]`, F[V]++) : o.field && a && (l.field = `${a}.${$}`); const u = l.field || a; F[u] = 0; } else o.field && a && (l.field = `${a}.${o.field}`); return o.children && (l.children = M(o.children, l.field || a, F)), l; }); } function m(f, a, F = "", V = {}) { const o = F || "root"; return V[o] === void 0 && (V[o] = 0), f.forEach((l) => { const $ = l.field || ""; let u = F ? `${F}.${$}` : `${$}`; l.type === "card" && l.multiple ? (typeof a[u][`${V[o]}`] == "object" ? Object.keys(a[u][`${V[o]}`]).forEach((_) => { a[`${u}[${V[o]}].${_}`] = a[u][`${V[o]}`][_]; }) : a[`${u}[${V[o]}]`] = a[u][`${V[o]}`], l.children && (l.children = m( l.children, a, `${u}[${V[o]}]` || F, V )), V[o]++) : l.children && (l.children = m(l.children, a, F, V)); }), V[o] = 0, a; } function U(f, a, F) { let V = m(G(f), G(a)); return { obj: M(f), dataObj: V }; } function L(f) { let a = D(P.pageSchema.schemas[0].children); i.value = a.filter((l) => l.type === "card" && l.multiple); const F = I(P.pageSchema.schemas[0].children, f); let { obj: V, dataObj: o } = U(F, f, i.value); return f = o, P.pageSchema.schemas[0].children = V, Object.keys(f).forEach((l) => { var $, u, _, z, oe, de, fe; if (l.indexOf("@") < 0) { const b = a.find((q) => q.field === l), Pe = ["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" && Pe.includes((z = b == null ? void 0 : b.componentProps) == null ? void 0 : z.type)) && typeof f[l] == "string") f[l] = (oe = f[l]) == null ? void 0 : oe.split(","); else if ((b == null ? void 0 : b.type) === "cascader" && ((fe = (de = b == null ? void 0 : b.componentProps) == null ? void 0 : de.props) != null && fe.multiple) && typeof f[l] == "string") f[l].indexOf(";") > -1 ? f[l] = f[l].split(";").map((q) => q.split(",")) : f[l] = f[l].split(","), f[l].indexOf(";") > -1 ? f[l] = f[l].split(";").map((q) => q.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 q = []; Object.entries(f).forEach(([ee, ye]) => { f[l] === ye && ee !== b.field && ee.indexOf("@") > -1 && ee.indexOf(l) > -1 && (q = ee.split("@")[1].split(",")); }), f[l] = f[l].split(",").map((ee, ye) => ({ url: ee, name: q[ye] || ee })); } 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 && h.setMethods(f, !0); }, { immediate: !0 } ), Z("slots", Le()), Z("pageManager", h), Z("forms", N), Z("pageSchema", p), Z( "disabled", W(() => P.disabled) ); const A = ue(), v = A == null ? void 0 : A.proxy; function j() { ce(() => { g.value = !0, c("ready", h), v && h.addComponentInstance("builder", v); }); } return k.on("updateformData" + (P.id ? P.id : ""), (f) => { c("change", f); }), n({ ready: g, pageManager: h, getData: O, setData: t, validate: x, getForms: d, setForms: S, validateAll: y, getFormInstance: E }), (f, a) => R(J).initialized.value ? (H(), Y(Fe, { key: 1, onResolve: j }, { default: T(() => [ X("div", ot, [ (H(!0), Ee(Je, null, ze(p.schemas, (F, V) => (H(), Y(R(et), { id: P.id, key: V, sourceDateUrl: P.sourceDateUrl, componentSchema: F }, null, 8, ["id", "sourceDateUrl", "componentSchema"]))), 128)) ]) ]), fallback: T(() => [ X("div", st, [ Q(R(r)) ]) ]), _: 1 })) : (H(), Ee("div", nt)); } }); function xe(e) { return Ze() ? (We(e), !0) : !1; } function lt(e) { let n = 0, s, r; const c = () => { n -= 1, r && n <= 0 && (r.stop(), s = void 0, r = void 0); }; return (...i) => (n += 1, r || (r = He(!0), s = r.run(() => e(...i))), xe(c), s); } function ie(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 ue(); } function pt(e, n = !0, s) { ft() ? Ae(e, s) : n ? e() : ce(e); } function mt(e = !1, n = {}) { const { truthyValue: s = !0, falsyValue: r = !1 } = n, c = Ke(e), i = C(e); function w(g) { if (arguments.length) return i.value = g, i.value; { const h = ie(s); return i.value = i.value === h ? ie(r) : h, i.value; } } return c ? w : [i, w]; } function Jt(e, n, s) { const r = B(e, (...c) => (ce(() => r()), n(...c)), s); return r; } const ve = at ? window : void 0; function ne(e) { var n; const s = ie(e); return (n = s == null ? void 0 : s.$el) != null ? n : s; } function ht(...e) { let n, s, r, c; if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([s, r, c] = e, n = ve) : [n, s, r, c] = e, !n) return dt; Array.isArray(s) || (s = [s]), Array.isArray(r) || (r = [r]); const i = [], w = () => { i.forEach((O) => O()), i.length = 0; }, g = (O, t, x, d) => (O.addEventListener(t, x, d), () => O.removeEventListener(t, x, d)), h = B( () => [ne(n), ie(c)], ([O, t]) => { if (w(), !O) return; const x = ut(t) ? { ...t } : t; i.push( ...s.flatMap((d) => r.map((S) => g(O, d, S, x))) ); }, { immediate: !0, flush: "post" } ), N = () => { h(), 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 Me(...e) { let n, s, r = {}; e.length === 3 ? (n = e[0], s = e[1], r = e[2]) : e.length === 2 ? typeof e[1] == "object" ? (n = !0, s = e[0], r = e[1]) : (n = e[0], s = e[1]) : (n = !0, s = e[0]); const { target: c = ve, eventName: i = "keydown", passive: w = !1, dedupe: g = !1 } = r, h = vt(n); return ht(c, i, (O) => { O.repeat && ie(g) || h(O) && s(O); }, w); } function we(e, n, s = {}) { return Me(e, n, { ...s, eventName: "keydown" }); } function Se(e, n, s = {}) { return Me(e, n, { ...s, eventName: "keyup" }); } function gt() { const e = C(!1), n = ue(); 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, s = {}) { const { window: r = ve, ...c } = s; let i; const w = yt(() => r && "ResizeObserver" in r), g = () => { i && (i.disconnect(), i = void 0); }, h = W(() => { const t = ie(e); return Array.isArray(t) ? t.map((x) => ne(x)) : [ne(t)]; }), N = B( h, (t) => { if (g(), w.value && r) { i = new ResizeObserver(n); for (const x of t) x && i.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 }, s = {}) { const { window: r = ve, box: c = "content-box" } = s, i = W(() => { var t, x; return (x = (t = ne(e)) == null ? void 0 : t.namespaceURI) == null ? void 0 : x.includes("svg"); }), w = C(n.width), g = C(n.height), { stop: h } = St( e, ([t]) => { const x = c === "border-box" ? t.borderBoxSize : c === "content-box" ? t.contentBoxSize : t.devicePixelContentBoxSize; if (r && i.value) { const d = ne(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; }, s ); pt(() => { const t = ne(e); t && (w.value = "offsetWidth" in t ? t.offsetWidth : n.width, g.value = "offsetHeight" in t ? t.offsetHeight : n.height); }); const N = B( () => ne(e), (t) => { w.value = t ? n.width : 0, g.value = t ? n.height : 0; } ); function O() { h(), N(); } return { width: w, height: g, stop: O }; } function Ht(e, n, s, r = {}) { var c, i, w; const { clone: g = !1, passive: h = !1, eventName: N, deep: O = !1, defaultValue: t, shouldEmit: x } = r, d = ue(), S = s || (d == null ? void 0 : d.emit) || ((c = d == null ? void 0 : d.$emit) == null ? void 0 : c.bind(d)) || ((w = (i = d == null ? void 0 : d.proxy) == null ? void 0 : i.$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, P = () => it(e[n]) ? E(e[n]) : t, p = (D) => { x ? x(D) && S(y, D) : S(y, D); }; if (h) { const D = P(), I = C(D); let M = !1; return B( () => e[n], (m) => { M || (M = !0, I.value = E(m), ce(() => M = !1)); } ), B( I, (m) => { !M && (m !== e[n] || O) && p(m); }, { deep: O } ), I; } else return W({ get() { return P(); }, set(D) { p(D); } }); } function Kt() { const { isDark: e } = ge(), n = mt(e); return { isDark: e, toggleDark: n }; } function Dt() { const e = C(!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"), s = new MutationObserver(function(r) { for (var c of r) if (c.type === "attributes" && c.attributeName === "class") { const i = c.target; new Array(...i.classList).includes("dark") ? e.value = !0 : e.value = !1; } }); s.observe(n, { attributes: !0, attributeFilter: ["class"] }), $e(() => { s.disconnect(); }); } function At() { const e = C(1), n = C(!1), { isDark: s } = Dt(), { pressSpace: r, pressShift: c, pressCtrl: i } = Ot(); return { canvasScale: e, pressSpace: r, pressShift: c, pressCtrl: i, disabledZoom: n, isDark: s }; } const ge = lt(At); function Ot() { const e = C(!1), n = C(!1), s = C(!1); return we(" ", () => { e.value = !0; }), Se(" ", () => { e.value = !1; }), we("Shift", (r) => { r.preventDefault(), n.value = !0; }), Se("Shift", () => { n.value = !1; }), we("Control", (r) => { r.preventDefault(), s.value = !0; }), Se("Control", () => { s.value = !1; }), { pressSpace: e, pressShift: n, pressCtrl: s }; } function Zt(e) { const { pressSpace: n } = ge(), s = new Image(1, 1); s.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="; let r = 0, c = 0; function i(h) { var N; n.value && (r = h.x, c = h.y, (N = h.dataTransfer) == null || N.setDragImage(document.createElement("div"), 0, 0)); } function w(h) { if (h.preventDefault(), !h.x || !h.y || !n.value) return; const N = h.x - r, O = h.y - c; r = h.x, c = h.y, e.value && (e.value.scrollTop -= O, e.value.scrollLeft -= N); } function g() { n.value = !1; } return { handleElementDragStart: i, handleElementDrag: w, handleElementDragEnd: g }; } function Wt(e) { const { pressCtrl: n, canvasScale: s, disabledZoom: r } = ge(); function c(i) { if (!n.value || r.value) return; i.preventDefault(); let w = 0; i.deltaY < 0 ? w = s.value + 0.05 : w = s.value - 0.05, !(w > 150 || w < 0.5) && (s.value = w); } return B( () => s.value, (i) => { e.value && !r.value && (e.value.style.transform = `scale(${i})`); } ), { handleZoom: c, canvasScale: s }; } function Gt(e, n = 16.66) { let s; function r() { c(), s = window.setInterval(e, n); } function c() { window.clearInterval(s); } return { startTimedQuery: r, stopTimedQuery: c }; } const xt = { class: "min-w-750px rounded" }, It = { class: "h-full rounded" }, _t = /* @__PURE__ */ le({ __name: "index", setup(e, { expose: n }) { const s = J.getComponent("monacoEditor"), r = J.getComponent("modal"), c = C(null), i = C(!1), w = C(!1), g = C({}), h = te("pageSchema"), N = C(null), O = C(""); function t() { w.value = !1; } function x() { i.value = !1; } function d() { i.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), ce(() => { 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(), Y(R(r), { modelValue: i.value, "onUpdate:modelValue": E[1] || (E[1] = (P) => i.value = P), title: "预览", class: "w-900px", width: "900px", onClose: x, onOk: S, okText: "表单数据" }, { default: T(() => [ X("div", xt, [ (H(), Y(R(rt), { key: O.value, ref_key: "kb", ref: N, "page-schema": R(h) }, null, 8, ["page-schema"])), Q(R(r), { modelValue: w.value, "onUpdate:modelValue": E[0] || (E[0] = (P) => w.value = P), title: "表单数据", class: "w-860px", width: "860px", onClose: t, onOk: t }, { default: T(() => [ X("div", It, [ Q(R(s), { 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" }, Ft = { class: "epic-header-container" }, Vt = { class: "epic-loading-box" }, Qt = /* @__PURE__ */ le({ __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: s }) { const { t: r } = Oe(), c = se(() => import("./index-IGxCNti8.js")), i = se(() => import("./index-WkZdU_zw.js")), w = se(() => import("./index-D5moT97y.js")), g = se(() => import("./index-Cln9MN7u.js")), h = se(() => import("./index-DgcFxYFp.js")), N = Ce(), O = ke(), t = e; let x = { schemas: [ { type: "form", id: "root", label: r("page"), children: [], componentProps: { name: r("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 && J.setSourceData(t.source), t.formMode && (x.schemas = J.formSchemas); }), N.setDesignMode(), N.setDefaultComponentIds(x.schemas); const d = s, S = C(null), y = re({ checkedNode: null, hoverNode: null, disableHover: !1, matched: [] }), E = re({ schemas: [], script: x.script }), { disabledZoom: P } = ge(); he(() => { P.value = t.disabledZoom; }), he(() => { const a = E.script; a && a !== "" && N.setMethods(a); }), Z("pageSchema", E), Z("revoke", O), Z("pageManager", N), Z( "designerProps", W(() => t) ), Z("designer", { setCheckedNode: D, setHoverNode: I, setDisableHover: m, handleToggleDeviceMode: j, reset: A, state: y }), k.on("saveSourceData", (a) => { d("saveSourceData", a); }), k.on("deleteSourceData", (a) => { d("deleteSourceData", a); }), k.on("updateSourceData", (a) => { d("updateSourceData", a); }); function p() { E.schemas = G(x.schemas), D(E.schemas[0]), O.push(E.schemas, "初始化撤销功能"); } async function D(a = E.schemas[0]) { y.checkedNode = a, y.matched = Xe(E.schemas, a.id); } async function I(a = null) { var F; if (!a || y.disableHover) return y.hoverNode = null, !1; if ((a == null ? void 0 : a.id) === ((F = y.hoverNode) == null ? void 0 : F.id)) return !1; y.hoverNode = a; } function M() { ce(() => { d("ready", { pageManager: N }); }); } async function m(a = !1) { y.disableHover = a; } function U(a) { ae(E, G(a)); } function L() { return Ie(E); } function A() { Ve(E.schemas, x.schemas) && E.script === x.script || (ae(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 j(a) { d("toggleDeviceMode", a); } function f() { S.value.handleOpen(); } return p(), n({ revoke: O, setData: U, getData: L, reset: A, preview: f }), (a, F) => R(J).initialized.value ? (H(), Y(Fe, { key: 1, onResolve: M }, { default: T(() => [ X("div", Nt, [ X("div", Ft, [ K(a.$slots, "header", {}, () => [ t.hiddenHeader ? Ne("", !0) : (H(), Y(R(c), { key: 0, onPreview: f, onSave: v }, { header: T(() => [ K(a.$slots, "header-prefix") ]), prefix: T(() => [ K(a.$slots, "header-prefix") ]), title: T(() => [ K(a.$slots, "header-title") ]), "right-prefix": T(() => [ K(a.$slots, "header-right-prefix") ]), "right-action": T(() => [ K(a.$slots, "header-right-action") ]), "right-suffix": T(() => [ K(a.$slots, "header-right-suffix") ]), _: 3 })) ]) ]), X("div", { class: Ge(["epic-split-view-container", { "hidden-header": a.hiddenHeader }]) }, [ Q(R(i)), Q(R(w)), Q(R(g)) ], 2), Q(_t, { ref_key: "previewRef", ref: S }, null, 512) ]) ]), fallback: T(() => [ X("div", Vt, [ Q(R(h)) ]) ]), _: 3 })) : (H(), Ee("div", $t)); } }), Ct = { component: async () => await import("./index-CAkpmC6c.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(), Mt = { 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 Pt(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-Dgdrnlh5.js")), e.component("ERuleEditor", async () => await import("./index-BdToAdGK.js")), e.component("EOptionsEditor", async () => await import("./index-DNWIP087.js")), e.component("ENode", async () => await import("./index-B34F68Fz.js")), e.component("EDataSource", async () => await import("./index-B0OgKtuT.js")), e.component("EColumnEditor", async () => await import("./index-AO9st9GO.js")), e.component("PaddingMarginControl", async () => await import("./index-CdnV7DS4.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-B__FQHVu.js") }), e.registerRightSidebar({ id: "style_view", title: me("style"), component: async () => await import("./styleView-DwuC1nZJ.js") }), e.registerRightSidebar({ id: "event_view", title: "事件", component: async () => await import("./eventView-C2wKhfU_.js") }), [Ct, Mt].forEach((s) => { e.registerComponent(s); }); } Pt(J); 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, Ce as k, ke as l, Ot as m, Dt as n, bt as o, At as p, ge as u, Jt as w };