@harbor-design/proform 1.0.20 → 1.1.1
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 +1 -1
- package/dist/index.js +90 -95
- package/dist/types/src/services/FormCustomizer.d.ts +1 -2
- package/dist/types/src/services/RuntimeCore.d.ts +2 -2
- package/dist/types/src/types/formCustomizerTypes.d.ts +0 -3
- package/dist/types/src/types/useFormTypes.d.ts +1 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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)&&!c.isObjectEmpty(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,8 +1,8 @@
|
|
|
1
1
|
var Z = Object.defineProperty;
|
|
2
2
|
var ee = (o, e, t) => e in o ? Z(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
3
|
var l = (o, e, t) => (ee(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { toRaw as
|
|
5
|
-
class
|
|
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
|
+
class f {
|
|
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,
|
|
89
|
-
i.set(t(n), t(
|
|
88
|
+
for (let [n, u] of s)
|
|
89
|
+
i.set(t(n), t(u));
|
|
90
90
|
return i;
|
|
91
91
|
}
|
|
92
92
|
if (s instanceof Set) {
|
|
@@ -127,7 +127,7 @@ class oe {
|
|
|
127
127
|
})), e;
|
|
128
128
|
}
|
|
129
129
|
setup(e) {
|
|
130
|
-
return this.runtimeCore = e, Object.assign(
|
|
130
|
+
return this.runtimeCore = e, Object.assign(this.runtimeCore.native, this.formCustomization.native), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps), Object.assign(
|
|
131
131
|
this.runtimeCore.runtimeSetters,
|
|
132
132
|
this.formCustomization.runtimeSetters
|
|
133
133
|
), this.formCustomization;
|
|
@@ -136,7 +136,7 @@ class oe {
|
|
|
136
136
|
return new Promise((e, t) => {
|
|
137
137
|
this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
|
|
138
138
|
this.cleanFallbackFields(
|
|
139
|
-
|
|
139
|
+
O(this.runtimeCore.processor.processedModel.value)
|
|
140
140
|
)
|
|
141
141
|
));
|
|
142
142
|
});
|
|
@@ -174,12 +174,8 @@ class oe {
|
|
|
174
174
|
}
|
|
175
175
|
);
|
|
176
176
|
}
|
|
177
|
-
// TODO:目前仅用于配制一些基本的如 Form,FormItem 等 UI 库组件的默认属性,但后续会扩展其价值,包括设置统一布局等,都会考虑往内部封装
|
|
178
|
-
customize(e) {
|
|
179
|
-
Object.assign(this.runtimeCore.customizedOptions, e), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps);
|
|
180
|
-
}
|
|
181
177
|
}
|
|
182
|
-
class
|
|
178
|
+
class M {
|
|
183
179
|
constructor() {
|
|
184
180
|
l(this, "effects", /* @__PURE__ */ new Set());
|
|
185
181
|
}
|
|
@@ -207,8 +203,8 @@ class ne {
|
|
|
207
203
|
l(this, "componentPropsPreset", I.componentPropsPreset);
|
|
208
204
|
l(this, "stableUpdaterProcessProgress");
|
|
209
205
|
l(this, "stableUpdaterTimes", 0);
|
|
210
|
-
l(this, "schemaEffect", new
|
|
211
|
-
l(this, "defaultValueEffect", new
|
|
206
|
+
l(this, "schemaEffect", new M());
|
|
207
|
+
l(this, "defaultValueEffect", new M());
|
|
212
208
|
l(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
|
|
213
209
|
l(this, "baseDefaultValueFunctionsLength");
|
|
214
210
|
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), E(
|
|
@@ -247,13 +243,13 @@ class ne {
|
|
|
247
243
|
}
|
|
248
244
|
// 派生过程,用于外部应用
|
|
249
245
|
parseSchemas(e, t) {
|
|
250
|
-
|
|
246
|
+
f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
|
|
251
247
|
y(e)
|
|
252
248
|
), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
|
|
253
249
|
}
|
|
254
250
|
parseStable(e) {
|
|
255
251
|
const t = {};
|
|
256
|
-
if (!
|
|
252
|
+
if (!f.isUndefined(e.stable))
|
|
257
253
|
t[e.key] = this.parseStable(e.stable);
|
|
258
254
|
else
|
|
259
255
|
return e;
|
|
@@ -262,8 +258,8 @@ class ne {
|
|
|
262
258
|
// 对于稳定初始化更新的抽象
|
|
263
259
|
stableUpdater(e = []) {
|
|
264
260
|
if (e.every(Boolean)) {
|
|
265
|
-
const t =
|
|
266
|
-
!
|
|
261
|
+
const t = O(this.processedSchemas.value);
|
|
262
|
+
!f.isProcessInprogress(t) && f.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
|
|
267
263
|
length: t.length
|
|
268
264
|
}).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
|
|
269
265
|
}
|
|
@@ -271,21 +267,21 @@ class ne {
|
|
|
271
267
|
// 核心单 schema 处理过程,接收一个对象键值对的数据结构
|
|
272
268
|
parseItem(e, t, s) {
|
|
273
269
|
const r = this, i = Array.from({
|
|
274
|
-
length: Object.keys(e).filter((
|
|
270
|
+
length: Object.keys(e).filter((u) => u !== "children").length
|
|
275
271
|
}).fill(!1);
|
|
276
272
|
this.objectParser({ data: e, index: t, updater: n });
|
|
277
|
-
function n(
|
|
278
|
-
const
|
|
279
|
-
if (!
|
|
273
|
+
function n(u) {
|
|
274
|
+
const a = u.index, d = u.key, C = u.keyIndex;
|
|
275
|
+
if (!u.stable)
|
|
280
276
|
return;
|
|
281
|
-
const w = r.parseStable(
|
|
277
|
+
const w = r.parseStable(u.stable), S = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
|
|
282
278
|
let h = w;
|
|
283
|
-
if (
|
|
284
|
-
let m = r.processedSchemas.value[S][g][
|
|
285
|
-
m &&
|
|
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);
|
|
286
282
|
} else {
|
|
287
|
-
let m = r.processedSchemas.value[
|
|
288
|
-
m &&
|
|
283
|
+
let m = r.processedSchemas.value[a][d];
|
|
284
|
+
m && f.isObject(m) && (h = p(m, h)), r.processedSchemas.value[a][d] = h, r.stableUpdater(i);
|
|
289
285
|
}
|
|
290
286
|
}
|
|
291
287
|
}
|
|
@@ -300,36 +296,36 @@ class ne {
|
|
|
300
296
|
keyIndex: i
|
|
301
297
|
});
|
|
302
298
|
else {
|
|
303
|
-
const n = (
|
|
299
|
+
const n = (u) => {
|
|
304
300
|
e.updater({
|
|
305
301
|
...e,
|
|
306
302
|
key: r,
|
|
307
303
|
keyIndex: i,
|
|
308
|
-
stable:
|
|
304
|
+
stable: u
|
|
309
305
|
});
|
|
310
306
|
};
|
|
311
|
-
|
|
307
|
+
f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
312
308
|
if (r === "component") {
|
|
313
|
-
const
|
|
314
|
-
this.promiseFieldParser(
|
|
309
|
+
const u = t[r](this.getRuntimeMeta());
|
|
310
|
+
this.promiseFieldParser(u, n, !1);
|
|
315
311
|
} else
|
|
316
312
|
this.fieldParser(t[r], n);
|
|
317
313
|
}) : this.defaultValueEffect.trackEffect(() => {
|
|
318
|
-
const
|
|
319
|
-
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (
|
|
320
|
-
if (!
|
|
321
|
-
return n(
|
|
322
|
-
this.defaultValueInprogressMap.set(t[r],
|
|
314
|
+
const u = this.schemaEffect.trackEffect(() => {
|
|
315
|
+
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (a) => {
|
|
316
|
+
if (!a)
|
|
317
|
+
return n(a);
|
|
318
|
+
this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
323
319
|
(d) => !d.includes("undefined")
|
|
324
|
-
) ? (n(
|
|
325
|
-
|
|
326
|
-
})) : n(
|
|
327
|
-
}) : this.fieldParser(t[r], (
|
|
328
|
-
this.defaultValueInprogressMap.set(t[r],
|
|
320
|
+
) ? (n(a), this.defaultValueEffect.clearEffects(), K(() => {
|
|
321
|
+
u();
|
|
322
|
+
})) : n(a);
|
|
323
|
+
}) : this.fieldParser(t[r], (a) => {
|
|
324
|
+
this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
329
325
|
(d) => !d.includes("undefined")
|
|
330
|
-
) ? (n(
|
|
331
|
-
|
|
332
|
-
})) : n(
|
|
326
|
+
) ? (n(a), this.defaultValueEffect.clearEffects(), K(() => {
|
|
327
|
+
u();
|
|
328
|
+
})) : n(a);
|
|
333
329
|
});
|
|
334
330
|
});
|
|
335
331
|
}) : r === "component" || r === "slots" || r === "runtimeSetters" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
|
|
@@ -337,19 +333,19 @@ class ne {
|
|
|
337
333
|
});
|
|
338
334
|
}
|
|
339
335
|
promiseFieldParser(e, t, s) {
|
|
340
|
-
|
|
341
|
-
s &&
|
|
336
|
+
f.isPromise(e) ? e.then((r) => {
|
|
337
|
+
s && f.isObject(r) ? this.objectParser({
|
|
342
338
|
data: r,
|
|
343
339
|
updater: t
|
|
344
340
|
}) : t(r);
|
|
345
|
-
}) : (
|
|
341
|
+
}) : (f.isString(e) && (e = X(e, "")), s && f.isObject(e) ? this.objectParser({
|
|
346
342
|
data: e,
|
|
347
343
|
updater: t
|
|
348
344
|
}) : t(e));
|
|
349
345
|
}
|
|
350
346
|
// 对任意对象中单个字段的 parse: 做基本处理
|
|
351
347
|
fieldParser(e, t, s = !0) {
|
|
352
|
-
if (
|
|
348
|
+
if (f.isFunction(e))
|
|
353
349
|
if (e.name.startsWith("__proform_raw_"))
|
|
354
350
|
t(e);
|
|
355
351
|
else {
|
|
@@ -360,7 +356,7 @@ class ne {
|
|
|
360
356
|
J(e) ? E(
|
|
361
357
|
() => e.value,
|
|
362
358
|
() => {
|
|
363
|
-
|
|
359
|
+
f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
|
|
364
360
|
data: e.value,
|
|
365
361
|
updater: t
|
|
366
362
|
}) : t(e.value));
|
|
@@ -372,7 +368,7 @@ class ne {
|
|
|
372
368
|
) : Q(e) ? E(
|
|
373
369
|
() => e,
|
|
374
370
|
() => {
|
|
375
|
-
|
|
371
|
+
f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
|
|
376
372
|
data: e,
|
|
377
373
|
updater: t
|
|
378
374
|
}) : t(e));
|
|
@@ -381,7 +377,7 @@ class ne {
|
|
|
381
377
|
immediate: !0,
|
|
382
378
|
deep: !0
|
|
383
379
|
}
|
|
384
|
-
) : s &&
|
|
380
|
+
) : s && f.isObject(e) ? this.objectParser({
|
|
385
381
|
data: e,
|
|
386
382
|
updater: t
|
|
387
383
|
}) : t(e);
|
|
@@ -389,20 +385,20 @@ class ne {
|
|
|
389
385
|
modelProcessor(e) {
|
|
390
386
|
e.map(
|
|
391
387
|
(t) => this.createModel(t, this.processedModel.value)
|
|
392
|
-
),
|
|
388
|
+
), 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());
|
|
393
389
|
}
|
|
394
390
|
createModel(e, t) {
|
|
395
|
-
|
|
391
|
+
f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
|
|
396
392
|
this.createModel(s, t[e.field][0]);
|
|
397
|
-
})),
|
|
393
|
+
})), f.isGroupSchema(e) && e.children.forEach((s) => {
|
|
398
394
|
this.createModel(s, t);
|
|
399
|
-
}),
|
|
395
|
+
}), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
|
|
400
396
|
}
|
|
401
397
|
}
|
|
402
398
|
function le(o) {
|
|
403
399
|
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !re(o);
|
|
404
400
|
}
|
|
405
|
-
class
|
|
401
|
+
class fe {
|
|
406
402
|
constructor(e) {
|
|
407
403
|
l(this, "schemas", A([]));
|
|
408
404
|
l(this, "model", A({}));
|
|
@@ -412,8 +408,8 @@ class ue {
|
|
|
412
408
|
list: this.runtimeListProcessor.bind(this)
|
|
413
409
|
});
|
|
414
410
|
l(this, "formRef", A(null));
|
|
415
|
-
l(this, "hydrateEffect", new
|
|
416
|
-
l(this, "
|
|
411
|
+
l(this, "hydrateEffect", new M());
|
|
412
|
+
l(this, "native", te({}));
|
|
417
413
|
l(this, "gridProps", {});
|
|
418
414
|
l(this, "runtimeSetters", {});
|
|
419
415
|
l(this, "globalNativeFormOverride", {
|
|
@@ -426,20 +422,20 @@ class ue {
|
|
|
426
422
|
}
|
|
427
423
|
getRuntimeMeta() {
|
|
428
424
|
return {
|
|
429
|
-
model:
|
|
425
|
+
model: O(y(this.model.value))
|
|
430
426
|
};
|
|
431
427
|
}
|
|
432
428
|
runtimeItemProcessor(e, t, s = this.model.value, r) {
|
|
433
|
-
var
|
|
434
|
-
p(this.globalNativeFormOverride.props, (
|
|
435
|
-
const i = p(y((
|
|
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 = {
|
|
436
432
|
display: "grid",
|
|
437
433
|
gridColumn: "1 / -1",
|
|
438
434
|
...e.gridProps
|
|
439
|
-
},
|
|
435
|
+
}, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
|
|
440
436
|
if (!d)
|
|
441
437
|
return;
|
|
442
|
-
const
|
|
438
|
+
const C = d.name, w = e.componentProps ?? {}, S = I.placeholderPresetByComponentName;
|
|
443
439
|
let g = e.placeholder;
|
|
444
440
|
if (e.required)
|
|
445
441
|
if (!e.rules)
|
|
@@ -453,21 +449,21 @@ class ue {
|
|
|
453
449
|
}
|
|
454
450
|
let m = e.show;
|
|
455
451
|
m === void 0 && (m = !0), m || delete s[e.field];
|
|
456
|
-
let
|
|
452
|
+
let V = e.label;
|
|
457
453
|
const P = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
|
|
458
|
-
return !
|
|
459
|
-
S[
|
|
460
|
-
S[
|
|
461
|
-
style:
|
|
462
|
-
}, [
|
|
454
|
+
return !f.isUndefined(t) && !f.isObjectEmpty(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", {
|
|
457
|
+
style: u
|
|
458
|
+
}, [c(b.runtimeDoms.Item, null, {
|
|
463
459
|
default() {
|
|
464
|
-
return W(
|
|
465
|
-
label: `${
|
|
460
|
+
return W(c(b.runtimeDoms.FormItem, F(i, {
|
|
461
|
+
label: `${V}:`,
|
|
466
462
|
rules: e.rules,
|
|
467
|
-
field:
|
|
463
|
+
field: a
|
|
468
464
|
}), {
|
|
469
465
|
default() {
|
|
470
|
-
return
|
|
466
|
+
return c(d, F({
|
|
471
467
|
modelValue: s[e.field],
|
|
472
468
|
"onUpdate:modelValue": (j) => s[e.field] = j,
|
|
473
469
|
placeholder: g
|
|
@@ -485,9 +481,9 @@ class ue {
|
|
|
485
481
|
gridColumn: "1 / -1",
|
|
486
482
|
...e.gridProps
|
|
487
483
|
};
|
|
488
|
-
return
|
|
484
|
+
return c("div", {
|
|
489
485
|
style: s
|
|
490
|
-
}, [
|
|
486
|
+
}, [c(b.runtimeDoms.Group, {
|
|
491
487
|
schema: e
|
|
492
488
|
}, le(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
|
|
493
489
|
default: () => [t]
|
|
@@ -511,32 +507,32 @@ class ue {
|
|
|
511
507
|
gridColumn: "1 / -1",
|
|
512
508
|
...e.gridProps
|
|
513
509
|
}, s = this;
|
|
514
|
-
return s.model.value[e.field] || (s.model.value[e.field] = [{}]),
|
|
510
|
+
return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
|
|
515
511
|
style: t
|
|
516
|
-
}, [
|
|
512
|
+
}, [c(b.runtimeDoms.List, {
|
|
517
513
|
schema: e
|
|
518
514
|
}, {
|
|
519
515
|
default() {
|
|
520
|
-
return s.model.value[e.field].map((r, i) =>
|
|
516
|
+
return s.model.value[e.field].map((r, i) => c(b.runtimeDoms.ListItem, null, {
|
|
521
517
|
default() {
|
|
522
518
|
return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
|
|
523
519
|
},
|
|
524
520
|
delete({
|
|
525
521
|
container: n
|
|
526
522
|
} = {}) {
|
|
527
|
-
var
|
|
528
|
-
let
|
|
529
|
-
return W(
|
|
523
|
+
var a;
|
|
524
|
+
let u = n ?? c("button", null, null);
|
|
525
|
+
return W(c(u, {
|
|
530
526
|
onClick: () => s.deleteListItem(e, i)
|
|
531
|
-
}, null), [[H, ((
|
|
527
|
+
}, null), [[H, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
|
|
532
528
|
}
|
|
533
529
|
}));
|
|
534
530
|
},
|
|
535
531
|
add({
|
|
536
532
|
container: r
|
|
537
533
|
} = {}) {
|
|
538
|
-
let i = r ??
|
|
539
|
-
return
|
|
534
|
+
let i = r ?? c("button", null, [se("添加")]);
|
|
535
|
+
return c(i, {
|
|
540
536
|
onClick: () => s.addListItem(e)
|
|
541
537
|
}, null);
|
|
542
538
|
}
|
|
@@ -546,19 +542,19 @@ class ue {
|
|
|
546
542
|
return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
|
|
547
543
|
}
|
|
548
544
|
exec() {
|
|
549
|
-
var i, n,
|
|
545
|
+
var i, n, u, a;
|
|
550
546
|
const e = {
|
|
551
547
|
display: "grid",
|
|
552
548
|
gridColumn: "1 / -1",
|
|
553
549
|
gridAutoColumns: "1fr",
|
|
554
550
|
...this.gridProps
|
|
555
|
-
}, t = this, s = p(y((n = (i = this.
|
|
556
|
-
return
|
|
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, {
|
|
557
553
|
ref: this.formRef,
|
|
558
554
|
model: this.model.value
|
|
559
555
|
}), {
|
|
560
556
|
default() {
|
|
561
|
-
return
|
|
557
|
+
return c("div", {
|
|
562
558
|
style: e
|
|
563
559
|
}, [t.runtimeProcessor(t.schemas.value)]);
|
|
564
560
|
},
|
|
@@ -625,7 +621,7 @@ l(v, "schemaPreset", {
|
|
|
625
621
|
}), // 基于基本功能提出基本预设
|
|
626
622
|
l(v, "placeholderPresetByComponentName", v.getPlaceholderPrefixPresetByComponentName());
|
|
627
623
|
let I = v;
|
|
628
|
-
const
|
|
624
|
+
const ce = /* @__PURE__ */ ie({
|
|
629
625
|
props: {
|
|
630
626
|
setup: {
|
|
631
627
|
type: Function,
|
|
@@ -633,7 +629,7 @@ const ae = /* @__PURE__ */ ie({
|
|
|
633
629
|
}
|
|
634
630
|
},
|
|
635
631
|
setup(o) {
|
|
636
|
-
const e = new
|
|
632
|
+
const e = new fe(o.setup);
|
|
637
633
|
return () => e.exec();
|
|
638
634
|
}
|
|
639
635
|
});
|
|
@@ -643,8 +639,7 @@ function de(o) {
|
|
|
643
639
|
e.setup.bind(e),
|
|
644
640
|
{
|
|
645
641
|
submit: e.submit.bind(e),
|
|
646
|
-
hydrate: e.hydrate.bind(e)
|
|
647
|
-
customize: e.customize.bind(e)
|
|
642
|
+
hydrate: e.hydrate.bind(e)
|
|
648
643
|
}
|
|
649
644
|
];
|
|
650
645
|
}
|
|
@@ -662,7 +657,7 @@ function me(o, e) {
|
|
|
662
657
|
}), o;
|
|
663
658
|
}
|
|
664
659
|
export {
|
|
665
|
-
|
|
660
|
+
ce as ProForm,
|
|
666
661
|
de as useForm,
|
|
667
662
|
pe as useFormRenderer,
|
|
668
663
|
me as useModifiers
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject,
|
|
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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ref } from "vue";
|
|
2
|
-
import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType,
|
|
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,7 +10,7 @@ export default class RuntimeCore {
|
|
|
10
10
|
processorBySchemaType: ProcessorBySchemaType;
|
|
11
11
|
formRef: Ref<AnyObject>;
|
|
12
12
|
hydrateEffect: Effect;
|
|
13
|
-
|
|
13
|
+
native: NativeCustomizationOptions;
|
|
14
14
|
gridProps: {};
|
|
15
15
|
runtimeSetters: RuntimeSetters;
|
|
16
16
|
globalNativeFormOverride: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject
|
|
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
|
];
|