@devtable/settings-form 8.50.3 → 8.50.5

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.
@@ -1,4 +1,4 @@
1
- const e = "@devtable/settings-form", s = "8.50.3", t = "Apache-2.0", i = {
1
+ const e = "@devtable/settings-form", s = "8.50.5", t = "Apache-2.0", i = {
2
2
  access: "public",
3
3
  registry: "https://registry.npmjs.org/"
4
4
  }, o = [
@@ -2308,7 +2308,7 @@ function Bt({
2308
2308
  })]
2309
2309
  });
2310
2310
  }
2311
- const Gt = () => import("./package.793c7118.mjs").then(({ version: t }) => (console.log(`[@devtable/dashboard] version: ${t}`), t));
2311
+ const Gt = () => import("./package.8256d562.mjs").then(({ version: t }) => (console.log(`[@devtable/dashboard] version: ${t}`), t));
2312
2312
  export {
2313
2313
  Bt as APIKeyList,
2314
2314
  Yt as AccountList,
@@ -26,4 +26,4 @@ Check your code at `+a+":"+d+"."}return""}}var dt={};function Sn(e){{var a=ut();
26
26
 
27
27
  Check the top-level render call using <`+d+">.")}return a}}function ft(e,a){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var d=Sn(a);if(dt[d])return;dt[d]=!0;var h="";e&&e._owner&&e._owner!==_e.current&&(h=" It was passed a child from "+L(e._owner.type)+"."),K(e),A('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',d,h),K(null)}}function pt(e,a){{if(typeof e!="object")return;if(ye(e))for(var d=0;d<e.length;d++){var h=e[d];Pe(h)&&ft(h,a)}else if(Pe(e))e._store&&(e._store.validated=!0);else if(e){var S=he(e);if(typeof S=="function"&&S!==e.entries)for(var R=S.call(e),w;!(w=R.next()).done;)Pe(w.value)&&ft(w.value,a)}}}function Pn(e){{var a=e.type;if(a==null||typeof a=="string")return;var d;if(typeof a=="function")d=a.propTypes;else if(typeof a=="object"&&(a.$$typeof===g||a.$$typeof===m))d=a.propTypes;else return;if(d){var h=L(a);cn(d,e.props,"prop",h,e)}else if(a.PropTypes!==void 0&&!Se){Se=!0;var S=L(a);A("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",S||"Unknown")}typeof a.getDefaultProps=="function"&&!a.getDefaultProps.isReactClassApproved&&A("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Cn(e){{for(var a=Object.keys(e.props),d=0;d<a.length;d++){var h=a[d];if(h!=="children"&&h!=="key"){K(e),A("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",h),K(null);break}}e.ref!==null&&(K(e),A("Invalid attribute `ref` supplied to `React.Fragment`."),K(null))}}function gt(e,a,d,h,S,R){{var w=tn(e);if(!w){var v="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(v+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var D=_n(S);D?v+=D:v+=ut();var E;e===null?E="null":ye(e)?E="array":e!==void 0&&e.$$typeof===r?(E="<"+(L(e.type)||"Unknown")+" />",v=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,A("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,v)}var x=wn(e,a,d,S,R);if(x==null)return x;if(w){var k=a.children;if(k!==void 0)if(h)if(ye(k)){for(var J=0;J<k.length;J++)pt(k[J],e);Object.freeze&&Object.freeze(k)}else A("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else pt(k,e)}return e===s?Cn(x):Pn(x),x}}function Rn(e,a,d){return gt(e,a,d,!0)}function Tn(e,a,d){return gt(e,a,d,!1)}var En=Tn,xn=Rn;ee.Fragment=s,ee.jsx=En,ee.jsxs=xn}()),ee}(function(t){process.env.NODE_ENV==="production"?t.exports=Tt():t.exports=Et()})(ae);const N=ae.exports.Fragment,n=ae.exports.jsx,b=ae.exports.jsxs;function xt({submit:t,styles:r=Y,type:i}){const{control:s,setValue:u,handleSubmit:l}=P.useForm({defaultValues:{type:i,key:"",config:{host:"",port:5432,username:"",password:"",database:""}}});return I.useEffect(()=>{u("type",i)},[u,i]),n(o.Box,{mx:"auto",children:b("form",{onSubmit:l(t),children:[n(P.Controller,{name:"key",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Name",placeholder:"A unique name",...c})}),n(o.Divider,{label:"Connection Info",labelPosition:"center"}),b(o.Group,{grow:!0,children:[n(P.Controller,{name:"config.host",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Host",sx:{flexGrow:1},...c})}),n(P.Controller,{name:"config.port",control:s,render:({field:c})=>n(o.NumberInput,{mb:r.spacing,size:r.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...c})})]}),n(P.Controller,{name:"config.username",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Username",...c})}),n(P.Controller,{name:"config.password",control:s,render:({field:c})=>n(o.PasswordInput,{mb:r.spacing,size:r.size,required:!0,label:"Password",...c})}),n(P.Controller,{name:"config.database",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Database",...c})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}const Ot=({value:t,onChange:r})=>{const i=s=>{!s||r(s)};return n(o.Box,{sx:{position:"relative"},children:n(Pt.default,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Te=I.forwardRef(({value:t,onChange:r,label:i,modalTitle:s,defaultValue:u,styles:l},c)=>{const[f,{setTrue:g,setFalse:y}]=U.useBoolean(),[_,m]=I.useState(t),p=()=>{y(),r(_)},z=()=>{y(),m(t)},q=()=>{m(u)};return I.useEffect(()=>{m(t)},[t]),b(N,{children:[n(o.Button,{variant:"filled",size:l.button.size,onClick:g,sx:{flexGrow:1},children:i}),n(o.Modal,{size:800,title:s,opened:f,onClose:y,closeOnClickOutside:!1,withCloseButton:!1,children:f&&b(o.Stack,{children:[n(Ot,{value:_,onChange:m}),b(o.Group,{position:"apart",children:[n(o.Button,{onClick:q,color:"red",leftIcon:n(B.Recycle,{size:20}),children:"Rest"}),b(o.Group,{position:"right",children:[n(o.Button,{onClick:z,variant:"subtle",children:"Cancel"}),n(o.Button,{onClick:p,children:"OK"})]})]})]})})]})}),oe={pre:["function pre_process({ method, url, params, headers, data }, utils) {"," // your code goes here"," return { method, url, params, headers, data }","}"].join(`
28
28
  `),post:["function post_process(res, utils) {"," // your code goes here"," return data","}"].join(`
29
- `)};function zt({submit:t,styles:r=Y}){const{control:i,setValue:s,handleSubmit:u}=P.useForm({defaultValues:{type:"http",key:"",config:{host:"",processing:{pre:oe.pre,post:oe.post}}}});return n(o.Box,{mx:"auto",children:b("form",{onSubmit:u(t),children:[n(P.Controller,{name:"key",control:i,render:({field:l})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Name",placeholder:"A unique name",...l})}),n(o.Divider,{label:"Connection Info",labelPosition:"center"}),n(P.Controller,{name:"config.host",control:i,render:({field:l})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Base URL",sx:{flexGrow:1},...l})}),b(o.Group,{grow:!0,children:[n(P.Controller,{name:"config.processing.pre",control:i,render:({field:l})=>n(Te,{label:"Pre Processing",modalTitle:"This function will run before sending the request (for scenarios like encryption)",defaultValue:oe.pre,...l,styles:r})}),n(P.Controller,{name:"config.processing.post",control:i,render:({field:l})=>n(Te,{label:"Post Processing",modalTitle:"This function will run after sending the request (for scenarios like decryption)",defaultValue:oe.post,...l,styles:r})})]}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}function At({postSubmit:t,styles:r=Y}){const[i,s]=I.useState("postgresql"),u=async({type:f,key:g,config:y})=>{T.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0});try{console.log({type:f,key:g,config:y}),await j.datasource.create(f,g,y),T.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),t()}catch(_){T.updateNotification({id:"for-creating",title:"Failed",message:_.message,color:"red"})}},l=i==="postgresql"||i==="mysql",c=i==="http";return b(o.Box,{mx:"auto",children:[n(o.SegmentedControl,{fullWidth:!0,mb:r.spacing,size:r.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http"}],value:i,onChange:f=>s(f)}),l&&n(xt,{submit:u,styles:r,type:i}),c&&n(zt,{submit:u,styles:r})]})}function Ee({onSuccess:t,styles:r=Y}){const[i,s]=W.default.useState(!1),u=()=>s(!0),l=()=>s(!1),c=()=>{t(),l()};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:i,onClose:()=>s(!1),title:"Add a data source",trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:n(At,{postSubmit:c,styles:r})}),n(o.Button,{size:r.button.size,onClick:u,leftIcon:n(B.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}const Dt=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function jt(t){I.useEffect(()=>{if(re.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/settings-form");const i=Dt(t);re.loader.config({paths:{vs:i}}),re.loader.init().then(s=>console.log("monaco instance:",s))},[])}function pe(){return pe=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var i=arguments[r];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},pe.apply(this,arguments)}function It(t,r){if(t==null)return{};var i,s,u=function(c,f){if(c==null)return{};var g,y,_={},m=Object.keys(c);for(y=0;y<m.length;y++)g=m[y],f.indexOf(g)>=0||(_[g]=c[g]);return _}(t,r);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(s=0;s<l.length;s++)i=l[s],r.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(u[i]=t[i])}return u}var kt=["size","color","stroke"];function qt(t){var r=t.size,i=r===void 0?24:r,s=t.color,u=s===void 0?"currentColor":s,l=t.stroke,c=l===void 0?2:l,f=It(t,kt);return Z.createElement("svg",pe({xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-lock",width:i,height:i,viewBox:"0 0 24 24",strokeWidth:c,stroke:u,fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},f),Z.createElement("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),Z.createElement("rect",{x:5,y:11,width:14,height:10,rx:2}),Z.createElement("circle",{cx:12,cy:16,r:1}),Z.createElement("path",{d:"M8 11v-4a4 4 0 0 1 8 0v4"}))}function xe({id:t,name:r,isProtected:i,onSuccess:s,styles:u=Y}){const l=X.useModals(),c=async()=>{!t||(T.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await j.datasource.delete(t),T.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${r}] is deleted`,color:"green"}),s())},f=()=>l.openConfirmModal({title:"Delete this data source?",children:n(o.Text,{size:u.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:c}),g=o.useMantineTheme();return i?n(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:"This is a preset datasource, it can not be deleted",children:n("span",{children:n(qt,{size:16,color:g.colors.gray[7]})})}):n(o.Button,{size:u.button.size,color:"red",onClick:f,leftIcon:n(B.Trash,{size:20}),children:"Delete"})}function Nt({styles:t=Y,config:r}){jt(r.monacoPath),ie(r);const{data:i=[],loading:s,refresh:u}=U.useRequest(async()=>{const{data:l}=await j.datasource.list();return l},{refreshDeps:[]});return b(N,{children:[n(o.Group,{pt:t.spacing,position:"right",children:n(Ee,{onSuccess:u})}),b(o.Box,{mt:t.spacing,sx:{position:"relative"},children:[n(o.LoadingOverlay,{visible:s}),b(o.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[n("thead",{children:b("tr",{children:[n("th",{children:"Type"}),n("th",{children:"Name"}),n("th",{children:"Action"})]})}),n("tbody",{children:i.map(({id:l,key:c,type:f,is_preset:g})=>b("tr",{children:[n("td",{width:200,children:f}),n("td",{children:c}),n("td",{width:200,children:n(o.Group,{position:"left",children:n(xe,{isProtected:g,id:l,name:c,onSuccess:u})})})]},c))})]})]})]})}const Lt=I.forwardRef(({label:t,value:r,description:i,...s},u)=>b(o.Stack,{spacing:2,ref:u,...s,children:[n(o.Text,{size:"sm",children:t}),n(o.Text,{size:"xs",color:"dimmed",className:"role-description",children:i})]})),ge=I.forwardRef(({styles:t,value:r,onChange:i},s)=>{const{data:u=[],loading:l}=U.useRequest(async()=>(await j.role.list()).map(f=>({label:f.name,value:f.id,description:f.description,disabled:f.id===50})),{refreshDeps:[]});return n(o.Select,{ref:s,mb:t.spacing,size:t.size,required:!0,label:"Role",itemComponent:Lt,data:u,disabled:l,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:r,onChange:i})}),F={size:"sm",spacing:"md",button:{size:"xs"}};function Mt({postSubmit:t,styles:r=F,initialRoleID:i}){const{control:s,handleSubmit:u}=P.useForm({defaultValues:{name:"",email:"",role_id:i,password:""}}),l=async({name:c,email:f,password:g,role_id:y})=>{try{T.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await j.account.create(c,f,g,y),T.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),t()}catch(_){T.updateNotification({id:"for-creating",title:"Failed",message:_.message,color:"red"})}};return n(o.Box,{mx:"auto",children:b("form",{onSubmit:u(l),children:[n(P.Controller,{name:"name",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Username",...c})}),n(P.Controller,{name:"email",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Email",...c})}),n(P.Controller,{name:"password",control:s,render:({field:c})=>n(o.PasswordInput,{mb:r.spacing,size:r.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...c})}),n(P.Controller,{name:"role_id",control:s,render:({field:c})=>n(ge,{styles:r,...c})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}function Oe({onSuccess:t,styles:r=F,initialRoleID:i}){const[s,u]=W.default.useState(!1),l=()=>u(!0),c=()=>u(!1),f=()=>{t(),c()};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:s,onClose:()=>u(!1),title:"Add an Account",trapFocus:!0,onDragStart:g=>{g.stopPropagation()},children:n(Mt,{postSubmit:f,styles:r,initialRoleID:i})}),n(o.Button,{size:r.button.size,onClick:l,leftIcon:n(B.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function ze({id:t,name:r,onSuccess:i,styles:s=F}){const u=X.useModals(),l=async()=>{if(!!t){T.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await j.account.delete(t),T.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${r}] is deleted`,color:"green"}),i()}catch(f){T.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},c=()=>u.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:l});return n(o.Button,{size:s.button.size,color:"red",onClick:c,leftIcon:n(B.Trash,{size:20}),children:"Delete"})}function Bt({id:t,name:r,email:i,role_id:s,postSubmit:u,styles:l=F}){const{control:c,handleSubmit:f,watch:g}=P.useForm({defaultValues:{name:r,email:i,role_id:s,reset_password:!1,new_password:""}}),y=async({name:p,email:z,role_id:q,reset_password:V,new_password:he})=>{try{T.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await j.account.edit({id:t,name:p,email:z,role_id:q,reset_password:V,new_password:he}),T.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),u()}catch($){T.updateNotification({id:"for-updating",title:"Failed",message:$.message,color:"red"})}},[_,m]=g(["reset_password","new_password"]);return n(o.Box,{mx:"auto",children:b("form",{onSubmit:f(y),children:[n(P.Controller,{name:"name",control:c,render:({field:p})=>n(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:"Username",...p})}),n(P.Controller,{name:"email",control:c,render:({field:p})=>n(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:"Email",...p})}),n(P.Controller,{name:"role_id",control:c,render:({field:p})=>n(ge,{styles:l,...p})}),n(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),n(P.Controller,{name:"reset_password",control:c,render:({field:p})=>n(o.Switch,{mb:l.spacing,size:l.size,label:"Reset password",checked:p.value,onChange:z=>p.onChange(z.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),_&&n(P.Controller,{name:"new_password",control:c,render:({field:p})=>n(o.PasswordInput,{autoComplete:"off",mb:l.spacing,size:l.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...p})}),n(o.Group,{position:"right",mt:l.spacing,children:n(o.Button,{type:"submit",size:l.button.size,children:"Submit"})})]})})}function Ft({account:t,onSuccess:r,styles:i=F}){const[s,u]=W.default.useState(!1),l=()=>u(!0),c=()=>u(!1),f=()=>{r(),c()};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:s,onClose:()=>u(!1),title:`Editing ${t.name}`,trapFocus:!0,onDragStart:g=>{g.stopPropagation()},children:n(Bt,{...t,postSubmit:f,styles:i})}),n(o.Button,{size:i.button.size,onClick:l,leftIcon:n(B.Edit,{size:20}),children:"Edit"})]})}function $t({styles:t=F,config:r}){var y,_;ie(r);const{data:i=[],loading:s,refresh:u}=U.useRequest(async()=>{const{data:m}=await j.account.list();return m},{refreshDeps:[]}),{data:l=[],loading:c}=U.useRequest(async()=>(await j.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=I.useMemo(()=>l.reduce((m,p)=>(m.set(p.value,p.label),m),new Map),[l]),g=m=>{var p;return(p=f.get(m))!=null?p:m};return b(N,{children:[n(o.Group,{pt:t.spacing,position:"right",children:n(Oe,{onSuccess:u,initialRoleID:(_=(y=l==null?void 0:l[0])==null?void 0:y.value)!=null?_:0})}),b(o.Box,{mt:t.spacing,sx:{position:"relative"},children:[n(o.LoadingOverlay,{visible:s||c}),b(o.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[n("thead",{children:b("tr",{children:[n("th",{children:"Username"}),n("th",{children:"Email"}),n("th",{children:"Role"}),n("th",{children:"Action"})]})}),n("tbody",{children:i.map(m=>{const{id:p,name:z,email:q,role_id:V}=m;return b("tr",{children:[n("td",{width:200,children:z}),n("td",{width:200,children:q}),n("td",{width:200,children:g(V)}),n("td",{width:200,children:b(o.Group,{position:"left",children:[n(Ft,{account:m,onSuccess:u}),n(ze,{id:p,name:z,onSuccess:u})]})})]},p)})})]})]})]})}function Ut({postSubmit:t,styles:r=F}){const{control:i,handleSubmit:s}=P.useForm({defaultValues:{name:"",password:""}}),u=async({name:l,password:c})=>{try{T.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const f=await j.account.login(l,c);window.localStorage.setItem("token",f.token),T.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),t(f)}catch(f){T.updateNotification({id:"for-login",title:"Login Failed",message:f.message,color:"red"})}};return n(o.Box,{mx:"auto",children:b("form",{onSubmit:s(u),children:[n(P.Controller,{name:"name",control:i,render:({field:l})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Username",...l})}),n(P.Controller,{name:"password",control:i,render:({field:l})=>n(o.PasswordInput,{mb:r.spacing,size:r.size,required:!0,label:"Password",...l})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Submit"})})]})})}function Vt({styles:t=F,config:r,onSuccess:i}){return ie(r),n(N,{children:n(o.Box,{mt:t.spacing,sx:{position:"relative"},children:n(Ut,{styles:t,postSubmit:i})})})}const se={size:"sm",spacing:"md",button:{size:"xs"}};function Gt({postSubmit:t,styles:r=se,initialRoleID:i}){const{control:s,handleSubmit:u}=P.useForm({defaultValues:{name:"",role_id:i}}),l=async({name:c,role_id:f})=>{try{T.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const{app_id:g,app_secret:y}=await j.api_key.create(c,f);T.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),t(g,y)}catch(g){T.updateNotification({id:"for-creating",title:"Failed",message:g.message,color:"red"})}};return n(o.Box,{mx:"auto",children:b("form",{onSubmit:u(l),children:[n(P.Controller,{name:"name",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Name",...c})}),n(P.Controller,{name:"role_id",control:s,render:({field:c})=>n(ge,{styles:r,...c})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}function Ae({onSuccess:t,styles:r=se,initialRoleID:i}){const s=X.useModals(),[u,l]=W.default.useState(!1),c=()=>l(!0),f=()=>l(!1),g=(y,_)=>{f(),s.openModal({title:"API Key is generated",children:b(o.Stack,{children:[n(o.Text,{color:"dimmed",children:"Make sure you save it - you won't be able to access it again."}),n(o.TextInput,{defaultValue:y,disabled:!0,label:"APP ID",styles:{input:{cursor:"text !important"}}}),n(o.TextInput,{defaultValue:_,disabled:!0,label:"APP Secret",styles:{input:{cursor:"text !important"}}}),n(o.Button,{size:"sm",onClick:()=>{X.closeAllModals()},children:"I've saved this API Key"})]}),onClose:()=>{t()}})};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:u,onClose:()=>l(!1),title:"Add an API Key",trapFocus:!0,onDragStart:y=>{y.stopPropagation()},children:n(Gt,{postSubmit:g,styles:r,initialRoleID:i})}),n(o.Button,{size:r.button.size,onClick:c,leftIcon:n(B.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function De({id:t,name:r,onSuccess:i,styles:s=se}){const u=X.useModals(),l=async()=>{if(!!t){T.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await j.api_key.delete(t),T.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${r}] is deleted`,color:"green"}),i()}catch(f){T.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},c=()=>u.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:l});return n(o.Button,{size:s.button.size,color:"red",onClick:c,leftIcon:n(B.Trash,{size:20}),children:"Delete"})}function Wt({styles:t=se,config:r}){var y,_;ie(r);const{data:i=[],loading:s,refresh:u}=U.useRequest(async()=>{const{data:m}=await j.api_key.list();return m},{refreshDeps:[]}),{data:l=[],loading:c}=U.useRequest(async()=>(await j.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=I.useMemo(()=>l.reduce((m,p)=>(m.set(p.value,p.label),m),new Map),[l]),g=m=>{var p;return(p=f.get(m))!=null?p:m};return b(N,{children:[n(o.Group,{pt:t.spacing,position:"right",children:n(Ae,{onSuccess:u,initialRoleID:(_=(y=l==null?void 0:l[0])==null?void 0:y.value)!=null?_:0})}),b(o.Box,{mt:t.spacing,sx:{position:"relative"},children:[n(o.LoadingOverlay,{visible:s||c}),b(o.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[n("thead",{children:b("tr",{children:[n("th",{children:"Name"}),n("th",{children:"APP ID"}),n("th",{children:"Role"}),n("th",{children:"Action"})]})}),n("tbody",{children:i.map(m=>{const{id:p,name:z,app_id:q,role_id:V}=m;return b("tr",{children:[n("td",{width:200,children:z}),n("td",{width:200,children:q}),n("td",{width:200,children:g(V)}),n("td",{width:200,children:n(o.Group,{position:"left",children:n(De,{id:p,name:z,onSuccess:u})})})]},p)})})]})]})]})}const Yt=()=>Promise.resolve().then(()=>Kt).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t)),je="@devtable/settings-form",Ie="8.50.3",ke="Apache-2.0",qe={access:"public",registry:"https://registry.npmjs.org/"},Ne=["dist"],Le="./dist/settings-form.umd.js",Me="./dist/settings-form.es.js",Be="./dist/index.d.ts",Fe={".":{import:"./dist/settings-form.es.js",require:"./dist/settings-form.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},$e={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview"},Ue={"@monaco-editor/react":"4.4.6","monaco-editor":"0.36.0"},Ve={"@types/crypto-js":"v4.1.1","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2","rollup-plugin-visualizer":"5.6.0",typescript:"^4.6.3","vite-plugin-static-copy":"0.13.1"},Ge={"@emotion/react":"11.10.0","@mantine/core":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5",ahooks:"^3.3.11",axios:"^0.27.2","crypto-js":"^4.1.1",lodash:"^4.17.21",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-hook-form":"^7.31.2","tabler-icons-react":"^1.48.0"},Kt=Object.freeze(Object.defineProperty({__proto__:null,name:je,version:Ie,license:ke,publishConfig:qe,files:Ne,main:Le,module:Me,types:Be,exports:Fe,scripts:$e,dependencies:Ue,devDependencies:Ve,peerDependencies:Ge,default:{name:je,version:Ie,license:ke,publishConfig:qe,files:Ne,main:Le,module:Me,types:Be,exports:Fe,scripts:$e,dependencies:Ue,devDependencies:Ve,peerDependencies:Ge}},Symbol.toStringTag,{value:"Module"}));C.APIKeyList=Wt,C.AccountList=$t,C.AddAPIKey=Ae,C.AddAccount=Oe,C.AddDataSource=Ee,C.DataSourceList=Nt,C.DeleteAPIKey=De,C.DeleteAccount=ze,C.DeleteDataSource=xe,C.Login=Vt,C.getVersion=Yt,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
29
+ `)};function zt({submit:t,styles:r=Y}){const{control:i,setValue:s,handleSubmit:u}=P.useForm({defaultValues:{type:"http",key:"",config:{host:"",processing:{pre:oe.pre,post:oe.post}}}});return n(o.Box,{mx:"auto",children:b("form",{onSubmit:u(t),children:[n(P.Controller,{name:"key",control:i,render:({field:l})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Name",placeholder:"A unique name",...l})}),n(o.Divider,{label:"Connection Info",labelPosition:"center"}),n(P.Controller,{name:"config.host",control:i,render:({field:l})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Base URL",sx:{flexGrow:1},...l})}),b(o.Group,{grow:!0,children:[n(P.Controller,{name:"config.processing.pre",control:i,render:({field:l})=>n(Te,{label:"Pre Processing",modalTitle:"This function will run before sending the request (for scenarios like encryption)",defaultValue:oe.pre,...l,styles:r})}),n(P.Controller,{name:"config.processing.post",control:i,render:({field:l})=>n(Te,{label:"Post Processing",modalTitle:"This function will run after sending the request (for scenarios like decryption)",defaultValue:oe.post,...l,styles:r})})]}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}function At({postSubmit:t,styles:r=Y}){const[i,s]=I.useState("postgresql"),u=async({type:f,key:g,config:y})=>{T.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0});try{console.log({type:f,key:g,config:y}),await j.datasource.create(f,g,y),T.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),t()}catch(_){T.updateNotification({id:"for-creating",title:"Failed",message:_.message,color:"red"})}},l=i==="postgresql"||i==="mysql",c=i==="http";return b(o.Box,{mx:"auto",children:[n(o.SegmentedControl,{fullWidth:!0,mb:r.spacing,size:r.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http"}],value:i,onChange:f=>s(f)}),l&&n(xt,{submit:u,styles:r,type:i}),c&&n(zt,{submit:u,styles:r})]})}function Ee({onSuccess:t,styles:r=Y}){const[i,s]=W.default.useState(!1),u=()=>s(!0),l=()=>s(!1),c=()=>{t(),l()};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:i,onClose:()=>s(!1),title:"Add a data source",trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:n(At,{postSubmit:c,styles:r})}),n(o.Button,{size:r.button.size,onClick:u,leftIcon:n(B.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}const Dt=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function jt(t){I.useEffect(()=>{if(re.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/settings-form");const i=Dt(t);re.loader.config({paths:{vs:i}}),re.loader.init().then(s=>console.log("monaco instance:",s))},[])}function pe(){return pe=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var i=arguments[r];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},pe.apply(this,arguments)}function It(t,r){if(t==null)return{};var i,s,u=function(c,f){if(c==null)return{};var g,y,_={},m=Object.keys(c);for(y=0;y<m.length;y++)g=m[y],f.indexOf(g)>=0||(_[g]=c[g]);return _}(t,r);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(s=0;s<l.length;s++)i=l[s],r.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(u[i]=t[i])}return u}var kt=["size","color","stroke"];function qt(t){var r=t.size,i=r===void 0?24:r,s=t.color,u=s===void 0?"currentColor":s,l=t.stroke,c=l===void 0?2:l,f=It(t,kt);return Z.createElement("svg",pe({xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-lock",width:i,height:i,viewBox:"0 0 24 24",strokeWidth:c,stroke:u,fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},f),Z.createElement("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),Z.createElement("rect",{x:5,y:11,width:14,height:10,rx:2}),Z.createElement("circle",{cx:12,cy:16,r:1}),Z.createElement("path",{d:"M8 11v-4a4 4 0 0 1 8 0v4"}))}function xe({id:t,name:r,isProtected:i,onSuccess:s,styles:u=Y}){const l=X.useModals(),c=async()=>{!t||(T.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await j.datasource.delete(t),T.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${r}] is deleted`,color:"green"}),s())},f=()=>l.openConfirmModal({title:"Delete this data source?",children:n(o.Text,{size:u.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:c}),g=o.useMantineTheme();return i?n(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:"This is a preset datasource, it can not be deleted",children:n("span",{children:n(qt,{size:16,color:g.colors.gray[7]})})}):n(o.Button,{size:u.button.size,color:"red",onClick:f,leftIcon:n(B.Trash,{size:20}),children:"Delete"})}function Nt({styles:t=Y,config:r}){jt(r.monacoPath),ie(r);const{data:i=[],loading:s,refresh:u}=U.useRequest(async()=>{const{data:l}=await j.datasource.list();return l},{refreshDeps:[]});return b(N,{children:[n(o.Group,{pt:t.spacing,position:"right",children:n(Ee,{onSuccess:u})}),b(o.Box,{mt:t.spacing,sx:{position:"relative"},children:[n(o.LoadingOverlay,{visible:s}),b(o.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[n("thead",{children:b("tr",{children:[n("th",{children:"Type"}),n("th",{children:"Name"}),n("th",{children:"Action"})]})}),n("tbody",{children:i.map(({id:l,key:c,type:f,is_preset:g})=>b("tr",{children:[n("td",{width:200,children:f}),n("td",{children:c}),n("td",{width:200,children:n(o.Group,{position:"left",children:n(xe,{isProtected:g,id:l,name:c,onSuccess:u})})})]},c))})]})]})]})}const Lt=I.forwardRef(({label:t,value:r,description:i,...s},u)=>b(o.Stack,{spacing:2,ref:u,...s,children:[n(o.Text,{size:"sm",children:t}),n(o.Text,{size:"xs",color:"dimmed",className:"role-description",children:i})]})),ge=I.forwardRef(({styles:t,value:r,onChange:i},s)=>{const{data:u=[],loading:l}=U.useRequest(async()=>(await j.role.list()).map(f=>({label:f.name,value:f.id,description:f.description,disabled:f.id===50})),{refreshDeps:[]});return n(o.Select,{ref:s,mb:t.spacing,size:t.size,required:!0,label:"Role",itemComponent:Lt,data:u,disabled:l,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:r,onChange:i})}),F={size:"sm",spacing:"md",button:{size:"xs"}};function Mt({postSubmit:t,styles:r=F,initialRoleID:i}){const{control:s,handleSubmit:u}=P.useForm({defaultValues:{name:"",email:"",role_id:i,password:""}}),l=async({name:c,email:f,password:g,role_id:y})=>{try{T.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await j.account.create(c,f,g,y),T.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),t()}catch(_){T.updateNotification({id:"for-creating",title:"Failed",message:_.message,color:"red"})}};return n(o.Box,{mx:"auto",children:b("form",{onSubmit:u(l),children:[n(P.Controller,{name:"name",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Username",...c})}),n(P.Controller,{name:"email",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Email",...c})}),n(P.Controller,{name:"password",control:s,render:({field:c})=>n(o.PasswordInput,{mb:r.spacing,size:r.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...c})}),n(P.Controller,{name:"role_id",control:s,render:({field:c})=>n(ge,{styles:r,...c})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}function Oe({onSuccess:t,styles:r=F,initialRoleID:i}){const[s,u]=W.default.useState(!1),l=()=>u(!0),c=()=>u(!1),f=()=>{t(),c()};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:s,onClose:()=>u(!1),title:"Add an Account",trapFocus:!0,onDragStart:g=>{g.stopPropagation()},children:n(Mt,{postSubmit:f,styles:r,initialRoleID:i})}),n(o.Button,{size:r.button.size,onClick:l,leftIcon:n(B.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function ze({id:t,name:r,onSuccess:i,styles:s=F}){const u=X.useModals(),l=async()=>{if(!!t){T.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await j.account.delete(t),T.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${r}] is deleted`,color:"green"}),i()}catch(f){T.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},c=()=>u.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:l});return n(o.Button,{size:s.button.size,color:"red",onClick:c,leftIcon:n(B.Trash,{size:20}),children:"Delete"})}function Bt({id:t,name:r,email:i,role_id:s,postSubmit:u,styles:l=F}){const{control:c,handleSubmit:f,watch:g}=P.useForm({defaultValues:{name:r,email:i,role_id:s,reset_password:!1,new_password:""}}),y=async({name:p,email:z,role_id:q,reset_password:V,new_password:he})=>{try{T.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await j.account.edit({id:t,name:p,email:z,role_id:q,reset_password:V,new_password:he}),T.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),u()}catch($){T.updateNotification({id:"for-updating",title:"Failed",message:$.message,color:"red"})}},[_,m]=g(["reset_password","new_password"]);return n(o.Box,{mx:"auto",children:b("form",{onSubmit:f(y),children:[n(P.Controller,{name:"name",control:c,render:({field:p})=>n(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:"Username",...p})}),n(P.Controller,{name:"email",control:c,render:({field:p})=>n(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:"Email",...p})}),n(P.Controller,{name:"role_id",control:c,render:({field:p})=>n(ge,{styles:l,...p})}),n(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),n(P.Controller,{name:"reset_password",control:c,render:({field:p})=>n(o.Switch,{mb:l.spacing,size:l.size,label:"Reset password",checked:p.value,onChange:z=>p.onChange(z.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),_&&n(P.Controller,{name:"new_password",control:c,render:({field:p})=>n(o.PasswordInput,{autoComplete:"off",mb:l.spacing,size:l.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...p})}),n(o.Group,{position:"right",mt:l.spacing,children:n(o.Button,{type:"submit",size:l.button.size,children:"Submit"})})]})})}function Ft({account:t,onSuccess:r,styles:i=F}){const[s,u]=W.default.useState(!1),l=()=>u(!0),c=()=>u(!1),f=()=>{r(),c()};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:s,onClose:()=>u(!1),title:`Editing ${t.name}`,trapFocus:!0,onDragStart:g=>{g.stopPropagation()},children:n(Bt,{...t,postSubmit:f,styles:i})}),n(o.Button,{size:i.button.size,onClick:l,leftIcon:n(B.Edit,{size:20}),children:"Edit"})]})}function $t({styles:t=F,config:r}){var y,_;ie(r);const{data:i=[],loading:s,refresh:u}=U.useRequest(async()=>{const{data:m}=await j.account.list();return m},{refreshDeps:[]}),{data:l=[],loading:c}=U.useRequest(async()=>(await j.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=I.useMemo(()=>l.reduce((m,p)=>(m.set(p.value,p.label),m),new Map),[l]),g=m=>{var p;return(p=f.get(m))!=null?p:m};return b(N,{children:[n(o.Group,{pt:t.spacing,position:"right",children:n(Oe,{onSuccess:u,initialRoleID:(_=(y=l==null?void 0:l[0])==null?void 0:y.value)!=null?_:0})}),b(o.Box,{mt:t.spacing,sx:{position:"relative"},children:[n(o.LoadingOverlay,{visible:s||c}),b(o.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[n("thead",{children:b("tr",{children:[n("th",{children:"Username"}),n("th",{children:"Email"}),n("th",{children:"Role"}),n("th",{children:"Action"})]})}),n("tbody",{children:i.map(m=>{const{id:p,name:z,email:q,role_id:V}=m;return b("tr",{children:[n("td",{width:200,children:z}),n("td",{width:200,children:q}),n("td",{width:200,children:g(V)}),n("td",{width:200,children:b(o.Group,{position:"left",children:[n(Ft,{account:m,onSuccess:u}),n(ze,{id:p,name:z,onSuccess:u})]})})]},p)})})]})]})]})}function Ut({postSubmit:t,styles:r=F}){const{control:i,handleSubmit:s}=P.useForm({defaultValues:{name:"",password:""}}),u=async({name:l,password:c})=>{try{T.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const f=await j.account.login(l,c);window.localStorage.setItem("token",f.token),T.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),t(f)}catch(f){T.updateNotification({id:"for-login",title:"Login Failed",message:f.message,color:"red"})}};return n(o.Box,{mx:"auto",children:b("form",{onSubmit:s(u),children:[n(P.Controller,{name:"name",control:i,render:({field:l})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Username",...l})}),n(P.Controller,{name:"password",control:i,render:({field:l})=>n(o.PasswordInput,{mb:r.spacing,size:r.size,required:!0,label:"Password",...l})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Submit"})})]})})}function Vt({styles:t=F,config:r,onSuccess:i}){return ie(r),n(N,{children:n(o.Box,{mt:t.spacing,sx:{position:"relative"},children:n(Ut,{styles:t,postSubmit:i})})})}const se={size:"sm",spacing:"md",button:{size:"xs"}};function Gt({postSubmit:t,styles:r=se,initialRoleID:i}){const{control:s,handleSubmit:u}=P.useForm({defaultValues:{name:"",role_id:i}}),l=async({name:c,role_id:f})=>{try{T.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const{app_id:g,app_secret:y}=await j.api_key.create(c,f);T.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),t(g,y)}catch(g){T.updateNotification({id:"for-creating",title:"Failed",message:g.message,color:"red"})}};return n(o.Box,{mx:"auto",children:b("form",{onSubmit:u(l),children:[n(P.Controller,{name:"name",control:s,render:({field:c})=>n(o.TextInput,{mb:r.spacing,size:r.size,required:!0,label:"Name",...c})}),n(P.Controller,{name:"role_id",control:s,render:({field:c})=>n(ge,{styles:r,...c})}),n(o.Group,{position:"right",mt:r.spacing,children:n(o.Button,{type:"submit",size:r.button.size,children:"Save"})})]})})}function Ae({onSuccess:t,styles:r=se,initialRoleID:i}){const s=X.useModals(),[u,l]=W.default.useState(!1),c=()=>l(!0),f=()=>l(!1),g=(y,_)=>{f(),s.openModal({title:"API Key is generated",children:b(o.Stack,{children:[n(o.Text,{color:"dimmed",children:"Make sure you save it - you won't be able to access it again."}),n(o.TextInput,{defaultValue:y,disabled:!0,label:"APP ID",styles:{input:{cursor:"text !important"}}}),n(o.TextInput,{defaultValue:_,disabled:!0,label:"APP Secret",styles:{input:{cursor:"text !important"}}}),n(o.Button,{size:"sm",onClick:()=>{X.closeAllModals()},children:"I've saved this API Key"})]}),onClose:()=>{t()}})};return b(N,{children:[n(o.Modal,{overflow:"inside",opened:u,onClose:()=>l(!1),title:"Add an API Key",trapFocus:!0,onDragStart:y=>{y.stopPropagation()},children:n(Gt,{postSubmit:g,styles:r,initialRoleID:i})}),n(o.Button,{size:r.button.size,onClick:c,leftIcon:n(B.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function De({id:t,name:r,onSuccess:i,styles:s=se}){const u=X.useModals(),l=async()=>{if(!!t){T.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await j.api_key.delete(t),T.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${r}] is deleted`,color:"green"}),i()}catch(f){T.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},c=()=>u.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:l});return n(o.Button,{size:s.button.size,color:"red",onClick:c,leftIcon:n(B.Trash,{size:20}),children:"Delete"})}function Wt({styles:t=se,config:r}){var y,_;ie(r);const{data:i=[],loading:s,refresh:u}=U.useRequest(async()=>{const{data:m}=await j.api_key.list();return m},{refreshDeps:[]}),{data:l=[],loading:c}=U.useRequest(async()=>(await j.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=I.useMemo(()=>l.reduce((m,p)=>(m.set(p.value,p.label),m),new Map),[l]),g=m=>{var p;return(p=f.get(m))!=null?p:m};return b(N,{children:[n(o.Group,{pt:t.spacing,position:"right",children:n(Ae,{onSuccess:u,initialRoleID:(_=(y=l==null?void 0:l[0])==null?void 0:y.value)!=null?_:0})}),b(o.Box,{mt:t.spacing,sx:{position:"relative"},children:[n(o.LoadingOverlay,{visible:s||c}),b(o.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[n("thead",{children:b("tr",{children:[n("th",{children:"Name"}),n("th",{children:"APP ID"}),n("th",{children:"Role"}),n("th",{children:"Action"})]})}),n("tbody",{children:i.map(m=>{const{id:p,name:z,app_id:q,role_id:V}=m;return b("tr",{children:[n("td",{width:200,children:z}),n("td",{width:200,children:q}),n("td",{width:200,children:g(V)}),n("td",{width:200,children:n(o.Group,{position:"left",children:n(De,{id:p,name:z,onSuccess:u})})})]},p)})})]})]})]})}const Yt=()=>Promise.resolve().then(()=>Kt).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t)),je="@devtable/settings-form",Ie="8.50.5",ke="Apache-2.0",qe={access:"public",registry:"https://registry.npmjs.org/"},Ne=["dist"],Le="./dist/settings-form.umd.js",Me="./dist/settings-form.es.js",Be="./dist/index.d.ts",Fe={".":{import:"./dist/settings-form.es.js",require:"./dist/settings-form.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},$e={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview"},Ue={"@monaco-editor/react":"4.4.6","monaco-editor":"0.36.0"},Ve={"@types/crypto-js":"v4.1.1","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2","rollup-plugin-visualizer":"5.6.0",typescript:"^4.6.3","vite-plugin-static-copy":"0.13.1"},Ge={"@emotion/react":"11.10.0","@mantine/core":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5",ahooks:"^3.3.11",axios:"^0.27.2","crypto-js":"^4.1.1",lodash:"^4.17.21",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-hook-form":"^7.31.2","tabler-icons-react":"^1.48.0"},Kt=Object.freeze(Object.defineProperty({__proto__:null,name:je,version:Ie,license:ke,publishConfig:qe,files:Ne,main:Le,module:Me,types:Be,exports:Fe,scripts:$e,dependencies:Ue,devDependencies:Ve,peerDependencies:Ge,default:{name:je,version:Ie,license:ke,publishConfig:qe,files:Ne,main:Le,module:Me,types:Be,exports:Fe,scripts:$e,dependencies:Ue,devDependencies:Ve,peerDependencies:Ge}},Symbol.toStringTag,{value:"Module"}));C.APIKeyList=Wt,C.AccountList=$t,C.AddAPIKey=Ae,C.AddAccount=Oe,C.AddDataSource=Ee,C.DataSourceList=Nt,C.DeleteAPIKey=De,C.DeleteAccount=ze,C.DeleteDataSource=xe,C.Login=Vt,C.getVersion=Yt,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/settings-form",
3
- "version": "8.50.3",
3
+ "version": "8.50.5",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public",