@harbor-design/proform 1.1.8 → 1.1.9

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 G=Object.defineProperty;var K=(n,e,t)=>e in n?G(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>(K(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class c{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function b(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const o=new Map;for(let[l,u]of s)o.set(t(l),t(u));return o}if(s instanceof Set){const o=new Set;for(let l of s)o.add(t(l));return o}if(e.has(s))return e.get(s);if(Array.isArray(s)){const o=[];e.set(s,o);for(let l=0;l<s.length;l++)o[l]=t(s[l]);return o}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let o in s)s.hasOwnProperty(o)&&(r[o]=t(s[o]));return r}return t(n)}function O(n,e){return n.replace(/undefined/g,e)}class W{constructor(e){a(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,Object.assign(this.runtimeCore.native,this.formCustomization.native),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps),Object.assign(this.runtimeCore.runtimeSetters,this.formCustomization.runtimeSetters),this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{i.isRef(e)?i.watch(()=>e.value,()=>{p(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):i.isReactive(e)?i.watch(()=>e,()=>{p(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):p(this.runtimeCore.model.value,e)},{lazy:!0})}}class N{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 H{constructor(e){a(this,"runtimeCore");a(this,"processedSchemas");a(this,"processedModel");a(this,"getRuntimeMeta");a(this,"stableSchemas",[]);a(this,"stableModel",{});a(this,"schemaPreset",E.schemaPreset);a(this,"componentPropsPreset",E.componentPropsPreset);a(this,"stableUpdaterProcessProgress");a(this,"stableUpdaterTimes",0);a(this,"schemaEffect",new N);a(this,"defaultValueEffect",new N);a(this,"defaultValueInprogressMap",new Map);a(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){c.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(b(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!c.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!c.isProcessInprogress(t)&&c.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,o=Array.from({length:Object.keys(e).filter(u=>u!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(u){const f=u.index,d=u.key,I=u.keyIndex;if(c.isUndefined(u.stable))return;const w=r.parseStable(u.stable),j=s==null?void 0:s.index,P=s==null?void 0:s.key;let y=w;if(c.isProcessInprogress(y)||(o[I]=!0),s){let h=r.processedSchemas.value[j][P][f][d];h&&c.isObject(h)&&d!=="component"&&(y=p(h,y)),r.processedSchemas.value[j][P][f][d]=y,r.stableUpdater(o)}else{let h=r.processedSchemas.value[f][d];h&&c.isObject(h)&&d!=="component"&&(y=p(h,y)),r.processedSchemas.value[f][d]=y,r.stableUpdater(o)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,o)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:o});else{const l=u=>{e.updater({...e,key:r,keyIndex:o,stable:u})};c.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const u=t[r](this.getRuntimeMeta());this.promiseFieldParser(u,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const u=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],f=>{if(!f)return l(f);this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)}):this.fieldParser(t[r],f=>{this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)})})}):r==="component"||r==="slots"||r==="runtimeSetters"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){c.isPromise(e)?e.then(r=>{c.isString(r)&&(r=O(r,"")),s&&c.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(c.isString(e)&&(e=O(e,"")),s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(c.isFunction(e))if(e.name.startsWith("__proform_raw_"))t((...r)=>{e({rawArgs:r,...this.getRuntimeMeta()})});else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{c.isUndefined(e.value)||(s&&c.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{c.isUndefined(e)||(s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),c.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=b(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){c.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),c.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),c.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function J(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class Q{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 N);a(this,"native",i.reactive({}));a(this,"gridProps",{});a(this,"runtimeSetters",{});a(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new H(this);const t=this.setup(this);if(i.isRef(t.schemas)){const s=i.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas.value),i.nextTick(()=>{s()})},{deep:!0})}else if(i.isReactive(t.schemas)){const s=i.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas),i.nextTick(()=>{s()})},{deep:!0})}else this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(b(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var A,R,x,M,F,U,D,k,_,L,z,T,q,$,B;p(this.globalNativeFormOverride.props,(R=(A=e.native)==null?void 0:A.props)==null?void 0:R.Form),p(this.globalNativeFormOverride.slots,(M=(x=e.native)==null?void 0:x.slots)==null?void 0:M.Form);const o=p(b((U=(F=this.native)==null?void 0:F.props)==null?void 0:U.FormItem)??{},(k=(D=e.native)==null?void 0:D.props)==null?void 0:k.FormItem),l=p(b((L=(_=this.native)==null?void 0:_.slots)==null?void 0:L.FormItem)??{},(T=(z=e.native)==null?void 0:z.slots)==null?void 0:T.FormItem),u={display:"grid",gridColumn:"1 / -1",...e.gridProps},f=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const I=d.name,w=e.componentProps??{},j=E.placeholderPresetByComponentName;let P=e.placeholder;const y=e.required;let h=e.show;h===void 0&&(h=!0),h||delete s[e.field];let v=e.label;const S=(r==null?void 0:r.runtimeSetters)??this.runtimeSetters;if(!c.isUndefined(t)&&!c.isObjectEmpty(S)&&(v=O((q=S==null?void 0:S.listItemLabelSetter)==null?void 0:q.call(S,e.label,t+1),""),P=`${j[I]??"请输入"}${v}`),P||(P=`${j[I]??"请输入"}${v}`),y)if(!e.rules)e.rules=[],($=e.rules)==null||$.push({required:!0,message:`${v}是必填项`});else{const m=e.rules.findIndex(C=>!c.isUndefined(C.required));m!==-1&&(e.rules[m].required=!0,e.rules[m].message=`${v}是必填项`)}else if(e.rules){const m=(B=e.rules)==null?void 0:B.findIndex(C=>!!C.required);m!==-1&&(e.rules[m].required=!1)}return i.createVNode("div",{style:u},[i.createVNode(g.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(g.runtimeDoms.FormItem,i.mergeProps(o,{label:`${v}:`,rules:e.rules,field:f}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":m=>s[e.field]=m,placeholder:P},w),null)},...l}),[[i.vShow,h]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.gridProps};return i.createVNode("div",{style:s},[i.createVNode(g.runtimeDoms.Group,{schema:e},J(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(b(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.gridProps},s=this;return s.model.value[e.field]||(s.model.value[e.field]=[{}]),i.createVNode("div",{style:t},[i.createVNode(g.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(g.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var f;let u=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(u,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((f=s.model.value[e.field])==null?void 0:f.length)>1]])}}))},add({container:r}={}){let o=r??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.createVNode(o,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var o,l,u,f;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.gridProps},t=this,s=p(b((l=(o=this.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(b((f=(u=this.native)==null?void 0:u.slots)==null?void 0:f.Form)??{},this.globalNativeFormOverride.slots);return i.createVNode(g.runtimeDoms.Form,i.mergeProps(s,{ref:this.formRef,model:this.model.value}),{default(){return i.createVNode("div",{style:e},[t.runtimeProcessor(t.schemas.value)])},...r})}}class g{}a(g,"runtimeDoms");const V=class V{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};a(V,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0,gridProps:void 0}),a(V,"componentPropsPreset",{options:{defaultValue:[]}}),a(V,"placeholderPresetByComponentName",V.getPlaceholderPrefixPresetByComponentName());let E=V;const X=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new Q(n.setup);return()=>e.exec()}});function Y(n){const e=new W(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function Z(n){return{install(){g.runtimeDoms=n}}}function ee(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=X;exports.useForm=Y;exports.useFormRenderer=Z;exports.useModifiers=ee;
1
+ "use strict";var G=Object.defineProperty;var K=(n,e,t)=>e in n?G(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>(K(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class c{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function g(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const o=new Map;for(let[l,u]of s)o.set(t(l),t(u));return o}if(s instanceof Set){const o=new Set;for(let l of s)o.add(t(l));return o}if(e.has(s))return e.get(s);if(Array.isArray(s)){const o=[];e.set(s,o);for(let l=0;l<s.length;l++)o[l]=t(s[l]);return o}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let o in s)s.hasOwnProperty(o)&&(r[o]=t(s[o]));return r}return t(n)}function O(n,e){return n.replace(/undefined/g,e)}class W{constructor(e){a(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,Object.assign(this.runtimeCore.native,this.formCustomization.native),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps),Object.assign(this.runtimeCore.runtimeSetters,this.formCustomization.runtimeSetters),this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{i.isRef(e)?i.watch(()=>e.value,()=>{p(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):i.isReactive(e)?i.watch(()=>e,()=>{p(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):p(this.runtimeCore.model.value,e)},{lazy:!0})}}class N{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 H{constructor(e){a(this,"runtimeCore");a(this,"processedSchemas");a(this,"processedModel");a(this,"getRuntimeMeta");a(this,"stableSchemas",[]);a(this,"stableModel",{});a(this,"schemaPreset",I.schemaPreset);a(this,"componentPropsPreset",I.componentPropsPreset);a(this,"stableUpdaterProcessProgress");a(this,"stableUpdaterTimes",0);a(this,"schemaEffect",new N);a(this,"defaultValueEffect",new N);a(this,"defaultValueInprogressMap",new Map);a(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){c.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(g(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!c.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!c.isProcessInprogress(t)&&c.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,o=Array.from({length:Object.keys(e).filter(u=>u!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(u){const f=u.index,d=u.key,S=u.keyIndex;if(c.isUndefined(u.stable))return;const C=r.parseStable(u.stable),v=s==null?void 0:s.index,b=s==null?void 0:s.key;let y=C;if(c.isProcessInprogress(y)||(o[S]=!0),s){let m=r.processedSchemas.value[v][b][f][d];m&&c.isObject(m)&&d!=="component"&&(y=p(m,y)),r.processedSchemas.value[v][b][f][d]=y,r.stableUpdater(o)}else{let m=r.processedSchemas.value[f][d];m&&c.isObject(m)&&d!=="component"&&(y=p(m,y)),r.processedSchemas.value[f][d]=y,r.stableUpdater(o)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,o)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:o});else{const l=u=>{e.updater({...e,key:r,keyIndex:o,stable:u})};c.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const u=t[r](this.getRuntimeMeta());this.promiseFieldParser(u,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const u=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],f=>{if(!f)return l(f);this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)}):this.fieldParser(t[r],f=>{this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)})})}):r==="component"||r==="slots"||r==="runtimeSetters"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){c.isPromise(e)?e.then(r=>{c.isString(r)&&(r=O(r,"")),s&&c.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(c.isString(e)&&(e=O(e,"")),s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(c.isFunction(e))if(e.name.startsWith("__proform_raw_"))t((...r)=>{e({rawArgs:r,...this.getRuntimeMeta()})});else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{c.isUndefined(e.value)||(s&&c.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{c.isUndefined(e)||(s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),c.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=g(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){c.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),c.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),c.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function J(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class Q{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 N);a(this,"native",i.reactive({}));a(this,"gridProps",{});a(this,"runtimeSetters",{});a(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new H(this);const t=this.setup(this);if(i.isRef(t.schemas)){const s=i.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas.value),i.nextTick(()=>{s()})},{deep:!0})}else if(i.isReactive(t.schemas)){const s=i.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas),i.nextTick(()=>{s()})},{deep:!0})}else this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(g(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var A,R,M,F,U,x,k,D,L,_,z,$,q,T,B;p(this.globalNativeFormOverride.props,(R=(A=e.native)==null?void 0:A.props)==null?void 0:R.Form),p(this.globalNativeFormOverride.slots,(F=(M=e.native)==null?void 0:M.slots)==null?void 0:F.Form);const o=p(g((x=(U=this.native)==null?void 0:U.props)==null?void 0:x.FormItem)??{},(D=(k=e.native)==null?void 0:k.props)==null?void 0:D.FormItem),l=p(g((_=(L=this.native)==null?void 0:L.slots)==null?void 0:_.FormItem)??{},($=(z=e.native)==null?void 0:z.slots)==null?void 0:$.FormItem),u={display:"grid",gridColumn:"1 / -1",...e.gridProps},f=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const S=d.name,C=e.componentProps??{},v=I.placeholderPresetByComponentName;let b=e.placeholder;const y=e.required;let m=e.show;m===void 0&&(m=!0),m||delete s[e.field];let V=e.label;const w=(r==null?void 0:r.runtimeSetters)??this.runtimeSetters;if(!c.isUndefined(t)&&!c.isObjectEmpty(w)&&(V=O((q=w==null?void 0:w.listItemLabelSetter)==null?void 0:q.call(w,e.label,t+1),"")),!b){let h="请输入";c.isUndefined(S)?b=`${h}${V}`:v[S.toLowerCase()]?(h=v[S.toLowerCase()],b=`${h}${V}`):(Object.keys(v).forEach(j=>{S.toLowerCase().includes(j.toLowerCase())&&(h=v[j])}),b=`${h}${V}`)}if(y)if(!e.rules)e.rules=[],(T=e.rules)==null||T.push({required:!0,message:`${V}是必填项`});else{const h=e.rules.findIndex(j=>!c.isUndefined(j.required));h!==-1&&(e.rules[h].required=!0,e.rules[h].message=`${V}是必填项`)}else if(e.rules){const h=(B=e.rules)==null?void 0:B.findIndex(j=>!!j.required);h!==-1&&(e.rules[h].required=!1)}return i.createVNode("div",{style:u},[i.createVNode(P.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(P.runtimeDoms.FormItem,i.mergeProps(o,{label:`${V}:`,rules:e.rules,field:f}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":h=>s[e.field]=h,placeholder:b},C),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(P.runtimeDoms.Group,{schema:e},J(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(g(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(P.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(P.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var f;let u=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(u,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((f=s.model.value[e.field])==null?void 0:f.length)>1]])}}))},add({container:r}={}){let o=r??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.createVNode(o,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var o,l,u,f;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.gridProps},t=this,s=p(g((l=(o=this.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(g((f=(u=this.native)==null?void 0:u.slots)==null?void 0:f.Form)??{},this.globalNativeFormOverride.slots);return i.createVNode(P.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 P{}a(P,"runtimeDoms");const E=class E{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["select","tree","treeselect"],请输入:["input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};a(E,"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(E,"componentPropsPreset",{options:{defaultValue:[]}}),a(E,"placeholderPresetByComponentName",E.getPlaceholderPrefixPresetByComponentName());let I=E;const X=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new Q(n.setup);return()=>e.exec()}});function Y(n){const e=new W(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function Z(n){return{install(){P.runtimeDoms=n}}}function ee(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=X;exports.useForm=Y;exports.useFormRenderer=Z;exports.useModifiers=ee;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var ee = Object.defineProperty;
2
2
  var te = (o, e, t) => e in o ? ee(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
3
  var l = (o, e, t) => (te(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { toRaw as O, isRef as N, watch as v, isReactive as R, nextTick as w, ref as M, reactive as se, createVNode as c, withDirectives as Y, mergeProps as U, vShow as Z, createTextVNode as re, isVNode as ie, defineComponent as oe } from "vue";
4
+ import { toRaw as O, isRef as D, watch as j, isReactive as N, nextTick as A, ref as M, reactive as se, createVNode as c, withDirectives as Y, mergeProps as F, vShow as Z, createTextVNode as re, isVNode as ie, defineComponent as oe } from "vue";
5
5
  class f {
6
6
  static typeChecker(e) {
7
7
  return {}.toString.call(e);
@@ -63,18 +63,18 @@ class f {
63
63
  return !1;
64
64
  }
65
65
  }
66
- function p(o, ...e) {
66
+ function m(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] = p(Array.isArray(s) ? [] : {}, s) : o[r] = s;
70
+ typeof s == "object" && s !== null ? o[r] = m(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] = p(o[s] || {}, t[s]) : o[s] = t[s]);
74
+ t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? o[s] = m(o[s] || {}, t[s]) : o[s] = t[s]);
75
75
  }), o;
76
76
  }
77
- function b(o) {
77
+ function g(o) {
78
78
  const e = /* @__PURE__ */ new WeakMap();
79
79
  function t(s) {
80
80
  if (s === null || typeof s != "object")
@@ -85,8 +85,8 @@ function b(o) {
85
85
  return new RegExp(s);
86
86
  if (s instanceof Map) {
87
87
  const i = /* @__PURE__ */ new Map();
88
- for (let [n, a] of s)
89
- i.set(t(n), t(a));
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 b(o) {
112
112
  }
113
113
  return t(o);
114
114
  }
115
- function F(o, e) {
115
+ function L(o, e) {
116
116
  return o.replace(/undefined/g, e);
117
117
  }
118
118
  class ne {
@@ -149,25 +149,25 @@ class ne {
149
149
  });
150
150
  this.runtimeCore.hydrateEffect.trackEffect(
151
151
  () => {
152
- N(e) ? v(
152
+ D(e) ? j(
153
153
  () => e.value,
154
154
  () => {
155
- p(this.runtimeCore.model.value, e.value);
155
+ m(this.runtimeCore.model.value, e.value);
156
156
  },
157
157
  {
158
158
  deep: !0,
159
159
  immediate: !0
160
160
  }
161
- ) : R(e) ? v(
161
+ ) : N(e) ? j(
162
162
  () => e,
163
163
  () => {
164
- p(this.runtimeCore.model.value, e);
164
+ m(this.runtimeCore.model.value, e);
165
165
  },
166
166
  {
167
167
  deep: !0,
168
168
  immediate: !0
169
169
  }
170
- ) : p(this.runtimeCore.model.value, e);
170
+ ) : m(this.runtimeCore.model.value, e);
171
171
  },
172
172
  {
173
173
  lazy: !0
@@ -175,7 +175,7 @@ class ne {
175
175
  );
176
176
  }
177
177
  }
178
- class D {
178
+ class x {
179
179
  constructor() {
180
180
  l(this, "effects", /* @__PURE__ */ new Set());
181
181
  }
@@ -199,15 +199,15 @@ class le {
199
199
  l(this, "getRuntimeMeta");
200
200
  l(this, "stableSchemas", []);
201
201
  l(this, "stableModel", {});
202
- l(this, "schemaPreset", V.schemaPreset);
203
- l(this, "componentPropsPreset", V.componentPropsPreset);
202
+ l(this, "schemaPreset", w.schemaPreset);
203
+ l(this, "componentPropsPreset", w.componentPropsPreset);
204
204
  l(this, "stableUpdaterProcessProgress");
205
205
  l(this, "stableUpdaterTimes", 0);
206
- l(this, "schemaEffect", new D());
207
- l(this, "defaultValueEffect", new D());
206
+ l(this, "schemaEffect", new x());
207
+ l(this, "defaultValueEffect", new x());
208
208
  l(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
209
209
  l(this, "baseDefaultValueFunctionsLength");
210
- this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), v(
210
+ this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), j(
211
211
  () => this.processedModel.value,
212
212
  () => {
213
213
  this.schemaEffect.triggerEffects();
@@ -244,7 +244,7 @@ class le {
244
244
  // 派生过程,用于外部应用
245
245
  parseSchemas(e, t) {
246
246
  f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
247
- b(e)
247
+ g(e)
248
248
  ), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
249
249
  }
250
250
  parseStable(e) {
@@ -267,21 +267,21 @@ class le {
267
267
  // 核心单 schema 处理过程,接收一个对象键值对的数据结构
268
268
  parseItem(e, t, s) {
269
269
  const r = this, i = Array.from({
270
- length: Object.keys(e).filter((a) => a !== "children").length
270
+ length: Object.keys(e).filter((u) => u !== "children").length
271
271
  }).fill(!1);
272
272
  this.objectParser({ data: e, index: t, updater: n });
273
- function n(a) {
274
- const u = a.index, d = a.key, C = a.keyIndex;
275
- if (f.isUndefined(a.stable))
273
+ function n(u) {
274
+ const a = u.index, d = u.key, E = u.keyIndex;
275
+ if (f.isUndefined(u.stable))
276
276
  return;
277
- const A = r.parseStable(a.stable), I = s == null ? void 0 : s.index, P = s == null ? void 0 : s.key;
278
- let y = A;
279
- if (f.isProcessInprogress(y) || (i[C] = !0), s) {
280
- let m = r.processedSchemas.value[I][P][u][d];
281
- m && f.isObject(m) && d !== "component" && (y = p(m, y)), r.processedSchemas.value[I][P][u][d] = y, r.stableUpdater(i);
277
+ const U = r.parseStable(u.stable), v = s == null ? void 0 : s.index, b = s == null ? void 0 : s.key;
278
+ let y = U;
279
+ if (f.isProcessInprogress(y) || (i[E] = !0), s) {
280
+ let h = r.processedSchemas.value[v][b][a][d];
281
+ h && f.isObject(h) && d !== "component" && (y = m(h, y)), r.processedSchemas.value[v][b][a][d] = y, r.stableUpdater(i);
282
282
  } else {
283
- let m = r.processedSchemas.value[u][d];
284
- m && f.isObject(m) && d !== "component" && (y = p(m, y)), r.processedSchemas.value[u][d] = y, r.stableUpdater(i);
283
+ let h = r.processedSchemas.value[a][d];
284
+ h && f.isObject(h) && d !== "component" && (y = m(h, y)), r.processedSchemas.value[a][d] = y, r.stableUpdater(i);
285
285
  }
286
286
  }
287
287
  }
@@ -296,36 +296,36 @@ class le {
296
296
  keyIndex: i
297
297
  });
298
298
  else {
299
- const n = (a) => {
299
+ const n = (u) => {
300
300
  e.updater({
301
301
  ...e,
302
302
  key: r,
303
303
  keyIndex: i,
304
- stable: a
304
+ stable: u
305
305
  });
306
306
  };
307
307
  f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
308
308
  if (r === "component") {
309
- const a = t[r](this.getRuntimeMeta());
310
- this.promiseFieldParser(a, n, !1);
309
+ const u = t[r](this.getRuntimeMeta());
310
+ this.promiseFieldParser(u, n, !1);
311
311
  } else
312
312
  this.fieldParser(t[r], n);
313
313
  }) : this.defaultValueEffect.trackEffect(() => {
314
- const a = this.schemaEffect.trackEffect(() => {
315
- /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (u) => {
316
- if (!u)
317
- return n(u);
318
- this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
314
+ const u = this.schemaEffect.trackEffect(() => {
315
+ /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (a) => {
316
+ if (!a)
317
+ return n(a);
318
+ this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
319
319
  (d) => !d.includes("undefined")
320
- ) ? (n(u), this.defaultValueEffect.clearEffects(), w(() => {
321
- a();
322
- })) : n(u);
323
- }) : this.fieldParser(t[r], (u) => {
324
- this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
320
+ ) ? (n(a), this.defaultValueEffect.clearEffects(), A(() => {
321
+ u();
322
+ })) : n(a);
323
+ }) : this.fieldParser(t[r], (a) => {
324
+ this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
325
325
  (d) => !d.includes("undefined")
326
- ) ? (n(u), this.defaultValueEffect.clearEffects(), w(() => {
327
- a();
328
- })) : n(u);
326
+ ) ? (n(a), this.defaultValueEffect.clearEffects(), A(() => {
327
+ u();
328
+ })) : n(a);
329
329
  });
330
330
  });
331
331
  }) : r === "component" || r === "slots" || r === "runtimeSetters" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
@@ -334,11 +334,11 @@ class le {
334
334
  }
335
335
  promiseFieldParser(e, t, s) {
336
336
  f.isPromise(e) ? e.then((r) => {
337
- f.isString(r) && (r = F(r, "")), s && f.isObject(r) ? this.objectParser({
337
+ f.isString(r) && (r = L(r, "")), s && f.isObject(r) ? this.objectParser({
338
338
  data: r,
339
339
  updater: t
340
340
  }) : t(r);
341
- }) : (f.isString(e) && (e = F(e, "")), s && f.isObject(e) ? this.objectParser({
341
+ }) : (f.isString(e) && (e = L(e, "")), s && f.isObject(e) ? this.objectParser({
342
342
  data: e,
343
343
  updater: t
344
344
  }) : t(e));
@@ -358,7 +358,7 @@ class le {
358
358
  this.promiseFieldParser(r, t, s);
359
359
  }
360
360
  else
361
- N(e) ? v(
361
+ D(e) ? j(
362
362
  () => e.value,
363
363
  () => {
364
364
  f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
@@ -370,7 +370,7 @@ class le {
370
370
  immediate: !0,
371
371
  deep: !0
372
372
  }
373
- ) : R(e) ? v(
373
+ ) : N(e) ? j(
374
374
  () => e,
375
375
  () => {
376
376
  f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
@@ -390,7 +390,7 @@ class le {
390
390
  modelProcessor(e) {
391
391
  e.map(
392
392
  (t) => this.createModel(t, this.processedModel.value)
393
- ), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = b(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
393
+ ), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = g(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
394
394
  }
395
395
  createModel(e, t) {
396
396
  f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
@@ -403,7 +403,7 @@ class le {
403
403
  function fe(o) {
404
404
  return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !ie(o);
405
405
  }
406
- class ue {
406
+ class ae {
407
407
  constructor(e) {
408
408
  l(this, "schemas", M([]));
409
409
  l(this, "model", M({}));
@@ -413,7 +413,7 @@ class ue {
413
413
  list: this.runtimeListProcessor.bind(this)
414
414
  });
415
415
  l(this, "formRef", M(null));
416
- l(this, "hydrateEffect", new D());
416
+ l(this, "hydrateEffect", new x());
417
417
  l(this, "native", se({}));
418
418
  l(this, "gridProps", {});
419
419
  l(this, "runtimeSetters", {});
@@ -423,17 +423,17 @@ class ue {
423
423
  });
424
424
  this.setup = e, this.processor = new le(this);
425
425
  const t = this.setup(this);
426
- if (N(t.schemas)) {
427
- const s = v(() => t.schemas, () => {
428
- this.processor.parseSchemas(t.schemas.value), w(() => {
426
+ if (D(t.schemas)) {
427
+ const s = j(() => t.schemas, () => {
428
+ this.processor.parseSchemas(t.schemas.value), A(() => {
429
429
  s();
430
430
  });
431
431
  }, {
432
432
  deep: !0
433
433
  });
434
- } else if (R(t.schemas)) {
435
- const s = v(() => t.schemas, () => {
436
- this.processor.parseSchemas(t.schemas), w(() => {
434
+ } else if (N(t.schemas)) {
435
+ const s = j(() => t.schemas, () => {
436
+ this.processor.parseSchemas(t.schemas), A(() => {
437
437
  s();
438
438
  });
439
439
  }, {
@@ -444,60 +444,65 @@ class ue {
444
444
  }
445
445
  getRuntimeMeta() {
446
446
  return {
447
- model: O(b(this.model.value))
447
+ model: O(g(this.model.value))
448
448
  };
449
449
  }
450
450
  runtimeItemProcessor(e, t, s = this.model.value, r) {
451
- var _, k, L, z, q, $, B, T, G, K, W, H, J, Q, X;
452
- p(this.globalNativeFormOverride.props, (k = (_ = e.native) == null ? void 0 : _.props) == null ? void 0 : k.Form), p(this.globalNativeFormOverride.slots, (z = (L = e.native) == null ? void 0 : L.slots) == null ? void 0 : z.Form);
453
- const i = p(b(($ = (q = this.native) == null ? void 0 : q.props) == null ? void 0 : $.FormItem) ?? {}, (T = (B = e.native) == null ? void 0 : B.props) == null ? void 0 : T.FormItem), n = p(b((K = (G = this.native) == null ? void 0 : G.slots) == null ? void 0 : K.FormItem) ?? {}, (H = (W = e.native) == null ? void 0 : W.slots) == null ? void 0 : H.FormItem), a = {
451
+ var R, k, _, z, $, q, B, T, G, K, W, H, J, Q, X;
452
+ m(this.globalNativeFormOverride.props, (k = (R = e.native) == null ? void 0 : R.props) == null ? void 0 : k.Form), m(this.globalNativeFormOverride.slots, (z = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : z.Form);
453
+ const i = m(g((q = ($ = this.native) == null ? void 0 : $.props) == null ? void 0 : q.FormItem) ?? {}, (T = (B = e.native) == null ? void 0 : B.props) == null ? void 0 : T.FormItem), n = m(g((K = (G = this.native) == null ? void 0 : G.slots) == null ? void 0 : K.FormItem) ?? {}, (H = (W = e.native) == null ? void 0 : W.slots) == null ? void 0 : H.FormItem), u = {
454
454
  display: "grid",
455
455
  gridColumn: "1 / -1",
456
456
  ...e.gridProps
457
- }, u = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
457
+ }, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
458
458
  if (!d)
459
459
  return;
460
- const C = d.name, A = e.componentProps ?? {}, I = V.placeholderPresetByComponentName;
461
- let P = e.placeholder;
460
+ const E = d.name, U = e.componentProps ?? {}, v = w.placeholderPresetByComponentName;
461
+ let b = e.placeholder;
462
462
  const y = e.required;
463
- let m = e.show;
464
- m === void 0 && (m = !0), m || delete s[e.field];
463
+ let h = e.show;
464
+ h === void 0 && (h = !0), h || delete s[e.field];
465
465
  let S = e.label;
466
- const j = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
467
- if (!f.isUndefined(t) && !f.isObjectEmpty(j) && (S = F((J = j == null ? void 0 : j.listItemLabelSetter) == null ? void 0 : J.call(j, e.label, t + 1), ""), P = `${// @ts-expect-error
468
- I[C] ?? "请输入"}${S}`), P || (P = `${// @ts-expect-error
469
- I[C] ?? "请输入"}${S}`), y)
466
+ const I = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
467
+ if (!f.isUndefined(t) && !f.isObjectEmpty(I) && (S = L((J = I == null ? void 0 : I.listItemLabelSetter) == null ? void 0 : J.call(I, e.label, t + 1), "")), !b) {
468
+ let p = "请输入";
469
+ f.isUndefined(E) ? b = `${p}${S}` : /* @ts-expect-error */ v[E.toLowerCase()] ? (p = // @ts-expect-error
470
+ v[E.toLowerCase()], b = `${p}${S}`) : (Object.keys(v).forEach((C) => {
471
+ E.toLowerCase().includes(C.toLowerCase()) && (p = v[C]);
472
+ }), b = `${p}${S}`);
473
+ }
474
+ if (y)
470
475
  if (!e.rules)
471
476
  e.rules = [], (Q = e.rules) == null || Q.push({
472
477
  required: !0,
473
478
  message: `${S}是必填项`
474
479
  });
475
480
  else {
476
- const h = e.rules.findIndex((x) => !f.isUndefined(x.required));
477
- h !== -1 && (e.rules[h].required = !0, e.rules[h].message = `${S}是必填项`);
481
+ const p = e.rules.findIndex((C) => !f.isUndefined(C.required));
482
+ p !== -1 && (e.rules[p].required = !0, e.rules[p].message = `${S}是必填项`);
478
483
  }
479
484
  else if (e.rules) {
480
- const h = (X = e.rules) == null ? void 0 : X.findIndex((x) => !!x.required);
481
- h !== -1 && (e.rules[h].required = !1);
485
+ const p = (X = e.rules) == null ? void 0 : X.findIndex((C) => !!C.required);
486
+ p !== -1 && (e.rules[p].required = !1);
482
487
  }
483
488
  return c("div", {
484
- style: a
485
- }, [c(g.runtimeDoms.Item, null, {
489
+ style: u
490
+ }, [c(P.runtimeDoms.Item, null, {
486
491
  default() {
487
- return Y(c(g.runtimeDoms.FormItem, U(i, {
492
+ return Y(c(P.runtimeDoms.FormItem, F(i, {
488
493
  label: `${S}:`,
489
494
  rules: e.rules,
490
- field: u
495
+ field: a
491
496
  }), {
492
497
  default() {
493
- return c(d, U({
498
+ return c(d, F({
494
499
  modelValue: s[e.field],
495
- "onUpdate:modelValue": (h) => s[e.field] = h,
496
- placeholder: P
497
- }, A), null);
500
+ "onUpdate:modelValue": (p) => s[e.field] = p,
501
+ placeholder: b
502
+ }, U), null);
498
503
  },
499
504
  ...n
500
- }), [[Z, m]]);
505
+ }), [[Z, h]]);
501
506
  }
502
507
  })]);
503
508
  }
@@ -510,7 +515,7 @@ class ue {
510
515
  };
511
516
  return c("div", {
512
517
  style: s
513
- }, [c(g.runtimeDoms.Group, {
518
+ }, [c(P.runtimeDoms.Group, {
514
519
  schema: e
515
520
  }, fe(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
516
521
  default: () => [t]
@@ -523,7 +528,7 @@ class ue {
523
528
  code: "0001",
524
529
  message: "异步默认值数据正在处理中,请您耐心等待... "
525
530
  });
526
- (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(b(this.processor.stableModel[e.field][0])), this.formRef.value.clearValidate();
531
+ (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(g(this.processor.stableModel[e.field][0])), this.formRef.value.clearValidate();
527
532
  }
528
533
  deleteListItem(e, t) {
529
534
  this.model.value[e.field].splice(t, 1), this.formRef.value.clearValidate();
@@ -536,22 +541,22 @@ class ue {
536
541
  }, s = this;
537
542
  return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
538
543
  style: t
539
- }, [c(g.runtimeDoms.List, {
544
+ }, [c(P.runtimeDoms.List, {
540
545
  schema: e
541
546
  }, {
542
547
  default() {
543
- return s.model.value[e.field].map((r, i) => c(g.runtimeDoms.ListItem, null, {
548
+ return s.model.value[e.field].map((r, i) => c(P.runtimeDoms.ListItem, null, {
544
549
  default() {
545
550
  return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
546
551
  },
547
552
  delete({
548
553
  container: n
549
554
  } = {}) {
550
- var u;
551
- let a = n ?? c("button", null, null);
552
- return Y(c(a, {
555
+ var a;
556
+ let u = n ?? c("button", null, null);
557
+ return Y(c(u, {
553
558
  onClick: () => s.deleteListItem(e, i)
554
- }, null), [[Z, ((u = s.model.value[e.field]) == null ? void 0 : u.length) > 1]]);
559
+ }, null), [[Z, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
555
560
  }
556
561
  }));
557
562
  },
@@ -569,14 +574,14 @@ class ue {
569
574
  return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
570
575
  }
571
576
  exec() {
572
- var i, n, a, u;
577
+ var i, n, u, a;
573
578
  const e = {
574
579
  display: "grid",
575
580
  gridColumn: "1 / -1",
576
581
  gridAutoColumns: "1fr",
577
582
  ...this.gridProps
578
- }, t = this, s = p(b((n = (i = this.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = p(b((u = (a = this.native) == null ? void 0 : a.slots) == null ? void 0 : u.Form) ?? {}, this.globalNativeFormOverride.slots);
579
- return c(g.runtimeDoms.Form, U(s, {
583
+ }, t = this, s = m(g((n = (i = this.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = m(g((a = (u = this.native) == null ? void 0 : u.slots) == null ? void 0 : a.Form) ?? {}, this.globalNativeFormOverride.slots);
584
+ return c(P.runtimeDoms.Form, F(s, {
580
585
  ref: this.formRef,
581
586
  model: this.model.value
582
587
  }), {
@@ -589,14 +594,14 @@ class ue {
589
594
  });
590
595
  }
591
596
  }
592
- class g {
597
+ class P {
593
598
  }
594
- l(g, "runtimeDoms");
595
- const E = class E {
599
+ l(P, "runtimeDoms");
600
+ const V = class V {
596
601
  static getPlaceholderPrefixPresetByComponentName() {
597
602
  const e = {
598
- 请选择: ["Select", "Tree", "TreeSelect"],
599
- 请输入: ["Input"]
603
+ 请选择: ["select", "tree", "treeselect"],
604
+ 请输入: ["input"]
600
605
  }, t = {};
601
606
  for (let s in e)
602
607
  e[s].forEach((r) => {
@@ -605,7 +610,7 @@ const E = class E {
605
610
  return t;
606
611
  }
607
612
  };
608
- l(E, "schemaPreset", {
613
+ l(V, "schemaPreset", {
609
614
  type: {
610
615
  defaultValue: "item"
611
616
  },
@@ -641,13 +646,13 @@ l(E, "schemaPreset", {
641
646
  },
642
647
  native: void 0,
643
648
  gridProps: void 0
644
- }), l(E, "componentPropsPreset", {
649
+ }), l(V, "componentPropsPreset", {
645
650
  options: {
646
651
  defaultValue: []
647
652
  }
648
653
  }), // 基于基本功能提出基本预设
649
- l(E, "placeholderPresetByComponentName", E.getPlaceholderPrefixPresetByComponentName());
650
- let V = E;
654
+ l(V, "placeholderPresetByComponentName", V.getPlaceholderPrefixPresetByComponentName());
655
+ let w = V;
651
656
  const de = /* @__PURE__ */ oe({
652
657
  props: {
653
658
  setup: {
@@ -656,7 +661,7 @@ const de = /* @__PURE__ */ oe({
656
661
  }
657
662
  },
658
663
  setup(o) {
659
- const e = new ue(o.setup);
664
+ const e = new ae(o.setup);
660
665
  return () => e.exec();
661
666
  }
662
667
  });
@@ -673,7 +678,7 @@ function pe(o) {
673
678
  function me(o) {
674
679
  return {
675
680
  install() {
676
- g.runtimeDoms = o;
681
+ P.runtimeDoms = o;
677
682
  }
678
683
  };
679
684
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbor-design/proform",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",