@harbor-design/proform 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +117 -113
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var G=(n,e,t)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>(G(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class c{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function y(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const o=new Map;for(let[l,u]of s)o.set(t(l),t(u));return o}if(s instanceof Set){const o=new Set;for(let l of s)o.add(t(l));return o}if(e.has(s))return e.get(s);if(Array.isArray(s)){const o=[];e.set(s,o);for(let l=0;l<s.length;l++)o[l]=t(s[l]);return o}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let o in s)s.hasOwnProperty(o)&&(r[o]=t(s[o]));return r}return t(n)}function $(n,e){return n.replace(/undefined/g,e)}class K{constructor(e){a(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,Object.assign(this.runtimeCore.native,this.formCustomization.native),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps),Object.assign(this.runtimeCore.runtimeSetters,this.formCustomization.runtimeSetters),this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{i.isRef(e)?i.watch(()=>e.value,()=>{p(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):i.isReactive(e)?i.watch(()=>e,()=>{p(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):p(this.runtimeCore.model.value,e)},{lazy:!0})}}class C{constructor(){a(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e,t={lazy:!1}){return!t.lazy&&e(),this.effects.add(e),()=>this.effects.delete(e)}}class W{constructor(e){a(this,"runtimeCore");a(this,"processedSchemas");a(this,"processedModel");a(this,"getRuntimeMeta");a(this,"stableSchemas",[]);a(this,"stableModel",{});a(this,"schemaPreset",E.schemaPreset);a(this,"componentPropsPreset",E.componentPropsPreset);a(this,"stableUpdaterProcessProgress");a(this,"stableUpdaterTimes",0);a(this,"schemaEffect",new C);a(this,"defaultValueEffect",new C);a(this,"defaultValueInprogressMap",new Map);a(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){c.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(y(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!c.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!c.isProcessInprogress(t)&&c.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,o=Array.from({length:Object.keys(e).filter(u=>u!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(u){const f=u.index,d=u.key,I=u.keyIndex;if(!u.stable)return;const w=r.parseStable(u.stable),S=s==null?void 0:s.index,g=s==null?void 0:s.key;let h=w;if(c.isProcessInprogress(h)||(o[I]=!0),s){let m=r.processedSchemas.value[S][g][f][d];m&&c.isObject(m)&&d!=="component"&&(h=p(m,h)),r.processedSchemas.value[S][g][f][d]=h,r.stableUpdater(o)}else{let m=r.processedSchemas.value[f][d];m&&c.isObject(m)&&d!=="component"&&(h=p(m,h)),r.processedSchemas.value[f][d]=h,r.stableUpdater(o)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,o)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:o});else{const l=u=>{e.updater({...e,key:r,keyIndex:o,stable:u})};c.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const u=t[r](this.getRuntimeMeta());this.promiseFieldParser(u,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const u=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],f=>{if(!f)return l(f);this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)}):this.fieldParser(t[r],f=>{this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)})})}):r==="component"||r==="slots"||r==="runtimeSetters"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){c.isPromise(e)?e.then(r=>{s&&c.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(c.isString(e)&&(e=$(e,"")),s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(c.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{c.isUndefined(e.value)||(s&&c.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{c.isUndefined(e)||(s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),c.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=y(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){c.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),c.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),c.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function H(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class J{constructor(e){a(this,"schemas",i.ref([]));a(this,"model",i.ref({}));a(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});a(this,"formRef",i.ref(null));a(this,"hydrateEffect",new C);a(this,"native",i.reactive({}));a(this,"gridProps",{});a(this,"runtimeSetters",{});a(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new W(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(y(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var O,N,A,F,M,R,x,D,U,k,_,L,z,T;p(this.globalNativeFormOverride.props,(N=(O=e.native)==null?void 0:O.props)==null?void 0:N.Form),p(this.globalNativeFormOverride.slots,(F=(A=e.native)==null?void 0:A.slots)==null?void 0:F.Form);const o=p(y((R=(M=this.native)==null?void 0:M.props)==null?void 0:R.FormItem)??{},(D=(x=e.native)==null?void 0:x.props)==null?void 0:D.FormItem),l=p(y((k=(U=this.native)==null?void 0:U.slots)==null?void 0:k.FormItem)??{},(L=(_=e.native)==null?void 0:_.slots)==null?void 0:L.FormItem),u={display:"grid",gridColumn:"1 / -1",...e.gridProps},f=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const I=d.name,w=e.componentProps??{},S=E.placeholderPresetByComponentName;let g=e.placeholder;const h=e.required;let m=e.show;m===void 0&&(m=!0),m||delete s[e.field];let P=e.label;const v=(r==null?void 0:r.runtimeSetters)??this.runtimeSetters;if(!c.isUndefined(t)&&!c.isObjectEmpty(v)&&(P=$((z=v==null?void 0:v.listItemLabelSetter)==null?void 0:z.call(v,e.label,t+1),""),g=`${S[I]??"请输入"}${P}`),g||(g=`${S[I]??"请输入"}${P}`),h)if(!e.rules)e.rules=[],(T=e.rules)==null||T.push({required:!0,message:`${P}是必填项`});else{const j=e.rules.findIndex(B=>!!B.required);e.rules[j].message=`${P}是必填项`}return i.createVNode("div",{style:u},[i.createVNode(b.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(b.runtimeDoms.FormItem,i.mergeProps(o,{label:`${P}:`,rules:e.rules,field:f}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":j=>s[e.field]=j,placeholder:g},w),null)},...l}),[[i.vShow,m]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.gridProps};return i.createVNode("div",{style:s},[i.createVNode(b.runtimeDoms.Group,{schema:e},H(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(y(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.gridProps},s=this;return s.model.value[e.field]||(s.model.value[e.field]=[{}]),i.createVNode("div",{style:t},[i.createVNode(b.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(b.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var f;let u=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(u,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((f=s.model.value[e.field])==null?void 0:f.length)>1]])}}))},add({container:r}={}){let o=r??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.createVNode(o,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var o,l,u,f;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.gridProps},t=this,s=p(y((l=(o=this.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(y((f=(u=this.native)==null?void 0:u.slots)==null?void 0:f.Form)??{},this.globalNativeFormOverride.slots);return i.createVNode(b.runtimeDoms.Form,i.mergeProps(s,{ref:this.formRef,model:this.model.value}),{default(){return i.createVNode("div",{style:e},[t.runtimeProcessor(t.schemas.value)])},...r})}}class b{}a(b,"runtimeDoms");const V=class V{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};a(V,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0,gridProps:void 0}),a(V,"componentPropsPreset",{options:{defaultValue:[]}}),a(V,"placeholderPresetByComponentName",V.getPlaceholderPrefixPresetByComponentName());let E=V;const Q=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new J(n.setup);return()=>e.exec()}});function X(n){const e=new K(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function Y(n){return{install(){b.runtimeDoms=n}}}function Z(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=Q;exports.useForm=X;exports.useFormRenderer=Y;exports.useModifiers=Z;
|
|
1
|
+
"use strict";var G=Object.defineProperty;var K=(n,e,t)=>e in n?G(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var f=(n,e,t)=>(K(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class a{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function b(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const o=new Map;for(let[l,u]of s)o.set(t(l),t(u));return o}if(s instanceof Set){const o=new Set;for(let l of s)o.add(t(l));return o}if(e.has(s))return e.get(s);if(Array.isArray(s)){const o=[];e.set(s,o);for(let l=0;l<s.length;l++)o[l]=t(s[l]);return o}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let o in s)s.hasOwnProperty(o)&&(r[o]=t(s[o]));return r}return t(n)}function O(n,e){return n.replace(/undefined/g,e)}class W{constructor(e){f(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,Object.assign(this.runtimeCore.native,this.formCustomization.native),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps),Object.assign(this.runtimeCore.runtimeSetters,this.formCustomization.runtimeSetters),this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{i.isRef(e)?i.watch(()=>e.value,()=>{p(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):i.isReactive(e)?i.watch(()=>e,()=>{p(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):p(this.runtimeCore.model.value,e)},{lazy:!0})}}class N{constructor(){f(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e,t={lazy:!1}){return!t.lazy&&e(),this.effects.add(e),()=>this.effects.delete(e)}}class H{constructor(e){f(this,"runtimeCore");f(this,"processedSchemas");f(this,"processedModel");f(this,"getRuntimeMeta");f(this,"stableSchemas",[]);f(this,"stableModel",{});f(this,"schemaPreset",E.schemaPreset);f(this,"componentPropsPreset",E.componentPropsPreset);f(this,"stableUpdaterProcessProgress");f(this,"stableUpdaterTimes",0);f(this,"schemaEffect",new N);f(this,"defaultValueEffect",new N);f(this,"defaultValueInprogressMap",new Map);f(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){a.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(b(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!a.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!a.isProcessInprogress(t)&&a.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,o=Array.from({length:Object.keys(e).filter(u=>u!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(u){const c=u.index,d=u.key,I=u.keyIndex;if(a.isUndefined(u.stable))return;const w=r.parseStable(u.stable),j=s==null?void 0:s.index,P=s==null?void 0:s.key;let y=w;if(a.isProcessInprogress(y)||(o[I]=!0),s){let m=r.processedSchemas.value[j][P][c][d];m&&a.isObject(m)&&d!=="component"&&(y=p(m,y)),r.processedSchemas.value[j][P][c][d]=y,r.stableUpdater(o)}else{let m=r.processedSchemas.value[c][d];m&&a.isObject(m)&&d!=="component"&&(y=p(m,y)),r.processedSchemas.value[c][d]=y,r.stableUpdater(o)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,o)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:o});else{const l=u=>{e.updater({...e,key:r,keyIndex:o,stable:u})};a.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const u=t[r](this.getRuntimeMeta());this.promiseFieldParser(u,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const u=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],c=>{if(!c)return l(c);this.defaultValueInprogressMap.set(t[r],c),!a.isProcessInprogress(c)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(c),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(c)}):this.fieldParser(t[r],c=>{this.defaultValueInprogressMap.set(t[r],c),!a.isProcessInprogress(c)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(c),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(c)})})}):r==="component"||r==="slots"||r==="runtimeSetters"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){a.isPromise(e)?e.then(r=>{a.isString(r)&&(r=O(r,"")),s&&a.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(a.isString(e)&&(e=O(e,"")),s&&a.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(a.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{a.isUndefined(e.value)||(s&&a.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{a.isUndefined(e)||(s&&a.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&a.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),a.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=b(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){a.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),a.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),a.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function J(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class Q{constructor(e){f(this,"schemas",i.ref([]));f(this,"model",i.ref({}));f(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});f(this,"formRef",i.ref(null));f(this,"hydrateEffect",new N);f(this,"native",i.reactive({}));f(this,"gridProps",{});f(this,"runtimeSetters",{});f(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new H(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(b(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var A,F,M,R,x,U,D,k,_,L,z,q,T,$,B;p(this.globalNativeFormOverride.props,(F=(A=e.native)==null?void 0:A.props)==null?void 0:F.Form),p(this.globalNativeFormOverride.slots,(R=(M=e.native)==null?void 0:M.slots)==null?void 0:R.Form);const o=p(b((U=(x=this.native)==null?void 0:x.props)==null?void 0:U.FormItem)??{},(k=(D=e.native)==null?void 0:D.props)==null?void 0:k.FormItem),l=p(b((L=(_=this.native)==null?void 0:_.slots)==null?void 0:L.FormItem)??{},(q=(z=e.native)==null?void 0:z.slots)==null?void 0:q.FormItem),u={display:"grid",gridColumn:"1 / -1",...e.gridProps},c=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const I=d.name,w=e.componentProps??{},j=E.placeholderPresetByComponentName;let P=e.placeholder;const y=e.required;let m=e.show;m===void 0&&(m=!0),m||delete s[e.field];let v=e.label;const V=(r==null?void 0:r.runtimeSetters)??this.runtimeSetters;if(!a.isUndefined(t)&&!a.isObjectEmpty(V)&&(v=O((T=V==null?void 0:V.listItemLabelSetter)==null?void 0:T.call(V,e.label,t+1),""),P=`${j[I]??"请输入"}${v}`),P||(P=`${j[I]??"请输入"}${v}`),y)if(!e.rules)e.rules=[],($=e.rules)==null||$.push({required:!0,message:`${v}是必填项`});else{const h=e.rules.findIndex(C=>!a.isUndefined(C.required));h!==-1&&(e.rules[h].required=!0,e.rules[h].message=`${v}是必填项`)}else if(e.rules){const h=(B=e.rules)==null?void 0:B.findIndex(C=>!!C.required);h!==-1&&(e.rules[h].required=!1)}return i.createVNode("div",{style:u},[i.createVNode(g.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(g.runtimeDoms.FormItem,i.mergeProps(o,{label:`${v}:`,rules:e.rules,field:c}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":h=>s[e.field]=h,placeholder:P},w),null)},...l}),[[i.vShow,m]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.gridProps};return i.createVNode("div",{style:s},[i.createVNode(g.runtimeDoms.Group,{schema:e},J(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(b(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.gridProps},s=this;return s.model.value[e.field]||(s.model.value[e.field]=[{}]),i.createVNode("div",{style:t},[i.createVNode(g.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(g.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var c;let u=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(u,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((c=s.model.value[e.field])==null?void 0:c.length)>1]])}}))},add({container:r}={}){let o=r??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.createVNode(o,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var o,l,u,c;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.gridProps},t=this,s=p(b((l=(o=this.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(b((c=(u=this.native)==null?void 0:u.slots)==null?void 0:c.Form)??{},this.globalNativeFormOverride.slots);return i.createVNode(g.runtimeDoms.Form,i.mergeProps(s,{ref:this.formRef,model:this.model.value}),{default(){return i.createVNode("div",{style:e},[t.runtimeProcessor(t.schemas.value)])},...r})}}class g{}f(g,"runtimeDoms");const S=class S{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};f(S,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0,gridProps:void 0}),f(S,"componentPropsPreset",{options:{defaultValue:[]}}),f(S,"placeholderPresetByComponentName",S.getPlaceholderPrefixPresetByComponentName());let E=S;const X=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new Q(n.setup);return()=>e.exec()}});function Y(n){const e=new W(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function Z(n){return{install(){g.runtimeDoms=n}}}function ee(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=X;exports.useForm=Y;exports.useFormRenderer=Z;exports.useModifiers=ee;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var l = (o, e, t) => (
|
|
4
|
-
import { toRaw as O, isRef as
|
|
1
|
+
var ee = Object.defineProperty;
|
|
2
|
+
var te = (o, e, t) => e in o ? ee(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var l = (o, e, t) => (te(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { toRaw as O, isRef as Y, watch as I, isReactive as Z, nextTick as J, ref as x, reactive as se, createVNode as c, withDirectives as Q, mergeProps as U, vShow as X, createTextVNode as re, isVNode as ie, defineComponent as oe } from "vue";
|
|
5
5
|
class f {
|
|
6
6
|
static typeChecker(e) {
|
|
7
7
|
return {}.toString.call(e);
|
|
@@ -74,7 +74,7 @@ function p(o, ...e) {
|
|
|
74
74
|
t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? o[s] = p(o[s] || {}, t[s]) : o[s] = t[s]);
|
|
75
75
|
}), o;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function b(o) {
|
|
78
78
|
const e = /* @__PURE__ */ new WeakMap();
|
|
79
79
|
function t(s) {
|
|
80
80
|
if (s === null || typeof s != "object")
|
|
@@ -85,8 +85,8 @@ function y(o) {
|
|
|
85
85
|
return new RegExp(s);
|
|
86
86
|
if (s instanceof Map) {
|
|
87
87
|
const i = /* @__PURE__ */ new Map();
|
|
88
|
-
for (let [n,
|
|
89
|
-
i.set(t(n), t(
|
|
88
|
+
for (let [n, a] of s)
|
|
89
|
+
i.set(t(n), t(a));
|
|
90
90
|
return i;
|
|
91
91
|
}
|
|
92
92
|
if (s instanceof Set) {
|
|
@@ -112,10 +112,10 @@ function y(o) {
|
|
|
112
112
|
}
|
|
113
113
|
return t(o);
|
|
114
114
|
}
|
|
115
|
-
function
|
|
115
|
+
function F(o, e) {
|
|
116
116
|
return o.replace(/undefined/g, e);
|
|
117
117
|
}
|
|
118
|
-
class
|
|
118
|
+
class ne {
|
|
119
119
|
constructor(e) {
|
|
120
120
|
l(this, "runtimeCore");
|
|
121
121
|
this.formCustomization = e;
|
|
@@ -149,7 +149,7 @@ class oe {
|
|
|
149
149
|
});
|
|
150
150
|
this.runtimeCore.hydrateEffect.trackEffect(
|
|
151
151
|
() => {
|
|
152
|
-
|
|
152
|
+
Y(e) ? I(
|
|
153
153
|
() => e.value,
|
|
154
154
|
() => {
|
|
155
155
|
p(this.runtimeCore.model.value, e.value);
|
|
@@ -158,7 +158,7 @@ class oe {
|
|
|
158
158
|
deep: !0,
|
|
159
159
|
immediate: !0
|
|
160
160
|
}
|
|
161
|
-
) :
|
|
161
|
+
) : Z(e) ? I(
|
|
162
162
|
() => e,
|
|
163
163
|
() => {
|
|
164
164
|
p(this.runtimeCore.model.value, e);
|
|
@@ -191,7 +191,7 @@ class M {
|
|
|
191
191
|
return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
class
|
|
194
|
+
class le {
|
|
195
195
|
constructor(e) {
|
|
196
196
|
l(this, "runtimeCore");
|
|
197
197
|
l(this, "processedSchemas");
|
|
@@ -199,8 +199,8 @@ class ne {
|
|
|
199
199
|
l(this, "getRuntimeMeta");
|
|
200
200
|
l(this, "stableSchemas", []);
|
|
201
201
|
l(this, "stableModel", {});
|
|
202
|
-
l(this, "schemaPreset",
|
|
203
|
-
l(this, "componentPropsPreset",
|
|
202
|
+
l(this, "schemaPreset", V.schemaPreset);
|
|
203
|
+
l(this, "componentPropsPreset", V.componentPropsPreset);
|
|
204
204
|
l(this, "stableUpdaterProcessProgress");
|
|
205
205
|
l(this, "stableUpdaterTimes", 0);
|
|
206
206
|
l(this, "schemaEffect", new M());
|
|
@@ -244,7 +244,7 @@ class ne {
|
|
|
244
244
|
// 派生过程,用于外部应用
|
|
245
245
|
parseSchemas(e, t) {
|
|
246
246
|
f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
|
|
247
|
-
|
|
247
|
+
b(e)
|
|
248
248
|
), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
|
|
249
249
|
}
|
|
250
250
|
parseStable(e) {
|
|
@@ -267,21 +267,21 @@ class ne {
|
|
|
267
267
|
// 核心单 schema 处理过程,接收一个对象键值对的数据结构
|
|
268
268
|
parseItem(e, t, s) {
|
|
269
269
|
const r = this, i = Array.from({
|
|
270
|
-
length: Object.keys(e).filter((
|
|
270
|
+
length: Object.keys(e).filter((a) => a !== "children").length
|
|
271
271
|
}).fill(!1);
|
|
272
272
|
this.objectParser({ data: e, index: t, updater: n });
|
|
273
|
-
function n(
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
273
|
+
function n(a) {
|
|
274
|
+
const u = a.index, d = a.key, C = a.keyIndex;
|
|
275
|
+
if (f.isUndefined(a.stable))
|
|
276
276
|
return;
|
|
277
|
-
const w = r.parseStable(
|
|
278
|
-
let
|
|
279
|
-
if (f.isProcessInprogress(
|
|
280
|
-
let m = r.processedSchemas.value[
|
|
281
|
-
m && f.isObject(m) && d !== "component" && (
|
|
277
|
+
const w = r.parseStable(a.stable), E = s == null ? void 0 : s.index, P = s == null ? void 0 : s.key;
|
|
278
|
+
let y = w;
|
|
279
|
+
if (f.isProcessInprogress(y) || (i[C] = !0), s) {
|
|
280
|
+
let m = r.processedSchemas.value[E][P][u][d];
|
|
281
|
+
m && f.isObject(m) && d !== "component" && (y = p(m, y)), r.processedSchemas.value[E][P][u][d] = y, r.stableUpdater(i);
|
|
282
282
|
} else {
|
|
283
|
-
let m = r.processedSchemas.value[
|
|
284
|
-
m && f.isObject(m) && d !== "component" && (
|
|
283
|
+
let m = r.processedSchemas.value[u][d];
|
|
284
|
+
m && f.isObject(m) && d !== "component" && (y = p(m, y)), r.processedSchemas.value[u][d] = y, r.stableUpdater(i);
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
}
|
|
@@ -296,36 +296,36 @@ class ne {
|
|
|
296
296
|
keyIndex: i
|
|
297
297
|
});
|
|
298
298
|
else {
|
|
299
|
-
const n = (
|
|
299
|
+
const n = (a) => {
|
|
300
300
|
e.updater({
|
|
301
301
|
...e,
|
|
302
302
|
key: r,
|
|
303
303
|
keyIndex: i,
|
|
304
|
-
stable:
|
|
304
|
+
stable: a
|
|
305
305
|
});
|
|
306
306
|
};
|
|
307
307
|
f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
308
308
|
if (r === "component") {
|
|
309
|
-
const
|
|
310
|
-
this.promiseFieldParser(
|
|
309
|
+
const a = t[r](this.getRuntimeMeta());
|
|
310
|
+
this.promiseFieldParser(a, n, !1);
|
|
311
311
|
} else
|
|
312
312
|
this.fieldParser(t[r], n);
|
|
313
313
|
}) : this.defaultValueEffect.trackEffect(() => {
|
|
314
|
-
const
|
|
315
|
-
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (
|
|
316
|
-
if (!
|
|
317
|
-
return n(
|
|
318
|
-
this.defaultValueInprogressMap.set(t[r],
|
|
314
|
+
const a = this.schemaEffect.trackEffect(() => {
|
|
315
|
+
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (u) => {
|
|
316
|
+
if (!u)
|
|
317
|
+
return n(u);
|
|
318
|
+
this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
319
319
|
(d) => !d.includes("undefined")
|
|
320
|
-
) ? (n(
|
|
321
|
-
|
|
322
|
-
})) : n(
|
|
323
|
-
}) : this.fieldParser(t[r], (
|
|
324
|
-
this.defaultValueInprogressMap.set(t[r],
|
|
320
|
+
) ? (n(u), this.defaultValueEffect.clearEffects(), J(() => {
|
|
321
|
+
a();
|
|
322
|
+
})) : n(u);
|
|
323
|
+
}) : this.fieldParser(t[r], (u) => {
|
|
324
|
+
this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
325
325
|
(d) => !d.includes("undefined")
|
|
326
|
-
) ? (n(
|
|
327
|
-
|
|
328
|
-
})) : n(
|
|
326
|
+
) ? (n(u), this.defaultValueEffect.clearEffects(), J(() => {
|
|
327
|
+
a();
|
|
328
|
+
})) : n(u);
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
331
|
}) : r === "component" || r === "slots" || r === "runtimeSetters" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
|
|
@@ -334,11 +334,11 @@ class ne {
|
|
|
334
334
|
}
|
|
335
335
|
promiseFieldParser(e, t, s) {
|
|
336
336
|
f.isPromise(e) ? e.then((r) => {
|
|
337
|
-
s && f.isObject(r) ? this.objectParser({
|
|
337
|
+
f.isString(r) && (r = F(r, "")), s && f.isObject(r) ? this.objectParser({
|
|
338
338
|
data: r,
|
|
339
339
|
updater: t
|
|
340
340
|
}) : t(r);
|
|
341
|
-
}) : (f.isString(e) && (e =
|
|
341
|
+
}) : (f.isString(e) && (e = F(e, "")), s && f.isObject(e) ? this.objectParser({
|
|
342
342
|
data: e,
|
|
343
343
|
updater: t
|
|
344
344
|
}) : t(e));
|
|
@@ -353,7 +353,7 @@ class ne {
|
|
|
353
353
|
this.promiseFieldParser(r, t, s);
|
|
354
354
|
}
|
|
355
355
|
else
|
|
356
|
-
|
|
356
|
+
Y(e) ? I(
|
|
357
357
|
() => e.value,
|
|
358
358
|
() => {
|
|
359
359
|
f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
|
|
@@ -365,7 +365,7 @@ class ne {
|
|
|
365
365
|
immediate: !0,
|
|
366
366
|
deep: !0
|
|
367
367
|
}
|
|
368
|
-
) :
|
|
368
|
+
) : Z(e) ? I(
|
|
369
369
|
() => e,
|
|
370
370
|
() => {
|
|
371
371
|
f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
|
|
@@ -385,7 +385,7 @@ class ne {
|
|
|
385
385
|
modelProcessor(e) {
|
|
386
386
|
e.map(
|
|
387
387
|
(t) => this.createModel(t, this.processedModel.value)
|
|
388
|
-
), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel =
|
|
388
|
+
), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = b(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
|
|
389
389
|
}
|
|
390
390
|
createModel(e, t) {
|
|
391
391
|
f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
|
|
@@ -395,83 +395,87 @@ class ne {
|
|
|
395
395
|
}), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
-
function
|
|
399
|
-
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !
|
|
398
|
+
function fe(o) {
|
|
399
|
+
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !ie(o);
|
|
400
400
|
}
|
|
401
|
-
class
|
|
401
|
+
class ue {
|
|
402
402
|
constructor(e) {
|
|
403
|
-
l(this, "schemas",
|
|
404
|
-
l(this, "model",
|
|
403
|
+
l(this, "schemas", x([]));
|
|
404
|
+
l(this, "model", x({}));
|
|
405
405
|
l(this, "processorBySchemaType", {
|
|
406
406
|
item: this.runtimeItemProcessor.bind(this),
|
|
407
407
|
group: this.runtimeGroupProcessor.bind(this),
|
|
408
408
|
list: this.runtimeListProcessor.bind(this)
|
|
409
409
|
});
|
|
410
|
-
l(this, "formRef",
|
|
410
|
+
l(this, "formRef", x(null));
|
|
411
411
|
l(this, "hydrateEffect", new M());
|
|
412
|
-
l(this, "native",
|
|
412
|
+
l(this, "native", se({}));
|
|
413
413
|
l(this, "gridProps", {});
|
|
414
414
|
l(this, "runtimeSetters", {});
|
|
415
415
|
l(this, "globalNativeFormOverride", {
|
|
416
416
|
props: {},
|
|
417
417
|
slots: {}
|
|
418
418
|
});
|
|
419
|
-
this.setup = e, this.processor = new
|
|
419
|
+
this.setup = e, this.processor = new le(this);
|
|
420
420
|
const t = this.setup(this);
|
|
421
421
|
this.processor.parseSchemas(t.schemas);
|
|
422
422
|
}
|
|
423
423
|
getRuntimeMeta() {
|
|
424
424
|
return {
|
|
425
|
-
model: O(
|
|
425
|
+
model: O(b(this.model.value))
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
428
|
runtimeItemProcessor(e, t, s = this.model.value, r) {
|
|
429
|
-
var
|
|
430
|
-
p(this.globalNativeFormOverride.props, (
|
|
431
|
-
const i = p(
|
|
429
|
+
var D, N, R, _, k, L, z, q, $, B, T, G, K, W, H;
|
|
430
|
+
p(this.globalNativeFormOverride.props, (N = (D = e.native) == null ? void 0 : D.props) == null ? void 0 : N.Form), p(this.globalNativeFormOverride.slots, (_ = (R = e.native) == null ? void 0 : R.slots) == null ? void 0 : _.Form);
|
|
431
|
+
const i = p(b((L = (k = this.native) == null ? void 0 : k.props) == null ? void 0 : L.FormItem) ?? {}, (q = (z = e.native) == null ? void 0 : z.props) == null ? void 0 : q.FormItem), n = p(b((B = ($ = this.native) == null ? void 0 : $.slots) == null ? void 0 : B.FormItem) ?? {}, (G = (T = e.native) == null ? void 0 : T.slots) == null ? void 0 : G.FormItem), a = {
|
|
432
432
|
display: "grid",
|
|
433
433
|
gridColumn: "1 / -1",
|
|
434
434
|
...e.gridProps
|
|
435
|
-
},
|
|
435
|
+
}, u = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
|
|
436
436
|
if (!d)
|
|
437
437
|
return;
|
|
438
|
-
const
|
|
439
|
-
let
|
|
440
|
-
const
|
|
438
|
+
const C = d.name, w = e.componentProps ?? {}, E = V.placeholderPresetByComponentName;
|
|
439
|
+
let P = e.placeholder;
|
|
440
|
+
const y = e.required;
|
|
441
441
|
let m = e.show;
|
|
442
442
|
m === void 0 && (m = !0), m || delete s[e.field];
|
|
443
|
-
let
|
|
444
|
-
const
|
|
445
|
-
if (!f.isUndefined(t) && !f.isObjectEmpty(
|
|
446
|
-
|
|
447
|
-
|
|
443
|
+
let v = e.label;
|
|
444
|
+
const S = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
|
|
445
|
+
if (!f.isUndefined(t) && !f.isObjectEmpty(S) && (v = F((K = S == null ? void 0 : S.listItemLabelSetter) == null ? void 0 : K.call(S, e.label, t + 1), ""), P = `${// @ts-expect-error
|
|
446
|
+
E[C] ?? "请输入"}${v}`), P || (P = `${// @ts-expect-error
|
|
447
|
+
E[C] ?? "请输入"}${v}`), y)
|
|
448
448
|
if (!e.rules)
|
|
449
|
-
e.rules = [], (
|
|
449
|
+
e.rules = [], (W = e.rules) == null || W.push({
|
|
450
450
|
required: !0,
|
|
451
|
-
message: `${
|
|
451
|
+
message: `${v}是必填项`
|
|
452
452
|
});
|
|
453
453
|
else {
|
|
454
|
-
const
|
|
455
|
-
e.rules[
|
|
454
|
+
const h = e.rules.findIndex((A) => !f.isUndefined(A.required));
|
|
455
|
+
h !== -1 && (e.rules[h].required = !0, e.rules[h].message = `${v}是必填项`);
|
|
456
456
|
}
|
|
457
|
+
else if (e.rules) {
|
|
458
|
+
const h = (H = e.rules) == null ? void 0 : H.findIndex((A) => !!A.required);
|
|
459
|
+
h !== -1 && (e.rules[h].required = !1);
|
|
460
|
+
}
|
|
457
461
|
return c("div", {
|
|
458
|
-
style:
|
|
459
|
-
}, [c(
|
|
462
|
+
style: a
|
|
463
|
+
}, [c(g.runtimeDoms.Item, null, {
|
|
460
464
|
default() {
|
|
461
|
-
return
|
|
462
|
-
label: `${
|
|
465
|
+
return Q(c(g.runtimeDoms.FormItem, U(i, {
|
|
466
|
+
label: `${v}:`,
|
|
463
467
|
rules: e.rules,
|
|
464
|
-
field:
|
|
468
|
+
field: u
|
|
465
469
|
}), {
|
|
466
470
|
default() {
|
|
467
|
-
return c(d,
|
|
471
|
+
return c(d, U({
|
|
468
472
|
modelValue: s[e.field],
|
|
469
|
-
"onUpdate:modelValue": (
|
|
470
|
-
placeholder:
|
|
473
|
+
"onUpdate:modelValue": (h) => s[e.field] = h,
|
|
474
|
+
placeholder: P
|
|
471
475
|
}, w), null);
|
|
472
476
|
},
|
|
473
477
|
...n
|
|
474
|
-
}), [[
|
|
478
|
+
}), [[X, m]]);
|
|
475
479
|
}
|
|
476
480
|
})]);
|
|
477
481
|
}
|
|
@@ -484,9 +488,9 @@ class fe {
|
|
|
484
488
|
};
|
|
485
489
|
return c("div", {
|
|
486
490
|
style: s
|
|
487
|
-
}, [c(
|
|
491
|
+
}, [c(g.runtimeDoms.Group, {
|
|
488
492
|
schema: e
|
|
489
|
-
},
|
|
493
|
+
}, fe(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
|
|
490
494
|
default: () => [t]
|
|
491
495
|
})]);
|
|
492
496
|
}
|
|
@@ -497,7 +501,7 @@ class fe {
|
|
|
497
501
|
code: "0001",
|
|
498
502
|
message: "异步默认值数据正在处理中,请您耐心等待... "
|
|
499
503
|
});
|
|
500
|
-
(s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(
|
|
504
|
+
(s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(b(this.processor.stableModel[e.field][0])), this.formRef.value.clearValidate();
|
|
501
505
|
}
|
|
502
506
|
deleteListItem(e, t) {
|
|
503
507
|
this.model.value[e.field].splice(t, 1), this.formRef.value.clearValidate();
|
|
@@ -510,29 +514,29 @@ class fe {
|
|
|
510
514
|
}, s = this;
|
|
511
515
|
return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
|
|
512
516
|
style: t
|
|
513
|
-
}, [c(
|
|
517
|
+
}, [c(g.runtimeDoms.List, {
|
|
514
518
|
schema: e
|
|
515
519
|
}, {
|
|
516
520
|
default() {
|
|
517
|
-
return s.model.value[e.field].map((r, i) => c(
|
|
521
|
+
return s.model.value[e.field].map((r, i) => c(g.runtimeDoms.ListItem, null, {
|
|
518
522
|
default() {
|
|
519
523
|
return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
|
|
520
524
|
},
|
|
521
525
|
delete({
|
|
522
526
|
container: n
|
|
523
527
|
} = {}) {
|
|
524
|
-
var
|
|
525
|
-
let
|
|
526
|
-
return
|
|
528
|
+
var u;
|
|
529
|
+
let a = n ?? c("button", null, null);
|
|
530
|
+
return Q(c(a, {
|
|
527
531
|
onClick: () => s.deleteListItem(e, i)
|
|
528
|
-
}, null), [[
|
|
532
|
+
}, null), [[X, ((u = s.model.value[e.field]) == null ? void 0 : u.length) > 1]]);
|
|
529
533
|
}
|
|
530
534
|
}));
|
|
531
535
|
},
|
|
532
536
|
add({
|
|
533
537
|
container: r
|
|
534
538
|
} = {}) {
|
|
535
|
-
let i = r ?? c("button", null, [
|
|
539
|
+
let i = r ?? c("button", null, [re("添加")]);
|
|
536
540
|
return c(i, {
|
|
537
541
|
onClick: () => s.addListItem(e)
|
|
538
542
|
}, null);
|
|
@@ -543,14 +547,14 @@ class fe {
|
|
|
543
547
|
return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
|
|
544
548
|
}
|
|
545
549
|
exec() {
|
|
546
|
-
var i, n,
|
|
550
|
+
var i, n, a, u;
|
|
547
551
|
const e = {
|
|
548
552
|
display: "grid",
|
|
549
553
|
gridColumn: "1 / -1",
|
|
550
554
|
gridAutoColumns: "1fr",
|
|
551
555
|
...this.gridProps
|
|
552
|
-
}, t = this, s = p(
|
|
553
|
-
return c(
|
|
556
|
+
}, t = this, s = p(b((n = (i = this.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = p(b((u = (a = this.native) == null ? void 0 : a.slots) == null ? void 0 : u.Form) ?? {}, this.globalNativeFormOverride.slots);
|
|
557
|
+
return c(g.runtimeDoms.Form, U(s, {
|
|
554
558
|
ref: this.formRef,
|
|
555
559
|
model: this.model.value
|
|
556
560
|
}), {
|
|
@@ -563,10 +567,10 @@ class fe {
|
|
|
563
567
|
});
|
|
564
568
|
}
|
|
565
569
|
}
|
|
566
|
-
class
|
|
570
|
+
class g {
|
|
567
571
|
}
|
|
568
|
-
l(
|
|
569
|
-
const
|
|
572
|
+
l(g, "runtimeDoms");
|
|
573
|
+
const j = class j {
|
|
570
574
|
static getPlaceholderPrefixPresetByComponentName() {
|
|
571
575
|
const e = {
|
|
572
576
|
请选择: ["Select", "Tree", "TreeSelect"],
|
|
@@ -579,7 +583,7 @@ const S = class S {
|
|
|
579
583
|
return t;
|
|
580
584
|
}
|
|
581
585
|
};
|
|
582
|
-
l(
|
|
586
|
+
l(j, "schemaPreset", {
|
|
583
587
|
type: {
|
|
584
588
|
defaultValue: "item"
|
|
585
589
|
},
|
|
@@ -615,14 +619,14 @@ l(S, "schemaPreset", {
|
|
|
615
619
|
},
|
|
616
620
|
native: void 0,
|
|
617
621
|
gridProps: void 0
|
|
618
|
-
}), l(
|
|
622
|
+
}), l(j, "componentPropsPreset", {
|
|
619
623
|
options: {
|
|
620
624
|
defaultValue: []
|
|
621
625
|
}
|
|
622
626
|
}), // 基于基本功能提出基本预设
|
|
623
|
-
l(
|
|
624
|
-
let
|
|
625
|
-
const
|
|
627
|
+
l(j, "placeholderPresetByComponentName", j.getPlaceholderPrefixPresetByComponentName());
|
|
628
|
+
let V = j;
|
|
629
|
+
const de = /* @__PURE__ */ oe({
|
|
626
630
|
props: {
|
|
627
631
|
setup: {
|
|
628
632
|
type: Function,
|
|
@@ -630,12 +634,12 @@ const ce = /* @__PURE__ */ ie({
|
|
|
630
634
|
}
|
|
631
635
|
},
|
|
632
636
|
setup(o) {
|
|
633
|
-
const e = new
|
|
637
|
+
const e = new ue(o.setup);
|
|
634
638
|
return () => e.exec();
|
|
635
639
|
}
|
|
636
640
|
});
|
|
637
|
-
function
|
|
638
|
-
const e = new
|
|
641
|
+
function pe(o) {
|
|
642
|
+
const e = new ne(o);
|
|
639
643
|
return [
|
|
640
644
|
e.setup.bind(e),
|
|
641
645
|
{
|
|
@@ -644,22 +648,22 @@ function de(o) {
|
|
|
644
648
|
}
|
|
645
649
|
];
|
|
646
650
|
}
|
|
647
|
-
function
|
|
651
|
+
function me(o) {
|
|
648
652
|
return {
|
|
649
653
|
install() {
|
|
650
|
-
|
|
654
|
+
g.runtimeDoms = o;
|
|
651
655
|
}
|
|
652
656
|
};
|
|
653
657
|
}
|
|
654
|
-
function
|
|
658
|
+
function he(o, e) {
|
|
655
659
|
return e === "raw" && Object.defineProperty(o, "name", {
|
|
656
660
|
value: `__proform_raw_${o.name}`,
|
|
657
661
|
writable: !0
|
|
658
662
|
}), o;
|
|
659
663
|
}
|
|
660
664
|
export {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
+
de as ProForm,
|
|
666
|
+
pe as useForm,
|
|
667
|
+
me as useFormRenderer,
|
|
668
|
+
he as useModifiers
|
|
665
669
|
};
|