UNPKG

epic-designer

Version:

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

2 lines (1 loc) 3.54 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("vue"),F=require("../../../utils/src/common/component.cjs");require("@vueuse/core");require("../store/index.cjs");require("../../../manager/src/pluginManager.cjs");require("../../../git/epic/epic-designer/node_modules/.pnpm/jsep@1.4.0/node_modules/jsep/dist/jsep.cjs");function H(){let l=[];const r={};let d={};const p={},m=new Map,f=V.ref([]);let a=[],c=["表单","布局"];function G(e){l.push(e)}function x(){d={}}function C(){c=[],u()}function h(e){l=e}function v(e,t){d[e]=t}function M(e){a=e,u()}function S(e,t,n=99){(m.get(e)??99)>n||(m.set(e,n),typeof t=="function"&&(t=F.loadAsyncComponent(t)),p[e]=t)}function u(){const e=[];Object.values(r).forEach(t=>{if(!a.includes(t.defaultSchema.type)&&t.groupName){const n=d[t.groupName]??t.groupName;let o=e.findIndex(i=>i.title===n);o===-1&&(e.push({title:n,list:[]}),o=e.length-1);const s=e[o].list.findIndex(i=>i.type===t.defaultSchema.type);s===-1?e[o].list.push(t.defaultSchema):e[o].list[s]=t.defaultSchema}}),e.sort((t,n)=>{const o=c.indexOf(t.title),s=c.indexOf(n.title);return o===-1?1:s===-1?-1:o-s}),e.forEach(t=>{t.list.sort((n,o)=>{var g,b;const s=((g=r[n.type])==null?void 0:g.sort)??1e3,i=((b=r[o.type])==null?void 0:b.sort)??1e3;return s-i})}),f.value=e}function N(e){return p[e]}function P(e){var t;return((t=r[e])==null?void 0:t.defaultSchema.label)??""}function q(e){var t;return((t=r[e])==null?void 0:t.icon)??"icon--epic--component"}function B(e){var t,n;return(n=(t=r[e])==null?void 0:t.editConstraints)==null?void 0:n.locked}function A(e){return r[e]}function I(){return r}function w(){return p}function E(){return f}function O(e){a.push(e),u()}function j(e){S(e.defaultSchema.type,e.component,e.priority),e.config.action||(e.config.action=[]),e.defaultSchema.input&&e.config.action.unshift({argsConfigs:[{...e.defaultSchema,field:"0",label:"设置数据"}],description:"设置值",type:"setValue"},{description:"获取值",type:"getValue"});const t=[...e.config.attribute||[]].filter(({field:n})=>String(n).startsWith("props"));e.config.action.push({argsConfigs:[{field:"0",label:"选择属性",props:{clearable:!0,options:t.map(({field:n,label:o})=>({label:o,value:String(n).replace("props.","")})),placeholder:"请选择"},type:"select"},...t.map((n,o)=>{const s=String(n.field).replace("props.","");return{field:String(o+1),label:n.label||"属性值",props:n.props,show:({values:i})=>i[0]===s,type:n.type||"input"}})],description:"修改属性",type:"setAttr"}),e.defaultSchema.componentProps&&(e.defaultSchema.props=e.defaultSchema.componentProps,delete e.defaultSchema.componentProps,console.warn(`[Epic] 注册组件 ${e.defaultSchema.type} 的 componentProps 属性已被弃用,请使用 props 代替。`)),r[e.defaultSchema.type]=e,u()}function k(){l.forEach(e=>{y(e)}),h([]),u()}function y(e){delete r[e],delete p[e]}function L(e){c=e,u()}function T(e){a=a.filter(t=>t!==e),u()}return{addBaseComponentType:G,addComponent:S,baseComponentTypes:l,clearComponentGroupNameMap:x,clearSortedGroups:C,componentConfigs:r,componentGroupNameMap:d,components:p,componentSchemaGroups:f,getComponent:N,getComponentConfigByType:A,getComponentConfigs:I,getComponents:w,getComponentSchemaGroups:E,getIcon:q,getLabel:P,getLocked:B,hiddenComponents:a,hideComponent:O,registerComponent:j,removeBaseComponents:k,removeComponent:y,setBaseComponentTypes:h,setComponentGroupNameMap:v,setHideComponents:M,setSortedGroups:L,showComponent:T,sortedGroups:c}}exports.useComponentManager=H;