@harbor-design/proform 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var I=Object.defineProperty;var O=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>(O(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 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 E(n,...e){return e.forEach(t=>{for(let s in t)t.hasOwnProperty(s)&&(typeof t[s]=="object"&&t[s]!==null?(n[s]=n[s]||{},E(n[s],t[s])):n[s]=t[s])}),n}function S(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 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(o.toRaw(this.runtimeCore.processor.processedModel.value))))})}hydrate(e){this.runtimeCore.hydrateEffect.trackEffect(()=>{o.isRef(e)?o.watch(()=>e.value,()=>{E(this.runtimeCore.model.value,e.value)},{deep:!0,immediate:!0}):o.isReactive(e)?o.watch(()=>e,()=>{E(this.runtimeCore.model.value,e)},{deep:!0,immediate:!0}):E(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),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(S(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,h=a.key,P=a.keyIndex;if(!a.stable)return;const v=r.parseStable(a.stable),b=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[b][g][u][h];p&&f.isObject(p)&&h!=="component"&&(d=Object.assign(p,d)),r.processedSchemas.value[b][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(),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(),a()):l(u)})})});else if(r==="component"){const a=t[r];this.promiseFieldParser(a,l,!1)}else this.fieldParser(t[r],l)}})}promiseFieldParser(e,t,s){f.isPromise(e)?e.then(r=>{s&&f.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):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=S(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(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!o.isVNode(n)}class M{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 j);this.setup=e,this.processor=new R(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:o.toRaw(S(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var g;const i=r?`${r.field}.${t}.${e.field}`:e.field,l=o.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 b=e.show;return b===void 0&&(b=!0),b||delete s[e.field],o.createVNode(m.runtimeDoms.Item,null,{default(){return o.withDirectives(o.createVNode(m.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:i},{default:()=>[o.createVNode(l,o.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":d=>s[e.field]=d,placeholder:P},u),null)]}),[[o.vShow,b]])}})}runtimeGroupProcessor(e){let t;return o.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(S(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(m.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>o.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??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(){let e;return o.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 y=class y{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};c(y,"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(y,"componentPropsPreset",{options:{defaultValue:[]}}),c(y,"placeholderPresetByComponentName",y.getPlaceholderPrefixPresetByComponentName());let V=y;const A=o.defineComponent({props:{setup:{type:Function,required:!0}},setup(n){const e=new M(n.setup);return()=>e.exec()}});function D(n){const e=new C(n);return[e.setup.bind(e),{submit:e.submit.bind(e),hydrate:e.hydrate.bind(e)}]}function N(n){return{install(){m.runtimeDoms=n}}}function x(n,e){return e==="raw"&&Object.defineProperty(n,"name",{value:`__proform_raw_${n.name}`,writable:!0}),n}exports.ProForm=A;exports.useForm=D;exports.useFormRenderer=N;exports.useModifiers=x;
|
|
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;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var _ = (n, e, t) => e in n ?
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var _ = (n, e, t) => e in n ? k(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
3
|
var o = (n, e, t) => (_(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { toRaw as V, isRef as
|
|
5
|
-
class
|
|
4
|
+
import { toRaw as V, isRef as U, watch as S, isReactive as D, nextTick as O, ref as I, createVNode as h, withDirectives as x, mergeProps as R, vShow as A, createTextVNode as L, isVNode as z, defineComponent as B } from "vue";
|
|
5
|
+
class c {
|
|
6
6
|
static typeChecker(e) {
|
|
7
7
|
return {}.toString.call(e);
|
|
8
8
|
}
|
|
9
|
+
static isString(e) {
|
|
10
|
+
return typeof e == "string";
|
|
11
|
+
}
|
|
9
12
|
static isArray(e) {
|
|
10
13
|
return this.typeChecker(e) === "[object Array]";
|
|
11
14
|
}
|
|
@@ -60,10 +63,10 @@ class f {
|
|
|
60
63
|
return !1;
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
|
-
function
|
|
66
|
+
function j(n, ...e) {
|
|
64
67
|
return e.forEach((t) => {
|
|
65
68
|
for (let s in t)
|
|
66
|
-
t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? (n[s] = n[s] || {},
|
|
69
|
+
t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? (n[s] = n[s] || {}, j(n[s], t[s])) : n[s] = t[s]);
|
|
67
70
|
}), n;
|
|
68
71
|
}
|
|
69
72
|
function v(n) {
|
|
@@ -77,8 +80,8 @@ function v(n) {
|
|
|
77
80
|
return new RegExp(s);
|
|
78
81
|
if (s instanceof Map) {
|
|
79
82
|
const i = /* @__PURE__ */ new Map();
|
|
80
|
-
for (let [l,
|
|
81
|
-
i.set(t(l), t(
|
|
83
|
+
for (let [l, f] of s)
|
|
84
|
+
i.set(t(l), t(f));
|
|
82
85
|
return i;
|
|
83
86
|
}
|
|
84
87
|
if (s instanceof Set) {
|
|
@@ -104,7 +107,7 @@ function v(n) {
|
|
|
104
107
|
}
|
|
105
108
|
return t(n);
|
|
106
109
|
}
|
|
107
|
-
class
|
|
110
|
+
class T {
|
|
108
111
|
constructor(e) {
|
|
109
112
|
o(this, "runtimeCore");
|
|
110
113
|
this.formCustomization = e;
|
|
@@ -130,25 +133,25 @@ class B {
|
|
|
130
133
|
hydrate(e) {
|
|
131
134
|
this.runtimeCore.hydrateEffect.trackEffect(
|
|
132
135
|
() => {
|
|
133
|
-
|
|
136
|
+
U(e) ? S(
|
|
134
137
|
() => e.value,
|
|
135
138
|
() => {
|
|
136
|
-
|
|
139
|
+
j(this.runtimeCore.model.value, e.value);
|
|
137
140
|
},
|
|
138
141
|
{
|
|
139
142
|
deep: !0,
|
|
140
143
|
immediate: !0
|
|
141
144
|
}
|
|
142
|
-
) : D(e) ?
|
|
145
|
+
) : D(e) ? S(
|
|
143
146
|
() => e,
|
|
144
147
|
() => {
|
|
145
|
-
|
|
148
|
+
j(this.runtimeCore.model.value, e);
|
|
146
149
|
},
|
|
147
150
|
{
|
|
148
151
|
deep: !0,
|
|
149
152
|
immediate: !0
|
|
150
153
|
}
|
|
151
|
-
) :
|
|
154
|
+
) : j(this.runtimeCore.model.value, e);
|
|
152
155
|
},
|
|
153
156
|
{
|
|
154
157
|
lazy: !0
|
|
@@ -172,7 +175,7 @@ class w {
|
|
|
172
175
|
return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
|
-
class
|
|
178
|
+
class N {
|
|
176
179
|
constructor(e) {
|
|
177
180
|
o(this, "runtimeCore");
|
|
178
181
|
o(this, "processedSchemas");
|
|
@@ -180,15 +183,15 @@ class F {
|
|
|
180
183
|
o(this, "getRuntimeMeta");
|
|
181
184
|
o(this, "stableSchemas", []);
|
|
182
185
|
o(this, "stableModel", {});
|
|
183
|
-
o(this, "schemaPreset",
|
|
184
|
-
o(this, "componentPropsPreset",
|
|
186
|
+
o(this, "schemaPreset", E.schemaPreset);
|
|
187
|
+
o(this, "componentPropsPreset", E.componentPropsPreset);
|
|
185
188
|
o(this, "stableUpdaterProcessProgress");
|
|
186
189
|
o(this, "stableUpdaterTimes", 0);
|
|
187
190
|
o(this, "schemaEffect", new w());
|
|
188
191
|
o(this, "defaultValueEffect", new w());
|
|
189
192
|
o(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
|
|
190
193
|
o(this, "baseDefaultValueFunctionsLength");
|
|
191
|
-
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e),
|
|
194
|
+
this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), S(
|
|
192
195
|
() => this.processedModel.value,
|
|
193
196
|
() => {
|
|
194
197
|
this.schemaEffect.triggerEffects();
|
|
@@ -224,13 +227,13 @@ class F {
|
|
|
224
227
|
}
|
|
225
228
|
// 派生过程,用于外部应用
|
|
226
229
|
parseSchemas(e, t) {
|
|
227
|
-
|
|
230
|
+
c.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
|
|
228
231
|
v(e)
|
|
229
232
|
), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
|
|
230
233
|
}
|
|
231
234
|
parseStable(e) {
|
|
232
235
|
const t = {};
|
|
233
|
-
if (!
|
|
236
|
+
if (!c.isUndefined(e.stable))
|
|
234
237
|
t[e.key] = this.parseStable(e.stable);
|
|
235
238
|
else
|
|
236
239
|
return e;
|
|
@@ -240,7 +243,7 @@ class F {
|
|
|
240
243
|
stableUpdater(e = []) {
|
|
241
244
|
if (e.every(Boolean)) {
|
|
242
245
|
const t = V(this.processedSchemas.value);
|
|
243
|
-
!
|
|
246
|
+
!c.isProcessInprogress(t) && c.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
|
|
244
247
|
length: t.length
|
|
245
248
|
}).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
|
|
246
249
|
}
|
|
@@ -248,21 +251,21 @@ class F {
|
|
|
248
251
|
// 核心单 schema 处理过程,接收一个对象键值对的数据结构
|
|
249
252
|
parseItem(e, t, s) {
|
|
250
253
|
const r = this, i = Array.from({
|
|
251
|
-
length: Object.keys(e).filter((
|
|
254
|
+
length: Object.keys(e).filter((f) => f !== "children").length
|
|
252
255
|
}).fill(!1);
|
|
253
256
|
this.objectParser({ data: e, index: t, updater: l });
|
|
254
|
-
function l(
|
|
255
|
-
const u =
|
|
256
|
-
if (!
|
|
257
|
+
function l(f) {
|
|
258
|
+
const u = f.index, d = f.key, P = f.keyIndex;
|
|
259
|
+
if (!f.stable)
|
|
257
260
|
return;
|
|
258
|
-
const C = r.parseStable(
|
|
261
|
+
const C = r.parseStable(f.stable), y = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
|
|
259
262
|
let a = C;
|
|
260
|
-
if (
|
|
261
|
-
let p = r.processedSchemas.value[
|
|
262
|
-
p &&
|
|
263
|
+
if (c.isProcessInprogress(a) || (i[P] = !0), s) {
|
|
264
|
+
let p = r.processedSchemas.value[y][g][u][d];
|
|
265
|
+
p && c.isObject(p) && d !== "component" && (a = Object.assign(p, a)), r.processedSchemas.value[y][g][u][d] = a, r.stableUpdater(i);
|
|
263
266
|
} else {
|
|
264
267
|
let p = r.processedSchemas.value[u][d];
|
|
265
|
-
p &&
|
|
268
|
+
p && c.isObject(p) && (a = Object.assign(p, a)), r.processedSchemas.value[u][d] = a, r.stableUpdater(i);
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
}
|
|
@@ -277,58 +280,65 @@ class F {
|
|
|
277
280
|
keyIndex: i
|
|
278
281
|
});
|
|
279
282
|
else {
|
|
280
|
-
const l = (
|
|
283
|
+
const l = (f) => {
|
|
281
284
|
e.updater({
|
|
282
285
|
...e,
|
|
283
286
|
key: r,
|
|
284
287
|
keyIndex: i,
|
|
285
|
-
stable:
|
|
288
|
+
stable: f
|
|
286
289
|
});
|
|
287
290
|
};
|
|
288
|
-
if (
|
|
291
|
+
if (c.isFunction(t[r]))
|
|
289
292
|
r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
290
293
|
if (r === "component") {
|
|
291
|
-
const
|
|
292
|
-
this.promiseFieldParser(
|
|
294
|
+
const f = t[r](this.getRuntimeMeta());
|
|
295
|
+
this.promiseFieldParser(f, l, !1);
|
|
293
296
|
} else
|
|
294
297
|
this.fieldParser(t[r], l);
|
|
295
298
|
}) : this.defaultValueEffect.trackEffect(() => {
|
|
296
|
-
const
|
|
299
|
+
const f = this.schemaEffect.trackEffect(() => {
|
|
297
300
|
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (u) => {
|
|
298
301
|
if (!u)
|
|
299
302
|
return l(u);
|
|
300
|
-
this.defaultValueInprogressMap.set(t[r], u), !
|
|
303
|
+
this.defaultValueInprogressMap.set(t[r], u), !c.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
301
304
|
(d) => !d.includes("undefined")
|
|
302
|
-
) ? (l(u), this.defaultValueEffect.clearEffects(),
|
|
305
|
+
) ? (l(u), this.defaultValueEffect.clearEffects(), O(() => {
|
|
306
|
+
f();
|
|
307
|
+
})) : l(u);
|
|
303
308
|
}) : this.fieldParser(t[r], (u) => {
|
|
304
|
-
this.defaultValueInprogressMap.set(t[r], u), !
|
|
309
|
+
this.defaultValueInprogressMap.set(t[r], u), !c.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
305
310
|
(d) => !d.includes("undefined")
|
|
306
|
-
) ? (l(u), this.defaultValueEffect.clearEffects(),
|
|
311
|
+
) ? (l(u), this.defaultValueEffect.clearEffects(), O(() => {
|
|
312
|
+
f();
|
|
313
|
+
})) : l(u);
|
|
307
314
|
});
|
|
308
315
|
});
|
|
309
316
|
});
|
|
310
317
|
else if (r === "component") {
|
|
311
|
-
const
|
|
312
|
-
this.promiseFieldParser(
|
|
318
|
+
const f = t[r];
|
|
319
|
+
this.promiseFieldParser(f, l, !1);
|
|
313
320
|
} else
|
|
314
321
|
this.fieldParser(t[r], l);
|
|
315
322
|
}
|
|
316
323
|
});
|
|
317
324
|
}
|
|
325
|
+
replaceUndefinedInString(e, t) {
|
|
326
|
+
return e.replace(/undefined/g, t);
|
|
327
|
+
}
|
|
318
328
|
promiseFieldParser(e, t, s) {
|
|
319
|
-
|
|
320
|
-
s &&
|
|
329
|
+
c.isPromise(e) ? e.then((r) => {
|
|
330
|
+
s && c.isObject(r) ? this.objectParser({
|
|
321
331
|
data: r,
|
|
322
332
|
updater: t
|
|
323
333
|
}) : t(r);
|
|
324
|
-
}) : s &&
|
|
334
|
+
}) : (c.isString(e) && (e = this.replaceUndefinedInString(e, "")), s && c.isObject(e) ? this.objectParser({
|
|
325
335
|
data: e,
|
|
326
336
|
updater: t
|
|
327
|
-
}) : t(e);
|
|
337
|
+
}) : t(e));
|
|
328
338
|
}
|
|
329
339
|
// 对任意对象中单个字段的 parse: 做基本处理
|
|
330
340
|
fieldParser(e, t, s = !0) {
|
|
331
|
-
if (
|
|
341
|
+
if (c.isFunction(e))
|
|
332
342
|
if (e.name.startsWith("__proform_raw_"))
|
|
333
343
|
t(e);
|
|
334
344
|
else {
|
|
@@ -336,10 +346,10 @@ class F {
|
|
|
336
346
|
this.promiseFieldParser(r, t, s);
|
|
337
347
|
}
|
|
338
348
|
else
|
|
339
|
-
|
|
349
|
+
U(e) ? S(
|
|
340
350
|
() => e.value,
|
|
341
351
|
() => {
|
|
342
|
-
|
|
352
|
+
c.isUndefined(e.value) || (s && c.isObject(e.value) ? this.objectParser({
|
|
343
353
|
data: e.value,
|
|
344
354
|
updater: t
|
|
345
355
|
}) : t(e.value));
|
|
@@ -348,10 +358,10 @@ class F {
|
|
|
348
358
|
immediate: !0,
|
|
349
359
|
deep: !0
|
|
350
360
|
}
|
|
351
|
-
) : D(e) ?
|
|
361
|
+
) : D(e) ? S(
|
|
352
362
|
() => e,
|
|
353
363
|
() => {
|
|
354
|
-
|
|
364
|
+
c.isUndefined(e) || (s && c.isObject(e) ? this.objectParser({
|
|
355
365
|
data: e,
|
|
356
366
|
updater: t
|
|
357
367
|
}) : t(e));
|
|
@@ -360,7 +370,7 @@ class F {
|
|
|
360
370
|
immediate: !0,
|
|
361
371
|
deep: !0
|
|
362
372
|
}
|
|
363
|
-
) : s &&
|
|
373
|
+
) : s && c.isObject(e) ? this.objectParser({
|
|
364
374
|
data: e,
|
|
365
375
|
updater: t
|
|
366
376
|
}) : t(e);
|
|
@@ -368,20 +378,20 @@ class F {
|
|
|
368
378
|
modelProcessor(e) {
|
|
369
379
|
e.map(
|
|
370
380
|
(t) => this.createModel(t, this.processedModel.value)
|
|
371
|
-
),
|
|
381
|
+
), c.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = v(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
|
|
372
382
|
}
|
|
373
383
|
createModel(e, t) {
|
|
374
|
-
|
|
384
|
+
c.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
|
|
375
385
|
this.createModel(s, t[e.field][0]);
|
|
376
|
-
})),
|
|
386
|
+
})), c.isGroupSchema(e) && e.children.forEach((s) => {
|
|
377
387
|
this.createModel(s, t);
|
|
378
|
-
}),
|
|
388
|
+
}), c.isItemSchema(e) && (t[e.field] = e.defaultValue);
|
|
379
389
|
}
|
|
380
390
|
}
|
|
381
|
-
function
|
|
382
|
-
return typeof n == "function" || Object.prototype.toString.call(n) === "[object Object]" && !
|
|
391
|
+
function M(n) {
|
|
392
|
+
return typeof n == "function" || Object.prototype.toString.call(n) === "[object Object]" && !z(n);
|
|
383
393
|
}
|
|
384
|
-
class
|
|
394
|
+
class $ {
|
|
385
395
|
constructor(e) {
|
|
386
396
|
o(this, "schemas", I([]));
|
|
387
397
|
o(this, "model", I({}));
|
|
@@ -392,7 +402,7 @@ class N {
|
|
|
392
402
|
});
|
|
393
403
|
o(this, "formRef", I(null));
|
|
394
404
|
o(this, "hydrateEffect", new w());
|
|
395
|
-
this.setup = e, this.processor = new
|
|
405
|
+
this.setup = e, this.processor = new N(this);
|
|
396
406
|
const t = this.setup(this);
|
|
397
407
|
this.processor.parseSchemas(t.schemas);
|
|
398
408
|
}
|
|
@@ -406,10 +416,10 @@ class N {
|
|
|
406
416
|
const i = r ? `${r.field}.${t}.${e.field}` : e.field, l = V(e.component);
|
|
407
417
|
if (!l)
|
|
408
418
|
return;
|
|
409
|
-
const
|
|
419
|
+
const f = l.name, u = e.componentProps ?? {}, d = E.placeholderPresetByComponentName;
|
|
410
420
|
let P = e.placeholder;
|
|
411
421
|
if (P || (P = `${// @ts-expect-error
|
|
412
|
-
d[
|
|
422
|
+
d[f] ?? "请输入"}${e.label}`), e.required)
|
|
413
423
|
if (!e.rules)
|
|
414
424
|
e.rules = [], (g = e.rules) == null || g.push({
|
|
415
425
|
required: !0,
|
|
@@ -419,20 +429,20 @@ class N {
|
|
|
419
429
|
const a = e.rules.findIndex((p) => !!p.required);
|
|
420
430
|
e.rules[a].message = `${e.label}是必填项`;
|
|
421
431
|
}
|
|
422
|
-
let
|
|
423
|
-
return
|
|
432
|
+
let y = e.show;
|
|
433
|
+
return y === void 0 && (y = !0), y || delete s[e.field], h(m.runtimeDoms.Item, null, {
|
|
424
434
|
default() {
|
|
425
|
-
return
|
|
435
|
+
return x(h(m.runtimeDoms.FormItem, {
|
|
426
436
|
label: `${e.label}:`,
|
|
427
437
|
rules: e.rules,
|
|
428
438
|
field: i
|
|
429
439
|
}, {
|
|
430
|
-
default: () => [h(l,
|
|
440
|
+
default: () => [h(l, R({
|
|
431
441
|
modelValue: s[e.field],
|
|
432
442
|
"onUpdate:modelValue": (a) => s[e.field] = a,
|
|
433
443
|
placeholder: P
|
|
434
444
|
}, u), null)]
|
|
435
|
-
}), [[A,
|
|
445
|
+
}), [[A, y]]);
|
|
436
446
|
}
|
|
437
447
|
});
|
|
438
448
|
}
|
|
@@ -440,7 +450,7 @@ class N {
|
|
|
440
450
|
let t;
|
|
441
451
|
return h(m.runtimeDoms.Group, {
|
|
442
452
|
schema: e
|
|
443
|
-
},
|
|
453
|
+
}, M(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
|
|
444
454
|
default: () => [t]
|
|
445
455
|
});
|
|
446
456
|
}
|
|
@@ -469,18 +479,18 @@ class N {
|
|
|
469
479
|
delete({
|
|
470
480
|
container: i
|
|
471
481
|
} = {}) {
|
|
472
|
-
var
|
|
482
|
+
var f;
|
|
473
483
|
let l = i ?? h("button", null, null);
|
|
474
|
-
return
|
|
484
|
+
return x(h(l, {
|
|
475
485
|
onClick: () => t.deleteListItem(e, r)
|
|
476
|
-
}, null), [[A, ((
|
|
486
|
+
}, null), [[A, ((f = t.model.value[e.field]) == null ? void 0 : f.length) > 1]]);
|
|
477
487
|
}
|
|
478
488
|
}));
|
|
479
489
|
},
|
|
480
490
|
add({
|
|
481
491
|
container: s
|
|
482
492
|
} = {}) {
|
|
483
|
-
let r = s ?? h("button", null, [
|
|
493
|
+
let r = s ?? h("button", null, [L("添加")]);
|
|
484
494
|
return h(r, {
|
|
485
495
|
onClick: () => t.addListItem(e)
|
|
486
496
|
}, null);
|
|
@@ -495,7 +505,7 @@ class N {
|
|
|
495
505
|
return h(m.runtimeDoms.Form, {
|
|
496
506
|
ref: this.formRef,
|
|
497
507
|
model: this.model.value
|
|
498
|
-
},
|
|
508
|
+
}, M(e = this.runtimeProcessor(this.schemas.value)) ? e : {
|
|
499
509
|
default: () => [e]
|
|
500
510
|
});
|
|
501
511
|
}
|
|
@@ -503,7 +513,7 @@ class N {
|
|
|
503
513
|
class m {
|
|
504
514
|
}
|
|
505
515
|
o(m, "runtimeDoms");
|
|
506
|
-
const
|
|
516
|
+
const b = class b {
|
|
507
517
|
static getPlaceholderPrefixPresetByComponentName() {
|
|
508
518
|
const e = {
|
|
509
519
|
请选择: ["Select", "Tree", "TreeSelect"],
|
|
@@ -516,7 +526,7 @@ const y = class y {
|
|
|
516
526
|
return t;
|
|
517
527
|
}
|
|
518
528
|
};
|
|
519
|
-
o(
|
|
529
|
+
o(b, "schemaPreset", {
|
|
520
530
|
type: {
|
|
521
531
|
defaultValue: "item"
|
|
522
532
|
},
|
|
@@ -550,14 +560,14 @@ o(y, "schemaPreset", {
|
|
|
550
560
|
children: {
|
|
551
561
|
defaultValue: []
|
|
552
562
|
}
|
|
553
|
-
}), o(
|
|
563
|
+
}), o(b, "componentPropsPreset", {
|
|
554
564
|
options: {
|
|
555
565
|
defaultValue: []
|
|
556
566
|
}
|
|
557
567
|
}), // 基于基本功能提出基本预设
|
|
558
|
-
o(
|
|
559
|
-
let
|
|
560
|
-
const
|
|
568
|
+
o(b, "placeholderPresetByComponentName", b.getPlaceholderPrefixPresetByComponentName());
|
|
569
|
+
let E = b;
|
|
570
|
+
const G = /* @__PURE__ */ B({
|
|
561
571
|
props: {
|
|
562
572
|
setup: {
|
|
563
573
|
type: Function,
|
|
@@ -565,12 +575,12 @@ const q = /* @__PURE__ */ z({
|
|
|
565
575
|
}
|
|
566
576
|
},
|
|
567
577
|
setup(n) {
|
|
568
|
-
const e = new
|
|
578
|
+
const e = new $(n.setup);
|
|
569
579
|
return () => e.exec();
|
|
570
580
|
}
|
|
571
581
|
});
|
|
572
|
-
function
|
|
573
|
-
const e = new
|
|
582
|
+
function K(n) {
|
|
583
|
+
const e = new T(n);
|
|
574
584
|
return [
|
|
575
585
|
e.setup.bind(e),
|
|
576
586
|
{
|
|
@@ -579,22 +589,22 @@ function G(n) {
|
|
|
579
589
|
}
|
|
580
590
|
];
|
|
581
591
|
}
|
|
582
|
-
function
|
|
592
|
+
function W(n) {
|
|
583
593
|
return {
|
|
584
594
|
install() {
|
|
585
595
|
m.runtimeDoms = n;
|
|
586
596
|
}
|
|
587
597
|
};
|
|
588
598
|
}
|
|
589
|
-
function
|
|
599
|
+
function H(n, e) {
|
|
590
600
|
return e === "raw" && Object.defineProperty(n, "name", {
|
|
591
601
|
value: `__proform_raw_${n.name}`,
|
|
592
602
|
writable: !0
|
|
593
603
|
}), n;
|
|
594
604
|
}
|
|
595
605
|
export {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
606
|
+
G as ProForm,
|
|
607
|
+
K as useForm,
|
|
608
|
+
W as useFormRenderer,
|
|
609
|
+
H as useModifiers
|
|
600
610
|
};
|
|
@@ -30,6 +30,7 @@ export default class Processor {
|
|
|
30
30
|
stableUpdater(parseProcess?: boolean[]): void;
|
|
31
31
|
parseItem(data: AnyObject, index: number, parentMeta?: AnyObject): void;
|
|
32
32
|
objectParser(root: ObjectParserRoot): void;
|
|
33
|
+
replaceUndefinedInString(data: string, replaceTo: string): string;
|
|
33
34
|
promiseFieldParser(rootField: any, updater: AnyFunction, deepProcess: boolean): void;
|
|
34
35
|
fieldParser(rootField: any, updater: AnyFunction, deepProcess?: boolean): void;
|
|
35
36
|
modelProcessor(schemas: Schema[]): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnyObject, GroupSchema, ItemSchema, ListSchema } from "../types";
|
|
2
2
|
export default class IS {
|
|
3
3
|
private static typeChecker;
|
|
4
|
+
static isString(data: any): data is string;
|
|
4
5
|
static isArray(data: any): data is any[];
|
|
5
6
|
static isFunction(data: any): data is (...args: any) => any;
|
|
6
7
|
static isPromise(data: any): data is Promise<any>;
|