@harbor-design/proform 1.0.19 → 1.0.20

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 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;
1
+ "use strict";var q=Object.defineProperty;var G=(n,e,t)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>(G(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class a{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function 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)}function $(n,e){return n.replace(/undefined/g,e)}class K{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,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})}customize(e){Object.assign(this.runtimeCore.customizedOptions,e),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps)}}class w{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 W{constructor(e){c(this,"runtimeCore");c(this,"processedSchemas");c(this,"processedModel");c(this,"getRuntimeMeta");c(this,"stableSchemas",[]);c(this,"stableModel",{});c(this,"schemaPreset",j.schemaPreset);c(this,"componentPropsPreset",j.componentPropsPreset);c(this,"stableUpdaterProcessProgress");c(this,"stableUpdaterTimes",0);c(this,"schemaEffect",new w);c(this,"defaultValueEffect",new w);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),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){a.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(y(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!a.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!a.isProcessInprogress(t)&&a.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,o=Array.from({length:Object.keys(e).filter(f=>f!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(f){const u=f.index,d=f.key,E=f.keyIndex;if(!f.stable)return;const O=r.parseStable(f.stable),V=s==null?void 0:s.index,g=s==null?void 0:s.key;let h=O;if(a.isProcessInprogress(h)||(o[E]=!0),s){let m=r.processedSchemas.value[V][g][u][d];m&&a.isObject(m)&&d!=="component"&&(h=p(m,h)),r.processedSchemas.value[V][g][u][d]=h,r.stableUpdater(o)}else{let m=r.processedSchemas.value[u][d];m&&a.isObject(m)&&(h=p(m,h)),r.processedSchemas.value[u][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})};a.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],u=>{if(!u)return l(u);this.defaultValueInprogressMap.set(t[r],u),!a.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{f()})):l(u)}):this.fieldParser(t[r],u=>{this.defaultValueInprogressMap.set(t[r],u),!a.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{f()})):l(u)})})}):r==="component"||r==="slots"||r==="runtimeSetters"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){a.isPromise(e)?e.then(r=>{s&&a.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(a.isString(e)&&(e=$(e,"")),s&&a.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(a.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{a.isUndefined(e.value)||(s&&a.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{a.isUndefined(e)||(s&&a.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&a.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),a.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=y(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){a.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),a.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),a.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function H(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class J{constructor(e){c(this,"schemas",i.ref([]));c(this,"model",i.ref({}));c(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});c(this,"formRef",i.ref(null));c(this,"hydrateEffect",new w);c(this,"customizedOptions",i.reactive({}));c(this,"gridProps",{});c(this,"runtimeSetters",{});c(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new W(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(y(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var C,N,A,z,F,M,R,x,D,U,k,_,L,T;p(this.globalNativeFormOverride.props,(N=(C=e.native)==null?void 0:C.props)==null?void 0:N.Form),p(this.globalNativeFormOverride.slots,(z=(A=e.native)==null?void 0:A.slots)==null?void 0:z.Form);const o=p(y((M=(F=this.customizedOptions.native)==null?void 0:F.props)==null?void 0:M.FormItem)??{},(x=(R=e.native)==null?void 0:R.props)==null?void 0:x.FormItem),l=p(y((U=(D=this.customizedOptions.native)==null?void 0:D.slots)==null?void 0:U.FormItem)??{},(_=(k=e.native)==null?void 0:k.slots)==null?void 0:_.FormItem),f={display:"grid",gridColumn:"1 / -1",...e.gridProps},u=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const E=d.name,O=e.componentProps??{},V=j.placeholderPresetByComponentName;let g=e.placeholder;if(e.required)if(!e.rules)e.rules=[],(L=e.rules)==null||L.push({required:!0,message:`${e.label}是必填项`});else{const S=e.rules.findIndex(B=>!!B.required);e.rules[S].message=`${e.label}是必填项`}let m=e.show;m===void 0&&(m=!0),m||delete s[e.field];let I=e.label;const P=(r==null?void 0:r.runtimeSetters)??this.runtimeSetters;return!a.isUndefined(t)&&P&&(I=$((T=P==null?void 0:P.listItemLabelSetter)==null?void 0:T.call(P,e.label,t+1),""),g=`${V[E]??"请输入"}${I}`),g||(g=`${V[E]??"请输入"}${I}`),i.createVNode("div",{style:f},[i.createVNode(b.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(b.runtimeDoms.FormItem,i.mergeProps(o,{label:`${I}:`,rules:e.rules,field:u}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":S=>s[e.field]=S,placeholder:g},O),null)},...l}),[[i.vShow,m]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.gridProps};return i.createVNode("div",{style:s},[i.createVNode(b.runtimeDoms.Group,{schema:e},H(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(y(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.gridProps},s=this;return s.model.value[e.field]||(s.model.value[e.field]=[{}]),i.createVNode("div",{style:t},[i.createVNode(b.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(b.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var u;let f=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(f,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((u=s.model.value[e.field])==null?void 0:u.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,u;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((u=(f=this.customizedOptions.native)==null?void 0:f.slots)==null?void 0:u.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{}c(b,"runtimeDoms");const v=class v{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};c(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}),c(v,"componentPropsPreset",{options:{defaultValue:[]}}),c(v,"placeholderPresetByComponentName",v.getPlaceholderPrefixPresetByComponentName());let j=v;const Q=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new J(n.setup);return()=>e.exec()}});function X(n){const e=new K(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e),customize:e.customize.bind(e)}]}function Y(n){return{install(){b.runtimeDoms=n}}}function Z(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=Q;exports.useForm=X;exports.useFormRenderer=Y;exports.useModifiers=Z;
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
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 {
1
+ var Z = Object.defineProperty;
2
+ var ee = (o, e, t) => e in o ? Z(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var l = (o, e, t) => (ee(o, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { toRaw as V, isRef as J, watch as E, isReactive as Q, nextTick as K, ref as A, reactive as te, createVNode as a, withDirectives as W, mergeProps as z, vShow as H, createTextVNode as se, isVNode as re, defineComponent as ie } from "vue";
5
+ class u {
6
6
  static typeChecker(e) {
7
7
  return {}.toString.call(e);
8
8
  }
@@ -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, u] of s)
89
- i.set(t(n), t(u));
88
+ for (let [n, c] of s)
89
+ i.set(t(n), t(c));
90
90
  return i;
91
91
  }
92
92
  if (s instanceof Set) {
@@ -112,7 +112,10 @@ function y(o) {
112
112
  }
113
113
  return t(o);
114
114
  }
115
- class te {
115
+ function X(o, e) {
116
+ return o.replace(/undefined/g, e);
117
+ }
118
+ class oe {
116
119
  constructor(e) {
117
120
  l(this, "runtimeCore");
118
121
  this.formCustomization = e;
@@ -124,13 +127,16 @@ class te {
124
127
  })), e;
125
128
  }
126
129
  setup(e) {
127
- return this.runtimeCore = e, this.formCustomization;
130
+ return this.runtimeCore = e, Object.assign(
131
+ this.runtimeCore.runtimeSetters,
132
+ this.formCustomization.runtimeSetters
133
+ ), this.formCustomization;
128
134
  }
129
135
  submit() {
130
136
  return new Promise((e, t) => {
131
137
  this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
132
138
  this.cleanFallbackFields(
133
- I(this.runtimeCore.processor.processedModel.value)
139
+ V(this.runtimeCore.processor.processedModel.value)
134
140
  )
135
141
  ));
136
142
  });
@@ -143,7 +149,7 @@ class te {
143
149
  });
144
150
  this.runtimeCore.hydrateEffect.trackEffect(
145
151
  () => {
146
- K(e) ? v(
152
+ J(e) ? E(
147
153
  () => e.value,
148
154
  () => {
149
155
  p(this.runtimeCore.model.value, e.value);
@@ -152,7 +158,7 @@ class te {
152
158
  deep: !0,
153
159
  immediate: !0
154
160
  }
155
- ) : W(e) ? v(
161
+ ) : Q(e) ? E(
156
162
  () => e,
157
163
  () => {
158
164
  p(this.runtimeCore.model.value, e);
@@ -173,7 +179,7 @@ class te {
173
179
  Object.assign(this.runtimeCore.customizedOptions, e), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps);
174
180
  }
175
181
  }
176
- class A {
182
+ class F {
177
183
  constructor() {
178
184
  l(this, "effects", /* @__PURE__ */ new Set());
179
185
  }
@@ -189,7 +195,7 @@ class A {
189
195
  return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
190
196
  }
191
197
  }
192
- class se {
198
+ class ne {
193
199
  constructor(e) {
194
200
  l(this, "runtimeCore");
195
201
  l(this, "processedSchemas");
@@ -197,15 +203,15 @@ class se {
197
203
  l(this, "getRuntimeMeta");
198
204
  l(this, "stableSchemas", []);
199
205
  l(this, "stableModel", {});
200
- l(this, "schemaPreset", S.schemaPreset);
201
- l(this, "componentPropsPreset", S.componentPropsPreset);
206
+ l(this, "schemaPreset", I.schemaPreset);
207
+ l(this, "componentPropsPreset", I.componentPropsPreset);
202
208
  l(this, "stableUpdaterProcessProgress");
203
209
  l(this, "stableUpdaterTimes", 0);
204
- l(this, "schemaEffect", new A());
205
- l(this, "defaultValueEffect", new A());
210
+ l(this, "schemaEffect", new F());
211
+ l(this, "defaultValueEffect", new F());
206
212
  l(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
207
213
  l(this, "baseDefaultValueFunctionsLength");
208
- this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), v(
214
+ this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), E(
209
215
  () => this.processedModel.value,
210
216
  () => {
211
217
  this.schemaEffect.triggerEffects();
@@ -241,13 +247,13 @@ class se {
241
247
  }
242
248
  // 派生过程,用于外部应用
243
249
  parseSchemas(e, t) {
244
- f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
250
+ u.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
245
251
  y(e)
246
252
  ), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
247
253
  }
248
254
  parseStable(e) {
249
255
  const t = {};
250
- if (!f.isUndefined(e.stable))
256
+ if (!u.isUndefined(e.stable))
251
257
  t[e.key] = this.parseStable(e.stable);
252
258
  else
253
259
  return e;
@@ -256,8 +262,8 @@ class se {
256
262
  // 对于稳定初始化更新的抽象
257
263
  stableUpdater(e = []) {
258
264
  if (e.every(Boolean)) {
259
- const t = I(this.processedSchemas.value);
260
- !f.isProcessInprogress(t) && f.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
265
+ const t = V(this.processedSchemas.value);
266
+ !u.isProcessInprogress(t) && u.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
261
267
  length: t.length
262
268
  }).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
263
269
  }
@@ -265,21 +271,21 @@ class se {
265
271
  // 核心单 schema 处理过程,接收一个对象键值对的数据结构
266
272
  parseItem(e, t, s) {
267
273
  const r = this, i = Array.from({
268
- length: Object.keys(e).filter((u) => u !== "children").length
274
+ length: Object.keys(e).filter((c) => c !== "children").length
269
275
  }).fill(!1);
270
276
  this.objectParser({ data: e, index: t, updater: n });
271
- function n(u) {
272
- const a = u.index, d = u.key, O = u.keyIndex;
273
- if (!u.stable)
277
+ function n(c) {
278
+ const f = c.index, d = c.key, O = c.keyIndex;
279
+ if (!c.stable)
274
280
  return;
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);
281
+ const w = r.parseStable(c.stable), S = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
282
+ let h = w;
283
+ if (u.isProcessInprogress(h) || (i[O] = !0), s) {
284
+ let m = r.processedSchemas.value[S][g][f][d];
285
+ m && u.isObject(m) && d !== "component" && (h = p(m, h)), r.processedSchemas.value[S][g][f][d] = h, r.stableUpdater(i);
280
286
  } else {
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);
287
+ let m = r.processedSchemas.value[f][d];
288
+ m && u.isObject(m) && (h = p(m, h)), r.processedSchemas.value[f][d] = h, r.stableUpdater(i);
283
289
  }
284
290
  }
285
291
  }
@@ -294,59 +300,56 @@ class se {
294
300
  keyIndex: i
295
301
  });
296
302
  else {
297
- const n = (u) => {
303
+ const n = (c) => {
298
304
  e.updater({
299
305
  ...e,
300
306
  key: r,
301
307
  keyIndex: i,
302
- stable: u
308
+ stable: c
303
309
  });
304
310
  };
305
- f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
311
+ u.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
306
312
  if (r === "component") {
307
- const u = t[r](this.getRuntimeMeta());
308
- this.promiseFieldParser(u, n, !1);
313
+ const c = t[r](this.getRuntimeMeta());
314
+ this.promiseFieldParser(c, n, !1);
309
315
  } else
310
316
  this.fieldParser(t[r], n);
311
317
  }) : this.defaultValueEffect.trackEffect(() => {
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(
318
+ const c = this.schemaEffect.trackEffect(() => {
319
+ /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (f) => {
320
+ if (!f)
321
+ return n(f);
322
+ this.defaultValueInprogressMap.set(t[r], f), !u.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
317
323
  (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(
324
+ ) ? (n(f), this.defaultValueEffect.clearEffects(), K(() => {
325
+ c();
326
+ })) : n(f);
327
+ }) : this.fieldParser(t[r], (f) => {
328
+ this.defaultValueInprogressMap.set(t[r], f), !u.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
323
329
  (d) => !d.includes("undefined")
324
- ) ? (n(a), this.defaultValueEffect.clearEffects(), $(() => {
325
- u();
326
- })) : n(a);
330
+ ) ? (n(f), this.defaultValueEffect.clearEffects(), K(() => {
331
+ c();
332
+ })) : n(f);
327
333
  });
328
334
  });
329
- }) : r === "component" || r === "slots" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
335
+ }) : r === "component" || r === "slots" || r === "runtimeSetters" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
330
336
  }
331
337
  });
332
338
  }
333
- replaceUndefinedInString(e, t) {
334
- return e.replace(/undefined/g, t);
335
- }
336
339
  promiseFieldParser(e, t, s) {
337
- f.isPromise(e) ? e.then((r) => {
338
- s && f.isObject(r) ? this.objectParser({
340
+ u.isPromise(e) ? e.then((r) => {
341
+ s && u.isObject(r) ? this.objectParser({
339
342
  data: r,
340
343
  updater: t
341
344
  }) : t(r);
342
- }) : (f.isString(e) && (e = this.replaceUndefinedInString(e, "")), s && f.isObject(e) ? this.objectParser({
345
+ }) : (u.isString(e) && (e = X(e, "")), s && u.isObject(e) ? this.objectParser({
343
346
  data: e,
344
347
  updater: t
345
348
  }) : t(e));
346
349
  }
347
350
  // 对任意对象中单个字段的 parse: 做基本处理
348
351
  fieldParser(e, t, s = !0) {
349
- if (f.isFunction(e))
352
+ if (u.isFunction(e))
350
353
  if (e.name.startsWith("__proform_raw_"))
351
354
  t(e);
352
355
  else {
@@ -354,10 +357,10 @@ class se {
354
357
  this.promiseFieldParser(r, t, s);
355
358
  }
356
359
  else
357
- K(e) ? v(
360
+ J(e) ? E(
358
361
  () => e.value,
359
362
  () => {
360
- f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
363
+ u.isUndefined(e.value) || (s && u.isObject(e.value) ? this.objectParser({
361
364
  data: e.value,
362
365
  updater: t
363
366
  }) : t(e.value));
@@ -366,10 +369,10 @@ class se {
366
369
  immediate: !0,
367
370
  deep: !0
368
371
  }
369
- ) : W(e) ? v(
372
+ ) : Q(e) ? E(
370
373
  () => e,
371
374
  () => {
372
- f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
375
+ u.isUndefined(e) || (s && u.isObject(e) ? this.objectParser({
373
376
  data: e,
374
377
  updater: t
375
378
  }) : t(e));
@@ -378,7 +381,7 @@ class se {
378
381
  immediate: !0,
379
382
  deep: !0
380
383
  }
381
- ) : s && f.isObject(e) ? this.objectParser({
384
+ ) : s && u.isObject(e) ? this.objectParser({
382
385
  data: e,
383
386
  updater: t
384
387
  }) : t(e);
@@ -386,87 +389,92 @@ class se {
386
389
  modelProcessor(e) {
387
390
  e.map(
388
391
  (t) => this.createModel(t, this.processedModel.value)
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());
392
+ ), 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());
390
393
  }
391
394
  createModel(e, t) {
392
- f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
395
+ u.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
393
396
  this.createModel(s, t[e.field][0]);
394
- })), f.isGroupSchema(e) && e.children.forEach((s) => {
397
+ })), u.isGroupSchema(e) && e.children.forEach((s) => {
395
398
  this.createModel(s, t);
396
- }), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
399
+ }), u.isItemSchema(e) && (t[e.field] = e.defaultValue);
397
400
  }
398
401
  }
399
- function re(o) {
400
- return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !Z(o);
402
+ function le(o) {
403
+ return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !re(o);
401
404
  }
402
- class ie {
405
+ class ue {
403
406
  constructor(e) {
404
- l(this, "schemas", C([]));
405
- l(this, "model", C({}));
407
+ l(this, "schemas", A([]));
408
+ l(this, "model", A({}));
406
409
  l(this, "processorBySchemaType", {
407
410
  item: this.runtimeItemProcessor.bind(this),
408
411
  group: this.runtimeGroupProcessor.bind(this),
409
412
  list: this.runtimeListProcessor.bind(this)
410
413
  });
411
- l(this, "formRef", C(null));
412
- l(this, "hydrateEffect", new A());
413
- l(this, "customizedOptions", X({}));
414
+ l(this, "formRef", A(null));
415
+ l(this, "hydrateEffect", new F());
416
+ l(this, "customizedOptions", te({}));
414
417
  l(this, "gridProps", {});
418
+ l(this, "runtimeSetters", {});
415
419
  l(this, "globalNativeFormOverride", {
416
420
  props: {},
417
421
  slots: {}
418
422
  });
419
- this.setup = e, this.processor = new se(this);
423
+ this.setup = e, this.processor = new ne(this);
420
424
  const t = this.setup(this);
421
425
  this.processor.parseSchemas(t.schemas);
422
426
  }
423
427
  getRuntimeMeta() {
424
428
  return {
425
- model: I(y(this.model.value))
429
+ model: V(y(this.model.value))
426
430
  };
427
431
  }
428
432
  runtimeItemProcessor(e, t, s = this.model.value, r) {
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 = {
433
+ var M, x, U, D, N, R, _, k, L, $, B, T, q, G;
434
+ p(this.globalNativeFormOverride.props, (x = (M = e.native) == null ? void 0 : M.props) == null ? void 0 : x.Form), p(this.globalNativeFormOverride.slots, (D = (U = e.native) == null ? void 0 : U.slots) == null ? void 0 : D.Form);
435
+ const i = p(y((R = (N = this.customizedOptions.native) == null ? void 0 : N.props) == null ? void 0 : R.FormItem) ?? {}, (k = (_ = e.native) == null ? void 0 : _.props) == null ? void 0 : k.FormItem), n = p(y(($ = (L = this.customizedOptions.native) == null ? void 0 : L.slots) == null ? void 0 : $.FormItem) ?? {}, (T = (B = e.native) == null ? void 0 : B.slots) == null ? void 0 : T.FormItem), c = {
432
436
  display: "grid",
433
437
  gridColumn: "1 / -1",
434
438
  ...e.gridProps
435
- }, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = I(e.component);
439
+ }, f = r ? `${r.field}.${t}.${e.field}` : e.field, d = V(e.component);
436
440
  if (!d)
437
441
  return;
438
- const O = d.name, V = e.componentProps ?? {}, E = S.placeholderPresetByComponentName;
442
+ const O = d.name, w = e.componentProps ?? {}, S = I.placeholderPresetByComponentName;
439
443
  let g = e.placeholder;
440
- if (g || (g = `${// @ts-expect-error
441
- E[O] ?? "请输入"}${e.label}`), e.required)
444
+ if (e.required)
442
445
  if (!e.rules)
443
- e.rules = [], (T = e.rules) == null || T.push({
446
+ e.rules = [], (q = e.rules) == null || q.push({
444
447
  required: !0,
445
448
  message: `${e.label}是必填项`
446
449
  });
447
450
  else {
448
- const j = e.rules.findIndex((H) => !!H.required);
451
+ const j = e.rules.findIndex((Y) => !!Y.required);
449
452
  e.rules[j].message = `${e.label}是必填项`;
450
453
  }
451
454
  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, {
455
+ m === void 0 && (m = !0), m || delete s[e.field];
456
+ let C = e.label;
457
+ const P = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
458
+ return !u.isUndefined(t) && P && (C = X((G = P == null ? void 0 : P.listItemLabelSetter) == null ? void 0 : G.call(P, e.label, t + 1), ""), g = `${// @ts-expect-error
459
+ S[O] ?? "请输入"}${C}`), g || (g = `${// @ts-expect-error
460
+ S[O] ?? "请输入"}${C}`), a("div", {
461
+ style: c
462
+ }, [a(b.runtimeDoms.Item, null, {
455
463
  default() {
456
- return q(c(b.runtimeDoms.FormItem, w(i, {
457
- label: `${e.label}:`,
464
+ return W(a(b.runtimeDoms.FormItem, z(i, {
465
+ label: `${C}:`,
458
466
  rules: e.rules,
459
- field: a
467
+ field: f
460
468
  }), {
461
469
  default() {
462
- return c(d, w({
470
+ return a(d, z({
463
471
  modelValue: s[e.field],
464
472
  "onUpdate:modelValue": (j) => s[e.field] = j,
465
473
  placeholder: g
466
- }, V), null);
474
+ }, w), null);
467
475
  },
468
476
  ...n
469
- }), [[G, m]]);
477
+ }), [[H, m]]);
470
478
  }
471
479
  })]);
472
480
  }
@@ -477,11 +485,11 @@ class ie {
477
485
  gridColumn: "1 / -1",
478
486
  ...e.gridProps
479
487
  };
480
- return c("div", {
488
+ return a("div", {
481
489
  style: s
482
- }, [c(b.runtimeDoms.Group, {
490
+ }, [a(b.runtimeDoms.Group, {
483
491
  schema: e
484
- }, re(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
492
+ }, le(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
485
493
  default: () => [t]
486
494
  })]);
487
495
  }
@@ -503,32 +511,32 @@ class ie {
503
511
  gridColumn: "1 / -1",
504
512
  ...e.gridProps
505
513
  }, s = this;
506
- return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
514
+ return s.model.value[e.field] || (s.model.value[e.field] = [{}]), a("div", {
507
515
  style: t
508
- }, [c(b.runtimeDoms.List, {
516
+ }, [a(b.runtimeDoms.List, {
509
517
  schema: e
510
518
  }, {
511
519
  default() {
512
- return s.model.value[e.field].map((r, i) => c(b.runtimeDoms.ListItem, null, {
520
+ return s.model.value[e.field].map((r, i) => a(b.runtimeDoms.ListItem, null, {
513
521
  default() {
514
522
  return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
515
523
  },
516
524
  delete({
517
525
  container: n
518
526
  } = {}) {
519
- var a;
520
- let u = n ?? c("button", null, null);
521
- return q(c(u, {
527
+ var f;
528
+ let c = n ?? a("button", null, null);
529
+ return W(a(c, {
522
530
  onClick: () => s.deleteListItem(e, i)
523
- }, null), [[G, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
531
+ }, null), [[H, ((f = s.model.value[e.field]) == null ? void 0 : f.length) > 1]]);
524
532
  }
525
533
  }));
526
534
  },
527
535
  add({
528
536
  container: r
529
537
  } = {}) {
530
- let i = r ?? c("button", null, [Y("添加")]);
531
- return c(i, {
538
+ let i = r ?? a("button", null, [se("添加")]);
539
+ return a(i, {
532
540
  onClick: () => s.addListItem(e)
533
541
  }, null);
534
542
  }
@@ -538,19 +546,19 @@ class ie {
538
546
  return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
539
547
  }
540
548
  exec() {
541
- var i, n, u, a;
549
+ var i, n, c, f;
542
550
  const e = {
543
551
  display: "grid",
544
552
  gridColumn: "1 / -1",
545
553
  gridAutoColumns: "1fr",
546
554
  ...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, {
555
+ }, 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((f = (c = this.customizedOptions.native) == null ? void 0 : c.slots) == null ? void 0 : f.Form) ?? {}, this.globalNativeFormOverride.slots);
556
+ return a(b.runtimeDoms.Form, z(s, {
549
557
  ref: this.formRef,
550
558
  model: this.model.value
551
559
  }), {
552
560
  default() {
553
- return c("div", {
561
+ return a("div", {
554
562
  style: e
555
563
  }, [t.runtimeProcessor(t.schemas.value)]);
556
564
  },
@@ -561,7 +569,7 @@ class ie {
561
569
  class b {
562
570
  }
563
571
  l(b, "runtimeDoms");
564
- const P = class P {
572
+ const v = class v {
565
573
  static getPlaceholderPrefixPresetByComponentName() {
566
574
  const e = {
567
575
  请选择: ["Select", "Tree", "TreeSelect"],
@@ -574,7 +582,7 @@ const P = class P {
574
582
  return t;
575
583
  }
576
584
  };
577
- l(P, "schemaPreset", {
585
+ l(v, "schemaPreset", {
578
586
  type: {
579
587
  defaultValue: "item"
580
588
  },
@@ -610,14 +618,14 @@ l(P, "schemaPreset", {
610
618
  },
611
619
  native: void 0,
612
620
  gridProps: void 0
613
- }), l(P, "componentPropsPreset", {
621
+ }), l(v, "componentPropsPreset", {
614
622
  options: {
615
623
  defaultValue: []
616
624
  }
617
625
  }), // 基于基本功能提出基本预设
618
- l(P, "placeholderPresetByComponentName", P.getPlaceholderPrefixPresetByComponentName());
619
- let S = P;
620
- const le = /* @__PURE__ */ ee({
626
+ l(v, "placeholderPresetByComponentName", v.getPlaceholderPrefixPresetByComponentName());
627
+ let I = v;
628
+ const ae = /* @__PURE__ */ ie({
621
629
  props: {
622
630
  setup: {
623
631
  type: Function,
@@ -625,12 +633,12 @@ const le = /* @__PURE__ */ ee({
625
633
  }
626
634
  },
627
635
  setup(o) {
628
- const e = new ie(o.setup);
636
+ const e = new ue(o.setup);
629
637
  return () => e.exec();
630
638
  }
631
639
  });
632
- function ae(o) {
633
- const e = new te(o);
640
+ function de(o) {
641
+ const e = new oe(o);
634
642
  return [
635
643
  e.setup.bind(e),
636
644
  {
@@ -640,22 +648,22 @@ function ae(o) {
640
648
  }
641
649
  ];
642
650
  }
643
- function fe(o) {
651
+ function pe(o) {
644
652
  return {
645
653
  install() {
646
654
  b.runtimeDoms = o;
647
655
  }
648
656
  };
649
657
  }
650
- function ue(o, e) {
658
+ function me(o, e) {
651
659
  return e === "raw" && Object.defineProperty(o, "name", {
652
660
  value: `__proform_raw_${o.name}`,
653
661
  writable: !0
654
662
  }), o;
655
663
  }
656
664
  export {
657
- le as ProForm,
658
- ae as useForm,
659
- fe as useFormRenderer,
660
- ue as useModifiers
665
+ ae as ProForm,
666
+ de as useForm,
667
+ pe as useFormRenderer,
668
+ me as useModifiers
661
669
  };
@@ -30,7 +30,6 @@ export default class Processor {
30
30
  stableUpdater(parseProcess?: boolean[]): void;
31
31
  parseItem(data: AnyObject, index: number, parentMeta?: AnyObject): void;
32
32
  objectParser(root: ObjectParserRoot): void;
33
- replaceUndefinedInString(data: string, replaceTo: string): string;
34
33
  promiseFieldParser(rootField: any, updater: AnyFunction, deepProcess: boolean): void;
35
34
  fieldParser(rootField: any, updater: AnyFunction, deepProcess?: boolean): void;
36
35
  modelProcessor(schemas: Schema[]): void;
@@ -1,5 +1,5 @@
1
1
  import { Ref } from "vue";
2
- import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType, CustomizationOptions } from "../types";
2
+ import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType, CustomizationOptions, RuntimeSetters } from "../types";
3
3
  import Processor from "./Processor";
4
4
  import Effect from "./Effect";
5
5
  export default class RuntimeCore {
@@ -12,6 +12,7 @@ export default class RuntimeCore {
12
12
  hydrateEffect: Effect;
13
13
  customizedOptions: CustomizationOptions;
14
14
  gridProps: {};
15
+ runtimeSetters: RuntimeSetters;
15
16
  globalNativeFormOverride: {
16
17
  props: {};
17
18
  slots: {};
@@ -78,6 +78,7 @@ export interface ListSchema {
78
78
  label: string;
79
79
  children: ProxyedSchema[];
80
80
  gridProps?: GridStyle;
81
+ runtimeSetters?: RuntimeSetters;
81
82
  }
82
83
  export type Schema = ItemSchema | GroupSchema | ListSchema;
83
84
  export interface runtimeMeta {
@@ -88,8 +89,13 @@ export type ProFormProxy<T> = {
88
89
  [K in keyof T]: ProFormProxyRule<T[K]>;
89
90
  };
90
91
  export type ProxyedSchema = ProFormProxy<ItemSchema | GroupSchema | ListSchema>;
92
+ export interface RuntimeSetters {
93
+ listItemLabelSetter?: (rawLabel: string, rawIndex: number) => any;
94
+ }
91
95
  export interface FormCustomization {
92
96
  gridProps?: GridStyle;
97
+ native?: NativeCustomizationOptions;
98
+ runtimeSetters?: RuntimeSetters;
93
99
  schemas: ProxyedSchema[];
94
100
  }
95
101
  export type NativeCustomizationOptions = {
@@ -1,2 +1,3 @@
1
1
  export { default as IS } from "./is";
2
2
  export * from "./deep";
3
+ export * from "./replace";
@@ -0,0 +1 @@
1
+ export declare function replaceUndefinedInString(data: string, replaceTo: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbor-design/proform",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",