UNPKG

epic-designer

Version:

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

2 lines (1 loc) 7.45 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("vue");;/* empty css */;/* empty css */;/* empty css */;/* empty css */require("vue-draggable-plus");const h=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 I=require("../../../manager/src/pluginManager.cjs");function y(n,l=!0,r=new WeakMap){if(typeof n!="object"||n===null)return n;if(r.has(n))return r.get(n);if(l&&typeof window.structuredClone=="function"){const e=p(n);return structuredClone(e)}if(Array.isArray(n)){const e=n.map(i=>y(i,l,r));return r.set(n,e),e}const t={};return r.set(n,t),Object.keys(n).forEach(e=>{t[e]=y(n[e],l,r)}),t}function p(n,l=new WeakMap){if(n===null||typeof n!="object")return n;if(l.has(n))return l.get(n);const r=m.isProxy(n)?m.toRaw(n):n;if(l.set(n,r),Array.isArray(r)){let i;for(let o=0;o<r.length;o++){const s=r[o];if(s!==null&&typeof s=="object"&&(i=p(s,l),i!==s)){const f=r.slice(0,o);f.push(i);for(let a=o+1;a<r.length;a++){const c=r[a];f.push(c!==null&&typeof c=="object"?p(c,l):c)}return f}}return r}let t=null;const e=Object.keys(r);for(const i of e){const o=r[i];if(o!==null&&typeof o=="object"){const s=m.isRef(o)?p(o.value,l):p(o,l);s!==o&&(t||(t={...r}),t[i]=s)}}return t||r}function S(n,l=[]){const[r]=A([y(n)],t=>{var s,f;let e=0,i=`${t.type}_${h.getUUID(4,"number")}`;for(;u(l,a=>a.id===i,!0);){if(e++,e>=50)throw new Error(`ID冲突,已尝试 ${e} 次,无法生成唯一ID`);i=`${t.type}_${h.getUUID(4,"number")}`}const o={...t,id:i};return(o.field||o.input)&&!((f=(s=I.pluginManager.component.getConfigByType(o.type))==null?void 0:s.editConstraints)!=null&&f.fixedField)&&(o.field=o.id),o});return r}function w(n,l,r=!0){const t=n;for(const[e,i]of Object.entries(l))t[e]&&i&&typeof t[e]=="object"&&typeof i=="object"?(Array.isArray(t[e])&&!Array.isArray(i)?t[e]={}:!Array.isArray(t[e])&&Array.isArray(i)&&(t[e]=[]),w(t[e],i,r)):t[e]=i;r&&Object.keys(t).reverse().forEach(e=>{Object.prototype.hasOwnProperty.call(l,e)||(Array.isArray(t)?t.splice(Number(e),1):delete t[e])})}function k(n,l,r=[],t=new WeakMap){const e=i=>{if(Array.isArray(i))return i.map(e);if(typeof i=="object"&&i!==null){if(t.has(i))return"[Circular]";t.set(i,!0);const o=Object.keys(i).sort(),s={};return o.forEach(f=>{r.includes(f)||(s[f]=e(i[f]))}),t.delete(i),s}else return i};return JSON.stringify(e(n))===JSON.stringify(e(l))}function C(n,l){const r=[];let t=!1;function e(i){if(r.push(i),i.id===l&&(t=!0),!t&&i.children&&i.children.length>0)for(let o=0;o<i.children.length&&(e(i.children[o]),!t);o++);if(!t&&i.slots)for(const o in i.slots)for(let s=0;s<i.slots[o].length&&(e(i.slots[o][s]),!t);s++);t||r.pop()}return n.forEach(e),t||console.error(`没有查询到id为${l}的节点`),r}function q(n,l,r){if(!l)return r;const t=l.split(".");let e=n;for(const i of t){if(e==null)return r;e=e[i]}return e===void 0?r:e}function P(n,l,r){if(!l)return n;const t=l.replaceAll(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let e=n;for(let i=0;i<t.length-1;i++){const o=t[i];e[o]==null&&(e[o]=Number.isNaN(Number(t[i+1]))?{}:[]),e=e[o]}return e[t[t.length-1]]=r,n}function F(n,l="default"){return b(n,l).map(t=>t.field)}function b(n,l="default"){const r=u(n,e=>{var i;return e.type==="form"&&(((i=e.props)==null?void 0:i.name)??e.name===l)},!0);return u((r==null?void 0:r.children)??[],e=>!!e.input,!1,e=>e.type!=="subform")}function u(n,l,r=!1,t){const e=[],i=[...n];for(;i.length>0;){const o=i.pop();if(o!=null&&o.children&&(!t||t(o))&&i.push(...o.children),o!=null&&o.slots&&(!t||t(o)))for(const s in o.slots)i.push(...o.slots[s]);if(l(o)&&(e.push(o),r))return o}return r?!1:e}function A(n,l,r){const t=[...n];for(;t.length>0;){const e=t.pop();if(e!=null&&e.children&&(!r||r(e))&&t.push(...e.children),e!=null&&e.slots&&(!r||r(e)))for(const i in e.slots)t.push(...e.slots[i]);w(e,l(e))}return n}function x(n,l){const r=u(n,t=>t.id===l,!0);return r||null}function B(n,l){const r=[{type:"",children:n}];let t=0,e=null;const i=u(r,o=>{if(e=o.children??null,!e){if(o!=null&&o.slots)for(const s in o.slots){e=o.slots[s];for(const[f,a]of e.entries())if(a.id===l)return t=f,!0}return!1}for(const[s,f]of e.entries())if(f.id===l)return t=s,!0;return!1},!0);if(!e)throw new Error(`没有查询到id为${l}的节点`);return{index:t,parentSchema:i,schema:e[t],list:e}}function O(n){n.config||(n.config={});const l={schemas:[{id:"root",label:"页面",props:{style:{padding:"16px"}},type:"page",children:[{label:"表单",type:"form",icon:"epic-icon-daibanshixiang",labelWidth:n.config.labelWidth||100,name:"default",props:{colon:n.config.colon||!0,hideRequiredMark:n.config.hideRequiredMark||!1,labelAlign:n.config.labelAlign||"right",labelCol:n.config.labelCol||{span:5},labelLayout:n.config.labelLayout==="flex"?"fixed":"flex",labelWidth:n.config.labelWidth||100,layout:n.config.layout||"horizontal",size:n.config.size||"middle",wrapperCol:n.config.wrapperCol||{span:19}},children:[],id:`form_${h.getUUID()}`}]}],script:n.script||""};if(l.schemas&&l.schemas.length>0){const r=l.schemas[0];if(r.children&&r.children.length>0){const t=r.children[0];n.list&&(t.children=d(n.list))}}return l}function d(n,l){return n.map(r=>{var f,a;let t=r.type??"";const e=r.options??{},i=(c,g)=>{t===c&&(t=g,typeof e.defaultValue=="string"&&(e.defaultValue=JSON.parse(e.defaultValue)))};if(i("uploadImg","upload-image"),i("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:c,minRows:g}=e;e.autoSize={maxRows:c,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"),l&&l.type==="grid"&&(t="col",e.span=r.span,r.key=h.getUUID());const o={field:r.model,icon:r.icon||"",id:r.key,label:r.label,props:e,type:t};return(e.noFormItem||!e.showLabel)&&(o.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)&&(o.input=!0,((a=(f=r.rules)==null?void 0:f[0])==null?void 0:a.required)===!1&&r.rules.shift(),r.rules&&r.rules.length>0&&(o.rules=r.rules)),r.list&&(o.children=d(r.list,r)),r.columns&&(o.children=d(r.columns,r)),r.trs&&(o.children=d(r.trs,r)),r.tds&&(o.children=d(r.tds,r)),o})}function M(n,l=!1){let r=!1;return u(n.schemas,t=>(t.componentProps&&(t.props=t.componentProps,delete t.componentProps,r=!0),!1)),r&&l&&console.warn("[Epic] PageSchema中的componentProps属性已迁移到props,请使用新版本设计器更新数据"),n}exports.convertKFormData=O;exports.deepClone=y;exports.deepCompareAndModify=w;exports.deepEqual=k;exports.deepToRaw=p;exports.findSchemaById=x;exports.findSchemaInfoById=B;exports.findSchemas=u;exports.generateNewSchema=S;exports.getFormFields=F;exports.getFormSchemas=b;exports.getMatchedById=C;exports.getValueByPath=q;exports.mapSchemas=A;exports.migrateComponentProps=M;exports.recursionConvertedNode=d;exports.setValueByPath=P;