@harbor-design/proform 1.0.10 → 1.0.12

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,p=a.key,P=a.keyIndex;if(!a.stable)return;const j=r.parseStable(a.stable),b=s==null?void 0:s.index,g=s==null?void 0:s.key;let d=j;if(u.isProcessInprogress(d)||(i[P]=!0),s){let h=r.processedSchemas.value[b][g][f][p];h&&u.isObject(h)&&p!=="component"&&(d=Object.assign(h,d)),r.processedSchemas.value[b][g][f][p]=d,r.stableUpdater(i)}else{let h=r.processedSchemas.value[f][p];h&&u.isObject(h)&&(d=Object.assign(h,d)),r.processedSchemas.value[f][p]=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 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(p=>!p.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(p=>!p.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??{},p=V.placeholderPresetByComponentName;let P=e.placeholder;if(P||(P=`${p[a]??"请输入"}${e.label}`),e.required){e.rules||(e.rules=[]);const d=e.rules.findIndex(h=>!!h.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 b=e.show;return b===void 0&&(b=!0),b||delete s[e.field],n.createVNode(m.runtimeDoms.Item,null,{default(){return n.withDirectives(n.createVNode(m.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:i},{default:()=>[n.createVNode(o,n.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":d=>s[e.field]=d,placeholder:P},f),null)]}),[[n.vShow,b]])}})}runtimeGroupProcessor(e){let t;return n.createVNode(m.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);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]=[{}]),n.createVNode(m.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>n.createVNode(m.runtimeDoms.ListItem,null,{default(){return e.children.map(i=>t.runtimeItemProcessor(i,r,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(m.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},E(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class m{}l(m,"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(){m.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)if(!e.rules)e.rules=[],(g=e.rules)==null||g.push({required:!0,message:`${e.label}是必填项`});else{const d=e.rules.findIndex(p=>!!p.required);e.rules[d].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 V, watch as E, isRef as M, isReactive as R, ref as I, createVNode as p, withDirectives as w, mergeProps as U, vShow as O, createTextVNode as k, isVNode as L, defineComponent as F } from "vue";
5
- class $ {
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
- V(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 j(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 j(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
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 B {
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
- j(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;
@@ -203,7 +240,7 @@ class B {
203
240
  stableUpdater(e = []) {
204
241
  if (e.every(Boolean)) {
205
242
  const t = V(this.processedSchemas.value);
206
- !u.isProcessInprogress(t) && u.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
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 B {
215
252
  }).fill(!1);
216
253
  this.objectParser({ data: e, index: t, updater: n });
217
254
  function n(c) {
218
- const f = c.index, d = 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 v = r.parseStable(c.stable), b = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
222
- let a = v;
223
- if (u.isProcessInprogress(a) || (i[P] = !0), s) {
224
- let h = r.processedSchemas.value[b][g][f][d];
225
- h && u.isObject(h) && d !== "component" && (a = Object.assign(h, a)), r.processedSchemas.value[b][g][f][d] = a, 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 h = r.processedSchemas.value[f][d];
228
- h && u.isObject(h) && (a = Object.assign(h, a)), r.processedSchemas.value[f][d] = a, 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 B {
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 B {
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(
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(
264
301
  (d) => !d.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(
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(
268
305
  (d) => !d.includes("undefined")
269
- ) ? (n(f), this.defaultValueEffect.clearEffects(), c()) : n(f);
306
+ ) ? (n(u), this.defaultValueEffect.clearEffects(), c()) : n(u);
270
307
  });
271
308
  });
272
309
  });
@@ -279,26 +316,26 @@ class B {
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 B {
307
344
  immediate: !0,
308
345
  deep: !0
309
346
  }
310
- ) : R(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 B {
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 B {
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 = j(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 q {
380
+ class N {
344
381
  constructor(e) {
345
382
  o(this, "schemas", I([]));
346
383
  o(this, "model", I({}));
@@ -350,13 +387,14 @@ class q {
350
387
  list: this.runtimeListProcessor.bind(this)
351
388
  });
352
389
  o(this, "formRef", I(null));
390
+ o(this, "hydrateEffect", new w());
353
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: V(j(this.model.value))
397
+ model: V(v(this.model.value))
360
398
  };
361
399
  }
362
400
  runtimeItemProcessor(e, t, s = this.model.value, r) {
@@ -364,42 +402,41 @@ class q {
364
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 ?? {}, d = S.placeholderPresetByComponentName;
405
+ const c = n.name, u = e.componentProps ?? {}, d = j.placeholderPresetByComponentName;
368
406
  let P = e.placeholder;
369
407
  if (P || (P = `${// @ts-expect-error
370
- d[c] ?? "请输入"}${e.label}`), e.required) {
371
- e.rules || (e.rules = []);
372
- const a = e.rules.findIndex((h) => !!h.required);
373
- a === -1 ? (g = e.rules) == null || g.push({
374
- required: !0,
375
- message: `${e.label}是必填项`
376
- }) : e.rules.splice(a, 1, {
377
- required: !0,
378
- message: `${e.label}是必填项`
379
- });
380
- }
381
- let b = e.show;
382
- return b === void 0 && (b = !0), b || delete s[e.field], p(m.runtimeDoms.Item, null, {
408
+ d[c] ?? "请输入"}${e.label}`), e.required)
409
+ if (!e.rules)
410
+ e.rules = [], (g = e.rules) == null || g.push({
411
+ required: !0,
412
+ message: `${e.label}是必填项`
413
+ });
414
+ else {
415
+ const a = e.rules.findIndex((p) => !!p.required);
416
+ e.rules[a].message = `${e.label}是必填项`;
417
+ }
418
+ let y = e.show;
419
+ return y === void 0 && (y = !0), y || delete s[e.field], h(m.runtimeDoms.Item, null, {
383
420
  default() {
384
- return w(p(m.runtimeDoms.FormItem, {
421
+ return O(h(m.runtimeDoms.FormItem, {
385
422
  label: `${e.label}:`,
386
423
  rules: e.rules,
387
424
  field: i
388
425
  }, {
389
- default: () => [p(n, U({
426
+ default: () => [h(n, k({
390
427
  modelValue: s[e.field],
391
428
  "onUpdate:modelValue": (a) => s[e.field] = a,
392
429
  placeholder: P
393
- }, f), null)]
394
- }), [[O, b]]);
430
+ }, u), null)]
431
+ }), [[A, y]]);
395
432
  }
396
433
  });
397
434
  }
398
435
  runtimeGroupProcessor(e) {
399
436
  let t;
400
- return p(m.runtimeDoms.Group, {
437
+ return h(m.runtimeDoms.Group, {
401
438
  schema: e
402
- }, A(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
439
+ }, x(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
403
440
  default: () => [t]
404
441
  });
405
442
  }
@@ -410,7 +447,7 @@ class q {
410
447
  code: "0001",
411
448
  message: "异步默认值数据正在处理中,请您耐心等待... "
412
449
  });
413
- (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(j(this.processor.stableModel[e.field][0]));
450
+ (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(v(this.processor.stableModel[e.field][0]));
414
451
  }
415
452
  deleteListItem(e, t) {
416
453
  this.model.value[e.field].splice(t, 1);
@@ -421,11 +458,11 @@ class q {
421
458
  }
422
459
  runtimeListProcessor(e) {
423
460
  const t = this;
424
- return t.model.value[e.field] || (t.model.value[e.field] = [{}]), p(m.runtimeDoms.List, {
461
+ return t.model.value[e.field] || (t.model.value[e.field] = [{}]), h(m.runtimeDoms.List, {
425
462
  schema: e
426
463
  }, {
427
464
  default() {
428
- return t.model.value[e.field].map((s, r) => p(m.runtimeDoms.ListItem, null, {
465
+ return t.model.value[e.field].map((s, r) => h(m.runtimeDoms.ListItem, null, {
429
466
  default() {
430
467
  return e.children.map((i) => t.runtimeItemProcessor(i, r, s, e));
431
468
  },
@@ -433,18 +470,18 @@ class q {
433
470
  container: i
434
471
  } = {}) {
435
472
  var c;
436
- let n = i ?? p("button", null, null);
437
- return w(p(n, {
473
+ let n = i ?? h("button", null, null);
474
+ return O(h(n, {
438
475
  onClick: () => t.deleteListItem(e, r)
439
- }, null), [[O, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
476
+ }, null), [[A, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
440
477
  }
441
478
  }));
442
479
  },
443
480
  add({
444
481
  container: s
445
482
  } = {}) {
446
- let r = s ?? p("button", null, [k("添加")]);
447
- return p(r, {
483
+ let r = s ?? h("button", null, [L("添加")]);
484
+ return h(r, {
448
485
  onClick: () => t.addListItem(e)
449
486
  }, null);
450
487
  }
@@ -455,10 +492,10 @@ class q {
455
492
  }
456
493
  exec() {
457
494
  let e;
458
- return p(m.runtimeDoms.Form, {
495
+ return h(m.runtimeDoms.Form, {
459
496
  ref: this.formRef,
460
497
  model: this.model.value
461
- }, A(e = this.runtimeProcessor(this.schemas.value)) ? e : {
498
+ }, x(e = this.runtimeProcessor(this.schemas.value)) ? e : {
462
499
  default: () => [e]
463
500
  });
464
501
  }
@@ -466,7 +503,7 @@ class q {
466
503
  class m {
467
504
  }
468
505
  o(m, "runtimeDoms");
469
- const y = class y {
506
+ const b = class b {
470
507
  static getPlaceholderPrefixPresetByComponentName() {
471
508
  const e = {
472
509
  请选择: ["Select", "Tree", "TreeSelect"],
@@ -479,7 +516,7 @@ const y = class y {
479
516
  return t;
480
517
  }
481
518
  };
482
- o(y, "schemaPreset", {
519
+ o(b, "schemaPreset", {
483
520
  type: {
484
521
  defaultValue: "item"
485
522
  },
@@ -513,14 +550,14 @@ o(y, "schemaPreset", {
513
550
  children: {
514
551
  defaultValue: []
515
552
  }
516
- }), o(y, "componentPropsPreset", {
553
+ }), o(b, "componentPropsPreset", {
517
554
  options: {
518
555
  defaultValue: []
519
556
  }
520
557
  }), // 基于基本功能提出基本预设
521
- o(y, "placeholderPresetByComponentName", y.getPlaceholderPrefixPresetByComponentName());
522
- let S = y;
523
- const _ = /* @__PURE__ */ F({
558
+ o(b, "placeholderPresetByComponentName", b.getPlaceholderPrefixPresetByComponentName());
559
+ let j = b;
560
+ const q = /* @__PURE__ */ z({
524
561
  props: {
525
562
  setup: {
526
563
  type: Function,
@@ -528,20 +565,21 @@ const _ = /* @__PURE__ */ F({
528
565
  }
529
566
  },
530
567
  setup(l) {
531
- const e = new q(l.setup);
568
+ const e = new N(l.setup);
532
569
  return () => e.exec();
533
570
  }
534
571
  });
535
- function z(l) {
572
+ function G(l) {
536
573
  const e = new $(l);
537
574
  return [
538
575
  e.setup.bind(e),
539
576
  {
540
- submit: e.submit.bind(e)
577
+ submit: e.submit.bind(e),
578
+ hydrate: e.hydrate.bind(e)
541
579
  }
542
580
  ];
543
581
  }
544
- function G(l) {
582
+ function K(l) {
545
583
  return {
546
584
  install() {
547
585
  m.runtimeDoms = l;
@@ -549,7 +587,7 @@ function G(l) {
549
587
  };
550
588
  }
551
589
  export {
552
- _ as ProForm,
553
- z as useForm,
554
- G as useFormRenderer
590
+ q as ProForm,
591
+ G as useForm,
592
+ K as useFormRenderer
555
593
  };
@@ -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
+ }
@@ -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.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",