vexip-ui
Version:
A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good
3 lines (2 loc) • 1.99 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),u=require("@vexip-ui/utils"),f=require("./symbol.cjs");function F(t,e,i=!1){if(!t||!e)return null;if(typeof e=="string"){if(e in t)return t[e];e=e.split(".")}if(Array.isArray(e)&&e.length){const r=e.pop();if(!r)return null;for(let l=0,s=e.length;l<s;++l){const a=String(e[l]);if(!a)break;if(t=t[a],u.isNull(t)){if(i)throw new Error("[vexip-ui:Form] Get value by an invalid path");return t}}if(i&&u.isNull(t[r]))throw new Error("[vexip-ui:Form] Get value by an invalid path");return t[r]}return null}function g(t,e,i,r=!1){if(!t||!e)return!1;if(typeof e=="string"){if(e in t)return t[e]=i,!0;e=e.split(".")}if(Array.isArray(e)&&e.length){const l=e.pop();if(!l)return!1;for(let s=0,a=e.length;s<a;++s){const o=String(e[s]);if(!o)return!1;if(typeof t[o]!="object"){if(r)throw new Error("[vexip-ui:Form] Set value by an invalid path");t[o]={}}t=t[o]}if(r&&typeof t!="object")throw new Error("[vexip-ui:Form] Set value by an invalid path");return t[l]=i,!0}return!1}const d=n.computed(()=>{}),v=n.computed(()=>"default"),c=n.computed(()=>!1),m=n.computed(()=>"default");function y(){return{isField:!1,idFor:d,labelId:d,state:v,disabled:c,loading:c,size:m,validateField:u.noop,clearField:u.noop,resetField:u.toFalse,getFieldValue:t=>t,setFieldValue:u.noop}}function S(t){const e=n.getCurrentInstance();if(!e)return y();const i=n.inject(f.FIELD_OPTIONS,null);if(!i)return y();n.provide(f.FIELD_OPTIONS,null),i.sync(e),t&&i.emitter.on("focus",t),n.onBeforeUnmount(()=>{i.unSync(e),t&&i.emitter.off("focus",t)});function r(l){i&&(i.setValue(l),i.clearError())}return{isField:!0,idFor:i.idFor,labelId:i.labelId,state:i.state,disabled:i.disabled,loading:i.loading,size:i.size,validateField:i.validate,clearField:r,resetField:i.reset,getFieldValue:i.getValue,setFieldValue:i.setValue}}exports.getValueByPath=F;exports.setValueByPath=g;exports.useFieldStore=S;
//# sourceMappingURL=helper.cjs.map