@harbor-design/proform 1.0.9 → 1.0.11

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var v=(c,e,t)=>e in c?I(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var l=(c,e,t)=>(v(c,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");class O{constructor(e){l(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,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(n.toRaw(this.runtimeCore.processor.processedModel.value))))})}}class u{static typeChecker(e){return{}.toString.call(e)}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 S(c){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 i=new Map;for(let[o,a]of s)i.set(t(o),t(a));return i}if(s instanceof Set){const i=new Set;for(let o of s)i.add(t(o));return i}if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=[];e.set(s,i);for(let o=0;o<s.length;o++)i[o]=t(s[o]);return i}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let i in s)s.hasOwnProperty(i)&&(r[i]=t(s[i]));return r}return t(c)}class w{constructor(){l(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e){return e(),this.effects.add(e),()=>this.effects.delete(e)}}class C{constructor(e){l(this,"processedSchemas");l(this,"processedModel");l(this,"getRuntimeMeta");l(this,"stableSchemas",[]);l(this,"stableModel",{});l(this,"schemaPreset",V.schemaPreset);l(this,"componentPropsPreset",V.componentPropsPreset);l(this,"stableUpdaterProcessProgress");l(this,"stableUpdaterTimes",0);l(this,"schemaEffect",new w);l(this,"defaultValueEffect",new w);l(this,"defaultValueInprogressMap",new Map);l(this,"baseDefaultValueFunctionsLength");this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),n.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(i){if(!s.has(i)&&(Array.isArray(i)||i!==null&&typeof i=="object")){s.add(i);for(let o in i)i.hasOwnProperty(o)&&(o==="defaultValue"&&typeof i[o]=="function"&&i[o].toString().includes("defaultValue")&&t++,r(i[o]))}}return r(e),t}parseSchemas(e,t){u.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(S(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!u.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=n.toRaw(this.processedSchemas.value);!u.isProcessInprogress(t)&&u.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,i=Array.from({length:Object.keys(e).filter(a=>a!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:o});function o(a){const f=a.index,d=a.key,P=a.keyIndex;if(!a.stable)return;const j=r.parseStable(a.stable),m=s==null?void 0:s.index,g=s==null?void 0:s.key;let h=j;if(u.isProcessInprogress(h)||(i[P]=!0),s){let b=r.processedSchemas.value[m][g][f][d];b&&u.isObject(b)&&d!=="component"&&(h=Object.assign(b,h)),r.processedSchemas.value[m][g][f][d]=h,r.stableUpdater(i)}else{let b=r.processedSchemas.value[f][d];b&&u.isObject(b)&&(h=Object.assign(b,h)),r.processedSchemas.value[f][d]=h,r.stableUpdater(i)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,i)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:i});else{const o=a=>{e.updater({...e,key:r,keyIndex:i,stable:a})};if(u.isFunction(t[r]))r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const a=t[r](this.getRuntimeMeta());this.promiseFieldParser(a,o,!1)}else this.fieldParser(t[r],o)}):this.defaultValueEffect.trackEffect(()=>{const a=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],f=>{if(!f)return o(f);this.defaultValueInprogressMap.set(t[r],f),!u.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(o(f),this.defaultValueEffect.clearEffects(),a()):o(f)}):this.fieldParser(t[r],f=>{this.defaultValueInprogressMap.set(t[r],f),!u.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(o(f),this.defaultValueEffect.clearEffects(),a()):o(f)})})});else if(r==="component"){const a=t[r];this.promiseFieldParser(a,o,!1)}else this.fieldParser(t[r],o)}})}promiseFieldParser(e,t,s){u.isPromise(e)?e.then(r=>{s&&u.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}fieldParser(e,t,s=!0){if(u.isFunction(e)){const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else n.isRef(e)?n.watch(()=>e.value,()=>{u.isUndefined(e.value)||(s&&u.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):n.isReactive(e)?n.watch(()=>e,()=>{u.isUndefined(e)||(s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),u.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=S(this.processedModel.value))}createModel(e,t){u.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),u.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),u.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function E(c){return typeof c=="function"||Object.prototype.toString.call(c)==="[object Object]"&&!n.isVNode(c)}class R{constructor(e){l(this,"schemas",n.ref([]));l(this,"model",n.ref({}));l(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});l(this,"formRef",n.ref(null));this.setup=e,this.processor=new C(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:n.toRaw(S(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var g;const i=r?`${r.field}.${t}.${e.field}`:e.field,o=n.toRaw(e.component);if(!o)return;const a=o.name,f=e.componentProps??{},d=V.placeholderPresetByComponentName;let P=e.placeholder;P||(P=`${d[a]??"请输入"}${e.label}`),e.required&&(e.rules||(e.rules=[]),(g=e.rules)==null||g.push({required:!0,message:`${e.label}是必填项`}));let m=e.show;return m===void 0&&(m=!0),m||delete s[e.field],n.createVNode(p.runtimeDoms.Item,null,{default(){return n.withDirectives(n.createVNode(p.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:i},{default:()=>[n.createVNode(o,n.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":h=>s[e.field]=h,placeholder:P},f),null)]}),[[n.vShow,m]])}})}runtimeGroupProcessor(e){let t;return n.createVNode(p.runtimeDoms.Group,{schema:e},E(t=e.children.map(s=>this.runtimeItemProcessor(s)))?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(S(this.processor.stableModel[e.field][0]))}deleteListItem(e,t){this.model.value[e.field].splice(t,1)}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),n.createVNode(p.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>n.createVNode(p.runtimeDoms.ListItem,null,{default(){return e.children.map((i,o)=>t.runtimeItemProcessor(i,o,s,e))},delete({container:i}={}){var a;let o=i??n.createVNode("button",null,null);return n.withDirectives(n.createVNode(o,{onClick:()=>t.deleteListItem(e,r)},null),[[n.vShow,((a=t.model.value[e.field])==null?void 0:a.length)>1]])}}))},add({container:s}={}){let r=s??n.createVNode("button",null,[n.createTextVNode("添加")]);return n.createVNode(r,{onClick:()=>t.addListItem(e)},null)}})}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){let e;return n.createVNode(p.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},E(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class p{}l(p,"runtimeDoms");const y=class y{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};l(y,"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:[]}}),l(y,"componentPropsPreset",{options:{defaultValue:[]}}),l(y,"placeholderPresetByComponentName",y.getPlaceholderPrefixPresetByComponentName());let V=y;const A=n.defineComponent({props:{setup:{type:Function,required:!0}},setup(c){const e=new R(c.setup);return()=>e.exec()}});function D(c){const e=new O(c);return[e.setup.bind(e),{submit:e.submit.bind(e)}]}function M(c){return{install(){p.runtimeDoms=c}}}exports.ProForm=A;exports.useForm=D;exports.useFormRenderer=M;
1
+ "use strict";var I=Object.defineProperty;var C=(l,e,t)=>e in l?I(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t;var c=(l,e,t)=>(C(l,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue");class u{static typeChecker(e){return{}.toString.call(e)}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 E(l,...e){return e.forEach(t=>{for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?(l[s]=l[s]||{},E(l[s],t[s])):l[s]=t[s])}),l}function S(l){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 i=new Map;for(let[n,f]of s)i.set(t(n),t(f));return i}if(s instanceof Set){const i=new Set;for(let n of s)i.add(t(n));return i}if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=[];e.set(s,i);for(let n=0;n<s.length;n++)i[n]=t(s[n]);return i}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let i in s)s.hasOwnProperty(i)&&(r[i]=t(s[i]));return r}return t(l)}class O{constructor(e){c(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,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(o.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){this.runtimeCore.hydrateEffect.trackEffect(()=>{o.isRef(e)?o.watch(()=>e.value,()=>{E(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):o.isReactive(e)?o.watch(()=>e,()=>{E(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):E(this.runtimeCore.model.value,e)},{lazy:!0})}}class j{constructor(){c(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 R{constructor(e){c(this,"runtimeCore");c(this,"processedSchemas");c(this,"processedModel");c(this,"getRuntimeMeta");c(this,"stableSchemas",[]);c(this,"stableModel",{});c(this,"schemaPreset",V.schemaPreset);c(this,"componentPropsPreset",V.componentPropsPreset);c(this,"stableUpdaterProcessProgress");c(this,"stableUpdaterTimes",0);c(this,"schemaEffect",new j);c(this,"defaultValueEffect",new j);c(this,"defaultValueInprogressMap",new Map);c(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),o.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(i){if(!s.has(i)&&(Array.isArray(i)||i!==null&&typeof i=="object")){s.add(i);for(let n in i)i.hasOwnProperty(n)&&(n==="defaultValue"&&typeof i[n]=="function"&&!i[n].toString().includes("[native code]")&&t++,r(i[n]))}}return r(e),t}parseSchemas(e,t){u.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(S(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!u.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=o.toRaw(this.processedSchemas.value);!u.isProcessInprogress(t)&&u.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,i=Array.from({length:Object.keys(e).filter(f=>f!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:n});function n(f){const a=f.index,h=f.key,P=f.keyIndex;if(!f.stable)return;const v=r.parseStable(f.stable),y=s==null?void 0:s.index,g=s==null?void 0:s.key;let d=v;if(u.isProcessInprogress(d)||(i[P]=!0),s){let p=r.processedSchemas.value[y][g][a][h];p&&u.isObject(p)&&h!=="component"&&(d=Object.assign(p,d)),r.processedSchemas.value[y][g][a][h]=d,r.stableUpdater(i)}else{let p=r.processedSchemas.value[a][h];p&&u.isObject(p)&&(d=Object.assign(p,d)),r.processedSchemas.value[a][h]=d,r.stableUpdater(i)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,i)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:i});else{const n=f=>{e.updater({...e,key:r,keyIndex:i,stable:f})};if(u.isFunction(t[r]))r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const f=t[r](this.getRuntimeMeta());this.promiseFieldParser(f,n,!1)}else this.fieldParser(t[r],n)}):this.defaultValueEffect.trackEffect(()=>{const f=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],a=>{if(!a)return n(a);this.defaultValueInprogressMap.set(t[r],a),!u.isProcessInprogress(a)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(h=>!h.includes("undefined"))?(n(a),this.defaultValueEffect.clearEffects(),f()):n(a)}):this.fieldParser(t[r],a=>{this.defaultValueInprogressMap.set(t[r],a),!u.isProcessInprogress(a)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(h=>!h.includes("undefined"))?(n(a),this.defaultValueEffect.clearEffects(),f()):n(a)})})});else if(r==="component"){const f=t[r];this.promiseFieldParser(f,n,!1)}else this.fieldParser(t[r],n)}})}promiseFieldParser(e,t,s){u.isPromise(e)?e.then(r=>{s&&u.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}fieldParser(e,t,s=!0){if(u.isFunction(e)){const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else o.isRef(e)?o.watch(()=>e.value,()=>{u.isUndefined(e.value)||(s&&u.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):o.isReactive(e)?o.watch(()=>e,()=>{u.isUndefined(e)||(s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),u.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=S(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){u.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),u.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),u.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function w(l){return typeof l=="function"||Object.prototype.toString.call(l)==="[object Object]"&&!o.isVNode(l)}class A{constructor(e){c(this,"schemas",o.ref([]));c(this,"model",o.ref({}));c(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});c(this,"formRef",o.ref(null));c(this,"hydrateEffect",new j);this.setup=e,this.processor=new R(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:o.toRaw(S(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var g;const i=r?`${r.field}.${t}.${e.field}`:e.field,n=o.toRaw(e.component);if(!n)return;const f=n.name,a=e.componentProps??{},h=V.placeholderPresetByComponentName;let P=e.placeholder;if(P||(P=`${h[f]??"请输入"}${e.label}`),e.required){e.rules||(e.rules=[]);const d=e.rules.findIndex(p=>!!p.required);d===-1?(g=e.rules)==null||g.push({required:!0,message:`${e.label}是必填项`}):e.rules.splice(d,1,{required:!0,message:`${e.label}是必填项`})}let y=e.show;return y===void 0&&(y=!0),y||delete s[e.field],o.createVNode(m.runtimeDoms.Item,null,{default(){return o.withDirectives(o.createVNode(m.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:i},{default:()=>[o.createVNode(n,o.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":d=>s[e.field]=d,placeholder:P},a),null)]}),[[o.vShow,y]])}})}runtimeGroupProcessor(e){let t;return o.createVNode(m.runtimeDoms.Group,{schema:e},w(t=e.children.map(s=>this.runtimeItemProcessor(s)))?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(S(this.processor.stableModel[e.field][0]))}deleteListItem(e,t){this.model.value[e.field].splice(t,1);const s=e.children.map(({field:r})=>`${e.field}.${t}.${r}`);this.formRef.value.clearValidate(s)}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),o.createVNode(m.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>o.createVNode(m.runtimeDoms.ListItem,null,{default(){return e.children.map(i=>t.runtimeItemProcessor(i,r,s,e))},delete({container:i}={}){var f;let n=i??o.createVNode("button",null,null);return o.withDirectives(o.createVNode(n,{onClick:()=>t.deleteListItem(e,r)},null),[[o.vShow,((f=t.model.value[e.field])==null?void 0:f.length)>1]])}}))},add({container:s}={}){let r=s??o.createVNode("button",null,[o.createTextVNode("添加")]);return o.createVNode(r,{onClick:()=>t.addListItem(e)},null)}})}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){let e;return o.createVNode(m.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},w(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class m{}c(m,"runtimeDoms");const b=class b{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};c(b,"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:[]}}),c(b,"componentPropsPreset",{options:{defaultValue:[]}}),c(b,"placeholderPresetByComponentName",b.getPlaceholderPrefixPresetByComponentName());let V=b;const D=o.defineComponent({props:{setup:{type:Function,required:!0}},setup(l){const e=new A(l.setup);return()=>e.exec()}});function M(l){const e=new O(l);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function N(l){return{install(){m.runtimeDoms=l}}}exports.ProForm=D;exports.useForm=M;exports.useFormRenderer=N;
package/dist/index.js CHANGED
@@ -1,32 +1,8 @@
1
- var x = Object.defineProperty;
2
- var D = (l, e, t) => e in l ? x(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var o = (l, e, t) => (D(l, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { toRaw as j, watch as E, isRef as M, isReactive as U, ref as I, createVNode as d, withDirectives as v, mergeProps as R, vShow as O, createTextVNode as k, isVNode as L, defineComponent as F } from "vue";
5
- class B {
6
- constructor(e) {
7
- o(this, "runtimeCore");
8
- this.formCustomization = e;
9
- }
10
- // happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
11
- cleanFallbackFields(e) {
12
- return e !== null && typeof e == "object" && (delete e.__yiwwhl_async_field_fallback, Object.values(e).forEach((t) => {
13
- this.cleanFallbackFields(t);
14
- })), e;
15
- }
16
- setup(e) {
17
- return this.runtimeCore = e, this.formCustomization;
18
- }
19
- submit() {
20
- return new Promise((e, t) => {
21
- this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
22
- this.cleanFallbackFields(
23
- j(this.runtimeCore.processor.processedModel.value)
24
- )
25
- ));
26
- });
27
- }
28
- }
29
- class u {
1
+ var R = Object.defineProperty;
2
+ var U = (l, e, t) => e in l ? R(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
+ var o = (l, e, t) => (U(l, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { toRaw as V, isRef as D, watch as E, isReactive as M, ref as I, createVNode as h, withDirectives as O, mergeProps as k, vShow as A, createTextVNode as L, isVNode as F, defineComponent as z } from "vue";
5
+ class f {
30
6
  static typeChecker(e) {
31
7
  return {}.toString.call(e);
32
8
  }
@@ -84,7 +60,13 @@ class u {
84
60
  return !1;
85
61
  }
86
62
  }
87
- function V(l) {
63
+ function S(l, ...e) {
64
+ return e.forEach((t) => {
65
+ for (let s in t)
66
+ t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? (l[s] = l[s] || {}, S(l[s], t[s])) : l[s] = t[s]);
67
+ }), l;
68
+ }
69
+ function v(l) {
88
70
  const e = /* @__PURE__ */ new WeakMap();
89
71
  function t(s) {
90
72
  if (s === null || typeof s != "object")
@@ -122,7 +104,59 @@ function V(l) {
122
104
  }
123
105
  return t(l);
124
106
  }
125
- class C {
107
+ class $ {
108
+ constructor(e) {
109
+ o(this, "runtimeCore");
110
+ this.formCustomization = e;
111
+ }
112
+ // happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
113
+ cleanFallbackFields(e) {
114
+ return e !== null && typeof e == "object" && (delete e.__yiwwhl_async_field_fallback, Object.values(e).forEach((t) => {
115
+ this.cleanFallbackFields(t);
116
+ })), e;
117
+ }
118
+ setup(e) {
119
+ return this.runtimeCore = e, this.formCustomization;
120
+ }
121
+ submit() {
122
+ return new Promise((e, t) => {
123
+ this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
124
+ this.cleanFallbackFields(
125
+ V(this.runtimeCore.processor.processedModel.value)
126
+ )
127
+ ));
128
+ });
129
+ }
130
+ hydrate(e) {
131
+ this.runtimeCore.hydrateEffect.trackEffect(
132
+ () => {
133
+ D(e) ? E(
134
+ () => e.value,
135
+ () => {
136
+ S(this.runtimeCore.model.value, e.value);
137
+ },
138
+ {
139
+ deep: !0,
140
+ immediate: !0
141
+ }
142
+ ) : M(e) ? E(
143
+ () => e,
144
+ () => {
145
+ S(this.runtimeCore.model.value, e);
146
+ },
147
+ {
148
+ deep: !0,
149
+ immediate: !0
150
+ }
151
+ ) : S(this.runtimeCore.model.value, e);
152
+ },
153
+ {
154
+ lazy: !0
155
+ }
156
+ );
157
+ }
158
+ }
159
+ class w {
126
160
  constructor() {
127
161
  o(this, "effects", /* @__PURE__ */ new Set());
128
162
  }
@@ -132,26 +166,29 @@ class C {
132
166
  triggerEffects() {
133
167
  Array.from(this.effects).forEach((e) => e());
134
168
  }
135
- trackEffect(e) {
136
- return e(), this.effects.add(e), () => this.effects.delete(e);
169
+ trackEffect(e, t = {
170
+ lazy: !1
171
+ }) {
172
+ return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
137
173
  }
138
174
  }
139
- class N {
175
+ class B {
140
176
  constructor(e) {
177
+ o(this, "runtimeCore");
141
178
  o(this, "processedSchemas");
142
179
  o(this, "processedModel");
143
180
  o(this, "getRuntimeMeta");
144
181
  o(this, "stableSchemas", []);
145
182
  o(this, "stableModel", {});
146
- o(this, "schemaPreset", S.schemaPreset);
147
- o(this, "componentPropsPreset", S.componentPropsPreset);
183
+ o(this, "schemaPreset", j.schemaPreset);
184
+ o(this, "componentPropsPreset", j.componentPropsPreset);
148
185
  o(this, "stableUpdaterProcessProgress");
149
186
  o(this, "stableUpdaterTimes", 0);
150
- o(this, "schemaEffect", new C());
151
- o(this, "defaultValueEffect", new C());
187
+ o(this, "schemaEffect", new w());
188
+ o(this, "defaultValueEffect", new w());
152
189
  o(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
153
190
  o(this, "baseDefaultValueFunctionsLength");
154
- this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), E(
191
+ this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), E(
155
192
  () => this.processedModel.value,
156
193
  () => {
157
194
  this.schemaEffect.triggerEffects();
@@ -180,20 +217,20 @@ class N {
180
217
  if (!s.has(i) && (Array.isArray(i) || i !== null && typeof i == "object")) {
181
218
  s.add(i);
182
219
  for (let n in i)
183
- i.hasOwnProperty(n) && (n === "defaultValue" && typeof i[n] == "function" && i[n].toString().includes("defaultValue") && t++, r(i[n]));
220
+ i.hasOwnProperty(n) && (n === "defaultValue" && typeof i[n] == "function" && !i[n].toString().includes("[native code]") && t++, r(i[n]));
184
221
  }
185
222
  }
186
223
  return r(e), t;
187
224
  }
188
225
  // 派生过程,用于外部应用
189
226
  parseSchemas(e, t) {
190
- u.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
191
- V(e)
227
+ f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
228
+ v(e)
192
229
  ), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
193
230
  }
194
231
  parseStable(e) {
195
232
  const t = {};
196
- if (!u.isUndefined(e.stable))
233
+ if (!f.isUndefined(e.stable))
197
234
  t[e.key] = this.parseStable(e.stable);
198
235
  else
199
236
  return e;
@@ -202,8 +239,8 @@ class N {
202
239
  // 对于稳定初始化更新的抽象
203
240
  stableUpdater(e = []) {
204
241
  if (e.every(Boolean)) {
205
- const t = j(this.processedSchemas.value);
206
- !u.isProcessInprogress(t) && u.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
242
+ const t = V(this.processedSchemas.value);
243
+ !f.isProcessInprogress(t) && f.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
207
244
  length: t.length
208
245
  }).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
209
246
  }
@@ -215,17 +252,17 @@ class N {
215
252
  }).fill(!1);
216
253
  this.objectParser({ data: e, index: t, updater: n });
217
254
  function n(c) {
218
- const f = c.index, a = c.key, P = c.keyIndex;
255
+ const u = c.index, d = c.key, P = c.keyIndex;
219
256
  if (!c.stable)
220
257
  return;
221
- const w = r.parseStable(c.stable), m = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
222
- let p = w;
223
- if (u.isProcessInprogress(p) || (i[P] = !0), s) {
224
- let b = r.processedSchemas.value[m][g][f][a];
225
- b && u.isObject(b) && a !== "component" && (p = Object.assign(b, p)), r.processedSchemas.value[m][g][f][a] = p, r.stableUpdater(i);
258
+ const C = r.parseStable(c.stable), y = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
259
+ let a = C;
260
+ if (f.isProcessInprogress(a) || (i[P] = !0), s) {
261
+ let p = r.processedSchemas.value[y][g][u][d];
262
+ p && f.isObject(p) && d !== "component" && (a = Object.assign(p, a)), r.processedSchemas.value[y][g][u][d] = a, r.stableUpdater(i);
226
263
  } else {
227
- let b = r.processedSchemas.value[f][a];
228
- b && u.isObject(b) && (p = Object.assign(b, p)), r.processedSchemas.value[f][a] = p, r.stableUpdater(i);
264
+ let p = r.processedSchemas.value[u][d];
265
+ p && f.isObject(p) && (a = Object.assign(p, a)), r.processedSchemas.value[u][d] = a, r.stableUpdater(i);
229
266
  }
230
267
  }
231
268
  }
@@ -248,7 +285,7 @@ class N {
248
285
  stable: c
249
286
  });
250
287
  };
251
- if (u.isFunction(t[r]))
288
+ if (f.isFunction(t[r]))
252
289
  r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
253
290
  if (r === "component") {
254
291
  const c = t[r](this.getRuntimeMeta());
@@ -257,16 +294,16 @@ class N {
257
294
  this.fieldParser(t[r], n);
258
295
  }) : this.defaultValueEffect.trackEffect(() => {
259
296
  const c = this.schemaEffect.trackEffect(() => {
260
- /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (f) => {
261
- if (!f)
262
- return n(f);
263
- this.defaultValueInprogressMap.set(t[r], f), !u.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
264
- (a) => !a.includes("undefined")
265
- ) ? (n(f), this.defaultValueEffect.clearEffects(), c()) : n(f);
266
- }) : this.fieldParser(t[r], (f) => {
267
- this.defaultValueInprogressMap.set(t[r], f), !u.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
268
- (a) => !a.includes("undefined")
269
- ) ? (n(f), this.defaultValueEffect.clearEffects(), c()) : n(f);
297
+ /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (u) => {
298
+ if (!u)
299
+ return n(u);
300
+ this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
301
+ (d) => !d.includes("undefined")
302
+ ) ? (n(u), this.defaultValueEffect.clearEffects(), c()) : n(u);
303
+ }) : this.fieldParser(t[r], (u) => {
304
+ this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
305
+ (d) => !d.includes("undefined")
306
+ ) ? (n(u), this.defaultValueEffect.clearEffects(), c()) : n(u);
270
307
  });
271
308
  });
272
309
  });
@@ -279,26 +316,26 @@ class N {
279
316
  });
280
317
  }
281
318
  promiseFieldParser(e, t, s) {
282
- u.isPromise(e) ? e.then((r) => {
283
- s && u.isObject(r) ? this.objectParser({
319
+ f.isPromise(e) ? e.then((r) => {
320
+ s && f.isObject(r) ? this.objectParser({
284
321
  data: r,
285
322
  updater: t
286
323
  }) : t(r);
287
- }) : s && u.isObject(e) ? this.objectParser({
324
+ }) : s && f.isObject(e) ? this.objectParser({
288
325
  data: e,
289
326
  updater: t
290
327
  }) : t(e);
291
328
  }
292
329
  // 对任意对象中单个字段的 parse: 做基本处理
293
330
  fieldParser(e, t, s = !0) {
294
- if (u.isFunction(e)) {
331
+ if (f.isFunction(e)) {
295
332
  const r = e(this.getRuntimeMeta());
296
333
  this.promiseFieldParser(r, t, s);
297
334
  } else
298
- M(e) ? E(
335
+ D(e) ? E(
299
336
  () => e.value,
300
337
  () => {
301
- u.isUndefined(e.value) || (s && u.isObject(e.value) ? this.objectParser({
338
+ f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
302
339
  data: e.value,
303
340
  updater: t
304
341
  }) : t(e.value));
@@ -307,10 +344,10 @@ class N {
307
344
  immediate: !0,
308
345
  deep: !0
309
346
  }
310
- ) : U(e) ? E(
347
+ ) : M(e) ? E(
311
348
  () => e,
312
349
  () => {
313
- u.isUndefined(e) || (s && u.isObject(e) ? this.objectParser({
350
+ f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
314
351
  data: e,
315
352
  updater: t
316
353
  }) : t(e));
@@ -319,7 +356,7 @@ class N {
319
356
  immediate: !0,
320
357
  deep: !0
321
358
  }
322
- ) : s && u.isObject(e) ? this.objectParser({
359
+ ) : s && f.isObject(e) ? this.objectParser({
323
360
  data: e,
324
361
  updater: t
325
362
  }) : t(e);
@@ -327,20 +364,20 @@ class N {
327
364
  modelProcessor(e) {
328
365
  e.map(
329
366
  (t) => this.createModel(t, this.processedModel.value)
330
- ), u.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = V(this.processedModel.value));
367
+ ), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = v(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
331
368
  }
332
369
  createModel(e, t) {
333
- u.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
370
+ f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
334
371
  this.createModel(s, t[e.field][0]);
335
- })), u.isGroupSchema(e) && e.children.forEach((s) => {
372
+ })), f.isGroupSchema(e) && e.children.forEach((s) => {
336
373
  this.createModel(s, t);
337
- }), u.isItemSchema(e) && (t[e.field] = e.defaultValue);
374
+ }), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
338
375
  }
339
376
  }
340
- function A(l) {
341
- return typeof l == "function" || Object.prototype.toString.call(l) === "[object Object]" && !L(l);
377
+ function x(l) {
378
+ return typeof l == "function" || Object.prototype.toString.call(l) === "[object Object]" && !F(l);
342
379
  }
343
- class T {
380
+ class q {
344
381
  constructor(e) {
345
382
  o(this, "schemas", I([]));
346
383
  o(this, "model", I({}));
@@ -350,49 +387,57 @@ class T {
350
387
  list: this.runtimeListProcessor.bind(this)
351
388
  });
352
389
  o(this, "formRef", I(null));
353
- this.setup = e, this.processor = new N(this);
390
+ o(this, "hydrateEffect", new w());
391
+ this.setup = e, this.processor = new B(this);
354
392
  const t = this.setup(this);
355
393
  this.processor.parseSchemas(t.schemas);
356
394
  }
357
395
  getRuntimeMeta() {
358
396
  return {
359
- model: j(V(this.model.value))
397
+ model: V(v(this.model.value))
360
398
  };
361
399
  }
362
400
  runtimeItemProcessor(e, t, s = this.model.value, r) {
363
401
  var g;
364
- const i = r ? `${r.field}.${t}.${e.field}` : e.field, n = j(e.component);
402
+ const i = r ? `${r.field}.${t}.${e.field}` : e.field, n = V(e.component);
365
403
  if (!n)
366
404
  return;
367
- const c = n.name, f = e.componentProps ?? {}, a = S.placeholderPresetByComponentName;
405
+ const c = n.name, u = e.componentProps ?? {}, d = j.placeholderPresetByComponentName;
368
406
  let P = e.placeholder;
369
- P || (P = `${// @ts-expect-error
370
- a[c] ?? "请输入"}${e.label}`), e.required && (e.rules || (e.rules = []), (g = e.rules) == null || g.push({
371
- required: !0,
372
- message: `${e.label}是必填项`
373
- }));
374
- let m = e.show;
375
- return m === void 0 && (m = !0), m || delete s[e.field], d(h.runtimeDoms.Item, null, {
407
+ if (P || (P = `${// @ts-expect-error
408
+ d[c] ?? "请输入"}${e.label}`), e.required) {
409
+ e.rules || (e.rules = []);
410
+ const a = e.rules.findIndex((p) => !!p.required);
411
+ a === -1 ? (g = e.rules) == null || g.push({
412
+ required: !0,
413
+ message: `${e.label}是必填项`
414
+ }) : e.rules.splice(a, 1, {
415
+ required: !0,
416
+ message: `${e.label}是必填项`
417
+ });
418
+ }
419
+ let y = e.show;
420
+ return y === void 0 && (y = !0), y || delete s[e.field], h(m.runtimeDoms.Item, null, {
376
421
  default() {
377
- return v(d(h.runtimeDoms.FormItem, {
422
+ return O(h(m.runtimeDoms.FormItem, {
378
423
  label: `${e.label}:`,
379
424
  rules: e.rules,
380
425
  field: i
381
426
  }, {
382
- default: () => [d(n, R({
427
+ default: () => [h(n, k({
383
428
  modelValue: s[e.field],
384
- "onUpdate:modelValue": (p) => s[e.field] = p,
429
+ "onUpdate:modelValue": (a) => s[e.field] = a,
385
430
  placeholder: P
386
- }, f), null)]
387
- }), [[O, m]]);
431
+ }, u), null)]
432
+ }), [[A, y]]);
388
433
  }
389
434
  });
390
435
  }
391
436
  runtimeGroupProcessor(e) {
392
437
  let t;
393
- return d(h.runtimeDoms.Group, {
438
+ return h(m.runtimeDoms.Group, {
394
439
  schema: e
395
- }, A(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
440
+ }, x(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
396
441
  default: () => [t]
397
442
  });
398
443
  }
@@ -403,37 +448,41 @@ class T {
403
448
  code: "0001",
404
449
  message: "异步默认值数据正在处理中,请您耐心等待... "
405
450
  });
406
- (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(V(this.processor.stableModel[e.field][0]));
451
+ (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(v(this.processor.stableModel[e.field][0]));
407
452
  }
408
453
  deleteListItem(e, t) {
409
454
  this.model.value[e.field].splice(t, 1);
455
+ const s = e.children.map(({
456
+ field: r
457
+ }) => `${e.field}.${t}.${r}`);
458
+ this.formRef.value.clearValidate(s);
410
459
  }
411
460
  runtimeListProcessor(e) {
412
461
  const t = this;
413
- return t.model.value[e.field] || (t.model.value[e.field] = [{}]), d(h.runtimeDoms.List, {
462
+ return t.model.value[e.field] || (t.model.value[e.field] = [{}]), h(m.runtimeDoms.List, {
414
463
  schema: e
415
464
  }, {
416
465
  default() {
417
- return t.model.value[e.field].map((s, r) => d(h.runtimeDoms.ListItem, null, {
466
+ return t.model.value[e.field].map((s, r) => h(m.runtimeDoms.ListItem, null, {
418
467
  default() {
419
- return e.children.map((i, n) => t.runtimeItemProcessor(i, n, s, e));
468
+ return e.children.map((i) => t.runtimeItemProcessor(i, r, s, e));
420
469
  },
421
470
  delete({
422
471
  container: i
423
472
  } = {}) {
424
473
  var c;
425
- let n = i ?? d("button", null, null);
426
- return v(d(n, {
474
+ let n = i ?? h("button", null, null);
475
+ return O(h(n, {
427
476
  onClick: () => t.deleteListItem(e, r)
428
- }, null), [[O, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
477
+ }, null), [[A, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
429
478
  }
430
479
  }));
431
480
  },
432
481
  add({
433
482
  container: s
434
483
  } = {}) {
435
- let r = s ?? d("button", null, [k("添加")]);
436
- return d(r, {
484
+ let r = s ?? h("button", null, [L("添加")]);
485
+ return h(r, {
437
486
  onClick: () => t.addListItem(e)
438
487
  }, null);
439
488
  }
@@ -444,18 +493,18 @@ class T {
444
493
  }
445
494
  exec() {
446
495
  let e;
447
- return d(h.runtimeDoms.Form, {
496
+ return h(m.runtimeDoms.Form, {
448
497
  ref: this.formRef,
449
498
  model: this.model.value
450
- }, A(e = this.runtimeProcessor(this.schemas.value)) ? e : {
499
+ }, x(e = this.runtimeProcessor(this.schemas.value)) ? e : {
451
500
  default: () => [e]
452
501
  });
453
502
  }
454
503
  }
455
- class h {
504
+ class m {
456
505
  }
457
- o(h, "runtimeDoms");
458
- const y = class y {
506
+ o(m, "runtimeDoms");
507
+ const b = class b {
459
508
  static getPlaceholderPrefixPresetByComponentName() {
460
509
  const e = {
461
510
  请选择: ["Select", "Tree", "TreeSelect"],
@@ -468,7 +517,7 @@ const y = class y {
468
517
  return t;
469
518
  }
470
519
  };
471
- o(y, "schemaPreset", {
520
+ o(b, "schemaPreset", {
472
521
  type: {
473
522
  defaultValue: "item"
474
523
  },
@@ -502,14 +551,14 @@ o(y, "schemaPreset", {
502
551
  children: {
503
552
  defaultValue: []
504
553
  }
505
- }), o(y, "componentPropsPreset", {
554
+ }), o(b, "componentPropsPreset", {
506
555
  options: {
507
556
  defaultValue: []
508
557
  }
509
558
  }), // 基于基本功能提出基本预设
510
- o(y, "placeholderPresetByComponentName", y.getPlaceholderPrefixPresetByComponentName());
511
- let S = y;
512
- const $ = /* @__PURE__ */ F({
559
+ o(b, "placeholderPresetByComponentName", b.getPlaceholderPrefixPresetByComponentName());
560
+ let j = b;
561
+ const _ = /* @__PURE__ */ z({
513
562
  props: {
514
563
  setup: {
515
564
  type: Function,
@@ -517,28 +566,29 @@ const $ = /* @__PURE__ */ F({
517
566
  }
518
567
  },
519
568
  setup(l) {
520
- const e = new T(l.setup);
569
+ const e = new q(l.setup);
521
570
  return () => e.exec();
522
571
  }
523
572
  });
524
- function q(l) {
525
- const e = new B(l);
573
+ function G(l) {
574
+ const e = new $(l);
526
575
  return [
527
576
  e.setup.bind(e),
528
577
  {
529
- submit: e.submit.bind(e)
578
+ submit: e.submit.bind(e),
579
+ hydrate: e.hydrate.bind(e)
530
580
  }
531
581
  ];
532
582
  }
533
- function G(l) {
583
+ function K(l) {
534
584
  return {
535
585
  install() {
536
- h.runtimeDoms = l;
586
+ m.runtimeDoms = l;
537
587
  }
538
588
  };
539
589
  }
540
590
  export {
541
- $ as ProForm,
542
- q as useForm,
543
- G as useFormRenderer
591
+ _ as ProForm,
592
+ G as useForm,
593
+ K as useFormRenderer
544
594
  };
@@ -1,8 +1,9 @@
1
1
  import { AnyFunction } from "../types";
2
+ import { TrackEffectMeta } from "../types/effectTypes";
2
3
  export default class Effect {
3
4
  effects: Set<Function>;
4
5
  constructor();
5
6
  clearEffects(): void;
6
7
  triggerEffects(): void;
7
- trackEffect(effect: AnyFunction): () => boolean;
8
+ trackEffect(effect: AnyFunction, meta?: TrackEffectMeta): () => boolean;
8
9
  }
@@ -7,4 +7,5 @@ export default class FormCustomizer {
7
7
  constructor(formCustomization: FormCustomization);
8
8
  setup(_runtimeCore: RuntimeCore): FormCustomization;
9
9
  submit(): Promise<AnyObject>;
10
+ hydrate(data: AnyObject): void;
10
11
  }
@@ -7,6 +7,7 @@ import Effect from "./Effect";
7
7
  * 对于函数的命名,如果是动词相关,代表对过程的处理,如果是名词,代表一个处理器
8
8
  */
9
9
  export default class Processor {
10
+ runtimeCore: RuntimeCore;
10
11
  processedSchemas: Ref<AnyObject[]>;
11
12
  processedModel: Ref<AnyObject>;
12
13
  getRuntimeMeta: AnyFunction;
@@ -1,6 +1,7 @@
1
1
  import { Ref } from "vue";
2
2
  import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType } from "../types";
3
3
  import Processor from "./Processor";
4
+ import Effect from "./Effect";
4
5
  export default class RuntimeCore {
5
6
  setup: Setup;
6
7
  processor: Processor;
@@ -8,6 +9,7 @@ export default class RuntimeCore {
8
9
  model: Ref<AnyObject>;
9
10
  processorBySchemaType: ProcessorBySchemaType;
10
11
  formRef: Ref<AnyObject>;
12
+ hydrateEffect: Effect;
11
13
  constructor(setup: Setup);
12
14
  getRuntimeMeta(): {
13
15
  model: AnyObject;
@@ -0,0 +1,3 @@
1
+ export interface TrackEffectMeta {
2
+ lazy?: boolean;
3
+ }
@@ -47,7 +47,10 @@ export interface ListSchema {
47
47
  children: ProxyedSchema[];
48
48
  }
49
49
  export type Schema = ItemSchema | GroupSchema | ListSchema;
50
- export type ProFormProxyRule<T> = T | ((...args: any) => T) | ((...args: any) => Promise<T>);
50
+ export interface runtimeMeta {
51
+ model: AnyObject;
52
+ }
53
+ export type ProFormProxyRule<T> = T | ((runtimeMeta: runtimeMeta) => T) | ((runtimeMeta: runtimeMeta) => Promise<T>);
51
54
  export type ProFormProxy<T> = {
52
55
  [K in keyof T]: ProFormProxyRule<T[K]>;
53
56
  };
@@ -5,5 +5,6 @@ export type UseForm = [
5
5
  Setup,
6
6
  {
7
7
  submit: () => Promise<AnyObject>;
8
+ hydrate: (data: AnyObject) => any;
8
9
  }
9
10
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbor-design/proform",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",