@harbor-design/proform 1.0.7 → 1.0.9
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 +148 -134
- package/dist/types/src/services/Processor.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var I=Object.defineProperty;var v=(l,e,t)=>e in l?I(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t;var f=(l,e,t)=>(v(l,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue");class O{constructor(e){f(this,"runtimeCore");this.formCustomization=e}cleanFallbackFields(e){return e!==null&&typeof e=="object"&&(delete e.__yiwwhl_async_field_fallback,Object.values(e).forEach(t=>{this.cleanFallbackFields(t)})),e}setup(e){return this.runtimeCore=e,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(s=>s?t(s):e(this.cleanFallbackFields(i.toRaw(this.runtimeCore.processor.processedModel.value))))})}}class u{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 j(l){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[o,c]of s)n.set(t(o),t(c));return n}if(s instanceof Set){const n=new Set;for(let o of s)n.add(t(o));return n}if(e.has(s))return e.get(s);if(Array.isArray(s)){const n=[];e.set(s,n);for(let o=0;o<s.length;o++)n[o]=t(s[o]);return n}const r=Object.create(Object.getPrototypeOf(s));e.set(s,r);for(let n in s)s.hasOwnProperty(n)&&(r[n]=t(s[n]));return r}return t(l)}class E{constructor(){f(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e){return e(),this.effects.add(e),()=>this.effects.delete(e)}}class C{constructor(e){f(this,"processedSchemas");f(this,"processedModel");f(this,"getRuntimeMeta");f(this,"stableSchemas",[]);f(this,"stableModel",{});f(this,"schemaPreset",S.schemaPreset);f(this,"componentPropsPreset",S.componentPropsPreset);f(this,"stableUpdaterProcessProgress");f(this,"stableUpdaterTimes",0);f(this,"schemaEffect",new E);f(this,"defaultValueEffect",new E);f(this,"defaultValueInprogressMap",new Map);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})}parseSchemas(e,t){u.isArrayEmpty(this.processedSchemas.value)&&(this.processedSchemas.value=this.initSchemas(e)),this.parse(e,t)}parseStable(e){const t={};if(!u.isUndefined(e.stable))t[e.key]=this.parseStable(e.stable);else return e;return t}stableUpdater(e=[]){if(e.every(Boolean)){const t=i.toRaw(this.processedSchemas.value);!u.isProcessInprogress(t)&&u.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,n=Array.from({length:Object.keys(e).filter(c=>c!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:o});function o(c){const a=c.index,d=c.key,y=c.keyIndex;if(!c.stable)return;const V=r.parseStable(c.stable),m=s==null?void 0:s.index,g=s==null?void 0:s.key;let p=V;if(u.isProcessInprogress(p)||(n[y]=!0),s){let b=r.processedSchemas.value[m][g][a][d];b&&u.isObject(b)&&d!=="component"&&(p=Object.assign(b,p)),r.processedSchemas.value[m][g][a][d]=p,r.stableUpdater(n)}else{let b=r.processedSchemas.value[a][d];b&&u.isObject(b)&&(p=Object.assign(b,p)),r.processedSchemas.value[a][d]=p,r.stableUpdater(n)}}}objectParser(e){const t=e.data;Object.keys(t).forEach((r,n)=>{if(r==="children")this.parseSchemas(t[r],{...e,key:r,keyIndex:n});else{const o=c=>{e.updater({...e,key:r,keyIndex:n,stable:c})};if(u.isFunction(t[r]))r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const c=t[r](this.getRuntimeMeta());this.promiseFieldParser(c,o,!1)}else this.fieldParser(t[r],o)}):this.defaultValueEffect.trackEffect(()=>{const c=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],a=>{if(!a)return o(a);this.defaultValueInprogressMap.set(t[r],a),!u.isProcessInprogress(a)&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(o(a),this.defaultValueEffect.clearEffects(),c()):o(a)}):this.fieldParser(t[r],a=>{!u.isProcessInprogress(a)&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(o(a),this.defaultValueEffect.clearEffects(),c()):o(a)})})});else if(r==="component"){const c=t[r];this.promiseFieldParser(c,o,!1)}else this.fieldParser(t[r],o)}})}promiseFieldParser(e,t,s){u.isPromise(e)?e.then(r=>{s&&u.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}fieldParser(e,t,s=!0){if(u.isFunction(e)){const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else i.isRef(e)?i.watch(()=>e.value,()=>{u.isUndefined(e.value)||(s&&u.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):i.isReactive(e)?i.watch(()=>e,()=>{u.isUndefined(e)||(s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),u.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=j(this.processedModel.value))}createModel(e,t){u.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),u.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),u.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function w(l){return typeof l=="function"||Object.prototype.toString.call(l)==="[object Object]"&&!i.isVNode(l)}class R{constructor(e){f(this,"schemas",i.ref([]));f(this,"model",i.ref({}));f(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});f(this,"formRef",i.ref(null));this.setup=e,this.processor=new C(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:i.toRaw(j(this.model.value))}}runtimeItemProcessor(e,t,s=this.model.value,r){var g;const n=r?`${r.field}.${t}.${e.field}`:e.field,o=i.toRaw(e.component);if(!o)return;const c=o.name,a=e.componentProps??{},d=S.placeholderPresetByComponentName;let y=e.placeholder;y||(y=`${d[c]??"请输入"}${e.label}`),e.required&&(e.rules||(e.rules=[]),(g=e.rules)==null||g.push({required:!0,message:`${e.label}是必填项`}));let m=e.show;return m===void 0&&(m=!0),m||delete s[e.field],i.createVNode(h.runtimeDoms.Item,null,{default(){return i.withDirectives(i.createVNode(h.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:n},{default:()=>[i.createVNode(o,i.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":p=>s[e.field]=p,placeholder:y},a),null)]}),[[i.vShow,m]])}})}runtimeGroupProcessor(e){let t;return i.createVNode(h.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(j(this.processor.stableModel[e.field][0]))}deleteListItem(e,t){this.model.value[e.field].splice(t,1)}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),i.createVNode(h.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>i.createVNode(h.runtimeDoms.ListItem,null,{default(){return e.children.map((n,o)=>t.runtimeItemProcessor(n,o,s,e))},delete({container:n}={}){var c;let o=n??i.createVNode("button",null,null);return i.withDirectives(i.createVNode(o,{onClick:()=>t.deleteListItem(e,r)},null),[[i.vShow,((c=t.model.value[e.field])==null?void 0:c.length)>1]])}}))},add({container:s}={}){let r=s??i.createVNode("button",null,[i.createTextVNode("添加")]);return i.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 i.createVNode(h.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},w(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class h{}f(h,"runtimeDoms");const P=class P{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let s in e)e[s].forEach(r=>{t[r]=s});return t}};f(P,"schemaPreset",{type:{defaultValue:"item"},component:{defaultValue:void 0},componentProps:{defaultValue:void 0},defaultValue:{defaultValue:void 0},label:{defaultValue:""},field:{defaultValue:"__yiwwhl_async_field_fallback"},rules:{defaultValue:[]},show:{defaultValue:!0},required:{defaultValue:!1},placeholder:{defaultValue:void 0},children:{defaultValue:[]}}),f(P,"componentPropsPreset",{options:{defaultValue:[]}}),f(P,"placeholderPresetByComponentName",P.getPlaceholderPrefixPresetByComponentName());let S=P;const N=i.defineComponent({props:{setup:{type:Function,required:!0}},setup(l){const e=new R(l.setup);return()=>e.exec()}});function x(l){const e=new O(l);return[e.setup.bind(e),{submit:e.submit.bind(e)}]}function A(l){return{install(){h.runtimeDoms=l}}}exports.ProForm=N;exports.useForm=x;exports.useFormRenderer=A;
|
|
1
|
+
"use strict";var I=Object.defineProperty;var v=(c,e,t)=>e in c?I(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var l=(c,e,t)=>(v(c,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");class O{constructor(e){l(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))))})}}class u{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 S(c){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[o,a]of s)i.set(t(o),t(a));return i}if(s instanceof Set){const i=new Set;for(let o of s)i.add(t(o));return i}if(e.has(s))return e.get(s);if(Array.isArray(s)){const i=[];e.set(s,i);for(let o=0;o<s.length;o++)i[o]=t(s[o]);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(c)}class w{constructor(){l(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e){return e(),this.effects.add(e),()=>this.effects.delete(e)}}class C{constructor(e){l(this,"processedSchemas");l(this,"processedModel");l(this,"getRuntimeMeta");l(this,"stableSchemas",[]);l(this,"stableModel",{});l(this,"schemaPreset",V.schemaPreset);l(this,"componentPropsPreset",V.componentPropsPreset);l(this,"stableUpdaterProcessProgress");l(this,"stableUpdaterTimes",0);l(this,"schemaEffect",new w);l(this,"defaultValueEffect",new w);l(this,"defaultValueInprogressMap",new Map);l(this,"baseDefaultValueFunctionsLength");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 o in i)i.hasOwnProperty(o)&&(o==="defaultValue"&&typeof i[o]=="function"&&i[o].toString().includes("defaultValue")&&t++,r(i[o]))}}return r(e),t}parseSchemas(e,t){u.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(!u.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);!u.isProcessInprogress(t)&&u.isObjectEmpty(this.stableModel)&&(this.stableUpdaterProcessProgress||(this.stableUpdaterProcessProgress=Array.from({length:t.length}).fill(!1)),this.stableUpdaterProcessProgress[this.stableUpdaterTimes]=!0,this.stableUpdaterTimes++,this.modelProcessor(t))}}parseItem(e,t,s){const r=this,i=Array.from({length:Object.keys(e).filter(a=>a!=="children").length}).fill(!1);this.objectParser({data:e,index:t,updater:o});function o(a){const f=a.index,d=a.key,P=a.keyIndex;if(!a.stable)return;const j=r.parseStable(a.stable),m=s==null?void 0:s.index,g=s==null?void 0:s.key;let h=j;if(u.isProcessInprogress(h)||(i[P]=!0),s){let b=r.processedSchemas.value[m][g][f][d];b&&u.isObject(b)&&d!=="component"&&(h=Object.assign(b,h)),r.processedSchemas.value[m][g][f][d]=h,r.stableUpdater(i)}else{let b=r.processedSchemas.value[f][d];b&&u.isObject(b)&&(h=Object.assign(b,h)),r.processedSchemas.value[f][d]=h,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 o=a=>{e.updater({...e,key:r,keyIndex:i,stable:a})};if(u.isFunction(t[r]))r!=="defaultValue"?this.schemaEffect.trackEffect(()=>{if(r==="component"){const a=t[r](this.getRuntimeMeta());this.promiseFieldParser(a,o,!1)}else this.fieldParser(t[r],o)}):this.defaultValueEffect.trackEffect(()=>{const a=this.schemaEffect.trackEffect(()=>{/\{\s*model\s*\}/.test(t[r].toString())?this.fieldParser(t[r],f=>{if(!f)return o(f);this.defaultValueInprogressMap.set(t[r],f),!u.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(o(f),this.defaultValueEffect.clearEffects(),a()):o(f)}):this.fieldParser(t[r],f=>{this.defaultValueInprogressMap.set(t[r],f),!u.isProcessInprogress(f)&&this.defaultValueInprogressMap.size===this.baseDefaultValueFunctionsLength&&Array.from(this.defaultValueInprogressMap.values()).every(d=>!d.includes("undefined"))?(o(f),this.defaultValueEffect.clearEffects(),a()):o(f)})})});else if(r==="component"){const a=t[r];this.promiseFieldParser(a,o,!1)}else this.fieldParser(t[r],o)}})}promiseFieldParser(e,t,s){u.isPromise(e)?e.then(r=>{s&&u.isObject(r)?this.objectParser({data:r,updater:t}):t(r)}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}fieldParser(e,t,s=!0){if(u.isFunction(e)){const r=e(this.getRuntimeMeta());this.promiseFieldParser(r,t,s)}else n.isRef(e)?n.watch(()=>e.value,()=>{u.isUndefined(e.value)||(s&&u.isObject(e.value)?this.objectParser({data:e.value,updater:t}):t(e.value))},{immediate:!0,deep:!0}):n.isReactive(e)?n.watch(()=>e,()=>{u.isUndefined(e)||(s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e))},{immediate:!0,deep:!0}):s&&u.isObject(e)?this.objectParser({data:e,updater:t}):t(e)}modelProcessor(e){e.map(t=>this.createModel(t,this.processedModel.value)),u.isObjectEmpty(this.stableModel)&&this.stableUpdaterProcessProgress.every(Boolean)&&this.defaultValueEffect.effects.size===0&&(this.stableModel=S(this.processedModel.value))}createModel(e,t){u.isListSchema(e)&&(t[e.field]||(t[e.field]=[{}]),e.children.forEach(s=>{this.createModel(s,t[e.field][0])})),u.isGroupSchema(e)&&e.children.forEach(s=>{this.createModel(s,t)}),u.isItemSchema(e)&&(t[e.field]=e.defaultValue)}}function E(c){return typeof c=="function"||Object.prototype.toString.call(c)==="[object Object]"&&!n.isVNode(c)}class R{constructor(e){l(this,"schemas",n.ref([]));l(this,"model",n.ref({}));l(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});l(this,"formRef",n.ref(null));this.setup=e,this.processor=new C(this);const t=this.setup(this);this.processor.parseSchemas(t.schemas)}getRuntimeMeta(){return{model:n.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,o=n.toRaw(e.component);if(!o)return;const a=o.name,f=e.componentProps??{},d=V.placeholderPresetByComponentName;let P=e.placeholder;P||(P=`${d[a]??"请输入"}${e.label}`),e.required&&(e.rules||(e.rules=[]),(g=e.rules)==null||g.push({required:!0,message:`${e.label}是必填项`}));let m=e.show;return m===void 0&&(m=!0),m||delete s[e.field],n.createVNode(p.runtimeDoms.Item,null,{default(){return n.withDirectives(n.createVNode(p.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:i},{default:()=>[n.createVNode(o,n.mergeProps({modelValue:s[e.field],"onUpdate:modelValue":h=>s[e.field]=h,placeholder:P},f),null)]}),[[n.vShow,m]])}})}runtimeGroupProcessor(e){let t;return n.createVNode(p.runtimeDoms.Group,{schema:e},E(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]))}deleteListItem(e,t){this.model.value[e.field].splice(t,1)}runtimeListProcessor(e){const t=this;return t.model.value[e.field]||(t.model.value[e.field]=[{}]),n.createVNode(p.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((s,r)=>n.createVNode(p.runtimeDoms.ListItem,null,{default(){return e.children.map((i,o)=>t.runtimeItemProcessor(i,o,s,e))},delete({container:i}={}){var a;let o=i??n.createVNode("button",null,null);return n.withDirectives(n.createVNode(o,{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(p.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},E(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class p{}l(p,"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}};l(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:[]}}),l(y,"componentPropsPreset",{options:{defaultValue:[]}}),l(y,"placeholderPresetByComponentName",y.getPlaceholderPrefixPresetByComponentName());let V=y;const A=n.defineComponent({props:{setup:{type:Function,required:!0}},setup(c){const e=new R(c.setup);return()=>e.exec()}});function D(c){const e=new O(c);return[e.setup.bind(e),{submit:e.submit.bind(e)}]}function M(c){return{install(){p.runtimeDoms=c}}}exports.ProForm=A;exports.useForm=D;exports.useFormRenderer=M;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { toRaw as
|
|
5
|
-
class
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var D = (l, e, t) => e in l ? x(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
|
|
3
|
+
var o = (l, e, t) => (D(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { toRaw as j, watch as E, isRef as M, isReactive as U, ref as I, createVNode as d, withDirectives as v, mergeProps as R, vShow as O, createTextVNode as k, isVNode as L, defineComponent as F } from "vue";
|
|
5
|
+
class B {
|
|
6
6
|
constructor(e) {
|
|
7
|
-
|
|
7
|
+
o(this, "runtimeCore");
|
|
8
8
|
this.formCustomization = e;
|
|
9
9
|
}
|
|
10
10
|
// happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
|
|
@@ -20,13 +20,13 @@ class N {
|
|
|
20
20
|
return new Promise((e, t) => {
|
|
21
21
|
this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
|
|
22
22
|
this.cleanFallbackFields(
|
|
23
|
-
|
|
23
|
+
j(this.runtimeCore.processor.processedModel.value)
|
|
24
24
|
)
|
|
25
25
|
));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
class
|
|
29
|
+
class u {
|
|
30
30
|
static typeChecker(e) {
|
|
31
31
|
return {}.toString.call(e);
|
|
32
32
|
}
|
|
@@ -84,7 +84,7 @@ class f {
|
|
|
84
84
|
return !1;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function V(
|
|
87
|
+
function V(l) {
|
|
88
88
|
const e = /* @__PURE__ */ new WeakMap();
|
|
89
89
|
function t(s) {
|
|
90
90
|
if (s === null || typeof s != "object")
|
|
@@ -94,37 +94,37 @@ function V(o) {
|
|
|
94
94
|
if (s instanceof RegExp)
|
|
95
95
|
return new RegExp(s);
|
|
96
96
|
if (s instanceof Map) {
|
|
97
|
-
const
|
|
98
|
-
for (let [
|
|
99
|
-
|
|
100
|
-
return
|
|
97
|
+
const i = /* @__PURE__ */ new Map();
|
|
98
|
+
for (let [n, c] of s)
|
|
99
|
+
i.set(t(n), t(c));
|
|
100
|
+
return i;
|
|
101
101
|
}
|
|
102
102
|
if (s instanceof Set) {
|
|
103
|
-
const
|
|
104
|
-
for (let
|
|
105
|
-
|
|
106
|
-
return
|
|
103
|
+
const i = /* @__PURE__ */ new Set();
|
|
104
|
+
for (let n of s)
|
|
105
|
+
i.add(t(n));
|
|
106
|
+
return i;
|
|
107
107
|
}
|
|
108
108
|
if (e.has(s))
|
|
109
109
|
return e.get(s);
|
|
110
110
|
if (Array.isArray(s)) {
|
|
111
|
-
const
|
|
112
|
-
e.set(s,
|
|
113
|
-
for (let
|
|
114
|
-
n
|
|
115
|
-
return
|
|
111
|
+
const i = [];
|
|
112
|
+
e.set(s, i);
|
|
113
|
+
for (let n = 0; n < s.length; n++)
|
|
114
|
+
i[n] = t(s[n]);
|
|
115
|
+
return i;
|
|
116
116
|
}
|
|
117
117
|
const r = Object.create(Object.getPrototypeOf(s));
|
|
118
118
|
e.set(s, r);
|
|
119
|
-
for (let
|
|
120
|
-
s.hasOwnProperty(
|
|
119
|
+
for (let i in s)
|
|
120
|
+
s.hasOwnProperty(i) && (r[i] = t(s[i]));
|
|
121
121
|
return r;
|
|
122
122
|
}
|
|
123
|
-
return t(
|
|
123
|
+
return t(l);
|
|
124
124
|
}
|
|
125
125
|
class C {
|
|
126
126
|
constructor() {
|
|
127
|
-
|
|
127
|
+
o(this, "effects", /* @__PURE__ */ new Set());
|
|
128
128
|
}
|
|
129
129
|
clearEffects() {
|
|
130
130
|
this.effects.clear();
|
|
@@ -136,20 +136,21 @@ class C {
|
|
|
136
136
|
return e(), this.effects.add(e), () => this.effects.delete(e);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
class
|
|
139
|
+
class N {
|
|
140
140
|
constructor(e) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
o(this, "processedSchemas");
|
|
142
|
+
o(this, "processedModel");
|
|
143
|
+
o(this, "getRuntimeMeta");
|
|
144
|
+
o(this, "stableSchemas", []);
|
|
145
|
+
o(this, "stableModel", {});
|
|
146
|
+
o(this, "schemaPreset", S.schemaPreset);
|
|
147
|
+
o(this, "componentPropsPreset", S.componentPropsPreset);
|
|
148
|
+
o(this, "stableUpdaterProcessProgress");
|
|
149
|
+
o(this, "stableUpdaterTimes", 0);
|
|
150
|
+
o(this, "schemaEffect", new C());
|
|
151
|
+
o(this, "defaultValueEffect", new C());
|
|
152
|
+
o(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
|
|
153
|
+
o(this, "baseDefaultValueFunctionsLength");
|
|
153
154
|
this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), E(
|
|
154
155
|
() => this.processedModel.value,
|
|
155
156
|
() => {
|
|
@@ -173,13 +174,26 @@ class T {
|
|
|
173
174
|
return t.children && (s.children = this.initSchemas(t.children)), s;
|
|
174
175
|
});
|
|
175
176
|
}
|
|
177
|
+
countFunctionDefaultValues(e) {
|
|
178
|
+
let t = 0, s = /* @__PURE__ */ new Set();
|
|
179
|
+
function r(i) {
|
|
180
|
+
if (!s.has(i) && (Array.isArray(i) || i !== null && typeof i == "object")) {
|
|
181
|
+
s.add(i);
|
|
182
|
+
for (let n in i)
|
|
183
|
+
i.hasOwnProperty(n) && (n === "defaultValue" && typeof i[n] == "function" && i[n].toString().includes("defaultValue") && t++, r(i[n]));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return r(e), t;
|
|
187
|
+
}
|
|
176
188
|
// 派生过程,用于外部应用
|
|
177
189
|
parseSchemas(e, t) {
|
|
178
|
-
|
|
190
|
+
u.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
|
|
191
|
+
V(e)
|
|
192
|
+
), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
|
|
179
193
|
}
|
|
180
194
|
parseStable(e) {
|
|
181
195
|
const t = {};
|
|
182
|
-
if (!
|
|
196
|
+
if (!u.isUndefined(e.stable))
|
|
183
197
|
t[e.key] = this.parseStable(e.stable);
|
|
184
198
|
else
|
|
185
199
|
return e;
|
|
@@ -188,103 +202,103 @@ class T {
|
|
|
188
202
|
// 对于稳定初始化更新的抽象
|
|
189
203
|
stableUpdater(e = []) {
|
|
190
204
|
if (e.every(Boolean)) {
|
|
191
|
-
const t =
|
|
192
|
-
!
|
|
205
|
+
const t = j(this.processedSchemas.value);
|
|
206
|
+
!u.isProcessInprogress(t) && u.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
|
|
193
207
|
length: t.length
|
|
194
208
|
}).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
|
|
195
209
|
}
|
|
196
210
|
}
|
|
197
211
|
// 核心单 schema 处理过程,接收一个对象键值对的数据结构
|
|
198
212
|
parseItem(e, t, s) {
|
|
199
|
-
const r = this,
|
|
200
|
-
length: Object.keys(e).filter((
|
|
213
|
+
const r = this, i = Array.from({
|
|
214
|
+
length: Object.keys(e).filter((c) => c !== "children").length
|
|
201
215
|
}).fill(!1);
|
|
202
|
-
this.objectParser({ data: e, index: t, updater:
|
|
203
|
-
function
|
|
204
|
-
const
|
|
205
|
-
if (!
|
|
216
|
+
this.objectParser({ data: e, index: t, updater: n });
|
|
217
|
+
function n(c) {
|
|
218
|
+
const f = c.index, a = c.key, P = c.keyIndex;
|
|
219
|
+
if (!c.stable)
|
|
206
220
|
return;
|
|
207
|
-
const w = r.parseStable(
|
|
221
|
+
const w = r.parseStable(c.stable), m = s == null ? void 0 : s.index, g = s == null ? void 0 : s.key;
|
|
208
222
|
let p = w;
|
|
209
|
-
if (
|
|
210
|
-
let b = r.processedSchemas.value[m][g][
|
|
211
|
-
b &&
|
|
223
|
+
if (u.isProcessInprogress(p) || (i[P] = !0), s) {
|
|
224
|
+
let b = r.processedSchemas.value[m][g][f][a];
|
|
225
|
+
b && u.isObject(b) && a !== "component" && (p = Object.assign(b, p)), r.processedSchemas.value[m][g][f][a] = p, r.stableUpdater(i);
|
|
212
226
|
} else {
|
|
213
|
-
let b = r.processedSchemas.value[
|
|
214
|
-
b &&
|
|
227
|
+
let b = r.processedSchemas.value[f][a];
|
|
228
|
+
b && u.isObject(b) && (p = Object.assign(b, p)), r.processedSchemas.value[f][a] = p, r.stableUpdater(i);
|
|
215
229
|
}
|
|
216
230
|
}
|
|
217
231
|
}
|
|
218
232
|
// 只做基本的对象 parser
|
|
219
233
|
objectParser(e) {
|
|
220
234
|
const t = e.data;
|
|
221
|
-
Object.keys(t).forEach((r,
|
|
235
|
+
Object.keys(t).forEach((r, i) => {
|
|
222
236
|
if (r === "children")
|
|
223
237
|
this.parseSchemas(t[r], {
|
|
224
238
|
...e,
|
|
225
239
|
key: r,
|
|
226
|
-
keyIndex:
|
|
240
|
+
keyIndex: i
|
|
227
241
|
});
|
|
228
242
|
else {
|
|
229
|
-
const
|
|
243
|
+
const n = (c) => {
|
|
230
244
|
e.updater({
|
|
231
245
|
...e,
|
|
232
246
|
key: r,
|
|
233
|
-
keyIndex:
|
|
234
|
-
stable:
|
|
247
|
+
keyIndex: i,
|
|
248
|
+
stable: c
|
|
235
249
|
});
|
|
236
250
|
};
|
|
237
|
-
if (
|
|
251
|
+
if (u.isFunction(t[r]))
|
|
238
252
|
r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
239
253
|
if (r === "component") {
|
|
240
|
-
const
|
|
241
|
-
this.promiseFieldParser(
|
|
254
|
+
const c = t[r](this.getRuntimeMeta());
|
|
255
|
+
this.promiseFieldParser(c, n, !1);
|
|
242
256
|
} else
|
|
243
|
-
this.fieldParser(t[r],
|
|
257
|
+
this.fieldParser(t[r], n);
|
|
244
258
|
}) : this.defaultValueEffect.trackEffect(() => {
|
|
245
|
-
const
|
|
246
|
-
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (
|
|
247
|
-
if (!
|
|
248
|
-
return
|
|
249
|
-
this.defaultValueInprogressMap.set(t[r],
|
|
259
|
+
const c = this.schemaEffect.trackEffect(() => {
|
|
260
|
+
/\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (f) => {
|
|
261
|
+
if (!f)
|
|
262
|
+
return n(f);
|
|
263
|
+
this.defaultValueInprogressMap.set(t[r], f), !u.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
250
264
|
(a) => !a.includes("undefined")
|
|
251
|
-
) ? (
|
|
252
|
-
}) : this.fieldParser(t[r], (
|
|
253
|
-
!
|
|
265
|
+
) ? (n(f), this.defaultValueEffect.clearEffects(), c()) : n(f);
|
|
266
|
+
}) : this.fieldParser(t[r], (f) => {
|
|
267
|
+
this.defaultValueInprogressMap.set(t[r], f), !u.isProcessInprogress(f) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
|
|
254
268
|
(a) => !a.includes("undefined")
|
|
255
|
-
) ? (
|
|
269
|
+
) ? (n(f), this.defaultValueEffect.clearEffects(), c()) : n(f);
|
|
256
270
|
});
|
|
257
271
|
});
|
|
258
272
|
});
|
|
259
273
|
else if (r === "component") {
|
|
260
|
-
const
|
|
261
|
-
this.promiseFieldParser(
|
|
274
|
+
const c = t[r];
|
|
275
|
+
this.promiseFieldParser(c, n, !1);
|
|
262
276
|
} else
|
|
263
|
-
this.fieldParser(t[r],
|
|
277
|
+
this.fieldParser(t[r], n);
|
|
264
278
|
}
|
|
265
279
|
});
|
|
266
280
|
}
|
|
267
281
|
promiseFieldParser(e, t, s) {
|
|
268
|
-
|
|
269
|
-
s &&
|
|
282
|
+
u.isPromise(e) ? e.then((r) => {
|
|
283
|
+
s && u.isObject(r) ? this.objectParser({
|
|
270
284
|
data: r,
|
|
271
285
|
updater: t
|
|
272
286
|
}) : t(r);
|
|
273
|
-
}) : s &&
|
|
287
|
+
}) : s && u.isObject(e) ? this.objectParser({
|
|
274
288
|
data: e,
|
|
275
289
|
updater: t
|
|
276
290
|
}) : t(e);
|
|
277
291
|
}
|
|
278
292
|
// 对任意对象中单个字段的 parse: 做基本处理
|
|
279
293
|
fieldParser(e, t, s = !0) {
|
|
280
|
-
if (
|
|
294
|
+
if (u.isFunction(e)) {
|
|
281
295
|
const r = e(this.getRuntimeMeta());
|
|
282
296
|
this.promiseFieldParser(r, t, s);
|
|
283
297
|
} else
|
|
284
|
-
|
|
298
|
+
M(e) ? E(
|
|
285
299
|
() => e.value,
|
|
286
300
|
() => {
|
|
287
|
-
|
|
301
|
+
u.isUndefined(e.value) || (s && u.isObject(e.value) ? this.objectParser({
|
|
288
302
|
data: e.value,
|
|
289
303
|
updater: t
|
|
290
304
|
}) : t(e.value));
|
|
@@ -293,10 +307,10 @@ class T {
|
|
|
293
307
|
immediate: !0,
|
|
294
308
|
deep: !0
|
|
295
309
|
}
|
|
296
|
-
) :
|
|
310
|
+
) : U(e) ? E(
|
|
297
311
|
() => e,
|
|
298
312
|
() => {
|
|
299
|
-
|
|
313
|
+
u.isUndefined(e) || (s && u.isObject(e) ? this.objectParser({
|
|
300
314
|
data: e,
|
|
301
315
|
updater: t
|
|
302
316
|
}) : t(e));
|
|
@@ -305,7 +319,7 @@ class T {
|
|
|
305
319
|
immediate: !0,
|
|
306
320
|
deep: !0
|
|
307
321
|
}
|
|
308
|
-
) : s &&
|
|
322
|
+
) : s && u.isObject(e) ? this.objectParser({
|
|
309
323
|
data: e,
|
|
310
324
|
updater: t
|
|
311
325
|
}) : t(e);
|
|
@@ -313,64 +327,64 @@ class T {
|
|
|
313
327
|
modelProcessor(e) {
|
|
314
328
|
e.map(
|
|
315
329
|
(t) => this.createModel(t, this.processedModel.value)
|
|
316
|
-
),
|
|
330
|
+
), u.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = V(this.processedModel.value));
|
|
317
331
|
}
|
|
318
332
|
createModel(e, t) {
|
|
319
|
-
|
|
333
|
+
u.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
|
|
320
334
|
this.createModel(s, t[e.field][0]);
|
|
321
|
-
})),
|
|
335
|
+
})), u.isGroupSchema(e) && e.children.forEach((s) => {
|
|
322
336
|
this.createModel(s, t);
|
|
323
|
-
}),
|
|
337
|
+
}), u.isItemSchema(e) && (t[e.field] = e.defaultValue);
|
|
324
338
|
}
|
|
325
339
|
}
|
|
326
|
-
function
|
|
327
|
-
return typeof
|
|
340
|
+
function A(l) {
|
|
341
|
+
return typeof l == "function" || Object.prototype.toString.call(l) === "[object Object]" && !L(l);
|
|
328
342
|
}
|
|
329
|
-
class
|
|
343
|
+
class T {
|
|
330
344
|
constructor(e) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
345
|
+
o(this, "schemas", I([]));
|
|
346
|
+
o(this, "model", I({}));
|
|
347
|
+
o(this, "processorBySchemaType", {
|
|
334
348
|
item: this.runtimeItemProcessor.bind(this),
|
|
335
349
|
group: this.runtimeGroupProcessor.bind(this),
|
|
336
350
|
list: this.runtimeListProcessor.bind(this)
|
|
337
351
|
});
|
|
338
|
-
|
|
339
|
-
this.setup = e, this.processor = new
|
|
352
|
+
o(this, "formRef", I(null));
|
|
353
|
+
this.setup = e, this.processor = new N(this);
|
|
340
354
|
const t = this.setup(this);
|
|
341
355
|
this.processor.parseSchemas(t.schemas);
|
|
342
356
|
}
|
|
343
357
|
getRuntimeMeta() {
|
|
344
358
|
return {
|
|
345
|
-
model:
|
|
359
|
+
model: j(V(this.model.value))
|
|
346
360
|
};
|
|
347
361
|
}
|
|
348
362
|
runtimeItemProcessor(e, t, s = this.model.value, r) {
|
|
349
363
|
var g;
|
|
350
|
-
const
|
|
351
|
-
if (!
|
|
364
|
+
const i = r ? `${r.field}.${t}.${e.field}` : e.field, n = j(e.component);
|
|
365
|
+
if (!n)
|
|
352
366
|
return;
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
|
|
356
|
-
a[
|
|
367
|
+
const c = n.name, f = e.componentProps ?? {}, a = S.placeholderPresetByComponentName;
|
|
368
|
+
let P = e.placeholder;
|
|
369
|
+
P || (P = `${// @ts-expect-error
|
|
370
|
+
a[c] ?? "请输入"}${e.label}`), e.required && (e.rules || (e.rules = []), (g = e.rules) == null || g.push({
|
|
357
371
|
required: !0,
|
|
358
372
|
message: `${e.label}是必填项`
|
|
359
373
|
}));
|
|
360
374
|
let m = e.show;
|
|
361
375
|
return m === void 0 && (m = !0), m || delete s[e.field], d(h.runtimeDoms.Item, null, {
|
|
362
376
|
default() {
|
|
363
|
-
return
|
|
377
|
+
return v(d(h.runtimeDoms.FormItem, {
|
|
364
378
|
label: `${e.label}:`,
|
|
365
379
|
rules: e.rules,
|
|
366
|
-
field:
|
|
380
|
+
field: i
|
|
367
381
|
}, {
|
|
368
|
-
default: () => [d(
|
|
382
|
+
default: () => [d(n, R({
|
|
369
383
|
modelValue: s[e.field],
|
|
370
384
|
"onUpdate:modelValue": (p) => s[e.field] = p,
|
|
371
|
-
placeholder:
|
|
372
|
-
},
|
|
373
|
-
}), [[
|
|
385
|
+
placeholder: P
|
|
386
|
+
}, f), null)]
|
|
387
|
+
}), [[O, m]]);
|
|
374
388
|
}
|
|
375
389
|
});
|
|
376
390
|
}
|
|
@@ -378,7 +392,7 @@ class _ {
|
|
|
378
392
|
let t;
|
|
379
393
|
return d(h.runtimeDoms.Group, {
|
|
380
394
|
schema: e
|
|
381
|
-
},
|
|
395
|
+
}, A(t = e.children.map((s) => this.runtimeItemProcessor(s))) ? t : {
|
|
382
396
|
default: () => [t]
|
|
383
397
|
});
|
|
384
398
|
}
|
|
@@ -402,23 +416,23 @@ class _ {
|
|
|
402
416
|
default() {
|
|
403
417
|
return t.model.value[e.field].map((s, r) => d(h.runtimeDoms.ListItem, null, {
|
|
404
418
|
default() {
|
|
405
|
-
return e.children.map((
|
|
419
|
+
return e.children.map((i, n) => t.runtimeItemProcessor(i, n, s, e));
|
|
406
420
|
},
|
|
407
421
|
delete({
|
|
408
|
-
container:
|
|
422
|
+
container: i
|
|
409
423
|
} = {}) {
|
|
410
|
-
var
|
|
411
|
-
let
|
|
412
|
-
return
|
|
424
|
+
var c;
|
|
425
|
+
let n = i ?? d("button", null, null);
|
|
426
|
+
return v(d(n, {
|
|
413
427
|
onClick: () => t.deleteListItem(e, r)
|
|
414
|
-
}, null), [[
|
|
428
|
+
}, null), [[O, ((c = t.model.value[e.field]) == null ? void 0 : c.length) > 1]]);
|
|
415
429
|
}
|
|
416
430
|
}));
|
|
417
431
|
},
|
|
418
432
|
add({
|
|
419
433
|
container: s
|
|
420
434
|
} = {}) {
|
|
421
|
-
let r = s ?? d("button", null, [
|
|
435
|
+
let r = s ?? d("button", null, [k("添加")]);
|
|
422
436
|
return d(r, {
|
|
423
437
|
onClick: () => t.addListItem(e)
|
|
424
438
|
}, null);
|
|
@@ -433,15 +447,15 @@ class _ {
|
|
|
433
447
|
return d(h.runtimeDoms.Form, {
|
|
434
448
|
ref: this.formRef,
|
|
435
449
|
model: this.model.value
|
|
436
|
-
},
|
|
450
|
+
}, A(e = this.runtimeProcessor(this.schemas.value)) ? e : {
|
|
437
451
|
default: () => [e]
|
|
438
452
|
});
|
|
439
453
|
}
|
|
440
454
|
}
|
|
441
455
|
class h {
|
|
442
456
|
}
|
|
443
|
-
|
|
444
|
-
const
|
|
457
|
+
o(h, "runtimeDoms");
|
|
458
|
+
const y = class y {
|
|
445
459
|
static getPlaceholderPrefixPresetByComponentName() {
|
|
446
460
|
const e = {
|
|
447
461
|
请选择: ["Select", "Tree", "TreeSelect"],
|
|
@@ -454,7 +468,7 @@ const P = class P {
|
|
|
454
468
|
return t;
|
|
455
469
|
}
|
|
456
470
|
};
|
|
457
|
-
|
|
471
|
+
o(y, "schemaPreset", {
|
|
458
472
|
type: {
|
|
459
473
|
defaultValue: "item"
|
|
460
474
|
},
|
|
@@ -488,27 +502,27 @@ c(P, "schemaPreset", {
|
|
|
488
502
|
children: {
|
|
489
503
|
defaultValue: []
|
|
490
504
|
}
|
|
491
|
-
}),
|
|
505
|
+
}), o(y, "componentPropsPreset", {
|
|
492
506
|
options: {
|
|
493
507
|
defaultValue: []
|
|
494
508
|
}
|
|
495
509
|
}), // 基于基本功能提出基本预设
|
|
496
|
-
|
|
497
|
-
let
|
|
498
|
-
const
|
|
510
|
+
o(y, "placeholderPresetByComponentName", y.getPlaceholderPrefixPresetByComponentName());
|
|
511
|
+
let S = y;
|
|
512
|
+
const $ = /* @__PURE__ */ F({
|
|
499
513
|
props: {
|
|
500
514
|
setup: {
|
|
501
515
|
type: Function,
|
|
502
516
|
required: !0
|
|
503
517
|
}
|
|
504
518
|
},
|
|
505
|
-
setup(
|
|
506
|
-
const e = new
|
|
519
|
+
setup(l) {
|
|
520
|
+
const e = new T(l.setup);
|
|
507
521
|
return () => e.exec();
|
|
508
522
|
}
|
|
509
523
|
});
|
|
510
|
-
function
|
|
511
|
-
const e = new
|
|
524
|
+
function q(l) {
|
|
525
|
+
const e = new B(l);
|
|
512
526
|
return [
|
|
513
527
|
e.setup.bind(e),
|
|
514
528
|
{
|
|
@@ -516,15 +530,15 @@ function F(o) {
|
|
|
516
530
|
}
|
|
517
531
|
];
|
|
518
532
|
}
|
|
519
|
-
function G(
|
|
533
|
+
function G(l) {
|
|
520
534
|
return {
|
|
521
535
|
install() {
|
|
522
|
-
h.runtimeDoms =
|
|
536
|
+
h.runtimeDoms = l;
|
|
523
537
|
}
|
|
524
538
|
};
|
|
525
539
|
}
|
|
526
540
|
export {
|
|
527
|
-
|
|
528
|
-
|
|
541
|
+
$ as ProForm,
|
|
542
|
+
q as useForm,
|
|
529
543
|
G as useFormRenderer
|
|
530
544
|
};
|
|
@@ -19,9 +19,11 @@ export default class Processor {
|
|
|
19
19
|
schemaEffect: Effect;
|
|
20
20
|
defaultValueEffect: Effect;
|
|
21
21
|
defaultValueInprogressMap: Map<any, any>;
|
|
22
|
+
baseDefaultValueFunctionsLength: number;
|
|
22
23
|
constructor(runtimeCore: RuntimeCore);
|
|
23
24
|
parse<T extends object = any>(data: T[], parentMeta?: AnyObject): void;
|
|
24
25
|
initSchemas(schemas: AnyObject[]): AnyObject[];
|
|
26
|
+
countFunctionDefaultValues(input: AnyObject): number;
|
|
25
27
|
parseSchemas(schemas: ProxyedSchema[], parentMeta?: AnyObject): void;
|
|
26
28
|
parseStable(stable: AnyObject): AnyObject;
|
|
27
29
|
stableUpdater(parseProcess?: boolean[]): void;
|