epic-designer
Version:
基于vue3的设计器,可视化开发页面表单
2 lines (1 loc) • 8.98 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("vue");;/* empty css */;/* empty css */;/* empty css */;/* empty css */require("vue-draggable-plus");const w=require("./string.cjs");require("../../../git/epic/epic-designer/node_modules/.pnpm/jsep@1.4.0/node_modules/jsep/dist/jsep.cjs");require("@vueuse/core");require("../../../hooks/src/store/index.cjs");const k=require("../../../manager/src/pluginManager.cjs");function A(r,i=!0,n=new WeakMap){if(typeof r!="object"||r===null)return r;if(n.has(r))return n.get(r);if(i&&typeof window.structuredClone=="function"){const e=d(r);return structuredClone(e)}if(Array.isArray(r)){const e=r.map(l=>A(l,i,n));return n.set(r,e),e}const t={};return n.set(r,t),Object.keys(r).forEach(e=>{t[e]=A(r[e],i,n)}),t}function d(r,i=new WeakMap){if(r===null||typeof r!="object")return r;if(i.has(r))return i.get(r);const n=S.isProxy(r)?S.toRaw(r):r;if(i.set(r,n),Array.isArray(n)){let l;for(let s=0;s<n.length;s++){const o=n[s];if(o!==null&&typeof o=="object"&&(l=d(o,i),l!==o)){const f=n.slice(0,s);f.push(l);for(let a=s+1;a<n.length;a++){const u=n[a];f.push(u!==null&&typeof u=="object"?d(u,i):u)}return f}}return n}let t=null;const e=Object.keys(n);for(const l of e){const s=n[l];if(s!==null&&typeof s=="object"){const o=S.isRef(s)?d(s.value,i):d(s,i);o!==s&&(t||(t={...n}),t[l]=o)}}return t||n}function q(r,i=[]){const[n]=B([A(r)],t=>{var o,f;let e=0,l=`${t.type}_${w.getUUID(4,"number")}`;for(;p(i,a=>a.id===l,!0);){if(e++,e>=50)throw new Error(`ID冲突,已尝试 ${e} 次,无法生成唯一ID`);l=`${t.type}_${w.getUUID(4,"number")}`}const s={...t,id:l};return(s.field||s.input)&&!((f=(o=k.pluginManager.component.getConfigByType(s.type))==null?void 0:o.editConstraints)!=null&&f.fixedField)&&(s.field=s.id),s});return n}function I(r,i,n=!0){const t=r;for(const[e,l]of Object.entries(i))t[e]&&l&&typeof t[e]=="object"&&typeof l=="object"?(Array.isArray(t[e])&&!Array.isArray(l)?t[e]={}:!Array.isArray(t[e])&&Array.isArray(l)&&(t[e]=[]),I(t[e],l,n)):t[e]=l;n&&Object.keys(t).reverse().forEach(e=>{Object.prototype.hasOwnProperty.call(i,e)||(Array.isArray(t)?t.splice(Number(e),1):delete t[e])})}function m(r,i,n=[],t=new WeakMap){if(Object.is(r,i))return!0;if(typeof r!="object"||r===null||typeof i!="object"||i===null)return!1;if(t.has(r))return t.get(r)===i;if(t.has(i))return t.get(i)===r;t.set(r,i),t.set(i,r);let e=!1;try{if(r instanceof Date&&i instanceof Date)return e=r.getTime()===i.getTime(),e;if(r instanceof RegExp&&i instanceof RegExp)return e=r.source===i.source&&r.flags===i.flags,e;if(r instanceof Map&&i instanceof Map){if(r.size!==i.size)return e=!1,e;for(const[c,h]of r)if(!i.has(c)||!m(h,i.get(c),n,t))return e=!1,e;return e=!0,e}if(r instanceof Set&&i instanceof Set){if(r.size!==i.size)return e=!1,e;const c=Array.from(i);for(const h of r){const C=c.findIndex(T=>m(h,T,n,t));if(C===-1)return e=!1,e;c.splice(C,1)}return e=!0,e}const l=Array.isArray(r),s=Array.isArray(i);if(l!==s)return e=!1,e;if(l&&s){if(r.length!==i.length)return e=!1,e;for(const[c,h]of r.entries())if(!m(h,i[c],n,t))return e=!1,e;return e=!0,e}const o=r,f=i,a=c=>Object.keys(c).filter(h=>!n.includes(h)),u=a(o),g=a(f);if(u.length!==g.length)return e=!1,e;for(const c of u)if(!Object.prototype.hasOwnProperty.call(f,c)||!m(o[c],f[c],n,t))return e=!1,e;return e=!0,e}finally{t.delete(r),t.delete(i)}}function F(r,i){const n=[];let t=!1;function e(l){if(n.push(l),l.id===i&&(t=!0),!t&&l.children&&l.children.length>0)for(let s=0;s<l.children.length&&(e(l.children[s]),!t);s++);if(!t&&l.slots)for(const s in l.slots)for(let o=0;o<l.slots[s].length&&(e(l.slots[s][o]),!t);o++);t||n.pop()}return r.forEach(e),t||console.error(`没有查询到id为${i}的节点`),n}function M(r,i,n){if(!i)return n;const t=i.split(".");let e=r;for(const l of t){if(e==null)return n;e=e[l]}return e===void 0?n:e}function P(r,i,n){if(!i)return r;const t=i.replaceAll(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let e=r;for(let l=0;l<t.length-1;l++){const s=t[l];e[s]==null&&(e[s]=Number.isNaN(Number(t[l+1]))?{}:[]),e=e[s]}return e[t[t.length-1]]=n,r}function V(r,i="default"){return x(r,i).map(t=>t.field)}function x(r,i="default"){const n=p(r,e=>{var l;return e.type==="form"&&(((l=e.props)==null?void 0:l.name)??e.name===i)},!0);return p((n==null?void 0:n.children)??[],e=>!!e.input,!1,e=>e.type!=="subform")}function p(r,i,n=!1,t){const e=[],l=[...r];for(;l.length>0;){const s=l.pop();if(s!=null&&s.children&&(!t||t(s))&&l.push(...s.children),s!=null&&s.slots&&(!t||t(s)))for(const o in s.slots)l.push(...s.slots[o]);if(i(s)&&(e.push(s),n))return s}return n?!1:e}function B(r,i,n){const t=[...r];for(;t.length>0;){const e=t.pop();if(e!=null&&e.children&&(!n||n(e))&&t.push(...e.children),e!=null&&e.slots&&(!n||n(e)))for(const l in e.slots)t.push(...e.slots[l]);I(e,i(e))}return r}function R(r,i){const n=p(r,t=>(t==null?void 0:t.id)===i,!0);return n||null}function E(r,i){const n=[{type:"",children:r}];let t=0,e=null;const l=p(n,s=>{if(e=s.children??null,!e){if(s!=null&&s.slots)for(const o in s.slots){e=s.slots[o];for(const[f,a]of e.entries())if(a.id===i)return t=f,!0}return!1}for(const[o,f]of e.entries())if(f.id===i)return t=o,!0;return!1},!0);if(!e)throw new Error(`没有查询到id为${i}的节点`);return{index:t,parentSchema:l,schema:e[t],list:e}}function z(r){r.config||(r.config={});const i={schemas:[{id:"root",label:"页面",type:"page",children:[{label:"表单",type:"form",icon:"epic-icon-daibanshixiang",labelWidth:r.config.labelWidth||100,name:"default",props:{colon:r.config.colon||!0,hideRequiredMark:r.config.hideRequiredMark||!1,labelAlign:r.config.labelAlign||"right",labelCol:r.config.labelCol||{span:5},labelLayout:r.config.labelLayout==="flex"?"fixed":"flex",labelWidth:r.config.labelWidth||100,layout:r.config.layout||"horizontal",size:r.config.size||"middle",wrapperCol:r.config.wrapperCol||{span:19}},children:[],id:`form_${w.getUUID()}`}]}],script:r.script||""};if(i.schemas&&i.schemas.length>0){const n=i.schemas[0];if(n.children&&n.children.length>0){const t=n.children[0];r.list&&(t.children=y(r.list))}}return i}function y(r,i){return r.map(n=>{var f,a;let t=n.type??"";const e=n.options??{},l=(u,g)=>{t===u&&(t=g,typeof e.defaultValue=="string"&&(e.defaultValue=JSON.parse(e.defaultValue)))};if(l("uploadImg","upload-image"),l("uploadFile","upload-file"),t==="date"&&e.range&&(e.type="daterange",delete e.range),(t==="date"||t==="time")&&(e.valueFormat=e.format),t==="textarea"){const{maxRows:u,minRows:g}=e;e.autoSize={maxRows:u,minRows:g},delete e.minRows,delete e.maxRows}t==="number"&&!e.precision&&delete e.precision,e.width&&(e.style={width:e.width},delete e.width),t==="grid"&&(t="row"),i&&i.type==="grid"&&(t="col",e.span=n.span,n.key=w.getUUID());const s={field:n.model,icon:n.icon||"",id:n.key,label:n.label,props:e,type:t};return(e.noFormItem||!e.showLabel)&&(s.noFormItem=!0,delete e.noFormItem,delete e.showLabel),e.clearable&&(e.allowClear=!0,delete e.clearable),["input","textarea","number","password","select","cascader","checkbox","radio","date","time","slider","switch","color-picker","upload-file","upload-image"].includes(t)&&(s.input=!0,((a=(f=n.rules)==null?void 0:f[0])==null?void 0:a.required)===!1&&n.rules.shift(),n.rules&&n.rules.length>0&&(s.rules=n.rules)),n.list&&(s.children=y(n.list,n)),n.columns&&(s.children=y(n.columns,n)),n.trs&&(s.children=y(n.trs,n)),n.tds&&(s.children=y(n.tds,n)),s})}function D(r,i=!1){var e,l;let n=!1;p(r.schemas,s=>(s.componentProps&&(s.props=s.componentProps,delete s.componentProps,n=!0),!1)),n&&i&&console.warn("[Epic] PageSchema中的componentProps属性已迁移到props,请使用新版本设计器更新数据");const t=(l=(e=r.schemas[0])==null?void 0:e.props)==null?void 0:l.style;return(t==null?void 0:t.padding)==="16px"&&delete t.padding,r}function U(r,i=[]){return p(r.schemas,t=>t.type==="form").forEach(t=>{var s;if(!((s=t.children)!=null&&s.length))return;const e=[],l=p(t.children,o=>{const f=k.pluginManager.component.getConfigByType(o.type),a=!!(o.input&&f&&!f.isSubTable);return a&&i.includes(o.type)&&(o.class="ep-full-width"),a},!1,o=>{const f=k.pluginManager.component.getConfigByType(o.type);return f!=null&&f.isSubTable?(o.class="ep-sub-table ep-full-width",e.push(o),!1):!0});t.children=l.reverse(),t.children.push(...e)}),r}exports.convertKFormData=z;exports.deepClone=A;exports.deepCompareAndModify=I;exports.deepEqual=m;exports.deepToRaw=d;exports.findSchemaById=R;exports.findSchemaInfoById=E;exports.findSchemas=p;exports.generateNewSchema=q;exports.getFormFields=V;exports.getFormSchemas=x;exports.getMatchedById=F;exports.getValueByPath=M;exports.mapSchemas=B;exports.migrateComponentProps=D;exports.recursionConvertedNode=y;exports.reorganizeSchemasForTableView=U;exports.setValueByPath=P;