@harbor-design/proform 1.0.1 → 1.0.3
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 +19 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +57 -58
- package/package.json +4 -2
package/CHANGELOG.md
ADDED
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)}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||(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.watchEffect(()=>{})):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 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=_;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (c, e, t) => (
|
|
4
|
-
import { toRaw as S, watch as F, watchEffect as
|
|
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 v, withDirectives as V, mergeProps as N, vShow as W, createTextVNode as G, isVNode as U, defineComponent as $ } from "vue";
|
|
5
5
|
class B {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
h(this, "runtimeCore");
|
|
@@ -152,11 +152,11 @@ class O {
|
|
|
152
152
|
this.schemaProcessor(
|
|
153
153
|
l,
|
|
154
154
|
s,
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
(p, y, m) => {
|
|
156
|
+
m ? i[s][m] = p[m] : (t[s] = p, this.modelProcessor(
|
|
157
|
+
p,
|
|
158
158
|
f && this.processedModel.value[f][0]
|
|
159
|
-
), (!i[s] || y) && (i[s] = A(
|
|
159
|
+
), (!i[s] || y) && (i[s] = A(p)), this.schemaEffect.triggerEffects(), this.modelEffect.triggerEffects());
|
|
160
160
|
},
|
|
161
161
|
o,
|
|
162
162
|
f
|
|
@@ -165,16 +165,16 @@ class O {
|
|
|
165
165
|
}
|
|
166
166
|
schemaProcessor(e, t, i, f, o) {
|
|
167
167
|
const s = {}, l = this;
|
|
168
|
-
function
|
|
169
|
-
var
|
|
168
|
+
function p(y = !1) {
|
|
169
|
+
var m, E;
|
|
170
170
|
if (s.componentProps) {
|
|
171
171
|
const a = {};
|
|
172
172
|
l.propsProcessor(
|
|
173
173
|
s.componentProps,
|
|
174
174
|
l.componentPropsPreset,
|
|
175
175
|
a,
|
|
176
|
-
(
|
|
177
|
-
s.componentProps = a, i({ ...s },
|
|
176
|
+
(M) => {
|
|
177
|
+
s.componentProps = a, i({ ...s }, M, "componentProps");
|
|
178
178
|
},
|
|
179
179
|
t,
|
|
180
180
|
f
|
|
@@ -185,7 +185,7 @@ class O {
|
|
|
185
185
|
l.processedSchemas.value[t] = s, l.rawSchemas[t] = s, i({ ...s }, y), l.schemaAnalyzer(
|
|
186
186
|
s.children,
|
|
187
187
|
// @ts-expect-error 此处已经守卫为非 ItemSchema
|
|
188
|
-
(
|
|
188
|
+
(m = l.processedSchemas.value[t]) == null ? void 0 : m.children,
|
|
189
189
|
// @ts-expect-error 此处已经守卫为非 ItemSchema
|
|
190
190
|
(E = l.rawSchemas[t]) == null ? void 0 : E.children,
|
|
191
191
|
s.field,
|
|
@@ -193,13 +193,13 @@ class O {
|
|
|
193
193
|
);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
i({ ...s }, y);
|
|
196
|
+
i({ ...s }, y), l.rawModel = A(l.processedModel.value);
|
|
197
197
|
}
|
|
198
198
|
this.propsProcessor(
|
|
199
199
|
e,
|
|
200
200
|
this.schemaPreset,
|
|
201
201
|
s,
|
|
202
|
-
|
|
202
|
+
p,
|
|
203
203
|
t,
|
|
204
204
|
f,
|
|
205
205
|
o
|
|
@@ -223,26 +223,26 @@ class O {
|
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
propsProcessor(e, t, i, f, o, s, l) {
|
|
226
|
-
const
|
|
227
|
-
length:
|
|
226
|
+
const p = Object.keys(e), y = Array.from({
|
|
227
|
+
length: p.length
|
|
228
228
|
}).fill(!1);
|
|
229
|
-
function
|
|
229
|
+
function m() {
|
|
230
230
|
return y.every((E) => E);
|
|
231
231
|
}
|
|
232
|
-
for (let E = 0; E <
|
|
233
|
-
const a =
|
|
234
|
-
if (d.isFunction(
|
|
235
|
-
const P =
|
|
232
|
+
for (let E = 0; E < p.length; E++) {
|
|
233
|
+
const a = p[E], M = e[a];
|
|
234
|
+
if (d.isFunction(M)) {
|
|
235
|
+
const P = M(this.runtimeMeta());
|
|
236
236
|
a !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
|
|
237
|
-
let n =
|
|
237
|
+
let n = M(this.runtimeMeta());
|
|
238
238
|
n instanceof Promise ? n.then((r) => {
|
|
239
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
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);
|
|
241
241
|
}) : this.modelEffect.trackEffect(() => {
|
|
242
|
-
let n =
|
|
242
|
+
let n = M(this.runtimeMeta());
|
|
243
243
|
this.stopWatchEffect.trackEffect(
|
|
244
|
-
|
|
245
|
-
if (n =
|
|
244
|
+
j(() => {
|
|
245
|
+
if (n = M(this.runtimeMeta()), n instanceof Promise)
|
|
246
246
|
n.then((r) => {
|
|
247
247
|
if (typeof r == "string" && !r.includes("undefined") ? this.stopWatchEffect.triggerEffects() : r = r.replace(/undefined/g, ""), o === void 0 || l === void 0) {
|
|
248
248
|
if (d.isFunction(e.field)) {
|
|
@@ -300,40 +300,39 @@ class O {
|
|
|
300
300
|
const g = e.field(
|
|
301
301
|
this.runtimeMeta()
|
|
302
302
|
);
|
|
303
|
-
g instanceof Promise ? g.then((
|
|
304
|
-
u[
|
|
303
|
+
g instanceof Promise ? g.then((C) => {
|
|
304
|
+
u[C] = n;
|
|
305
305
|
}) : u[g] = n;
|
|
306
306
|
return;
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
-
this.rawModel
|
|
309
|
+
this.rawModel = A(this.processedModel.value), this.modelEffect.clearEffects();
|
|
310
310
|
}
|
|
311
311
|
})
|
|
312
312
|
);
|
|
313
|
-
}), P instanceof Promise ? (y[E] = !0, i[a] = t[a].defaultValueWhenAsync,
|
|
314
|
-
y[E] = !0, i[a] = n,
|
|
315
|
-
})) : (y[E] = !0, i[a] = P,
|
|
313
|
+
}), P instanceof Promise ? (y[E] = !0, i[a] = t[a].defaultValueWhenAsync, m() && f(), P.then((n) => {
|
|
314
|
+
y[E] = !0, i[a] = n, m() && f(!0);
|
|
315
|
+
})) : (y[E] = !0, i[a] = P, m() && f());
|
|
316
316
|
} else
|
|
317
|
-
y[E] = !0, L(
|
|
318
|
-
() =>
|
|
317
|
+
y[E] = !0, L(M) ? F(
|
|
318
|
+
() => M.value,
|
|
319
319
|
(P) => {
|
|
320
|
-
i[a] = P,
|
|
320
|
+
i[a] = P, m() && f();
|
|
321
321
|
},
|
|
322
322
|
{
|
|
323
323
|
immediate: !0,
|
|
324
324
|
deep: !0
|
|
325
325
|
}
|
|
326
|
-
)
|
|
327
|
-
|
|
328
|
-
() => v,
|
|
326
|
+
) : z(M) ? F(
|
|
327
|
+
() => M,
|
|
329
328
|
(P) => {
|
|
330
|
-
i[a] = P,
|
|
329
|
+
i[a] = P, m() && f();
|
|
331
330
|
},
|
|
332
331
|
{
|
|
333
332
|
immediate: !0,
|
|
334
333
|
deep: !0
|
|
335
334
|
}
|
|
336
|
-
) : (i[a] =
|
|
335
|
+
) : (i[a] = M, m() && f());
|
|
337
336
|
}
|
|
338
337
|
}
|
|
339
338
|
modelProcessor(e, t = this.processedModel.value) {
|
|
@@ -358,7 +357,7 @@ class O {
|
|
|
358
357
|
}
|
|
359
358
|
}
|
|
360
359
|
}
|
|
361
|
-
function
|
|
360
|
+
function R(c) {
|
|
362
361
|
return typeof c == "function" || Object.prototype.toString.call(c) === "[object Object]" && !U(c);
|
|
363
362
|
}
|
|
364
363
|
class T {
|
|
@@ -378,33 +377,33 @@ class T {
|
|
|
378
377
|
}
|
|
379
378
|
runtimeItemProcessor(e, t, i = this.model.value, f) {
|
|
380
379
|
const o = f ? `${f.field}.${t}.${e.field}` : e.field, s = S(e.component), l = e.componentProps ?? {};
|
|
381
|
-
let
|
|
382
|
-
return
|
|
380
|
+
let p = e.show;
|
|
381
|
+
return p === void 0 && (p = !0), p || delete i[e.field], v(w.runtimeDoms.Item, null, {
|
|
383
382
|
default() {
|
|
384
|
-
return
|
|
383
|
+
return V(v(w.runtimeDoms.FormItem, {
|
|
385
384
|
label: `${e.label}:`,
|
|
386
385
|
rules: e.rules,
|
|
387
386
|
field: o
|
|
388
387
|
}, {
|
|
389
|
-
default: () => [
|
|
388
|
+
default: () => [v(s, N({
|
|
390
389
|
modelValue: i[e.field],
|
|
391
390
|
"onUpdate:modelValue": (y) => i[e.field] = y
|
|
392
391
|
}, l), null)]
|
|
393
|
-
}), [[
|
|
392
|
+
}), [[W, p]]);
|
|
394
393
|
}
|
|
395
394
|
});
|
|
396
395
|
}
|
|
397
396
|
runtimeGroupProcessor(e) {
|
|
398
397
|
let t;
|
|
399
|
-
return
|
|
398
|
+
return v(w.runtimeDoms.Group, {
|
|
400
399
|
schema: e
|
|
401
|
-
},
|
|
400
|
+
}, R(t = e.children.map((i) => this.runtimeItemProcessor(i))) ? t : {
|
|
402
401
|
default: () => [t]
|
|
403
402
|
});
|
|
404
403
|
}
|
|
405
404
|
addListItem(e) {
|
|
406
405
|
var t, i;
|
|
407
|
-
if (!((t = this.processors.rawModel[e.field]) != null && t[0]))
|
|
406
|
+
if (console.log(this.processors.rawModel, e.field), !((t = this.processors.rawModel[e.field]) != null && t[0]))
|
|
408
407
|
return Promise.reject({
|
|
409
408
|
code: "0001",
|
|
410
409
|
message: "异步默认值数据正在处理中,请您耐心等待... "
|
|
@@ -416,11 +415,11 @@ class T {
|
|
|
416
415
|
}
|
|
417
416
|
runtimeListProcessor(e) {
|
|
418
417
|
const t = this;
|
|
419
|
-
return
|
|
418
|
+
return v(w.runtimeDoms.List, {
|
|
420
419
|
schema: e
|
|
421
420
|
}, {
|
|
422
421
|
default() {
|
|
423
|
-
return t.model.value[e.field].map((i, f) =>
|
|
422
|
+
return t.model.value[e.field].map((i, f) => v(w.runtimeDoms.ListItem, null, {
|
|
424
423
|
default() {
|
|
425
424
|
return e.children.map((o, s) => t.runtimeItemProcessor(o, s, i, e));
|
|
426
425
|
},
|
|
@@ -428,18 +427,18 @@ class T {
|
|
|
428
427
|
container: o
|
|
429
428
|
} = {}) {
|
|
430
429
|
var l;
|
|
431
|
-
let s = o ??
|
|
432
|
-
return
|
|
430
|
+
let s = o ?? v("button", null, null);
|
|
431
|
+
return V(v(s, {
|
|
433
432
|
onClick: () => t.deleteListItem(e, f)
|
|
434
|
-
}, null), [[
|
|
433
|
+
}, null), [[W, ((l = t.model.value[e.field]) == null ? void 0 : l.length) > 1]]);
|
|
435
434
|
}
|
|
436
435
|
}));
|
|
437
436
|
},
|
|
438
437
|
add({
|
|
439
438
|
container: i
|
|
440
439
|
} = {}) {
|
|
441
|
-
let f = i ??
|
|
442
|
-
return
|
|
440
|
+
let f = i ?? v("button", null, [G("添加")]);
|
|
441
|
+
return v(f, {
|
|
443
442
|
onClick: () => t.addListItem(e)
|
|
444
443
|
}, null);
|
|
445
444
|
}
|
|
@@ -450,10 +449,10 @@ class T {
|
|
|
450
449
|
}
|
|
451
450
|
exec() {
|
|
452
451
|
let e;
|
|
453
|
-
return
|
|
452
|
+
return v(w.runtimeDoms.Form, {
|
|
454
453
|
ref: this.formRef,
|
|
455
454
|
model: this.model.value
|
|
456
|
-
},
|
|
455
|
+
}, R(e = this.runtimeProcessor(this.schemas.value)) ? e : {
|
|
457
456
|
default: () => [e]
|
|
458
457
|
});
|
|
459
458
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harbor-design/proform",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist/"
|
|
22
|
+
"dist/",
|
|
23
|
+
"./LICENSE",
|
|
24
|
+
"./CHANGELOG.md"
|
|
23
25
|
],
|
|
24
26
|
"author": "yiwwhl<yiwwhl@qq.com>",
|
|
25
27
|
"license": "MIT",
|