@harbor-design/proform 1.0.18 → 1.0.19

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 _=Object.defineProperty;var L=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>(L(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue");class f{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function d(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=d(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=d(n[s]||{},t[s]):n[s]=t[s])}),n}function y(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const i=new Map;for(let[l,a]of s)i.set(t(l),t(a));return i}if(s instanceof Set){const i=new Set;for(let l of s)i.add(t(l));return i}if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=[];e.set(s,i);for(let l=0;l<s.length;l++)i[l]=t(s[l]);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(n)}class T{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){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{o.isRef(e)?o.watch(()=>e.value,()=>{d(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):o.isReactive(e)?o.watch(()=>e,()=>{d(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):d(this.runtimeCore.model.value,e)},{lazy:!0})}customize(e){Object.assign(this.runtimeCore.customizedOptions,e)}}class I{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 B{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 I);c(this,"defaultValueEffect",new I);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 l in i)i.hasOwnProperty(l)&&(l==="defaultValue"&&typeof i[l]=="function"&&!i[l].toString().includes("[native code]")&&t++,r(i[l]))}}return r(e),t}parseSchemas(e,t){f.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(y(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!f.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);!f.isProcessInprogress(t)&&f.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:l});function l(a){const u=a.index,m=a.key,S=a.keyIndex;if(!a.stable)return;const E=r.parseStable(a.stable),P=s==null?void 0:s.index,j=s==null?void 0:s.key;let p=E;if(f.isProcessInprogress(p)||(i[S]=!0),s){let h=r.processedSchemas.value[P][j][u][m];h&&f.isObject(h)&&m!=="component"&&(p=d(h,p)),r.processedSchemas.value[P][j][u][m]=p,r.stableUpdater(i)}else{let h=r.processedSchemas.value[u][m];h&&f.isObject(h)&&(p=d(h,p)),r.processedSchemas.value[u][m]=p,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 l=a=>{e.updater({...e,key:r,keyIndex:i,stable:a})};f.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const a=t[r](this.getRuntimeMeta());this.promiseFieldParser(a,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const a=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],u=>{if(!u)return l(u);this.defaultValueInprogressMap.set(t[r],u),!f.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(m=>!m.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),o.nextTick(()=>{a()})):l(u)}):this.fieldParser(t[r],u=>{this.defaultValueInprogressMap.set(t[r],u),!f.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(m=>!m.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),o.nextTick(()=>{a()})):l(u)})})}):r==="component"||r==="slots"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}replaceUndefinedInString(e,t){return e.replace(/undefined/g,t)}promiseFieldParser(e,t,s){f.isPromise(e)?e.then(r=>{s&&f.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(f.isString(e)&&(e=this.replaceUndefinedInString(e,"")),s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(f.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else o.isRef(e)?o.watch(()=>e.value,()=>{f.isUndefined(e.value)||(s&&f.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):o.isReactive(e)?o.watch(()=>e,()=>{f.isUndefined(e)||(s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),f.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=y(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){f.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),f.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),f.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function q(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!o.isVNode(n)}class ${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 I);c(this,"customizedOptions",o.reactive({}));c(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new B(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:o.toRaw(y(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var h,w,O,C,N,A,F,M,R,z,x,D,U;d(this.globalNativeFormOverride.props,(w=(h=e.native)==null?void 0:h.props)==null?void 0:w.Form),d(this.globalNativeFormOverride.slots,(C=(O=e.native)==null?void 0:O.slots)==null?void 0:C.Form);const i=d(y((A=(N=this.customizedOptions.native)==null?void 0:N.props)==null?void 0:A.FormItem)??{},(M=(F=e.native)==null?void 0:F.props)==null?void 0:M.FormItem),l=d(y((z=(R=this.customizedOptions.native)==null?void 0:R.slots)==null?void 0:z.FormItem)??{},(D=(x=e.native)==null?void 0:x.slots)==null?void 0:D.FormItem),a=r?`${r.field}.${t}.${e.field}`:e.field,u=o.toRaw(e.component);if(!u)return;const m=u.name,S=e.componentProps??{},E=v.placeholderPresetByComponentName;let P=e.placeholder;if(P||(P=`${E[m]??"请输入"}${e.label}`),e.required)if(!e.rules)e.rules=[],(U=e.rules)==null||U.push({required:!0,message:`${e.label}是必填项`});else{const V=e.rules.findIndex(k=>!!k.required);e.rules[V].message=`${e.label}是必填项`}let p=e.show;return p===void 0&&(p=!0),p||delete s[e.field],o.createVNode(b.runtimeDoms.Item,null,{default(){return o.withDirectives(o.createVNode(b.runtimeDoms.FormItem,o.mergeProps(i,{label:`${e.label}:`,rules:e.rules,field:a}),{default(){return o.createVNode(u,o.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":V=>s[e.field]=V,placeholder:P},S),null)},...l}),[[o.vShow,p]])}})}runtimeGroupProcessor(e){let t;return o.createVNode(b.runtimeDoms.Group,{schema:e},q(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(y(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),o.createVNode(b.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>o.createVNode(b.runtimeDoms.ListItem,null,{default(){return e.children.map(i=>t.runtimeItemProcessor(i,r,s,e))},delete({container:i}={}){var a;let l=i??o.createVNode("button",null,null);return o.withDirectives(o.createVNode(l,{onClick:()=>t.deleteListItem(e,r)},null),[[o.vShow,((a=t.model.value[e.field])==null?void 0:a.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(){var r,i,l,a;const e=this,t=d(y((i=(r=this.customizedOptions.native)==null?void 0:r.props)==null?void 0:i.Form)??{},this.globalNativeFormOverride.props),s=d(y((a=(l=this.customizedOptions.native)==null?void 0:l.slots)==null?void 0:a.Form)??{},this.globalNativeFormOverride.slots);return o.createVNode(b.runtimeDoms.Form,o.mergeProps(t,{ref:this.formRef,model:this.model.value}),{default(){return e.runtimeProcessor(e.schemas.value)},...s})}}class b{}c(b,"runtimeDoms");const g=class g{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};c(g,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0}),c(g,"componentPropsPreset",{options:{defaultValue:[]}}),c(g,"placeholderPresetByComponentName",g.getPlaceholderPrefixPresetByComponentName());let v=g;const G=o.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new $(n.setup);return()=>e.exec()}});function K(n){const e=new T(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e),customize:e.customize.bind(e)}]}function W(n){return{install(){b.runtimeDoms=n}}}function H(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=G;exports.useForm=K;exports.useFormRenderer=W;exports.useModifiers=H;
1
+ "use strict";var L=Object.defineProperty;var T=(n,e,t)=>e in n?L(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>(T(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class u{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function y(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const o=new Map;for(let[l,f]of s)o.set(t(l),t(f));return o}if(s instanceof Set){const o=new Set;for(let l of s)o.add(t(l));return o}if(e.has(s))return e.get(s);if(Array.isArray(s)){const o=[];e.set(s,o);for(let l=0;l<s.length;l++)o[l]=t(s[l]);return o}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let o in s)s.hasOwnProperty(o)&&(r[o]=t(s[o]));return r}return t(n)}class B{constructor(e){a(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{i.isRef(e)?i.watch(()=>e.value,()=>{p(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):i.isReactive(e)?i.watch(()=>e,()=>{p(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):p(this.runtimeCore.model.value,e)},{lazy:!0})}customize(e){Object.assign(this.runtimeCore.customizedOptions,e),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps)}}class I{constructor(){a(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e,t={lazy:!1}){return!t.lazy&&e(),this.effects.add(e),()=>this.effects.delete(e)}}class q{constructor(e){a(this,"runtimeCore");a(this,"processedSchemas");a(this,"processedModel");a(this,"getRuntimeMeta");a(this,"stableSchemas",[]);a(this,"stableModel",{});a(this,"schemaPreset",v.schemaPreset);a(this,"componentPropsPreset",v.componentPropsPreset);a(this,"stableUpdaterProcessProgress");a(this,"stableUpdaterTimes",0);a(this,"schemaEffect",new I);a(this,"defaultValueEffect",new I);a(this,"defaultValueInprogressMap",new Map);a(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){u.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(y(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!u.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!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,o=Array.from({length:Object.keys(e).filter(f=>f!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(f){const c=f.index,d=f.key,j=f.keyIndex;if(!f.stable)return;const E=r.parseStable(f.stable),V=s==null?void 0:s.index,g=s==null?void 0:s.key;let h=E;if(u.isProcessInprogress(h)||(o[j]=!0),s){let m=r.processedSchemas.value[V][g][c][d];m&&u.isObject(m)&&d!=="component"&&(h=p(m,h)),r.processedSchemas.value[V][g][c][d]=h,r.stableUpdater(o)}else{let m=r.processedSchemas.value[c][d];m&&u.isObject(m)&&(h=p(m,h)),r.processedSchemas.value[c][d]=h,r.stableUpdater(o)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,o)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:o});else{const l=f=>{e.updater({...e,key:r,keyIndex:o,stable:f})};u.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const f=t[r](this.getRuntimeMeta());this.promiseFieldParser(f,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const f=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],c=>{if(!c)return l(c);this.defaultValueInprogressMap.set(t[r],c),!u.isProcessInprogress(c)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(c),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{f()})):l(c)}):this.fieldParser(t[r],c=>{this.defaultValueInprogressMap.set(t[r],c),!u.isProcessInprogress(c)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(c),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{f()})):l(c)})})}):r==="component"||r==="slots"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}replaceUndefinedInString(e,t){return e.replace(/undefined/g,t)}promiseFieldParser(e,t,s){u.isPromise(e)?e.then(r=>{s&&u.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(u.isString(e)&&(e=this.replaceUndefinedInString(e,"")),s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(u.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{u.isUndefined(e.value)||(s&&u.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.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=y(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 $(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class G{constructor(e){a(this,"schemas",i.ref([]));a(this,"model",i.ref({}));a(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});a(this,"formRef",i.ref(null));a(this,"hydrateEffect",new I);a(this,"customizedOptions",i.reactive({}));a(this,"gridProps",{});a(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new q(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(y(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var w,O,C,N,A,F,M,R,z,x,D,U,k;p(this.globalNativeFormOverride.props,(O=(w=e.native)==null?void 0:w.props)==null?void 0:O.Form),p(this.globalNativeFormOverride.slots,(N=(C=e.native)==null?void 0:C.slots)==null?void 0:N.Form);const o=p(y((F=(A=this.customizedOptions.native)==null?void 0:A.props)==null?void 0:F.FormItem)??{},(R=(M=e.native)==null?void 0:M.props)==null?void 0:R.FormItem),l=p(y((x=(z=this.customizedOptions.native)==null?void 0:z.slots)==null?void 0:x.FormItem)??{},(U=(D=e.native)==null?void 0:D.slots)==null?void 0:U.FormItem),f={display:"grid",gridColumn:"1 / -1",...e.gridProps},c=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const j=d.name,E=e.componentProps??{},V=v.placeholderPresetByComponentName;let g=e.placeholder;if(g||(g=`${V[j]??"请输入"}${e.label}`),e.required)if(!e.rules)e.rules=[],(k=e.rules)==null||k.push({required:!0,message:`${e.label}是必填项`});else{const S=e.rules.findIndex(_=>!!_.required);e.rules[S].message=`${e.label}是必填项`}let m=e.show;return m===void 0&&(m=!0),m||delete s[e.field],i.createVNode("div",{style:f},[i.createVNode(b.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(b.runtimeDoms.FormItem,i.mergeProps(o,{label:`${e.label}:`,rules:e.rules,field:c}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":S=>s[e.field]=S,placeholder:g},E),null)},...l}),[[i.vShow,m]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.gridProps};return i.createVNode("div",{style:s},[i.createVNode(b.runtimeDoms.Group,{schema:e},$(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(y(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.gridProps},s=this;return s.model.value[e.field]||(s.model.value[e.field]=[{}]),i.createVNode("div",{style:t},[i.createVNode(b.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(b.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var c;let f=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(f,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((c=s.model.value[e.field])==null?void 0:c.length)>1]])}}))},add({container:r}={}){let o=r??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.createVNode(o,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var o,l,f,c;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.gridProps},t=this,s=p(y((l=(o=this.customizedOptions.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(y((c=(f=this.customizedOptions.native)==null?void 0:f.slots)==null?void 0:c.Form)??{},this.globalNativeFormOverride.slots);return i.createVNode(b.runtimeDoms.Form,i.mergeProps(s,{ref:this.formRef,model:this.model.value}),{default(){return i.createVNode("div",{style:e},[t.runtimeProcessor(t.schemas.value)])},...r})}}class b{}a(b,"runtimeDoms");const P=class P{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};a(P,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0,gridProps:void 0}),a(P,"componentPropsPreset",{options:{defaultValue:[]}}),a(P,"placeholderPresetByComponentName",P.getPlaceholderPrefixPresetByComponentName());let v=P;const K=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new G(n.setup);return()=>e.exec()}});function W(n){const e=new B(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e),customize:e.customize.bind(e)}]}function H(n){return{install(){b.runtimeDoms=n}}}function J(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=K;exports.useForm=W;exports.useFormRenderer=H;exports.useModifiers=J;
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var H = Object.defineProperty;
2
- var J = (o, e, t) => e in o ? H(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var l = (o, e, t) => (J(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { toRaw as j, isRef as G, watch as v, isReactive as K, nextTick as T, ref as w, reactive as Q, createVNode as m, withDirectives as $, mergeProps as C, vShow as q, createTextVNode as X, isVNode as Y, defineComponent as Z } from "vue";
5
- class a {
1
+ var J = Object.defineProperty;
2
+ var Q = (o, e, t) => e in o ? J(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var l = (o, e, t) => (Q(o, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { toRaw as I, isRef as K, watch as v, isReactive as W, nextTick as $, ref as C, reactive as X, createVNode as c, withDirectives as q, mergeProps as w, vShow as G, createTextVNode as Y, isVNode as Z, defineComponent as ee } from "vue";
5
+ class f {
6
6
  static typeChecker(e) {
7
7
  return {}.toString.call(e);
8
8
  }
@@ -63,15 +63,15 @@ class a {
63
63
  return !1;
64
64
  }
65
65
  }
66
- function u(o, ...e) {
66
+ function p(o, ...e) {
67
67
  return e.forEach((t) => {
68
68
  if (Array.isArray(t))
69
69
  Array.isArray(o) || (o = []), t.forEach((s, r) => {
70
- typeof s == "object" && s !== null ? o[r] = u(Array.isArray(s) ? [] : {}, s) : o[r] = s;
70
+ typeof s == "object" && s !== null ? o[r] = p(Array.isArray(s) ? [] : {}, s) : o[r] = s;
71
71
  });
72
72
  else
73
73
  for (let s in t)
74
- t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? o[s] = u(o[s] || {}, t[s]) : o[s] = t[s]);
74
+ t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? o[s] = p(o[s] || {}, t[s]) : o[s] = t[s]);
75
75
  }), o;
76
76
  }
77
77
  function y(o) {
@@ -85,8 +85,8 @@ function y(o) {
85
85
  return new RegExp(s);
86
86
  if (s instanceof Map) {
87
87
  const i = /* @__PURE__ */ new Map();
88
- for (let [n, c] of s)
89
- i.set(t(n), t(c));
88
+ for (let [n, u] of s)
89
+ i.set(t(n), t(u));
90
90
  return i;
91
91
  }
92
92
  if (s instanceof Set) {
@@ -112,7 +112,7 @@ function y(o) {
112
112
  }
113
113
  return t(o);
114
114
  }
115
- class ee {
115
+ class te {
116
116
  constructor(e) {
117
117
  l(this, "runtimeCore");
118
118
  this.formCustomization = e;
@@ -130,7 +130,7 @@ class ee {
130
130
  return new Promise((e, t) => {
131
131
  this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
132
132
  this.cleanFallbackFields(
133
- j(this.runtimeCore.processor.processedModel.value)
133
+ I(this.runtimeCore.processor.processedModel.value)
134
134
  )
135
135
  ));
136
136
  });
@@ -143,25 +143,25 @@ class ee {
143
143
  });
144
144
  this.runtimeCore.hydrateEffect.trackEffect(
145
145
  () => {
146
- G(e) ? v(
146
+ K(e) ? v(
147
147
  () => e.value,
148
148
  () => {
149
- u(this.runtimeCore.model.value, e.value);
149
+ p(this.runtimeCore.model.value, e.value);
150
150
  },
151
151
  {
152
152
  deep: !0,
153
153
  immediate: !0
154
154
  }
155
- ) : K(e) ? v(
155
+ ) : W(e) ? v(
156
156
  () => e,
157
157
  () => {
158
- u(this.runtimeCore.model.value, e);
158
+ p(this.runtimeCore.model.value, e);
159
159
  },
160
160
  {
161
161
  deep: !0,
162
162
  immediate: !0
163
163
  }
164
- ) : u(this.runtimeCore.model.value, e);
164
+ ) : p(this.runtimeCore.model.value, e);
165
165
  },
166
166
  {
167
167
  lazy: !0
@@ -170,7 +170,7 @@ class ee {
170
170
  }
171
171
  // TODO:目前仅用于配制一些基本的如 Form,FormItem 等 UI 库组件的默认属性,但后续会扩展其价值,包括设置统一布局等,都会考虑往内部封装
172
172
  customize(e) {
173
- Object.assign(this.runtimeCore.customizedOptions, e);
173
+ Object.assign(this.runtimeCore.customizedOptions, e), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps);
174
174
  }
175
175
  }
176
176
  class A {
@@ -189,7 +189,7 @@ class A {
189
189
  return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
190
190
  }
191
191
  }
192
- class te {
192
+ class se {
193
193
  constructor(e) {
194
194
  l(this, "runtimeCore");
195
195
  l(this, "processedSchemas");
@@ -241,13 +241,13 @@ class te {
241
241
  }
242
242
  // 派生过程,用于外部应用
243
243
  parseSchemas(e, t) {
244
- a.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
244
+ f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
245
245
  y(e)
246
246
  ), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
247
247
  }
248
248
  parseStable(e) {
249
249
  const t = {};
250
- if (!a.isUndefined(e.stable))
250
+ if (!f.isUndefined(e.stable))
251
251
  t[e.key] = this.parseStable(e.stable);
252
252
  else
253
253
  return e;
@@ -256,8 +256,8 @@ class te {
256
256
  // 对于稳定初始化更新的抽象
257
257
  stableUpdater(e = []) {
258
258
  if (e.every(Boolean)) {
259
- const t = j(this.processedSchemas.value);
260
- !a.isProcessInprogress(t) && a.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
259
+ const t = I(this.processedSchemas.value);
260
+ !f.isProcessInprogress(t) && f.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
261
261
  length: t.length
262
262
  }).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
263
263
  }
@@ -265,21 +265,21 @@ class te {
265
265
  // 核心单 schema 处理过程,接收一个对象键值对的数据结构
266
266
  parseItem(e, t, s) {
267
267
  const r = this, i = Array.from({
268
- length: Object.keys(e).filter((c) => c !== "children").length
268
+ length: Object.keys(e).filter((u) => u !== "children").length
269
269
  }).fill(!1);
270
270
  this.objectParser({ data: e, index: t, updater: n });
271
- function n(c) {
272
- const f = c.index, p = c.key, I = c.keyIndex;
273
- if (!c.stable)
271
+ function n(u) {
272
+ const a = u.index, d = u.key, O = u.keyIndex;
273
+ if (!u.stable)
274
274
  return;
275
- const V = r.parseStable(c.stable), P = s == null ? void 0 : s.index, O = s == null ? void 0 : s.key;
276
- let d = V;
277
- if (a.isProcessInprogress(d) || (i[I] = !0), s) {
278
- let h = r.processedSchemas.value[P][O][f][p];
279
- h && a.isObject(h) && p !== "component" && (d = u(h, d)), r.processedSchemas.value[P][O][f][p] = d, r.stableUpdater(i);
275
+ const V = r.parseStable(u.stable), E = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
276
+ let h = V;
277
+ if (f.isProcessInprogress(h) || (i[O] = !0), s) {
278
+ let m = r.processedSchemas.value[E][g][a][d];
279
+ m && f.isObject(m) && d !== "component" && (h = p(m, h)), r.processedSchemas.value[E][g][a][d] = h, r.stableUpdater(i);
280
280
  } else {
281
- let h = r.processedSchemas.value[f][p];
282
- h && a.isObject(h) && (d = u(h, d)), r.processedSchemas.value[f][p] = d, r.stableUpdater(i);
281
+ let m = r.processedSchemas.value[a][d];
282
+ m && f.isObject(m) && (h = p(m, h)), r.processedSchemas.value[a][d] = h, r.stableUpdater(i);
283
283
  }
284
284
  }
285
285
  }
@@ -294,36 +294,36 @@ class te {
294
294
  keyIndex: i
295
295
  });
296
296
  else {
297
- const n = (c) => {
297
+ const n = (u) => {
298
298
  e.updater({
299
299
  ...e,
300
300
  key: r,
301
301
  keyIndex: i,
302
- stable: c
302
+ stable: u
303
303
  });
304
304
  };
305
- a.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
305
+ f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
306
306
  if (r === "component") {
307
- const c = t[r](this.getRuntimeMeta());
308
- this.promiseFieldParser(c, n, !1);
307
+ const u = t[r](this.getRuntimeMeta());
308
+ this.promiseFieldParser(u, n, !1);
309
309
  } else
310
310
  this.fieldParser(t[r], n);
311
311
  }) : this.defaultValueEffect.trackEffect(() => {
312
- const c = this.schemaEffect.trackEffect(() => {
313
- /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (f) => {
314
- if (!f)
315
- return n(f);
316
- this.defaultValueInprogressMap.set(t[r], f), !a.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
317
- (p) => !p.includes("undefined")
318
- ) ? (n(f), this.defaultValueEffect.clearEffects(), T(() => {
319
- c();
320
- })) : n(f);
321
- }) : this.fieldParser(t[r], (f) => {
322
- this.defaultValueInprogressMap.set(t[r], f), !a.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
323
- (p) => !p.includes("undefined")
324
- ) ? (n(f), this.defaultValueEffect.clearEffects(), T(() => {
325
- c();
326
- })) : n(f);
312
+ const u = this.schemaEffect.trackEffect(() => {
313
+ /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (a) => {
314
+ if (!a)
315
+ return n(a);
316
+ this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
317
+ (d) => !d.includes("undefined")
318
+ ) ? (n(a), this.defaultValueEffect.clearEffects(), $(() => {
319
+ u();
320
+ })) : n(a);
321
+ }) : this.fieldParser(t[r], (a) => {
322
+ this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
323
+ (d) => !d.includes("undefined")
324
+ ) ? (n(a), this.defaultValueEffect.clearEffects(), $(() => {
325
+ u();
326
+ })) : n(a);
327
327
  });
328
328
  });
329
329
  }) : r === "component" || r === "slots" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
@@ -334,19 +334,19 @@ class te {
334
334
  return e.replace(/undefined/g, t);
335
335
  }
336
336
  promiseFieldParser(e, t, s) {
337
- a.isPromise(e) ? e.then((r) => {
338
- s && a.isObject(r) ? this.objectParser({
337
+ f.isPromise(e) ? e.then((r) => {
338
+ s && f.isObject(r) ? this.objectParser({
339
339
  data: r,
340
340
  updater: t
341
341
  }) : t(r);
342
- }) : (a.isString(e) && (e = this.replaceUndefinedInString(e, "")), s && a.isObject(e) ? this.objectParser({
342
+ }) : (f.isString(e) && (e = this.replaceUndefinedInString(e, "")), s && f.isObject(e) ? this.objectParser({
343
343
  data: e,
344
344
  updater: t
345
345
  }) : t(e));
346
346
  }
347
347
  // 对任意对象中单个字段的 parse: 做基本处理
348
348
  fieldParser(e, t, s = !0) {
349
- if (a.isFunction(e))
349
+ if (f.isFunction(e))
350
350
  if (e.name.startsWith("__proform_raw_"))
351
351
  t(e);
352
352
  else {
@@ -354,10 +354,10 @@ class te {
354
354
  this.promiseFieldParser(r, t, s);
355
355
  }
356
356
  else
357
- G(e) ? v(
357
+ K(e) ? v(
358
358
  () => e.value,
359
359
  () => {
360
- a.isUndefined(e.value) || (s && a.isObject(e.value) ? this.objectParser({
360
+ f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
361
361
  data: e.value,
362
362
  updater: t
363
363
  }) : t(e.value));
@@ -366,10 +366,10 @@ class te {
366
366
  immediate: !0,
367
367
  deep: !0
368
368
  }
369
- ) : K(e) ? v(
369
+ ) : W(e) ? v(
370
370
  () => e,
371
371
  () => {
372
- a.isUndefined(e) || (s && a.isObject(e) ? this.objectParser({
372
+ f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
373
373
  data: e,
374
374
  updater: t
375
375
  }) : t(e));
@@ -378,7 +378,7 @@ class te {
378
378
  immediate: !0,
379
379
  deep: !0
380
380
  }
381
- ) : s && a.isObject(e) ? this.objectParser({
381
+ ) : s && f.isObject(e) ? this.objectParser({
382
382
  data: e,
383
383
  updater: t
384
384
  }) : t(e);
@@ -386,90 +386,104 @@ class te {
386
386
  modelProcessor(e) {
387
387
  e.map(
388
388
  (t) => this.createModel(t, this.processedModel.value)
389
- ), a.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = y(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
389
+ ), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = y(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
390
390
  }
391
391
  createModel(e, t) {
392
- a.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
392
+ f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
393
393
  this.createModel(s, t[e.field][0]);
394
- })), a.isGroupSchema(e) && e.children.forEach((s) => {
394
+ })), f.isGroupSchema(e) && e.children.forEach((s) => {
395
395
  this.createModel(s, t);
396
- }), a.isItemSchema(e) && (t[e.field] = e.defaultValue);
396
+ }), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
397
397
  }
398
398
  }
399
- function se(o) {
400
- return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !Y(o);
399
+ function re(o) {
400
+ return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !Z(o);
401
401
  }
402
- class re {
402
+ class ie {
403
403
  constructor(e) {
404
- l(this, "schemas", w([]));
405
- l(this, "model", w({}));
404
+ l(this, "schemas", C([]));
405
+ l(this, "model", C({}));
406
406
  l(this, "processorBySchemaType", {
407
407
  item: this.runtimeItemProcessor.bind(this),
408
408
  group: this.runtimeGroupProcessor.bind(this),
409
409
  list: this.runtimeListProcessor.bind(this)
410
410
  });
411
- l(this, "formRef", w(null));
411
+ l(this, "formRef", C(null));
412
412
  l(this, "hydrateEffect", new A());
413
- l(this, "customizedOptions", Q({}));
413
+ l(this, "customizedOptions", X({}));
414
+ l(this, "gridProps", {});
414
415
  l(this, "globalNativeFormOverride", {
415
416
  props: {},
416
417
  slots: {}
417
418
  });
418
- this.setup = e, this.processor = new te(this);
419
+ this.setup = e, this.processor = new se(this);
419
420
  const t = this.setup(this);
420
421
  this.processor.parseSchemas(t.schemas);
421
422
  }
422
423
  getRuntimeMeta() {
423
424
  return {
424
- model: j(y(this.model.value))
425
+ model: I(y(this.model.value))
425
426
  };
426
427
  }
427
428
  runtimeItemProcessor(e, t, s = this.model.value, r) {
428
- var h, z, F, M, x, U, D, N, k, R, _, L, B;
429
- u(this.globalNativeFormOverride.props, (z = (h = e.native) == null ? void 0 : h.props) == null ? void 0 : z.Form), u(this.globalNativeFormOverride.slots, (M = (F = e.native) == null ? void 0 : F.slots) == null ? void 0 : M.Form);
430
- const i = u(y((U = (x = this.customizedOptions.native) == null ? void 0 : x.props) == null ? void 0 : U.FormItem) ?? {}, (N = (D = e.native) == null ? void 0 : D.props) == null ? void 0 : N.FormItem), n = u(y((R = (k = this.customizedOptions.native) == null ? void 0 : k.slots) == null ? void 0 : R.FormItem) ?? {}, (L = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : L.FormItem), c = r ? `${r.field}.${t}.${e.field}` : e.field, f = j(e.component);
431
- if (!f)
429
+ var z, F, M, x, U, D, N, k, R, _, L, B, T;
430
+ p(this.globalNativeFormOverride.props, (F = (z = e.native) == null ? void 0 : z.props) == null ? void 0 : F.Form), p(this.globalNativeFormOverride.slots, (x = (M = e.native) == null ? void 0 : M.slots) == null ? void 0 : x.Form);
431
+ const i = p(y((D = (U = this.customizedOptions.native) == null ? void 0 : U.props) == null ? void 0 : D.FormItem) ?? {}, (k = (N = e.native) == null ? void 0 : N.props) == null ? void 0 : k.FormItem), n = p(y((_ = (R = this.customizedOptions.native) == null ? void 0 : R.slots) == null ? void 0 : _.FormItem) ?? {}, (B = (L = e.native) == null ? void 0 : L.slots) == null ? void 0 : B.FormItem), u = {
432
+ display: "grid",
433
+ gridColumn: "1 / -1",
434
+ ...e.gridProps
435
+ }, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = I(e.component);
436
+ if (!d)
432
437
  return;
433
- const p = f.name, I = e.componentProps ?? {}, V = S.placeholderPresetByComponentName;
434
- let P = e.placeholder;
435
- if (P || (P = `${// @ts-expect-error
436
- V[p] ?? "请输入"}${e.label}`), e.required)
438
+ const O = d.name, V = e.componentProps ?? {}, E = S.placeholderPresetByComponentName;
439
+ let g = e.placeholder;
440
+ if (g || (g = `${// @ts-expect-error
441
+ E[O] ?? "请输入"}${e.label}`), e.required)
437
442
  if (!e.rules)
438
- e.rules = [], (B = e.rules) == null || B.push({
443
+ e.rules = [], (T = e.rules) == null || T.push({
439
444
  required: !0,
440
445
  message: `${e.label}是必填项`
441
446
  });
442
447
  else {
443
- const E = e.rules.findIndex((W) => !!W.required);
444
- e.rules[E].message = `${e.label}是必填项`;
448
+ const j = e.rules.findIndex((H) => !!H.required);
449
+ e.rules[j].message = `${e.label}是必填项`;
445
450
  }
446
- let d = e.show;
447
- return d === void 0 && (d = !0), d || delete s[e.field], m(b.runtimeDoms.Item, null, {
451
+ let m = e.show;
452
+ return m === void 0 && (m = !0), m || delete s[e.field], c("div", {
453
+ style: u
454
+ }, [c(b.runtimeDoms.Item, null, {
448
455
  default() {
449
- return $(m(b.runtimeDoms.FormItem, C(i, {
456
+ return q(c(b.runtimeDoms.FormItem, w(i, {
450
457
  label: `${e.label}:`,
451
458
  rules: e.rules,
452
- field: c
459
+ field: a
453
460
  }), {
454
461
  default() {
455
- return m(f, C({
462
+ return c(d, w({
456
463
  modelValue: s[e.field],
457
- "onUpdate:modelValue": (E) => s[e.field] = E,
458
- placeholder: P
459
- }, I), null);
464
+ "onUpdate:modelValue": (j) => s[e.field] = j,
465
+ placeholder: g
466
+ }, V), null);
460
467
  },
461
468
  ...n
462
- }), [[q, d]]);
469
+ }), [[G, m]]);
463
470
  }
464
- });
471
+ })]);
465
472
  }
466
473
  runtimeGroupProcessor(e) {
467
474
  let t;
468
- return m(b.runtimeDoms.Group, {
475
+ const s = {
476
+ display: "grid",
477
+ gridColumn: "1 / -1",
478
+ ...e.gridProps
479
+ };
480
+ return c("div", {
481
+ style: s
482
+ }, [c(b.runtimeDoms.Group, {
469
483
  schema: e
470
- }, se(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
484
+ }, re(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
471
485
  default: () => [t]
472
- });
486
+ })]);
473
487
  }
474
488
  addListItem(e) {
475
489
  var t, s;
@@ -484,57 +498,70 @@ class re {
484
498
  this.model.value[e.field].splice(t, 1), this.formRef.value.clearValidate();
485
499
  }
486
500
  runtimeListProcessor(e) {
487
- const t = this;
488
- return t.model.value[e.field] || (t.model.value[e.field] = [{}]), m(b.runtimeDoms.List, {
501
+ const t = {
502
+ display: "grid",
503
+ gridColumn: "1 / -1",
504
+ ...e.gridProps
505
+ }, s = this;
506
+ return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
507
+ style: t
508
+ }, [c(b.runtimeDoms.List, {
489
509
  schema: e
490
510
  }, {
491
511
  default() {
492
- return t.model.value[e.field].map((s, r) => m(b.runtimeDoms.ListItem, null, {
512
+ return s.model.value[e.field].map((r, i) => c(b.runtimeDoms.ListItem, null, {
493
513
  default() {
494
- return e.children.map((i) => t.runtimeItemProcessor(i, r, s, e));
514
+ return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
495
515
  },
496
516
  delete({
497
- container: i
517
+ container: n
498
518
  } = {}) {
499
- var c;
500
- let n = i ?? m("button", null, null);
501
- return $(m(n, {
502
- onClick: () => t.deleteListItem(e, r)
503
- }, null), [[q, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
519
+ var a;
520
+ let u = n ?? c("button", null, null);
521
+ return q(c(u, {
522
+ onClick: () => s.deleteListItem(e, i)
523
+ }, null), [[G, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
504
524
  }
505
525
  }));
506
526
  },
507
527
  add({
508
- container: s
528
+ container: r
509
529
  } = {}) {
510
- let r = s ?? m("button", null, [X("添加")]);
511
- return m(r, {
512
- onClick: () => t.addListItem(e)
530
+ let i = r ?? c("button", null, [Y("添加")]);
531
+ return c(i, {
532
+ onClick: () => s.addListItem(e)
513
533
  }, null);
514
534
  }
515
- });
535
+ })]);
516
536
  }
517
537
  runtimeProcessor(e) {
518
538
  return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
519
539
  }
520
540
  exec() {
521
- var r, i, n, c;
522
- const e = this, t = u(y((i = (r = this.customizedOptions.native) == null ? void 0 : r.props) == null ? void 0 : i.Form) ?? {}, this.globalNativeFormOverride.props), s = u(y((c = (n = this.customizedOptions.native) == null ? void 0 : n.slots) == null ? void 0 : c.Form) ?? {}, this.globalNativeFormOverride.slots);
523
- return m(b.runtimeDoms.Form, C(t, {
541
+ var i, n, u, a;
542
+ const e = {
543
+ display: "grid",
544
+ gridColumn: "1 / -1",
545
+ gridAutoColumns: "1fr",
546
+ ...this.gridProps
547
+ }, t = this, s = p(y((n = (i = this.customizedOptions.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = p(y((a = (u = this.customizedOptions.native) == null ? void 0 : u.slots) == null ? void 0 : a.Form) ?? {}, this.globalNativeFormOverride.slots);
548
+ return c(b.runtimeDoms.Form, w(s, {
524
549
  ref: this.formRef,
525
550
  model: this.model.value
526
551
  }), {
527
552
  default() {
528
- return e.runtimeProcessor(e.schemas.value);
553
+ return c("div", {
554
+ style: e
555
+ }, [t.runtimeProcessor(t.schemas.value)]);
529
556
  },
530
- ...s
557
+ ...r
531
558
  });
532
559
  }
533
560
  }
534
561
  class b {
535
562
  }
536
563
  l(b, "runtimeDoms");
537
- const g = class g {
564
+ const P = class P {
538
565
  static getPlaceholderPrefixPresetByComponentName() {
539
566
  const e = {
540
567
  请选择: ["Select", "Tree", "TreeSelect"],
@@ -547,7 +574,7 @@ const g = class g {
547
574
  return t;
548
575
  }
549
576
  };
550
- l(g, "schemaPreset", {
577
+ l(P, "schemaPreset", {
551
578
  type: {
552
579
  defaultValue: "item"
553
580
  },
@@ -581,15 +608,16 @@ l(g, "schemaPreset", {
581
608
  children: {
582
609
  defaultValue: []
583
610
  },
584
- native: void 0
585
- }), l(g, "componentPropsPreset", {
611
+ native: void 0,
612
+ gridProps: void 0
613
+ }), l(P, "componentPropsPreset", {
586
614
  options: {
587
615
  defaultValue: []
588
616
  }
589
617
  }), // 基于基本功能提出基本预设
590
- l(g, "placeholderPresetByComponentName", g.getPlaceholderPrefixPresetByComponentName());
591
- let S = g;
592
- const ne = /* @__PURE__ */ Z({
618
+ l(P, "placeholderPresetByComponentName", P.getPlaceholderPrefixPresetByComponentName());
619
+ let S = P;
620
+ const le = /* @__PURE__ */ ee({
593
621
  props: {
594
622
  setup: {
595
623
  type: Function,
@@ -597,12 +625,12 @@ const ne = /* @__PURE__ */ Z({
597
625
  }
598
626
  },
599
627
  setup(o) {
600
- const e = new re(o.setup);
628
+ const e = new ie(o.setup);
601
629
  return () => e.exec();
602
630
  }
603
631
  });
604
- function le(o) {
605
- const e = new ee(o);
632
+ function ae(o) {
633
+ const e = new te(o);
606
634
  return [
607
635
  e.setup.bind(e),
608
636
  {
@@ -612,22 +640,22 @@ function le(o) {
612
640
  }
613
641
  ];
614
642
  }
615
- function ce(o) {
643
+ function fe(o) {
616
644
  return {
617
645
  install() {
618
646
  b.runtimeDoms = o;
619
647
  }
620
648
  };
621
649
  }
622
- function ae(o, e) {
650
+ function ue(o, e) {
623
651
  return e === "raw" && Object.defineProperty(o, "name", {
624
652
  value: `__proform_raw_${o.name}`,
625
653
  writable: !0
626
654
  }), o;
627
655
  }
628
656
  export {
629
- ne as ProForm,
630
- le as useForm,
631
- ce as useFormRenderer,
632
- ae as useModifiers
657
+ le as ProForm,
658
+ ae as useForm,
659
+ fe as useFormRenderer,
660
+ ue as useModifiers
633
661
  };
@@ -11,6 +11,7 @@ export default class RuntimeCore {
11
11
  formRef: Ref<AnyObject>;
12
12
  hydrateEffect: Effect;
13
13
  customizedOptions: CustomizationOptions;
14
+ gridProps: {};
14
15
  globalNativeFormOverride: {
15
16
  props: {};
16
17
  slots: {};
@@ -23,6 +23,35 @@ export type FieldRule<T = any> = {
23
23
  hasKeys?: string[];
24
24
  validator?: (value: T | undefined, callback: (error?: string) => void) => void;
25
25
  };
26
+ interface GridStyle {
27
+ gridTemplateColumns?: string;
28
+ gridTemplateRows?: string;
29
+ gridTemplateAreas?: string;
30
+ gridTemplate?: string;
31
+ gridColumnGap?: string;
32
+ gridRowGap?: string;
33
+ gridGap?: string;
34
+ justifyItems?: string;
35
+ alignItems?: string;
36
+ placeItems?: string;
37
+ justifyContent?: string;
38
+ alignContent?: string;
39
+ placeContent?: string;
40
+ gridAutoColumns?: string;
41
+ gridAutoRows?: string;
42
+ gridAutoFlow?: string;
43
+ gridColumnStart?: string;
44
+ gridColumnEnd?: string;
45
+ gridRowStart?: string;
46
+ gridRowEnd?: string;
47
+ gridColumn?: string;
48
+ gridRow?: string;
49
+ gridArea?: string;
50
+ justifySelf?: string;
51
+ alignSelf?: string;
52
+ placeSelf?: string;
53
+ [key: string]: any;
54
+ }
26
55
  export interface ItemSchema {
27
56
  type?: "item";
28
57
  rules?: FieldRule[];
@@ -30,6 +59,7 @@ export interface ItemSchema {
30
59
  required?: boolean;
31
60
  placeholder?: string;
32
61
  native?: NativeCustomizationOptions;
62
+ gridProps?: GridStyle;
33
63
  label: string;
34
64
  field: string;
35
65
  component: DomType;
@@ -40,12 +70,14 @@ export interface GroupSchema {
40
70
  type: "group";
41
71
  label: string;
42
72
  children: ProxyedSchema[];
73
+ gridProps?: GridStyle;
43
74
  }
44
75
  export interface ListSchema {
45
76
  type: "list";
46
77
  field: string;
47
78
  label: string;
48
79
  children: ProxyedSchema[];
80
+ gridProps?: GridStyle;
49
81
  }
50
82
  export type Schema = ItemSchema | GroupSchema | ListSchema;
51
83
  export interface runtimeMeta {
@@ -57,6 +89,7 @@ export type ProFormProxy<T> = {
57
89
  };
58
90
  export type ProxyedSchema = ProFormProxy<ItemSchema | GroupSchema | ListSchema>;
59
91
  export interface FormCustomization {
92
+ gridProps?: GridStyle;
60
93
  schemas: ProxyedSchema[];
61
94
  }
62
95
  export type NativeCustomizationOptions = {
@@ -72,3 +105,4 @@ export type NativeCustomizationOptions = {
72
105
  export type CustomizationOptions = {
73
106
  native?: NativeCustomizationOptions;
74
107
  };
108
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbor-design/proform",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",