UNPKG

ai-form-designer

Version:

vue3+adv的设计器,可视化开发页面表单

1,847 lines (1,844 loc) 51.6 kB
var Se = Object.defineProperty; var Ae = (t, e, n) => e in t ? Se(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; var V = (t, e, n) => Ae(t, typeof e != "symbol" ? e + "" : e, n); import { defineAsyncComponent as xe, ref as b, shallowRef as ue, reactive as q, defineComponent as Z, createBlock as z, renderSlot as N, openBlock as F, unref as I, mergeProps as me, withCtx as D, getCurrentInstance as te, inject as H, watch as _, useAttrs as Ee, provide as B, computed as $, watchEffect as oe, onUnmounted as he, resolveComponent as Ie, createCommentVNode as ve, resolveDynamicComponent as ke, createVNode as T, normalizeProps as De, guardReactiveProps as _e, useSlots as Pe, createElementBlock as de, Suspense as ye, createElementVNode as U, Fragment as Re, renderList as Me, nextTick as Y, effectScope as Ve, isRef as Fe, getCurrentScope as Oe, onScopeDispose as Ne, onMounted as fe, normalizeClass as Be } from "vue"; const L = (t, e) => xe({ loader: t, loadingComponent: e, delay: 80 }); function se(t = 10) { const e = "abcdefghijklmnopqrstuvwxyz0123456789"; let n = ""; for (let o = 0; o < t; o++) { const s = Math.floor(Math.random() * e.length); n += e[s]; } return n; } function $e(t) { return t.charAt(0).toUpperCase() + t.slice(1); } function Ge(t) { return t.replace(/-/g, ""); } function O(t, e = /* @__PURE__ */ new WeakMap()) { if (typeof t != "object" || t === null) return t; if (e.has(t)) return e.get(t); if (Array.isArray(t)) { const o = t.map((s) => O(s, e)); return e.set(t, o), o; } const n = {}; return e.set(t, n), Object.keys(t).forEach((o) => { n[o] = O(t[o], e); }), n; } function Pt(t) { const [e] = ze([O(t)], (n) => { var s, i; const o = { ...n, id: `${Ge(n.type)}${se(8)}` }; return (o.field || o.input) && !((i = (s = M.getComponentConfingByType(o.type)) == null ? void 0 : s.editConstraints) != null && i.fixedField) && (o.field = o.id), o; }); return e; } function J(t, e, n = !0) { for (const [o, s] of Object.entries(e)) t[o] && s && typeof t[o] == "object" && typeof s == "object" ? (Array.isArray(t[o]) && !Array.isArray(s) ? t[o] = {} : !Array.isArray(t[o]) && Array.isArray(s) && (t[o] = []), J(t[o], s, n)) : t[o] = s; n && Object.keys(t).reverse().forEach((o) => { e.hasOwnProperty(o) || (Array.isArray(t) ? t.splice(Number(o), 1) : delete t[o]); }); } function ge(t, e, n = [], o = /* @__PURE__ */ new WeakMap()) { const s = (i) => { if (Array.isArray(i)) return i.map(s); if (typeof i == "object" && i !== null) { if (o.has(i)) return "[Circular]"; o.set(i, !0); const r = Object.keys(i).sort(), l = {}; return r.forEach((c) => { n.includes(c) || (l[c] = s(i[c])); }), o.delete(i), l; } else return i; }; return JSON.stringify(s(t)) === JSON.stringify(s(e)); } function Te(t, e) { const n = []; let o = !1; function s(i) { if (n.push(i), i.id === e && (o = !0), !o && i.children != null && i.children.length > 0) for (let r = 0; r < i.children.length && (s(i.children[r]), !o); r++) ; if (!o && i.slots) for (let r in i.slots) for (let l = 0; l < i.slots[r].length && (s(i.slots[r][l]), !o); l++) ; o || n.pop(); } return t.forEach(s), o || console.error(`没有查询到id为${e}的节点`), n; } function Rt(t, e, n) { const o = e.split("."); let s = t; for (let i = 0; i < o.length; i++) { if (s == null) return n; s = s[o[i]]; } return s === void 0 ? n : s; } function Mt(t, e, n) { const o = e.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean); let s = t; for (let i = 0; i < o.length - 1; i++) { const r = o[i]; s[r] == null && (s[r] = isNaN(Number(o[i + 1])) ? {} : []), s = s[r]; } return s[o[o.length - 1]] = n, t; } function Vt(t, e = "default") { return Le(t, e).map((o) => o.field); } function Le(t, e = "default") { const n = ee( t, (s) => { var i; return s.type === "form" && (((i = s.componentProps) == null ? void 0 : i.name) ?? s.name === e); }, !0 ); return ee( (n == null ? void 0 : n.children) ?? [], (s) => !!s.input, !1, (s) => s.type !== "subform" ); } function ee(t, e, n = !1, o) { const s = [], i = [...t]; for (; i.length; ) { const r = i.pop(); if (r != null && r.children && (!o || o(r)) && i.push(...r.children), r != null && r.slots && (!o || o(r))) for (let l in r.slots) i.push(...r.slots[l]); if (e(r) && (s.push(r), n)) return r; } return n ? !1 : s; } function ze(t, e, n) { const o = [...t]; for (; o.length; ) { const s = o.pop(); if (s != null && s.children && (!n || n(s)) && o.push(...s.children), s != null && s.slots && (!n || n(s))) for (let i in s.slots) o.push(...s.slots[i]); J(s, e(s)); } return t; } function Ft(t, e) { const n = ee( t, (o) => o.id === e, !0 ); if (!n) throw new Error(`没有查询到id为${e}的节点`); return n; } function Ot(t, e) { const n = [{ type: "", children: t }]; let o = 0, s = null; if (ee( n, (i) => { if (s = i.children ?? null, !s) { if (i != null && i.slots) for (let r in i.slots) { s = i.slots[r]; for (let l = 0; l < s.length; l++) if (s[l].id === e) return o = l, !0; } return !1; } for (let r = 0; r < s.length; r++) if (s[r].id === e) return o = r, !0; return !1; }, !0 ), !s) throw new Error(`没有查询到id为${e}的节点`); return { list: s, schema: s[o], index: o }; } function Nt(t) { const e = { schemas: [ { type: "page", id: "root", label: "页面", children: [ { label: "表单", type: "form", icon: "epic-icon-daibanshixiang", labelWidth: t.config.labelWidth || 100, name: "default", componentProps: { layout: t.config.layout || "horizontal", labelWidth: t.config.labelWidth || 100, labelLayout: t.config.labelLayout === "flex" ? "fixed" : "flex", labelCol: t.config.labelCol || { span: 5 }, wrapperCol: t.config.wrapperCol || { span: 19 }, hideRequiredMark: t.config.hideRequiredMark || !1, colon: t.config.colon || !0, labelAlign: t.config.labelAlign || "right", size: t.config.size || "middle" }, children: [], id: "form_" + se() } ], componentProps: { style: { padding: "16px" } } } ], script: t.script || "" }; return e.schemas[0].children[0].children = j( t.list ), e; } function j(t, e) { return t.map((n) => { var c, w, h; let o = n.type ?? ""; const s = n.options ?? {}, i = (a, v) => { o === a && (o = v, s.defaultValue && (s.defaultValue = JSON.parse(s.defaultValue))); }; if (i("uploadImg", "upload-image"), i("uploadFile", "upload-file"), o === "date" && s.range && (s.type = "daterange", delete s.range), (o === "date" || o === "time") && (s.valueFormat = s.format), o === "textarea") { const { minRows: a, maxRows: v } = s; s.autoSize = { minRows: a, maxRows: v }, delete s.minRows, delete s.maxRows; } o === "number" && !s.precision && delete s.precision, s.width && (s.style = { width: s.width }, delete s.width), o === "grid" && (o = "row"), e && e.type === "grid" && (o = "col", s.span = n.span, n.key = se()); const r = { label: n.label, type: o, icon: n.icon || "", field: n.model, componentProps: s, id: n.key }; return (s.noFormItem || !s.showLabel) && (r.noFormItem = !0, delete s.noFormItem, delete s.showLabel), s.clearable && (s.allowClear = !0, delete s.clearable), [ "input", "textarea", "number", "password", "select", "cascader", "checkbox", "radio", "date", "time", "slider", "switch", "color-picker", "upload-file", "upload-image" ].includes(o) && (r.input = !0, ((w = (c = n.rules) == null ? void 0 : c[0]) == null ? void 0 : w.required) === !1 && n.rules.shift(), ((h = n.rules) == null ? void 0 : h.length) > 0 && (r.rules = n.rules)), n.list && (r.children = j(n.list, n)), n.columns && (r.children = j(n.columns, n)), n.trs && (r.children = j(n.trs, n)), n.tds && (r.children = j(n.tds, n)), r; }); } function Bt(t, e) { let n = null; return (...o) => { n && clearTimeout(n), n = setTimeout(() => { t(...o); }, e); }; } class Ue { constructor() { // 已初始化基础UI V(this, "initialized", b(!1)); // 组件对象字典,key 为组件type,value 为组件 V(this, "components", {}); // 组件配置记录字典,key 为组件type,value 为组件配置 V(this, "componentConfigs", {}); // 基础组件type,切换ui时,可先移除该数组记录的type V(this, "baseComponentTypes", []); // 组件模式分组,使用 Vue Composition API 的 ref 进行响应式处理 V(this, "componentSchemaGroups", b([])); // 隐藏的组件列表,存储需要隐藏的组件名称 V(this, "hiddenComponents", []); // 表单模式默认schema数据 V(this, "formSchemas", [ { label: "表单", type: "form", componentProps: { layout: "horizontal", name: "default", labelWidth: 100, labelLayout: "fixed", labelCol: { span: 5 }, wrapperCol: { span: 19 }, colon: !0, labelAlign: "right", labelPlacement: "left" }, children: [], id: "root" } ]); // 组件分组名称映射,key 为组件原名称,value 为组件分组映射名称 V(this, "componentGroupNameMap", {}); // 组件分组排序列表(设置之后,按该数组下标排序) V(this, "sortedGroups", ["表单", "布局"]); // 视图容器模型,包含活动栏和右侧边栏的配置 V(this, "viewsContainers", { activitybars: ue([]), // 活动栏配置列表 rightSidebars: ue([]) // 右侧边栏配置列表 }); // 公共方法模型,存储插件的公共方法 V(this, "publicMethods", { // 示例数据 // publicTest: { // describe: "测试函数", // name: "test", // handler: (e) => { // console.log(e) // // alert("测试函数弹出"); // }, // }, }); } /** * 添加组件到插件管理器中 * @param componentType 组件类型 * @param component 组件 */ component(e, n) { typeof n == "function" && (n = L(n)), this.components[e] = n; } /** * 注册组件到插件管理器中 * @param componentConfig 组件配置 */ registerComponent(e) { this.component( e.defaultSchema.type, e.component ), e.defaultSchema.input && (e.config.action || (e.config.action = []), e.config.action.unshift( { type: "setValue", describe: "设置值", // 参数配置 argsConfigs: [ { ...e.defaultSchema, label: "设置数据", field: "0" } ] }, { type: "getValue", describe: "获取值" } )), this.componentConfigs[e.defaultSchema.type] = e, this.computedComponentSchemaGroups(); } /** * 从已记录的基础组件类型中移除特定类型的组件 * @param componentType 要移除的组件类型 */ removeComponent(e) { delete this.componentConfigs[e], delete this.components[e]; } /** * 记录基础组件类型 * @returns baseComponentTypes string[] */ setBaseComponentTypes(e) { this.baseComponentTypes = e; } /** * 添加基础组件类型 * @returns baseComponentType string */ addBaseComponentTypes(e) { this.baseComponentTypes.push(e); } /** * 移除已记录的基础组件类型 */ removeBaseComponents() { this.baseComponentTypes.forEach((e) => { this.removeComponent(e); }), this.setBaseComponentTypes([]), this.computedComponentSchemaGroups(); } /** * 获取所有插件管理中的所有组件 * @returns components */ getComponents() { return this.components; } /** * 通过type 查询相应的组件 * @returns components */ getComponent(e) { return this.components[e]; } /** * 注册或更新活动栏(Activitybar)模型。 * 如果模型中的组件是一个函数,则异步加载该组件。 * @param activitybar 要注册或更新的活动栏模型 */ registerActivitybar(e) { typeof e.component == "function" && (e.component = L(e.component)), typeof e.visible > "u" && (e.visible = !0); const n = this.viewsContainers.activitybars.value.findIndex( (o) => o.id === e.id ); n !== -1 ? this.viewsContainers.activitybars.value[n] = e : this.viewsContainers.activitybars.value.push(e); } /** * 获取所有activitybars * @returns activitybars */ getActivitybars() { return this.viewsContainers.activitybars.value; } /** * 隐藏活动栏 * @param value 属性 * @param attr 查询字段 默认值 title */ hideActivitybar(e, n = "title") { const o = this.viewsContainers.activitybars.value.findIndex( (s) => s[n] === e ); o !== -1 && (this.viewsContainers.activitybars.value[o].visible = !1); } /** * 显示活动栏 * @param value 属性 * @param attr 查询字段 默认值 title */ showActivitybar(e, n = "title") { const o = this.viewsContainers.activitybars.value.findIndex( (s) => s[n] === e ); o !== -1 && (this.viewsContainers.activitybars.value[o].visible = !0); } /** * 注册右侧栏 */ registerRightSidebar(e) { typeof e.component == "function" && (e.component = L(e.component)), typeof e.visible > "u" && (e.visible = !0); const n = this.viewsContainers.rightSidebars.value.findIndex( (o) => o.id === e.id ); n !== -1 ? this.viewsContainers.rightSidebars.value[n] = e : this.viewsContainers.rightSidebars.value.push(e); } /** * 获取所有rightSidebars * @returns rightSidebars */ getRightSidebars() { return this.viewsContainers.rightSidebars.value; } /** * 隐藏右侧边栏 * @param value 属性 * @param attr 查询字段 默认值 title */ hideRightSidebar(e, n = "title") { const o = this.viewsContainers.rightSidebars.value.findIndex( (s) => s[n] === e ); o !== -1 && (this.viewsContainers.rightSidebars.value[o].visible = !1); } /** * 显示右侧边栏 * @param value 属性 * @param attr 查询字段 默认值 title */ showRightSidebar(e, n = "title") { const o = this.viewsContainers.rightSidebars.value.findIndex( (s) => s[n] === e ); o !== -1 && (this.viewsContainers.rightSidebars.value[o].visible = !0); } /** * 获取所有插件管理中的所有组件配置 * @returns componentAttrs */ getComponentConfings() { return this.componentConfigs; } /** * 通过type获取ComponentConfing * @returns */ getComponentConfingByType(e) { return this.componentConfigs[e]; } /** * 计算componentSchemaGroups */ computedComponentSchemaGroups() { const e = []; Object.values(this.componentConfigs).forEach((n) => { if (!this.hiddenComponents.includes(n.defaultSchema.type) && n.groupName) { const o = this.componentGroupNameMap[n.groupName] ?? n.groupName; let s = e.findIndex( (r) => r.title === o ); s === -1 && (e.push({ title: o, list: [] }), s = e.length - 1); let i = e[s].list.findIndex( (r) => r.type === n.defaultSchema.type ); i !== -1 ? e[s].list[i] = n.defaultSchema : e[s].list.push( n.defaultSchema ); } }), e.sort((n, o) => { const s = this.sortedGroups.indexOf(n.title), i = this.sortedGroups.indexOf(o.title); return s === -1 ? 1 : i === -1 ? -1 : s - i; }), e.forEach((n) => { n.list.sort((o, s) => { var l, c; const i = ((l = this.componentConfigs[o.type]) == null ? void 0 : l.sort) ?? 1e3, r = ((c = this.componentConfigs[s.type]) == null ? void 0 : c.sort) ?? 1e3; return i - r; }); }), this.componentSchemaGroups.value = e; } /** * 按照分组获取componentSchemaGroups 暂时没啥用 * @returns componentSchemaGroups */ getComponentSchemaGroups() { return this.componentSchemaGroups; } /** * 设置组件分组名称到映射名称的关系 * @param groupName 组件分组名称 * @param mapName 映射的名称 */ setComponentGroupNameMap(e, n) { this.componentGroupNameMap[e] = n; } /** * 清空组件分组名称到映射名称的关系 */ clearComponentGroupNameMap() { this.componentGroupNameMap = {}; } /** * 设置组件分组的排序 * @param sortedGroups 包含组名和排序字段的对象数组 */ setSortedGroups(e) { this.sortedGroups = e, this.computedComponentSchemaGroups(); } /** * 清空组件分组的排序 */ clearSortedGroups() { this.sortedGroups = [], this.computedComponentSchemaGroups(); } /** * 添加需要隐藏的组件类型 * @param {*} type * @returns */ hideComponent(e) { this.hiddenComponents.push(e), this.computedComponentSchemaGroups(); } /** * 移除需要隐藏的组件类型 * @param {*} type * @returns */ showComponent(e) { this.hiddenComponents = this.hiddenComponents.filter( (n) => n !== e ), this.computedComponentSchemaGroups(); } /** * 设置需要隐藏的组件类型数组 * @param {*} type[] * @returns */ setHideComponents(e) { this.hiddenComponents = e, this.computedComponentSchemaGroups(); } /** * 设置initialized的状态。 * * @param value 要设置的布尔值。 */ setInitialized(e) { this.initialized.value = e; } /** * 添加公共方法 * @param publicMethod */ addPublicMethod(e) { const n = e.methodName ?? e.name, o = e.method ?? e.handler; this.publicMethods[n] = { ...e, name: n, handler: o }; } /** * 移除公共方法 * @param methodName */ removePublicMethod(e) { delete this.publicMethods[e]; } } const M = new Ue(); function we() { const t = b({}), e = b({}), n = b(!1), o = b([]), s = q({}); function i(d) { return console.log("==============="), console.log(d), console.log(t), console.log("==============="), t.value[d]; } function r(d, y) { t.value[d] = y; } function l(d) { delete t.value[d]; } function c(d, y = !1) { const g = Object.entries( M.publicMethods ).reduce((S, [k, G]) => (S[k] = G.handler, S), {}); try { new Function(`const epic = this;${d}`).bind({ ...g, getComponent: i, find: i, defineExpose: w, publicMethods: g, pluginManager: M })(); } catch (S) { y && console.error("[epic:自定义函数]异常:", S); } } function w(d) { d != null && (e.value = d); } function h(d, ...y) { if (!d || d.length === 0) { console.warn("未提供任何动作"); return; } d.forEach((g) => { const S = g.args ? JSON.parse(g.args) : y; switch (g.type) { case "public": a(g, S); break; case "custom": v(g, S); break; case "component": f(g, S); break; default: console.warn(`未知的动作类型: ${g.type}`); break; } }); } function a(d, y) { var g; try { (g = M.publicMethods[d.methodName]) == null || g.handler(...y); } catch (S) { console.error(`[Epic:公共函数(${d.methodName})]执行异常:`, S); } } function v(d, y) { var g, S; try { (S = (g = e.value)[d.methodName]) == null || S.call(g, ...y); } catch (k) { console.error(`[Epic:自定义函数(${d.methodName})]执行异常:`, k); } } function f(d, y) { const g = d.componentId != null && i(d.componentId); if (!g) { console.warn(`[Epic:组件${d.componentId}]未找到`); return; } try { g[d.methodName](...y); } catch (S) { console.error(`[Epic:组件${d.componentId}函数(${d.methodName})]执行异常:`, S); } } function p(d = !0) { n.value = d; } function m(d) { const y = ee(d, () => !0); o.value = y.map((g) => g.id); } function C(d, y = "default") { if (s[y]) { const g = s[y]; J(d, g); } s[y] = d; } function x(d, y = "default") { if (s[y]) { J(s[y], d, !1); return; } s[y] = d; } return { componentInstances: t, funcs: e, isDesignMode: n, defaultComponentIds: o, forms: s, addFormData: C, setFormData: x, getComponentInstance: i, // 简化查询函数, 推荐使用 find: i, addComponentInstance: r, removeComponentInstance: l, setMethods: c, doActions: h, setDesignMode: p, setDefaultComponentIds: m }; } function Je() { const t = b([]), e = b([]), n = b(null); let o = 0; function s(c, w = "插入组件") { const h = Date.now(); o + 150 > h || (o = h, n.value != null && (t.value.push(n.value), e.value.splice(0, e.value.length)), n.value = { type: w, componentSchema: JSON.stringify(c) }, t.value.length > 60 && t.value.unshift()); } function i() { if (t.value.length === 0) return !1; const c = t.value.pop(); return n.value != null && e.value.push(n.value), n.value = c, JSON.parse(c.componentSchema); } function r() { if (e.value.length === 0) return !1; const c = e.value.pop(); return n.value != null && t.value.push(n.value), n.value = c, JSON.parse(c.componentSchema); } function l() { t.value = [], e.value = [], n.value = null; } return { recordList: t, undoList: e, currentRecord: n, push: s, undo: i, redo: r, reset: l }; } const He = /* @__PURE__ */ Z({ inheritAttrs: !1, __name: "dynamicFormItem", props: { hasFormItem: { type: Boolean }, formItemProps: {} }, emits: ["updateFormItemRef"], setup(t, { emit: e }) { const n = M.getComponent("form-item"), o = t, s = e, i = b(), r = () => { s("updateFormItemRef", i.value); }; return (l, c) => o.hasFormItem ? (F(), z(I(n), me({ key: 0, ref_key: "formItemRef", ref: i, onVnodeMounted: r }, o.formItemProps), { default: D(() => [ N(l.$slots, "default") ]), _: 3 }, 16, ["onVnodeMounted"])) : N(l.$slots, "default", { key: 1 }); } }), We = /* @__PURE__ */ Z({ name: "ENode", __name: "node", props: { componentSchema: {}, modelValue: {}, ruleField: {}, resetFormData: { type: Boolean }, name: {} }, emits: ["update:modelValue", "change"], setup(t, { emit: e }) { const { proxy: n } = te(), o = t, s = b(null); let i = H("formData", q({})); const r = H("slots", {}), l = H("pageManager", {}), c = H("disabled", { value: !1 }), w = H("ruleFieldPrefix", null), h = H("resetFormData", !1); let a = q(O(o.componentSchema)); v(), _(() => o.componentSchema, (u) => { ge(a, u, ["children"]) || (J(a, O(u)), v()); }, { deep: !0 }); function v() { l.isDesignMode.value && typeof a.field == "string" && (a.field += "-design-mode"); } (o.resetFormData || h) && (i = {}); const f = e, p = b(), m = b(), C = (u) => { m.value = u; }, x = Ee(); Object.keys(x).length && B("nodeAttrs", x); const d = ue(null), y = $(() => { var u, A; return (u = a.componentProps) != null && u.hidden ? !1 : typeof a.show == "boolean" ? a.show : ((A = a.show) == null ? void 0 : A.call(a, { values: i })) ?? !0; }), g = $(() => { var R; const u = y.value && ((R = a.rules) == null ? void 0 : R.map( (E) => ({ ...E, validator: E.validator && l.funcs.value[E.validator] // 自定义校验函数 }) )); let A = a.field; o.ruleField ? A = o.ruleField : w && a.field && (A = O(w), A.push(a.field)); const P = { ...a, rules: u, rule: u, field: A }; return P.children && delete P.children, P; }), S = $(() => { var P, R; const u = ((P = k.value) == null ? void 0 : P.bindModel) ?? "modelValue", A = {}; return a.on && Object.keys(a.on).forEach((E) => { A[`on${$e(E)}`] = (...Ce) => l.doActions(a.on[E], ...Ce); }), { ...o, ...a.componentProps, disabled: (c == null ? void 0 : c.value) || ((R = a.componentProps) == null ? void 0 : R.disabled), bindModel: u, ...A }; }), k = $(() => M.getComponentConfingByType(a.type) ?? null); oe(() => { s.value = o.modelValue ?? i[a.field ?? ""]; }), _(() => s.value, () => { s.value !== (o.modelValue ?? i[a.field ?? ""]) && K(s.value); }), _(() => p.value, () => { G(); }, { immediate: !0 }); function G() { var A; const u = p.value || n; a.id && u && (a.input && (u.setValue = K, u.getValue = () => i[a.field] || o.modelValue), u.setAttr = (P, R) => (a.componentProps || (a.componentProps = {}), a.componentProps[P] = R), u.getAttr = (P) => a.componentProps[P], l.addComponentInstance(a.id, u), (A = k.value) != null && A.defaultSchema.input && a.noFormItem !== !0 && m.value && l.addComponentInstance(a.id + "formItem", m.value)); } function ne() { var u; a.id && (l.removeComponentInstance(a.id), (u = k.value) != null && u.defaultSchema.input && a.noFormItem !== !0 && l.removeComponentInstance(a.id + "formItem")); } async function re() { var A, P, R; if (typeof ((A = a.componentProps) == null ? void 0 : A.defaultValue) < "u") { const E = l.isDesignMode.value ? (P = a.componentProps) == null ? void 0 : P.defaultValue : i[a.field] ?? ((R = a.componentProps) == null ? void 0 : R.defaultValue); K(O(E)); } if (a.type === "slot") { const E = a.slotName; if (!E) return; d.value = Z({ setup() { return () => N(r, E, { componentSchema: a, model: i }); } }); return; } const u = M.getComponent(a.type); if (!u) { console.error(`组件${a.type}未注册`); return; } if (typeof u == "function") { const E = await u(); d.value = E.default ?? E; } else d.value = u; } function K(u) { f("update:modelValue", u), f("change", u), a.field && (i[a.field] = u); } let X = null; return _(() => a, (u) => { const A = JSON.stringify({ ...u, children: void 0 }); if (A === X) return !1; X = A, re(); }, { immediate: !0, deep: !0 }), he(ne), (u, A) => { var R; const P = Ie("ENode"); return d.value && y.value ? (F(), z(He, { key: 0, hasFormItem: I(a).noFormItem !== !0 && ((R = k.value) == null ? void 0 : R.defaultSchema.input), formItemProps: g.value, onUpdateFormItemRef: C }, { default: D(() => [ (F(), z(ke(d.value), me({ ref_key: "componentInstance", ref: p, onVnodeMounted: G, model: I(i) }, { ...S.value }, { [S.value.bindModel]: s.value, ["onUpdate:" + S.value.bindModel]: A[0] || (A[0] = (E) => s.value = E), [`onUpdate:${S.value.bindModel}` || ""]: K }), { node: D((E) => [ T(P, De(_e(E)), null, 16) ]), "edit-node": D(() => [ N(u.$slots, "edit-node") ]), _: 3 }, 16, ["model"])) ]), _: 3 }, 8, ["hasFormItem", "formItemProps"])) : ve("", !0); }; } }); function Ke() { const t = b(!1), e = we(), n = b({}); function o() { return new Promise((f) => { if (t.value) f(); else { const p = _(t, () => { p(), f(); }); } }); } async function s(f = "default") { var m; await o(); const p = (m = n.value) == null ? void 0 : m[f]; if (!p) throw new Error(`表单 [name=${f}] 不存在`); return p; } async function i(f, p) { const m = await s(f); return O(await p(m)); } async function r(f = "default") { return await i(f, (p) => p.getData()); } function l(f, p = "default") { var C; e.setFormData(f, p); const m = (C = n.value) == null ? void 0 : C[p]; m == null || m.clearValidate(); } async function c(f = "default") { return await i(f, async (p) => (await p.validate(), await p.getData())); } async function w(f) { await o(); const p = {}; for (const m in n.value) { const C = n.value[m]; C && (p[m] = O(await f(C))); } return p; } async function h() { return await w((f) => f.getData()); } function a(f) { for (const p in f) l(f[p], p); } async function v() { return await w(async (f) => (await f.validate(), await f.getData())); } return { ready: t, pageManager: e, forms: n, getData: r, setData: l, validate: c, getForms: h, setForms: a, validateAll: v, getFormInstance: s }; } const qe = { key: 0, class: "epic-loading-box" }, Ze = { class: "epic-builder-main" }, Qe = { class: "epic-loading-box" }, Ye = /* @__PURE__ */ Z({ __name: "builder", props: { pageSchema: {}, formData: {}, disabled: { type: Boolean } }, emits: ["ready"], setup(t, { expose: e, emit: n }) { const o = L(() => import("./index-D3ccvEyD.js")), s = n, { ready: i, pageManager: r, forms: l, getData: c, setData: w, validate: h, getForms: a, setForms: v, validateAll: f, getFormInstance: p } = Ke(), m = t, C = q({ schemas: [] }); _( () => m.pageSchema, (g) => { J(C, g); }, { immediate: !0, deep: !0 } ), _( () => m.formData, (g) => { g && w(g); }, { immediate: !0, deep: !0 } ), _( () => C.script, (g) => { g && r.setMethods(g, !0); }, { immediate: !0 } ), B("slots", Pe()), B("pageManager", r), B("forms", l), B("pageSchema", C), B( "disabled", $(() => m.disabled) ); const x = te(), d = x == null ? void 0 : x.proxy; function y() { Y(() => { i.value = !0, s("ready", r), d && r.addComponentInstance("builder", d); }); } return e({ ready: i, pageManager: r, getData: c, setData: w, validate: h, getForms: a, setForms: v, validateAll: f, getFormInstance: p }), (g, S) => I(M).initialized.value ? (F(), z(ye, { key: 1, onResolve: y }, { default: D(() => [ U("div", Ze, [ (F(!0), de(Re, null, Me(C.schemas, (k, G) => (F(), z(I(We), { key: G, componentSchema: k }, null, 8, ["componentSchema"]))), 128)) ]) ]), fallback: D(() => [ U("div", Qe, [ T(I(o)) ]) ]), _: 1 })) : (F(), de("div", qe)); } }); function pe(t) { return Oe() ? (Ne(t), !0) : !1; } function Xe(t) { let e = 0, n, o; const s = () => { e -= 1, o && e <= 0 && (o.stop(), n = void 0, o = void 0); }; return (...i) => (e += 1, o || (o = Ve(!0), n = o.run(() => t(...i))), pe(s), n); } function Q(t) { return typeof t == "function" ? t() : I(t); } const je = typeof window < "u" && typeof document < "u"; typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope; const et = (t) => typeof t < "u", tt = Object.prototype.toString, nt = (t) => tt.call(t) === "[object Object]", ot = () => { }; function st(t) { return te(); } function it(t, e = !0, n) { st() ? fe(t, n) : e ? t() : Y(t); } function at(t = !1, e = {}) { const { truthyValue: n = !0, falsyValue: o = !1 } = e, s = Fe(t), i = b(t); function r(l) { if (arguments.length) return i.value = l, i.value; { const c = Q(n); return i.value = i.value === c ? Q(o) : c, i.value; } } return s ? r : [i, r]; } function $t(t, e, n) { const o = _(t, (...s) => (Y(() => o()), e(...s)), n); return o; } const ie = je ? window : void 0; function W(t) { var e; const n = Q(t); return (e = n == null ? void 0 : n.$el) != null ? e : n; } function rt(...t) { let e, n, o, s; if (typeof t[0] == "string" || Array.isArray(t[0]) ? ([n, o, s] = t, e = ie) : [e, n, o, s] = t, !e) return ot; Array.isArray(n) || (n = [n]), Array.isArray(o) || (o = [o]); const i = [], r = () => { i.forEach((h) => h()), i.length = 0; }, l = (h, a, v, f) => (h.addEventListener(a, v, f), () => h.removeEventListener(a, v, f)), c = _( () => [W(e), Q(s)], ([h, a]) => { if (r(), !h) return; const v = nt(a) ? { ...a } : a; i.push( ...n.flatMap((f) => o.map((p) => l(h, f, p, v))) ); }, { immediate: !0, flush: "post" } ), w = () => { c(), r(); }; return pe(w), w; } function lt(t) { return typeof t == "function" ? t : typeof t == "string" ? (e) => e.key === t : Array.isArray(t) ? (e) => t.includes(e.key) : () => !0; } function be(...t) { let e, n, o = {}; t.length === 3 ? (e = t[0], n = t[1], o = t[2]) : t.length === 2 ? typeof t[1] == "object" ? (e = !0, n = t[0], o = t[1]) : (e = t[0], n = t[1]) : (e = !0, n = t[0]); const { target: s = ie, eventName: i = "keydown", passive: r = !1, dedupe: l = !1 } = o, c = lt(e); return rt(s, i, (h) => { h.repeat && Q(l) || c(h) && n(h); }, r); } function le(t, e, n = {}) { return be(t, e, { ...n, eventName: "keydown" }); } function ce(t, e, n = {}) { return be(t, e, { ...n, eventName: "keyup" }); } function ct() { const t = b(!1), e = te(); return e && fe(() => { t.value = !0; }, e), t; } function ut(t) { const e = ct(); return $(() => (e.value, !!t())); } function dt(t) { return JSON.parse(JSON.stringify(t)); } function ft(t, e, n = {}) { const { window: o = ie, ...s } = n; let i; const r = ut(() => o && "ResizeObserver" in o), l = () => { i && (i.disconnect(), i = void 0); }, c = $(() => { const a = Q(t); return Array.isArray(a) ? a.map((v) => W(v)) : [W(a)]; }), w = _( c, (a) => { if (l(), r.value && o) { i = new ResizeObserver(e); for (const v of a) v && i.observe(v, s); } }, { immediate: !0, flush: "post" } ), h = () => { l(), w(); }; return pe(h), { isSupported: r, stop: h }; } function Gt(t, e = { width: 0, height: 0 }, n = {}) { const { window: o = ie, box: s = "content-box" } = n, i = $(() => { var a, v; return (v = (a = W(t)) == null ? void 0 : a.namespaceURI) == null ? void 0 : v.includes("svg"); }), r = b(e.width), l = b(e.height), { stop: c } = ft( t, ([a]) => { const v = s === "border-box" ? a.borderBoxSize : s === "content-box" ? a.contentBoxSize : a.devicePixelContentBoxSize; if (o && i.value) { const f = W(t); if (f) { const p = f.getBoundingClientRect(); r.value = p.width, l.value = p.height; } } else if (v) { const f = Array.isArray(v) ? v : [v]; r.value = f.reduce((p, { inlineSize: m }) => p + m, 0), l.value = f.reduce((p, { blockSize: m }) => p + m, 0); } else r.value = a.contentRect.width, l.value = a.contentRect.height; }, n ); it(() => { const a = W(t); a && (r.value = "offsetWidth" in a ? a.offsetWidth : e.width, l.value = "offsetHeight" in a ? a.offsetHeight : e.height); }); const w = _( () => W(t), (a) => { r.value = a ? e.width : 0, l.value = a ? e.height : 0; } ); function h() { c(), w(); } return { width: r, height: l, stop: h }; } function Tt(t, e, n, o = {}) { var s, i, r; const { clone: l = !1, passive: c = !1, eventName: w, deep: h = !1, defaultValue: a, shouldEmit: v } = o, f = te(), p = n || (f == null ? void 0 : f.emit) || ((s = f == null ? void 0 : f.$emit) == null ? void 0 : s.bind(f)) || ((r = (i = f == null ? void 0 : f.proxy) == null ? void 0 : i.$emit) == null ? void 0 : r.bind(f == null ? void 0 : f.proxy)); let m = w; m = m || `update:${e.toString()}`; const C = (y) => l ? typeof l == "function" ? l(y) : dt(y) : y, x = () => et(t[e]) ? C(t[e]) : a, d = (y) => { v ? v(y) && p(m, y) : p(m, y); }; if (c) { const y = x(), g = b(y); let S = !1; return _( () => t[e], (k) => { S || (S = !0, g.value = C(k), Y(() => S = !1)); } ), _( g, (k) => { !S && (k !== t[e] || h) && d(k); }, { deep: h } ), g; } else return $({ get() { return x(); }, set(y) { d(y); } }); } function Lt() { const { isDark: t } = ae(), e = at(t); return { isDark: t, toggleDark: e }; } function pt() { const t = b(!1); return fe(() => { mt(t), ht(t); }), _( () => t.value, () => { t.value ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark"); } ), { isDark: t }; } function mt(t) { var e = document.documentElement; e && (e.classList.contains("dark") ? t.value = !0 : t.value = !1); } function ht(t) { var e = document.querySelector("html"), n = new MutationObserver(function(o) { for (var s of o) if (s.type === "attributes" && s.attributeName === "class") { const i = s.target; new Array(...i.classList).includes("dark") ? t.value = !0 : t.value = !1; } }); n.observe(e, { attributes: !0, attributeFilter: ["class"] }), he(() => { n.disconnect(); }); } function vt() { const t = b(1), e = b(!1), { isDark: n } = pt(), { pressSpace: o, pressShift: s, pressCtrl: i } = yt(); return { canvasScale: t, pressSpace: o, pressShift: s, pressCtrl: i, disabledZoom: e, isDark: n }; } const ae = Xe(vt); function yt() { const t = b(!1), e = b(!1), n = b(!1); return le(" ", () => { t.value = !0; }), ce(" ", () => { t.value = !1; }), le("Shift", (o) => { o.preventDefault(), e.value = !0; }), ce("Shift", () => { e.value = !1; }), le("Control", (o) => { o.preventDefault(), n.value = !0; }), ce("Control", () => { n.value = !1; }), { pressSpace: t, pressShift: e, pressCtrl: n }; } function zt(t) { const { pressSpace: e } = ae(), n = new Image(1, 1); n.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="; let o = 0, s = 0; function i(c) { var w; e.value && (o = c.x, s = c.y, (w = c.dataTransfer) == null || w.setDragImage(document.createElement("div"), 0, 0)); } function r(c) { if (c.preventDefault(), !c.x || !c.y || !e.value) return; const w = c.x - o, h = c.y - s; o = c.x, s = c.y, t.value && (t.value.scrollTop -= h, t.value.scrollLeft -= w); } function l() { e.value = !1; } return { handleElementDragStart: i, handleElementDrag: r, handleElementDragEnd: l }; } function Ut(t) { const { pressCtrl: e, canvasScale: n, disabledZoom: o } = ae(); function s(i) { if (!e.value || o.value) return; i.preventDefault(); let r = 0; i.deltaY < 0 ? r = n.value + 0.05 : r = n.value - 0.05, !(r > 150 || r < 0.5) && (n.value = r); } return _( () => n.value, (i) => { t.value && !o.value && (t.value.style.transform = `scale(${i})`); } ), { handleZoom: s, canvasScale: n }; } function Jt(t, e = 16.66) { let n; function o() { s(), n = window.setInterval(t, e); } function s() { window.clearInterval(n); } return { startTimedQuery: o, stopTimedQuery: s }; } const gt = { class: "min-w-750px rounded" }, wt = { class: "h-full rounded" }, bt = /* @__PURE__ */ Z({ __name: "index", props: { hideConfirm: { type: Boolean } }, setup(t, { expose: e }) { const n = t, o = M.getComponent("monacoEditor"), s = M.getComponent("modal"), i = b(null), r = b(!1), l = b(!1), c = b({}), w = H("pageSchema"), h = b(null), a = b(""); function v() { l.value = !1; } function f() { r.value = !1; } function p() { r.value = !0, a.value = se(); } async function m() { try { let C = await h.value.validateAll(); if (!Object.keys(C).length) { alert("请添加表单组件后再尝试!"); return; } Object.keys(C).length === 1 && (C = C.default), c.value = JSON.stringify(C, null, 2), Y(() => { var x; (x = i.value) == null || x.setValue(c.value); }), l.value = !0; } catch (C) { console.error(C); } } return e({ handleOpen: p }), (C, x) => (F(), z(I(s), { modelValue: r.value, "onUpdate:modelValue": x[1] || (x[1] = (d) => r.value = d), title: "预览", class: "w-900px", width: "900px", onClose: f, onOk: m, hideConfirm: n.hideConfirm, okText: "表单数据" }, { default: D(() => [ U("div", gt, [ (F(), z(I(Ye), { key: a.value, ref_key: "kb", ref: h, "page-schema": I(w) }, null, 8, ["page-schema"])), T(I(s), { modelValue: l.value, "onUpdate:modelValue": x[0] || (x[0] = (d) => l.value = d), title: "表单数据", class: "w-860px", width: "860px", onClose: v, onOk: v }, { default: D(() => [ U("div", wt, [ T(I(o), { ref_key: "monacoEditorRef", ref: i, autoToggleTheme: "", readOnly: "", class: "h-full editor", "model-value": c.value }, null, 8, ["model-value"]) ]) ]), _: 1 }, 8, ["modelValue"]) ]) ]), _: 1 }, 8, ["modelValue", "hideConfirm"])); } }), Ct = { key: 0, class: "epic-loading-box" }, St = { class: "ai-form-designer-main" }, At = { class: "epic-header-container" }, xt = { class: "epic-loading-box" }, Ht = /* @__PURE__ */ Z({ __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 }, hidePreviewConfirm: { type: Boolean } }, emits: ["ready", "save", "reset", "toggleDeviceMode"], setup(t, { expose: e, emit: n }) { const o = L(() => import("./index-BtTbo_re.js")), s = L(() => import("./index-CUuLUlfB.js")), i = L( () => import("./index-AMwl01uD.js") ), r = L( () => import("./index-Ccgh2j7r.js") ), l = L(() => import("./index-D3ccvEyD.js")), c = we(), w = Je(), h = t; let a = { schemas: [ { type: "page", id: "root", label: "页面", children: [], componentProps: { style: { padding: "16px" } } } ], script: `const { defineExpose, find } = epic; function test (){ console.log('test') } // 通过defineExpose暴露的函数或者属性 defineExpose({ test })` }; oe(() => { if (h.defaultSchema) { a = h.defaultSchema; return; } h.formMode && (a.schemas = M.formSchemas); }), c.setDesignMode(), c.setDefaultComponentIds(a.schemas); const v = n, f = b(null), p = q({ checkedNode: null, hoverNode: null, disableHover: !1, matched: [] }), m = q({ schemas: [], script: a.script }), { disabledZoom: C } = ae(); oe(() => { C.value = h.disabledZoom; }), oe(() => { const u = m.script; u && u !== "" && c.setMethods(u); }), B("pageSchema", m), B("revoke", w), B("pageManager", c), B( "designerProps", $(() => h) ), B("designer", { setCheckedNode: d, setHoverNode: y, setDisableHover: S, handleToggleDeviceMode: K, reset: ne, state: p }); function x() { m.schemas = O(a.schemas), d(m.schemas[0]), w.push(m.schemas, "初始化撤销功能"); } async function d(u = m.schemas[0]) { p.checkedNode = u, p.matched = Te(m.schemas, u.id); } async function y(u = null) { var A; if (!u || p.disableHover) return p.hoverNode = null, !1; if ((u == null ? void 0 : u.id) === ((A = p.hoverNode) == null ? void 0 : A.id)) return !1; p.hoverNode = u; } function g() { Y(() => { v("ready", { pageManager: c }); }); } async function S(u = !1) { p.disableHover = u; } function k(u) { J(m, O(u)); } function G() { return O(m); } function ne() { ge(m.schemas, a.schemas) && m.script === a.script || (J(m.schemas, a.schemas), m.script = a.script, d(m.schemas[0]), w.push(m.schemas, "重置操作"), v("reset", m)); } function re() { v("save", G()); } function K(u) { v("toggleDeviceMode", u); } function X() { f.value.handleOpen(); } return x(), e({ revoke: w, setData: k, getData: G, reset: ne, preview: X }), (u, A) => I(M).initialized.value ? (F(), z(ye, { key: 1, onResolve: g }, { default: D(() => [ U("div", St, [ U("div", At, [ N(u.$slots, "header", {}, () => [ h.hiddenHeader ? ve("", !0) : (F(), z(I(o), { key: 0, onPreview: X, onSave: re }, { header: D(() => [ N(u.$slots, "header-prefix") ]), prefix: D(() => [ N(u.$slots, "header-prefix") ]), title: D(() => [ N(u.$slots, "header-title") ]), "right-prefix": D(() => [ N(u.$slots, "header-right-prefix") ]), "right-action": D(() => [ N(u.$slots, "header-right-action") ]), "right-suffix": D(() => [ N(u.$slots, "header-right-suffix") ]), _: 3 })) ]) ]), U("div", { class: Be(["epic-split-view-container", { "hidden-header": u.hiddenHeader }]) }, [ T(I(s)), T(I(i)), T(I(r)) ], 2), T(bt, { hideConfirm: h.hidePreviewConfirm, ref_key: "previewRef", ref: f }, null, 8, ["hideConfirm"]) ]) ]), fallback: D(() => [ U("div", xt, [ T(I(l)) ]) ]), _: 3 })) : (F(), de("div", Ct)); } }), Et = { component: async () => await import("./index-DR2ea5-n.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" }, It = { component: async () => await import("./index-KXG0ExdR.js"), defaultSchema: { label: "页面", type: "page", componentProps: {}, children: [] }, config: { attribute: [ { label: "页面名称", type: "input", componentProps: { placeholder: "请输入" }, field: "componentProps.name" } ] } }; function kt(t) { t.component("EInputSize", async () => await import("./index-DXALZsBA.js")), t.component("EColEditor", async () => await import("./index-DILhizY-.js")), t.component("EActionEditor", async () => await import("./index-CnqUFHQH.js")), t.component("ERuleEditor", async () => await import("./index-TwN-wYTG.js")), t.component("EOptionsEditor", async () => await import("./index-BKU7YVCn.js")), t.component("SelectPanel", async () => await import("./index-DKFURQzL.js")), t.component("CasPanel", async () => await import("./index-Cz3cUe0B.js")), t.component("RelSelectPanel", async () => await import("./index-CvhQ_FOb.js")), t.component("DepartmentPanel", async () => await import("./index-CvvbIECp.js")), t.component("DocumentNumberRule", async () => await import("./index-CqrhHEgJ.js")), t.component("ENode", async () => await import("./index-DbdrIMhY.js")), t.registerActivitybar({ id: "component_view", title: "组件", icon: "icon--epic--extension-outline", component: async () => await import("./index-uX1eaB8k.js") }), t.registerActivitybar({ id: "sound_code_view", title: "源码", icon: "icon--epic--sdk-outline-rounded", component: async () => await import("./index-CzSduAcG.js") }), t.registerActivitybar({ id: "outline_view", title: "大纲", icon: "icon--epic--account-tree-outline-rounded", component: async () => await import("./outline-sg7qRW7N.js") }), t.registerRightSidebar({ id: "attribute_view", title: "属性", component: async () => await import("./attributeView-tiP9N2ZF.js") }), t.registerRightSidebar({ id: "style_view", title: "样式", component: async () => await import("./styleView-mMWvXZ8h.js") }), t.registerRightSidebar({ id: "event_view", title: "事件", component: async () => await import("./eventView-B9HhboCj.js") }), [Et, It].forEach((n) => { t.registerComponent(n); }); } kt(M); export { Te as A, Vt as B, Le as C, ee as D, ze as E, j as F, $e as G, Ge as H, yt as I, pt as J, mt as K, vt as L, Ue as P, We as _, Jt as a, ft as b, Nt as c, J as d, zt as e, Ot as f, Pt as g, Gt as h, Ut as i, Bt as j, se as k, Ft as l, O as m, Tt as n, ge as o, M as p, Rt as q, Lt as r, Mt as s, Ye as t, ae as u, Ht as v, $t as w, we as x, Je as y, L as z };