@harbor-design/proform 1.1.9 → 1.1.11
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 +374 -250
- package/dist/types/index.d.ts +1 -1
- package/dist/types/src/interactions/useFormPresetConfigurer.d.ts +2 -0
- package/dist/types/src/services/Context/index.d.ts +4 -0
- package/dist/types/src/services/{Effect.d.ts → Effect/index.d.ts} +2 -2
- package/dist/types/src/services/{FormCustomizer.d.ts → FormCustomizer/index.d.ts} +2 -2
- package/dist/types/src/services/Preset/AdapterPreset.d.ts +3 -0
- package/dist/types/src/services/{Preset.d.ts → Preset/RuntimePreset.d.ts} +2 -2
- package/dist/types/src/services/Preset/index.d.ts +11 -0
- package/dist/types/src/services/{Processor.d.ts → Processor/index.d.ts} +3 -3
- package/dist/types/src/services/RuntimeCore/RuntimeAdapter.d.ts +8 -0
- package/dist/types/src/services/RuntimeCore/RuntimeContainer.d.ts +9 -0
- package/dist/types/src/services/{RuntimeCore.d.ts → RuntimeCore/index.d.ts} +8 -5
- package/dist/types/src/types/adapter.d.ts +7 -0
- package/dist/types/src/types/contextTypes.d.ts +17 -7
- package/dist/types/src/types/formCustomizerTypes.d.ts +11 -10
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/runtimeTypes.d.ts +3 -0
- package/package.json +1 -1
- package/dist/types/src/interactions/useFormRenderer.d.ts +0 -4
- package/dist/types/src/services/Context.d.ts +0 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var K=(n,e,t)=>e in n?G(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>(K(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class c{static typeChecker(e){return{}.toString.call(e)}static isString(e){return typeof e=="string"}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e)==="[object Function]"}static isPromise(e){return e instanceof Promise}static isObject(e){return this.typeChecker(e)==="[object Object]"}static isAsyncFunction(e){return this.typeChecker(e)==="[object AsyncFunction]"}static isUndefined(e){return e===void 0}static isArrayEmpty(e){return(e==null?void 0:e.length)<1}static isObjectEmpty(e){return this.isArrayEmpty(Object.keys(e))}static isListSchema(e){return e.type==="list"}static isGroupSchema(e){return e.type==="group"}static isItemSchema(e){return this.isUndefined(e.type)||e.type==="item"}static isProcessInprogress(e){if(e===void 0)return!0;if(this.isObject(e)){if(e.setup&&this.isFunction(e.setup)&&e.props)return!1;if(this.isObjectEmpty(e))return!0;for(const t in e)if(e.hasOwnProperty(t)&&this.isProcessInprogress(e[t]))return!0}else if(this.isArray(e)){if(this.isArrayEmpty(e))return!0;for(const t of e)if(this.isProcessInprogress(t))return!0}return!1}}function p(n,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(n)||(n=[]),t.forEach((s,r)=>{typeof s=="object"&&s!==null?n[r]=p(Array.isArray(s)?[]:{},s):n[r]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?n[s]=p(n[s]||{},t[s]):n[s]=t[s])}),n}function g(n){const e=new WeakMap;function t(s){if(s===null||typeof s!="object")return s;if(s instanceof Date)return new Date(s);if(s instanceof RegExp)return new RegExp(s);if(s instanceof Map){const o=new Map;for(let[l,u]of s)o.set(t(l),t(u));return o}if(s instanceof Set){const o=new Set;for(let l of s)o.add(t(l));return o}if(e.has(s))return e.get(s);if(Array.isArray(s)){const o=[];e.set(s,o);for(let l=0;l<s.length;l++)o[l]=t(s[l]);return o}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let o in s)s.hasOwnProperty(o)&&(r[o]=t(s[o]));return r}return t(n)}function O(n,e){return n.replace(/undefined/g,e)}class W{constructor(e){a(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,Object.assign(this.runtimeCore.native,this.formCustomization.native),Object.assign(this.runtimeCore.gridProps,this.formCustomization.gridProps),Object.assign(this.runtimeCore.runtimeSetters,this.formCustomization.runtimeSetters),this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){if(!this.runtimeCore)return Promise.reject({code:"0002",message:"hydrate 使用时机错误,建议将 hydrate 操作放到 onMounted 等页面节点挂载完成的钩子中,或者使用响应式的值来注入数据"});this.runtimeCore.hydrateEffect.trackEffect(()=>{i.isRef(e)?i.watch(()=>e.value,()=>{p(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):i.isReactive(e)?i.watch(()=>e,()=>{p(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):p(this.runtimeCore.model.value,e)},{lazy:!0})}}class N{constructor(){a(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e,t={lazy:!1}){return!t.lazy&&e(),this.effects.add(e),()=>this.effects.delete(e)}}class H{constructor(e){a(this,"runtimeCore");a(this,"processedSchemas");a(this,"processedModel");a(this,"getRuntimeMeta");a(this,"stableSchemas",[]);a(this,"stableModel",{});a(this,"schemaPreset",I.schemaPreset);a(this,"componentPropsPreset",I.componentPropsPreset);a(this,"stableUpdaterProcessProgress");a(this,"stableUpdaterTimes",0);a(this,"schemaEffect",new N);a(this,"defaultValueEffect",new N);a(this,"defaultValueInprogressMap",new Map);a(this,"baseDefaultValueFunctionsLength");this.runtimeCore=e,this.processedSchemas=e.schemas,this.processedModel=e.model,this.getRuntimeMeta=e.getRuntimeMeta.bind(e),i.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects()},{deep:!0})}parse(e,t){e.forEach((s,r)=>{this.parseItem(s,r,t)})}initSchemas(e){return e.map(t=>{const s={};return t.children&&(s.children=this.initSchemas(t.children)),s})}countFunctionDefaultValues(e){let t=0,s=new Set;function r(o){if(!s.has(o)&&(Array.isArray(o)||o!==null&&typeof o=="object")){s.add(o);for(let l in o)o.hasOwnProperty(l)&&(l==="defaultValue"&&typeof o[l]=="function"&&!o[l].toString().includes("[native code]")&&t++,r(o[l]))}}return r(e),t}parseSchemas(e,t){c.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(g(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!c.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!c.isProcessInprogress(t)&&c.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,o=Array.from({length:Object.keys(e).filter(u=>u!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(u){const f=u.index,d=u.key,S=u.keyIndex;if(c.isUndefined(u.stable))return;const C=r.parseStable(u.stable),v=s==null?void 0:s.index,b=s==null?void 0:s.key;let y=C;if(c.isProcessInprogress(y)||(o[S]=!0),s){let m=r.processedSchemas.value[v][b][f][d];m&&c.isObject(m)&&d!=="component"&&(y=p(m,y)),r.processedSchemas.value[v][b][f][d]=y,r.stableUpdater(o)}else{let m=r.processedSchemas.value[f][d];m&&c.isObject(m)&&d!=="component"&&(y=p(m,y)),r.processedSchemas.value[f][d]=y,r.stableUpdater(o)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,o)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:o});else{const l=u=>{e.updater({...e,key:r,keyIndex:o,stable:u})};c.isFunction(t[r])?r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const u=t[r](this.getRuntimeMeta());this.promiseFieldParser(u,l,!1)}else this.fieldParser(t[r],l)}):this.defaultValueEffect.trackEffect(()=>{const u=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],f=>{if(!f)return l(f);this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)}):this.fieldParser(t[r],f=>{this.defaultValueInprogressMap.set(t[r],f),!c.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),i.nextTick(()=>{u()})):l(f)})})}):r==="component"||r==="slots"||r==="runtimeSetters"?this.promiseFieldParser(t[r],l,!1):this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){c.isPromise(e)?e.then(r=>{c.isString(r)&&(r=O(r,"")),s&&c.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):(c.isString(e)&&(e=O(e,"")),s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))}fieldParser(e,t,s=!0){if(c.isFunction(e))if(e.name.startsWith("__proform_raw_"))t((...r)=>{e({rawArgs:r,...this.getRuntimeMeta()})});else{const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{c.isUndefined(e.value)||(s&&c.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{c.isUndefined(e)||(s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&c.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),c.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=g(this.processedModel.value),this.runtimeCore.hydrateEffect.triggerEffects(),this.runtimeCore.hydrateEffect.clearEffects())}createModel(e,t){c.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),c.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),c.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function J(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!i.isVNode(n)}class Q{constructor(e){a(this,"schemas",i.ref([]));a(this,"model",i.ref({}));a(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});a(this,"formRef",i.ref(null));a(this,"hydrateEffect",new N);a(this,"native",i.reactive({}));a(this,"gridProps",{});a(this,"runtimeSetters",{});a(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new H(this);const t=this.setup(this);if(i.isRef(t.schemas)){const s=i.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas.value),i.nextTick(()=>{s()})},{deep:!0})}else if(i.isReactive(t.schemas)){const s=i.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas),i.nextTick(()=>{s()})},{deep:!0})}else this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(g(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var A,R,M,F,U,x,k,D,L,_,z,$,q,T,B;p(this.globalNativeFormOverride.props,(R=(A=e.native)==null?void 0:A.props)==null?void 0:R.Form),p(this.globalNativeFormOverride.slots,(F=(M=e.native)==null?void 0:M.slots)==null?void 0:F.Form);const o=p(g((x=(U=this.native)==null?void 0:U.props)==null?void 0:x.FormItem)??{},(D=(k=e.native)==null?void 0:k.props)==null?void 0:D.FormItem),l=p(g((_=(L=this.native)==null?void 0:L.slots)==null?void 0:_.FormItem)??{},($=(z=e.native)==null?void 0:z.slots)==null?void 0:$.FormItem),u={display:"grid",gridColumn:"1 / -1",...e.gridProps},f=r?`${r.field}.${t}.${e.field}`:e.field,d=i.toRaw(e.component);if(!d)return;const S=d.name,C=e.componentProps??{},v=I.placeholderPresetByComponentName;let b=e.placeholder;const y=e.required;let m=e.show;m===void 0&&(m=!0),m||delete s[e.field];let V=e.label;const w=(r==null?void 0:r.runtimeSetters)??this.runtimeSetters;if(!c.isUndefined(t)&&!c.isObjectEmpty(w)&&(V=O((q=w==null?void 0:w.listItemLabelSetter)==null?void 0:q.call(w,e.label,t+1),"")),!b){let h="请输入";c.isUndefined(S)?b=`${h}${V}`:v[S.toLowerCase()]?(h=v[S.toLowerCase()],b=`${h}${V}`):(Object.keys(v).forEach(j=>{S.toLowerCase().includes(j.toLowerCase())&&(h=v[j])}),b=`${h}${V}`)}if(y)if(!e.rules)e.rules=[],(T=e.rules)==null||T.push({required:!0,message:`${V}是必填项`});else{const h=e.rules.findIndex(j=>!c.isUndefined(j.required));h!==-1&&(e.rules[h].required=!0,e.rules[h].message=`${V}是必填项`)}else if(e.rules){const h=(B=e.rules)==null?void 0:B.findIndex(j=>!!j.required);h!==-1&&(e.rules[h].required=!1)}return i.createVNode("div",{style:u},[i.createVNode(P.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(P.runtimeDoms.FormItem,i.mergeProps(o,{label:`${V}:`,rules:e.rules,field:f}),{default(){return i.createVNode(d,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":h=>s[e.field]=h,placeholder:b},C),null)},...l}),[[i.vShow,m]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.gridProps};return i.createVNode("div",{style:s},[i.createVNode(P.runtimeDoms.Group,{schema:e},J(t=e.children.map(r=>this.runtimeItemProcessor(r)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(g(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.gridProps},s=this;return s.model.value[e.field]||(s.model.value[e.field]=[{}]),i.createVNode("div",{style:t},[i.createVNode(P.runtimeDoms.List,{schema:e},{default(){return s.model.value[e.field].map((r,o)=>i.createVNode(P.runtimeDoms.ListItem,null,{default(){return e.children.map(l=>s.runtimeItemProcessor(l,o,r,e))},delete({container:l}={}){var f;let u=l??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(u,{onClick:()=>s.deleteListItem(e,o)},null),[[i.vShow,((f=s.model.value[e.field])==null?void 0:f.length)>1]])}}))},add({container:r}={}){let o=r??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.createVNode(o,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var o,l,u,f;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.gridProps},t=this,s=p(g((l=(o=this.native)==null?void 0:o.props)==null?void 0:l.Form)??{},this.globalNativeFormOverride.props),r=p(g((f=(u=this.native)==null?void 0:u.slots)==null?void 0:f.Form)??{},this.globalNativeFormOverride.slots);return i.createVNode(P.runtimeDoms.Form,i.mergeProps(s,{ref:this.formRef,model:this.model.value}),{default(){return i.createVNode("div",{style:e},[t.runtimeProcessor(t.schemas.value)])},...r})}}class P{}a(P,"runtimeDoms");const E=class E{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["select","tree","treeselect"],请输入:["input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};a(E,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]},native:void 0,gridProps:void 0}),a(E,"componentPropsPreset",{options:{defaultValue:[]}}),a(E,"placeholderPresetByComponentName",E.getPlaceholderPrefixPresetByComponentName());let I=E;const X=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new Q(n.setup);return()=>e.exec()}});function Y(n){const e=new W(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function Z(n){return{install(){P.runtimeDoms=n}}}function ee(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=X;exports.useForm=Y;exports.useFormRenderer=Z;exports.useModifiers=ee;
|
|
1
|
+
"use strict";var J=Object.defineProperty;var Q=(r,e,t)=>e in r?J(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>(Q(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=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 m(r,...e){return e.forEach(t=>{if(Array.isArray(t))Array.isArray(r)||(r=[]),t.forEach((s,i)=>{typeof s=="object"&&s!==null?r[i]=m(Array.isArray(s)?[]:{},s):r[i]=s});else for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?r[s]=m(r[s]||{},t[s]):r[s]=t[s])}),r}function g(r){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 n=new Map;for(let[l,c]of s)n.set(t(l),t(c));return n}if(s instanceof Set){const n=new Set;for(let l of s)n.add(t(l));return n}if(e.has(s))return e.get(s);if(Array.isArray(s)){const n=[];e.set(s,n);for(let l=0;l<s.length;l++)n[l]=t(s[l]);return n}const i=Object.create(Object.getPrototypeOf(s));e.set(s,i);for(let n in s)s.hasOwnProperty(n)&&(i[n]=t(s[n]));return i}return t(r)}function F(r,e){return r.replace(/undefined/g,e)}class X{constructor(e){u(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.grid,this.formCustomization.grid),Object.assign(this.runtimeCore.runtime,this.formCustomization.runtime),this.formCustomization.ui&&(this.runtimeCore.ui=this.formCustomization.ui),this.formCustomization}submit(){var s;const e=(s=d.presets.uiPresets[this.runtimeCore.ui])==null?void 0:s.adapter,t=I.adapters[this.runtimeCore.ui];return(e==null?void 0:e.validateForm(this))??(t==null?void 0:t.validateForm(this))}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,()=>{m(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):o.isReactive(e)?o.watch(()=>e,()=>{m(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):m(this.runtimeCore.model.value,e)},{lazy:!0})}}class E{constructor(){u(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 Y{constructor(e){u(this,"runtimeCore");u(this,"processedSchemas");u(this,"processedModel");u(this,"getRuntimeMeta");u(this,"stableSchemas",[]);u(this,"stableModel",{});u(this,"schemaPreset",I.schemaPreset);u(this,"componentPropsPreset",I.componentPropsPreset);u(this,"stableUpdaterProcessProgress");u(this,"stableUpdaterTimes",0);u(this,"schemaEffect",new E);u(this,"defaultValueEffect",new E);u(this,"defaultValueInprogressMap",new Map);u(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,i)=>{this.parseItem(s,i,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 i(n){if(!s.has(n)&&(Array.isArray(n)||n!==null&&typeof n=="object")){s.add(n);for(let l in n)n.hasOwnProperty(l)&&(l==="defaultValue"&&typeof n[l]=="function"&&!n[l].toString().includes("[native code]")&&t++,i(n[l]))}}return i(e),t}parseSchemas(e,t){a.isArrayEmpty(this.processedSchemas.value)&&(this.baseDefaultValueFunctionsLength=this.countFunctionDefaultValues(g(e)),this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!a.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);!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 i=this,n=Array.from({length:Object.keys(e).filter(c=>c!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:l});function l(c){const f=c.index,h=c.key,y=c.keyIndex;if(a.isUndefined(c.stable))return;const j=i.parseStable(c.stable),v=s==null?void 0:s.index,b=s==null?void 0:s.key;let P=j;if(a.isProcessInprogress(P)||(n[y]=!0),s){let p=i.processedSchemas.value[v][b][f][h];p&&a.isObject(p)&&h!=="component"&&(P=m(p,P)),i.processedSchemas.value[v][b][f][h]=P,i.stableUpdater(n)}else{let p=i.processedSchemas.value[f][h];p&&a.isObject(p)&&h!=="component"&&(P=m(p,P)),i.processedSchemas.value[f][h]=P,i.stableUpdater(n)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((i,n)=>{if(i==="children")this.parseSchemas(t[i],{...e,key:i,keyIndex:n});else{const l=c=>{e.updater({...e,key:i,keyIndex:n,stable:c})};a.isFunction(t[i])?i!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(i==="component"){const c=t[i](this.getRuntimeMeta());this.promiseFieldParser(c,l,!1)}else this.fieldParser(t[i],l)}):this.defaultValueEffect.trackEffect(()=>{const c=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[i].toString())?this.fieldParser(t[i],f=>{if(!f)return l(f);this.defaultValueInprogressMap.set(t[i],f),!a.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(h=>!h.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),o.nextTick(()=>{c()})):l(f)}):this.fieldParser(t[i],f=>{this.defaultValueInprogressMap.set(t[i],f),!a.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(h=>!h.includes("undefined"))?(l(f),this.defaultValueEffect.clearEffects(),o.nextTick(()=>{c()})):l(f)})})}):i==="component"||i==="slots"||i==="runtime"?this.promiseFieldParser(t[i],l,!1):this.fieldParser(t[i],l)}})}promiseFieldParser(e,t,s){a.isPromise(e)?e.then(i=>{a.isString(i)&&(i=F(i,"")),s&&a.isObject(i)?this.objectParser({data:i,updater:t}):t(i)}):(a.isString(e)&&(e=F(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((...i)=>{e({rawArgs:i,...this.getRuntimeMeta()})});else{const i=e(this.getRuntimeMeta());this.promiseFieldParser(i,t,s)}else o.isRef(e)?o.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}):o.isReactive(e)?o.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=g(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)}}class w{static getFormContainer({ui:e}={}){return d.presets.uiPresets[e??d.presets.ui].container.Form}static getFormItemContainer({ui:e}={}){return d.presets.uiPresets[e??d.presets.ui].container.FormItem}static getItemContainer({ui:e}={}){return d.presets.uiPresets[e??d.presets.ui].container.Item}static getGroupContainer({ui:e}={}){return d.presets.uiPresets[e??d.presets.ui].container.Group}static getListContainer({ui:e}={}){return d.presets.uiPresets[e??d.presets.ui].container.List}static getListItemContainer({ui:e}={}){return d.presets.uiPresets[e??d.presets.ui].container.ListItem}}class Z{constructor(e){this.ui=e}getRuntimeField(e){var i;const t=(i=d.presets.uiPresets[this.ui])==null?void 0:i.adapter,s=I.adapters[this.ui];return(t==null?void 0:t.getRuntimeField(e))??(s==null?void 0:s.getRuntimeField(e))}getRuntimeRequired(e){var i;const t=(i=d.presets.uiPresets[this.ui])==null?void 0:i.adapter,s=I.adapters[this.ui];return(t==null?void 0:t.getRuntimeRequired(e))??(s==null?void 0:s.getRuntimeRequired(e))}getFormModelPropName(){var s;const e=(s=d.presets.uiPresets[this.ui])==null?void 0:s.adapter,t=I.adapters[this.ui];return(e==null?void 0:e.getFormModelPropName())??(t==null?void 0:t.getFormModelPropName())}}function A(r){return typeof r=="function"||Object.prototype.toString.call(r)==="[object Object]"&&!o.isVNode(r)}class ee{constructor(e){u(this,"schemas",o.ref([]));u(this,"model",o.ref({}));u(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});u(this,"formRef",o.ref(null));u(this,"hydrateEffect",new E);u(this,"native",o.reactive({}));u(this,"grid",{});u(this,"runtime",{});u(this,"globalNativeFormOverride",{props:{},slots:{}});this.setup=e,this.processor=new Y(this);const t=this.setup(this);if(this.ui=t.ui??d.presets.ui,this.runtimeAdapter=new Z(this.ui),o.isRef(t.schemas)){const s=o.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas.value),o.nextTick(()=>{s()})},{deep:!0})}else if(o.isReactive(t.schemas)){const s=o.watch(()=>t.schemas,()=>{this.processor.parseSchemas(t.schemas),o.nextTick(()=>{s()})},{deep:!0})}else this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:o.toRaw(g(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,i){var N,O,M,q,L,U,k,x,z,_,$,T,D;const n=o.toRaw(e.component);if(!n)return;m(this.globalNativeFormOverride.props,(O=(N=e.native)==null?void 0:N.props)==null?void 0:O.Form),m(this.globalNativeFormOverride.slots,(q=(M=e.native)==null?void 0:M.slots)==null?void 0:q.Form);const l=m(g((U=(L=this.native)==null?void 0:L.slots)==null?void 0:U.FormItem)??{},(x=(k=e.native)==null?void 0:k.slots)==null?void 0:x.FormItem),c={display:"grid",gridColumn:"1 / -1",...e.grid},f=m(g((_=(z=this.native)==null?void 0:z.props)==null?void 0:_.FormItem)??{},(T=($=e.native)==null?void 0:$.props)==null?void 0:T.FormItem),h=this.runtimeAdapter.getRuntimeField({schema:e,parentSchema:i,index:t}),y=n.name,j=e.componentProps??{},v=I.placeholderPresetByComponentName;let b=e.placeholder,P=e.show;P===void 0&&(P=!0),P||delete s[e.field];let p=e.label;const V=(i==null?void 0:i.runtime)??this.runtime;if(!a.isUndefined(t)&&!a.isObjectEmpty(V)&&(p=F((D=V==null?void 0:V.customizeItemLabel)==null?void 0:D.call(V,e.label??"",t+1),"")),!b){let C="请输入";a.isUndefined(y)?b=`${C}${p}`:v[y.toLowerCase()]?(C=v[y.toLowerCase()],b=`${C}${p}`):(Object.keys(v).forEach(B=>{y.toLowerCase().includes(B.toLowerCase())&&(C=v[B])}),b=`${C}${p}`)}const K=this.runtimeAdapter.getRuntimeRequired({...e,label:p}),W=w.getItemContainer(this),H=w.getFormItemContainer(this);return o.createVNode("div",{style:c},[o.createVNode(W,null,{default(){return o.withDirectives(o.createVNode(H,o.mergeProps(f,{label:`${p}:`},h,K),{default(){return o.createVNode(n,o.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":C=>s[e.field]=C,placeholder:b},j),null)},...l}),[[o.vShow,P]])}})])}runtimeGroupProcessor(e){let t;const s={display:"grid",gridColumn:"1 / -1",...e.grid},i=w.getGroupContainer(this);return o.createVNode("div",{style:s},[o.createVNode(i,{schema:e},A(t=e.children.map(n=>this.runtimeItemProcessor(n)))?t:{default:()=>[t]})])}addListItem(e){var t,s;if(!((t=this.processor.stableModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(s=this.processor.stableModel[e.field])!=null&&s[0]&&this.model.value[e.field].push(g(this.processor.stableModel[e.field][0])),this.formRef.value.clearValidate()}deleteListItem(e,t){this.model.value[e.field].splice(t,1),this.formRef.value.clearValidate()}runtimeListProcessor(e){const t={display:"grid",gridColumn:"1 / -1",...e.grid},s=this;s.model.value[e.field]||(s.model.value[e.field]=[{}]);const i=w.getListContainer(this),n=w.getListItemContainer(this);return o.createVNode("div",{style:t},[o.createVNode(i,{schema:e},{default(){return s.model.value[e.field].map((l,c)=>o.createVNode(n,null,{default(){return e.children.map(f=>s.runtimeItemProcessor(f,c,l,e))},delete({container:f}={}){var y;let h=f??o.createVNode("button",null,null);return o.withDirectives(o.createVNode(h,{onClick:()=>s.deleteListItem(e,c)},null),[[o.vShow,((y=s.model.value[e.field])==null?void 0:y.length)>1]])}}))},add({container:l}={}){let c=l??o.createVNode("button",null,[o.createTextVNode("添加")]);return o.createVNode(c,{onClick:()=>s.addListItem(e)},null)}})])}runtimeProcessor(e){return e.map(t=>(t.type||(t.type="item"),this.processorBySchemaType[t.type](t)))}exec(){var c,f,h,y;const e={display:"grid",gridColumn:"1 / -1",gridAutoColumns:"1fr",...this.grid},t=this,s=m(g((f=(c=this.native)==null?void 0:c.props)==null?void 0:f.Form)??{},this.globalNativeFormOverride.props),i=m(g((y=(h=this.native)==null?void 0:h.slots)==null?void 0:y.Form)??{},this.globalNativeFormOverride.slots),n=w.getFormContainer(this),l=this.runtimeAdapter.getFormModelPropName();return o.createVNode(n,o.mergeProps(s,{ref:this.formRef},{[l]:this.model.value}),{default(){return o.createVNode("div",{style:e},[t.runtimeProcessor(t.schemas.value)])},...i})}}class d{}u(d,"presets");function G({parentSchema:r,schema:e,index:t}){return r?`${r.field}.${t}.${e.field}`:e.field}const te={ArcoVue:{getRuntimeField(r){return{field:G(r)}},getRuntimeRequired(r){var e,t;if(r.required)if(!r.rules)r.rules=[],(e=r.rules)==null||e.push({required:!0,message:`${r.label}是必填项`});else{const s=r.rules.findIndex(i=>!a.isUndefined(i.required));s!==-1&&(r.rules[s].required=!0,r.rules[s].message=`${r.label}是必填项`)}else if(r.rules){const s=(t=r.rules)==null?void 0:t.findIndex(i=>!!i.required);s!==-1&&(r.rules[s].required=!1)}return{rules:r.rules}},getFormModelPropName(){return"model"},validateForm(r){return new Promise((e,t)=>{r.runtimeCore.formRef.value.validate(s=>s?t(s):e(r.cleanFallbackFields(o.toRaw(r.runtimeCore.processor.processedModel.value))))})}},NutUI:{getRuntimeField(r){return{prop:G(r)}},getRuntimeRequired(r){var e,t;if(r.required)if(!r.rules)r.rules=[],(e=r.rules)==null||e.push({required:!0,message:`${r.label}是必填项`});else{const s=r.rules.findIndex(i=>!a.isUndefined(i.required));s!==-1&&(r.rules[s].required=!0,r.rules[s].message=`${r.label}是必填项`)}else if(r.rules){const s=(t=r.rules)==null?void 0:t.findIndex(i=>!!i.required);s!==-1&&(r.rules[s].required=!1)}return{rules:r.rules,required:r.required}},getFormModelPropName(){return"modelValue"},validateForm(r){return new Promise((e,t)=>{r.runtimeCore.formRef.value.validate().then(({valid:s,errors:i})=>{s?e(r.cleanFallbackFields(o.toRaw(r.runtimeCore.processor.processedModel.value))):t(i)})})}}},S=class S{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["select","tree"],请输入:["input"]},t={};for(let s in e)e[s].forEach(i=>{t[i]=s});return t}};u(S,"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:{defaultValue:void 0},grid:{default:void 0}}),u(S,"componentPropsPreset",{options:{defaultValue:[]}}),u(S,"placeholderPresetByComponentName",S.getPlaceholderPrefixPresetByComponentName());let R=S;const I={...R,adapters:{...te}},se=o.defineComponent({props:{setup:{type:Function,required:!0}},setup(r){const e=new ee(r.setup);return()=>e.exec()}});function re(r){const e=new X(r);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function ie(r){d.presets=r}function oe(r,e){return e==="raw"&&Object.defineProperty(r,"name",{value:`__proform_raw_${r.name}`,writable:!0}),r}exports.ProForm=se;exports.useForm=re;exports.useFormPresetConfigurer=ie;exports.useModifiers=oe;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
class
|
|
1
|
+
var re = Object.defineProperty;
|
|
2
|
+
var ie = (r, e, t) => e in r ? re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var a = (r, e, t) => (ie(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { isRef as U, watch as I, isReactive as x, toRaw as V, nextTick as w, ref as R, reactive as oe, createVNode as p, withDirectives as Y, mergeProps as M, vShow as Z, createTextVNode as ne, isVNode as le, defineComponent as ae } from "vue";
|
|
5
|
+
class l {
|
|
6
6
|
static typeChecker(e) {
|
|
7
7
|
return {}.toString.call(e);
|
|
8
8
|
}
|
|
@@ -63,18 +63,18 @@ class f {
|
|
|
63
63
|
return !1;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function m(
|
|
66
|
+
function m(r, ...e) {
|
|
67
67
|
return e.forEach((t) => {
|
|
68
68
|
if (Array.isArray(t))
|
|
69
|
-
Array.isArray(
|
|
70
|
-
typeof s == "object" && s !== null ?
|
|
69
|
+
Array.isArray(r) || (r = []), t.forEach((s, i) => {
|
|
70
|
+
typeof s == "object" && s !== null ? r[i] = m(Array.isArray(s) ? [] : {}, s) : r[i] = s;
|
|
71
71
|
});
|
|
72
72
|
else
|
|
73
73
|
for (let s in t)
|
|
74
|
-
t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ?
|
|
75
|
-
}),
|
|
74
|
+
t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? r[s] = m(r[s] || {}, t[s]) : r[s] = t[s]);
|
|
75
|
+
}), r;
|
|
76
76
|
}
|
|
77
|
-
function g(
|
|
77
|
+
function g(r) {
|
|
78
78
|
const e = /* @__PURE__ */ new WeakMap();
|
|
79
79
|
function t(s) {
|
|
80
80
|
if (s === null || typeof s != "object")
|
|
@@ -84,40 +84,40 @@ function g(o) {
|
|
|
84
84
|
if (s instanceof RegExp)
|
|
85
85
|
return new RegExp(s);
|
|
86
86
|
if (s instanceof Map) {
|
|
87
|
-
const
|
|
87
|
+
const o = /* @__PURE__ */ new Map();
|
|
88
88
|
for (let [n, u] of s)
|
|
89
|
-
|
|
90
|
-
return
|
|
89
|
+
o.set(t(n), t(u));
|
|
90
|
+
return o;
|
|
91
91
|
}
|
|
92
92
|
if (s instanceof Set) {
|
|
93
|
-
const
|
|
93
|
+
const o = /* @__PURE__ */ new Set();
|
|
94
94
|
for (let n of s)
|
|
95
|
-
|
|
96
|
-
return
|
|
95
|
+
o.add(t(n));
|
|
96
|
+
return o;
|
|
97
97
|
}
|
|
98
98
|
if (e.has(s))
|
|
99
99
|
return e.get(s);
|
|
100
100
|
if (Array.isArray(s)) {
|
|
101
|
-
const
|
|
102
|
-
e.set(s,
|
|
101
|
+
const o = [];
|
|
102
|
+
e.set(s, o);
|
|
103
103
|
for (let n = 0; n < s.length; n++)
|
|
104
|
-
|
|
105
|
-
return
|
|
104
|
+
o[n] = t(s[n]);
|
|
105
|
+
return o;
|
|
106
106
|
}
|
|
107
|
-
const
|
|
108
|
-
e.set(s,
|
|
109
|
-
for (let
|
|
110
|
-
s.hasOwnProperty(
|
|
111
|
-
return
|
|
107
|
+
const i = Object.create(Object.getPrototypeOf(s));
|
|
108
|
+
e.set(s, i);
|
|
109
|
+
for (let o in s)
|
|
110
|
+
s.hasOwnProperty(o) && (i[o] = t(s[o]));
|
|
111
|
+
return i;
|
|
112
112
|
}
|
|
113
|
-
return t(
|
|
113
|
+
return t(r);
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
return
|
|
115
|
+
function q(r, e) {
|
|
116
|
+
return r.replace(/undefined/g, e);
|
|
117
117
|
}
|
|
118
|
-
class
|
|
118
|
+
class ue {
|
|
119
119
|
constructor(e) {
|
|
120
|
-
|
|
120
|
+
a(this, "runtimeCore");
|
|
121
121
|
this.formCustomization = e;
|
|
122
122
|
}
|
|
123
123
|
// happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
|
|
@@ -127,19 +127,12 @@ class ne {
|
|
|
127
127
|
})), e;
|
|
128
128
|
}
|
|
129
129
|
setup(e) {
|
|
130
|
-
return this.runtimeCore = e, Object.assign(this.runtimeCore.native, this.formCustomization.native), Object.assign(this.runtimeCore.
|
|
131
|
-
this.runtimeCore.runtimeSetters,
|
|
132
|
-
this.formCustomization.runtimeSetters
|
|
133
|
-
), this.formCustomization;
|
|
130
|
+
return this.runtimeCore = e, Object.assign(this.runtimeCore.native, this.formCustomization.native), Object.assign(this.runtimeCore.grid, this.formCustomization.grid), Object.assign(this.runtimeCore.runtime, this.formCustomization.runtime), this.formCustomization.ui && (this.runtimeCore.ui = this.formCustomization.ui), this.formCustomization;
|
|
134
131
|
}
|
|
135
132
|
submit() {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
O(this.runtimeCore.processor.processedModel.value)
|
|
140
|
-
)
|
|
141
|
-
));
|
|
142
|
-
});
|
|
133
|
+
var s;
|
|
134
|
+
const e = (s = f.presets.uiPresets[this.runtimeCore.ui]) == null ? void 0 : s.adapter, t = j.adapters[this.runtimeCore.ui];
|
|
135
|
+
return (e == null ? void 0 : e.validateForm(this)) ?? (t == null ? void 0 : t.validateForm(this));
|
|
143
136
|
}
|
|
144
137
|
hydrate(e) {
|
|
145
138
|
if (!this.runtimeCore)
|
|
@@ -149,7 +142,7 @@ class ne {
|
|
|
149
142
|
});
|
|
150
143
|
this.runtimeCore.hydrateEffect.trackEffect(
|
|
151
144
|
() => {
|
|
152
|
-
|
|
145
|
+
U(e) ? I(
|
|
153
146
|
() => e.value,
|
|
154
147
|
() => {
|
|
155
148
|
m(this.runtimeCore.model.value, e.value);
|
|
@@ -158,7 +151,7 @@ class ne {
|
|
|
158
151
|
deep: !0,
|
|
159
152
|
immediate: !0
|
|
160
153
|
}
|
|
161
|
-
) :
|
|
154
|
+
) : x(e) ? I(
|
|
162
155
|
() => e,
|
|
163
156
|
() => {
|
|
164
157
|
m(this.runtimeCore.model.value, e);
|
|
@@ -175,9 +168,9 @@ class ne {
|
|
|
175
168
|
);
|
|
176
169
|
}
|
|
177
170
|
}
|
|
178
|
-
class
|
|
171
|
+
class N {
|
|
179
172
|
constructor() {
|
|
180
|
-
|
|
173
|
+
a(this, "effects", /* @__PURE__ */ new Set());
|
|
181
174
|
}
|
|
182
175
|
clearEffects() {
|
|
183
176
|
this.effects.clear();
|
|
@@ -191,23 +184,23 @@ class x {
|
|
|
191
184
|
return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
|
|
192
185
|
}
|
|
193
186
|
}
|
|
194
|
-
class
|
|
187
|
+
class ce {
|
|
195
188
|
constructor(e) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e),
|
|
189
|
+
a(this, "runtimeCore");
|
|
190
|
+
a(this, "processedSchemas");
|
|
191
|
+
a(this, "processedModel");
|
|
192
|
+
a(this, "getRuntimeMeta");
|
|
193
|
+
a(this, "stableSchemas", []);
|
|
194
|
+
a(this, "stableModel", {});
|
|
195
|
+
a(this, "schemaPreset", j.schemaPreset);
|
|
196
|
+
a(this, "componentPropsPreset", j.componentPropsPreset);
|
|
197
|
+
a(this, "stableUpdaterProcessProgress");
|
|
198
|
+
a(this, "stableUpdaterTimes", 0);
|
|
199
|
+
a(this, "schemaEffect", new N());
|
|
200
|
+
a(this, "defaultValueEffect", new N());
|
|
201
|
+
a(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
|
|
202
|
+
a(this, "baseDefaultValueFunctionsLength");
|
|
203
|
+
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), I(
|
|
211
204
|
() => this.processedModel.value,
|
|
212
205
|
() => {
|
|
213
206
|
this.schemaEffect.triggerEffects();
|
|
@@ -219,8 +212,8 @@ class le {
|
|
|
219
212
|
}
|
|
220
213
|
// 核心处理过程,接收一个初始的代理数据结构,由其衍生的有 parseSchema
|
|
221
214
|
parse(e, t) {
|
|
222
|
-
e.forEach((s,
|
|
223
|
-
this.parseItem(s,
|
|
215
|
+
e.forEach((s, i) => {
|
|
216
|
+
this.parseItem(s, i, t);
|
|
224
217
|
});
|
|
225
218
|
}
|
|
226
219
|
// 初始化空数据结构,避免后续复杂的 if else
|
|
@@ -232,24 +225,24 @@ class le {
|
|
|
232
225
|
}
|
|
233
226
|
countFunctionDefaultValues(e) {
|
|
234
227
|
let t = 0, s = /* @__PURE__ */ new Set();
|
|
235
|
-
function
|
|
236
|
-
if (!s.has(
|
|
237
|
-
s.add(
|
|
238
|
-
for (let n in
|
|
239
|
-
|
|
228
|
+
function i(o) {
|
|
229
|
+
if (!s.has(o) && (Array.isArray(o) || o !== null && typeof o == "object")) {
|
|
230
|
+
s.add(o);
|
|
231
|
+
for (let n in o)
|
|
232
|
+
o.hasOwnProperty(n) && (n === "defaultValue" && typeof o[n] == "function" && !o[n].toString().includes("[native code]") && t++, i(o[n]));
|
|
240
233
|
}
|
|
241
234
|
}
|
|
242
|
-
return
|
|
235
|
+
return i(e), t;
|
|
243
236
|
}
|
|
244
237
|
// 派生过程,用于外部应用
|
|
245
238
|
parseSchemas(e, t) {
|
|
246
|
-
|
|
239
|
+
l.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
|
|
247
240
|
g(e)
|
|
248
241
|
), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
|
|
249
242
|
}
|
|
250
243
|
parseStable(e) {
|
|
251
244
|
const t = {};
|
|
252
|
-
if (!
|
|
245
|
+
if (!l.isUndefined(e.stable))
|
|
253
246
|
t[e.key] = this.parseStable(e.stable);
|
|
254
247
|
else
|
|
255
248
|
return e;
|
|
@@ -258,110 +251,110 @@ class le {
|
|
|
258
251
|
// 对于稳定初始化更新的抽象
|
|
259
252
|
stableUpdater(e = []) {
|
|
260
253
|
if (e.every(Boolean)) {
|
|
261
|
-
const t =
|
|
262
|
-
!
|
|
254
|
+
const t = V(this.processedSchemas.value);
|
|
255
|
+
!l.isProcessInprogress(t) && l.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
|
|
263
256
|
length: t.length
|
|
264
257
|
}).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
|
|
265
258
|
}
|
|
266
259
|
}
|
|
267
260
|
// 核心单 schema 处理过程,接收一个对象键值对的数据结构
|
|
268
261
|
parseItem(e, t, s) {
|
|
269
|
-
const
|
|
262
|
+
const i = this, o = Array.from({
|
|
270
263
|
length: Object.keys(e).filter((u) => u !== "children").length
|
|
271
264
|
}).fill(!1);
|
|
272
265
|
this.objectParser({ data: e, index: t, updater: n });
|
|
273
266
|
function n(u) {
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
267
|
+
const c = u.index, d = u.key, y = u.keyIndex;
|
|
268
|
+
if (l.isUndefined(u.stable))
|
|
276
269
|
return;
|
|
277
|
-
const
|
|
278
|
-
let
|
|
279
|
-
if (
|
|
280
|
-
let h =
|
|
281
|
-
h &&
|
|
270
|
+
const O = i.parseStable(u.stable), v = s == null ? void 0 : s.index, P = s == null ? void 0 : s.key;
|
|
271
|
+
let b = O;
|
|
272
|
+
if (l.isProcessInprogress(b) || (o[y] = !0), s) {
|
|
273
|
+
let h = i.processedSchemas.value[v][P][c][d];
|
|
274
|
+
h && l.isObject(h) && d !== "component" && (b = m(h, b)), i.processedSchemas.value[v][P][c][d] = b, i.stableUpdater(o);
|
|
282
275
|
} else {
|
|
283
|
-
let h =
|
|
284
|
-
h &&
|
|
276
|
+
let h = i.processedSchemas.value[c][d];
|
|
277
|
+
h && l.isObject(h) && d !== "component" && (b = m(h, b)), i.processedSchemas.value[c][d] = b, i.stableUpdater(o);
|
|
285
278
|
}
|
|
286
279
|
}
|
|
287
280
|
}
|
|
288
281
|
// 只做基本的对象 parser
|
|
289
282
|
objectParser(e) {
|
|
290
283
|
const t = e.data;
|
|
291
|
-
Object.keys(t).forEach((
|
|
292
|
-
if (
|
|
293
|
-
this.parseSchemas(t[
|
|
284
|
+
Object.keys(t).forEach((i, o) => {
|
|
285
|
+
if (i === "children")
|
|
286
|
+
this.parseSchemas(t[i], {
|
|
294
287
|
...e,
|
|
295
|
-
key:
|
|
296
|
-
keyIndex:
|
|
288
|
+
key: i,
|
|
289
|
+
keyIndex: o
|
|
297
290
|
});
|
|
298
291
|
else {
|
|
299
292
|
const n = (u) => {
|
|
300
293
|
e.updater({
|
|
301
294
|
...e,
|
|
302
|
-
key:
|
|
303
|
-
keyIndex:
|
|
295
|
+
key: i,
|
|
296
|
+
keyIndex: o,
|
|
304
297
|
stable: u
|
|
305
298
|
});
|
|
306
299
|
};
|
|
307
|
-
|
|
308
|
-
if (
|
|
309
|
-
const u = t[
|
|
300
|
+
l.isFunction(t[i]) ? i !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
301
|
+
if (i === "component") {
|
|
302
|
+
const u = t[i](this.getRuntimeMeta());
|
|
310
303
|
this.promiseFieldParser(u, n, !1);
|
|
311
304
|
} else
|
|
312
|
-
this.fieldParser(t[
|
|
305
|
+
this.fieldParser(t[i], n);
|
|
313
306
|
}) : this.defaultValueEffect.trackEffect(() => {
|
|
314
307
|
const u = this.schemaEffect.trackEffect(() => {
|
|
315
|
-
/\{\s*model\s*\}/.test(t[
|
|
316
|
-
if (!
|
|
317
|
-
return n(
|
|
318
|
-
this.defaultValueInprogressMap.set(t[
|
|
308
|
+
/\{\s*model\s*\}/.test(t[i].toString()) ? this.fieldParser(t[i], (c) => {
|
|
309
|
+
if (!c)
|
|
310
|
+
return n(c);
|
|
311
|
+
this.defaultValueInprogressMap.set(t[i], c), !l.isProcessInprogress(c) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
319
312
|
(d) => !d.includes("undefined")
|
|
320
|
-
) ? (n(
|
|
313
|
+
) ? (n(c), this.defaultValueEffect.clearEffects(), w(() => {
|
|
321
314
|
u();
|
|
322
|
-
})) : n(
|
|
323
|
-
}) : this.fieldParser(t[
|
|
324
|
-
this.defaultValueInprogressMap.set(t[
|
|
315
|
+
})) : n(c);
|
|
316
|
+
}) : this.fieldParser(t[i], (c) => {
|
|
317
|
+
this.defaultValueInprogressMap.set(t[i], c), !l.isProcessInprogress(c) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
325
318
|
(d) => !d.includes("undefined")
|
|
326
|
-
) ? (n(
|
|
319
|
+
) ? (n(c), this.defaultValueEffect.clearEffects(), w(() => {
|
|
327
320
|
u();
|
|
328
|
-
})) : n(
|
|
321
|
+
})) : n(c);
|
|
329
322
|
});
|
|
330
323
|
});
|
|
331
|
-
}) :
|
|
324
|
+
}) : i === "component" || i === "slots" || i === "runtime" ? this.promiseFieldParser(t[i], n, !1) : this.fieldParser(t[i], n);
|
|
332
325
|
}
|
|
333
326
|
});
|
|
334
327
|
}
|
|
335
328
|
promiseFieldParser(e, t, s) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
data:
|
|
329
|
+
l.isPromise(e) ? e.then((i) => {
|
|
330
|
+
l.isString(i) && (i = q(i, "")), s && l.isObject(i) ? this.objectParser({
|
|
331
|
+
data: i,
|
|
339
332
|
updater: t
|
|
340
|
-
}) : t(
|
|
341
|
-
}) : (
|
|
333
|
+
}) : t(i);
|
|
334
|
+
}) : (l.isString(e) && (e = q(e, "")), s && l.isObject(e) ? this.objectParser({
|
|
342
335
|
data: e,
|
|
343
336
|
updater: t
|
|
344
337
|
}) : t(e));
|
|
345
338
|
}
|
|
346
339
|
// 对任意对象中单个字段的 parse: 做基本处理
|
|
347
340
|
fieldParser(e, t, s = !0) {
|
|
348
|
-
if (
|
|
341
|
+
if (l.isFunction(e))
|
|
349
342
|
if (e.name.startsWith("__proform_raw_"))
|
|
350
|
-
t((...
|
|
343
|
+
t((...i) => {
|
|
351
344
|
e({
|
|
352
|
-
rawArgs:
|
|
345
|
+
rawArgs: i,
|
|
353
346
|
...this.getRuntimeMeta()
|
|
354
347
|
});
|
|
355
348
|
});
|
|
356
349
|
else {
|
|
357
|
-
const
|
|
358
|
-
this.promiseFieldParser(
|
|
350
|
+
const i = e(this.getRuntimeMeta());
|
|
351
|
+
this.promiseFieldParser(i, t, s);
|
|
359
352
|
}
|
|
360
353
|
else
|
|
361
|
-
|
|
354
|
+
U(e) ? I(
|
|
362
355
|
() => e.value,
|
|
363
356
|
() => {
|
|
364
|
-
|
|
357
|
+
l.isUndefined(e.value) || (s && l.isObject(e.value) ? this.objectParser({
|
|
365
358
|
data: e.value,
|
|
366
359
|
updater: t
|
|
367
360
|
}) : t(e.value));
|
|
@@ -370,10 +363,10 @@ class le {
|
|
|
370
363
|
immediate: !0,
|
|
371
364
|
deep: !0
|
|
372
365
|
}
|
|
373
|
-
) :
|
|
366
|
+
) : x(e) ? I(
|
|
374
367
|
() => e,
|
|
375
368
|
() => {
|
|
376
|
-
|
|
369
|
+
l.isUndefined(e) || (s && l.isObject(e) ? this.objectParser({
|
|
377
370
|
data: e,
|
|
378
371
|
updater: t
|
|
379
372
|
}) : t(e));
|
|
@@ -382,7 +375,7 @@ class le {
|
|
|
382
375
|
immediate: !0,
|
|
383
376
|
deep: !0
|
|
384
377
|
}
|
|
385
|
-
) : s &&
|
|
378
|
+
) : s && l.isObject(e) ? this.objectParser({
|
|
386
379
|
data: e,
|
|
387
380
|
updater: t
|
|
388
381
|
}) : t(e);
|
|
@@ -390,50 +383,90 @@ class le {
|
|
|
390
383
|
modelProcessor(e) {
|
|
391
384
|
e.map(
|
|
392
385
|
(t) => this.createModel(t, this.processedModel.value)
|
|
393
|
-
),
|
|
386
|
+
), l.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = g(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
|
|
394
387
|
}
|
|
395
388
|
createModel(e, t) {
|
|
396
|
-
|
|
389
|
+
l.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
|
|
397
390
|
this.createModel(s, t[e.field][0]);
|
|
398
|
-
})),
|
|
391
|
+
})), l.isGroupSchema(e) && e.children.forEach((s) => {
|
|
399
392
|
this.createModel(s, t);
|
|
400
|
-
}),
|
|
393
|
+
}), l.isItemSchema(e) && (t[e.field] = e.defaultValue);
|
|
401
394
|
}
|
|
402
395
|
}
|
|
403
|
-
|
|
404
|
-
|
|
396
|
+
class F {
|
|
397
|
+
static getFormContainer({ ui: e } = {}) {
|
|
398
|
+
return f.presets.uiPresets[e ?? f.presets.ui].container.Form;
|
|
399
|
+
}
|
|
400
|
+
static getFormItemContainer({ ui: e } = {}) {
|
|
401
|
+
return f.presets.uiPresets[e ?? f.presets.ui].container.FormItem;
|
|
402
|
+
}
|
|
403
|
+
static getItemContainer({ ui: e } = {}) {
|
|
404
|
+
return f.presets.uiPresets[e ?? f.presets.ui].container.Item;
|
|
405
|
+
}
|
|
406
|
+
static getGroupContainer({ ui: e } = {}) {
|
|
407
|
+
return f.presets.uiPresets[e ?? f.presets.ui].container.Group;
|
|
408
|
+
}
|
|
409
|
+
static getListContainer({ ui: e } = {}) {
|
|
410
|
+
return f.presets.uiPresets[e ?? f.presets.ui].container.List;
|
|
411
|
+
}
|
|
412
|
+
static getListItemContainer({ ui: e } = {}) {
|
|
413
|
+
return f.presets.uiPresets[e ?? f.presets.ui].container.ListItem;
|
|
414
|
+
}
|
|
405
415
|
}
|
|
406
|
-
class
|
|
416
|
+
class fe {
|
|
407
417
|
constructor(e) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
418
|
+
this.ui = e;
|
|
419
|
+
}
|
|
420
|
+
getRuntimeField(e) {
|
|
421
|
+
var i;
|
|
422
|
+
const t = (i = f.presets.uiPresets[this.ui]) == null ? void 0 : i.adapter, s = j.adapters[this.ui];
|
|
423
|
+
return (t == null ? void 0 : t.getRuntimeField(e)) ?? (s == null ? void 0 : s.getRuntimeField(e));
|
|
424
|
+
}
|
|
425
|
+
getRuntimeRequired(e) {
|
|
426
|
+
var i;
|
|
427
|
+
const t = (i = f.presets.uiPresets[this.ui]) == null ? void 0 : i.adapter, s = j.adapters[this.ui];
|
|
428
|
+
return (t == null ? void 0 : t.getRuntimeRequired(e)) ?? (s == null ? void 0 : s.getRuntimeRequired(e));
|
|
429
|
+
}
|
|
430
|
+
getFormModelPropName() {
|
|
431
|
+
var s;
|
|
432
|
+
const e = (s = f.presets.uiPresets[this.ui]) == null ? void 0 : s.adapter, t = j.adapters[this.ui];
|
|
433
|
+
return (e == null ? void 0 : e.getFormModelPropName()) ?? (t == null ? void 0 : t.getFormModelPropName());
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function de(r) {
|
|
437
|
+
return typeof r == "function" || Object.prototype.toString.call(r) === "[object Object]" && !le(r);
|
|
438
|
+
}
|
|
439
|
+
class pe {
|
|
440
|
+
constructor(e) {
|
|
441
|
+
a(this, "schemas", R([]));
|
|
442
|
+
a(this, "model", R({}));
|
|
443
|
+
a(this, "processorBySchemaType", {
|
|
411
444
|
item: this.runtimeItemProcessor.bind(this),
|
|
412
445
|
group: this.runtimeGroupProcessor.bind(this),
|
|
413
446
|
list: this.runtimeListProcessor.bind(this)
|
|
414
447
|
});
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
448
|
+
a(this, "formRef", R(null));
|
|
449
|
+
a(this, "hydrateEffect", new N());
|
|
450
|
+
a(this, "native", oe({}));
|
|
451
|
+
a(this, "grid", {});
|
|
452
|
+
a(this, "runtime", {});
|
|
453
|
+
a(this, "globalNativeFormOverride", {
|
|
421
454
|
props: {},
|
|
422
455
|
slots: {}
|
|
423
456
|
});
|
|
424
|
-
this.setup = e, this.processor = new
|
|
457
|
+
this.setup = e, this.processor = new ce(this);
|
|
425
458
|
const t = this.setup(this);
|
|
426
|
-
if (
|
|
427
|
-
const s =
|
|
428
|
-
this.processor.parseSchemas(t.schemas.value),
|
|
459
|
+
if (this.ui = t.ui ?? f.presets.ui, this.runtimeAdapter = new fe(this.ui), U(t.schemas)) {
|
|
460
|
+
const s = I(() => t.schemas, () => {
|
|
461
|
+
this.processor.parseSchemas(t.schemas.value), w(() => {
|
|
429
462
|
s();
|
|
430
463
|
});
|
|
431
464
|
}, {
|
|
432
465
|
deep: !0
|
|
433
466
|
});
|
|
434
|
-
} else if (
|
|
435
|
-
const s =
|
|
436
|
-
this.processor.parseSchemas(t.schemas),
|
|
467
|
+
} else if (x(t.schemas)) {
|
|
468
|
+
const s = I(() => t.schemas, () => {
|
|
469
|
+
this.processor.parseSchemas(t.schemas), w(() => {
|
|
437
470
|
s();
|
|
438
471
|
});
|
|
439
472
|
}, {
|
|
@@ -444,65 +477,55 @@ class ae {
|
|
|
444
477
|
}
|
|
445
478
|
getRuntimeMeta() {
|
|
446
479
|
return {
|
|
447
|
-
model:
|
|
480
|
+
model: V(g(this.model.value))
|
|
448
481
|
};
|
|
449
482
|
}
|
|
450
|
-
runtimeItemProcessor(e, t, s = this.model.value,
|
|
451
|
-
var
|
|
452
|
-
|
|
453
|
-
|
|
483
|
+
runtimeItemProcessor(e, t, s = this.model.value, i) {
|
|
484
|
+
var k, z, _, $, B, D, G, T, K, W, H, J, Q;
|
|
485
|
+
const o = V(e.component);
|
|
486
|
+
if (!o)
|
|
487
|
+
return;
|
|
488
|
+
m(this.globalNativeFormOverride.props, (z = (k = e.native) == null ? void 0 : k.props) == null ? void 0 : z.Form), m(this.globalNativeFormOverride.slots, ($ = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : $.Form);
|
|
489
|
+
const n = m(g((D = (B = this.native) == null ? void 0 : B.slots) == null ? void 0 : D.FormItem) ?? {}, (T = (G = e.native) == null ? void 0 : G.slots) == null ? void 0 : T.FormItem), u = {
|
|
454
490
|
display: "grid",
|
|
455
491
|
gridColumn: "1 / -1",
|
|
456
|
-
...e.
|
|
457
|
-
},
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}), b = `${p}${S}`);
|
|
473
|
-
}
|
|
474
|
-
if (y)
|
|
475
|
-
if (!e.rules)
|
|
476
|
-
e.rules = [], (Q = e.rules) == null || Q.push({
|
|
477
|
-
required: !0,
|
|
478
|
-
message: `${S}是必填项`
|
|
479
|
-
});
|
|
480
|
-
else {
|
|
481
|
-
const p = e.rules.findIndex((C) => !f.isUndefined(C.required));
|
|
482
|
-
p !== -1 && (e.rules[p].required = !0, e.rules[p].message = `${S}是必填项`);
|
|
483
|
-
}
|
|
484
|
-
else if (e.rules) {
|
|
485
|
-
const p = (X = e.rules) == null ? void 0 : X.findIndex((C) => !!C.required);
|
|
486
|
-
p !== -1 && (e.rules[p].required = !1);
|
|
492
|
+
...e.grid
|
|
493
|
+
}, c = m(g((W = (K = this.native) == null ? void 0 : K.props) == null ? void 0 : W.FormItem) ?? {}, (J = (H = e.native) == null ? void 0 : H.props) == null ? void 0 : J.FormItem), d = this.runtimeAdapter.getRuntimeField({
|
|
494
|
+
schema: e,
|
|
495
|
+
parentSchema: i,
|
|
496
|
+
index: t
|
|
497
|
+
}), y = o.name, O = e.componentProps ?? {}, v = j.placeholderPresetByComponentName;
|
|
498
|
+
let P = e.placeholder, b = e.show;
|
|
499
|
+
b === void 0 && (b = !0), b || delete s[e.field];
|
|
500
|
+
let h = e.label;
|
|
501
|
+
const E = (i == null ? void 0 : i.runtime) ?? this.runtime;
|
|
502
|
+
if (!l.isUndefined(t) && !l.isObjectEmpty(E) && (h = q((Q = E == null ? void 0 : E.customizeItemLabel) == null ? void 0 : Q.call(E, e.label ?? "", t + 1), "")), !P) {
|
|
503
|
+
let C = "请输入";
|
|
504
|
+
l.isUndefined(y) ? P = `${C}${h}` : /* @ts-expect-error */ v[y.toLowerCase()] ? (C = // @ts-expect-error
|
|
505
|
+
v[y.toLowerCase()], P = `${C}${h}`) : (Object.keys(v).forEach((X) => {
|
|
506
|
+
y.toLowerCase().includes(X.toLowerCase()) && (C = v[X]);
|
|
507
|
+
}), P = `${C}${h}`);
|
|
487
508
|
}
|
|
488
|
-
|
|
509
|
+
const ee = this.runtimeAdapter.getRuntimeRequired({
|
|
510
|
+
...e,
|
|
511
|
+
label: h
|
|
512
|
+
}), te = F.getItemContainer(this), se = F.getFormItemContainer(this);
|
|
513
|
+
return p("div", {
|
|
489
514
|
style: u
|
|
490
|
-
}, [
|
|
515
|
+
}, [p(te, null, {
|
|
491
516
|
default() {
|
|
492
|
-
return Y(
|
|
493
|
-
label: `${
|
|
494
|
-
|
|
495
|
-
field: a
|
|
496
|
-
}), {
|
|
517
|
+
return Y(p(se, M(c, {
|
|
518
|
+
label: `${h}:`
|
|
519
|
+
}, d, ee), {
|
|
497
520
|
default() {
|
|
498
|
-
return
|
|
521
|
+
return p(o, M({
|
|
499
522
|
modelValue: s[e.field],
|
|
500
|
-
"onUpdate:modelValue": (
|
|
501
|
-
placeholder:
|
|
502
|
-
},
|
|
523
|
+
"onUpdate:modelValue": (C) => s[e.field] = C,
|
|
524
|
+
placeholder: P
|
|
525
|
+
}, O), null);
|
|
503
526
|
},
|
|
504
527
|
...n
|
|
505
|
-
}), [[Z,
|
|
528
|
+
}), [[Z, b]]);
|
|
506
529
|
}
|
|
507
530
|
})]);
|
|
508
531
|
}
|
|
@@ -511,13 +534,13 @@ class ae {
|
|
|
511
534
|
const s = {
|
|
512
535
|
display: "grid",
|
|
513
536
|
gridColumn: "1 / -1",
|
|
514
|
-
...e.
|
|
515
|
-
};
|
|
516
|
-
return
|
|
537
|
+
...e.grid
|
|
538
|
+
}, i = F.getGroupContainer(this);
|
|
539
|
+
return p("div", {
|
|
517
540
|
style: s
|
|
518
|
-
}, [
|
|
541
|
+
}, [p(i, {
|
|
519
542
|
schema: e
|
|
520
|
-
},
|
|
543
|
+
}, de(t = e.children.map((o) => this.runtimeItemProcessor(o))) ? t : {
|
|
521
544
|
default: () => [t]
|
|
522
545
|
})]);
|
|
523
546
|
}
|
|
@@ -537,34 +560,36 @@ class ae {
|
|
|
537
560
|
const t = {
|
|
538
561
|
display: "grid",
|
|
539
562
|
gridColumn: "1 / -1",
|
|
540
|
-
...e.
|
|
563
|
+
...e.grid
|
|
541
564
|
}, s = this;
|
|
542
|
-
|
|
565
|
+
s.model.value[e.field] || (s.model.value[e.field] = [{}]);
|
|
566
|
+
const i = F.getListContainer(this), o = F.getListItemContainer(this);
|
|
567
|
+
return p("div", {
|
|
543
568
|
style: t
|
|
544
|
-
}, [
|
|
569
|
+
}, [p(i, {
|
|
545
570
|
schema: e
|
|
546
571
|
}, {
|
|
547
572
|
default() {
|
|
548
|
-
return s.model.value[e.field].map((
|
|
573
|
+
return s.model.value[e.field].map((n, u) => p(o, null, {
|
|
549
574
|
default() {
|
|
550
|
-
return e.children.map((
|
|
575
|
+
return e.children.map((c) => s.runtimeItemProcessor(c, u, n, e));
|
|
551
576
|
},
|
|
552
577
|
delete({
|
|
553
|
-
container:
|
|
578
|
+
container: c
|
|
554
579
|
} = {}) {
|
|
555
|
-
var
|
|
556
|
-
let
|
|
557
|
-
return Y(
|
|
558
|
-
onClick: () => s.deleteListItem(e,
|
|
559
|
-
}, null), [[Z, ((
|
|
580
|
+
var y;
|
|
581
|
+
let d = c ?? p("button", null, null);
|
|
582
|
+
return Y(p(d, {
|
|
583
|
+
onClick: () => s.deleteListItem(e, u)
|
|
584
|
+
}, null), [[Z, ((y = s.model.value[e.field]) == null ? void 0 : y.length) > 1]]);
|
|
560
585
|
}
|
|
561
586
|
}));
|
|
562
587
|
},
|
|
563
588
|
add({
|
|
564
|
-
container:
|
|
589
|
+
container: n
|
|
565
590
|
} = {}) {
|
|
566
|
-
let
|
|
567
|
-
return
|
|
591
|
+
let u = n ?? p("button", null, [ne("添加")]);
|
|
592
|
+
return p(u, {
|
|
568
593
|
onClick: () => s.addListItem(e)
|
|
569
594
|
}, null);
|
|
570
595
|
}
|
|
@@ -574,43 +599,137 @@ class ae {
|
|
|
574
599
|
return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
|
|
575
600
|
}
|
|
576
601
|
exec() {
|
|
577
|
-
var
|
|
602
|
+
var u, c, d, y;
|
|
578
603
|
const e = {
|
|
579
604
|
display: "grid",
|
|
580
605
|
gridColumn: "1 / -1",
|
|
581
606
|
gridAutoColumns: "1fr",
|
|
582
|
-
...this.
|
|
583
|
-
}, t = this, s = m(g((
|
|
584
|
-
return
|
|
585
|
-
ref: this.formRef
|
|
586
|
-
|
|
607
|
+
...this.grid
|
|
608
|
+
}, t = this, s = m(g((c = (u = this.native) == null ? void 0 : u.props) == null ? void 0 : c.Form) ?? {}, this.globalNativeFormOverride.props), i = m(g((y = (d = this.native) == null ? void 0 : d.slots) == null ? void 0 : y.Form) ?? {}, this.globalNativeFormOverride.slots), o = F.getFormContainer(this), n = this.runtimeAdapter.getFormModelPropName();
|
|
609
|
+
return p(o, M(s, {
|
|
610
|
+
ref: this.formRef
|
|
611
|
+
}, {
|
|
612
|
+
[n]: this.model.value
|
|
587
613
|
}), {
|
|
588
614
|
default() {
|
|
589
|
-
return
|
|
615
|
+
return p("div", {
|
|
590
616
|
style: e
|
|
591
617
|
}, [t.runtimeProcessor(t.schemas.value)]);
|
|
592
618
|
},
|
|
593
|
-
...
|
|
619
|
+
...i
|
|
594
620
|
});
|
|
595
621
|
}
|
|
596
622
|
}
|
|
597
|
-
class
|
|
623
|
+
class f {
|
|
624
|
+
}
|
|
625
|
+
a(f, "presets");
|
|
626
|
+
function A({ parentSchema: r, schema: e, index: t }) {
|
|
627
|
+
return r ? `${r.field}.${t}.${e.field}` : e.field;
|
|
598
628
|
}
|
|
599
|
-
|
|
600
|
-
|
|
629
|
+
const he = {
|
|
630
|
+
ArcoVue: {
|
|
631
|
+
getRuntimeField(r) {
|
|
632
|
+
return {
|
|
633
|
+
field: A(r)
|
|
634
|
+
};
|
|
635
|
+
},
|
|
636
|
+
getRuntimeRequired(r) {
|
|
637
|
+
var e, t;
|
|
638
|
+
if (r.required)
|
|
639
|
+
if (!r.rules)
|
|
640
|
+
r.rules = [], (e = r.rules) == null || e.push({
|
|
641
|
+
required: !0,
|
|
642
|
+
message: `${r.label}是必填项`
|
|
643
|
+
});
|
|
644
|
+
else {
|
|
645
|
+
const s = r.rules.findIndex(
|
|
646
|
+
(i) => !l.isUndefined(i.required)
|
|
647
|
+
);
|
|
648
|
+
s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
|
|
649
|
+
}
|
|
650
|
+
else if (r.rules) {
|
|
651
|
+
const s = (t = r.rules) == null ? void 0 : t.findIndex(
|
|
652
|
+
(i) => !!i.required
|
|
653
|
+
);
|
|
654
|
+
s !== -1 && (r.rules[s].required = !1);
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
rules: r.rules
|
|
658
|
+
};
|
|
659
|
+
},
|
|
660
|
+
getFormModelPropName() {
|
|
661
|
+
return "model";
|
|
662
|
+
},
|
|
663
|
+
validateForm(r) {
|
|
664
|
+
return new Promise((e, t) => {
|
|
665
|
+
r.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
|
|
666
|
+
r.cleanFallbackFields(
|
|
667
|
+
V(r.runtimeCore.processor.processedModel.value)
|
|
668
|
+
)
|
|
669
|
+
));
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
NutUI: {
|
|
674
|
+
getRuntimeField(r) {
|
|
675
|
+
return {
|
|
676
|
+
prop: A(r)
|
|
677
|
+
};
|
|
678
|
+
},
|
|
679
|
+
getRuntimeRequired(r) {
|
|
680
|
+
var e, t;
|
|
681
|
+
if (r.required)
|
|
682
|
+
if (!r.rules)
|
|
683
|
+
r.rules = [], (e = r.rules) == null || e.push({
|
|
684
|
+
required: !0,
|
|
685
|
+
message: `${r.label}是必填项`
|
|
686
|
+
});
|
|
687
|
+
else {
|
|
688
|
+
const s = r.rules.findIndex(
|
|
689
|
+
(i) => !l.isUndefined(i.required)
|
|
690
|
+
);
|
|
691
|
+
s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
|
|
692
|
+
}
|
|
693
|
+
else if (r.rules) {
|
|
694
|
+
const s = (t = r.rules) == null ? void 0 : t.findIndex(
|
|
695
|
+
(i) => !!i.required
|
|
696
|
+
);
|
|
697
|
+
s !== -1 && (r.rules[s].required = !1);
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
rules: r.rules,
|
|
701
|
+
required: r.required
|
|
702
|
+
};
|
|
703
|
+
},
|
|
704
|
+
getFormModelPropName() {
|
|
705
|
+
return "modelValue";
|
|
706
|
+
},
|
|
707
|
+
validateForm(r) {
|
|
708
|
+
return new Promise((e, t) => {
|
|
709
|
+
r.runtimeCore.formRef.value.validate().then(({ valid: s, errors: i }) => {
|
|
710
|
+
s ? e(
|
|
711
|
+
r.cleanFallbackFields(
|
|
712
|
+
V(r.runtimeCore.processor.processedModel.value)
|
|
713
|
+
)
|
|
714
|
+
) : t(i);
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}, S = class S {
|
|
601
720
|
static getPlaceholderPrefixPresetByComponentName() {
|
|
602
721
|
const e = {
|
|
603
|
-
请选择: ["select", "tree"
|
|
722
|
+
请选择: ["select", "tree"],
|
|
604
723
|
请输入: ["input"]
|
|
605
724
|
}, t = {};
|
|
606
725
|
for (let s in e)
|
|
607
|
-
e[s].forEach((
|
|
608
|
-
t[
|
|
726
|
+
e[s].forEach((i) => {
|
|
727
|
+
t[i] = s;
|
|
609
728
|
});
|
|
610
729
|
return t;
|
|
611
730
|
}
|
|
612
731
|
};
|
|
613
|
-
|
|
732
|
+
a(S, "schemaPreset", {
|
|
614
733
|
type: {
|
|
615
734
|
defaultValue: "item"
|
|
616
735
|
},
|
|
@@ -644,29 +763,38 @@ l(V, "schemaPreset", {
|
|
|
644
763
|
children: {
|
|
645
764
|
defaultValue: []
|
|
646
765
|
},
|
|
647
|
-
native:
|
|
648
|
-
|
|
649
|
-
}
|
|
766
|
+
native: {
|
|
767
|
+
defaultValue: void 0
|
|
768
|
+
},
|
|
769
|
+
grid: {
|
|
770
|
+
default: void 0
|
|
771
|
+
}
|
|
772
|
+
}), a(S, "componentPropsPreset", {
|
|
650
773
|
options: {
|
|
651
774
|
defaultValue: []
|
|
652
775
|
}
|
|
653
776
|
}), // 基于基本功能提出基本预设
|
|
654
|
-
|
|
655
|
-
let
|
|
656
|
-
const
|
|
777
|
+
a(S, "placeholderPresetByComponentName", S.getPlaceholderPrefixPresetByComponentName());
|
|
778
|
+
let L = S;
|
|
779
|
+
const j = {
|
|
780
|
+
...L,
|
|
781
|
+
adapters: {
|
|
782
|
+
...he
|
|
783
|
+
}
|
|
784
|
+
}, be = /* @__PURE__ */ ae({
|
|
657
785
|
props: {
|
|
658
786
|
setup: {
|
|
659
787
|
type: Function,
|
|
660
788
|
required: !0
|
|
661
789
|
}
|
|
662
790
|
},
|
|
663
|
-
setup(
|
|
664
|
-
const e = new
|
|
791
|
+
setup(r) {
|
|
792
|
+
const e = new pe(r.setup);
|
|
665
793
|
return () => e.exec();
|
|
666
794
|
}
|
|
667
795
|
});
|
|
668
|
-
function
|
|
669
|
-
const e = new
|
|
796
|
+
function Pe(r) {
|
|
797
|
+
const e = new ue(r);
|
|
670
798
|
return [
|
|
671
799
|
e.setup.bind(e),
|
|
672
800
|
{
|
|
@@ -675,22 +803,18 @@ function pe(o) {
|
|
|
675
803
|
}
|
|
676
804
|
];
|
|
677
805
|
}
|
|
678
|
-
function
|
|
679
|
-
|
|
680
|
-
install() {
|
|
681
|
-
P.runtimeDoms = o;
|
|
682
|
-
}
|
|
683
|
-
};
|
|
806
|
+
function ge(r) {
|
|
807
|
+
f.presets = r;
|
|
684
808
|
}
|
|
685
|
-
function
|
|
686
|
-
return e === "raw" && Object.defineProperty(
|
|
687
|
-
value: `__proform_raw_${
|
|
809
|
+
function ve(r, e) {
|
|
810
|
+
return e === "raw" && Object.defineProperty(r, "name", {
|
|
811
|
+
value: `__proform_raw_${r.name}`,
|
|
688
812
|
writable: !0
|
|
689
|
-
}),
|
|
813
|
+
}), r;
|
|
690
814
|
}
|
|
691
815
|
export {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
816
|
+
be as ProForm,
|
|
817
|
+
Pe as useForm,
|
|
818
|
+
ge as useFormPresetConfigurer,
|
|
819
|
+
ve as useModifiers
|
|
696
820
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as ProForm } from "./src/form/index";
|
|
2
2
|
export { useForm } from "./src/interactions/useForm";
|
|
3
|
-
export {
|
|
3
|
+
export { useFormPresetConfigurer } from "./src/interactions/useFormPresetConfigurer";
|
|
4
4
|
export { useModifiers } from "./src/interactions/useModifiers";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyFunction } from "
|
|
2
|
-
import { TrackEffectMeta } from "
|
|
1
|
+
import { AnyFunction } from "../../types";
|
|
2
|
+
import { TrackEffectMeta } from "../../types/effectTypes";
|
|
3
3
|
export default class Effect {
|
|
4
4
|
effects: Set<Function>;
|
|
5
5
|
constructor();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyObject, FormCustomization } from "
|
|
2
|
-
import { RuntimeCore } from "
|
|
1
|
+
import { AnyObject, FormCustomization } from "../../types";
|
|
2
|
+
import { RuntimeCore } from "../index";
|
|
3
3
|
export default class FormCustomizer {
|
|
4
4
|
formCustomization: FormCustomization;
|
|
5
5
|
runtimeCore: RuntimeCore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
adapters: {
|
|
3
|
+
[x: string]: import("../../types").AdaptedInterface;
|
|
4
|
+
};
|
|
5
|
+
schemaPreset: Record<keyof import("../../types").ItemSchema, any> & {
|
|
6
|
+
children: any;
|
|
7
|
+
};
|
|
8
|
+
componentPropsPreset: import("../../types").AnyObject;
|
|
9
|
+
placeholderPresetByComponentName: {};
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ref } from "vue";
|
|
2
|
-
import { AnyObject, Schema, ProxyedSchema, AnyFunction, ObjectParserRoot } from "
|
|
3
|
-
import { RuntimeCore } from "
|
|
4
|
-
import Effect from "
|
|
2
|
+
import { AnyObject, Schema, ProxyedSchema, AnyFunction, ObjectParserRoot } from "../../types";
|
|
3
|
+
import { RuntimeCore } from "..";
|
|
4
|
+
import Effect from "../Effect";
|
|
5
5
|
/**
|
|
6
6
|
* 基本描述
|
|
7
7
|
* 对于函数的命名,如果是动词相关,代表对过程的处理,如果是名词,代表一个处理器
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RuntimeOptions } from "../../types";
|
|
2
|
+
export default class RuntimeContainer {
|
|
3
|
+
static getFormContainer({ ui }?: RuntimeOptions): import("../../types").DomType;
|
|
4
|
+
static getFormItemContainer({ ui }?: RuntimeOptions): import("../../types").DomType;
|
|
5
|
+
static getItemContainer({ ui }?: RuntimeOptions): import("../../types").DomType;
|
|
6
|
+
static getGroupContainer({ ui }?: RuntimeOptions): import("../../types").DomType;
|
|
7
|
+
static getListContainer({ ui }?: RuntimeOptions): import("../../types").DomType;
|
|
8
|
+
static getListItemContainer({ ui }?: RuntimeOptions): import("../../types").DomType;
|
|
9
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Ref } from "vue";
|
|
2
|
-
import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType,
|
|
3
|
-
import Processor from "
|
|
4
|
-
import Effect from "
|
|
2
|
+
import { Setup, Schema, AnyObject, ItemSchema, GroupSchema, ListSchema, ProcessorBySchemaType, runtime, NativeCustomizationOptions } from "../../types";
|
|
3
|
+
import Processor from "../Processor";
|
|
4
|
+
import Effect from "../Effect";
|
|
5
|
+
import RuntimeAdpter from "./RuntimeAdapter";
|
|
5
6
|
export default class RuntimeCore {
|
|
6
7
|
setup: Setup;
|
|
7
8
|
processor: Processor;
|
|
@@ -11,12 +12,14 @@ export default class RuntimeCore {
|
|
|
11
12
|
formRef: Ref<AnyObject>;
|
|
12
13
|
hydrateEffect: Effect;
|
|
13
14
|
native: NativeCustomizationOptions;
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
grid: {};
|
|
16
|
+
runtime: runtime;
|
|
16
17
|
globalNativeFormOverride: {
|
|
17
18
|
props: {};
|
|
18
19
|
slots: {};
|
|
19
20
|
};
|
|
21
|
+
ui: string;
|
|
22
|
+
runtimeAdapter: RuntimeAdpter;
|
|
20
23
|
constructor(setup: Setup);
|
|
21
24
|
getRuntimeMeta(): {
|
|
22
25
|
model: AnyObject;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import { AdaptedInterface } from ".";
|
|
1
2
|
import { AnyObject } from "./utilTypes";
|
|
2
3
|
export type DomType = new (...args: any) => AnyObject & {
|
|
3
4
|
$props: AnyObject;
|
|
4
5
|
};
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export interface FormPreset {
|
|
7
|
+
container: {
|
|
8
|
+
Form: DomType;
|
|
9
|
+
FormItem: DomType;
|
|
10
|
+
Item: DomType;
|
|
11
|
+
List: DomType;
|
|
12
|
+
ListItem: DomType;
|
|
13
|
+
Group: DomType;
|
|
14
|
+
};
|
|
15
|
+
adapter?: AdaptedInterface;
|
|
12
16
|
}
|
|
17
|
+
export type UIName = "ArcoVue" | "NutUI" | (string & {});
|
|
18
|
+
export type AdaptedInterfacePreset = Record<string, AdaptedInterface>;
|
|
19
|
+
export type FormPresets = {
|
|
20
|
+
ui: UIName;
|
|
21
|
+
uiPresets: Partial<Record<UIName, FormPreset>>;
|
|
22
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject, DomType } from "./index";
|
|
1
|
+
import { AnyObject, DomType, UIName } from "./index";
|
|
2
2
|
export type SchemaType = "item" | "list" | "group";
|
|
3
3
|
export type FieldRule<T = any> = {
|
|
4
4
|
type?: "string" | "number" | "boolean" | "array" | "object" | "email" | "url" | "ip";
|
|
@@ -59,8 +59,8 @@ export interface ItemSchema {
|
|
|
59
59
|
required?: boolean;
|
|
60
60
|
placeholder?: string;
|
|
61
61
|
native?: NativeCustomizationOptions;
|
|
62
|
-
|
|
63
|
-
label
|
|
62
|
+
grid?: GridStyle;
|
|
63
|
+
label?: string;
|
|
64
64
|
field: string;
|
|
65
65
|
component: DomType;
|
|
66
66
|
componentProps?: AnyObject;
|
|
@@ -70,15 +70,15 @@ export interface GroupSchema {
|
|
|
70
70
|
type: "group";
|
|
71
71
|
label: string;
|
|
72
72
|
children: ProxyedSchema[];
|
|
73
|
-
|
|
73
|
+
grid?: GridStyle;
|
|
74
74
|
}
|
|
75
75
|
export interface ListSchema {
|
|
76
76
|
type: "list";
|
|
77
77
|
field: string;
|
|
78
78
|
label: string;
|
|
79
79
|
children: ProxyedSchema[];
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
grid?: GridStyle;
|
|
81
|
+
runtime?: runtime;
|
|
82
82
|
}
|
|
83
83
|
export type Schema = ItemSchema | GroupSchema | ListSchema;
|
|
84
84
|
export interface runtimeMeta {
|
|
@@ -89,13 +89,14 @@ export type ProFormProxy<T> = {
|
|
|
89
89
|
[K in keyof T]: ProFormProxyRule<T[K]>;
|
|
90
90
|
};
|
|
91
91
|
export type ProxyedSchema = ProFormProxy<ItemSchema | GroupSchema | ListSchema>;
|
|
92
|
-
export interface
|
|
93
|
-
|
|
92
|
+
export interface runtime {
|
|
93
|
+
customizeItemLabel?: (rawLabel: string, rawIndex: number) => any;
|
|
94
94
|
}
|
|
95
95
|
export interface FormCustomization {
|
|
96
|
-
|
|
96
|
+
ui?: UIName;
|
|
97
|
+
grid?: GridStyle;
|
|
97
98
|
native?: NativeCustomizationOptions;
|
|
98
|
-
|
|
99
|
+
runtime?: runtime;
|
|
99
100
|
schemas: ProxyedSchema[];
|
|
100
101
|
}
|
|
101
102
|
export type NativeCustomizationOptions = {
|
package/package.json
CHANGED