@harbor-design/proform 1.0.17 → 1.0.18
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 +197 -174
- package/dist/types/src/services/FormCustomizer.d.ts +3 -2
- package/dist/types/src/services/RuntimeCore.d.ts +6 -1
- package/dist/types/src/types/formCustomizerTypes.d.ts +14 -0
- package/dist/types/src/types/useFormTypes.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var I=Object.defineProperty;var O=(o,e,t)=>e in o?I(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var c=(o,e,t)=>(O(o,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");class f{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function S(o,...e){return e.forEach(t=>{for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?(o[s]=o[s]||{},S(o[s],t[s])):o[s]=t[s])}),o}function E(o){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const i=new Map;for(let[l,a]of s)i.set(t(l),t(a));return i}if(s instanceof Set){const i=new Set;for(let l of s)i.add(t(l));return i}if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=[];e.set(s,i);for(let l=0;l<s.length;l++)i[l]=t(s[l]);return i}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let i in s)s.hasOwnProperty(i)&&(r[i]=t(s[i]));return r}return t(o)}class C{constructor(e){c(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(n.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){this.runtimeCore.hydrateEffect.trackEffect(()=>{n.isRef(e)?n.watch(()=>e.value,()=>{S(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):n.isReactive(e)?n.watch(()=>e,()=>{S(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):S(this.runtimeCore.model.value,e)},{lazy:!0})}}class j{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 R{constructor(e){c(this,"runtimeCore");c(this,"processedSchemas");c(this,"processedModel");c(this,"getRuntimeMeta");c(this,"stableSchemas",[]);c(this,"stableModel",{});c(this,"schemaPreset",V.schemaPreset);c(this,"componentPropsPreset",V.componentPropsPreset);c(this,"stableUpdaterProcessProgress");c(this,"stableUpdaterTimes",0);c(this,"schemaEffect",new j);c(this,"defaultValueEffect",new j);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),n.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(i){if(!s.has(i)&&(Array.isArray(i)||i!==null&&typeof i=="object")){s.add(i);for(let l in i)i.hasOwnProperty(l)&&(l==="defaultValue"&&typeof i[l]=="function"&&!i[l].toString().includes("[native code]")&&t++,r(i[l]))}}return r(e),t}parseSchemas(e,t){f.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(E(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!f.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=n.toRaw(this.processedSchemas.value);!f.isProcessInprogress(t)&&f.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,i=Array.from({length:Object.keys(e).filter(a=>a!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(a){const u=a.index,h=a.key,P=a.keyIndex;if(!a.stable)return;const v=r.parseStable(a.stable),y=s==null?void 0:s.index,g=s==null?void 0:s.key;let d=v;if(f.isProcessInprogress(d)||(i[P]=!0),s){let p=r.processedSchemas.value[y][g][u][h];p&&f.isObject(p)&&h!=="component"&&(d=Object.assign(p,d)),r.processedSchemas.value[y][g][u][h]=d,r.stableUpdater(i)}else{let p=r.processedSchemas.value[u][h];p&&f.isObject(p)&&(d=Object.assign(p,d)),r.processedSchemas.value[u][h]=d,r.stableUpdater(i)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,i)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:i});else{const l=a=>{e.updater({...e,key:r,keyIndex:i,stable:a})};if(f.isFunction(t[r]))r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const a=t[r](this.getRuntimeMeta());this.promiseFieldParser(a,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const a=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],u=>{if(!u)return l(u);this.defaultValueInprogressMap.set(t[r],u),!f.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(h=>!h.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),n.nextTick(()=>{a()})):l(u)}):this.fieldParser(t[r],u=>{this.defaultValueInprogressMap.set(t[r],u),!f.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(h=>!h.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),n.nextTick(()=>{a()})):l(u)})})});else if(r==="component"){const a=t[r];this.promiseFieldParser(a,l,!1)}else this.fieldParser(t[r],l)}})}replaceUndefinedInString(e,t){return e.replace(/undefined/g,t)}promiseFieldParser(e,t,s){f.isPromise(e)?e.then(r=>{s&&f.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(f.isString(e)&&(e=this.replaceUndefinedInString(e,"")),s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(f.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else n.isRef(e)?n.watch(()=>e.value,()=>{f.isUndefined(e.value)||(s&&f.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):n.isReactive(e)?n.watch(()=>e,()=>{f.isUndefined(e)||(s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),f.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=E(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){f.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),f.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),f.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function w(o){return typeof o=="function"||Object.prototype.toString.call(o)==="[object Object]"&&!n.isVNode(o)}class M{constructor(e){c(this,"schemas",n.ref([]));c(this,"model",n.ref({}));c(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});c(this,"formRef",n.ref(null));c(this,"hydrateEffect",new j);this.setup=e,this.processor=new R(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:n.toRaw(E(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var g;const i=r?`${r.field}.${t}.${e.field}`:e.field,l=n.toRaw(e.component);if(!l)return;const a=l.name,u=e.componentProps??{},h=V.placeholderPresetByComponentName;let P=e.placeholder;if(P||(P=`${h[a]??"请输入"}${e.label}`),e.required)if(!e.rules)e.rules=[],(g=e.rules)==null||g.push({required:!0,message:`${e.label}是必填项`});else{const d=e.rules.findIndex(p=>!!p.required);e.rules[d].message=`${e.label}是必填项`}let y=e.show;return y===void 0&&(y=!0),y||delete s[e.field],n.createVNode(m.runtimeDoms.Item,null,{default(){return n.withDirectives(n.createVNode(m.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:i},{default:()=>[n.createVNode(l,n.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":d=>s[e.field]=d,placeholder:P},u),null)]}),[[n.vShow,y]])}})}runtimeGroupProcessor(e){let t;return n.createVNode(m.runtimeDoms.Group,{schema:e},w(t=e.children.map(s=>this.runtimeItemProcessor(s)))?t:{default:()=>[t]})}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(E(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),n.createVNode(m.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>n.createVNode(m.runtimeDoms.ListItem,null,{default(){return e.children.map(i=>t.runtimeItemProcessor(i,r,s,e))},delete({container:i}={}){var a;let l=i??n.createVNode("button",null,null);return n.withDirectives(n.createVNode(l,{onClick:()=>t.deleteListItem(e,r)},null),[[n.vShow,((a=t.model.value[e.field])==null?void 0:a.length)>1]])}}))},add({container:s}={}){let r=s??n.createVNode("button",null,[n.createTextVNode("添加")]);return n.createVNode(r,{onClick:()=>t.addListItem(e)},null)}})}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){let e;return n.createVNode(m.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},w(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class m{}c(m,"runtimeDoms");const b=class b{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};c(b,"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:[]}}),c(b,"componentPropsPreset",{options:{defaultValue:[]}}),c(b,"placeholderPresetByComponentName",b.getPlaceholderPrefixPresetByComponentName());let V=b;const x=n.defineComponent({props:{setup:{type:Function,required:!0}},setup(o){const e=new M(o.setup);return()=>e.exec()}});function A(o){const e=new C(o);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function D(o){return{install(){m.runtimeDoms=o}}}function N(o,e){return e==="raw"&&Object.defineProperty(o,"name",{value:`__proform_raw_${o.name}`,writable:!0}),o}exports.ProForm=x;exports.useForm=A;exports.useFormRenderer=D;exports.useModifiers=N;
|
|
1
|
+
"use strict";var _=Object.defineProperty;var L=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>(L(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue");class f{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function d(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=d(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=d(n[s]||{},t[s]):n[s]=t[s])}),n}function y(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const i=new Map;for(let[l,a]of s)i.set(t(l),t(a));return i}if(s instanceof Set){const i=new Set;for(let l of s)i.add(t(l));return i}if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=[];e.set(s,i);for(let l=0;l<s.length;l++)i[l]=t(s[l]);return i}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let i in s)s.hasOwnProperty(i)&&(r[i]=t(s[i]));return r}return t(n)}class T{constructor(e){c(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(o.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{o.isRef(e)?o.watch(()=>e.value,()=>{d(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):o.isReactive(e)?o.watch(()=>e,()=>{d(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):d(this.runtimeCore.model.value,e)},{lazy:!0})}customize(e){Object.assign(this.runtimeCore.customizedOptions,e)}}class I{constructor(){c(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e,t={lazy:!1}){return!t.lazy&&e(),this.effects.add(e),()=>this.effects.delete(e)}}class B{constructor(e){c(this,"runtimeCore");c(this,"processedSchemas");c(this,"processedModel");c(this,"getRuntimeMeta");c(this,"stableSchemas",[]);c(this,"stableModel",{});c(this,"schemaPreset",v.schemaPreset);c(this,"componentPropsPreset",v.componentPropsPreset);c(this,"stableUpdaterProcessProgress");c(this,"stableUpdaterTimes",0);c(this,"schemaEffect",new I);c(this,"defaultValueEffect",new I);c(this,"defaultValueInprogressMap",new Map);c(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),o.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(i){if(!s.has(i)&&(Array.isArray(i)||i!==null&&typeof i=="object")){s.add(i);for(let l in i)i.hasOwnProperty(l)&&(l==="defaultValue"&&typeof i[l]=="function"&&!i[l].toString().includes("[native code]")&&t++,r(i[l]))}}return r(e),t}parseSchemas(e,t){f.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(y(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!f.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=o.toRaw(this.processedSchemas.value);!f.isProcessInprogress(t)&&f.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,i=Array.from({length:Object.keys(e).filter(a=>a!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(a){const u=a.index,m=a.key,S=a.keyIndex;if(!a.stable)return;const E=r.parseStable(a.stable),P=s==null?void 0:s.index,j=s==null?void 0:s.key;let p=E;if(f.isProcessInprogress(p)||(i[S]=!0),s){let h=r.processedSchemas.value[P][j][u][m];h&&f.isObject(h)&&m!=="component"&&(p=d(h,p)),r.processedSchemas.value[P][j][u][m]=p,r.stableUpdater(i)}else{let h=r.processedSchemas.value[u][m];h&&f.isObject(h)&&(p=d(h,p)),r.processedSchemas.value[u][m]=p,r.stableUpdater(i)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,i)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:i});else{const l=a=>{e.updater({...e,key:r,keyIndex:i,stable:a})};f.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const a=t[r](this.getRuntimeMeta());this.promiseFieldParser(a,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const a=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],u=>{if(!u)return l(u);this.defaultValueInprogressMap.set(t[r],u),!f.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(m=>!m.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),o.nextTick(()=>{a()})):l(u)}):this.fieldParser(t[r],u=>{this.defaultValueInprogressMap.set(t[r],u),!f.isProcessInprogress(u)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(m=>!m.includes("undefined"))?(l(u),this.defaultValueEffect.clearEffects(),o.nextTick(()=>{a()})):l(u)})})}):r==="component"||r==="slots"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}replaceUndefinedInString(e,t){return e.replace(/undefined/g,t)}promiseFieldParser(e,t,s){f.isPromise(e)?e.then(r=>{s&&f.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(f.isString(e)&&(e=this.replaceUndefinedInString(e,"")),s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(f.isFunction(e))if(e.name.startsWith("__proform_raw_"))t(e);else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else o.isRef(e)?o.watch(()=>e.value,()=>{f.isUndefined(e.value)||(s&&f.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):o.isReactive(e)?o.watch(()=>e,()=>{f.isUndefined(e)||(s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&f.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),f.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=y(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){f.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),f.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),f.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function q(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!o.isVNode(n)}class ${constructor(e){c(this,"schemas",o.ref([]));c(this,"model",o.ref({}));c(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});c(this,"formRef",o.ref(null));c(this,"hydrateEffect",new I);c(this,"customizedOptions",o.reactive({}));c(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new B(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:o.toRaw(y(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var h,w,O,C,N,A,F,M,R,z,x,D,U;d(this.globalNativeFormOverride.props,(w=(h=e.native)==null?void 0:h.props)==null?void 0:w.Form),d(this.globalNativeFormOverride.slots,(C=(O=e.native)==null?void 0:O.slots)==null?void 0:C.Form);const i=d(y((A=(N=this.customizedOptions.native)==null?void 0:N.props)==null?void 0:A.FormItem)??{},(M=(F=e.native)==null?void 0:F.props)==null?void 0:M.FormItem),l=d(y((z=(R=this.customizedOptions.native)==null?void 0:R.slots)==null?void 0:z.FormItem)??{},(D=(x=e.native)==null?void 0:x.slots)==null?void 0:D.FormItem),a=r?`${r.field}.${t}.${e.field}`:e.field,u=o.toRaw(e.component);if(!u)return;const m=u.name,S=e.componentProps??{},E=v.placeholderPresetByComponentName;let P=e.placeholder;if(P||(P=`${E[m]??"请输入"}${e.label}`),e.required)if(!e.rules)e.rules=[],(U=e.rules)==null||U.push({required:!0,message:`${e.label}是必填项`});else{const V=e.rules.findIndex(k=>!!k.required);e.rules[V].message=`${e.label}是必填项`}let p=e.show;return p===void 0&&(p=!0),p||delete s[e.field],o.createVNode(b.runtimeDoms.Item,null,{default(){return o.withDirectives(o.createVNode(b.runtimeDoms.FormItem,o.mergeProps(i,{label:`${e.label}:`,rules:e.rules,field:a}),{default(){return o.createVNode(u,o.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":V=>s[e.field]=V,placeholder:P},S),null)},...l}),[[o.vShow,p]])}})}runtimeGroupProcessor(e){let t;return o.createVNode(b.runtimeDoms.Group,{schema:e},q(t=e.children.map(s=>this.runtimeItemProcessor(s)))?t:{default:()=>[t]})}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(y(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),o.createVNode(b.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>o.createVNode(b.runtimeDoms.ListItem,null,{default(){return e.children.map(i=>t.runtimeItemProcessor(i,r,s,e))},delete({container:i}={}){var a;let l=i??o.createVNode("button",null,null);return o.withDirectives(o.createVNode(l,{onClick:()=>t.deleteListItem(e,r)},null),[[o.vShow,((a=t.model.value[e.field])==null?void 0:a.length)>1]])}}))},add({container:s}={}){let r=s??o.createVNode("button",null,[o.createTextVNode("添加")]);return o.createVNode(r,{onClick:()=>t.addListItem(e)},null)}})}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var r,i,l,a;const e=this,t=d(y((i=(r=this.customizedOptions.native)==null?void 0:r.props)==null?void 0:i.Form)??{},this.globalNativeFormOverride.props),s=d(y((a=(l=this.customizedOptions.native)==null?void 0:l.slots)==null?void 0:a.Form)??{},this.globalNativeFormOverride.slots);return o.createVNode(b.runtimeDoms.Form,o.mergeProps(t,{ref:this.formRef,model:this.model.value}),{default(){return e.runtimeProcessor(e.schemas.value)},...s})}}class b{}c(b,"runtimeDoms");const g=class g{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};c(g,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0}),c(g,"componentPropsPreset",{options:{defaultValue:[]}}),c(g,"placeholderPresetByComponentName",g.getPlaceholderPrefixPresetByComponentName());let v=g;const G=o.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new $(n.setup);return()=>e.exec()}});function K(n){const e=new T(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e),customize:e.customize.bind(e)}]}function W(n){return{install(){b.runtimeDoms=n}}}function H(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=G;exports.useForm=K;exports.useFormRenderer=W;exports.useModifiers=H;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { toRaw as
|
|
5
|
-
class
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var J = (o, e, t) => e in o ? H(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var l = (o, e, t) => (J(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { toRaw as j, isRef as G, watch as v, isReactive as K, nextTick as T, ref as w, reactive as Q, createVNode as m, withDirectives as $, mergeProps as C, vShow as q, createTextVNode as X, isVNode as Y, defineComponent as Z } from "vue";
|
|
5
|
+
class a {
|
|
6
6
|
static typeChecker(e) {
|
|
7
7
|
return {}.toString.call(e);
|
|
8
8
|
}
|
|
@@ -63,13 +63,18 @@ class c {
|
|
|
63
63
|
return !1;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function u(o, ...e) {
|
|
67
67
|
return e.forEach((t) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
if (Array.isArray(t))
|
|
69
|
+
Array.isArray(o) || (o = []), t.forEach((s, r) => {
|
|
70
|
+
typeof s == "object" && s !== null ? o[r] = u(Array.isArray(s) ? [] : {}, s) : o[r] = s;
|
|
71
|
+
});
|
|
72
|
+
else
|
|
73
|
+
for (let s in t)
|
|
74
|
+
t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? o[s] = u(o[s] || {}, t[s]) : o[s] = t[s]);
|
|
75
|
+
}), o;
|
|
71
76
|
}
|
|
72
|
-
function
|
|
77
|
+
function y(o) {
|
|
73
78
|
const e = /* @__PURE__ */ new WeakMap();
|
|
74
79
|
function t(s) {
|
|
75
80
|
if (s === null || typeof s != "object")
|
|
@@ -80,14 +85,14 @@ function v(n) {
|
|
|
80
85
|
return new RegExp(s);
|
|
81
86
|
if (s instanceof Map) {
|
|
82
87
|
const i = /* @__PURE__ */ new Map();
|
|
83
|
-
for (let [
|
|
84
|
-
i.set(t(
|
|
88
|
+
for (let [n, c] of s)
|
|
89
|
+
i.set(t(n), t(c));
|
|
85
90
|
return i;
|
|
86
91
|
}
|
|
87
92
|
if (s instanceof Set) {
|
|
88
93
|
const i = /* @__PURE__ */ new Set();
|
|
89
|
-
for (let
|
|
90
|
-
i.add(t(
|
|
94
|
+
for (let n of s)
|
|
95
|
+
i.add(t(n));
|
|
91
96
|
return i;
|
|
92
97
|
}
|
|
93
98
|
if (e.has(s))
|
|
@@ -95,8 +100,8 @@ function v(n) {
|
|
|
95
100
|
if (Array.isArray(s)) {
|
|
96
101
|
const i = [];
|
|
97
102
|
e.set(s, i);
|
|
98
|
-
for (let
|
|
99
|
-
i[
|
|
103
|
+
for (let n = 0; n < s.length; n++)
|
|
104
|
+
i[n] = t(s[n]);
|
|
100
105
|
return i;
|
|
101
106
|
}
|
|
102
107
|
const r = Object.create(Object.getPrototypeOf(s));
|
|
@@ -105,11 +110,11 @@ function v(n) {
|
|
|
105
110
|
s.hasOwnProperty(i) && (r[i] = t(s[i]));
|
|
106
111
|
return r;
|
|
107
112
|
}
|
|
108
|
-
return t(
|
|
113
|
+
return t(o);
|
|
109
114
|
}
|
|
110
|
-
class
|
|
115
|
+
class ee {
|
|
111
116
|
constructor(e) {
|
|
112
|
-
|
|
117
|
+
l(this, "runtimeCore");
|
|
113
118
|
this.formCustomization = e;
|
|
114
119
|
}
|
|
115
120
|
// happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
|
|
@@ -125,43 +130,52 @@ class T {
|
|
|
125
130
|
return new Promise((e, t) => {
|
|
126
131
|
this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
|
|
127
132
|
this.cleanFallbackFields(
|
|
128
|
-
|
|
133
|
+
j(this.runtimeCore.processor.processedModel.value)
|
|
129
134
|
)
|
|
130
135
|
));
|
|
131
136
|
});
|
|
132
137
|
}
|
|
133
138
|
hydrate(e) {
|
|
139
|
+
if (!this.runtimeCore)
|
|
140
|
+
return Promise.reject({
|
|
141
|
+
code: "0002",
|
|
142
|
+
message: "hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"
|
|
143
|
+
});
|
|
134
144
|
this.runtimeCore.hydrateEffect.trackEffect(
|
|
135
145
|
() => {
|
|
136
|
-
|
|
146
|
+
G(e) ? v(
|
|
137
147
|
() => e.value,
|
|
138
148
|
() => {
|
|
139
|
-
|
|
149
|
+
u(this.runtimeCore.model.value, e.value);
|
|
140
150
|
},
|
|
141
151
|
{
|
|
142
152
|
deep: !0,
|
|
143
153
|
immediate: !0
|
|
144
154
|
}
|
|
145
|
-
) :
|
|
155
|
+
) : K(e) ? v(
|
|
146
156
|
() => e,
|
|
147
157
|
() => {
|
|
148
|
-
|
|
158
|
+
u(this.runtimeCore.model.value, e);
|
|
149
159
|
},
|
|
150
160
|
{
|
|
151
161
|
deep: !0,
|
|
152
162
|
immediate: !0
|
|
153
163
|
}
|
|
154
|
-
) :
|
|
164
|
+
) : u(this.runtimeCore.model.value, e);
|
|
155
165
|
},
|
|
156
166
|
{
|
|
157
167
|
lazy: !0
|
|
158
168
|
}
|
|
159
169
|
);
|
|
160
170
|
}
|
|
171
|
+
// TODO:目前仅用于配制一些基本的如 Form,FormItem 等 UI 库组件的默认属性,但后续会扩展其价值,包括设置统一布局等,都会考虑往内部封装
|
|
172
|
+
customize(e) {
|
|
173
|
+
Object.assign(this.runtimeCore.customizedOptions, e);
|
|
174
|
+
}
|
|
161
175
|
}
|
|
162
|
-
class
|
|
176
|
+
class A {
|
|
163
177
|
constructor() {
|
|
164
|
-
|
|
178
|
+
l(this, "effects", /* @__PURE__ */ new Set());
|
|
165
179
|
}
|
|
166
180
|
clearEffects() {
|
|
167
181
|
this.effects.clear();
|
|
@@ -175,23 +189,23 @@ class w {
|
|
|
175
189
|
return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
|
-
class
|
|
192
|
+
class te {
|
|
179
193
|
constructor(e) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e),
|
|
194
|
+
l(this, "runtimeCore");
|
|
195
|
+
l(this, "processedSchemas");
|
|
196
|
+
l(this, "processedModel");
|
|
197
|
+
l(this, "getRuntimeMeta");
|
|
198
|
+
l(this, "stableSchemas", []);
|
|
199
|
+
l(this, "stableModel", {});
|
|
200
|
+
l(this, "schemaPreset", S.schemaPreset);
|
|
201
|
+
l(this, "componentPropsPreset", S.componentPropsPreset);
|
|
202
|
+
l(this, "stableUpdaterProcessProgress");
|
|
203
|
+
l(this, "stableUpdaterTimes", 0);
|
|
204
|
+
l(this, "schemaEffect", new A());
|
|
205
|
+
l(this, "defaultValueEffect", new A());
|
|
206
|
+
l(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
|
|
207
|
+
l(this, "baseDefaultValueFunctionsLength");
|
|
208
|
+
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), v(
|
|
195
209
|
() => this.processedModel.value,
|
|
196
210
|
() => {
|
|
197
211
|
this.schemaEffect.triggerEffects();
|
|
@@ -219,21 +233,21 @@ class N {
|
|
|
219
233
|
function r(i) {
|
|
220
234
|
if (!s.has(i) && (Array.isArray(i) || i !== null && typeof i == "object")) {
|
|
221
235
|
s.add(i);
|
|
222
|
-
for (let
|
|
223
|
-
i.hasOwnProperty(
|
|
236
|
+
for (let n in i)
|
|
237
|
+
i.hasOwnProperty(n) && (n === "defaultValue" && typeof i[n] == "function" && !i[n].toString().includes("[native code]") && t++, r(i[n]));
|
|
224
238
|
}
|
|
225
239
|
}
|
|
226
240
|
return r(e), t;
|
|
227
241
|
}
|
|
228
242
|
// 派生过程,用于外部应用
|
|
229
243
|
parseSchemas(e, t) {
|
|
230
|
-
|
|
231
|
-
|
|
244
|
+
a.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
|
|
245
|
+
y(e)
|
|
232
246
|
), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
|
|
233
247
|
}
|
|
234
248
|
parseStable(e) {
|
|
235
249
|
const t = {};
|
|
236
|
-
if (!
|
|
250
|
+
if (!a.isUndefined(e.stable))
|
|
237
251
|
t[e.key] = this.parseStable(e.stable);
|
|
238
252
|
else
|
|
239
253
|
return e;
|
|
@@ -242,8 +256,8 @@ class N {
|
|
|
242
256
|
// 对于稳定初始化更新的抽象
|
|
243
257
|
stableUpdater(e = []) {
|
|
244
258
|
if (e.every(Boolean)) {
|
|
245
|
-
const t =
|
|
246
|
-
!
|
|
259
|
+
const t = j(this.processedSchemas.value);
|
|
260
|
+
!a.isProcessInprogress(t) && a.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
|
|
247
261
|
length: t.length
|
|
248
262
|
}).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
|
|
249
263
|
}
|
|
@@ -251,21 +265,21 @@ class N {
|
|
|
251
265
|
// 核心单 schema 处理过程,接收一个对象键值对的数据结构
|
|
252
266
|
parseItem(e, t, s) {
|
|
253
267
|
const r = this, i = Array.from({
|
|
254
|
-
length: Object.keys(e).filter((
|
|
268
|
+
length: Object.keys(e).filter((c) => c !== "children").length
|
|
255
269
|
}).fill(!1);
|
|
256
|
-
this.objectParser({ data: e, index: t, updater:
|
|
257
|
-
function
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
270
|
+
this.objectParser({ data: e, index: t, updater: n });
|
|
271
|
+
function n(c) {
|
|
272
|
+
const f = c.index, p = c.key, I = c.keyIndex;
|
|
273
|
+
if (!c.stable)
|
|
260
274
|
return;
|
|
261
|
-
const
|
|
262
|
-
let
|
|
263
|
-
if (
|
|
264
|
-
let
|
|
265
|
-
|
|
275
|
+
const V = r.parseStable(c.stable), P = s == null ? void 0 : s.index, O = s == null ? void 0 : s.key;
|
|
276
|
+
let d = V;
|
|
277
|
+
if (a.isProcessInprogress(d) || (i[I] = !0), s) {
|
|
278
|
+
let h = r.processedSchemas.value[P][O][f][p];
|
|
279
|
+
h && a.isObject(h) && p !== "component" && (d = u(h, d)), r.processedSchemas.value[P][O][f][p] = d, r.stableUpdater(i);
|
|
266
280
|
} else {
|
|
267
|
-
let
|
|
268
|
-
|
|
281
|
+
let h = r.processedSchemas.value[f][p];
|
|
282
|
+
h && a.isObject(h) && (d = u(h, d)), r.processedSchemas.value[f][p] = d, r.stableUpdater(i);
|
|
269
283
|
}
|
|
270
284
|
}
|
|
271
285
|
}
|
|
@@ -280,45 +294,39 @@ class N {
|
|
|
280
294
|
keyIndex: i
|
|
281
295
|
});
|
|
282
296
|
else {
|
|
283
|
-
const
|
|
297
|
+
const n = (c) => {
|
|
284
298
|
e.updater({
|
|
285
299
|
...e,
|
|
286
300
|
key: r,
|
|
287
301
|
keyIndex: i,
|
|
288
|
-
stable:
|
|
302
|
+
stable: c
|
|
289
303
|
});
|
|
290
304
|
};
|
|
291
|
-
|
|
292
|
-
r
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
})) : l(u);
|
|
314
|
-
});
|
|
305
|
+
a.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
306
|
+
if (r === "component") {
|
|
307
|
+
const c = t[r](this.getRuntimeMeta());
|
|
308
|
+
this.promiseFieldParser(c, n, !1);
|
|
309
|
+
} else
|
|
310
|
+
this.fieldParser(t[r], n);
|
|
311
|
+
}) : this.defaultValueEffect.trackEffect(() => {
|
|
312
|
+
const c = this.schemaEffect.trackEffect(() => {
|
|
313
|
+
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (f) => {
|
|
314
|
+
if (!f)
|
|
315
|
+
return n(f);
|
|
316
|
+
this.defaultValueInprogressMap.set(t[r], f), !a.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
317
|
+
(p) => !p.includes("undefined")
|
|
318
|
+
) ? (n(f), this.defaultValueEffect.clearEffects(), T(() => {
|
|
319
|
+
c();
|
|
320
|
+
})) : n(f);
|
|
321
|
+
}) : this.fieldParser(t[r], (f) => {
|
|
322
|
+
this.defaultValueInprogressMap.set(t[r], f), !a.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
323
|
+
(p) => !p.includes("undefined")
|
|
324
|
+
) ? (n(f), this.defaultValueEffect.clearEffects(), T(() => {
|
|
325
|
+
c();
|
|
326
|
+
})) : n(f);
|
|
315
327
|
});
|
|
316
328
|
});
|
|
317
|
-
|
|
318
|
-
const f = t[r];
|
|
319
|
-
this.promiseFieldParser(f, l, !1);
|
|
320
|
-
} else
|
|
321
|
-
this.fieldParser(t[r], l);
|
|
329
|
+
}) : r === "component" || r === "slots" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
|
|
322
330
|
}
|
|
323
331
|
});
|
|
324
332
|
}
|
|
@@ -326,19 +334,19 @@ class N {
|
|
|
326
334
|
return e.replace(/undefined/g, t);
|
|
327
335
|
}
|
|
328
336
|
promiseFieldParser(e, t, s) {
|
|
329
|
-
|
|
330
|
-
s &&
|
|
337
|
+
a.isPromise(e) ? e.then((r) => {
|
|
338
|
+
s && a.isObject(r) ? this.objectParser({
|
|
331
339
|
data: r,
|
|
332
340
|
updater: t
|
|
333
341
|
}) : t(r);
|
|
334
|
-
}) : (
|
|
342
|
+
}) : (a.isString(e) && (e = this.replaceUndefinedInString(e, "")), s && a.isObject(e) ? this.objectParser({
|
|
335
343
|
data: e,
|
|
336
344
|
updater: t
|
|
337
345
|
}) : t(e));
|
|
338
346
|
}
|
|
339
347
|
// 对任意对象中单个字段的 parse: 做基本处理
|
|
340
348
|
fieldParser(e, t, s = !0) {
|
|
341
|
-
if (
|
|
349
|
+
if (a.isFunction(e))
|
|
342
350
|
if (e.name.startsWith("__proform_raw_"))
|
|
343
351
|
t(e);
|
|
344
352
|
else {
|
|
@@ -346,10 +354,10 @@ class N {
|
|
|
346
354
|
this.promiseFieldParser(r, t, s);
|
|
347
355
|
}
|
|
348
356
|
else
|
|
349
|
-
|
|
357
|
+
G(e) ? v(
|
|
350
358
|
() => e.value,
|
|
351
359
|
() => {
|
|
352
|
-
|
|
360
|
+
a.isUndefined(e.value) || (s && a.isObject(e.value) ? this.objectParser({
|
|
353
361
|
data: e.value,
|
|
354
362
|
updater: t
|
|
355
363
|
}) : t(e.value));
|
|
@@ -358,10 +366,10 @@ class N {
|
|
|
358
366
|
immediate: !0,
|
|
359
367
|
deep: !0
|
|
360
368
|
}
|
|
361
|
-
) :
|
|
369
|
+
) : K(e) ? v(
|
|
362
370
|
() => e,
|
|
363
371
|
() => {
|
|
364
|
-
|
|
372
|
+
a.isUndefined(e) || (s && a.isObject(e) ? this.objectParser({
|
|
365
373
|
data: e,
|
|
366
374
|
updater: t
|
|
367
375
|
}) : t(e));
|
|
@@ -370,7 +378,7 @@ class N {
|
|
|
370
378
|
immediate: !0,
|
|
371
379
|
deep: !0
|
|
372
380
|
}
|
|
373
|
-
) : s &&
|
|
381
|
+
) : s && a.isObject(e) ? this.objectParser({
|
|
374
382
|
data: e,
|
|
375
383
|
updater: t
|
|
376
384
|
}) : t(e);
|
|
@@ -378,79 +386,88 @@ class N {
|
|
|
378
386
|
modelProcessor(e) {
|
|
379
387
|
e.map(
|
|
380
388
|
(t) => this.createModel(t, this.processedModel.value)
|
|
381
|
-
),
|
|
389
|
+
), a.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = y(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
|
|
382
390
|
}
|
|
383
391
|
createModel(e, t) {
|
|
384
|
-
|
|
392
|
+
a.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
|
|
385
393
|
this.createModel(s, t[e.field][0]);
|
|
386
|
-
})),
|
|
394
|
+
})), a.isGroupSchema(e) && e.children.forEach((s) => {
|
|
387
395
|
this.createModel(s, t);
|
|
388
|
-
}),
|
|
396
|
+
}), a.isItemSchema(e) && (t[e.field] = e.defaultValue);
|
|
389
397
|
}
|
|
390
398
|
}
|
|
391
|
-
function
|
|
392
|
-
return typeof
|
|
399
|
+
function se(o) {
|
|
400
|
+
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !Y(o);
|
|
393
401
|
}
|
|
394
|
-
class
|
|
402
|
+
class re {
|
|
395
403
|
constructor(e) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
404
|
+
l(this, "schemas", w([]));
|
|
405
|
+
l(this, "model", w({}));
|
|
406
|
+
l(this, "processorBySchemaType", {
|
|
399
407
|
item: this.runtimeItemProcessor.bind(this),
|
|
400
408
|
group: this.runtimeGroupProcessor.bind(this),
|
|
401
409
|
list: this.runtimeListProcessor.bind(this)
|
|
402
410
|
});
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
this
|
|
411
|
+
l(this, "formRef", w(null));
|
|
412
|
+
l(this, "hydrateEffect", new A());
|
|
413
|
+
l(this, "customizedOptions", Q({}));
|
|
414
|
+
l(this, "globalNativeFormOverride", {
|
|
415
|
+
props: {},
|
|
416
|
+
slots: {}
|
|
417
|
+
});
|
|
418
|
+
this.setup = e, this.processor = new te(this);
|
|
406
419
|
const t = this.setup(this);
|
|
407
420
|
this.processor.parseSchemas(t.schemas);
|
|
408
421
|
}
|
|
409
422
|
getRuntimeMeta() {
|
|
410
423
|
return {
|
|
411
|
-
model:
|
|
424
|
+
model: j(y(this.model.value))
|
|
412
425
|
};
|
|
413
426
|
}
|
|
414
427
|
runtimeItemProcessor(e, t, s = this.model.value, r) {
|
|
415
|
-
var
|
|
416
|
-
|
|
417
|
-
|
|
428
|
+
var h, z, F, M, x, U, D, N, k, R, _, L, B;
|
|
429
|
+
u(this.globalNativeFormOverride.props, (z = (h = e.native) == null ? void 0 : h.props) == null ? void 0 : z.Form), u(this.globalNativeFormOverride.slots, (M = (F = e.native) == null ? void 0 : F.slots) == null ? void 0 : M.Form);
|
|
430
|
+
const i = u(y((U = (x = this.customizedOptions.native) == null ? void 0 : x.props) == null ? void 0 : U.FormItem) ?? {}, (N = (D = e.native) == null ? void 0 : D.props) == null ? void 0 : N.FormItem), n = u(y((R = (k = this.customizedOptions.native) == null ? void 0 : k.slots) == null ? void 0 : R.FormItem) ?? {}, (L = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : L.FormItem), c = r ? `${r.field}.${t}.${e.field}` : e.field, f = j(e.component);
|
|
431
|
+
if (!f)
|
|
418
432
|
return;
|
|
419
|
-
const
|
|
433
|
+
const p = f.name, I = e.componentProps ?? {}, V = S.placeholderPresetByComponentName;
|
|
420
434
|
let P = e.placeholder;
|
|
421
435
|
if (P || (P = `${// @ts-expect-error
|
|
422
|
-
|
|
436
|
+
V[p] ?? "请输入"}${e.label}`), e.required)
|
|
423
437
|
if (!e.rules)
|
|
424
|
-
e.rules = [], (
|
|
438
|
+
e.rules = [], (B = e.rules) == null || B.push({
|
|
425
439
|
required: !0,
|
|
426
440
|
message: `${e.label}是必填项`
|
|
427
441
|
});
|
|
428
442
|
else {
|
|
429
|
-
const
|
|
430
|
-
e.rules[
|
|
443
|
+
const E = e.rules.findIndex((W) => !!W.required);
|
|
444
|
+
e.rules[E].message = `${e.label}是必填项`;
|
|
431
445
|
}
|
|
432
|
-
let
|
|
433
|
-
return
|
|
446
|
+
let d = e.show;
|
|
447
|
+
return d === void 0 && (d = !0), d || delete s[e.field], m(b.runtimeDoms.Item, null, {
|
|
434
448
|
default() {
|
|
435
|
-
return
|
|
449
|
+
return $(m(b.runtimeDoms.FormItem, C(i, {
|
|
436
450
|
label: `${e.label}:`,
|
|
437
451
|
rules: e.rules,
|
|
438
|
-
field:
|
|
439
|
-
}, {
|
|
440
|
-
default
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
452
|
+
field: c
|
|
453
|
+
}), {
|
|
454
|
+
default() {
|
|
455
|
+
return m(f, C({
|
|
456
|
+
modelValue: s[e.field],
|
|
457
|
+
"onUpdate:modelValue": (E) => s[e.field] = E,
|
|
458
|
+
placeholder: P
|
|
459
|
+
}, I), null);
|
|
460
|
+
},
|
|
461
|
+
...n
|
|
462
|
+
}), [[q, d]]);
|
|
446
463
|
}
|
|
447
464
|
});
|
|
448
465
|
}
|
|
449
466
|
runtimeGroupProcessor(e) {
|
|
450
467
|
let t;
|
|
451
|
-
return
|
|
468
|
+
return m(b.runtimeDoms.Group, {
|
|
452
469
|
schema: e
|
|
453
|
-
},
|
|
470
|
+
}, se(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
|
|
454
471
|
default: () => [t]
|
|
455
472
|
});
|
|
456
473
|
}
|
|
@@ -461,37 +478,37 @@ class $ {
|
|
|
461
478
|
code: "0001",
|
|
462
479
|
message: "异步默认值数据正在处理中,请您耐心等待... "
|
|
463
480
|
});
|
|
464
|
-
(s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(
|
|
481
|
+
(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();
|
|
465
482
|
}
|
|
466
483
|
deleteListItem(e, t) {
|
|
467
484
|
this.model.value[e.field].splice(t, 1), this.formRef.value.clearValidate();
|
|
468
485
|
}
|
|
469
486
|
runtimeListProcessor(e) {
|
|
470
487
|
const t = this;
|
|
471
|
-
return t.model.value[e.field] || (t.model.value[e.field] = [{}]),
|
|
488
|
+
return t.model.value[e.field] || (t.model.value[e.field] = [{}]), m(b.runtimeDoms.List, {
|
|
472
489
|
schema: e
|
|
473
490
|
}, {
|
|
474
491
|
default() {
|
|
475
|
-
return t.model.value[e.field].map((s, r) =>
|
|
492
|
+
return t.model.value[e.field].map((s, r) => m(b.runtimeDoms.ListItem, null, {
|
|
476
493
|
default() {
|
|
477
494
|
return e.children.map((i) => t.runtimeItemProcessor(i, r, s, e));
|
|
478
495
|
},
|
|
479
496
|
delete({
|
|
480
497
|
container: i
|
|
481
498
|
} = {}) {
|
|
482
|
-
var
|
|
483
|
-
let
|
|
484
|
-
return
|
|
499
|
+
var c;
|
|
500
|
+
let n = i ?? m("button", null, null);
|
|
501
|
+
return $(m(n, {
|
|
485
502
|
onClick: () => t.deleteListItem(e, r)
|
|
486
|
-
}, null), [[
|
|
503
|
+
}, null), [[q, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
|
|
487
504
|
}
|
|
488
505
|
}));
|
|
489
506
|
},
|
|
490
507
|
add({
|
|
491
508
|
container: s
|
|
492
509
|
} = {}) {
|
|
493
|
-
let r = s ??
|
|
494
|
-
return
|
|
510
|
+
let r = s ?? m("button", null, [X("添加")]);
|
|
511
|
+
return m(r, {
|
|
495
512
|
onClick: () => t.addListItem(e)
|
|
496
513
|
}, null);
|
|
497
514
|
}
|
|
@@ -501,19 +518,23 @@ class $ {
|
|
|
501
518
|
return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
|
|
502
519
|
}
|
|
503
520
|
exec() {
|
|
504
|
-
|
|
505
|
-
|
|
521
|
+
var r, i, n, c;
|
|
522
|
+
const e = this, t = u(y((i = (r = this.customizedOptions.native) == null ? void 0 : r.props) == null ? void 0 : i.Form) ?? {}, this.globalNativeFormOverride.props), s = u(y((c = (n = this.customizedOptions.native) == null ? void 0 : n.slots) == null ? void 0 : c.Form) ?? {}, this.globalNativeFormOverride.slots);
|
|
523
|
+
return m(b.runtimeDoms.Form, C(t, {
|
|
506
524
|
ref: this.formRef,
|
|
507
525
|
model: this.model.value
|
|
508
|
-
},
|
|
509
|
-
default
|
|
526
|
+
}), {
|
|
527
|
+
default() {
|
|
528
|
+
return e.runtimeProcessor(e.schemas.value);
|
|
529
|
+
},
|
|
530
|
+
...s
|
|
510
531
|
});
|
|
511
532
|
}
|
|
512
533
|
}
|
|
513
|
-
class
|
|
534
|
+
class b {
|
|
514
535
|
}
|
|
515
|
-
|
|
516
|
-
const
|
|
536
|
+
l(b, "runtimeDoms");
|
|
537
|
+
const g = class g {
|
|
517
538
|
static getPlaceholderPrefixPresetByComponentName() {
|
|
518
539
|
const e = {
|
|
519
540
|
请选择: ["Select", "Tree", "TreeSelect"],
|
|
@@ -526,7 +547,7 @@ const b = class b {
|
|
|
526
547
|
return t;
|
|
527
548
|
}
|
|
528
549
|
};
|
|
529
|
-
|
|
550
|
+
l(g, "schemaPreset", {
|
|
530
551
|
type: {
|
|
531
552
|
defaultValue: "item"
|
|
532
553
|
},
|
|
@@ -559,52 +580,54 @@ o(b, "schemaPreset", {
|
|
|
559
580
|
},
|
|
560
581
|
children: {
|
|
561
582
|
defaultValue: []
|
|
562
|
-
}
|
|
563
|
-
|
|
583
|
+
},
|
|
584
|
+
native: void 0
|
|
585
|
+
}), l(g, "componentPropsPreset", {
|
|
564
586
|
options: {
|
|
565
587
|
defaultValue: []
|
|
566
588
|
}
|
|
567
589
|
}), // 基于基本功能提出基本预设
|
|
568
|
-
|
|
569
|
-
let
|
|
570
|
-
const
|
|
590
|
+
l(g, "placeholderPresetByComponentName", g.getPlaceholderPrefixPresetByComponentName());
|
|
591
|
+
let S = g;
|
|
592
|
+
const ne = /* @__PURE__ */ Z({
|
|
571
593
|
props: {
|
|
572
594
|
setup: {
|
|
573
595
|
type: Function,
|
|
574
596
|
required: !0
|
|
575
597
|
}
|
|
576
598
|
},
|
|
577
|
-
setup(
|
|
578
|
-
const e = new
|
|
599
|
+
setup(o) {
|
|
600
|
+
const e = new re(o.setup);
|
|
579
601
|
return () => e.exec();
|
|
580
602
|
}
|
|
581
603
|
});
|
|
582
|
-
function
|
|
583
|
-
const e = new
|
|
604
|
+
function le(o) {
|
|
605
|
+
const e = new ee(o);
|
|
584
606
|
return [
|
|
585
607
|
e.setup.bind(e),
|
|
586
608
|
{
|
|
587
609
|
submit: e.submit.bind(e),
|
|
588
|
-
hydrate: e.hydrate.bind(e)
|
|
610
|
+
hydrate: e.hydrate.bind(e),
|
|
611
|
+
customize: e.customize.bind(e)
|
|
589
612
|
}
|
|
590
613
|
];
|
|
591
614
|
}
|
|
592
|
-
function
|
|
615
|
+
function ce(o) {
|
|
593
616
|
return {
|
|
594
617
|
install() {
|
|
595
|
-
|
|
618
|
+
b.runtimeDoms = o;
|
|
596
619
|
}
|
|
597
620
|
};
|
|
598
621
|
}
|
|
599
|
-
function
|
|
600
|
-
return e === "raw" && Object.defineProperty(
|
|
601
|
-
value: `__proform_raw_${
|
|
622
|
+
function ae(o, e) {
|
|
623
|
+
return e === "raw" && Object.defineProperty(o, "name", {
|
|
624
|
+
value: `__proform_raw_${o.name}`,
|
|
602
625
|
writable: !0
|
|
603
|
-
}),
|
|
626
|
+
}), o;
|
|
604
627
|
}
|
|
605
628
|
export {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
629
|
+
ne as ProForm,
|
|
630
|
+
le as useForm,
|
|
631
|
+
ce as useFormRenderer,
|
|
632
|
+
ae as useModifiers
|
|
610
633
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject, FormCustomization } from "../types";
|
|
1
|
+
import { AnyObject, CustomizationOptions, FormCustomization } from "../types";
|
|
2
2
|
import { RuntimeCore } from "./index";
|
|
3
3
|
export default class FormCustomizer {
|
|
4
4
|
formCustomization: FormCustomization;
|
|
@@ -7,5 +7,6 @@ export default class FormCustomizer {
|
|
|
7
7
|
constructor(formCustomization: FormCustomization);
|
|
8
8
|
setup(_runtimeCore: RuntimeCore): FormCustomization;
|
|
9
9
|
submit(): Promise<AnyObject>;
|
|
10
|
-
hydrate(data: AnyObject):
|
|
10
|
+
hydrate(data: AnyObject): Promise<never> | undefined;
|
|
11
|
+
customize(options: Partial<CustomizationOptions>): void;
|
|
11
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ref } from "vue";
|
|
2
|
-
import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType } from "../types";
|
|
2
|
+
import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType, CustomizationOptions } from "../types";
|
|
3
3
|
import Processor from "./Processor";
|
|
4
4
|
import Effect from "./Effect";
|
|
5
5
|
export default class RuntimeCore {
|
|
@@ -10,6 +10,11 @@ export default class RuntimeCore {
|
|
|
10
10
|
processorBySchemaType: ProcessorBySchemaType;
|
|
11
11
|
formRef: Ref<AnyObject>;
|
|
12
12
|
hydrateEffect: Effect;
|
|
13
|
+
customizedOptions: CustomizationOptions;
|
|
14
|
+
globalNativeFormOverride: {
|
|
15
|
+
props: {};
|
|
16
|
+
slots: {};
|
|
17
|
+
};
|
|
13
18
|
constructor(setup: Setup);
|
|
14
19
|
getRuntimeMeta(): {
|
|
15
20
|
model: AnyObject;
|
|
@@ -29,6 +29,7 @@ export interface ItemSchema {
|
|
|
29
29
|
show?: boolean;
|
|
30
30
|
required?: boolean;
|
|
31
31
|
placeholder?: string;
|
|
32
|
+
native?: NativeCustomizationOptions;
|
|
32
33
|
label: string;
|
|
33
34
|
field: string;
|
|
34
35
|
component: DomType;
|
|
@@ -58,3 +59,16 @@ export type ProxyedSchema = ProFormProxy<ItemSchema | GroupSchema | ListSchema>;
|
|
|
58
59
|
export interface FormCustomization {
|
|
59
60
|
schemas: ProxyedSchema[];
|
|
60
61
|
}
|
|
62
|
+
export type NativeCustomizationOptions = {
|
|
63
|
+
props?: {
|
|
64
|
+
Form?: AnyObject;
|
|
65
|
+
FormItem?: AnyObject;
|
|
66
|
+
};
|
|
67
|
+
slots?: {
|
|
68
|
+
Form?: AnyObject;
|
|
69
|
+
FormItem?: AnyObject;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export type CustomizationOptions = {
|
|
73
|
+
native?: NativeCustomizationOptions;
|
|
74
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject } from "../types";
|
|
1
|
+
import { AnyObject, CustomizationOptions } from "../types";
|
|
2
2
|
import type { RuntimeCore } from "../services";
|
|
3
3
|
export type Setup = (runtimeCore: RuntimeCore) => any;
|
|
4
4
|
export type UseForm = [
|
|
@@ -6,5 +6,6 @@ export type UseForm = [
|
|
|
6
6
|
{
|
|
7
7
|
submit: () => Promise<AnyObject>;
|
|
8
8
|
hydrate: (data: AnyObject) => any;
|
|
9
|
+
customize: (options: CustomizationOptions) => any;
|
|
9
10
|
}
|
|
10
11
|
];
|