@harbor-design/proform 1.0.4 → 1.0.6
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +178 -148
- package/dist/types/src/services/Preset.d.ts +7 -0
- package/dist/types/src/services/Processors.d.ts +2 -2
- package/dist/types/src/services/index.d.ts +1 -0
- package/dist/types/src/types/formCustomizerTypes.d.ts +2 -0
- package/package.json +2 -5
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var k=(u,e,t)=>e in u?b(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t;var m=(u,e,t)=>(k(u,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue");class R{constructor(e){m(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(i=>i?t(i):e(this.cleanFallbackFields(l.toRaw(this.runtimeCore.processors.processedModel.value))))})}}class a{static typeChecker(e){return{}.toString.call(e)}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e).includes("Function")}static isAsyncFunction(e){let t=!1;return this.typeChecker(e)==="[object AsyncFunction]"&&(t=!0),t}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"}}function V(u){const e=new WeakMap;function t(i){if(i===null||typeof i!="object")return i;if(i instanceof Date)return new Date(i);if(i instanceof RegExp)return new RegExp(i);if(i instanceof Map){const o=new Map;for(let[s,f]of i)o.set(t(s),t(f));return o}if(i instanceof Set){const o=new Set;for(let s of i)o.add(t(s));return o}if(e.has(i))return e.get(i);if(Array.isArray(i)){const o=[];e.set(i,o);for(let s=0;s<i.length;s++)o[s]=t(i[s]);return o}const c=Object.create(Object.getPrototypeOf(i));e.set(i,c);for(let o in i)i.hasOwnProperty(o)&&(c[o]=t(i[o]));return c}return t(u)}class W{constructor(e,t){m(this,"rawSchemas",[]);m(this,"rawModel",{});m(this,"schemaPreset",{type:{defaultValueWhenAsync:"item"},component:{defaultValueWhenAsync:void 0},componentProps:{defaultValueWhenAsync:void 0},defaultValue:{defaultValueWhenAsync:void 0},label:{defaultValueWhenAsync:""},field:{defaultValueWhenAsync:"__yiwwhl_async_field_fallback"},rules:{defaultValueWhenAsync:[]},show:{defaultValueWhenAsync:!0}});m(this,"componentPropsPreset",{options:{defaultValueWhenAsync:[]}});m(this,"uniqueEffectMap",{});m(this,"schemaEffect",new F);m(this,"modelEffect",new F);m(this,"stopWatchEffect",new F);this.processedSchemas=e,this.processedModel=t,l.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects(),this.modelEffect.triggerEffects()},{deep:!0})}schemaAnalyzer(e,t=this.processedSchemas.value,i=this.rawSchemas,c,o){for(let s=0;s<e.length;s++){let f=e[s];this.schemaProcessor(f,s,(p,v,y)=>{y?i[s][y]=p[y]:(t[s]=p,this.modelProcessor(p,c&&this.processedModel.value[c][0]),(!i[s]||v)&&(i[s]=V(p)),this.schemaEffect.triggerEffects(),this.modelEffect.triggerEffects())},o,c)}}schemaProcessor(e,t,i,c,o){const s={},f=this;function p(v=!1){var y,w;if(s.componentProps){const h={};f.propsProcessor(s.componentProps,f.componentPropsPreset,h,E=>{s.componentProps=h,i({...s},E,"componentProps")},t,c);return}if(s.children){f.processedSchemas.value[t]=s,f.rawSchemas[t]=s,i({...s},v),f.schemaAnalyzer(s.children,(y=f.processedSchemas.value[t])==null?void 0:y.children,(w=f.rawSchemas[t])==null?void 0:w.children,s.field,t);return}i({...s},v),f.rawModel=V(f.processedModel.value)}this.propsProcessor(e,this.schemaPreset,s,p,t,c,o)}replaceFunctionsWithUndefined(e){if(typeof e!="object"||e===null)return e;for(let t in e)if(e.hasOwnProperty(t)){let i=e[t];typeof i=="function"||typeof i=="object"&&this.replaceFunctionsWithUndefined(i)}return e}runtimeMeta(){return{model:this.replaceFunctionsWithUndefined(l.toRaw(V(this.processedModel.value)))}}propsProcessor(e,t,i,c,o,s,f){const p=Object.keys(e),v=Array.from({length:p.length}).fill(!1);function y(){return v.every(w=>w)}for(let w=0;w<p.length;w++){const h=p[w],E=e[h];if(a.isFunction(E)){const P=E(this.runtimeMeta());h!=="defaultValue"?this.schemaEffect.trackEffect(()=>{let n=E(this.runtimeMeta());n instanceof Promise?n.then(r=>{s===void 0?a.isFunction(r)||(typeof r=="string"&&r.includes("undefined")&&(r=r.replace(/undefined/g,"")),this.processedSchemas.value[o][h]=r):a.isFunction(r)||(typeof r=="string"&&r.includes("undefined")&&(r=r.replace(/undefined/g,"")),this.processedSchemas.value[s].children[o][h]=r)}):s===void 0?a.isFunction(n)||(typeof n=="string"&&n.includes("undefined")&&(n=n.replace(/undefined/g,"")),this.processedSchemas.value[o][h]=n):a.isFunction(n)||(typeof n=="string"&&n.includes("undefined")&&(n=n.replace(/undefined/g,"")),this.processedSchemas.value[s].children[o][h]=n)}):this.modelEffect.trackEffect(()=>{let n=E(this.runtimeMeta());this.stopWatchEffect.trackEffect(l.watchEffect(()=>{if(n=E(this.runtimeMeta()),n instanceof Promise)n.then(r=>{if(typeof r=="string"&&!r.includes("undefined")?this.stopWatchEffect.triggerEffects():r=r.replace(/undefined/g,""),o===void 0||f===void 0){if(a.isFunction(e.field)){const d=e.field(this.runtimeMeta());d instanceof Promise?d.then(g=>{this.processedModel.value[g]=r}):this.processedModel.value[d]=r;return}this.processedModel.value[e.field]=r}else{if(a.isFunction(e.field)){const d=e.field(this.runtimeMeta());d instanceof Promise?d.then(g=>{this.processedModel.value[f][o][g]=r}):this.processedModel.value[f][o]&&(this.processedModel.value[f][o][d]=r);return}this.processedModel.value[f]&&this.processedModel.value[f].forEach(d=>{d[e.field]=r})}this.rawModel=V(this.processedModel.value),this.modelEffect.clearEffects()});else{if(typeof n=="string"&&!n.includes("undefined")?this.stopWatchEffect.triggerEffects():n=n.replace(/undefined/g,""),a.isFunction(e.field)){const r=e.field(this.runtimeMeta());r instanceof Promise?r.then(d=>{this.processedModel.value[d]=n}):this.processedModel.value[r]=n;return}if(this.processedModel.value[e.field]=n,o===void 0||f===void 0){if(a.isFunction(e.field)){const r=e.field(this.runtimeMeta());r instanceof Promise?r.then(d=>{this.processedModel.value[d]=n}):this.processedModel.value[r]=n;return}this.processedModel.value[e.field]=n}else for(let r=0;r<this.processedModel.value[f].length;r++){const d=this.processedModel.value[f][r];if(!a.isFunction(e.field))d[e.field]=n;else{const g=e.field(this.runtimeMeta());g instanceof Promise?g.then(S=>{d[S]=n}):d[g]=n;return}}this.rawModel=V(this.processedModel.value),this.modelEffect.clearEffects()}}))}),P instanceof Promise?(v[w]=!0,i[h]=t[h].defaultValueWhenAsync,y()&&c(),P.then(n=>{v[w]=!0,i[h]=n,y()&&c(!0)})):(v[w]=!0,i[h]=P,y()&&c())}else v[w]=!0,l.isRef(E)?l.watch(()=>E.value,P=>{i[h]=P,y()&&c()},{immediate:!0,deep:!0}):l.isReactive(E)?l.watch(()=>E,P=>{i[h]=P,y()&&c()},{immediate:!0,deep:!0}):(i[h]=E,y()&&c())}}modelProcessor(e,t=this.processedModel.value){if(a.isListSchema(e)){if(a.isFunction(e.field))return;t[e.field]||(t[e.field]=[{}]),e.children.forEach(i=>{this.modelProcessor(i,t[e.field][0])});return}if(a.isGroupSchema(e)){e.children.forEach(i=>{this.modelProcessor(i,t)});return}if(a.isItemSchema(e)){if(a.isFunction(e.field)||a.isUndefined(e.field)||!Number.isNaN(Number(e.field))||a.isFunction(e.defaultValue))return;t[e.field]=e.defaultValue}}}function A(u){return typeof u=="function"||Object.prototype.toString.call(u)==="[object Object]"&&!l.isVNode(u)}class N{constructor(e){m(this,"schemas",l.ref([]));m(this,"model",l.ref({}));m(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});m(this,"formRef",l.ref(null));this.setup=e,this.processors=new W(this.schemas,this.model),this.analyze(this.setup(this))}analyze(e){this.processors.schemaAnalyzer(e.schemas)}runtimeItemProcessor(e,t,i=this.model.value,c){const o=c?`${c.field}.${t}.${e.field}`:e.field,s=l.toRaw(e.component),f=e.componentProps??{};let p=e.show;return p===void 0&&(p=!0),p||delete i[e.field],l.createVNode(M.runtimeDoms.Item,null,{default(){return l.withDirectives(l.createVNode(M.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:o},{default:()=>[l.createVNode(s,l.mergeProps({modelValue:i[e.field],"onUpdate:modelValue":v=>i[e.field]=v},f),null)]}),[[l.vShow,p]])}})}runtimeGroupProcessor(e){let t;return l.createVNode(M.runtimeDoms.Group,{schema:e},A(t=e.children.map(i=>this.runtimeItemProcessor(i)))?t:{default:()=>[t]})}addListItem(e){var t,i;if(console.log(this.processors.rawModel,e.field),!((t=this.processors.rawModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(i=this.processors.rawModel[e.field])!=null&&i[0]&&this.model.value[e.field].push(V(this.processors.rawModel[e.field][0]))}deleteListItem(e,t){this.model.value[e.field].splice(t,1)}runtimeListProcessor(e){const t=this;return l.createVNode(M.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((i,c)=>l.createVNode(M.runtimeDoms.ListItem,null,{default(){return e.children.map((o,s)=>t.runtimeItemProcessor(o,s,i,e))},delete({container:o}={}){var f;let s=o??l.createVNode("button",null,null);return l.withDirectives(l.createVNode(s,{onClick:()=>t.deleteListItem(e,c)},null),[[l.vShow,((f=t.model.value[e.field])==null?void 0:f.length)>1]])}}))},add({container:i}={}){let c=i??l.createVNode("button",null,[l.createTextVNode("添加")]);return l.createVNode(c,{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 l.createVNode(M.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},A(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class M{}m(M,"runtimeDoms");class F{constructor(){m(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e){this.effects.add(e)}}const D=l.defineComponent({props:{setup:{type:Function,required:!0}},setup(u){const e=new N(u.setup);return()=>e.exec()}});function C(u){const e=new R(u);return[e.setup.bind(e),{submit:e.submit.bind(e)}]}function _(u){return{install(){M.runtimeDoms=u}}}exports.ProForm=D;exports.useForm=C;exports.useFormRenderer=_;
|
|
1
|
+
"use strict";var k=Object.defineProperty;var W=(u,e,t)=>e in u?k(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t;var a=(u,e,t)=>(W(u,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue");class R{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,this.formCustomization}submit(){return new Promise((e,t)=>{this.runtimeCore.formRef.value.validate(i=>i?t(i):e(this.cleanFallbackFields(l.toRaw(this.runtimeCore.processors.processedModel.value))))})}}class m{static typeChecker(e){return{}.toString.call(e)}static isArray(e){return this.typeChecker(e)==="[object Array]"}static isFunction(e){return this.typeChecker(e).includes("Function")}static isAsyncFunction(e){let t=!1;return this.typeChecker(e)==="[object AsyncFunction]"&&(t=!0),t}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"}}function V(u){const e=new WeakMap;function t(i){if(i===null||typeof i!="object")return i;if(i instanceof Date)return new Date(i);if(i instanceof RegExp)return new RegExp(i);if(i instanceof Map){const o=new Map;for(let[s,c]of i)o.set(t(s),t(c));return o}if(i instanceof Set){const o=new Set;for(let s of i)o.add(t(s));return o}if(e.has(i))return e.get(i);if(Array.isArray(i)){const o=[];e.set(i,o);for(let s=0;s<i.length;s++)o[s]=t(i[s]);return o}const f=Object.create(Object.getPrototypeOf(i));e.set(i,f);for(let o in i)i.hasOwnProperty(o)&&(f[o]=t(i[o]));return f}return t(u)}class C{constructor(e,t){a(this,"rawSchemas",[]);a(this,"rawModel",{});a(this,"schemaPreset",A.schemaPreset);a(this,"componentPropsPreset",A.componentPropsPreset);a(this,"uniqueEffectMap",{});a(this,"schemaEffect",new S);a(this,"modelEffect",new S);a(this,"stopWatchEffect",new S);this.processedSchemas=e,this.processedModel=t,l.watch(()=>this.processedModel.value,()=>{this.schemaEffect.triggerEffects(),this.modelEffect.triggerEffects()},{deep:!0})}schemaAnalyzer(e,t=this.processedSchemas.value,i=this.rawSchemas,f,o){for(let s=0;s<e.length;s++){let c=e[s];this.schemaProcessor(c,s,(v,E,h)=>{h?i[s][h]=v[h]:(t[s]=v,this.modelProcessor(v,f&&this.processedModel.value[f][0]),(!i[s]||E)&&(i[s]=V(v)),this.schemaEffect.triggerEffects(),this.modelEffect.triggerEffects())},o,f)}}schemaProcessor(e,t,i,f,o){const s={},c=this;function v(E=!1){var h,P;if(s.componentProps){const d={};c.propsProcessor(s.componentProps,c.componentPropsPreset,d,y=>{s.componentProps=d,i({...s},y,"componentProps")},t,f);return}if(s.children){c.processedSchemas.value[t]=s,c.rawSchemas[t]=s,i({...s},E),c.schemaAnalyzer(s.children,(h=c.processedSchemas.value[t])==null?void 0:h.children,(P=c.rawSchemas[t])==null?void 0:P.children,s.field,t);return}i({...s},E),c.rawModel=V(c.processedModel.value)}this.propsProcessor(e,this.schemaPreset,s,v,t,f,o)}replaceFunctionsWithUndefined(e){if(typeof e!="object"||e===null)return e;for(let t in e)if(e.hasOwnProperty(t)){let i=e[t];typeof i=="function"||typeof i=="object"&&this.replaceFunctionsWithUndefined(i)}return e}runtimeMeta(){return{model:this.replaceFunctionsWithUndefined(l.toRaw(V(this.processedModel.value)))}}propsProcessor(e,t,i,f,o,s,c){const v=Object.keys(e),E=Array.from({length:v.length}).fill(!1);function h(){return E.every(P=>P)}for(let P=0;P<v.length;P++){const d=v[P],y=e[d];if(m.isFunction(y)){const w=y(this.runtimeMeta());d!=="defaultValue"?this.schemaEffect.trackEffect(()=>{let n=y(this.runtimeMeta());n instanceof Promise?n.then(r=>{s===void 0?m.isFunction(r)||(typeof r=="string"&&r.includes("undefined")&&(r=r.replace(/undefined/g,"")),this.processedSchemas.value[o][d]=r):m.isFunction(r)||(typeof r=="string"&&r.includes("undefined")&&(r=r.replace(/undefined/g,"")),this.processedSchemas.value[s].children[o][d]=r)}):s===void 0?m.isFunction(n)||(typeof n=="string"&&n.includes("undefined")&&(n=n.replace(/undefined/g,"")),this.processedSchemas.value[o][d]=n):m.isFunction(n)||(typeof n=="string"&&n.includes("undefined")&&(n=n.replace(/undefined/g,"")),this.processedSchemas.value[s].children[o][d]=n)}):this.modelEffect.trackEffect(()=>{let n=y(this.runtimeMeta());this.stopWatchEffect.trackEffect(l.watchEffect(()=>{if(n=y(this.runtimeMeta()),n instanceof Promise)n.then(r=>{if(typeof r=="string"&&!r.includes("undefined")?this.stopWatchEffect.triggerEffects():r=r.replace(/undefined/g,""),o===void 0||c===void 0){if(m.isFunction(e.field)){const p=e.field(this.runtimeMeta());p instanceof Promise?p.then(g=>{this.processedModel.value[g]=r}):this.processedModel.value[p]=r;return}this.processedModel.value[e.field]=r}else{if(m.isFunction(e.field)){const p=e.field(this.runtimeMeta());p instanceof Promise?p.then(g=>{this.processedModel.value[c][o][g]=r}):this.processedModel.value[c][o]&&(this.processedModel.value[c][o][p]=r);return}this.processedModel.value[c]&&this.processedModel.value[c].forEach(p=>{p[e.field]=r})}this.rawModel=V(this.processedModel.value),this.modelEffect.clearEffects()});else{if(typeof n=="string"&&!n.includes("undefined")?this.stopWatchEffect.triggerEffects():n=n.replace(/undefined/g,""),m.isFunction(e.field)){const r=e.field(this.runtimeMeta());r instanceof Promise?r.then(p=>{this.processedModel.value[p]=n}):this.processedModel.value[r]=n;return}if(this.processedModel.value[e.field]=n,o===void 0||c===void 0){if(m.isFunction(e.field)){const r=e.field(this.runtimeMeta());r instanceof Promise?r.then(p=>{this.processedModel.value[p]=n}):this.processedModel.value[r]=n;return}this.processedModel.value[e.field]=n}else for(let r=0;r<this.processedModel.value[c].length;r++){const p=this.processedModel.value[c][r];if(!m.isFunction(e.field))p[e.field]=n;else{const g=e.field(this.runtimeMeta());g instanceof Promise?g.then(N=>{p[N]=n}):p[g]=n;return}}this.rawModel=V(this.processedModel.value),this.modelEffect.clearEffects()}}))}),w instanceof Promise?(E[P]=!0,i[d]=t[d].defaultValueWhenAsync,h()&&f(),w.then(n=>{E[P]=!0,i[d]=n,h()&&f(!0)})):(E[P]=!0,i[d]=w,h()&&f())}else E[P]=!0,l.isRef(y)?l.watch(()=>y.value,w=>{i[d]=w,h()&&f()},{immediate:!0,deep:!0}):l.isReactive(y)?l.watch(()=>y,w=>{i[d]=w,h()&&f()},{immediate:!0,deep:!0}):(i[d]=y,h()&&f())}}modelProcessor(e,t=this.processedModel.value){if(m.isListSchema(e)){if(m.isFunction(e.field))return;t[e.field]||(t[e.field]=[{}]),e.children.forEach(i=>{this.modelProcessor(i,t[e.field][0])});return}if(m.isGroupSchema(e)){e.children.forEach(i=>{this.modelProcessor(i,t)});return}if(m.isItemSchema(e)){if(m.isFunction(e.field)||m.isUndefined(e.field)||!Number.isNaN(Number(e.field))||m.isFunction(e.defaultValue))return;t[e.field]=e.defaultValue}}}function b(u){return typeof u=="function"||Object.prototype.toString.call(u)==="[object Object]"&&!l.isVNode(u)}class D{constructor(e){a(this,"schemas",l.ref([]));a(this,"model",l.ref({}));a(this,"processorBySchemaType",{item:this.runtimeItemProcessor.bind(this),group:this.runtimeGroupProcessor.bind(this),list:this.runtimeListProcessor.bind(this)});a(this,"formRef",l.ref(null));this.setup=e,this.processors=new C(this.schemas,this.model),this.analyze(this.setup(this))}analyze(e){this.processors.schemaAnalyzer(e.schemas)}runtimeItemProcessor(e,t,i=this.model.value,f){var y;const o=f?`${f.field}.${t}.${e.field}`:e.field,s=l.toRaw(e.component),c=s.name,v=e.componentProps??{},E=A.placeholderPresetByComponentName;let h=e.placeholder;h||(h=`${E[c]??"请输入"}${e.label}`),e.required&&(e.rules||(e.rules=[]),(y=e.rules)==null||y.push({required:!0,message:`${e.label}是必填项`}));let d=e.show;return d===void 0&&(d=!0),d||delete i[e.field],l.createVNode(M.runtimeDoms.Item,null,{default(){return l.withDirectives(l.createVNode(M.runtimeDoms.FormItem,{label:`${e.label}:`,rules:e.rules,field:o},{default:()=>[l.createVNode(s,l.mergeProps({modelValue:i[e.field],"onUpdate:modelValue":w=>i[e.field]=w,placeholder:h},v),null)]}),[[l.vShow,d]])}})}runtimeGroupProcessor(e){let t;return l.createVNode(M.runtimeDoms.Group,{schema:e},b(t=e.children.map(i=>this.runtimeItemProcessor(i)))?t:{default:()=>[t]})}addListItem(e){var t,i;if(!((t=this.processors.rawModel[e.field])!=null&&t[0]))return Promise.reject({code:"0001",message:"异步默认值数据正在处理中,请您耐心等待... "});(i=this.processors.rawModel[e.field])!=null&&i[0]&&this.model.value[e.field].push(V(this.processors.rawModel[e.field][0]))}deleteListItem(e,t){this.model.value[e.field].splice(t,1)}runtimeListProcessor(e){const t=this;return l.createVNode(M.runtimeDoms.List,{schema:e},{default(){return t.model.value[e.field].map((i,f)=>l.createVNode(M.runtimeDoms.ListItem,null,{default(){return e.children.map((o,s)=>t.runtimeItemProcessor(o,s,i,e))},delete({container:o}={}){var c;let s=o??l.createVNode("button",null,null);return l.withDirectives(l.createVNode(s,{onClick:()=>t.deleteListItem(e,f)},null),[[l.vShow,((c=t.model.value[e.field])==null?void 0:c.length)>1]])}}))},add({container:i}={}){let f=i??l.createVNode("button",null,[l.createTextVNode("添加")]);return l.createVNode(f,{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 l.createVNode(M.runtimeDoms.Form,{ref:this.formRef,model:this.model.value},b(e=this.runtimeProcessor(this.schemas.value))?e:{default:()=>[e]})}}class M{}a(M,"runtimeDoms");class S{constructor(){a(this,"effects",new Set)}clearEffects(){this.effects.clear()}triggerEffects(){Array.from(this.effects).forEach(e=>e())}trackEffect(e){this.effects.add(e)}}const F=class F{static getPlaceholderPrefixPresetByComponentName(){const e={请选择:["Select","Tree","TreeSelect"],请输入:["Input"]},t={};for(let i in e)e[i].forEach(f=>{t[f]=i});return t}};a(F,"schemaPreset",{type:{defaultValueWhenAsync:"item"},component:{defaultValueWhenAsync:void 0},componentProps:{defaultValueWhenAsync:void 0},defaultValue:{defaultValueWhenAsync:void 0},label:{defaultValueWhenAsync:""},field:{defaultValueWhenAsync:"__yiwwhl_async_field_fallback"},rules:{defaultValueWhenAsync:[]},show:{defaultValueWhenAsync:!0},required:{defaultValueWhenAsync:!1},placeholder:{defaultValueWhenAsync:void 0}}),a(F,"componentPropsPreset",{options:{defaultValueWhenAsync:[]}}),a(F,"placeholderPresetByComponentName",F.getPlaceholderPrefixPresetByComponentName());let A=F;const j=l.defineComponent({props:{setup:{type:Function,required:!0}},setup(u){const e=new D(u.setup);return()=>e.exec()}});function L(u){const e=new R(u);return[e.setup.bind(e),{submit:e.submit.bind(e)}]}function z(u){return{install(){M.runtimeDoms=u}}}exports.ProForm=j;exports.useForm=L;exports.useFormRenderer=z;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { toRaw as
|
|
5
|
-
class
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var L = (c, e, t) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
+
var d = (c, e, t) => (L(c, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { toRaw as W, watch as S, watchEffect as z, isRef as _, isReactive as B, ref as k, createVNode as v, withDirectives as C, mergeProps as q, vShow as R, createTextVNode as $, isVNode as G, defineComponent as T } from "vue";
|
|
5
|
+
class U {
|
|
6
6
|
constructor(e) {
|
|
7
|
-
|
|
7
|
+
d(this, "runtimeCore");
|
|
8
8
|
this.formCustomization = e;
|
|
9
9
|
}
|
|
10
10
|
// happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
|
|
@@ -20,13 +20,13 @@ class B {
|
|
|
20
20
|
return new Promise((e, t) => {
|
|
21
21
|
this.runtimeCore.formRef.value.validate((i) => i ? t(i) : e(
|
|
22
22
|
this.cleanFallbackFields(
|
|
23
|
-
|
|
23
|
+
W(this.runtimeCore.processors.processedModel.value)
|
|
24
24
|
)
|
|
25
25
|
));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
class
|
|
29
|
+
class p {
|
|
30
30
|
static typeChecker(e) {
|
|
31
31
|
return {}.toString.call(e);
|
|
32
32
|
}
|
|
@@ -99,44 +99,15 @@ function A(c) {
|
|
|
99
99
|
}
|
|
100
100
|
class O {
|
|
101
101
|
constructor(e, t) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
componentProps: {
|
|
112
|
-
defaultValueWhenAsync: void 0
|
|
113
|
-
},
|
|
114
|
-
defaultValue: {
|
|
115
|
-
defaultValueWhenAsync: void 0
|
|
116
|
-
},
|
|
117
|
-
label: {
|
|
118
|
-
defaultValueWhenAsync: ""
|
|
119
|
-
},
|
|
120
|
-
field: {
|
|
121
|
-
defaultValueWhenAsync: "__yiwwhl_async_field_fallback"
|
|
122
|
-
},
|
|
123
|
-
rules: {
|
|
124
|
-
defaultValueWhenAsync: []
|
|
125
|
-
},
|
|
126
|
-
show: {
|
|
127
|
-
defaultValueWhenAsync: !0
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
h(this, "componentPropsPreset", {
|
|
131
|
-
options: {
|
|
132
|
-
defaultValueWhenAsync: []
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
h(this, "uniqueEffectMap", {});
|
|
136
|
-
h(this, "schemaEffect", new k());
|
|
137
|
-
h(this, "modelEffect", new k());
|
|
138
|
-
h(this, "stopWatchEffect", new k());
|
|
139
|
-
this.processedSchemas = e, this.processedModel = t, F(
|
|
102
|
+
d(this, "rawSchemas", []);
|
|
103
|
+
d(this, "rawModel", {});
|
|
104
|
+
d(this, "schemaPreset", b.schemaPreset);
|
|
105
|
+
d(this, "componentPropsPreset", b.componentPropsPreset);
|
|
106
|
+
d(this, "uniqueEffectMap", {});
|
|
107
|
+
d(this, "schemaEffect", new V());
|
|
108
|
+
d(this, "modelEffect", new V());
|
|
109
|
+
d(this, "stopWatchEffect", new V());
|
|
110
|
+
this.processedSchemas = e, this.processedModel = t, S(
|
|
140
111
|
() => this.processedModel.value,
|
|
141
112
|
() => {
|
|
142
113
|
this.schemaEffect.triggerEffects(), this.modelEffect.triggerEffects();
|
|
@@ -152,11 +123,11 @@ class O {
|
|
|
152
123
|
this.schemaProcessor(
|
|
153
124
|
l,
|
|
154
125
|
s,
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
|
|
126
|
+
(P, E, a) => {
|
|
127
|
+
a ? i[s][a] = P[a] : (t[s] = P, this.modelProcessor(
|
|
128
|
+
P,
|
|
158
129
|
f && this.processedModel.value[f][0]
|
|
159
|
-
), (!i[s] ||
|
|
130
|
+
), (!i[s] || E) && (i[s] = A(P)), this.schemaEffect.triggerEffects(), this.modelEffect.triggerEffects());
|
|
160
131
|
},
|
|
161
132
|
o,
|
|
162
133
|
f
|
|
@@ -165,16 +136,16 @@ class O {
|
|
|
165
136
|
}
|
|
166
137
|
schemaProcessor(e, t, i, f, o) {
|
|
167
138
|
const s = {}, l = this;
|
|
168
|
-
function
|
|
169
|
-
var
|
|
139
|
+
function P(E = !1) {
|
|
140
|
+
var a, y;
|
|
170
141
|
if (s.componentProps) {
|
|
171
|
-
const
|
|
142
|
+
const u = {};
|
|
172
143
|
l.propsProcessor(
|
|
173
144
|
s.componentProps,
|
|
174
145
|
l.componentPropsPreset,
|
|
175
|
-
|
|
176
|
-
(
|
|
177
|
-
s.componentProps =
|
|
146
|
+
u,
|
|
147
|
+
(m) => {
|
|
148
|
+
s.componentProps = u, i({ ...s }, m, "componentProps");
|
|
178
149
|
},
|
|
179
150
|
t,
|
|
180
151
|
f
|
|
@@ -182,24 +153,24 @@ class O {
|
|
|
182
153
|
return;
|
|
183
154
|
}
|
|
184
155
|
if (s.children) {
|
|
185
|
-
l.processedSchemas.value[t] = s, l.rawSchemas[t] = s, i({ ...s },
|
|
156
|
+
l.processedSchemas.value[t] = s, l.rawSchemas[t] = s, i({ ...s }, E), l.schemaAnalyzer(
|
|
186
157
|
s.children,
|
|
187
158
|
// @ts-expect-error 此处已经守卫为非 ItemSchema
|
|
188
|
-
(
|
|
159
|
+
(a = l.processedSchemas.value[t]) == null ? void 0 : a.children,
|
|
189
160
|
// @ts-expect-error 此处已经守卫为非 ItemSchema
|
|
190
|
-
(
|
|
161
|
+
(y = l.rawSchemas[t]) == null ? void 0 : y.children,
|
|
191
162
|
s.field,
|
|
192
163
|
t
|
|
193
164
|
);
|
|
194
165
|
return;
|
|
195
166
|
}
|
|
196
|
-
i({ ...s },
|
|
167
|
+
i({ ...s }, E), l.rawModel = A(l.processedModel.value);
|
|
197
168
|
}
|
|
198
169
|
this.propsProcessor(
|
|
199
170
|
e,
|
|
200
171
|
this.schemaPreset,
|
|
201
172
|
s,
|
|
202
|
-
|
|
173
|
+
P,
|
|
203
174
|
t,
|
|
204
175
|
f,
|
|
205
176
|
o
|
|
@@ -218,91 +189,91 @@ class O {
|
|
|
218
189
|
runtimeMeta() {
|
|
219
190
|
return {
|
|
220
191
|
model: this.replaceFunctionsWithUndefined(
|
|
221
|
-
|
|
192
|
+
W(A(this.processedModel.value))
|
|
222
193
|
)
|
|
223
194
|
};
|
|
224
195
|
}
|
|
225
196
|
propsProcessor(e, t, i, f, o, s, l) {
|
|
226
|
-
const
|
|
227
|
-
length:
|
|
197
|
+
const P = Object.keys(e), E = Array.from({
|
|
198
|
+
length: P.length
|
|
228
199
|
}).fill(!1);
|
|
229
|
-
function
|
|
230
|
-
return
|
|
200
|
+
function a() {
|
|
201
|
+
return E.every((y) => y);
|
|
231
202
|
}
|
|
232
|
-
for (let
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
let n =
|
|
203
|
+
for (let y = 0; y < P.length; y++) {
|
|
204
|
+
const u = P[y], m = e[u];
|
|
205
|
+
if (p.isFunction(m)) {
|
|
206
|
+
const M = m(this.runtimeMeta());
|
|
207
|
+
u !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
208
|
+
let n = m(this.runtimeMeta());
|
|
238
209
|
n instanceof Promise ? n.then((r) => {
|
|
239
|
-
s === void 0 ?
|
|
240
|
-
}) : s === void 0 ?
|
|
210
|
+
s === void 0 ? p.isFunction(r) || (typeof r == "string" && r.includes("undefined") && (r = r.replace(/undefined/g, "")), this.processedSchemas.value[o][u] = r) : p.isFunction(r) || (typeof r == "string" && r.includes("undefined") && (r = r.replace(/undefined/g, "")), this.processedSchemas.value[s].children[o][u] = r);
|
|
211
|
+
}) : s === void 0 ? p.isFunction(n) || (typeof n == "string" && n.includes("undefined") && (n = n.replace(/undefined/g, "")), this.processedSchemas.value[o][u] = n) : p.isFunction(n) || (typeof n == "string" && n.includes("undefined") && (n = n.replace(/undefined/g, "")), this.processedSchemas.value[s].children[o][u] = n);
|
|
241
212
|
}) : this.modelEffect.trackEffect(() => {
|
|
242
|
-
let n =
|
|
213
|
+
let n = m(this.runtimeMeta());
|
|
243
214
|
this.stopWatchEffect.trackEffect(
|
|
244
|
-
|
|
245
|
-
if (n =
|
|
215
|
+
z(() => {
|
|
216
|
+
if (n = m(this.runtimeMeta()), n instanceof Promise)
|
|
246
217
|
n.then((r) => {
|
|
247
218
|
if (typeof r == "string" && !r.includes("undefined") ? this.stopWatchEffect.triggerEffects() : r = r.replace(/undefined/g, ""), o === void 0 || l === void 0) {
|
|
248
|
-
if (
|
|
249
|
-
const
|
|
219
|
+
if (p.isFunction(e.field)) {
|
|
220
|
+
const h = e.field(
|
|
250
221
|
this.runtimeMeta()
|
|
251
222
|
);
|
|
252
|
-
|
|
223
|
+
h instanceof Promise ? h.then((g) => {
|
|
253
224
|
this.processedModel.value[g] = r;
|
|
254
|
-
}) : this.processedModel.value[
|
|
225
|
+
}) : this.processedModel.value[h] = r;
|
|
255
226
|
return;
|
|
256
227
|
}
|
|
257
228
|
this.processedModel.value[e.field] = r;
|
|
258
229
|
} else {
|
|
259
|
-
if (
|
|
260
|
-
const
|
|
230
|
+
if (p.isFunction(e.field)) {
|
|
231
|
+
const h = e.field(
|
|
261
232
|
this.runtimeMeta()
|
|
262
233
|
);
|
|
263
|
-
|
|
234
|
+
h instanceof Promise ? h.then((g) => {
|
|
264
235
|
this.processedModel.value[l][o][g] = r;
|
|
265
|
-
}) : this.processedModel.value[l][o] && (this.processedModel.value[l][o][
|
|
236
|
+
}) : this.processedModel.value[l][o] && (this.processedModel.value[l][o][h] = r);
|
|
266
237
|
return;
|
|
267
238
|
}
|
|
268
239
|
this.processedModel.value[l] && this.processedModel.value[l].forEach(
|
|
269
240
|
// @ts-expect-error
|
|
270
|
-
(
|
|
271
|
-
|
|
241
|
+
(h) => {
|
|
242
|
+
h[e.field] = r;
|
|
272
243
|
}
|
|
273
244
|
);
|
|
274
245
|
}
|
|
275
246
|
this.rawModel = A(this.processedModel.value), this.modelEffect.clearEffects();
|
|
276
247
|
});
|
|
277
248
|
else {
|
|
278
|
-
if (typeof n == "string" && !n.includes("undefined") ? this.stopWatchEffect.triggerEffects() : n = n.replace(/undefined/g, ""),
|
|
249
|
+
if (typeof n == "string" && !n.includes("undefined") ? this.stopWatchEffect.triggerEffects() : n = n.replace(/undefined/g, ""), p.isFunction(e.field)) {
|
|
279
250
|
const r = e.field(this.runtimeMeta());
|
|
280
|
-
r instanceof Promise ? r.then((
|
|
281
|
-
this.processedModel.value[
|
|
251
|
+
r instanceof Promise ? r.then((h) => {
|
|
252
|
+
this.processedModel.value[h] = n;
|
|
282
253
|
}) : this.processedModel.value[r] = n;
|
|
283
254
|
return;
|
|
284
255
|
}
|
|
285
256
|
if (this.processedModel.value[e.field] = n, o === void 0 || l === void 0) {
|
|
286
|
-
if (
|
|
257
|
+
if (p.isFunction(e.field)) {
|
|
287
258
|
const r = e.field(this.runtimeMeta());
|
|
288
|
-
r instanceof Promise ? r.then((
|
|
289
|
-
this.processedModel.value[
|
|
259
|
+
r instanceof Promise ? r.then((h) => {
|
|
260
|
+
this.processedModel.value[h] = n;
|
|
290
261
|
}) : this.processedModel.value[r] = n;
|
|
291
262
|
return;
|
|
292
263
|
}
|
|
293
264
|
this.processedModel.value[e.field] = n;
|
|
294
265
|
} else
|
|
295
266
|
for (let r = 0; r < this.processedModel.value[l].length; r++) {
|
|
296
|
-
const
|
|
297
|
-
if (!
|
|
298
|
-
|
|
267
|
+
const h = this.processedModel.value[l][r];
|
|
268
|
+
if (!p.isFunction(e.field))
|
|
269
|
+
h[e.field] = n;
|
|
299
270
|
else {
|
|
300
271
|
const g = e.field(
|
|
301
272
|
this.runtimeMeta()
|
|
302
273
|
);
|
|
303
|
-
g instanceof Promise ? g.then((
|
|
304
|
-
|
|
305
|
-
}) :
|
|
274
|
+
g instanceof Promise ? g.then((N) => {
|
|
275
|
+
h[N] = n;
|
|
276
|
+
}) : h[g] = n;
|
|
306
277
|
return;
|
|
307
278
|
}
|
|
308
279
|
}
|
|
@@ -310,86 +281,94 @@ class O {
|
|
|
310
281
|
}
|
|
311
282
|
})
|
|
312
283
|
);
|
|
313
|
-
}),
|
|
314
|
-
y
|
|
315
|
-
})) : (y
|
|
284
|
+
}), M instanceof Promise ? (E[y] = !0, i[u] = t[u].defaultValueWhenAsync, a() && f(), M.then((n) => {
|
|
285
|
+
E[y] = !0, i[u] = n, a() && f(!0);
|
|
286
|
+
})) : (E[y] = !0, i[u] = M, a() && f());
|
|
316
287
|
} else
|
|
317
|
-
y
|
|
318
|
-
() =>
|
|
319
|
-
(
|
|
320
|
-
i[
|
|
288
|
+
E[y] = !0, _(m) ? S(
|
|
289
|
+
() => m.value,
|
|
290
|
+
(M) => {
|
|
291
|
+
i[u] = M, a() && f();
|
|
321
292
|
},
|
|
322
293
|
{
|
|
323
294
|
immediate: !0,
|
|
324
295
|
deep: !0
|
|
325
296
|
}
|
|
326
|
-
) :
|
|
327
|
-
() =>
|
|
328
|
-
(
|
|
329
|
-
i[
|
|
297
|
+
) : B(m) ? S(
|
|
298
|
+
() => m,
|
|
299
|
+
(M) => {
|
|
300
|
+
i[u] = M, a() && f();
|
|
330
301
|
},
|
|
331
302
|
{
|
|
332
303
|
immediate: !0,
|
|
333
304
|
deep: !0
|
|
334
305
|
}
|
|
335
|
-
) : (i[
|
|
306
|
+
) : (i[u] = m, a() && f());
|
|
336
307
|
}
|
|
337
308
|
}
|
|
338
309
|
modelProcessor(e, t = this.processedModel.value) {
|
|
339
|
-
if (
|
|
340
|
-
if (
|
|
310
|
+
if (p.isListSchema(e)) {
|
|
311
|
+
if (p.isFunction(e.field))
|
|
341
312
|
return;
|
|
342
313
|
t[e.field] || (t[e.field] = [{}]), e.children.forEach((i) => {
|
|
343
314
|
this.modelProcessor(i, t[e.field][0]);
|
|
344
315
|
});
|
|
345
316
|
return;
|
|
346
317
|
}
|
|
347
|
-
if (
|
|
318
|
+
if (p.isGroupSchema(e)) {
|
|
348
319
|
e.children.forEach((i) => {
|
|
349
320
|
this.modelProcessor(i, t);
|
|
350
321
|
});
|
|
351
322
|
return;
|
|
352
323
|
}
|
|
353
|
-
if (
|
|
354
|
-
if (
|
|
324
|
+
if (p.isItemSchema(e)) {
|
|
325
|
+
if (p.isFunction(e.field) || p.isUndefined(e.field) || !Number.isNaN(Number(e.field)) || p.isFunction(e.defaultValue))
|
|
355
326
|
return;
|
|
356
327
|
t[e.field] = e.defaultValue;
|
|
357
328
|
}
|
|
358
329
|
}
|
|
359
330
|
}
|
|
360
|
-
function
|
|
361
|
-
return typeof c == "function" || Object.prototype.toString.call(c) === "[object Object]" && !
|
|
331
|
+
function D(c) {
|
|
332
|
+
return typeof c == "function" || Object.prototype.toString.call(c) === "[object Object]" && !G(c);
|
|
362
333
|
}
|
|
363
|
-
class
|
|
334
|
+
class H {
|
|
364
335
|
constructor(e) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
336
|
+
d(this, "schemas", k([]));
|
|
337
|
+
d(this, "model", k({}));
|
|
338
|
+
d(this, "processorBySchemaType", {
|
|
368
339
|
item: this.runtimeItemProcessor.bind(this),
|
|
369
340
|
group: this.runtimeGroupProcessor.bind(this),
|
|
370
341
|
list: this.runtimeListProcessor.bind(this)
|
|
371
342
|
});
|
|
372
|
-
|
|
343
|
+
d(this, "formRef", k(null));
|
|
373
344
|
this.setup = e, this.processors = new O(this.schemas, this.model), this.analyze(this.setup(this));
|
|
374
345
|
}
|
|
375
346
|
analyze(e) {
|
|
376
347
|
this.processors.schemaAnalyzer(e.schemas);
|
|
377
348
|
}
|
|
378
349
|
runtimeItemProcessor(e, t, i = this.model.value, f) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
350
|
+
var m;
|
|
351
|
+
const o = f ? `${f.field}.${t}.${e.field}` : e.field, s = W(e.component), l = s.name, P = e.componentProps ?? {}, E = b.placeholderPresetByComponentName;
|
|
352
|
+
let a = e.placeholder;
|
|
353
|
+
a || (a = `${// @ts-expect-error
|
|
354
|
+
E[l] ?? "请输入"}${e.label}`), e.required && (e.rules || (e.rules = []), (m = e.rules) == null || m.push({
|
|
355
|
+
required: !0,
|
|
356
|
+
message: `${e.label}是必填项`
|
|
357
|
+
}));
|
|
358
|
+
let u = e.show;
|
|
359
|
+
return u === void 0 && (u = !0), u || delete i[e.field], v(w.runtimeDoms.Item, null, {
|
|
382
360
|
default() {
|
|
383
|
-
return
|
|
361
|
+
return C(v(w.runtimeDoms.FormItem, {
|
|
384
362
|
label: `${e.label}:`,
|
|
385
363
|
rules: e.rules,
|
|
386
364
|
field: o
|
|
387
365
|
}, {
|
|
388
|
-
default: () => [v(s,
|
|
366
|
+
default: () => [v(s, q({
|
|
389
367
|
modelValue: i[e.field],
|
|
390
|
-
"onUpdate:modelValue": (
|
|
391
|
-
|
|
392
|
-
|
|
368
|
+
"onUpdate:modelValue": (M) => i[e.field] = M,
|
|
369
|
+
placeholder: a
|
|
370
|
+
}, P), null)]
|
|
371
|
+
}), [[R, u]]);
|
|
393
372
|
}
|
|
394
373
|
});
|
|
395
374
|
}
|
|
@@ -397,13 +376,13 @@ class T {
|
|
|
397
376
|
let t;
|
|
398
377
|
return v(w.runtimeDoms.Group, {
|
|
399
378
|
schema: e
|
|
400
|
-
},
|
|
379
|
+
}, D(t = e.children.map((i) => this.runtimeItemProcessor(i))) ? t : {
|
|
401
380
|
default: () => [t]
|
|
402
381
|
});
|
|
403
382
|
}
|
|
404
383
|
addListItem(e) {
|
|
405
384
|
var t, i;
|
|
406
|
-
if (
|
|
385
|
+
if (!((t = this.processors.rawModel[e.field]) != null && t[0]))
|
|
407
386
|
return Promise.reject({
|
|
408
387
|
code: "0001",
|
|
409
388
|
message: "异步默认值数据正在处理中,请您耐心等待... "
|
|
@@ -428,16 +407,16 @@ class T {
|
|
|
428
407
|
} = {}) {
|
|
429
408
|
var l;
|
|
430
409
|
let s = o ?? v("button", null, null);
|
|
431
|
-
return
|
|
410
|
+
return C(v(s, {
|
|
432
411
|
onClick: () => t.deleteListItem(e, f)
|
|
433
|
-
}, null), [[
|
|
412
|
+
}, null), [[R, ((l = t.model.value[e.field]) == null ? void 0 : l.length) > 1]]);
|
|
434
413
|
}
|
|
435
414
|
}));
|
|
436
415
|
},
|
|
437
416
|
add({
|
|
438
417
|
container: i
|
|
439
418
|
} = {}) {
|
|
440
|
-
let f = i ?? v("button", null, [
|
|
419
|
+
let f = i ?? v("button", null, [$("添加")]);
|
|
441
420
|
return v(f, {
|
|
442
421
|
onClick: () => t.addListItem(e)
|
|
443
422
|
}, null);
|
|
@@ -452,17 +431,17 @@ class T {
|
|
|
452
431
|
return v(w.runtimeDoms.Form, {
|
|
453
432
|
ref: this.formRef,
|
|
454
433
|
model: this.model.value
|
|
455
|
-
},
|
|
434
|
+
}, D(e = this.runtimeProcessor(this.schemas.value)) ? e : {
|
|
456
435
|
default: () => [e]
|
|
457
436
|
});
|
|
458
437
|
}
|
|
459
438
|
}
|
|
460
439
|
class w {
|
|
461
440
|
}
|
|
462
|
-
|
|
463
|
-
class
|
|
441
|
+
d(w, "runtimeDoms");
|
|
442
|
+
class V {
|
|
464
443
|
constructor() {
|
|
465
|
-
|
|
444
|
+
d(this, "effects", /* @__PURE__ */ new Set());
|
|
466
445
|
}
|
|
467
446
|
clearEffects() {
|
|
468
447
|
this.effects.clear();
|
|
@@ -474,7 +453,58 @@ class k {
|
|
|
474
453
|
this.effects.add(e);
|
|
475
454
|
}
|
|
476
455
|
}
|
|
477
|
-
const
|
|
456
|
+
const F = class F {
|
|
457
|
+
static getPlaceholderPrefixPresetByComponentName() {
|
|
458
|
+
const e = {
|
|
459
|
+
请选择: ["Select", "Tree", "TreeSelect"],
|
|
460
|
+
请输入: ["Input"]
|
|
461
|
+
}, t = {};
|
|
462
|
+
for (let i in e)
|
|
463
|
+
e[i].forEach((f) => {
|
|
464
|
+
t[f] = i;
|
|
465
|
+
});
|
|
466
|
+
return t;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
d(F, "schemaPreset", {
|
|
470
|
+
type: {
|
|
471
|
+
defaultValueWhenAsync: "item"
|
|
472
|
+
},
|
|
473
|
+
component: {
|
|
474
|
+
defaultValueWhenAsync: void 0
|
|
475
|
+
},
|
|
476
|
+
componentProps: {
|
|
477
|
+
defaultValueWhenAsync: void 0
|
|
478
|
+
},
|
|
479
|
+
defaultValue: {
|
|
480
|
+
defaultValueWhenAsync: void 0
|
|
481
|
+
},
|
|
482
|
+
label: {
|
|
483
|
+
defaultValueWhenAsync: ""
|
|
484
|
+
},
|
|
485
|
+
field: {
|
|
486
|
+
defaultValueWhenAsync: "__yiwwhl_async_field_fallback"
|
|
487
|
+
},
|
|
488
|
+
rules: {
|
|
489
|
+
defaultValueWhenAsync: []
|
|
490
|
+
},
|
|
491
|
+
show: {
|
|
492
|
+
defaultValueWhenAsync: !0
|
|
493
|
+
},
|
|
494
|
+
required: {
|
|
495
|
+
defaultValueWhenAsync: !1
|
|
496
|
+
},
|
|
497
|
+
placeholder: {
|
|
498
|
+
defaultValueWhenAsync: void 0
|
|
499
|
+
}
|
|
500
|
+
}), d(F, "componentPropsPreset", {
|
|
501
|
+
options: {
|
|
502
|
+
defaultValueWhenAsync: []
|
|
503
|
+
}
|
|
504
|
+
}), // 基于基本功能提出基本预设
|
|
505
|
+
d(F, "placeholderPresetByComponentName", F.getPlaceholderPrefixPresetByComponentName());
|
|
506
|
+
let b = F;
|
|
507
|
+
const Q = /* @__PURE__ */ T({
|
|
478
508
|
props: {
|
|
479
509
|
setup: {
|
|
480
510
|
type: Function,
|
|
@@ -482,12 +512,12 @@ const J = /* @__PURE__ */ $({
|
|
|
482
512
|
}
|
|
483
513
|
},
|
|
484
514
|
setup(c) {
|
|
485
|
-
const e = new
|
|
515
|
+
const e = new H(c.setup);
|
|
486
516
|
return () => e.exec();
|
|
487
517
|
}
|
|
488
518
|
});
|
|
489
|
-
function
|
|
490
|
-
const e = new
|
|
519
|
+
function X(c) {
|
|
520
|
+
const e = new U(c);
|
|
491
521
|
return [
|
|
492
522
|
e.setup.bind(e),
|
|
493
523
|
{
|
|
@@ -495,7 +525,7 @@ function K(c) {
|
|
|
495
525
|
}
|
|
496
526
|
];
|
|
497
527
|
}
|
|
498
|
-
function
|
|
528
|
+
function Y(c) {
|
|
499
529
|
return {
|
|
500
530
|
install() {
|
|
501
531
|
w.runtimeDoms = c;
|
|
@@ -503,7 +533,7 @@ function Q(c) {
|
|
|
503
533
|
};
|
|
504
534
|
}
|
|
505
535
|
export {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
536
|
+
Q as ProForm,
|
|
537
|
+
X as useForm,
|
|
538
|
+
Y as useFormRenderer
|
|
509
539
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyObject, ItemSchema } from "../types";
|
|
2
|
+
export default class Preset {
|
|
3
|
+
static schemaPreset: Record<keyof ItemSchema, any>;
|
|
4
|
+
static componentPropsPreset: AnyObject;
|
|
5
|
+
static placeholderPresetByComponentName: {};
|
|
6
|
+
static getPlaceholderPrefixPresetByComponentName(): {};
|
|
7
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Ref } from "vue";
|
|
2
|
-
import { AnyObject, Schema,
|
|
2
|
+
import { AnyObject, Schema, ProxyedSchema, AnyFunction } from "../types";
|
|
3
3
|
import { Effect } from "../services";
|
|
4
4
|
export default class Processors {
|
|
5
5
|
processedSchemas: Ref<Schema[]>;
|
|
6
6
|
processedModel: Ref<AnyObject>;
|
|
7
7
|
rawSchemas: ProxyedSchema[];
|
|
8
8
|
rawModel: AnyObject;
|
|
9
|
-
schemaPreset: Record<keyof ItemSchema, any>;
|
|
9
|
+
schemaPreset: Record<keyof import("../types").ItemSchema, any>;
|
|
10
10
|
componentPropsPreset: AnyObject;
|
|
11
11
|
uniqueEffectMap: any;
|
|
12
12
|
schemaEffect: Effect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harbor-design/proform",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,9 +26,6 @@
|
|
|
26
26
|
"author": "yiwwhl<yiwwhl@qq.com>",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"scripts": {
|
|
29
|
-
"build": "vue-tsc && vite build"
|
|
30
|
-
"prerelease": "pnpm build",
|
|
31
|
-
"release": "pnpm prerelease && changeset && pnpm postrelease",
|
|
32
|
-
"postrelease": "changeset version && changeset publish && git push --follow-tags"
|
|
29
|
+
"build": "vue-tsc && vite build"
|
|
33
30
|
}
|
|
34
31
|
}
|