@harbor-design/proform 1.0.5 → 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @harbor-design/proform
2
2
 
3
+ ## 1.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - support required and default placeholder
8
+
3
9
  ## 1.0.5
4
10
 
5
11
  ### Patch Changes
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(!((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 D = Object.defineProperty;
2
- var _ = (c, e, t) => e in c ? D(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
3
- var h = (c, e, t) => (_(c, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { toRaw as S, watch as F, watchEffect as j, isRef as L, isReactive as z, ref as b, createVNode as M, withDirectives as V, mergeProps as N, vShow as W, createTextVNode as G, isVNode as U, defineComponent as $ } from "vue";
5
- class B {
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
- h(this, "runtimeCore");
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
- S(this.runtimeCore.processors.processedModel.value)
23
+ W(this.runtimeCore.processors.processedModel.value)
24
24
  )
25
25
  ));
26
26
  });
27
27
  }
28
28
  }
29
- class d {
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
- h(this, "rawSchemas", []);
103
- h(this, "rawModel", {});
104
- h(this, "schemaPreset", {
105
- type: {
106
- defaultValueWhenAsync: "item"
107
- },
108
- component: {
109
- defaultValueWhenAsync: void 0
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
- (m, y, p) => {
156
- p ? i[s][p] = m[p] : (t[s] = m, this.modelProcessor(
157
- m,
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] || y) && (i[s] = A(m)), this.schemaEffect.triggerEffects(), this.modelEffect.triggerEffects());
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 m(y = !1) {
169
- var p, E;
139
+ function P(E = !1) {
140
+ var a, y;
170
141
  if (s.componentProps) {
171
- const a = {};
142
+ const u = {};
172
143
  l.propsProcessor(
173
144
  s.componentProps,
174
145
  l.componentPropsPreset,
175
- a,
176
- (v) => {
177
- s.componentProps = a, i({ ...s }, v, "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 }, y), l.schemaAnalyzer(
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
- (p = l.processedSchemas.value[t]) == null ? void 0 : p.children,
159
+ (a = l.processedSchemas.value[t]) == null ? void 0 : a.children,
189
160
  // @ts-expect-error 此处已经守卫为非 ItemSchema
190
- (E = l.rawSchemas[t]) == null ? void 0 : E.children,
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 }, y), l.rawModel = A(l.processedModel.value);
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
- m,
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
- S(A(this.processedModel.value))
192
+ W(A(this.processedModel.value))
222
193
  )
223
194
  };
224
195
  }
225
196
  propsProcessor(e, t, i, f, o, s, l) {
226
- const m = Object.keys(e), y = Array.from({
227
- length: m.length
197
+ const P = Object.keys(e), E = Array.from({
198
+ length: P.length
228
199
  }).fill(!1);
229
- function p() {
230
- return y.every((E) => E);
200
+ function a() {
201
+ return E.every((y) => y);
231
202
  }
232
- for (let E = 0; E < m.length; E++) {
233
- const a = m[E], v = e[a];
234
- if (d.isFunction(v)) {
235
- const P = v(this.runtimeMeta());
236
- a !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
237
- let n = v(this.runtimeMeta());
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 ? d.isFunction(r) || (typeof r == "string" && r.includes("undefined") && (r = r.replace(/undefined/g, "")), this.processedSchemas.value[o][a] = r) : d.isFunction(r) || (typeof r == "string" && r.includes("undefined") && (r = r.replace(/undefined/g, "")), this.processedSchemas.value[s].children[o][a] = r);
240
- }) : s === void 0 ? d.isFunction(n) || (typeof n == "string" && n.includes("undefined") && (n = n.replace(/undefined/g, "")), this.processedSchemas.value[o][a] = n) : d.isFunction(n) || (typeof n == "string" && n.includes("undefined") && (n = n.replace(/undefined/g, "")), this.processedSchemas.value[s].children[o][a] = n);
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 = v(this.runtimeMeta());
213
+ let n = m(this.runtimeMeta());
243
214
  this.stopWatchEffect.trackEffect(
244
- j(() => {
245
- if (n = v(this.runtimeMeta()), n instanceof Promise)
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 (d.isFunction(e.field)) {
249
- const u = e.field(
219
+ if (p.isFunction(e.field)) {
220
+ const h = e.field(
250
221
  this.runtimeMeta()
251
222
  );
252
- u instanceof Promise ? u.then((g) => {
223
+ h instanceof Promise ? h.then((g) => {
253
224
  this.processedModel.value[g] = r;
254
- }) : this.processedModel.value[u] = r;
225
+ }) : this.processedModel.value[h] = r;
255
226
  return;
256
227
  }
257
228
  this.processedModel.value[e.field] = r;
258
229
  } else {
259
- if (d.isFunction(e.field)) {
260
- const u = e.field(
230
+ if (p.isFunction(e.field)) {
231
+ const h = e.field(
261
232
  this.runtimeMeta()
262
233
  );
263
- u instanceof Promise ? u.then((g) => {
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][u] = r);
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
- (u) => {
271
- u[e.field] = r;
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, ""), d.isFunction(e.field)) {
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((u) => {
281
- this.processedModel.value[u] = n;
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 (d.isFunction(e.field)) {
257
+ if (p.isFunction(e.field)) {
287
258
  const r = e.field(this.runtimeMeta());
288
- r instanceof Promise ? r.then((u) => {
289
- this.processedModel.value[u] = n;
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 u = this.processedModel.value[l][r];
297
- if (!d.isFunction(e.field))
298
- u[e.field] = n;
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((C) => {
304
- u[C] = n;
305
- }) : u[g] = n;
274
+ g instanceof Promise ? g.then((N) => {
275
+ h[N] = n;
276
+ }) : h[g] = n;
306
277
  return;
307
278
  }
308
279
  }
@@ -310,94 +281,102 @@ class O {
310
281
  }
311
282
  })
312
283
  );
313
- }), P instanceof Promise ? (y[E] = !0, i[a] = t[a].defaultValueWhenAsync, p() && f(), P.then((n) => {
314
- y[E] = !0, i[a] = n, p() && f(!0);
315
- })) : (y[E] = !0, i[a] = P, p() && f());
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[E] = !0, L(v) ? F(
318
- () => v.value,
319
- (P) => {
320
- i[a] = P, p() && f();
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
- ) : z(v) ? F(
327
- () => v,
328
- (P) => {
329
- i[a] = P, p() && f();
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[a] = v, p() && f());
306
+ ) : (i[u] = m, a() && f());
336
307
  }
337
308
  }
338
309
  modelProcessor(e, t = this.processedModel.value) {
339
- if (d.isListSchema(e)) {
340
- if (d.isFunction(e.field))
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 (d.isGroupSchema(e)) {
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 (d.isItemSchema(e)) {
354
- if (d.isFunction(e.field) || d.isUndefined(e.field) || !Number.isNaN(Number(e.field)) || d.isFunction(e.defaultValue))
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 R(c) {
361
- return typeof c == "function" || Object.prototype.toString.call(c) === "[object Object]" && !U(c);
331
+ function D(c) {
332
+ return typeof c == "function" || Object.prototype.toString.call(c) === "[object Object]" && !G(c);
362
333
  }
363
- class T {
334
+ class H {
364
335
  constructor(e) {
365
- h(this, "schemas", b([]));
366
- h(this, "model", b({}));
367
- h(this, "processorBySchemaType", {
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
- h(this, "formRef", b(null));
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
- const o = f ? `${f.field}.${t}.${e.field}` : e.field, s = S(e.component), l = e.componentProps ?? {};
380
- let m = e.show;
381
- return m === void 0 && (m = !0), m || delete i[e.field], M(w.runtimeDoms.Item, null, {
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 V(M(w.runtimeDoms.FormItem, {
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: () => [M(s, N({
366
+ default: () => [v(s, q({
389
367
  modelValue: i[e.field],
390
- "onUpdate:modelValue": (y) => i[e.field] = y
391
- }, l), null)]
392
- }), [[W, m]]);
368
+ "onUpdate:modelValue": (M) => i[e.field] = M,
369
+ placeholder: a
370
+ }, P), null)]
371
+ }), [[R, u]]);
393
372
  }
394
373
  });
395
374
  }
396
375
  runtimeGroupProcessor(e) {
397
376
  let t;
398
- return M(w.runtimeDoms.Group, {
377
+ return v(w.runtimeDoms.Group, {
399
378
  schema: e
400
- }, R(t = e.children.map((i) => this.runtimeItemProcessor(i))) ? t : {
379
+ }, D(t = e.children.map((i) => this.runtimeItemProcessor(i))) ? t : {
401
380
  default: () => [t]
402
381
  });
403
382
  }
@@ -415,11 +394,11 @@ class T {
415
394
  }
416
395
  runtimeListProcessor(e) {
417
396
  const t = this;
418
- return M(w.runtimeDoms.List, {
397
+ return v(w.runtimeDoms.List, {
419
398
  schema: e
420
399
  }, {
421
400
  default() {
422
- return t.model.value[e.field].map((i, f) => M(w.runtimeDoms.ListItem, null, {
401
+ return t.model.value[e.field].map((i, f) => v(w.runtimeDoms.ListItem, null, {
423
402
  default() {
424
403
  return e.children.map((o, s) => t.runtimeItemProcessor(o, s, i, e));
425
404
  },
@@ -427,18 +406,18 @@ class T {
427
406
  container: o
428
407
  } = {}) {
429
408
  var l;
430
- let s = o ?? M("button", null, null);
431
- return V(M(s, {
409
+ let s = o ?? v("button", null, null);
410
+ return C(v(s, {
432
411
  onClick: () => t.deleteListItem(e, f)
433
- }, null), [[W, ((l = t.model.value[e.field]) == null ? void 0 : l.length) > 1]]);
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 ?? M("button", null, [G("添加")]);
441
- return M(f, {
419
+ let f = i ?? v("button", null, [$("添加")]);
420
+ return v(f, {
442
421
  onClick: () => t.addListItem(e)
443
422
  }, null);
444
423
  }
@@ -449,20 +428,20 @@ class T {
449
428
  }
450
429
  exec() {
451
430
  let e;
452
- return M(w.runtimeDoms.Form, {
431
+ return v(w.runtimeDoms.Form, {
453
432
  ref: this.formRef,
454
433
  model: this.model.value
455
- }, R(e = this.runtimeProcessor(this.schemas.value)) ? e : {
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
- h(w, "runtimeDoms");
463
- class k {
441
+ d(w, "runtimeDoms");
442
+ class V {
464
443
  constructor() {
465
- h(this, "effects", /* @__PURE__ */ new Set());
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 J = /* @__PURE__ */ $({
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 T(c.setup);
515
+ const e = new H(c.setup);
486
516
  return () => e.exec();
487
517
  }
488
518
  });
489
- function K(c) {
490
- const e = new B(c);
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 Q(c) {
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
- J as ProForm,
507
- K as useForm,
508
- Q as useFormRenderer
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, ItemSchema, ProxyedSchema, AnyFunction } from "../types";
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;
@@ -3,3 +3,4 @@ export { default as RuntimeCore } from "./RuntimeCore";
3
3
  export { default as Context } from "./Context";
4
4
  export { default as Processors } from "./Processors";
5
5
  export { default as Effect } from "./Effect";
6
+ export { default as Preset } from "./Preset";
@@ -27,6 +27,8 @@ export interface ItemSchema {
27
27
  type?: "item";
28
28
  rules?: FieldRule[];
29
29
  show?: boolean;
30
+ required?: boolean;
31
+ placeholder?: string;
30
32
  label: string;
31
33
  field: string;
32
34
  component: DomType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbor-design/proform",
3
- "version": "1.0.5",
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
  }