@devtable/settings-form 8.51.0 → 8.51.1

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,22 +1,22 @@
1
- export type DataSourceType = 'postgresql' | 'mysql' | 'http';
1
+ export declare type DataSourceType = 'postgresql' | 'mysql' | 'http';
2
2
  export interface IDataSource {
3
3
  id: string;
4
4
  type: DataSourceType;
5
5
  key: string;
6
6
  is_preset?: boolean;
7
7
  }
8
- export type TDataSourceConfig_DB = {
8
+ export declare type TDataSourceConfig_DB = {
9
9
  host: string;
10
10
  port: number;
11
11
  username: string;
12
12
  password: string;
13
13
  database: string;
14
14
  };
15
- export type TDataSourceConfig_HTTP = {
15
+ export declare type TDataSourceConfig_HTTP = {
16
16
  host: string;
17
17
  processing: {
18
18
  pre: TFunctionString;
19
19
  post: TFunctionString;
20
20
  };
21
21
  };
22
- export type TDataSourceConfig = TDataSourceConfig_DB | TDataSourceConfig_HTTP;
22
+ export declare type TDataSourceConfig = TDataSourceConfig_DB | TDataSourceConfig_HTTP;
@@ -1,4 +1,4 @@
1
- export type PaginationResponse<T> = {
1
+ export declare type PaginationResponse<T> = {
2
2
  total: number;
3
3
  offset: number;
4
4
  data: T[];
@@ -0,0 +1,12 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ type $TSFixMe = any;
3
+
4
+ interface ISettingsFormConfig {
5
+ basename: string;
6
+ apiBaseURL: string;
7
+ app_id?: string;
8
+ app_secret?: string;
9
+ monacoPath: string;
10
+ }
11
+
12
+ type TFunctionString = string;
@@ -1,4 +1,4 @@
1
- const e = "@devtable/settings-form", s = "8.51.0", t = "Apache-2.0", i = {
1
+ const e = "@devtable/settings-form", s = "8.51.1", t = "Apache-2.0", i = {
2
2
  access: "public",
3
3
  registry: "https://registry.npmjs.org/"
4
4
  }, o = [
@@ -1115,7 +1115,7 @@ function ot({
1115
1115
  ] })
1116
1116
  ] });
1117
1117
  }
1118
- const at = () => import("./package-f107145d.mjs").then(({
1118
+ const at = () => import("./package-fe846bfe.mjs").then(({
1119
1119
  version: t
1120
1120
  }) => (console.log(`[@devtable/dashboard] version: ${t}`), t));
1121
1121
  export {
@@ -1,3 +1,3 @@
1
1
  (function(m,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("/Users/leto/Merico/merico-dev/table/node_modules/react/jsx-runtime.js"),require("@mantine/core"),require("@mantine/notifications"),require("react"),require("tabler-icons-react"),require("axios"),require("crypto-js"),require("lodash"),require("react-hook-form"),require("ahooks"),require("@monaco-editor/react"),require("@mantine/modals")):typeof define=="function"&&define.amd?define(["exports","/Users/leto/Merico/merico-dev/table/node_modules/react/jsx-runtime.js","@mantine/core","@mantine/notifications","react","tabler-icons-react","axios","crypto-js","lodash","react-hook-form","ahooks","@monaco-editor/react","@mantine/modals"],q):(m=typeof globalThis<"u"?globalThis:m||self,q(m["settings-form"]={},m["/Users/leto/Merico/merico-dev/table/node_modules/react/jsx-runtime"].js,m["@mantine/core"],m["@mantine/notifications"],m.react,m["tabler-icons-react"],m.axios,m.CryptoJS,m._,m["react-hook-form"],m.ahooks,m["@monaco-editor/react"],m["@mantine/modals"]))})(this,function(m,q,r,b,z,y,oe,se,le,h,x,I,D){"use strict";function k(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const a=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(n,i,a.get?a:{enumerable:!0,get:()=>t[i]})}}return n.default=t,Object.freeze(n)}const B=k(q),O=k(z),P=B.Fragment,e=B.jsx,u=B.jsxs;function ce(t){t=t||{};const n=Object.keys(t).sort(),i=[];for(let a=0;a<n.length;a++){const l=n[a];if(l!="authentication"&&t[l])i.push(n[a]+"="+(typeof t[l]=="object"?JSON.stringify(t[l]):t[l]));else{const o=Object.keys(t[l]).sort();for(let s=0;s<o.length;s++){const c=o[s];c!="sign"&&t[l][c]&&i.push(o[s]+"="+(typeof t[l][c]=="object"?JSON.stringify(t[l][c]):t[l][c]))}}}return i.sort().join("&")}function de(t,n){let i=ce(t);return i+="&key="+n,se.MD5(i).toString().toUpperCase()}const S={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(t){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:de({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}},getRequest(t){return(n,i,a={})=>{const l=window.localStorage.getItem("token"),o={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:l?`bearer ${l}`:"",...a.headers},s={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?i:a.params,headers:o};return["POST","PUT"].includes(t)&&(s.data=a.string?JSON.stringify(i):i,s.data.authentication=this.getAuthentication(s.data)),oe(s).then(c=>c.data).catch(c=>le.has(c,"response.data.detail.message")?Promise.reject(new Error(c.response.data.detail.message)):Promise.reject(c))}}};function j(t){S.baseURL!==t.apiBaseURL&&(S.baseURL=t.apiBaseURL),t.app_id&&(S.app_id=t.app_id),t.app_secret&&(S.app_secret=t.app_secret)}const v={datasource:{list:async()=>await S.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}}),create:async(t,n,i)=>await S.getRequest("POST")("/datasource/create",{type:t,key:n,config:i}),delete:async t=>{await S.getRequest("POST")("/datasource/delete",{id:t})}},account:{login:async(t,n)=>{const i={name:t,password:n};return await S.getRequest("POST")("/account/login",i)},list:async()=>await S.getRequest("POST")("/account/list",{filter:{},sort:[{field:"name",order:"ASC"}],pagination:{page:1,pagesize:100}}),get:async()=>await S.getRequest("GET")("/account/get",{}),update:async(t,n)=>{const i={name:t,email:n};return await S.getRequest("PUT")("/account/update",i)},changepassword:async(t,n)=>{const i={old_password:t,new_password:n};return await S.getRequest("POST")("/account/changepassword",i)},create:async(t,n,i,a)=>await S.getRequest("POST")("/account/create",{name:t,email:n,password:i,role_id:a}),edit:async t=>(t.reset_password||(t.new_password=void 0),await S.getRequest("PUT")("/account/edit",t)),delete:async t=>{if(t)return S.getRequest("POST")("/account/delete",{id:t})}},role:{list:async()=>await S.getRequest("GET")("/role/list",{})},api_key:{list:async()=>await S.getRequest("POST")("/api/key/list",{filter:{search:""},sort:[{field:"name",order:"ASC"}],pagination:{page:1,pagesize:100}}),create:async(t,n)=>S.getRequest("POST")("/api/key/create",{name:t,role_id:n}),delete:async t=>{if(t)return S.getRequest("POST")("/api/key/delete",{id:t})}}},T={size:"sm",spacing:"md",button:{size:"xs"}};function ue({submit:t,styles:n=T,type:i}){const{control:a,setValue:l,handleSubmit:o}=h.useForm({defaultValues:{type:i,key:"",config:{host:"",port:5432,username:"",password:"",database:""}}});return z.useEffect(()=>{l("type",i)},[l,i]),e(r.Box,{mx:"auto",children:u("form",{onSubmit:o(t),children:[e(h.Controller,{name:"key",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",placeholder:"A unique name",...s})}),e(r.Divider,{label:"Connection Info",labelPosition:"center"}),u(r.Group,{grow:!0,children:[e(h.Controller,{name:"config.host",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Host",sx:{flexGrow:1},...s})}),e(h.Controller,{name:"config.port",control:a,render:({field:s})=>e(r.NumberInput,{mb:n.spacing,size:n.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...s})})]}),e(h.Controller,{name:"config.username",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...s})}),e(h.Controller,{name:"config.password",control:a,render:({field:s})=>e(r.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...s})}),e(h.Controller,{name:"config.database",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Database",...s})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}const pe=({value:t,onChange:n})=>{const i=a=>{a&&n(a)};return e(r.Box,{sx:{position:"relative"},children:e(I,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},G=z.forwardRef(({value:t,onChange:n,label:i,modalTitle:a,defaultValue:l,styles:o},s)=>{const[c,{setTrue:p,setFalse:f}]=x.useBoolean(),[d,g]=z.useState(t),w=()=>{f(),n(d)},C=()=>{f(),g(t)},_=()=>{g(l)};return z.useEffect(()=>{g(t)},[t]),u(P,{children:[e(r.Button,{variant:"filled",size:o.button.size,onClick:p,sx:{flexGrow:1},children:i}),e(r.Modal,{size:800,title:a,opened:c,onClose:f,closeOnClickOutside:!1,withCloseButton:!1,children:c&&u(r.Stack,{children:[e(pe,{value:d,onChange:g}),u(r.Group,{position:"apart",children:[e(r.Button,{onClick:_,color:"red",leftIcon:e(y.Recycle,{size:20}),children:"Rest"}),u(r.Group,{position:"right",children:[e(r.Button,{onClick:C,variant:"subtle",children:"Cancel"}),e(r.Button,{onClick:w,children:"OK"})]})]})]})})]})}),R={pre:["function pre_process({ method, url, params, headers, data }, utils) {"," // your code goes here"," return { method, url, params, headers, data }","}"].join(`
2
2
  `),post:["function post_process(res, utils) {"," // your code goes here"," return data","}"].join(`
3
- `)};function ge({submit:t,styles:n=T}){const{control:i,setValue:a,handleSubmit:l}=h.useForm({defaultValues:{type:"http",key:"",config:{host:"",processing:{pre:R.pre,post:R.post}}}});return e(r.Box,{mx:"auto",children:u("form",{onSubmit:l(t),children:[e(h.Controller,{name:"key",control:i,render:({field:o})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",placeholder:"A unique name",...o})}),e(r.Divider,{label:"Connection Info",labelPosition:"center"}),e(h.Controller,{name:"config.host",control:i,render:({field:o})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Base URL",sx:{flexGrow:1},...o})}),u(r.Group,{grow:!0,children:[e(h.Controller,{name:"config.processing.pre",control:i,render:({field:o})=>e(G,{label:"Pre Processing",modalTitle:"This function will run before sending the request (for scenarios like encryption)",defaultValue:R.pre,...o,styles:n})}),e(h.Controller,{name:"config.processing.post",control:i,render:({field:o})=>e(G,{label:"Post Processing",modalTitle:"This function will run after sending the request (for scenarios like decryption)",defaultValue:R.post,...o,styles:n})})]}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function he({postSubmit:t,styles:n=T}){const[i,a]=z.useState("postgresql"),l=async({type:c,key:p,config:f})=>{b.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0});try{console.log({type:c,key:p,config:f}),await v.datasource.create(c,p,f),b.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),t()}catch(d){b.updateNotification({id:"for-creating",title:"Failed",message:d.message,color:"red"})}},o=i==="postgresql"||i==="mysql",s=i==="http";return u(r.Box,{mx:"auto",children:[e(r.SegmentedControl,{fullWidth:!0,mb:n.spacing,size:n.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http"}],value:i,onChange:c=>a(c)}),o&&e(ue,{submit:l,styles:n,type:i}),s&&e(ge,{submit:l,styles:n})]})}function U({onSuccess:t,styles:n=T}){const[i,a]=z.useState(!1),l=()=>a(!0),o=()=>a(!1),s=()=>{t(),o()};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:i,onClose:()=>a(!1),title:"Add a data source",trapFocus:!0,onDragStart:c=>{c.stopPropagation()},children:e(he,{postSubmit:s,styles:n})}),e(r.Button,{size:n.button.size,onClick:l,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}const me=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function fe(t){z.useEffect(()=>{if(I.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/settings-form");const i=me(t);I.loader.config({paths:{vs:i}}),I.loader.init().then(a=>console.log("monaco instance:",a))},[])}function L(){return L=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},L.apply(this,arguments)}function be(t,n){if(t==null)return{};var i,a,l=function(s,c){if(s==null)return{};var p,f,d={},g=Object.keys(s);for(f=0;f<g.length;f++)p=g[f],c.indexOf(p)>=0||(d[p]=s[p]);return d}(t,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(a=0;a<o.length;a++)i=o[a],n.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(l[i]=t[i])}return l}var we=["size","color","stroke"];function Se(t){var n=t.size,i=n===void 0?24:n,a=t.color,l=a===void 0?"currentColor":a,o=t.stroke,s=o===void 0?2:o,c=be(t,we);return O.createElement("svg",L({xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-lock",width:i,height:i,viewBox:"0 0 24 24",strokeWidth:s,stroke:l,fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},c),O.createElement("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),O.createElement("rect",{x:5,y:11,width:14,height:10,rx:2}),O.createElement("circle",{cx:12,cy:16,r:1}),O.createElement("path",{d:"M8 11v-4a4 4 0 0 1 8 0v4"}))}function E({id:t,name:n,isProtected:i,onSuccess:a,styles:l=T}){const o=D.useModals(),s=async()=>{t&&(b.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await v.datasource.delete(t),b.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${n}] is deleted`,color:"green"}),a())},c=()=>o.openConfirmModal({title:"Delete this data source?",children:e(r.Text,{size:l.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:s}),p=r.useMantineTheme();return i?e(r.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:"This is a preset datasource, it can not be deleted",children:e("span",{children:e(Se,{size:16,color:p.colors.gray[7]})})}):e(r.Button,{size:l.button.size,color:"red",onClick:c,leftIcon:e(y.Trash,{size:20}),children:"Delete"})}function ze({styles:t=T,config:n}){fe(n.monacoPath),j(n);const{data:i=[],loading:a,refresh:l}=x.useRequest(async()=>{const{data:o}=await v.datasource.list();return o},{refreshDeps:[]});return u(P,{children:[e(r.Group,{pt:t.spacing,position:"right",children:e(U,{onSuccess:l})}),u(r.Box,{mt:t.spacing,sx:{position:"relative"},children:[e(r.LoadingOverlay,{visible:a}),u(r.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[e("thead",{children:u("tr",{children:[e("th",{children:"Type"}),e("th",{children:"Name"}),e("th",{children:"Action"})]})}),e("tbody",{children:i.map(({id:o,key:s,type:c,is_preset:p})=>u("tr",{children:[e("td",{width:200,children:c}),e("td",{children:s}),e("td",{width:200,children:e(r.Group,{position:"left",children:e(E,{isProtected:p,id:o,name:s,onSuccess:l})})})]},s))})]})]})]})}const ve=z.forwardRef(({label:t,value:n,description:i,...a},l)=>u(r.Stack,{spacing:2,ref:l,...a,children:[e(r.Text,{size:"sm",children:t}),e(r.Text,{size:"xs",color:"dimmed",className:"role-description",children:i})]})),M=z.forwardRef(({styles:t,value:n,onChange:i},a)=>{const{data:l=[],loading:o}=x.useRequest(async()=>(await v.role.list()).map(c=>({label:c.name,value:c.id,description:c.description,disabled:c.id===50})),{refreshDeps:[]});return e(r.Select,{ref:a,mb:t.spacing,size:t.size,required:!0,label:"Role",itemComponent:ve,data:l,disabled:o,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:n,onChange:i})}),A={size:"sm",spacing:"md",button:{size:"xs"}};function Pe({postSubmit:t,styles:n=A,initialRoleID:i}){const{control:a,handleSubmit:l}=h.useForm({defaultValues:{name:"",email:"",role_id:i,password:""}}),o=async({name:s,email:c,password:p,role_id:f})=>{try{b.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await v.account.create(s,c,p,f),b.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),t()}catch(d){b.updateNotification({id:"for-creating",title:"Failed",message:d.message,color:"red"})}};return e(r.Box,{mx:"auto",children:u("form",{onSubmit:l(o),children:[e(h.Controller,{name:"name",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...s})}),e(h.Controller,{name:"email",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Email",...s})}),e(h.Controller,{name:"password",control:a,render:({field:s})=>e(r.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...s})}),e(h.Controller,{name:"role_id",control:a,render:({field:s})=>e(M,{styles:n,...s})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function K({onSuccess:t,styles:n=A,initialRoleID:i}){const[a,l]=z.useState(!1),o=()=>l(!0),s=()=>l(!1),c=()=>{t(),s()};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:a,onClose:()=>l(!1),title:"Add an Account",trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e(Pe,{postSubmit:c,styles:n,initialRoleID:i})}),e(r.Button,{size:n.button.size,onClick:o,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function V({id:t,name:n,onSuccess:i,styles:a=A}){const l=D.useModals(),o=async()=>{if(t){b.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await v.account.delete(t),b.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${n}] is deleted`,color:"green"}),i()}catch(c){b.updateNotification({id:"for-deleting",title:"Failed",message:c.message,color:"red"})}}},s=()=>l.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:o});return e(r.Button,{size:a.button.size,color:"red",onClick:s,leftIcon:e(y.Trash,{size:20}),children:"Delete"})}function Ce({id:t,name:n,email:i,role_id:a,postSubmit:l,styles:o=A}){const{control:s,handleSubmit:c,watch:p}=h.useForm({defaultValues:{name:n,email:i,role_id:a,reset_password:!1,new_password:""}}),f=async({name:w,email:C,role_id:_,reset_password:Ie,new_password:je})=>{try{b.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await v.account.edit({id:t,name:w,email:C,role_id:_,reset_password:Ie,new_password:je}),b.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),l()}catch(Re){b.updateNotification({id:"for-updating",title:"Failed",message:Re.message,color:"red"})}},[d,g]=p(["reset_password","new_password"]);return e(r.Box,{mx:"auto",children:u("form",{onSubmit:c(f),children:[e(h.Controller,{name:"name",control:s,render:({field:w})=>e(r.TextInput,{mb:o.spacing,size:o.size,required:!0,label:"Username",...w})}),e(h.Controller,{name:"email",control:s,render:({field:w})=>e(r.TextInput,{mb:o.spacing,size:o.size,required:!0,label:"Email",...w})}),e(h.Controller,{name:"role_id",control:s,render:({field:w})=>e(M,{styles:o,...w})}),e(r.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),e(h.Controller,{name:"reset_password",control:s,render:({field:w})=>e(r.Switch,{mb:o.spacing,size:o.size,label:"Reset password",checked:w.value,onChange:C=>w.onChange(C.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),d&&e(h.Controller,{name:"new_password",control:s,render:({field:w})=>e(r.PasswordInput,{autoComplete:"off",mb:o.spacing,size:o.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...w})}),e(r.Group,{position:"right",mt:o.spacing,children:e(r.Button,{type:"submit",size:o.button.size,children:"Submit"})})]})})}function ye({account:t,onSuccess:n,styles:i=A}){const[a,l]=z.useState(!1),o=()=>l(!0),s=()=>l(!1),c=()=>{n(),s()};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:a,onClose:()=>l(!1),title:`Editing ${t.name}`,trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e(Ce,{...t,postSubmit:c,styles:i})}),e(r.Button,{size:i.button.size,onClick:o,leftIcon:e(y.Edit,{size:20}),children:"Edit"})]})}function Ae({styles:t=A,config:n}){var f;j(n);const{data:i=[],loading:a,refresh:l}=x.useRequest(async()=>{const{data:d}=await v.account.list();return d},{refreshDeps:[]}),{data:o=[],loading:s}=x.useRequest(async()=>(await v.role.list()).map(g=>({label:g.name,value:g.id,description:g.description,disabled:g.id===50})),{refreshDeps:[]}),c=z.useMemo(()=>o.reduce((d,g)=>(d.set(g.value,g.label),d),new Map),[o]),p=d=>c.get(d)??d;return u(P,{children:[e(r.Group,{pt:t.spacing,position:"right",children:e(K,{onSuccess:l,initialRoleID:((f=o==null?void 0:o[0])==null?void 0:f.value)??0})}),u(r.Box,{mt:t.spacing,sx:{position:"relative"},children:[e(r.LoadingOverlay,{visible:a||s}),u(r.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[e("thead",{children:u("tr",{children:[e("th",{children:"Username"}),e("th",{children:"Email"}),e("th",{children:"Role"}),e("th",{children:"Action"})]})}),e("tbody",{children:i.map(d=>{const{id:g,name:w,email:C,role_id:_}=d;return u("tr",{children:[e("td",{width:200,children:w}),e("td",{width:200,children:C}),e("td",{width:200,children:p(_)}),e("td",{width:200,children:u(r.Group,{position:"left",children:[e(ye,{account:d,onSuccess:l}),e(V,{id:g,name:w,onSuccess:l})]})})]},g)})})]})]})]})}function xe({postSubmit:t,styles:n=A}){const{control:i,handleSubmit:a}=h.useForm({defaultValues:{name:"",password:""}}),l=async({name:o,password:s})=>{try{b.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const c=await v.account.login(o,s);window.localStorage.setItem("token",c.token),b.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),t(c)}catch(c){b.updateNotification({id:"for-login",title:"Login Failed",message:c.message,color:"red"})}};return e(r.Box,{mx:"auto",children:u("form",{onSubmit:a(l),children:[e(h.Controller,{name:"name",control:i,render:({field:o})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...o})}),e(h.Controller,{name:"password",control:i,render:({field:o})=>e(r.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...o})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Submit"})})]})})}function _e({styles:t=A,config:n,onSuccess:i}){return j(n),e(P,{children:e(r.Box,{mt:t.spacing,sx:{position:"relative"},children:e(xe,{styles:t,postSubmit:i})})})}const N={size:"sm",spacing:"md",button:{size:"xs"}};function Te({postSubmit:t,styles:n=N,initialRoleID:i}){const{control:a,handleSubmit:l}=h.useForm({defaultValues:{name:"",role_id:i}}),o=async({name:s,role_id:c})=>{try{b.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const{app_id:p,app_secret:f}=await v.api_key.create(s,c);b.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),t(p,f)}catch(p){b.updateNotification({id:"for-creating",title:"Failed",message:p.message,color:"red"})}};return e(r.Box,{mx:"auto",children:u("form",{onSubmit:l(o),children:[e(h.Controller,{name:"name",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",...s})}),e(h.Controller,{name:"role_id",control:a,render:({field:s})=>e(M,{styles:n,...s})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function $({onSuccess:t,styles:n=N,initialRoleID:i}){const a=D.useModals(),[l,o]=z.useState(!1),s=()=>o(!0),c=()=>o(!1),p=(f,d)=>{c(),a.openModal({title:"API Key is generated",children:u(r.Stack,{children:[e(r.Text,{color:"dimmed",children:"Make sure you save it - you won't be able to access it again."}),e(r.TextInput,{defaultValue:f,disabled:!0,label:"APP ID",styles:{input:{cursor:"text !important"}}}),e(r.TextInput,{defaultValue:d,disabled:!0,label:"APP Secret",styles:{input:{cursor:"text !important"}}}),e(r.Button,{size:"sm",onClick:()=>{D.closeAllModals()},children:"I've saved this API Key"})]}),onClose:()=>{t()}})};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:l,onClose:()=>o(!1),title:"Add an API Key",trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:e(Te,{postSubmit:p,styles:n,initialRoleID:i})}),e(r.Button,{size:n.button.size,onClick:s,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function F({id:t,name:n,onSuccess:i,styles:a=N}){const l=D.useModals(),o=async()=>{if(t){b.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await v.api_key.delete(t),b.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${n}] is deleted`,color:"green"}),i()}catch(c){b.updateNotification({id:"for-deleting",title:"Failed",message:c.message,color:"red"})}}},s=()=>l.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:o});return e(r.Button,{size:a.button.size,color:"red",onClick:s,leftIcon:e(y.Trash,{size:20}),children:"Delete"})}function qe({styles:t=N,config:n}){var f;j(n);const{data:i=[],loading:a,refresh:l}=x.useRequest(async()=>{const{data:d}=await v.api_key.list();return d},{refreshDeps:[]}),{data:o=[],loading:s}=x.useRequest(async()=>(await v.role.list()).map(g=>({label:g.name,value:g.id,description:g.description,disabled:g.id===50})),{refreshDeps:[]}),c=z.useMemo(()=>o.reduce((d,g)=>(d.set(g.value,g.label),d),new Map),[o]),p=d=>c.get(d)??d;return u(P,{children:[e(r.Group,{pt:t.spacing,position:"right",children:e($,{onSuccess:l,initialRoleID:((f=o==null?void 0:o[0])==null?void 0:f.value)??0})}),u(r.Box,{mt:t.spacing,sx:{position:"relative"},children:[e(r.LoadingOverlay,{visible:a||s}),u(r.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[e("thead",{children:u("tr",{children:[e("th",{children:"Name"}),e("th",{children:"APP ID"}),e("th",{children:"Role"}),e("th",{children:"Action"})]})}),e("tbody",{children:i.map(d=>{const{id:g,name:w,app_id:C,role_id:_}=d;return u("tr",{children:[e("td",{width:200,children:w}),e("td",{width:200,children:C}),e("td",{width:200,children:p(_)}),e("td",{width:200,children:e(r.Group,{position:"left",children:e(F,{id:g,name:w,onSuccess:l})})})]},g)})})]})]})]})}const De=()=>Promise.resolve().then(()=>Oe).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t)),J="@devtable/settings-form",Q="8.51.0",W="Apache-2.0",X={access:"public",registry:"https://registry.npmjs.org/"},Y=["dist"],Z="./dist/settings-form.umd.js",H="./dist/settings-form.es.js",ee="./dist/index.d.ts",te={".":{import:"./dist/settings-form.es.js",require:"./dist/settings-form.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},ne={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview"},ie={"@monaco-editor/react":"4.4.6","monaco-editor":"0.36.0"},re={"@emotion/babel-plugin":"11.7.2","@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"},ae={"@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"},Oe=Object.freeze(Object.defineProperty({__proto__:null,default:{name:J,version:Q,license:W,publishConfig:X,files:Y,main:Z,module:H,types:ee,exports:te,scripts:ne,dependencies:ie,devDependencies:re,peerDependencies:ae},dependencies:ie,devDependencies:re,exports:te,files:Y,license:W,main:Z,module:H,name:J,peerDependencies:ae,publishConfig:X,scripts:ne,types:ee,version:Q},Symbol.toStringTag,{value:"Module"}));m.APIKeyList=qe,m.AccountList=Ae,m.AddAPIKey=$,m.AddAccount=K,m.AddDataSource=U,m.DataSourceList=ze,m.DeleteAPIKey=F,m.DeleteAccount=V,m.DeleteDataSource=E,m.Login=_e,m.getVersion=De,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
3
+ `)};function ge({submit:t,styles:n=T}){const{control:i,setValue:a,handleSubmit:l}=h.useForm({defaultValues:{type:"http",key:"",config:{host:"",processing:{pre:R.pre,post:R.post}}}});return e(r.Box,{mx:"auto",children:u("form",{onSubmit:l(t),children:[e(h.Controller,{name:"key",control:i,render:({field:o})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",placeholder:"A unique name",...o})}),e(r.Divider,{label:"Connection Info",labelPosition:"center"}),e(h.Controller,{name:"config.host",control:i,render:({field:o})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Base URL",sx:{flexGrow:1},...o})}),u(r.Group,{grow:!0,children:[e(h.Controller,{name:"config.processing.pre",control:i,render:({field:o})=>e(G,{label:"Pre Processing",modalTitle:"This function will run before sending the request (for scenarios like encryption)",defaultValue:R.pre,...o,styles:n})}),e(h.Controller,{name:"config.processing.post",control:i,render:({field:o})=>e(G,{label:"Post Processing",modalTitle:"This function will run after sending the request (for scenarios like decryption)",defaultValue:R.post,...o,styles:n})})]}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function he({postSubmit:t,styles:n=T}){const[i,a]=z.useState("postgresql"),l=async({type:c,key:p,config:f})=>{b.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0});try{console.log({type:c,key:p,config:f}),await v.datasource.create(c,p,f),b.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),t()}catch(d){b.updateNotification({id:"for-creating",title:"Failed",message:d.message,color:"red"})}},o=i==="postgresql"||i==="mysql",s=i==="http";return u(r.Box,{mx:"auto",children:[e(r.SegmentedControl,{fullWidth:!0,mb:n.spacing,size:n.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http"}],value:i,onChange:c=>a(c)}),o&&e(ue,{submit:l,styles:n,type:i}),s&&e(ge,{submit:l,styles:n})]})}function U({onSuccess:t,styles:n=T}){const[i,a]=z.useState(!1),l=()=>a(!0),o=()=>a(!1),s=()=>{t(),o()};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:i,onClose:()=>a(!1),title:"Add a data source",trapFocus:!0,onDragStart:c=>{c.stopPropagation()},children:e(he,{postSubmit:s,styles:n})}),e(r.Button,{size:n.button.size,onClick:l,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}const me=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function fe(t){z.useEffect(()=>{if(I.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/settings-form");const i=me(t);I.loader.config({paths:{vs:i}}),I.loader.init().then(a=>console.log("monaco instance:",a))},[])}function L(){return L=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},L.apply(this,arguments)}function be(t,n){if(t==null)return{};var i,a,l=function(s,c){if(s==null)return{};var p,f,d={},g=Object.keys(s);for(f=0;f<g.length;f++)p=g[f],c.indexOf(p)>=0||(d[p]=s[p]);return d}(t,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(a=0;a<o.length;a++)i=o[a],n.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(l[i]=t[i])}return l}var we=["size","color","stroke"];function Se(t){var n=t.size,i=n===void 0?24:n,a=t.color,l=a===void 0?"currentColor":a,o=t.stroke,s=o===void 0?2:o,c=be(t,we);return O.createElement("svg",L({xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-lock",width:i,height:i,viewBox:"0 0 24 24",strokeWidth:s,stroke:l,fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},c),O.createElement("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),O.createElement("rect",{x:5,y:11,width:14,height:10,rx:2}),O.createElement("circle",{cx:12,cy:16,r:1}),O.createElement("path",{d:"M8 11v-4a4 4 0 0 1 8 0v4"}))}function E({id:t,name:n,isProtected:i,onSuccess:a,styles:l=T}){const o=D.useModals(),s=async()=>{t&&(b.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await v.datasource.delete(t),b.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${n}] is deleted`,color:"green"}),a())},c=()=>o.openConfirmModal({title:"Delete this data source?",children:e(r.Text,{size:l.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:s}),p=r.useMantineTheme();return i?e(r.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:"This is a preset datasource, it can not be deleted",children:e("span",{children:e(Se,{size:16,color:p.colors.gray[7]})})}):e(r.Button,{size:l.button.size,color:"red",onClick:c,leftIcon:e(y.Trash,{size:20}),children:"Delete"})}function ze({styles:t=T,config:n}){fe(n.monacoPath),j(n);const{data:i=[],loading:a,refresh:l}=x.useRequest(async()=>{const{data:o}=await v.datasource.list();return o},{refreshDeps:[]});return u(P,{children:[e(r.Group,{pt:t.spacing,position:"right",children:e(U,{onSuccess:l})}),u(r.Box,{mt:t.spacing,sx:{position:"relative"},children:[e(r.LoadingOverlay,{visible:a}),u(r.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[e("thead",{children:u("tr",{children:[e("th",{children:"Type"}),e("th",{children:"Name"}),e("th",{children:"Action"})]})}),e("tbody",{children:i.map(({id:o,key:s,type:c,is_preset:p})=>u("tr",{children:[e("td",{width:200,children:c}),e("td",{children:s}),e("td",{width:200,children:e(r.Group,{position:"left",children:e(E,{isProtected:p,id:o,name:s,onSuccess:l})})})]},s))})]})]})]})}const ve=z.forwardRef(({label:t,value:n,description:i,...a},l)=>u(r.Stack,{spacing:2,ref:l,...a,children:[e(r.Text,{size:"sm",children:t}),e(r.Text,{size:"xs",color:"dimmed",className:"role-description",children:i})]})),M=z.forwardRef(({styles:t,value:n,onChange:i},a)=>{const{data:l=[],loading:o}=x.useRequest(async()=>(await v.role.list()).map(c=>({label:c.name,value:c.id,description:c.description,disabled:c.id===50})),{refreshDeps:[]});return e(r.Select,{ref:a,mb:t.spacing,size:t.size,required:!0,label:"Role",itemComponent:ve,data:l,disabled:o,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:n,onChange:i})}),A={size:"sm",spacing:"md",button:{size:"xs"}};function Pe({postSubmit:t,styles:n=A,initialRoleID:i}){const{control:a,handleSubmit:l}=h.useForm({defaultValues:{name:"",email:"",role_id:i,password:""}}),o=async({name:s,email:c,password:p,role_id:f})=>{try{b.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await v.account.create(s,c,p,f),b.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),t()}catch(d){b.updateNotification({id:"for-creating",title:"Failed",message:d.message,color:"red"})}};return e(r.Box,{mx:"auto",children:u("form",{onSubmit:l(o),children:[e(h.Controller,{name:"name",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...s})}),e(h.Controller,{name:"email",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Email",...s})}),e(h.Controller,{name:"password",control:a,render:({field:s})=>e(r.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...s})}),e(h.Controller,{name:"role_id",control:a,render:({field:s})=>e(M,{styles:n,...s})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function K({onSuccess:t,styles:n=A,initialRoleID:i}){const[a,l]=z.useState(!1),o=()=>l(!0),s=()=>l(!1),c=()=>{t(),s()};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:a,onClose:()=>l(!1),title:"Add an Account",trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e(Pe,{postSubmit:c,styles:n,initialRoleID:i})}),e(r.Button,{size:n.button.size,onClick:o,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function V({id:t,name:n,onSuccess:i,styles:a=A}){const l=D.useModals(),o=async()=>{if(t){b.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await v.account.delete(t),b.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${n}] is deleted`,color:"green"}),i()}catch(c){b.updateNotification({id:"for-deleting",title:"Failed",message:c.message,color:"red"})}}},s=()=>l.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:o});return e(r.Button,{size:a.button.size,color:"red",onClick:s,leftIcon:e(y.Trash,{size:20}),children:"Delete"})}function Ce({id:t,name:n,email:i,role_id:a,postSubmit:l,styles:o=A}){const{control:s,handleSubmit:c,watch:p}=h.useForm({defaultValues:{name:n,email:i,role_id:a,reset_password:!1,new_password:""}}),f=async({name:w,email:C,role_id:_,reset_password:Ie,new_password:je})=>{try{b.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await v.account.edit({id:t,name:w,email:C,role_id:_,reset_password:Ie,new_password:je}),b.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),l()}catch(Re){b.updateNotification({id:"for-updating",title:"Failed",message:Re.message,color:"red"})}},[d,g]=p(["reset_password","new_password"]);return e(r.Box,{mx:"auto",children:u("form",{onSubmit:c(f),children:[e(h.Controller,{name:"name",control:s,render:({field:w})=>e(r.TextInput,{mb:o.spacing,size:o.size,required:!0,label:"Username",...w})}),e(h.Controller,{name:"email",control:s,render:({field:w})=>e(r.TextInput,{mb:o.spacing,size:o.size,required:!0,label:"Email",...w})}),e(h.Controller,{name:"role_id",control:s,render:({field:w})=>e(M,{styles:o,...w})}),e(r.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),e(h.Controller,{name:"reset_password",control:s,render:({field:w})=>e(r.Switch,{mb:o.spacing,size:o.size,label:"Reset password",checked:w.value,onChange:C=>w.onChange(C.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),d&&e(h.Controller,{name:"new_password",control:s,render:({field:w})=>e(r.PasswordInput,{autoComplete:"off",mb:o.spacing,size:o.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...w})}),e(r.Group,{position:"right",mt:o.spacing,children:e(r.Button,{type:"submit",size:o.button.size,children:"Submit"})})]})})}function ye({account:t,onSuccess:n,styles:i=A}){const[a,l]=z.useState(!1),o=()=>l(!0),s=()=>l(!1),c=()=>{n(),s()};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:a,onClose:()=>l(!1),title:`Editing ${t.name}`,trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e(Ce,{...t,postSubmit:c,styles:i})}),e(r.Button,{size:i.button.size,onClick:o,leftIcon:e(y.Edit,{size:20}),children:"Edit"})]})}function Ae({styles:t=A,config:n}){var f;j(n);const{data:i=[],loading:a,refresh:l}=x.useRequest(async()=>{const{data:d}=await v.account.list();return d},{refreshDeps:[]}),{data:o=[],loading:s}=x.useRequest(async()=>(await v.role.list()).map(g=>({label:g.name,value:g.id,description:g.description,disabled:g.id===50})),{refreshDeps:[]}),c=z.useMemo(()=>o.reduce((d,g)=>(d.set(g.value,g.label),d),new Map),[o]),p=d=>c.get(d)??d;return u(P,{children:[e(r.Group,{pt:t.spacing,position:"right",children:e(K,{onSuccess:l,initialRoleID:((f=o==null?void 0:o[0])==null?void 0:f.value)??0})}),u(r.Box,{mt:t.spacing,sx:{position:"relative"},children:[e(r.LoadingOverlay,{visible:a||s}),u(r.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[e("thead",{children:u("tr",{children:[e("th",{children:"Username"}),e("th",{children:"Email"}),e("th",{children:"Role"}),e("th",{children:"Action"})]})}),e("tbody",{children:i.map(d=>{const{id:g,name:w,email:C,role_id:_}=d;return u("tr",{children:[e("td",{width:200,children:w}),e("td",{width:200,children:C}),e("td",{width:200,children:p(_)}),e("td",{width:200,children:u(r.Group,{position:"left",children:[e(ye,{account:d,onSuccess:l}),e(V,{id:g,name:w,onSuccess:l})]})})]},g)})})]})]})]})}function xe({postSubmit:t,styles:n=A}){const{control:i,handleSubmit:a}=h.useForm({defaultValues:{name:"",password:""}}),l=async({name:o,password:s})=>{try{b.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const c=await v.account.login(o,s);window.localStorage.setItem("token",c.token),b.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),t(c)}catch(c){b.updateNotification({id:"for-login",title:"Login Failed",message:c.message,color:"red"})}};return e(r.Box,{mx:"auto",children:u("form",{onSubmit:a(l),children:[e(h.Controller,{name:"name",control:i,render:({field:o})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...o})}),e(h.Controller,{name:"password",control:i,render:({field:o})=>e(r.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...o})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Submit"})})]})})}function _e({styles:t=A,config:n,onSuccess:i}){return j(n),e(P,{children:e(r.Box,{mt:t.spacing,sx:{position:"relative"},children:e(xe,{styles:t,postSubmit:i})})})}const N={size:"sm",spacing:"md",button:{size:"xs"}};function Te({postSubmit:t,styles:n=N,initialRoleID:i}){const{control:a,handleSubmit:l}=h.useForm({defaultValues:{name:"",role_id:i}}),o=async({name:s,role_id:c})=>{try{b.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const{app_id:p,app_secret:f}=await v.api_key.create(s,c);b.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),t(p,f)}catch(p){b.updateNotification({id:"for-creating",title:"Failed",message:p.message,color:"red"})}};return e(r.Box,{mx:"auto",children:u("form",{onSubmit:l(o),children:[e(h.Controller,{name:"name",control:a,render:({field:s})=>e(r.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",...s})}),e(h.Controller,{name:"role_id",control:a,render:({field:s})=>e(M,{styles:n,...s})}),e(r.Group,{position:"right",mt:n.spacing,children:e(r.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function $({onSuccess:t,styles:n=N,initialRoleID:i}){const a=D.useModals(),[l,o]=z.useState(!1),s=()=>o(!0),c=()=>o(!1),p=(f,d)=>{c(),a.openModal({title:"API Key is generated",children:u(r.Stack,{children:[e(r.Text,{color:"dimmed",children:"Make sure you save it - you won't be able to access it again."}),e(r.TextInput,{defaultValue:f,disabled:!0,label:"APP ID",styles:{input:{cursor:"text !important"}}}),e(r.TextInput,{defaultValue:d,disabled:!0,label:"APP Secret",styles:{input:{cursor:"text !important"}}}),e(r.Button,{size:"sm",onClick:()=>{D.closeAllModals()},children:"I've saved this API Key"})]}),onClose:()=>{t()}})};return u(P,{children:[e(r.Modal,{overflow:"inside",opened:l,onClose:()=>o(!1),title:"Add an API Key",trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:e(Te,{postSubmit:p,styles:n,initialRoleID:i})}),e(r.Button,{size:n.button.size,onClick:s,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function F({id:t,name:n,onSuccess:i,styles:a=N}){const l=D.useModals(),o=async()=>{if(t){b.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await v.api_key.delete(t),b.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${n}] is deleted`,color:"green"}),i()}catch(c){b.updateNotification({id:"for-deleting",title:"Failed",message:c.message,color:"red"})}}},s=()=>l.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:o});return e(r.Button,{size:a.button.size,color:"red",onClick:s,leftIcon:e(y.Trash,{size:20}),children:"Delete"})}function qe({styles:t=N,config:n}){var f;j(n);const{data:i=[],loading:a,refresh:l}=x.useRequest(async()=>{const{data:d}=await v.api_key.list();return d},{refreshDeps:[]}),{data:o=[],loading:s}=x.useRequest(async()=>(await v.role.list()).map(g=>({label:g.name,value:g.id,description:g.description,disabled:g.id===50})),{refreshDeps:[]}),c=z.useMemo(()=>o.reduce((d,g)=>(d.set(g.value,g.label),d),new Map),[o]),p=d=>c.get(d)??d;return u(P,{children:[e(r.Group,{pt:t.spacing,position:"right",children:e($,{onSuccess:l,initialRoleID:((f=o==null?void 0:o[0])==null?void 0:f.value)??0})}),u(r.Box,{mt:t.spacing,sx:{position:"relative"},children:[e(r.LoadingOverlay,{visible:a||s}),u(r.Table,{horizontalSpacing:t.spacing,verticalSpacing:t.spacing,fontSize:t.size,highlightOnHover:!0,children:[e("thead",{children:u("tr",{children:[e("th",{children:"Name"}),e("th",{children:"APP ID"}),e("th",{children:"Role"}),e("th",{children:"Action"})]})}),e("tbody",{children:i.map(d=>{const{id:g,name:w,app_id:C,role_id:_}=d;return u("tr",{children:[e("td",{width:200,children:w}),e("td",{width:200,children:C}),e("td",{width:200,children:p(_)}),e("td",{width:200,children:e(r.Group,{position:"left",children:e(F,{id:g,name:w,onSuccess:l})})})]},g)})})]})]})]})}const De=()=>Promise.resolve().then(()=>Oe).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t)),J="@devtable/settings-form",Q="8.51.1",W="Apache-2.0",X={access:"public",registry:"https://registry.npmjs.org/"},Y=["dist"],Z="./dist/settings-form.umd.js",H="./dist/settings-form.es.js",ee="./dist/index.d.ts",te={".":{import:"./dist/settings-form.es.js",require:"./dist/settings-form.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},ne={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview"},ie={"@monaco-editor/react":"4.4.6","monaco-editor":"0.36.0"},re={"@emotion/babel-plugin":"11.7.2","@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"},ae={"@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"},Oe=Object.freeze(Object.defineProperty({__proto__:null,default:{name:J,version:Q,license:W,publishConfig:X,files:Y,main:Z,module:H,types:ee,exports:te,scripts:ne,dependencies:ie,devDependencies:re,peerDependencies:ae},dependencies:ie,devDependencies:re,exports:te,files:Y,license:W,main:Z,module:H,name:J,peerDependencies:ae,publishConfig:X,scripts:ne,types:ee,version:Q},Symbol.toStringTag,{value:"Module"}));m.APIKeyList=qe,m.AccountList=Ae,m.AddAPIKey=$,m.AddAccount=K,m.AddDataSource=U,m.DataSourceList=ze,m.DeleteAPIKey=F,m.DeleteAccount=V,m.DeleteDataSource=E,m.Login=_e,m.getVersion=De,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/settings-form",
3
- "version": "8.51.0",
3
+ "version": "8.51.1",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public",