@harbor-design/proform 1.0.19 → 1.1.0

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 a=(n,e,t)=>(G(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 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,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 $(n,e){return n.replace(/undefined/g,e)}class K{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 C{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 W{constructor(e){a(this,"runtimeCore");a(this,"processedSchemas");a(this,"processedModel");a(this,"getRuntimeMeta");a(this,"stableSchemas",[]);a(this,"stableModel",{});a(this,"schemaPreset",j.schemaPreset);a(this,"componentPropsPreset",j.componentPropsPreset);a(this,"stableUpdaterProcessProgress");a(this,"stableUpdaterTimes",0);a(this,"schemaEffect",new C);a(this,"defaultValueEffect",new C);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(y(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,E=u.keyIndex;if(!u.stable)return;const w=r.parseStable(u.stable),V=s==null?void 0:s.index,g=s==null?void 0:s.key;let h=w;if(c.isProcessInprogress(h)||(o[E]=!0),s){let m=r.processedSchemas.value[V][g][f][d];m&&c.isObject(m)&&d!=="component"&&(h=p(m,h)),r.processedSchemas.value[V][g][f][d]=h,r.stableUpdater(o)}else{let m=r.processedSchemas.value[f][d];m&&c.isObject(m)&&(h=p(m,h)),r.processedSchemas.value[f][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=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=>{s&&c.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(c.isString(e)&&(e=$(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(e);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=y(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 H(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class J{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 C);a(this,"native",i.reactive({}));a(this,"gridProps",{});a(this,"runtimeSetters",{});a(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 O,N,A,F,M,R,x,D,U,k,_,L,z,T;p(this.globalNativeFormOverride.props,(N=(O=e.native)==null?void 0:O.props)==null?void 0:N.Form),p(this.globalNativeFormOverride.slots,(F=(A=e.native)==null?void 0:A.slots)==null?void 0:F.Form);const o=p(y((R=(M=this.native)==null?void 0:M.props)==null?void 0:R.FormItem)??{},(D=(x=e.native)==null?void 0:x.props)==null?void 0:D.FormItem),l=p(y((k=(U=this.native)==null?void 0:U.slots)==null?void 0:k.FormItem)??{},(L=(_=e.native)==null?void 0:_.slots)==null?void 0:L.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 E=d.name,w=e.componentProps??{},V=j.placeholderPresetByComponentName;let g=e.placeholder;if(e.required)if(!e.rules)e.rules=[],(z=e.rules)==null||z.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!c.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:u},[i.createVNode(b.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(b.runtimeDoms.FormItem,i.mergeProps(o,{label:`${I}:`,rules:e.rules,field:f}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":S=>s[e.field]=S,placeholder:g},w),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 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(y((l=(o=this.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(y((f=(u=this.native)==null?void 0:u.slots)==null?void 0:f.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 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 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)}]}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,7 +1,7 @@
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";
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 O, isRef as J, watch as E, isReactive as Q, nextTick as K, ref as A, reactive as te, createVNode as c, withDirectives as W, mergeProps as F, vShow as H, createTextVNode as se, isVNode as re, defineComponent as ie } from "vue";
5
5
  class f {
6
6
  static typeChecker(e) {
7
7
  return {}.toString.call(e);
@@ -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(this.runtimeCore.native, this.formCustomization.native), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps), 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
+ O(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);
@@ -168,12 +174,8 @@ class te {
168
174
  }
169
175
  );
170
176
  }
171
- // TODO:目前仅用于配制一些基本的如 Form,FormItem 等 UI 库组件的默认属性,但后续会扩展其价值,包括设置统一布局等,都会考虑往内部封装
172
- customize(e) {
173
- Object.assign(this.runtimeCore.customizedOptions, e), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps);
174
- }
175
177
  }
176
- class A {
178
+ class M {
177
179
  constructor() {
178
180
  l(this, "effects", /* @__PURE__ */ new Set());
179
181
  }
@@ -189,7 +191,7 @@ class A {
189
191
  return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
190
192
  }
191
193
  }
192
- class se {
194
+ class ne {
193
195
  constructor(e) {
194
196
  l(this, "runtimeCore");
195
197
  l(this, "processedSchemas");
@@ -197,15 +199,15 @@ class se {
197
199
  l(this, "getRuntimeMeta");
198
200
  l(this, "stableSchemas", []);
199
201
  l(this, "stableModel", {});
200
- l(this, "schemaPreset", S.schemaPreset);
201
- l(this, "componentPropsPreset", S.componentPropsPreset);
202
+ l(this, "schemaPreset", I.schemaPreset);
203
+ l(this, "componentPropsPreset", I.componentPropsPreset);
202
204
  l(this, "stableUpdaterProcessProgress");
203
205
  l(this, "stableUpdaterTimes", 0);
204
- l(this, "schemaEffect", new A());
205
- l(this, "defaultValueEffect", new A());
206
+ l(this, "schemaEffect", new M());
207
+ l(this, "defaultValueEffect", new M());
206
208
  l(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
207
209
  l(this, "baseDefaultValueFunctionsLength");
208
- 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), E(
209
211
  () => this.processedModel.value,
210
212
  () => {
211
213
  this.schemaEffect.triggerEffects();
@@ -256,7 +258,7 @@ class se {
256
258
  // 对于稳定初始化更新的抽象
257
259
  stableUpdater(e = []) {
258
260
  if (e.every(Boolean)) {
259
- const t = I(this.processedSchemas.value);
261
+ const t = O(this.processedSchemas.value);
260
262
  !f.isProcessInprogress(t) && f.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
261
263
  length: t.length
262
264
  }).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
@@ -269,14 +271,14 @@ class se {
269
271
  }).fill(!1);
270
272
  this.objectParser({ data: e, index: t, updater: n });
271
273
  function n(u) {
272
- const a = u.index, d = u.key, O = u.keyIndex;
274
+ const a = u.index, d = u.key, C = u.keyIndex;
273
275
  if (!u.stable)
274
276
  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);
277
+ const w = r.parseStable(u.stable), S = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
278
+ let h = w;
279
+ if (f.isProcessInprogress(h) || (i[C] = !0), s) {
280
+ let m = r.processedSchemas.value[S][g][a][d];
281
+ m && f.isObject(m) && d !== "component" && (h = p(m, h)), r.processedSchemas.value[S][g][a][d] = h, r.stableUpdater(i);
280
282
  } else {
281
283
  let m = r.processedSchemas.value[a][d];
282
284
  m && f.isObject(m) && (h = p(m, h)), r.processedSchemas.value[a][d] = h, r.stableUpdater(i);
@@ -315,31 +317,28 @@ class se {
315
317
  return n(a);
316
318
  this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
317
319
  (d) => !d.includes("undefined")
318
- ) ? (n(a), this.defaultValueEffect.clearEffects(), $(() => {
320
+ ) ? (n(a), this.defaultValueEffect.clearEffects(), K(() => {
319
321
  u();
320
322
  })) : n(a);
321
323
  }) : this.fieldParser(t[r], (a) => {
322
324
  this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
323
325
  (d) => !d.includes("undefined")
324
- ) ? (n(a), this.defaultValueEffect.clearEffects(), $(() => {
326
+ ) ? (n(a), this.defaultValueEffect.clearEffects(), K(() => {
325
327
  u();
326
328
  })) : n(a);
327
329
  });
328
330
  });
329
- }) : r === "component" || r === "slots" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
331
+ }) : r === "component" || r === "slots" || r === "runtimeSetters" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
330
332
  }
331
333
  });
332
334
  }
333
- replaceUndefinedInString(e, t) {
334
- return e.replace(/undefined/g, t);
335
- }
336
335
  promiseFieldParser(e, t, s) {
337
336
  f.isPromise(e) ? e.then((r) => {
338
337
  s && f.isObject(r) ? this.objectParser({
339
338
  data: r,
340
339
  updater: t
341
340
  }) : t(r);
342
- }) : (f.isString(e) && (e = this.replaceUndefinedInString(e, "")), s && f.isObject(e) ? this.objectParser({
341
+ }) : (f.isString(e) && (e = X(e, "")), s && f.isObject(e) ? this.objectParser({
343
342
  data: e,
344
343
  updater: t
345
344
  }) : t(e));
@@ -354,7 +353,7 @@ class se {
354
353
  this.promiseFieldParser(r, t, s);
355
354
  }
356
355
  else
357
- K(e) ? v(
356
+ J(e) ? E(
358
357
  () => e.value,
359
358
  () => {
360
359
  f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
@@ -366,7 +365,7 @@ class se {
366
365
  immediate: !0,
367
366
  deep: !0
368
367
  }
369
- ) : W(e) ? v(
368
+ ) : Q(e) ? E(
370
369
  () => e,
371
370
  () => {
372
371
  f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
@@ -396,77 +395,82 @@ class se {
396
395
  }), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
397
396
  }
398
397
  }
399
- function re(o) {
400
- return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !Z(o);
398
+ function le(o) {
399
+ return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !re(o);
401
400
  }
402
- class ie {
401
+ class fe {
403
402
  constructor(e) {
404
- l(this, "schemas", C([]));
405
- l(this, "model", C({}));
403
+ l(this, "schemas", A([]));
404
+ l(this, "model", A({}));
406
405
  l(this, "processorBySchemaType", {
407
406
  item: this.runtimeItemProcessor.bind(this),
408
407
  group: this.runtimeGroupProcessor.bind(this),
409
408
  list: this.runtimeListProcessor.bind(this)
410
409
  });
411
- l(this, "formRef", C(null));
412
- l(this, "hydrateEffect", new A());
413
- l(this, "customizedOptions", X({}));
410
+ l(this, "formRef", A(null));
411
+ l(this, "hydrateEffect", new M());
412
+ l(this, "native", te({}));
414
413
  l(this, "gridProps", {});
414
+ l(this, "runtimeSetters", {});
415
415
  l(this, "globalNativeFormOverride", {
416
416
  props: {},
417
417
  slots: {}
418
418
  });
419
- this.setup = e, this.processor = new se(this);
419
+ this.setup = e, this.processor = new ne(this);
420
420
  const t = this.setup(this);
421
421
  this.processor.parseSchemas(t.schemas);
422
422
  }
423
423
  getRuntimeMeta() {
424
424
  return {
425
- model: I(y(this.model.value))
425
+ model: O(y(this.model.value))
426
426
  };
427
427
  }
428
428
  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 = {
429
+ var x, U, D, N, R, _, k, L, z, $, B, T, q, G;
430
+ p(this.globalNativeFormOverride.props, (U = (x = e.native) == null ? void 0 : x.props) == null ? void 0 : U.Form), p(this.globalNativeFormOverride.slots, (N = (D = e.native) == null ? void 0 : D.slots) == null ? void 0 : N.Form);
431
+ const i = p(y((_ = (R = this.native) == null ? void 0 : R.props) == null ? void 0 : _.FormItem) ?? {}, (L = (k = e.native) == null ? void 0 : k.props) == null ? void 0 : L.FormItem), n = p(y(($ = (z = this.native) == null ? void 0 : z.slots) == null ? void 0 : $.FormItem) ?? {}, (T = (B = e.native) == null ? void 0 : B.slots) == null ? void 0 : T.FormItem), u = {
432
432
  display: "grid",
433
433
  gridColumn: "1 / -1",
434
434
  ...e.gridProps
435
- }, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = I(e.component);
435
+ }, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
436
436
  if (!d)
437
437
  return;
438
- const O = d.name, V = e.componentProps ?? {}, E = S.placeholderPresetByComponentName;
438
+ const C = d.name, w = e.componentProps ?? {}, S = I.placeholderPresetByComponentName;
439
439
  let g = e.placeholder;
440
- if (g || (g = `${// @ts-expect-error
441
- E[O] ?? "请输入"}${e.label}`), e.required)
440
+ if (e.required)
442
441
  if (!e.rules)
443
- e.rules = [], (T = e.rules) == null || T.push({
442
+ e.rules = [], (q = e.rules) == null || q.push({
444
443
  required: !0,
445
444
  message: `${e.label}是必填项`
446
445
  });
447
446
  else {
448
- const j = e.rules.findIndex((H) => !!H.required);
447
+ const j = e.rules.findIndex((Y) => !!Y.required);
449
448
  e.rules[j].message = `${e.label}是必填项`;
450
449
  }
451
450
  let m = e.show;
452
- return m === void 0 && (m = !0), m || delete s[e.field], c("div", {
451
+ m === void 0 && (m = !0), m || delete s[e.field];
452
+ let V = e.label;
453
+ const P = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
454
+ return !f.isUndefined(t) && P && (V = X((G = P == null ? void 0 : P.listItemLabelSetter) == null ? void 0 : G.call(P, e.label, t + 1), ""), g = `${// @ts-expect-error
455
+ S[C] ?? "请输入"}${V}`), g || (g = `${// @ts-expect-error
456
+ S[C] ?? "请输入"}${V}`), c("div", {
453
457
  style: u
454
458
  }, [c(b.runtimeDoms.Item, null, {
455
459
  default() {
456
- return q(c(b.runtimeDoms.FormItem, w(i, {
457
- label: `${e.label}:`,
460
+ return W(c(b.runtimeDoms.FormItem, F(i, {
461
+ label: `${V}:`,
458
462
  rules: e.rules,
459
463
  field: a
460
464
  }), {
461
465
  default() {
462
- return c(d, w({
466
+ return c(d, F({
463
467
  modelValue: s[e.field],
464
468
  "onUpdate:modelValue": (j) => s[e.field] = j,
465
469
  placeholder: g
466
- }, V), null);
470
+ }, w), null);
467
471
  },
468
472
  ...n
469
- }), [[G, m]]);
473
+ }), [[H, m]]);
470
474
  }
471
475
  })]);
472
476
  }
@@ -481,7 +485,7 @@ class ie {
481
485
  style: s
482
486
  }, [c(b.runtimeDoms.Group, {
483
487
  schema: e
484
- }, re(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
488
+ }, le(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
485
489
  default: () => [t]
486
490
  })]);
487
491
  }
@@ -518,16 +522,16 @@ class ie {
518
522
  } = {}) {
519
523
  var a;
520
524
  let u = n ?? c("button", null, null);
521
- return q(c(u, {
525
+ return W(c(u, {
522
526
  onClick: () => s.deleteListItem(e, i)
523
- }, null), [[G, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
527
+ }, null), [[H, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
524
528
  }
525
529
  }));
526
530
  },
527
531
  add({
528
532
  container: r
529
533
  } = {}) {
530
- let i = r ?? c("button", null, [Y("添加")]);
534
+ let i = r ?? c("button", null, [se("添加")]);
531
535
  return c(i, {
532
536
  onClick: () => s.addListItem(e)
533
537
  }, null);
@@ -544,8 +548,8 @@ class ie {
544
548
  gridColumn: "1 / -1",
545
549
  gridAutoColumns: "1fr",
546
550
  ...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, {
551
+ }, t = this, s = p(y((n = (i = this.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = p(y((a = (u = this.native) == null ? void 0 : u.slots) == null ? void 0 : a.Form) ?? {}, this.globalNativeFormOverride.slots);
552
+ return c(b.runtimeDoms.Form, F(s, {
549
553
  ref: this.formRef,
550
554
  model: this.model.value
551
555
  }), {
@@ -561,7 +565,7 @@ class ie {
561
565
  class b {
562
566
  }
563
567
  l(b, "runtimeDoms");
564
- const P = class P {
568
+ const v = class v {
565
569
  static getPlaceholderPrefixPresetByComponentName() {
566
570
  const e = {
567
571
  请选择: ["Select", "Tree", "TreeSelect"],
@@ -574,7 +578,7 @@ const P = class P {
574
578
  return t;
575
579
  }
576
580
  };
577
- l(P, "schemaPreset", {
581
+ l(v, "schemaPreset", {
578
582
  type: {
579
583
  defaultValue: "item"
580
584
  },
@@ -610,14 +614,14 @@ l(P, "schemaPreset", {
610
614
  },
611
615
  native: void 0,
612
616
  gridProps: void 0
613
- }), l(P, "componentPropsPreset", {
617
+ }), l(v, "componentPropsPreset", {
614
618
  options: {
615
619
  defaultValue: []
616
620
  }
617
621
  }), // 基于基本功能提出基本预设
618
- l(P, "placeholderPresetByComponentName", P.getPlaceholderPrefixPresetByComponentName());
619
- let S = P;
620
- const le = /* @__PURE__ */ ee({
622
+ l(v, "placeholderPresetByComponentName", v.getPlaceholderPrefixPresetByComponentName());
623
+ let I = v;
624
+ const ce = /* @__PURE__ */ ie({
621
625
  props: {
622
626
  setup: {
623
627
  type: Function,
@@ -625,37 +629,36 @@ const le = /* @__PURE__ */ ee({
625
629
  }
626
630
  },
627
631
  setup(o) {
628
- const e = new ie(o.setup);
632
+ const e = new fe(o.setup);
629
633
  return () => e.exec();
630
634
  }
631
635
  });
632
- function ae(o) {
633
- const e = new te(o);
636
+ function de(o) {
637
+ const e = new oe(o);
634
638
  return [
635
639
  e.setup.bind(e),
636
640
  {
637
641
  submit: e.submit.bind(e),
638
- hydrate: e.hydrate.bind(e),
639
- customize: e.customize.bind(e)
642
+ hydrate: e.hydrate.bind(e)
640
643
  }
641
644
  ];
642
645
  }
643
- function fe(o) {
646
+ function pe(o) {
644
647
  return {
645
648
  install() {
646
649
  b.runtimeDoms = o;
647
650
  }
648
651
  };
649
652
  }
650
- function ue(o, e) {
653
+ function me(o, e) {
651
654
  return e === "raw" && Object.defineProperty(o, "name", {
652
655
  value: `__proform_raw_${o.name}`,
653
656
  writable: !0
654
657
  }), o;
655
658
  }
656
659
  export {
657
- le as ProForm,
658
- ae as useForm,
659
- fe as useFormRenderer,
660
- ue as useModifiers
660
+ ce as ProForm,
661
+ de as useForm,
662
+ pe as useFormRenderer,
663
+ me as useModifiers
661
664
  };
@@ -1,4 +1,4 @@
1
- import { AnyObject, CustomizationOptions, FormCustomization } from "../types";
1
+ import { AnyObject, FormCustomization } from "../types";
2
2
  import { RuntimeCore } from "./index";
3
3
  export default class FormCustomizer {
4
4
  formCustomization: FormCustomization;
@@ -8,5 +8,4 @@ export default class FormCustomizer {
8
8
  setup(_runtimeCore: RuntimeCore): FormCustomization;
9
9
  submit(): Promise<AnyObject>;
10
10
  hydrate(data: AnyObject): Promise<never> | undefined;
11
- customize(options: Partial<CustomizationOptions>): void;
12
11
  }
@@ -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, RuntimeSetters, NativeCustomizationOptions } from "../types";
3
3
  import Processor from "./Processor";
4
4
  import Effect from "./Effect";
5
5
  export default class RuntimeCore {
@@ -10,8 +10,9 @@ export default class RuntimeCore {
10
10
  processorBySchemaType: ProcessorBySchemaType;
11
11
  formRef: Ref<AnyObject>;
12
12
  hydrateEffect: Effect;
13
- customizedOptions: CustomizationOptions;
13
+ native: NativeCustomizationOptions;
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 = {
@@ -102,7 +108,4 @@ export type NativeCustomizationOptions = {
102
108
  FormItem?: AnyObject;
103
109
  };
104
110
  };
105
- export type CustomizationOptions = {
106
- native?: NativeCustomizationOptions;
107
- };
108
111
  export {};
@@ -1,4 +1,4 @@
1
- import { AnyObject, CustomizationOptions } from "../types";
1
+ import { AnyObject } from "../types";
2
2
  import type { RuntimeCore } from "../services";
3
3
  export type Setup = (runtimeCore: RuntimeCore) => any;
4
4
  export type UseForm = [
@@ -6,6 +6,5 @@ export type UseForm = [
6
6
  {
7
7
  submit: () => Promise<AnyObject>;
8
8
  hydrate: (data: AnyObject) => any;
9
- customize: (options: CustomizationOptions) => any;
10
9
  }
11
10
  ];
@@ -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.1.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",