UNPKG

snowy-designer

Version:

基于Epic-Designer-Pro版本的设计器,可视化开发页面表单

2 lines (1 loc) 6.47 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("vue");;/* empty css */require("radix-vue");require("clsx");require("tailwind-merge");require("lucide-vue-next");require("../../../ui-kit/base-ui/src/shadch-ui/button/index.cjs");require("@vueuse/core");require("../../../ui-kit/base-ui/src/shadch-ui/toast/index.cjs");require("vuedraggable");const p=require("./string.cjs");require("../../../hooks/src/store/index.cjs");require("lodash");const A=require("../manager/pluginManager.cjs");require("monaco-editor");require("../request/index.cjs");function d(i,s=new WeakMap){if(typeof i!="object"||i===null)return i;if(s.has(i))return s.get(i);if(Array.isArray(i)){const r=i.map(e=>d(e,s));return s.set(i,r),r}const t={};return s.set(i,t),Object.keys(i).forEach(r=>{t[r]=d(i[r],s)}),t}function q(i,s=[]){const[t]=S([d(i)],r=>{var o,a;let e=0,n=`${r.type}_${p.getUUID(4,"number")}`;for(;u(s,f=>f.id===n,!0);){if(e++,e>=50)throw new Error(`ID冲突,已尝试 ${e} 次,无法生成唯一ID`);n=`${r.type}_${p.getUUID(4,"number")}`}const l={...r,id:n};return(l.field||l.input)&&!((a=(o=A.pluginManager.getComponentConfingByType(l.type))==null?void 0:o.editConstraints)!=null&&a.fixedField)&&(l.field=l.id),l});return t}function g(i,s,t=!0){const r=i;for(const[e,n]of Object.entries(s))r[e]&&n&&typeof r[e]=="object"&&typeof n=="object"?(Array.isArray(r[e])&&!Array.isArray(n)?r[e]={}:!Array.isArray(r[e])&&Array.isArray(n)&&(r[e]=[]),g(r[e],n,t)):r[e]=n;t&&Object.keys(r).reverse().forEach(e=>{Object.prototype.hasOwnProperty.call(s,e)||(Array.isArray(r)?r.splice(Number(e),1):delete r[e])})}function b(i,s,t=[],r=new WeakMap){const e=n=>{if(Array.isArray(n))return n.map(e);if(typeof n=="object"&&n!==null){if(r.has(n))return"[Circular]";r.set(n,!0);const l=Object.keys(n).sort(),o={};return l.forEach(a=>{t.includes(a)||(o[a]=e(n[a]))}),r.delete(n),o}else return n};return JSON.stringify(e(i))===JSON.stringify(e(s))}function I(i,s){const t=[];let r=!1;function e(n){if(!r){if(t.push(n),n.id===s){r=!0;return}if(n.children&&n.children.length>0){for(let l=0;l<n.children.length;l++)if(e(n.children[l]),r)return}if(n.slots){for(const l in n.slots)for(let o=0;o<n.slots[l].length;o++)if(e(n.slots[l][o]),r)return}r||t.pop()}}for(const n of i){if(r)break;e(n)}return r||console.error(`没有查询到id为${s}的节点`),t}function C(i,s,t){const r=s.split(".");let e=i;for(const n of r){if(e==null)return t;e=e[n]}return e===void 0?t:e}function k(i,s,t){const r=s.replaceAll(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let e=i;for(let n=0;n<r.length-1;n++){const l=r[n];e[l]==null&&(e[l]=Number.isNaN(Number(r[n+1]))?{}:[]),e=e[l]}return e[r[r.length-1]]=t,i}function F(i,s="default"){return w(i,s).map(r=>r.field)}function w(i,s="default"){const t=u(i,e=>{var n;return e.type==="form"&&(((n=e.componentProps)==null?void 0:n.name)??e.name===s)},!0);return u((t==null?void 0:t.children)??[],e=>!!e.input,!1,e=>e.type!=="subform")}function u(i,s,t=!1,r){const e=[],n=[...i];for(;n.length;){const l=n.pop();if(l!=null&&l.children&&(!r||r(l))&&n.push(...l.children),l!=null&&l.slots&&(!r||r(l)))for(const o in l.slots)n.push(...l.slots[o]);if(s(l)&&(e.push(l),t))return l}return t?!1:e}function S(i,s,t){const r=[...i];for(;r.length;){const e=r.pop();if(e!=null&&e.children&&(!t||t(e))&&r.push(...e.children),e!=null&&e.slots&&(!t||t(e)))for(const n in e.slots)r.push(...e.slots[n]);g(e,s(e))}return i}function B(i,s){const t=u(i,r=>r.id===s,!0);return t||null}function x(i,s){const t=[{type:"",children:i}];let r=0,e=null;const n=u(t,l=>{if(e=l.children??null,!e){if(l!=null&&l.slots)for(const o in l.slots){e=l.slots[o];for(const[a,f]of e.entries())if(f.id===s)return r=a,!0}return!1}for(const[o,a]of e.entries())if(a.id===s)return r=o,!0;return!1},!0);if(!e)throw new Error(`没有查询到id为${s}的节点`);return{index:r,parentSchema:n,schema:e[r],list:e}}function M(i){i.config||(i.config={});const s={schemas:[{componentProps:{style:{padding:"16px"}},id:"root",label:"页面",type:"page",children:[{label:"表单",type:"form",icon:"epic-icon-daibanshixiang",labelWidth:i.config.labelWidth||100,name:"default",componentProps:{colon:i.config.colon||!0,hideRequiredMark:i.config.hideRequiredMark||!1,labelAlign:i.config.labelAlign||"right",labelCol:i.config.labelCol||{span:5},labelLayout:i.config.labelLayout==="flex"?"fixed":"flex",labelWidth:i.config.labelWidth||100,layout:i.config.layout||"horizontal",size:i.config.size||"middle",wrapperCol:i.config.wrapperCol||{span:19}},children:[],id:`form_${p.getUUID()}`}]}],script:i.script||""};if(s.schemas&&s.schemas.length>0){const t=s.schemas[0];if(t.children&&t.children.length>0){const r=t.children[0];i.list&&(r.children=c(i.list))}}return s}function c(i,s){return i.map(t=>{var a,f,m;let r=t.type??"";const e=t.options??{},n=(h,y)=>{r===h&&(r=y,e.defaultValue&&(e.defaultValue=JSON.parse(e.defaultValue)))};if(n("uploadImg","upload-image"),n("uploadFile","upload-file"),r==="date"&&e.range&&(e.type="daterange",delete e.range),(r==="date"||r==="time")&&(e.valueFormat=e.format),r==="textarea"){const{maxRows:h,minRows:y}=e;e.autoSize={maxRows:h,minRows:y},delete e.minRows,delete e.maxRows}r==="number"&&!e.precision&&delete e.precision,e.width&&(e.style={width:e.width},delete e.width),r==="grid"&&(r="row"),s&&s.type==="grid"&&(r="col",e.span=t.span,t.key=p.getUUID());const l={componentProps:e,field:t.model,icon:t.icon||"",id:t.key,label:t.label,type:r};return(e.noFormItem||!e.showLabel)&&(l.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(r)&&(l.input=!0,((f=(a=t.rules)==null?void 0:a[0])==null?void 0:f.required)===!1&&t.rules.shift(),((m=t.rules)==null?void 0:m.length)>0&&(l.rules=t.rules)),t.list&&(l.children=c(t.list,t)),t.columns&&(l.children=c(t.columns,t)),t.trs&&(l.children=c(t.trs,t)),t.tds&&(l.children=c(t.tds,t)),l})}exports.convertKFormData=M;exports.deepClone=d;exports.deepCompareAndModify=g;exports.deepEqual=b;exports.findSchemaById=B;exports.findSchemaInfoById=x;exports.findSchemas=u;exports.generateNewSchema=q;exports.getFormFields=F;exports.getFormSchemas=w;exports.getMatchedById=I;exports.getValueByPath=C;exports.mapSchemas=S;exports.recursionConvertedNode=c;exports.setValueByPath=k;