@devtable/dashboard 4.18.0 → 4.19.0

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.
@@ -773,18 +773,19 @@ const Ke = {
773
773
  baseURL: "http://localhost:31200",
774
774
  getRequest(e) {
775
775
  return (t, n, r = {}) => {
776
- const o = {
776
+ const o = window.localStorage.getItem("token"), a = {
777
777
  "X-Requested-With": "XMLHttpRequest",
778
778
  "Content-Type": r.string ? "application/x-www-form-urlencoded" : "application/json",
779
+ authorization: o ? `bearer ${o}` : "",
779
780
  ...r.headers
780
- }, a = {
781
+ }, l = {
781
782
  baseURL: this.baseURL,
782
783
  method: e,
783
784
  url: t,
784
785
  params: e === "GET" ? n : r.params,
785
- headers: o
786
+ headers: a
786
787
  };
787
- return e === "POST" && (a.data = r.string ? JSON.stringify(n) : n), il(a).then((l) => l.data).catch((l) => Promise.reject(l));
788
+ return ["POST", "PUT"].includes(e) && (l.data = r.string ? JSON.stringify(n) : n), il(l).then((s) => s.data).catch((s) => Promise.reject(s));
788
789
  };
789
790
  }
790
791
  }, Hn = ({ type: e, key: t, sql: n }) => async () => {
@@ -3126,7 +3127,7 @@ const Es = (e) => {
3126
3127
  getColor: Xt(["#fff7f1", "darkorange", "#b60000"]),
3127
3128
  name: "orange",
3128
3129
  category: "sequential"
3129
- }, Ts = "4.18.0";
3130
+ }, Ts = "4.19.0";
3130
3131
  class Ls {
3131
3132
  constructor(t) {
3132
3133
  P(this, "staticColors", /* @__PURE__ */ new Map());
@@ -24,7 +24,7 @@ Check the render method of \``+h+"`."}return""}}function ag(h){{if(h!==void 0){v
24
24
 
25
25
  Check your code at `+x+":"+D+"."}return""}}var Wi={};function lg(h){{var x=ji();if(!x){var D=typeof h=="string"?h:h.displayName||h.name;D&&(x=`
26
26
 
27
- Check the top-level render call using <`+D+">.")}return x}}function Ui(h,x){{if(!h._store||h._store.validated||h.key!=null)return;h._store.validated=!0;var D=lg(x);if(Wi[D])return;Wi[D]=!0;var R="";h&&h._owner&&h._owner!==Rn.current&&(R=" It was passed a child from "+ie(h._owner.type)+"."),ze(h),k('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',D,R),ze(null)}}function Qi(h,x){{if(typeof h!="object")return;if(Vn(h))for(var D=0;D<h.length;D++){var R=h[D];Fn(R)&&Ui(R,x)}else if(Fn(h))h._store&&(h._store.validated=!0);else if(h){var G=A(h);if(typeof G=="function"&&G!==h.entries)for(var q=G.call(h),O;!(O=q.next()).done;)Fn(O.value)&&Ui(O.value,x)}}}function sg(h){{var x=h.type;if(x==null||typeof x=="string")return;var D;if(typeof x=="function")D=x.propTypes;else if(typeof x=="object"&&(x.$$typeof===d||x.$$typeof===f))D=x.propTypes;else return;if(D){var R=ie(x);Hc(D,h.props,"prop",R,h)}else if(x.PropTypes!==void 0&&!Tn){Tn=!0;var G=ie(x);k("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",G||"Unknown")}typeof x.getDefaultProps=="function"&&!x.getDefaultProps.isReactClassApproved&&k("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ug(h){{for(var x=Object.keys(h.props),D=0;D<x.length;D++){var R=x[D];if(R!=="children"&&R!=="key"){ze(h),k("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",R),ze(null);break}}h.ref!==null&&(ze(h),k("Invalid attribute `ref` supplied to `React.Fragment`."),ze(null))}}function Hi(h,x,D,R,G,q){{var O=vt(h);if(!O){var P="";(h===void 0||typeof h=="object"&&h!==null&&Object.keys(h).length===0)&&(P+=" 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 ne=ag(G);ne?P+=ne:P+=ji();var H;h===null?H="null":Vn(h)?H="array":h!==void 0&&h.$$typeof===t?(H="<"+(ie(h.type)||"Unknown")+" />",P=" Did you accidentally export a JSX literal instead of a component?"):H=typeof h,k("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",H,P)}var X=og(h,x,D,G,q);if(X==null)return X;if(O){var de=x.children;if(de!==void 0)if(R)if(Vn(de)){for(var Ge=0;Ge<de.length;Ge++)Qi(de[Ge],h);Object.freeze&&Object.freeze(de)}else k("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 Qi(de,h)}return h===r?ug(X):sg(X),X}}function dg(h,x,D){return Hi(h,x,D,!0)}function cg(h,x,D){return Hi(h,x,D,!1)}var gg=cg,pg=dg;Be.Fragment=r,Be.jsx=gg,Be.jsxs=pg}()),Be}(function(e){process.env.NODE_ENV==="production"?e.exports=po():e.exports=fo()})(Ze);const U=Ze.exports.Fragment,o=Ze.exports.jsx,g=Ze.exports.jsxs;class ke extends C.default.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return g(a.Box,{children:[o(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),o(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}function ho({label:e,config:{default_value:t,...n},value:r,onChange:i}){return g(a.Box,{children:[o(a.Text,{children:"\xA0"}),o(a.Checkbox,{label:e,checked:r,onChange:l=>i(l.currentTarget.checked),...n})]})}const qn=E.observer(({label:e,config:t,value:n,onChange:r})=>o(Xi.DateRangePicker,{label:e,value:n,onChange:r,icon:o(V.Calendar,{size:16}),sx:{minWidth:"16em"},...t}));function mo(e,t,n){const r=Rt(t,[],n),i=Object.keys(r),l=Object.values(r);try{return new Function(...i,`return \`${e}\`;`)(...l)}catch(s){return console.error(s),s.message}}function Et(e,t={}){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(i){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient params"):i}}function Rt(e,t,n){const r={...e,filters:n},i=t.reduce((l,s)=>(l[s.key]=Et(s.value,r),l),{});return z.default.merge({},i,e,{filters:n})}function Bn(e,t,n,r){try{const i=Rt(t,n,r);return Et(e,i)}catch(i){return console.error(i),i.message}}const $e={baseURL:"http://localhost:31200",getRequest(e){return(t,n,r={})=>{const i={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},l={baseURL:this.baseURL,method:e,url:t,params:e==="GET"?n:r.params,headers:i};return e==="POST"&&(l.data=r.string?JSON.stringify(n):n),so.default(l).then(s=>s.data).catch(s=>Promise.reject(s))}}},Tt=({type:e,key:t,sql:n})=>async()=>{if(!e||!t||!n)return[];try{return await $e.getRequest("POST")("/query",{type:e,key:t,query:n})}catch(r){return console.error(r),[]}};async function vo({context:e,sqlSnippets:t,title:n,query:r,filterValues:i}){if(!r.sql)return[];const{type:l,key:s,sql:u}=r,d=u.includes("$");try{const p=Rt(e,t,i),c=Et(u,p);return d&&(console.groupCollapsed(`Final SQL for: ${n}`),console.log(c),console.groupEnd()),await $e.getRequest("POST")("/query",{type:l,key:s,query:c})}catch(p){return console.error(p),[]}}async function yo(){try{return(await $e.getRequest("POST")("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}function bo({label:e,config:t,value:n,onChange:r}){const i=!!t.options_query.sql,{data:l=[],loading:s}=j.useRequest(Tt(t.options_query),{refreshDeps:[t.options_query,i]});return o(a.MultiSelect,{label:e,data:i?l:t.static_options,disabled:i?s:!1,value:n,onChange:r,sx:{minWidth:"14em"}})}function Co({label:e,config:t,value:n,onChange:r}){const i=!!t.options_query.sql,{data:l=[],loading:s}=j.useRequest(Tt(t.options_query),{refreshDeps:[t.options_query,i]});return o(a.Select,{label:e,data:i?l:t.static_options,disabled:i?s:!1,value:n,onChange:r})}function xo({label:e,config:t,value:n,onChange:r}){return o(a.TextInput,{label:e,value:n,onChange:r,...t})}const So=E.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return o(Co,{...r,...i,config:t});case"multi-select":return o(bo,{...r,...i,config:t});case"text-input":return o(xo,{...r,...i,config:t});case"date-range":return o(qn,{...r,...i,config:t});case"checkbox":return o(ho,{...r,...i,config:t});default:return null}}),jn=E.observer(C.default.forwardRef(({filter:e,...t},n)=>o("div",{className:"filter-root",ref:n,children:o(ke,{children:o(So,{filter:e,formFieldProps:t})})}))),Wn=E.observer(function({view:t}){const n=Y(),{control:r,handleSubmit:i}=S.useForm({defaultValues:n.filters.values}),l=n.filters.visibleInView(t.id);return l.length===0?null:o("form",{onSubmit:i(n.filters.setValues),children:g(a.Group,{className:"dashboard-filters",position:"apart",p:"md",noWrap:!0,sx:{border:"1px solid #ced4da",borderRadius:"4px"},children:[o(a.Group,{align:"flex-start",children:l.map(s=>o(S.Controller,{name:s.key,control:r,render:({field:u})=>o(jn,{filter:s,...u})},s.id))}),o(a.Group,{sx:{alignSelf:"flex-end"},children:o(a.Button,{color:"blue",size:"sm",type:"submit",children:"Submit"})})]})})}),wo={layoutFrozen:!1,freezeLayout:z.default.noop,inEditMode:!1,inUseMode:!0},le=C.default.createContext(wo),Un=C.default.createContext({panel:null,data:[],loading:!1}),Qn=Un.Provider;function ee(){const e=C.default.useContext(Un);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const _o=`
27
+ Check the top-level render call using <`+D+">.")}return x}}function Ui(h,x){{if(!h._store||h._store.validated||h.key!=null)return;h._store.validated=!0;var D=lg(x);if(Wi[D])return;Wi[D]=!0;var R="";h&&h._owner&&h._owner!==Rn.current&&(R=" It was passed a child from "+ie(h._owner.type)+"."),ze(h),k('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',D,R),ze(null)}}function Qi(h,x){{if(typeof h!="object")return;if(Vn(h))for(var D=0;D<h.length;D++){var R=h[D];Fn(R)&&Ui(R,x)}else if(Fn(h))h._store&&(h._store.validated=!0);else if(h){var G=A(h);if(typeof G=="function"&&G!==h.entries)for(var q=G.call(h),O;!(O=q.next()).done;)Fn(O.value)&&Ui(O.value,x)}}}function sg(h){{var x=h.type;if(x==null||typeof x=="string")return;var D;if(typeof x=="function")D=x.propTypes;else if(typeof x=="object"&&(x.$$typeof===d||x.$$typeof===f))D=x.propTypes;else return;if(D){var R=ie(x);Hc(D,h.props,"prop",R,h)}else if(x.PropTypes!==void 0&&!Tn){Tn=!0;var G=ie(x);k("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",G||"Unknown")}typeof x.getDefaultProps=="function"&&!x.getDefaultProps.isReactClassApproved&&k("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ug(h){{for(var x=Object.keys(h.props),D=0;D<x.length;D++){var R=x[D];if(R!=="children"&&R!=="key"){ze(h),k("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",R),ze(null);break}}h.ref!==null&&(ze(h),k("Invalid attribute `ref` supplied to `React.Fragment`."),ze(null))}}function Hi(h,x,D,R,G,q){{var O=vt(h);if(!O){var P="";(h===void 0||typeof h=="object"&&h!==null&&Object.keys(h).length===0)&&(P+=" 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 ne=ag(G);ne?P+=ne:P+=ji();var H;h===null?H="null":Vn(h)?H="array":h!==void 0&&h.$$typeof===t?(H="<"+(ie(h.type)||"Unknown")+" />",P=" Did you accidentally export a JSX literal instead of a component?"):H=typeof h,k("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",H,P)}var X=og(h,x,D,G,q);if(X==null)return X;if(O){var de=x.children;if(de!==void 0)if(R)if(Vn(de)){for(var Ge=0;Ge<de.length;Ge++)Qi(de[Ge],h);Object.freeze&&Object.freeze(de)}else k("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 Qi(de,h)}return h===r?ug(X):sg(X),X}}function dg(h,x,D){return Hi(h,x,D,!0)}function cg(h,x,D){return Hi(h,x,D,!1)}var gg=cg,pg=dg;Be.Fragment=r,Be.jsx=gg,Be.jsxs=pg}()),Be}(function(e){process.env.NODE_ENV==="production"?e.exports=po():e.exports=fo()})(Ze);const U=Ze.exports.Fragment,o=Ze.exports.jsx,g=Ze.exports.jsxs;class ke extends C.default.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return g(a.Box,{children:[o(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),o(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}function ho({label:e,config:{default_value:t,...n},value:r,onChange:i}){return g(a.Box,{children:[o(a.Text,{children:"\xA0"}),o(a.Checkbox,{label:e,checked:r,onChange:l=>i(l.currentTarget.checked),...n})]})}const qn=E.observer(({label:e,config:t,value:n,onChange:r})=>o(Xi.DateRangePicker,{label:e,value:n,onChange:r,icon:o(V.Calendar,{size:16}),sx:{minWidth:"16em"},...t}));function mo(e,t,n){const r=Rt(t,[],n),i=Object.keys(r),l=Object.values(r);try{return new Function(...i,`return \`${e}\`;`)(...l)}catch(s){return console.error(s),s.message}}function Et(e,t={}){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(i){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient params"):i}}function Rt(e,t,n){const r={...e,filters:n},i=t.reduce((l,s)=>(l[s.key]=Et(s.value,r),l),{});return z.default.merge({},i,e,{filters:n})}function Bn(e,t,n,r){try{const i=Rt(t,n,r);return Et(e,i)}catch(i){return console.error(i),i.message}}const $e={baseURL:"http://localhost:31200",getRequest(e){return(t,n,r={})=>{const i=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",authorization:i?`bearer ${i}`:"",...r.headers},s={baseURL:this.baseURL,method:e,url:t,params:e==="GET"?n:r.params,headers:l};return["POST","PUT"].includes(e)&&(s.data=r.string?JSON.stringify(n):n),so.default(s).then(u=>u.data).catch(u=>Promise.reject(u))}}},Tt=({type:e,key:t,sql:n})=>async()=>{if(!e||!t||!n)return[];try{return await $e.getRequest("POST")("/query",{type:e,key:t,query:n})}catch(r){return console.error(r),[]}};async function vo({context:e,sqlSnippets:t,title:n,query:r,filterValues:i}){if(!r.sql)return[];const{type:l,key:s,sql:u}=r,d=u.includes("$");try{const p=Rt(e,t,i),c=Et(u,p);return d&&(console.groupCollapsed(`Final SQL for: ${n}`),console.log(c),console.groupEnd()),await $e.getRequest("POST")("/query",{type:l,key:s,query:c})}catch(p){return console.error(p),[]}}async function yo(){try{return(await $e.getRequest("POST")("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}function bo({label:e,config:t,value:n,onChange:r}){const i=!!t.options_query.sql,{data:l=[],loading:s}=j.useRequest(Tt(t.options_query),{refreshDeps:[t.options_query,i]});return o(a.MultiSelect,{label:e,data:i?l:t.static_options,disabled:i?s:!1,value:n,onChange:r,sx:{minWidth:"14em"}})}function Co({label:e,config:t,value:n,onChange:r}){const i=!!t.options_query.sql,{data:l=[],loading:s}=j.useRequest(Tt(t.options_query),{refreshDeps:[t.options_query,i]});return o(a.Select,{label:e,data:i?l:t.static_options,disabled:i?s:!1,value:n,onChange:r})}function xo({label:e,config:t,value:n,onChange:r}){return o(a.TextInput,{label:e,value:n,onChange:r,...t})}const So=E.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return o(Co,{...r,...i,config:t});case"multi-select":return o(bo,{...r,...i,config:t});case"text-input":return o(xo,{...r,...i,config:t});case"date-range":return o(qn,{...r,...i,config:t});case"checkbox":return o(ho,{...r,...i,config:t});default:return null}}),jn=E.observer(C.default.forwardRef(({filter:e,...t},n)=>o("div",{className:"filter-root",ref:n,children:o(ke,{children:o(So,{filter:e,formFieldProps:t})})}))),Wn=E.observer(function({view:t}){const n=Y(),{control:r,handleSubmit:i}=S.useForm({defaultValues:n.filters.values}),l=n.filters.visibleInView(t.id);return l.length===0?null:o("form",{onSubmit:i(n.filters.setValues),children:g(a.Group,{className:"dashboard-filters",position:"apart",p:"md",noWrap:!0,sx:{border:"1px solid #ced4da",borderRadius:"4px"},children:[o(a.Group,{align:"flex-start",children:l.map(s=>o(S.Controller,{name:s.key,control:r,render:({field:u})=>o(jn,{filter:s,...u})},s.id))}),o(a.Group,{sx:{alignSelf:"flex-end"},children:o(a.Button,{color:"blue",size:"sm",type:"submit",children:"Submit"})})]})})}),wo={layoutFrozen:!1,freezeLayout:z.default.noop,inEditMode:!1,inUseMode:!0},le=C.default.createContext(wo),Un=C.default.createContext({panel:null,data:[],loading:!1}),Qn=Un.Provider;function ee(){const e=C.default.useContext(Un);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const _o=`
28
28
  -- You may reference global variables in SQL or VizConfig.
29
29
  SELECT *
30
30
  FROM commit
@@ -36,7 +36,7 @@ WHERE
36
36
  -- SQL snippets
37
37
  AND \${sql_snippets.author_email_condition}
38
38
  \${sql_snippets.order_by_clause}
39
- `,Hn=E.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=Y(),i=r.context.current,l=C.default.useMemo(()=>{const s={context:i,filters:r.filters.values};if(t){const u=r.sqlSnippets.current.reduce((d,p)=>(d[p.key]=p.value,d),{});s.sql_snippets=u}return JSON.stringify(s,null,2)},[i,r.sqlSnippets.current,r.filters.values,t]);return g(a.Stack,{sx:{border:"1px solid #eee",maxWidth:"40%",overflow:"hidden",...n},children:[o(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:o(a.Text,{weight:500,children:"Global Variables"})}),g(a.Stack,{px:"md",pb:"md",sx:{width:"100%"},children:[o(Fe.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:_o}),o(a.Text,{weight:500,sx:{flexGrow:0},children:"Current Values"}),o(Fe.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})]})]})});function Io({data:e}){return e.length===0?o(a.Box,{sx:{height:"5em"}}):g(a.Table,{children:[o("thead",{children:o("tr",{children:Object.keys(e==null?void 0:e[0]).map(t=>o("th",{children:o(a.Text,{weight:700,color:"#000",children:t})},t))})}),o("tbody",{children:e.slice(0,10).map((t,n)=>o("tr",{children:Object.values(t).map((r,i)=>o("td",{children:o(a.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:o(a.Text,{children:r})})},`${r}--${i}`))},`row-${n}`))})]})}const Yn=E.observer(function({id:t}){const n=Y(),{data:r,state:i}=n.getDataStuffByID(t),l=i==="loading",s=()=>{n.queries.refetchDataByQueryID(t)};return g(a.Stack,{my:"xl",sx:{border:"1px solid #eee"},children:[g(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[g(a.Group,{position:"left",children:[o(a.Text,{weight:500,children:"Preview Data"}),r.length>10&&g(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",r.length]})]}),o(a.ActionIcon,{mr:15,variant:"subtle",color:"blue",disabled:l,onClick:s,children:o(V.Refresh,{size:15})})]}),g(a.Box,{sx:{position:"relative"},children:[o(a.LoadingOverlay,{visible:l}),o(Io,{data:r})]})]})}),Do=w.forwardRef(({label:e,type:t,...n},r)=>g(a.Group,{position:"apart",ref:r,...n,children:[o(a.Text,{children:e}),o(a.Text,{children:t})]})),Xn=E.observer(function({value:t,onChange:n}){const{data:r=[],loading:i}=j.useRequest(yo,{refreshDeps:[]},[]),l=w.useMemo(()=>r.map(u=>({label:u.key,value:u.key,type:u.type})),[r]),s=w.useMemo(()=>l.reduce((u,d)=>(u[d.value]=d.type,u),{}),[l]);return o(a.Select,{label:"Data Source",data:l,itemComponent:Do,sx:{flex:1},disabled:i,value:t.key,onChange:u=>{u!==null&&n({key:u,type:s[u]})}})});function Jn({value:e}){const t=Y(),n=t.context.current,r=C.default.useMemo(()=>Bn(e,n,t.sqlSnippets.current,t.filters.values),[e,n,t.sqlSnippets.current,t.filters.values]);return o(Fe.Prism,{language:"sql",colorScheme:"light",children:r})}const Ao=E.observer(function({queryModel:t,setCurrentID:n}){const r=C.default.useRef(t.id),[i,l]=C.default.useState(r.current);C.default.useEffect(()=>{r.current!==t.id&&(l(t.id),r.current=t.id)},[r,t.id]);const[s,u]=C.default.useState(t.sql);C.default.useEffect(()=>{u(f=>f!==t.sql?t.sql:f)},[t.sql]);const d=s!==t.sql,p=()=>{t.setSQL(s)},c=()=>{n(i),t.setID(i)};return g(a.Stack,{sx:{border:"1px solid #eee",flexGrow:1},children:[o(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:o(a.Text,{weight:500,children:"Edit Query"})}),g(a.Stack,{my:0,p:"md",pr:40,children:[g(a.Group,{grow:!0,children:[o(a.TextInput,{placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},value:i,onChange:f=>{l(f.currentTarget.value)},rightSection:o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:i===t.id,onClick:c,children:o(V.DeviceFloppy,{size:18})})}),o(Xn,{value:{type:t.type,key:t.key},onChange:({type:f,key:m})=>{t.setKey(m),t.setType(f)}})]}),g(a.Tabs,{defaultValue:"SQL",children:[g(a.Tabs.List,{children:[o(a.Tabs.Tab,{value:"SQL",children:"SQL"}),o(a.Tabs.Tab,{value:"Preview",children:"Preview"})]}),o(a.Tabs.Panel,{value:"SQL",pt:"sm",children:g(a.Box,{sx:{position:"relative"},children:[o(a.Textarea,{autosize:!0,minRows:12,maxRows:24,className:"code-textarea",value:s,onChange:f=>{u(f.currentTarget.value)}}),o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:10,top:10},disabled:!d,onClick:p,children:o(V.DeviceFloppy,{size:20})})]})}),o(a.Tabs.Panel,{value:"Preview",pt:"sm",children:o(Jn,{value:t.sql})})]})]})]})}),Mo=E.observer(function({id:t,setID:n}){const r=Y(),i=C.default.useMemo(()=>r.queries.findByID(t),[r.queries,t]);return t?i?o(Ao,{queryModel:i,setCurrentID:n}):o("span",{children:"Invalid Query ID"}):null});var me=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(me||{});const Vo=E.observer(function({id:t,setID:n}){const r=Y(),i=()=>{var s;n((s=r.queries.firstID)!=null?s:"")};C.default.useEffect(()=>{if(!t){i();return}r.queries.current.findIndex(u=>u.id===t)===-1&&i()},[t,r.queries.current,i]);const l=()=>{const s=J.randomId();r.queries.append(y.cast({id:s,type:me.Postgresql,key:"",sql:""})),n(s)};return o(a.Group,{pb:"xl",children:g(a.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[o(a.Text,{children:"Select a Query"}),o(a.Select,{data:r.queries.options,value:t,onChange:n,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}}),o(a.Text,{children:"or"}),o(a.Group,{position:"center",mt:"md",children:o(a.Button,{onClick:l,children:"Add a Query"})})]})})}),Eo=E.observer(function(){const[t,n]=C.default.useState("");return g(a.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 225px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:[g(a.Group,{position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[g(a.Stack,{sx:{flexGrow:1,maxWidth:"calc(60% - 16px)"},children:[o(Vo,{id:t,setID:n}),o(Mo,{id:t,setID:n})]}),o(Hn,{})]}),o(Yn,{id:t})]})}),Ro=E.observer(({value:e})=>{const t=Y(),n=t.context.current,r=C.default.useMemo(()=>mo(e,n,t.filters.values),[e,n]);return g(a.Stack,{children:[o(a.Text,{children:"Preview"}),o(Fe.Prism,{language:"sql",noCopy:!0,colorScheme:"dark",children:r})]})}),To=E.observer(function(){const t=Y(),n=()=>t.sqlSnippets.append(y.cast({key:J.randomId(),value:""}));return g(a.Stack,{sx:{border:"1px solid #eee",flexGrow:1},children:[o(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:o(a.Text,{weight:500,children:"SQL Snippets"})}),o(a.Group,{px:"md",pb:"md",pt:"md",children:g(a.Stack,{sx:{width:"100%",position:"relative"},children:[t.sqlSnippets.current.map((r,i)=>g(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[o(a.TextInput,{label:"Key",required:!0,value:r.key,onChange:l=>{r.setKey(l.currentTarget.value)}}),o(a.Textarea,{minRows:3,label:"Value",required:!0,value:r.value,onChange:l=>{r.setValue(l.currentTarget.value)},className:"code-textarea"}),o(Ro,{value:r.value}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.sqlSnippets.remove(i),sx:{position:"absolute",top:15,right:5},children:o(V.Trash,{size:16})})]},i)),o(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"40%"},mx:"auto",children:o(a.Button,{variant:"default",onClick:n,children:"Add a snippet"})})]})})]})});function Fo(){return o(a.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 225px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:g(a.Group,{position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[o(To,{}),o(Hn,{showSQLSnippets:!1})]})})}const $o=E.observer(function({opened:t,close:n}){const{freezeLayout:r}=C.default.useContext(le);return C.default.useEffect(()=>{r(t)},[t]),o(a.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:"Data Settings",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},children:g(a.Tabs,{defaultValue:"Queries",children:[g(a.Tabs.List,{children:[o(a.Tabs.Tab,{value:"SQL Snippet",children:"SQL Snippet"}),o(a.Tabs.Tab,{value:"Queries",children:"Queries"})]}),o(a.Tabs.Panel,{value:"SQL Snippet",pt:"sm",children:o(Fo,{})}),o(a.Tabs.Panel,{value:"Queries",pt:"sm",children:o(Eo,{})})]})})});var se=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(se||{});const Kn=y.types.model({type:y.types.enumeration("DataSourceType",[me.Postgresql,me.MySQL,me.HTTP]),key:y.types.string,sql:y.types.string}),Zn=y.types.model("FilterConfigModel_TextInput",{required:y.types.boolean,default_value:y.types.string}).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),er=()=>Zn.create({required:!1,default_value:""}),Po=E.observer(function({config:t}){return o(U,{children:o(a.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"})})}),ko=[{label:"2022",value:"YYYY"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Oo=E.observer(function({config:t}){return g(U,{children:[g(a.Group,{children:[o(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),o(a.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),label:"Clearable"})]}),o(a.Select,{data:ko,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),o(qn,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue})]})});function zo({data:e}){return e.length===0?o(a.Box,{sx:{height:"5em"}}):g(a.Table,{children:[o("thead",{children:o("tr",{children:Object.keys(e==null?void 0:e[0]).map(t=>o("th",{children:o(a.Text,{weight:700,color:"#000",children:t})},t))})}),o("tbody",{children:e.slice(0,3).map((t,n)=>o("tr",{children:Object.values(t).map((r,i)=>o("td",{children:o(a.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:o(a.Text,{children:r})})},`${r}--${i}`))},`row-${n}`))}),e.length>3&&o("tfoot",{children:o("tr",{children:o("td",{colSpan:Object.keys(e==null?void 0:e[0]).length,children:g(a.Text,{color:"gray",size:"sm",children:[e.length-3," more row(s) hidden"]})})})})]})}const Go=E.observer(function({query:t}){const{data:n=[],loading:r,refresh:i}=j.useRequest(Tt(t),{refreshDeps:[t]});return g(a.Stack,{my:0,children:[g(a.Group,{position:"apart",children:[o(a.Text,{size:"md",pl:"sm",children:"Fetched Data"}),o(a.Button,{size:"xs",onClick:i,disabled:!t.sql||!t.key,children:"Retry"})]}),g(a.Box,{sx:{position:"relative"},children:[o(a.LoadingOverlay,{visible:r,exitTransitionDuration:0}),o(zo,{data:n})]})]})}),tr=E.observer(function({value:t,onChange:n}){return g(a.Stack,{my:0,children:[o(Xn,{value:t,onChange:({type:r,key:i})=>{n({...t,type:r,key:i})}}),g(a.Tabs,{defaultValue:"SQL",children:[g(a.Tabs.List,{children:[o(a.Tabs.Tab,{value:"SQL",children:"SQL"}),o(a.Tabs.Tab,{value:"Preview",children:"Preview"}),o(a.Tabs.Tab,{value:"Data",children:"Data"})]}),o(a.Tabs.Panel,{value:"SQL",pt:"sm",children:o(a.Textarea,{autosize:!0,minRows:12,maxRows:24,className:"code-textarea",value:t.sql,onChange:r=>{n({...t,sql:r.currentTarget.value})},placeholder:"SELECT name AS label, id AS value"})}),o(a.Tabs.Panel,{value:"Preview",pt:"sm",children:o(Jn,{value:t.sql})}),o(a.Tabs.Panel,{value:"Data",pt:"sm",children:o(Go,{query:t})})]})]})}),Lo=E.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,i=[...r];return g(U,{children:[o(a.Divider,{label:"Configure options",labelPosition:"center"}),r.length>0&&o(a.MultiSelect,{label:"Default Selection",data:i,value:t.default_value,onChange:t.setDefaultValue}),r.map((l,s)=>g(a.Group,{sx:{position:"relative"},pr:"40px",children:[o(a.TextInput,{label:"Label",required:!0,value:t.static_options[s].label,onChange:u=>{t.static_options[s].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.TextInput,{label:"Value",required:!0,value:t.static_options[s].value,onChange:u=>{t.static_options[s].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(s),sx:{position:"absolute",top:28,right:5},children:o(V.Trash,{size:16})})]})),o(a.Button,{size:"xs",color:"blue",leftIcon:o(V.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"}),o(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),o(tr,{value:t.options_query,onChange:t.setOptionsQuery})]})}),No=E.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,i=[{label:"No default selection",value:""},...r];return g(U,{children:[o(a.Checkbox,{checked:t.required,onChange:l=>t.setRequired(l.currentTarget.checked),label:"Required"}),o(a.Divider,{label:"Configure options",labelPosition:"center"}),r.length>0&&o(a.Select,{label:"Default Selection",data:i,value:t.default_value,onChange:t.setDefaultValue}),r.map((l,s)=>g(a.Group,{sx:{position:"relative"},pr:"40px",children:[o(a.TextInput,{label:"Label",required:!0,value:t.static_options[s].label,onChange:u=>{t.static_options[s].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.TextInput,{label:"Value",required:!0,value:t.static_options[s].value,onChange:u=>{t.static_options[s].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(s),sx:{position:"absolute",top:28,right:5},children:o(V.Trash,{size:16})})]},s)),o(a.Button,{size:"xs",color:"blue",leftIcon:o(V.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"}),o(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),o(tr,{value:t.options_query,onChange:t.setOptionsQuery})]})}),qo=E.observer(function({config:t}){return g(U,{children:[o(a.TextInput,{label:"Default Value",value:t.default_value,onChange:n=>{t.setDefaultValue(n.currentTarget.value)}}),o(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"})]})}),Bo=E.observer(function({filter:t}){const n=t.plainDefaultValue,[r,i]=C.default.useState(n);return C.default.useEffect(()=>{i(n)},[n]),g(a.Box,{sx:{maxWidth:"30em"},children:[o(a.Text,{pb:"md",color:"gray",children:"Preview"}),o(jn,{filter:t,value:r,onChange:i}),o(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),o(Fe.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),jo={select:No,"multi-select":Lo,"text-input":qo,checkbox:Po,"date-range":Oo},Wo=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],Uo=E.observer(function({filter:t,index:n}){const r=Y(),i=C.default.useMemo(()=>jo[t.type],[t.type]);return g(a.SimpleGrid,{cols:2,children:[g(a.Box,{pl:"md",children:[o(a.Text,{pb:"md",color:"gray",children:"Edit"}),g(a.Stack,{sx:{maxWidth:"30em"},children:[o(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0}),o(a.MultiSelect,{label:"Visible in...",data:r.views.options,value:t.visibleInViewsIDs,onChange:t.setVisibleInViewsIDs}),o(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:l=>{t.setKey(l.currentTarget.value)}}),o(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:l=>{t.setLabel(l.currentTarget.value)}}),o(a.Select,{label:"Widget",data:Wo,required:!0,value:t.type,onChange:t.setType}),o(i,{config:t.config,index:n})]})]}),o(Bo,{filter:t})]})}),vg="",Qo=E.observer(function(){const t=Y(),n=t.filters.current,r=()=>{const i=J.randomId(),l={id:i,key:i,label:i,order:n.length+1,type:se.TextInput,config:er(),visibleInViewsIDs:["Main"]};t.filters.append(l)};return g(a.Box,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)"},p:0,children:[o(a.Group,{sx:{position:"absolute",top:"16px",right:"16px"},children:o(a.Button,{size:"xs",color:"red",leftIcon:o(V.Recycle,{size:20}),disabled:!t.filters.changed,onClick:t.filters.reset,children:"Revert Changes"})}),o(a.Tabs,{className:"filter-settings-tabs",orientation:"vertical",defaultValue:t.filters.firstID,styles:{root:{display:"block"}},children:g(a.Group,{sx:{height:"100%"},children:[g(a.Stack,{sx:{height:"100%"},children:[o(a.Tabs.List,{position:"left",sx:{flexGrow:1,width:"200px"},children:t.filters.current.map(i=>o(a.Tabs.Tab,{value:i.id,children:i.label},i.id))}),o(a.Button,{size:"xs",color:"blue",leftIcon:o(V.PlaylistAdd,{size:20}),onClick:r,children:"Add a Filter"})]}),o(a.Box,{sx:{flexGrow:1,height:"100%"},children:t.filters.current.map((i,l)=>o(a.Tabs.Panel,{value:i.id,sx:{height:"100%"},children:g(a.Stack,{sx:{height:"100%"},spacing:"sm",children:[o(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"scroll"},children:o(Uo,{filter:i,index:l})}),o(a.Group,{position:"right",pt:10,children:o(a.Button,{size:"xs",color:"red",leftIcon:o(V.Trash,{size:20}),onClick:()=>t.filters.remove(l),children:"Delete this filter"})})]})},i.id))})]})})]})}),Ho=E.observer(function({opened:t,close:n}){const{freezeLayout:r}=C.default.useContext(le);return C.default.useEffect(()=>{r(t)},[t]),o(a.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:"Filters",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},withCloseButton:!1,children:o(Qo,{})})});var nr=(e=>(e.Use="use",e.Edit="edit",e))(nr||{}),ve=(e=>(e.Division="div",e.Modal="modal",e))(ve||{}),rr=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(rr||{});const Yo=E.observer(()=>{const t=Y().views.VIE;return!t||t.type!==ve.Division?null:g(a.Stack,{children:[o(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),o(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})}),Xo=E.observer(()=>{const t=Y().views.VIE;return!t||t.type!==ve.Modal?null:g(a.Stack,{children:[o(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),g(a.Group,{grow:!0,children:[o(a.TextInput,{label:"Width",value:t.config.width,onChange:n=>t.updateConfig("width",n.currentTarget.value),placeholder:"600px / 50vw"}),o(a.TextInput,{label:"Height",value:t.config.height,onChange:n=>t.updateConfig("height",n.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),Jo=E.observer(()=>g(U,{children:[o(Yo,{}),o(Xo,{})]})),Ko=[{label:"Division",value:ve.Division},{label:"Modal",value:ve.Modal}],Zo=E.observer(()=>{const t=Y().views.VIE;return t?g(a.Stack,{sx:{position:"relative"},children:[o(a.TextInput,{label:"Name",value:t.name,onChange:n=>{t.setName(n.currentTarget.value)}}),o(a.Select,{label:"Type",value:t.type,onChange:t.setType,data:Ko}),o(Jo,{})]}):null}),ea=E.observer(({opened:e,close:t})=>{var i;const n=Y(),{freezeLayout:r}=C.default.useContext(le);return C.default.useEffect(()=>{r(e)},[e]),o(a.Modal,{size:"500px",overflow:"inside",opened:e,onClose:t,withCloseButton:!1,styles:{header:{width:"100%"},title:{width:"100%"}},title:g(a.Group,{position:"apart",children:[g(a.Text,{sx:{flexGrow:1},children:["Editing ",(i=n.views.VIE)==null?void 0:i.name]}),o(a.ActionIcon,{size:18,color:"red",onClick:n.views.removeVIE,disabled:n.views.isVIETheFirstView,children:o(V.Trash,{size:18})})]}),trapFocus:!0,onDragStart:l=>{l.stopPropagation()},children:o(Zo,{})})}),ta=w.forwardRef(({label:e,type:t,...n},r)=>t!=="TRIGGER_TO_ADD"?o("div",{ref:r,...n,children:g(a.Group,{noWrap:!0,position:"apart",children:[o(a.Text,{size:"sm",children:e}),o(a.Text,{size:"xs",color:"dimmed",children:t})]})}):o("div",{ref:r,...n,children:o(a.Group,{noWrap:!0,grow:!0,children:o(a.Text,{size:"sm",align:"center",color:"#228be6",children:e})})})),ir="TRIGGER_TO_ADD",na=E.observer(({value:e,onChange:t,triggerAdd:n,triggerEdit:r,options:i})=>{const l=w.useMemo(()=>[...i,{label:"Add a View",value:ir,type:"TRIGGER_TO_ADD"}],[i,n]),s=u=>{u!==ir?t(u):n()};return g(a.Group,{position:"left",spacing:0,sx:{minWidth:"260px"},children:[o(a.Select,{value:e,onChange:s,placeholder:"Pick a View",itemComponent:ta,data:l,nothingFound:"Empty",sx:{flexGrow:1},styles:{input:{borderTopRightRadius:0,borderBottomRightRadius:0}}}),o(a.ActionIcon,{onClick:r,variant:"default",size:36,sx:{borderLeft:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,"&:active":{transform:"none",svg:{transform:"translateY(1px)"}}},children:o(V.Settings,{size:20})})]})}),ra=E.observer(()=>{const e=Y(),[t,n]=w.useState(!1),r=()=>{n(!0)},i=()=>{n(!1)};return g(U,{children:[o(na,{value:e.views.idOfVIE,onChange:e.views.setIDOfVIE,triggerAdd:e.views.addARandomNewView,triggerEdit:r,options:e.views.options}),o(ea,{opened:t,close:i})]})});function ia({opened:e,close:t,getCurrentSchema:n}){const{freezeLayout:r}=C.default.useContext(le);C.default.useEffect(()=>{r(e)},[e]);const i=C.default.useMemo(()=>JSON.stringify(n(),null,2),[e]);return o(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"This dashboard is described by this schema",trapFocus:!0,onDragStart:l=>{l.stopPropagation()},children:e&&o(Fe.Prism,{language:"json",sx:{width:"100%"},colorScheme:"dark",children:i})})}const or=E.observer(function({saveChanges:t}){const n=Y(),r=C.default.useCallback(()=>{const N=n.queries.current,te=n.views.current,ye=n.sqlSnippets.current;return{filters:n.filters.current,views:te,definition:{sqlSnippets:ye,queries:N}}},[n]),i=()=>{n.filters.reset(),n.views.reset(),n.sqlSnippets.reset(),n.queries.reset()},l=n.views.changed||n.sqlSnippets.changed||n.queries.changed||n.filters.changed,{inEditMode:s,inUseMode:u}=C.default.useContext(le),[d,p]=C.default.useState(!1),c=()=>p(!0),f=()=>p(!1),[m,v]=C.default.useState(!1),b=()=>v(!0),I=()=>v(!1),[A,T]=C.default.useState(!1),k=()=>T(!0),B=()=>T(!1);return g(a.Group,{position:"apart",pt:0,px:10,pb:"xs",children:[o(a.Group,{position:"left",children:s&&o(ra,{})}),g(a.Group,{position:"right",children:[!u&&o(a.Button,{variant:"default",size:"xs",disabled:!n.views.VIE,onClick:n.views.addAPanelToVIE,leftIcon:o(V.PlaylistAdd,{size:20}),children:"Add a Panel"}),s&&o(a.Button,{variant:"default",size:"xs",onClick:b,leftIcon:o(V.Filter,{size:20}),children:"Filters"}),s&&o(a.Button,{variant:"default",size:"xs",onClick:c,leftIcon:o(V.Database,{size:20}),children:"Data Settings"}),!u&&o(a.Button,{variant:"default",size:"xs",onClick:t,disabled:!l,leftIcon:o(V.DeviceFloppy,{size:20}),children:"Save Changes"}),!u&&o(a.Button,{color:"red",size:"xs",disabled:!l,onClick:i,leftIcon:o(V.Recycle,{size:20}),children:"Revert Changes"}),!u&&g(a.Menu,{width:180,children:[o(a.Menu.Target,{children:o(a.Button,{variant:"default",size:"xs",leftIcon:o(V.Share,{size:20}),children:"Export"})}),g(a.Menu.Dropdown,{children:[o(a.Menu.Item,{icon:o(V.Download,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),o(a.Menu.Item,{icon:o(V.Code,{size:14}),onClick:k,children:"View Schema"})]})]})]}),o(Ho,{opened:m,close:I}),o($o,{opened:d,close:f}),o(ia,{opened:A,close:B,getCurrentSchema:r})]})}),yg="",ar=E.observer(()=>{const{freezeLayout:e}=C.default.useContext(le),[t,n]=C.default.useState(!1),{panel:r}=ee();return C.default.useEffect(()=>{e(t)},[t]),!r.description||r.description==="<p><br></p>"?null:g(U,{children:[o(a.Modal,{opened:t,onClose:()=>n(!1),title:r.title,withCloseButton:!1,children:o(kn.default,{readOnly:!0,value:r.description,onChange:z.default.noop,sx:{border:"none"}})}),o(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:o(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:o(V.InfoCircle,{size:20})})})]})}),lr=e=>{const{title:t="Variables",variables:n}=e,r=J.useClipboard(),i=l=>{r.copy(l),_t.showNotification({color:"green",message:"Copied to clipboard"})};return g(a.Paper,{withBorder:!0,p:"sm",children:[o(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),o(a.Stack,{style:{maxHeight:"300px"},children:n.map(l=>g(a.Text,{size:"sm",children:[g(a.Code,{color:"teal",children:["// ",l.description]}),o("br",{}),g(a.Code,{onClick:()=>i(l.name),style:{cursor:"pointer"},children:[l.name," : ",l.valueType]})]},l.name))})]})};class oa{constructor(t,n){$(this,"operationId");$(this,"operation");$(this,"operationSchema");$(this,"variables",[]);this.operationManager=t,this.instance=n,K.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),i=this.operationManager.getOperationSchemaList().find(l=>l.id===(r==null?void 0:r.schemaRef));K.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function aa(e){return!!e.operationId}const la=E.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return o(a.Button,{variant:"outline",onClick:t,children:n})}),sa=E.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return w.createElement(e.operationSchema.configRender,t)});function ua({model:e}){const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(l=>l.id===i))}return o(a.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id})}const da=E.observer(e=>{const[t,{setTrue:n,setFalse:r}]=j.useBoolean(!1),{operationManager:i,operationId:l,instance:s,variables:u}=e,d=j.useCreation(()=>new oa(i,s),[i,s]);return j.useAsyncEffect(async()=>{await d.configOperation(l,u)},[l,d]),aa(d)?g(U,{children:[o(la,{model:d,onClick:n}),o(a.Modal,{opened:t,onClose:r,title:"Operation Settings",closeButtonLabel:"close",children:g(a.Stack,{children:[o(ua,{model:d}),o(sa,{model:d}),o(lr,{title:"Variables",variables:d.variables})]})})]}):null});class ca{constructor(t,n){$(this,"triggerId");$(this,"trigger");$(this,"triggerSchema");$(this,"sampleData");this.triggerManager=t,this.instance=n,K.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),i=this.triggerManager.getTriggerSchemaList().find(l=>l.id===(r==null?void 0:r.schemaRef));K.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return ga(this)}}function ga(e){return!!e.triggerId&&!!e.triggerSchema}function pa(e,t){return j.useCreation(()=>new ca(e,t),[e,t])}const fa=E.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return o(a.Button,{variant:"outline",onClick:t,children:w.createElement(n,r)})}),ha=E.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(l=>l.id===i))}return o(a.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),ma=E.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return w.createElement(e.triggerSchema.configRender,t)}),va=E.observer(e=>{const[t,{setTrue:n,setFalse:r}]=j.useBoolean(!1),i=e.model;return g(U,{children:[o(a.Modal,{opened:t,onClose:r,title:"Setup Trigger",closeButtonLabel:"close setup",children:g(a.Stack,{children:[o(ha,{model:i}),o(ma,{model:i}),o(lr,{title:"Payload",variables:i.triggerSchema.payload})]})}),o(fa,{onClick:n,model:i})]})});class Oe{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,_.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:_.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(i,l)=>{n(i,l)},r):this.root.watchItem(this.path,(i,l)=>{const s=_.get(i,t),u=_.get(l,t);s!==u&&n(s,u)},r)}}class Ft{constructor(t,n,r){$(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Oe(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Oe(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Oe(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(_.values(t).map(n=>this.constructInstance(new Oe(this.attachmentStorage,n.id))))}}class sr{constructor(t){$(this,"rootRef");this.rootRef=K.observable({current:t})}async deleteItem(t){K.runInAction(()=>{_.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?K.toJS(this.rootRef.current):_.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(_.isObject(n))K.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else K.runInAction(()=>{_.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return K.reaction(()=>this.getValueFromRoot(t),(i,l)=>{n(i,l)},{requiresObservable:!0,fireImmediately:_.get(r,"fireImmediately",!1)})}}class ya{constructor(){$(this,"channels",new Map);$(this,"globalChannel",new On.default)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new On.default;return this.channels.set(t,r),r}}class ba{constructor(t){$(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new ya,instanceData:new sr(t.viz.conf)};return this.instances.set(t.id,r),r}}function ur(e,t,n){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new sr({}),colorPalette:{getColor(){return()=>""}},data:t}}const Ca=e=>{const{panel:t,vizManager:n,data:r}=e,i=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),s={...ur(l,r,n),viewport:{width:t.layout.w,height:t.layout.h}},u=i.viewRender;return o(u,{context:s,instance:l,..._.omit(e,["panel","vizManager","data"])})},xa=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:i}=e,l=t.resolveComponent(n.viz.type),s=t.getOrCreateInstance(n),u={...ur(s,i,t),panelInfoEditor:r},d=l.configRender;return o(d,{context:u,instance:s,..._.omit(e,["panel","vizManager","data","panelInfoEditor"])})},dr=(e,t)=>{const n=Le.default.bezier(e),r=Le.default.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},et=e=>{const t=Le.default.bezier(e);return function(n){return t(n/100).hex()}},Sa={type:"interpolation",displayName:"Red / Green",getColor:dr(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},wa={type:"interpolation",displayName:"Yellow / Blue",getColor:dr(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},_a={type:"interpolation",displayName:"Red",getColor:et(["#fff7f1","darkred"]),name:"red",category:"sequential"},Ia={type:"interpolation",displayName:"Green",getColor:et(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Da={type:"interpolation",displayName:"Blue",getColor:et(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Aa={type:"interpolation",displayName:"Orange",getColor:et(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},Ma="4.18.0";class Va{constructor(t){$(this,"staticColors",new Map);$(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class Ea{constructor(){$(this,"plugins",new Map);$(this,"vizComponents",new Map);$(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ra{constructor(){$(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const r=this.migrations.filter(s=>s.version>t.from&&s.version<=t.to),i=_.orderBy(r,"version","asc");if(((l=_.last(i))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return i.reduce((s,u)=>u.handler(s),n)}}class ge extends Ra{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,r=>({version:t,...n(r)}))}async migrate({instanceData:t}){const n=await t.getItem(null),r=_.get(n,"version",0),i=this.run({from:r,to:this.VERSION},n);await t.setItem(null,i)}async needMigration({instanceData:t}){const n=await t.getItem(null);return _.get(n,"version",0)<this.VERSION}}const $t={content:""},L=(e,t)=>{const[n,{setFalse:r}]=j.useBoolean(!0),[i,l]=w.useState();w.useEffect(()=>(e.getItem(t).then(u=>{l(u),r()}),e.watchItem(t,u=>{l(u)})));const s=w.useCallback(async u=>{await e.setItem(t,u),l(u)},[e,t]);return{loading:n,value:i,set:s}};function cr(e){const t=w.useRef(null);return w.useEffect(()=>{var n,r,i;e&&((i=(r=(n=t.current)==null?void 0:n.editor)==null?void 0:r.clipboard)==null||i.dangerouslyPasteHTML(e))},[e]),t}function Ta({context:e}){const{panel:t}=ee(),{value:n}=L(e.instanceData,"config"),r=n==null?void 0:n.content,i=cr(r);return n!=null&&n.content?o(wt.RichTextEditor,{id:t.id,ref:i,readOnly:!0,value:n.content,onChange:_.noop,sx:{border:"none",".ql-editor":{padding:0,"h1, h2, h3, h4, h5, p, ul, ol":{"&:last-child":{marginBottom:0}}}}}):null}function Fa({context:e}){const{value:t,set:n}=L(e.instanceData,"config"),r=w.useMemo(()=>_.defaults({},t,$t),[t]),{control:i,handleSubmit:l,watch:s,getValues:u}=S.useForm({defaultValues:r});s("content");const d=u(),p=w.useMemo(()=>!_.isEqual(d,t),[d,t]),c=cr(t==null?void 0:t.content);return o(a.Stack,{mt:"md",spacing:"xs",children:g("form",{onSubmit:l(n),children:[g(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[o(a.Text,{children:"Content"}),o(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:o(V.DeviceFloppy,{size:20})})]}),o(S.Controller,{name:"content",control:i,render:({field:f})=>o(kn.default,{ref:c,sx:{flex:1},..._.omit(f,"ref")})})]})})}class $a extends ge{constructor(){super(...arguments);$(this,"VERSION",1)}fixMalformedConfig(n){return _.defaults({},n,$t)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Pa={displayName:"RichText",migrator:new $a,name:"richText",viewRender:Ta,configRender:Fa,createConfig:()=>$t},Pt={align:"center",template:"The variable ${value} is defined in Variables section",variables:[{name:"value",size:"20px",weight:"bold",color:{type:"static",staticColor:"blue"},data_field:"",aggregation:{type:"none",config:{}},formatter:{output:"number",mantissa:0}}]};function ka(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:i,content:{prefix:l="",data_field:s="value",formatter:u={output:"number",mantissa:0},postfix:d=""}={}}=e;return{align:t,template:`${l} \${value} ${d}`,variables:[{name:"value",data_field:s,aggregation:{type:"none",config:{}},formatter:u,color:i,weight:r,size:n}]}}class Oa extends ge{constructor(){super(...arguments);$(this,"VERSION",1)}configVersions(){this.version(1,n=>({config:ka(n)}))}}const kt=w.forwardRef(function({value:t,onChange:n,...r},i){return o(a.TextInput,{ref:i,value:t,onChange:n,...r})}),je={mantissa:0,output:"number",trimMantissa:!1,average:!1};function za({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},i=u=>{const d=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:d})},l=u=>{t({...e,trimMantissa:u.currentTarget.checked})},s=u=>{t({...e,average:u.currentTarget.checked})};return g(a.Stack,{ref:n,children:[g(a.Group,{grow:!0,children:[o(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),o(a.Switch,{label:g(a.Stack,{spacing:0,children:[o(a.Text,{children:"Average"}),o(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:s,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),g(a.Group,{grow:!0,children:[o(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),o(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:l,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),g(a.Stack,{spacing:0,children:[o(a.Text,{weight:"bold",children:"Preview"}),o(ke,{children:g(a.Group,{position:"apart",children:[g(a.Text,{size:12,color:"gray",children:["123456789 ",o(V.ArrowRight,{size:9})," ",ae.default(123456789).format(e)]}),g(a.Text,{size:12,color:"gray",children:["1234 ",o(V.ArrowRight,{size:9})," ",ae.default(1234).format(e)]}),g(a.Text,{size:12,color:"gray",children:["0.1234 ",o(V.ArrowRight,{size:9})," ",ae.default(.1234).format(e)]})]})})]})]})}const Ot=C.default.forwardRef(za);function tt(){return{name:J.randomId(),size:"20px",weight:"bold",color:{type:"static",staticColor:"blue"},data_field:"",aggregation:{type:"none",config:{}},formatter:je}}const Ga=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function La({label:e,value:t,onChange:n},r){w.useEffect(()=>{typeof t=="string"&&(console.log(t),n({type:t,config:{}}))},[t,n]);const i=s=>{n(s==="quantile"?{type:"quantile",config:{p:.99}}:{type:s,config:{}})},l=s=>{n({type:"quantile",config:{p:s}})};return g(a.Group,{grow:!0,noWrap:!0,pt:"sm",children:[o(a.Select,{ref:r,label:e,data:Ga,value:t.type,onChange:i}),t.type==="quantile"&&o(a.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Na=C.default.forwardRef(La);function qa({label:e,required:t,value:n,onChange:r,data:i,clearable:l=!1,sx:s,...u},d){const p=C.default.useMemo(()=>{if(!Array.isArray(i)||i.length===0)return[];const f=Object.keys(i[0]).map(m=>({label:m,value:m}));return l?f.concat([{label:"unset",value:""}]):f},[i]);return o(a.Select,{ref:d,label:e,data:p,value:n,onChange:r,required:t,sx:s,...u})}const Q=C.default.forwardRef(qa);function Ba({label:e,value:t,onChange:n},r){const[i,l]=C.default.useState(Array.isArray(t)?[...t]:[]),s=C.default.useCallback(()=>{l(m=>[...m,""])},[l]),u=C.default.useCallback(m=>{l(v=>(v.splice(m,1),[...v]))},[l]),d=C.default.useMemo(()=>!z.default.isEqual(i,t),[i,t]),p=()=>{n(i.map(m=>m.toString()))},c=a.useMantineTheme(),f=C.default.useMemo(()=>Object.entries(c.colors).map(([m,v])=>v[6]),[c]);return g(U,{children:[g(a.Group,{position:"left",ref:r,children:[o(a.Text,{children:e}),o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:o(V.DeviceFloppy,{size:20})})]}),g(a.Group,{children:[i.map((m,v)=>o(a.ColorInput,{value:m,onChange:b=>{l(I=>(I.splice(v,1,b),[...I]))},swatches:f,rightSection:o(a.ActionIcon,{onClick:()=>u(v),color:"red",children:o(V.Trash,{size:14})}),sx:{width:"45%"}})),o(a.ActionIcon,{onClick:s,color:"blue",variant:"outline",children:o(V.PlaylistAdd,{size:20})})]})]})}const ja=C.default.forwardRef(Ba);function Wa({value:e,onChange:t},n){const{colorManager:r}=w.useContext(xe),i=C.default.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),l=C.default.useMemo(()=>i.some(s=>s.value===e),[e,i]);return g(a.Group,{position:"apart",spacing:4,ref:n,children:[o(a.TextInput,{placeholder:"Set any color",value:l?"":e,onChange:s=>t(s.currentTarget.value),rightSection:o(a.ColorSwatch,{color:l?"transparent":e,radius:4}),variant:l?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),o(a.Text,{sx:{flexGrow:0},children:"or"}),o(a.Select,{data:i,value:e,onChange:t,variant:l?"default":"filled",placeholder:"Pick a theme color",icon:o(a.ColorSwatch,{color:l?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const De=C.default.forwardRef(Wa),nt=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Ua({label:e,value:t,onChange:n},r){var s,u;const[i,l]=C.default.useState((u=(s=nt.find(d=>d.label===t))==null?void 0:s.value)!=null?u:nt[0].value);return C.default.useEffect(()=>{const d=nt.find(p=>p.value===i);d&&n(d.label)},[i]),g(a.Stack,{spacing:0,mt:"sm",mb:"lg",children:[o(a.Text,{size:"sm",children:e}),o(a.Slider,{label:null,marks:nt,value:i,onChange:l,step:25,placeholder:"Pick a font size",ref:r})]})}const Qa=C.default.forwardRef(Ua);function Ha({label:e,value:t,onChange:n},r){const[i,l]=C.default.useState(Array.isArray(t)?[...t]:[]),s=C.default.useCallback(()=>{l(c=>[...c,""])},[l]),u=C.default.useCallback(c=>{l(f=>(f.splice(c,1),[...f]))},[l]),d=C.default.useMemo(()=>!z.default.isEqual(i,t),[i,t]),p=()=>{n(i.map(c=>c.toString()))};return g(U,{children:[g(a.Group,{position:"left",ref:r,children:[o(a.Text,{children:e}),o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:o(V.DeviceFloppy,{size:20})})]}),g(a.Group,{children:[i.map((c,f)=>o(a.TextInput,{value:c,onChange:m=>{const v=m.currentTarget.value;l(b=>(b.splice(f,1,v),[...b]))},rightSection:o(a.ActionIcon,{onClick:()=>u(f),color:"red",children:o(V.Trash,{size:14})}),sx:{width:"45%"}})),o(a.ActionIcon,{onClick:s,color:"blue",variant:"outline",children:o(V.PlaylistAdd,{size:20})})]})]})}const Ya=C.default.forwardRef(Ha),Xa=C.default.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,l=(s,u)=>{const d=z.default.cloneDeep(t);z.default.set(d,s,u),n(d)};return g(U,{children:[o(a.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),o(a.Stack,{children:o(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:s=>l("size",s.currentTarget.value)})}),o(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:o(Qa,{label:"Font Weight",value:t.weight,onChange:s=>l("weight",s)})}),o(a.Divider,{my:"xs",label:"Style",labelPosition:"center"}),g(a.Stack,{children:[o(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:s=>l("color.type",s)}),i==="static"&&o(De,{value:t.color.staticColor,onChange:s=>l("color.staticColor",s)}),i==="continuous"&&g(U,{children:[o(Ya,{label:"Value Range",value:t.color.valueRange,onChange:s=>l("color.valueRange",s)}),o(ja,{label:"Color Range",value:t.color.colorRange,onChange:s=>l("color.colorRange",s)})]})]})]})}),rt=C.default.forwardRef(function({value:t,onChange:n,data:r,withStyle:i=!0},l){const s=(u,d)=>{const p=z.default.cloneDeep(t);z.default.set(p,u,d),n(p)};return g(a.Box,{px:"sm",py:"md",ref:l,children:[o(a.Text,{weight:"bold",pb:0,children:t.name}),o(a.Divider,{my:"xs",label:"Data",labelPosition:"center"}),g(a.Group,{grow:!0,noWrap:!0,children:[o(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>s("name",u.currentTarget.value)}),o(Q,{label:"Data Field",required:!0,data:r,value:t.data_field,onChange:u=>s("data_field",u)})]}),o(Na,{label:"Aggregation",value:t.aggregation,onChange:u=>s("aggregation",u)}),o(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),o(Ot,{value:t.formatter,onChange:u=>s("formatter",u)}),i&&o(Xa,{value:t,onChange:n})]})});function Ja(e){const t=Array.from(e).sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function zt(e,t,n){var i,l,s,u;const r=e.map(d=>d[t]);switch(n.type){case"sum":return z.default.sum(r);case"mean":return z.default.mean(r);case"median":return Ja(r);case"max":return(i=z.default.max(r))!=null?i:0;case"min":return(l=z.default.min(r))!=null?l:0;case"quantile":return(s=to.quantile(r,n.config.p))!=null?s:0;default:return(u=e[0])==null?void 0:u[t]}}var gr=function(){},We=function(){};process.env.NODE_ENV!=="production"&&(gr=function(e,t){!e&&typeof console<"u"&&console.warn(t)},We=function(e,t){if(!e)throw new Error(t)});const Ka=(e,t,n)=>Math.min(Math.max(n,e),t),pr=(e,t,n)=>{const r=t-e;return r===0?1:(n-e)/r},Gt=(e,t,n)=>-n*e+n*t+e,fr=(e,t)=>n=>Math.max(Math.min(n,t),e),Ue=e=>e%1?Number(e.toFixed(5)):e,it=/(-)?([\d]*\.?[\d])+/g,Lt=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,Za=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function Qe(e){return typeof e=="string"}const ot={test:e=>typeof e=="number",parse:parseFloat,transform:e=>e},hr=Object.assign(Object.assign({},ot),{transform:fr(0,1)});Object.assign(Object.assign({},ot),{default:1});const He=(e=>({test:t=>Qe(t)&&t.endsWith(e)&&t.split(" ").length===1,parse:parseFloat,transform:t=>`${t}${e}`}))("%");Object.assign(Object.assign({},He),{parse:e=>He.parse(e)/100,transform:e=>He.transform(e*100)});const Nt=(e,t)=>n=>Boolean(Qe(n)&&Za.test(n)&&n.startsWith(e)||t&&Object.prototype.hasOwnProperty.call(n,t)),mr=(e,t,n)=>r=>{if(!Qe(r))return r;const[i,l,s,u]=r.match(it);return{[e]:parseFloat(i),[t]:parseFloat(l),[n]:parseFloat(s),alpha:u!==void 0?parseFloat(u):1}},Pe={test:Nt("hsl","hue"),parse:mr("hue","saturation","lightness"),transform:({hue:e,saturation:t,lightness:n,alpha:r=1})=>"hsla("+Math.round(e)+", "+He.transform(Ue(t))+", "+He.transform(Ue(n))+", "+Ue(hr.transform(r))+")"},el=fr(0,255),qt=Object.assign(Object.assign({},ot),{transform:e=>Math.round(el(e))}),Ae={test:Nt("rgb","red"),parse:mr("red","green","blue"),transform:({red:e,green:t,blue:n,alpha:r=1})=>"rgba("+qt.transform(e)+", "+qt.transform(t)+", "+qt.transform(n)+", "+Ue(hr.transform(r))+")"};function tl(e){let t="",n="",r="",i="";return e.length>5?(t=e.substr(1,2),n=e.substr(3,2),r=e.substr(5,2),i=e.substr(7,2)):(t=e.substr(1,1),n=e.substr(2,1),r=e.substr(3,1),i=e.substr(4,1),t+=t,n+=n,r+=r,i+=i),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(r,16),alpha:i?parseInt(i,16)/255:1}}const Bt={test:Nt("#"),parse:tl,transform:Ae.transform},at={test:e=>Ae.test(e)||Bt.test(e)||Pe.test(e),parse:e=>Ae.test(e)?Ae.parse(e):Pe.test(e)?Pe.parse(e):Bt.parse(e),transform:e=>Qe(e)?e:e.hasOwnProperty("red")?Ae.transform(e):Pe.transform(e)},vr="${c}",yr="${n}";function nl(e){var t,n,r,i;return isNaN(e)&&Qe(e)&&((n=(t=e.match(it))===null||t===void 0?void 0:t.length)!==null&&n!==void 0?n:0)+((i=(r=e.match(Lt))===null||r===void 0?void 0:r.length)!==null&&i!==void 0?i:0)>0}function br(e){typeof e=="number"&&(e=`${e}`);const t=[];let n=0;const r=e.match(Lt);r&&(n=r.length,e=e.replace(Lt,vr),t.push(...r.map(at.parse)));const i=e.match(it);return i&&(e=e.replace(it,yr),t.push(...i.map(ot.parse))),{values:t,numColors:n,tokenised:e}}function Cr(e){return br(e).values}function xr(e){const{values:t,numColors:n,tokenised:r}=br(e),i=t.length;return l=>{let s=r;for(let u=0;u<i;u++)s=s.replace(u<n?vr:yr,u<n?at.transform(l[u]):Ue(l[u]));return s}}const rl=e=>typeof e=="number"?0:e;function il(e){const t=Cr(e);return xr(e)(t.map(rl))}const Sr={test:nl,parse:Cr,createTransformer:xr,getAnimatableNone:il};function jt(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function wr({hue:e,saturation:t,lightness:n,alpha:r}){e/=360,t/=100,n/=100;let i=0,l=0,s=0;if(!t)i=l=s=n;else{const u=n<.5?n*(1+t):n+t-n*t,d=2*n-u;i=jt(d,u,e+1/3),l=jt(d,u,e),s=jt(d,u,e-1/3)}return{red:Math.round(i*255),green:Math.round(l*255),blue:Math.round(s*255),alpha:r}}const ol=(e,t,n)=>{const r=e*e,i=t*t;return Math.sqrt(Math.max(0,n*(i-r)+r))},al=[Bt,Ae,Pe],_r=e=>al.find(t=>t.test(e)),Ir=e=>`'${e}' is not an animatable color. Use the equivalent color code instead.`,Dr=(e,t)=>{let n=_r(e),r=_r(t);We(!!n,Ir(e)),We(!!r,Ir(t));let i=n.parse(e),l=r.parse(t);n===Pe&&(i=wr(i),n=Ae),r===Pe&&(l=wr(l),r=Ae);const s=Object.assign({},i);return u=>{for(const d in s)d!=="alpha"&&(s[d]=ol(i[d],l[d],u));return s.alpha=Gt(i.alpha,l.alpha,u),n.transform(s)}},ll=e=>typeof e=="number",sl=(e,t)=>n=>t(e(n)),Ar=(...e)=>e.reduce(sl);function Mr(e,t){return ll(e)?n=>Gt(e,t,n):at.test(e)?Dr(e,t):Rr(e,t)}const Vr=(e,t)=>{const n=[...e],r=n.length,i=e.map((l,s)=>Mr(l,t[s]));return l=>{for(let s=0;s<r;s++)n[s]=i[s](l);return n}},ul=(e,t)=>{const n=Object.assign(Object.assign({},e),t),r={};for(const i in n)e[i]!==void 0&&t[i]!==void 0&&(r[i]=Mr(e[i],t[i]));return i=>{for(const l in r)n[l]=r[l](i);return n}};function Er(e){const t=Sr.parse(e),n=t.length;let r=0,i=0,l=0;for(let s=0;s<n;s++)r||typeof t[s]=="number"?r++:t[s].hue!==void 0?l++:i++;return{parsed:t,numNumbers:r,numRGB:i,numHSL:l}}const Rr=(e,t)=>{const n=Sr.createTransformer(t),r=Er(e),i=Er(t);return r.numHSL===i.numHSL&&r.numRGB===i.numRGB&&r.numNumbers>=i.numNumbers?Ar(Vr(r.parsed,i.parsed),n):(gr(!0,`Complex values '${e}' and '${t}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`),s=>`${s>0?t:e}`)},dl=(e,t)=>n=>Gt(e,t,n);function cl(e){if(typeof e=="number")return dl;if(typeof e=="string")return at.test(e)?Dr:Rr;if(Array.isArray(e))return Vr;if(typeof e=="object")return ul}function gl(e,t,n){const r=[],i=n||cl(e[0]),l=e.length-1;for(let s=0;s<l;s++){let u=i(e[s],e[s+1]);if(t){const d=Array.isArray(t)?t[s]:t;u=Ar(d,u)}r.push(u)}return r}function pl([e,t],[n]){return r=>n(pr(e,t,r))}function fl(e,t){const n=e.length,r=n-1;return i=>{let l=0,s=!1;if(i<=e[0]?s=!0:i>=e[r]&&(l=r-1,s=!0),!s){let d=1;for(;d<n&&!(e[d]>i||d===r);d++);l=d-1}const u=pr(e[l],e[l+1],i);return t[l](u)}}function hl(e,t,{clamp:n=!0,ease:r,mixer:i}={}){const l=e.length;We(l===t.length,"Both input and output ranges must be the same length"),We(!r||!Array.isArray(r)||r.length===l-1,"Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values."),e[0]>e[l-1]&&(e=[].concat(e),t=[].concat(t),e.reverse(),t.reverse());const s=gl(t,r,i),u=l===2?pl(e,s):fl(e,s);return n?d=>u(Ka(e[0],e[l-1],d)):u}class ml{constructor({valueRange:t,colorRange:n}){$(this,"mapper");this.mapper=hl(t,n)}getColor(t){return this.mapper(t)}}function vl(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function Tr({data_field:e,aggregation:t},n){return zt(n,e,t)}function lt({formatter:e},t){return["string","number"].includes(typeof t)?ae.default(t).format(e):vl(t)}function yl(e,t){return e.type==="static"?e.staticColor:e.type==="continuous"?new ml(e).getColor(t):"black"}function bl(e,t){const n={};return e.forEach(r=>{const{name:i,color:l,data_field:s,aggregation:u,size:d,weight:p}=r,c=zt(t,s,u),f=lt(r,c);n[i]=o(a.Text,{sx:{fontSize:d,display:"inline"},color:yl(l,c),weight:p,children:f})}),n}function Cl(e){return e.split(" ").map(t=>g(U,{children:[t,"\xA0"]}))}function xl(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
39
+ `,Hn=E.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=Y(),i=r.context.current,l=C.default.useMemo(()=>{const s={context:i,filters:r.filters.values};if(t){const u=r.sqlSnippets.current.reduce((d,p)=>(d[p.key]=p.value,d),{});s.sql_snippets=u}return JSON.stringify(s,null,2)},[i,r.sqlSnippets.current,r.filters.values,t]);return g(a.Stack,{sx:{border:"1px solid #eee",maxWidth:"40%",overflow:"hidden",...n},children:[o(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:o(a.Text,{weight:500,children:"Global Variables"})}),g(a.Stack,{px:"md",pb:"md",sx:{width:"100%"},children:[o(Fe.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:_o}),o(a.Text,{weight:500,sx:{flexGrow:0},children:"Current Values"}),o(Fe.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})]})]})});function Io({data:e}){return e.length===0?o(a.Box,{sx:{height:"5em"}}):g(a.Table,{children:[o("thead",{children:o("tr",{children:Object.keys(e==null?void 0:e[0]).map(t=>o("th",{children:o(a.Text,{weight:700,color:"#000",children:t})},t))})}),o("tbody",{children:e.slice(0,10).map((t,n)=>o("tr",{children:Object.values(t).map((r,i)=>o("td",{children:o(a.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:o(a.Text,{children:r})})},`${r}--${i}`))},`row-${n}`))})]})}const Yn=E.observer(function({id:t}){const n=Y(),{data:r,state:i}=n.getDataStuffByID(t),l=i==="loading",s=()=>{n.queries.refetchDataByQueryID(t)};return g(a.Stack,{my:"xl",sx:{border:"1px solid #eee"},children:[g(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[g(a.Group,{position:"left",children:[o(a.Text,{weight:500,children:"Preview Data"}),r.length>10&&g(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",r.length]})]}),o(a.ActionIcon,{mr:15,variant:"subtle",color:"blue",disabled:l,onClick:s,children:o(V.Refresh,{size:15})})]}),g(a.Box,{sx:{position:"relative"},children:[o(a.LoadingOverlay,{visible:l}),o(Io,{data:r})]})]})}),Do=w.forwardRef(({label:e,type:t,...n},r)=>g(a.Group,{position:"apart",ref:r,...n,children:[o(a.Text,{children:e}),o(a.Text,{children:t})]})),Xn=E.observer(function({value:t,onChange:n}){const{data:r=[],loading:i}=j.useRequest(yo,{refreshDeps:[]},[]),l=w.useMemo(()=>r.map(u=>({label:u.key,value:u.key,type:u.type})),[r]),s=w.useMemo(()=>l.reduce((u,d)=>(u[d.value]=d.type,u),{}),[l]);return o(a.Select,{label:"Data Source",data:l,itemComponent:Do,sx:{flex:1},disabled:i,value:t.key,onChange:u=>{u!==null&&n({key:u,type:s[u]})}})});function Jn({value:e}){const t=Y(),n=t.context.current,r=C.default.useMemo(()=>Bn(e,n,t.sqlSnippets.current,t.filters.values),[e,n,t.sqlSnippets.current,t.filters.values]);return o(Fe.Prism,{language:"sql",colorScheme:"light",children:r})}const Ao=E.observer(function({queryModel:t,setCurrentID:n}){const r=C.default.useRef(t.id),[i,l]=C.default.useState(r.current);C.default.useEffect(()=>{r.current!==t.id&&(l(t.id),r.current=t.id)},[r,t.id]);const[s,u]=C.default.useState(t.sql);C.default.useEffect(()=>{u(f=>f!==t.sql?t.sql:f)},[t.sql]);const d=s!==t.sql,p=()=>{t.setSQL(s)},c=()=>{n(i),t.setID(i)};return g(a.Stack,{sx:{border:"1px solid #eee",flexGrow:1},children:[o(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:o(a.Text,{weight:500,children:"Edit Query"})}),g(a.Stack,{my:0,p:"md",pr:40,children:[g(a.Group,{grow:!0,children:[o(a.TextInput,{placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},value:i,onChange:f=>{l(f.currentTarget.value)},rightSection:o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:i===t.id,onClick:c,children:o(V.DeviceFloppy,{size:18})})}),o(Xn,{value:{type:t.type,key:t.key},onChange:({type:f,key:m})=>{t.setKey(m),t.setType(f)}})]}),g(a.Tabs,{defaultValue:"SQL",children:[g(a.Tabs.List,{children:[o(a.Tabs.Tab,{value:"SQL",children:"SQL"}),o(a.Tabs.Tab,{value:"Preview",children:"Preview"})]}),o(a.Tabs.Panel,{value:"SQL",pt:"sm",children:g(a.Box,{sx:{position:"relative"},children:[o(a.Textarea,{autosize:!0,minRows:12,maxRows:24,className:"code-textarea",value:s,onChange:f=>{u(f.currentTarget.value)}}),o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:10,top:10},disabled:!d,onClick:p,children:o(V.DeviceFloppy,{size:20})})]})}),o(a.Tabs.Panel,{value:"Preview",pt:"sm",children:o(Jn,{value:t.sql})})]})]})]})}),Mo=E.observer(function({id:t,setID:n}){const r=Y(),i=C.default.useMemo(()=>r.queries.findByID(t),[r.queries,t]);return t?i?o(Ao,{queryModel:i,setCurrentID:n}):o("span",{children:"Invalid Query ID"}):null});var me=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(me||{});const Vo=E.observer(function({id:t,setID:n}){const r=Y(),i=()=>{var s;n((s=r.queries.firstID)!=null?s:"")};C.default.useEffect(()=>{if(!t){i();return}r.queries.current.findIndex(u=>u.id===t)===-1&&i()},[t,r.queries.current,i]);const l=()=>{const s=J.randomId();r.queries.append(y.cast({id:s,type:me.Postgresql,key:"",sql:""})),n(s)};return o(a.Group,{pb:"xl",children:g(a.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[o(a.Text,{children:"Select a Query"}),o(a.Select,{data:r.queries.options,value:t,onChange:n,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}}),o(a.Text,{children:"or"}),o(a.Group,{position:"center",mt:"md",children:o(a.Button,{onClick:l,children:"Add a Query"})})]})})}),Eo=E.observer(function(){const[t,n]=C.default.useState("");return g(a.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 225px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:[g(a.Group,{position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[g(a.Stack,{sx:{flexGrow:1,maxWidth:"calc(60% - 16px)"},children:[o(Vo,{id:t,setID:n}),o(Mo,{id:t,setID:n})]}),o(Hn,{})]}),o(Yn,{id:t})]})}),Ro=E.observer(({value:e})=>{const t=Y(),n=t.context.current,r=C.default.useMemo(()=>mo(e,n,t.filters.values),[e,n]);return g(a.Stack,{children:[o(a.Text,{children:"Preview"}),o(Fe.Prism,{language:"sql",noCopy:!0,colorScheme:"dark",children:r})]})}),To=E.observer(function(){const t=Y(),n=()=>t.sqlSnippets.append(y.cast({key:J.randomId(),value:""}));return g(a.Stack,{sx:{border:"1px solid #eee",flexGrow:1},children:[o(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:o(a.Text,{weight:500,children:"SQL Snippets"})}),o(a.Group,{px:"md",pb:"md",pt:"md",children:g(a.Stack,{sx:{width:"100%",position:"relative"},children:[t.sqlSnippets.current.map((r,i)=>g(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[o(a.TextInput,{label:"Key",required:!0,value:r.key,onChange:l=>{r.setKey(l.currentTarget.value)}}),o(a.Textarea,{minRows:3,label:"Value",required:!0,value:r.value,onChange:l=>{r.setValue(l.currentTarget.value)},className:"code-textarea"}),o(Ro,{value:r.value}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.sqlSnippets.remove(i),sx:{position:"absolute",top:15,right:5},children:o(V.Trash,{size:16})})]},i)),o(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"40%"},mx:"auto",children:o(a.Button,{variant:"default",onClick:n,children:"Add a snippet"})})]})})]})});function Fo(){return o(a.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 225px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:g(a.Group,{position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[o(To,{}),o(Hn,{showSQLSnippets:!1})]})})}const $o=E.observer(function({opened:t,close:n}){const{freezeLayout:r}=C.default.useContext(le);return C.default.useEffect(()=>{r(t)},[t]),o(a.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:"Data Settings",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},children:g(a.Tabs,{defaultValue:"Queries",children:[g(a.Tabs.List,{children:[o(a.Tabs.Tab,{value:"SQL Snippet",children:"SQL Snippet"}),o(a.Tabs.Tab,{value:"Queries",children:"Queries"})]}),o(a.Tabs.Panel,{value:"SQL Snippet",pt:"sm",children:o(Fo,{})}),o(a.Tabs.Panel,{value:"Queries",pt:"sm",children:o(Eo,{})})]})})});var se=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(se||{});const Kn=y.types.model({type:y.types.enumeration("DataSourceType",[me.Postgresql,me.MySQL,me.HTTP]),key:y.types.string,sql:y.types.string}),Zn=y.types.model("FilterConfigModel_TextInput",{required:y.types.boolean,default_value:y.types.string}).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),er=()=>Zn.create({required:!1,default_value:""}),Po=E.observer(function({config:t}){return o(U,{children:o(a.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"})})}),ko=[{label:"2022",value:"YYYY"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Oo=E.observer(function({config:t}){return g(U,{children:[g(a.Group,{children:[o(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),o(a.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),label:"Clearable"})]}),o(a.Select,{data:ko,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),o(qn,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue})]})});function zo({data:e}){return e.length===0?o(a.Box,{sx:{height:"5em"}}):g(a.Table,{children:[o("thead",{children:o("tr",{children:Object.keys(e==null?void 0:e[0]).map(t=>o("th",{children:o(a.Text,{weight:700,color:"#000",children:t})},t))})}),o("tbody",{children:e.slice(0,3).map((t,n)=>o("tr",{children:Object.values(t).map((r,i)=>o("td",{children:o(a.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:o(a.Text,{children:r})})},`${r}--${i}`))},`row-${n}`))}),e.length>3&&o("tfoot",{children:o("tr",{children:o("td",{colSpan:Object.keys(e==null?void 0:e[0]).length,children:g(a.Text,{color:"gray",size:"sm",children:[e.length-3," more row(s) hidden"]})})})})]})}const Go=E.observer(function({query:t}){const{data:n=[],loading:r,refresh:i}=j.useRequest(Tt(t),{refreshDeps:[t]});return g(a.Stack,{my:0,children:[g(a.Group,{position:"apart",children:[o(a.Text,{size:"md",pl:"sm",children:"Fetched Data"}),o(a.Button,{size:"xs",onClick:i,disabled:!t.sql||!t.key,children:"Retry"})]}),g(a.Box,{sx:{position:"relative"},children:[o(a.LoadingOverlay,{visible:r,exitTransitionDuration:0}),o(zo,{data:n})]})]})}),tr=E.observer(function({value:t,onChange:n}){return g(a.Stack,{my:0,children:[o(Xn,{value:t,onChange:({type:r,key:i})=>{n({...t,type:r,key:i})}}),g(a.Tabs,{defaultValue:"SQL",children:[g(a.Tabs.List,{children:[o(a.Tabs.Tab,{value:"SQL",children:"SQL"}),o(a.Tabs.Tab,{value:"Preview",children:"Preview"}),o(a.Tabs.Tab,{value:"Data",children:"Data"})]}),o(a.Tabs.Panel,{value:"SQL",pt:"sm",children:o(a.Textarea,{autosize:!0,minRows:12,maxRows:24,className:"code-textarea",value:t.sql,onChange:r=>{n({...t,sql:r.currentTarget.value})},placeholder:"SELECT name AS label, id AS value"})}),o(a.Tabs.Panel,{value:"Preview",pt:"sm",children:o(Jn,{value:t.sql})}),o(a.Tabs.Panel,{value:"Data",pt:"sm",children:o(Go,{query:t})})]})]})}),Lo=E.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,i=[...r];return g(U,{children:[o(a.Divider,{label:"Configure options",labelPosition:"center"}),r.length>0&&o(a.MultiSelect,{label:"Default Selection",data:i,value:t.default_value,onChange:t.setDefaultValue}),r.map((l,s)=>g(a.Group,{sx:{position:"relative"},pr:"40px",children:[o(a.TextInput,{label:"Label",required:!0,value:t.static_options[s].label,onChange:u=>{t.static_options[s].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.TextInput,{label:"Value",required:!0,value:t.static_options[s].value,onChange:u=>{t.static_options[s].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(s),sx:{position:"absolute",top:28,right:5},children:o(V.Trash,{size:16})})]})),o(a.Button,{size:"xs",color:"blue",leftIcon:o(V.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"}),o(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),o(tr,{value:t.options_query,onChange:t.setOptionsQuery})]})}),No=E.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,i=[{label:"No default selection",value:""},...r];return g(U,{children:[o(a.Checkbox,{checked:t.required,onChange:l=>t.setRequired(l.currentTarget.checked),label:"Required"}),o(a.Divider,{label:"Configure options",labelPosition:"center"}),r.length>0&&o(a.Select,{label:"Default Selection",data:i,value:t.default_value,onChange:t.setDefaultValue}),r.map((l,s)=>g(a.Group,{sx:{position:"relative"},pr:"40px",children:[o(a.TextInput,{label:"Label",required:!0,value:t.static_options[s].label,onChange:u=>{t.static_options[s].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.TextInput,{label:"Value",required:!0,value:t.static_options[s].value,onChange:u=>{t.static_options[s].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(s),sx:{position:"absolute",top:28,right:5},children:o(V.Trash,{size:16})})]},s)),o(a.Button,{size:"xs",color:"blue",leftIcon:o(V.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"}),o(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),o(tr,{value:t.options_query,onChange:t.setOptionsQuery})]})}),qo=E.observer(function({config:t}){return g(U,{children:[o(a.TextInput,{label:"Default Value",value:t.default_value,onChange:n=>{t.setDefaultValue(n.currentTarget.value)}}),o(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"})]})}),Bo=E.observer(function({filter:t}){const n=t.plainDefaultValue,[r,i]=C.default.useState(n);return C.default.useEffect(()=>{i(n)},[n]),g(a.Box,{sx:{maxWidth:"30em"},children:[o(a.Text,{pb:"md",color:"gray",children:"Preview"}),o(jn,{filter:t,value:r,onChange:i}),o(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),o(Fe.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),jo={select:No,"multi-select":Lo,"text-input":qo,checkbox:Po,"date-range":Oo},Wo=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],Uo=E.observer(function({filter:t,index:n}){const r=Y(),i=C.default.useMemo(()=>jo[t.type],[t.type]);return g(a.SimpleGrid,{cols:2,children:[g(a.Box,{pl:"md",children:[o(a.Text,{pb:"md",color:"gray",children:"Edit"}),g(a.Stack,{sx:{maxWidth:"30em"},children:[o(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0}),o(a.MultiSelect,{label:"Visible in...",data:r.views.options,value:t.visibleInViewsIDs,onChange:t.setVisibleInViewsIDs}),o(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:l=>{t.setKey(l.currentTarget.value)}}),o(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:l=>{t.setLabel(l.currentTarget.value)}}),o(a.Select,{label:"Widget",data:Wo,required:!0,value:t.type,onChange:t.setType}),o(i,{config:t.config,index:n})]})]}),o(Bo,{filter:t})]})}),vg="",Qo=E.observer(function(){const t=Y(),n=t.filters.current,r=()=>{const i=J.randomId(),l={id:i,key:i,label:i,order:n.length+1,type:se.TextInput,config:er(),visibleInViewsIDs:["Main"]};t.filters.append(l)};return g(a.Box,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)"},p:0,children:[o(a.Group,{sx:{position:"absolute",top:"16px",right:"16px"},children:o(a.Button,{size:"xs",color:"red",leftIcon:o(V.Recycle,{size:20}),disabled:!t.filters.changed,onClick:t.filters.reset,children:"Revert Changes"})}),o(a.Tabs,{className:"filter-settings-tabs",orientation:"vertical",defaultValue:t.filters.firstID,styles:{root:{display:"block"}},children:g(a.Group,{sx:{height:"100%"},children:[g(a.Stack,{sx:{height:"100%"},children:[o(a.Tabs.List,{position:"left",sx:{flexGrow:1,width:"200px"},children:t.filters.current.map(i=>o(a.Tabs.Tab,{value:i.id,children:i.label},i.id))}),o(a.Button,{size:"xs",color:"blue",leftIcon:o(V.PlaylistAdd,{size:20}),onClick:r,children:"Add a Filter"})]}),o(a.Box,{sx:{flexGrow:1,height:"100%"},children:t.filters.current.map((i,l)=>o(a.Tabs.Panel,{value:i.id,sx:{height:"100%"},children:g(a.Stack,{sx:{height:"100%"},spacing:"sm",children:[o(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"scroll"},children:o(Uo,{filter:i,index:l})}),o(a.Group,{position:"right",pt:10,children:o(a.Button,{size:"xs",color:"red",leftIcon:o(V.Trash,{size:20}),onClick:()=>t.filters.remove(l),children:"Delete this filter"})})]})},i.id))})]})})]})}),Ho=E.observer(function({opened:t,close:n}){const{freezeLayout:r}=C.default.useContext(le);return C.default.useEffect(()=>{r(t)},[t]),o(a.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:"Filters",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},withCloseButton:!1,children:o(Qo,{})})});var nr=(e=>(e.Use="use",e.Edit="edit",e))(nr||{}),ve=(e=>(e.Division="div",e.Modal="modal",e))(ve||{}),rr=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(rr||{});const Yo=E.observer(()=>{const t=Y().views.VIE;return!t||t.type!==ve.Division?null:g(a.Stack,{children:[o(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),o(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})}),Xo=E.observer(()=>{const t=Y().views.VIE;return!t||t.type!==ve.Modal?null:g(a.Stack,{children:[o(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),g(a.Group,{grow:!0,children:[o(a.TextInput,{label:"Width",value:t.config.width,onChange:n=>t.updateConfig("width",n.currentTarget.value),placeholder:"600px / 50vw"}),o(a.TextInput,{label:"Height",value:t.config.height,onChange:n=>t.updateConfig("height",n.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),Jo=E.observer(()=>g(U,{children:[o(Yo,{}),o(Xo,{})]})),Ko=[{label:"Division",value:ve.Division},{label:"Modal",value:ve.Modal}],Zo=E.observer(()=>{const t=Y().views.VIE;return t?g(a.Stack,{sx:{position:"relative"},children:[o(a.TextInput,{label:"Name",value:t.name,onChange:n=>{t.setName(n.currentTarget.value)}}),o(a.Select,{label:"Type",value:t.type,onChange:t.setType,data:Ko}),o(Jo,{})]}):null}),ea=E.observer(({opened:e,close:t})=>{var i;const n=Y(),{freezeLayout:r}=C.default.useContext(le);return C.default.useEffect(()=>{r(e)},[e]),o(a.Modal,{size:"500px",overflow:"inside",opened:e,onClose:t,withCloseButton:!1,styles:{header:{width:"100%"},title:{width:"100%"}},title:g(a.Group,{position:"apart",children:[g(a.Text,{sx:{flexGrow:1},children:["Editing ",(i=n.views.VIE)==null?void 0:i.name]}),o(a.ActionIcon,{size:18,color:"red",onClick:n.views.removeVIE,disabled:n.views.isVIETheFirstView,children:o(V.Trash,{size:18})})]}),trapFocus:!0,onDragStart:l=>{l.stopPropagation()},children:o(Zo,{})})}),ta=w.forwardRef(({label:e,type:t,...n},r)=>t!=="TRIGGER_TO_ADD"?o("div",{ref:r,...n,children:g(a.Group,{noWrap:!0,position:"apart",children:[o(a.Text,{size:"sm",children:e}),o(a.Text,{size:"xs",color:"dimmed",children:t})]})}):o("div",{ref:r,...n,children:o(a.Group,{noWrap:!0,grow:!0,children:o(a.Text,{size:"sm",align:"center",color:"#228be6",children:e})})})),ir="TRIGGER_TO_ADD",na=E.observer(({value:e,onChange:t,triggerAdd:n,triggerEdit:r,options:i})=>{const l=w.useMemo(()=>[...i,{label:"Add a View",value:ir,type:"TRIGGER_TO_ADD"}],[i,n]),s=u=>{u!==ir?t(u):n()};return g(a.Group,{position:"left",spacing:0,sx:{minWidth:"260px"},children:[o(a.Select,{value:e,onChange:s,placeholder:"Pick a View",itemComponent:ta,data:l,nothingFound:"Empty",sx:{flexGrow:1},styles:{input:{borderTopRightRadius:0,borderBottomRightRadius:0}}}),o(a.ActionIcon,{onClick:r,variant:"default",size:36,sx:{borderLeft:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,"&:active":{transform:"none",svg:{transform:"translateY(1px)"}}},children:o(V.Settings,{size:20})})]})}),ra=E.observer(()=>{const e=Y(),[t,n]=w.useState(!1),r=()=>{n(!0)},i=()=>{n(!1)};return g(U,{children:[o(na,{value:e.views.idOfVIE,onChange:e.views.setIDOfVIE,triggerAdd:e.views.addARandomNewView,triggerEdit:r,options:e.views.options}),o(ea,{opened:t,close:i})]})});function ia({opened:e,close:t,getCurrentSchema:n}){const{freezeLayout:r}=C.default.useContext(le);C.default.useEffect(()=>{r(e)},[e]);const i=C.default.useMemo(()=>JSON.stringify(n(),null,2),[e]);return o(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"This dashboard is described by this schema",trapFocus:!0,onDragStart:l=>{l.stopPropagation()},children:e&&o(Fe.Prism,{language:"json",sx:{width:"100%"},colorScheme:"dark",children:i})})}const or=E.observer(function({saveChanges:t}){const n=Y(),r=C.default.useCallback(()=>{const N=n.queries.current,te=n.views.current,ye=n.sqlSnippets.current;return{filters:n.filters.current,views:te,definition:{sqlSnippets:ye,queries:N}}},[n]),i=()=>{n.filters.reset(),n.views.reset(),n.sqlSnippets.reset(),n.queries.reset()},l=n.views.changed||n.sqlSnippets.changed||n.queries.changed||n.filters.changed,{inEditMode:s,inUseMode:u}=C.default.useContext(le),[d,p]=C.default.useState(!1),c=()=>p(!0),f=()=>p(!1),[m,v]=C.default.useState(!1),b=()=>v(!0),I=()=>v(!1),[A,T]=C.default.useState(!1),k=()=>T(!0),B=()=>T(!1);return g(a.Group,{position:"apart",pt:0,px:10,pb:"xs",children:[o(a.Group,{position:"left",children:s&&o(ra,{})}),g(a.Group,{position:"right",children:[!u&&o(a.Button,{variant:"default",size:"xs",disabled:!n.views.VIE,onClick:n.views.addAPanelToVIE,leftIcon:o(V.PlaylistAdd,{size:20}),children:"Add a Panel"}),s&&o(a.Button,{variant:"default",size:"xs",onClick:b,leftIcon:o(V.Filter,{size:20}),children:"Filters"}),s&&o(a.Button,{variant:"default",size:"xs",onClick:c,leftIcon:o(V.Database,{size:20}),children:"Data Settings"}),!u&&o(a.Button,{variant:"default",size:"xs",onClick:t,disabled:!l,leftIcon:o(V.DeviceFloppy,{size:20}),children:"Save Changes"}),!u&&o(a.Button,{color:"red",size:"xs",disabled:!l,onClick:i,leftIcon:o(V.Recycle,{size:20}),children:"Revert Changes"}),!u&&g(a.Menu,{width:180,children:[o(a.Menu.Target,{children:o(a.Button,{variant:"default",size:"xs",leftIcon:o(V.Share,{size:20}),children:"Export"})}),g(a.Menu.Dropdown,{children:[o(a.Menu.Item,{icon:o(V.Download,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),o(a.Menu.Item,{icon:o(V.Code,{size:14}),onClick:k,children:"View Schema"})]})]})]}),o(Ho,{opened:m,close:I}),o($o,{opened:d,close:f}),o(ia,{opened:A,close:B,getCurrentSchema:r})]})}),yg="",ar=E.observer(()=>{const{freezeLayout:e}=C.default.useContext(le),[t,n]=C.default.useState(!1),{panel:r}=ee();return C.default.useEffect(()=>{e(t)},[t]),!r.description||r.description==="<p><br></p>"?null:g(U,{children:[o(a.Modal,{opened:t,onClose:()=>n(!1),title:r.title,withCloseButton:!1,children:o(kn.default,{readOnly:!0,value:r.description,onChange:z.default.noop,sx:{border:"none"}})}),o(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:o(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:o(V.InfoCircle,{size:20})})})]})}),lr=e=>{const{title:t="Variables",variables:n}=e,r=J.useClipboard(),i=l=>{r.copy(l),_t.showNotification({color:"green",message:"Copied to clipboard"})};return g(a.Paper,{withBorder:!0,p:"sm",children:[o(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),o(a.Stack,{style:{maxHeight:"300px"},children:n.map(l=>g(a.Text,{size:"sm",children:[g(a.Code,{color:"teal",children:["// ",l.description]}),o("br",{}),g(a.Code,{onClick:()=>i(l.name),style:{cursor:"pointer"},children:[l.name," : ",l.valueType]})]},l.name))})]})};class oa{constructor(t,n){$(this,"operationId");$(this,"operation");$(this,"operationSchema");$(this,"variables",[]);this.operationManager=t,this.instance=n,K.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),i=this.operationManager.getOperationSchemaList().find(l=>l.id===(r==null?void 0:r.schemaRef));K.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function aa(e){return!!e.operationId}const la=E.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return o(a.Button,{variant:"outline",onClick:t,children:n})}),sa=E.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return w.createElement(e.operationSchema.configRender,t)});function ua({model:e}){const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(l=>l.id===i))}return o(a.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id})}const da=E.observer(e=>{const[t,{setTrue:n,setFalse:r}]=j.useBoolean(!1),{operationManager:i,operationId:l,instance:s,variables:u}=e,d=j.useCreation(()=>new oa(i,s),[i,s]);return j.useAsyncEffect(async()=>{await d.configOperation(l,u)},[l,d]),aa(d)?g(U,{children:[o(la,{model:d,onClick:n}),o(a.Modal,{opened:t,onClose:r,title:"Operation Settings",closeButtonLabel:"close",children:g(a.Stack,{children:[o(ua,{model:d}),o(sa,{model:d}),o(lr,{title:"Variables",variables:d.variables})]})})]}):null});class ca{constructor(t,n){$(this,"triggerId");$(this,"trigger");$(this,"triggerSchema");$(this,"sampleData");this.triggerManager=t,this.instance=n,K.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),i=this.triggerManager.getTriggerSchemaList().find(l=>l.id===(r==null?void 0:r.schemaRef));K.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return ga(this)}}function ga(e){return!!e.triggerId&&!!e.triggerSchema}function pa(e,t){return j.useCreation(()=>new ca(e,t),[e,t])}const fa=E.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return o(a.Button,{variant:"outline",onClick:t,children:w.createElement(n,r)})}),ha=E.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(l=>l.id===i))}return o(a.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),ma=E.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return w.createElement(e.triggerSchema.configRender,t)}),va=E.observer(e=>{const[t,{setTrue:n,setFalse:r}]=j.useBoolean(!1),i=e.model;return g(U,{children:[o(a.Modal,{opened:t,onClose:r,title:"Setup Trigger",closeButtonLabel:"close setup",children:g(a.Stack,{children:[o(ha,{model:i}),o(ma,{model:i}),o(lr,{title:"Payload",variables:i.triggerSchema.payload})]})}),o(fa,{onClick:n,model:i})]})});class Oe{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,_.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:_.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(i,l)=>{n(i,l)},r):this.root.watchItem(this.path,(i,l)=>{const s=_.get(i,t),u=_.get(l,t);s!==u&&n(s,u)},r)}}class Ft{constructor(t,n,r){$(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Oe(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Oe(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Oe(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(_.values(t).map(n=>this.constructInstance(new Oe(this.attachmentStorage,n.id))))}}class sr{constructor(t){$(this,"rootRef");this.rootRef=K.observable({current:t})}async deleteItem(t){K.runInAction(()=>{_.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?K.toJS(this.rootRef.current):_.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(_.isObject(n))K.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else K.runInAction(()=>{_.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return K.reaction(()=>this.getValueFromRoot(t),(i,l)=>{n(i,l)},{requiresObservable:!0,fireImmediately:_.get(r,"fireImmediately",!1)})}}class ya{constructor(){$(this,"channels",new Map);$(this,"globalChannel",new On.default)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new On.default;return this.channels.set(t,r),r}}class ba{constructor(t){$(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new ya,instanceData:new sr(t.viz.conf)};return this.instances.set(t.id,r),r}}function ur(e,t,n){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new sr({}),colorPalette:{getColor(){return()=>""}},data:t}}const Ca=e=>{const{panel:t,vizManager:n,data:r}=e,i=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),s={...ur(l,r,n),viewport:{width:t.layout.w,height:t.layout.h}},u=i.viewRender;return o(u,{context:s,instance:l,..._.omit(e,["panel","vizManager","data"])})},xa=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:i}=e,l=t.resolveComponent(n.viz.type),s=t.getOrCreateInstance(n),u={...ur(s,i,t),panelInfoEditor:r},d=l.configRender;return o(d,{context:u,instance:s,..._.omit(e,["panel","vizManager","data","panelInfoEditor"])})},dr=(e,t)=>{const n=Le.default.bezier(e),r=Le.default.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},et=e=>{const t=Le.default.bezier(e);return function(n){return t(n/100).hex()}},Sa={type:"interpolation",displayName:"Red / Green",getColor:dr(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},wa={type:"interpolation",displayName:"Yellow / Blue",getColor:dr(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},_a={type:"interpolation",displayName:"Red",getColor:et(["#fff7f1","darkred"]),name:"red",category:"sequential"},Ia={type:"interpolation",displayName:"Green",getColor:et(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Da={type:"interpolation",displayName:"Blue",getColor:et(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Aa={type:"interpolation",displayName:"Orange",getColor:et(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},Ma="4.19.0";class Va{constructor(t){$(this,"staticColors",new Map);$(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class Ea{constructor(){$(this,"plugins",new Map);$(this,"vizComponents",new Map);$(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ra{constructor(){$(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const r=this.migrations.filter(s=>s.version>t.from&&s.version<=t.to),i=_.orderBy(r,"version","asc");if(((l=_.last(i))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return i.reduce((s,u)=>u.handler(s),n)}}class ge extends Ra{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,r=>({version:t,...n(r)}))}async migrate({instanceData:t}){const n=await t.getItem(null),r=_.get(n,"version",0),i=this.run({from:r,to:this.VERSION},n);await t.setItem(null,i)}async needMigration({instanceData:t}){const n=await t.getItem(null);return _.get(n,"version",0)<this.VERSION}}const $t={content:""},L=(e,t)=>{const[n,{setFalse:r}]=j.useBoolean(!0),[i,l]=w.useState();w.useEffect(()=>(e.getItem(t).then(u=>{l(u),r()}),e.watchItem(t,u=>{l(u)})));const s=w.useCallback(async u=>{await e.setItem(t,u),l(u)},[e,t]);return{loading:n,value:i,set:s}};function cr(e){const t=w.useRef(null);return w.useEffect(()=>{var n,r,i;e&&((i=(r=(n=t.current)==null?void 0:n.editor)==null?void 0:r.clipboard)==null||i.dangerouslyPasteHTML(e))},[e]),t}function Ta({context:e}){const{panel:t}=ee(),{value:n}=L(e.instanceData,"config"),r=n==null?void 0:n.content,i=cr(r);return n!=null&&n.content?o(wt.RichTextEditor,{id:t.id,ref:i,readOnly:!0,value:n.content,onChange:_.noop,sx:{border:"none",".ql-editor":{padding:0,"h1, h2, h3, h4, h5, p, ul, ol":{"&:last-child":{marginBottom:0}}}}}):null}function Fa({context:e}){const{value:t,set:n}=L(e.instanceData,"config"),r=w.useMemo(()=>_.defaults({},t,$t),[t]),{control:i,handleSubmit:l,watch:s,getValues:u}=S.useForm({defaultValues:r});s("content");const d=u(),p=w.useMemo(()=>!_.isEqual(d,t),[d,t]),c=cr(t==null?void 0:t.content);return o(a.Stack,{mt:"md",spacing:"xs",children:g("form",{onSubmit:l(n),children:[g(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[o(a.Text,{children:"Content"}),o(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:o(V.DeviceFloppy,{size:20})})]}),o(S.Controller,{name:"content",control:i,render:({field:f})=>o(kn.default,{ref:c,sx:{flex:1},..._.omit(f,"ref")})})]})})}class $a extends ge{constructor(){super(...arguments);$(this,"VERSION",1)}fixMalformedConfig(n){return _.defaults({},n,$t)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Pa={displayName:"RichText",migrator:new $a,name:"richText",viewRender:Ta,configRender:Fa,createConfig:()=>$t},Pt={align:"center",template:"The variable ${value} is defined in Variables section",variables:[{name:"value",size:"20px",weight:"bold",color:{type:"static",staticColor:"blue"},data_field:"",aggregation:{type:"none",config:{}},formatter:{output:"number",mantissa:0}}]};function ka(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:i,content:{prefix:l="",data_field:s="value",formatter:u={output:"number",mantissa:0},postfix:d=""}={}}=e;return{align:t,template:`${l} \${value} ${d}`,variables:[{name:"value",data_field:s,aggregation:{type:"none",config:{}},formatter:u,color:i,weight:r,size:n}]}}class Oa extends ge{constructor(){super(...arguments);$(this,"VERSION",1)}configVersions(){this.version(1,n=>({config:ka(n)}))}}const kt=w.forwardRef(function({value:t,onChange:n,...r},i){return o(a.TextInput,{ref:i,value:t,onChange:n,...r})}),je={mantissa:0,output:"number",trimMantissa:!1,average:!1};function za({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},i=u=>{const d=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:d})},l=u=>{t({...e,trimMantissa:u.currentTarget.checked})},s=u=>{t({...e,average:u.currentTarget.checked})};return g(a.Stack,{ref:n,children:[g(a.Group,{grow:!0,children:[o(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),o(a.Switch,{label:g(a.Stack,{spacing:0,children:[o(a.Text,{children:"Average"}),o(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:s,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),g(a.Group,{grow:!0,children:[o(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),o(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:l,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),g(a.Stack,{spacing:0,children:[o(a.Text,{weight:"bold",children:"Preview"}),o(ke,{children:g(a.Group,{position:"apart",children:[g(a.Text,{size:12,color:"gray",children:["123456789 ",o(V.ArrowRight,{size:9})," ",ae.default(123456789).format(e)]}),g(a.Text,{size:12,color:"gray",children:["1234 ",o(V.ArrowRight,{size:9})," ",ae.default(1234).format(e)]}),g(a.Text,{size:12,color:"gray",children:["0.1234 ",o(V.ArrowRight,{size:9})," ",ae.default(.1234).format(e)]})]})})]})]})}const Ot=C.default.forwardRef(za);function tt(){return{name:J.randomId(),size:"20px",weight:"bold",color:{type:"static",staticColor:"blue"},data_field:"",aggregation:{type:"none",config:{}},formatter:je}}const Ga=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function La({label:e,value:t,onChange:n},r){w.useEffect(()=>{typeof t=="string"&&(console.log(t),n({type:t,config:{}}))},[t,n]);const i=s=>{n(s==="quantile"?{type:"quantile",config:{p:.99}}:{type:s,config:{}})},l=s=>{n({type:"quantile",config:{p:s}})};return g(a.Group,{grow:!0,noWrap:!0,pt:"sm",children:[o(a.Select,{ref:r,label:e,data:Ga,value:t.type,onChange:i}),t.type==="quantile"&&o(a.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Na=C.default.forwardRef(La);function qa({label:e,required:t,value:n,onChange:r,data:i,clearable:l=!1,sx:s,...u},d){const p=C.default.useMemo(()=>{if(!Array.isArray(i)||i.length===0)return[];const f=Object.keys(i[0]).map(m=>({label:m,value:m}));return l?f.concat([{label:"unset",value:""}]):f},[i]);return o(a.Select,{ref:d,label:e,data:p,value:n,onChange:r,required:t,sx:s,...u})}const Q=C.default.forwardRef(qa);function Ba({label:e,value:t,onChange:n},r){const[i,l]=C.default.useState(Array.isArray(t)?[...t]:[]),s=C.default.useCallback(()=>{l(m=>[...m,""])},[l]),u=C.default.useCallback(m=>{l(v=>(v.splice(m,1),[...v]))},[l]),d=C.default.useMemo(()=>!z.default.isEqual(i,t),[i,t]),p=()=>{n(i.map(m=>m.toString()))},c=a.useMantineTheme(),f=C.default.useMemo(()=>Object.entries(c.colors).map(([m,v])=>v[6]),[c]);return g(U,{children:[g(a.Group,{position:"left",ref:r,children:[o(a.Text,{children:e}),o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:o(V.DeviceFloppy,{size:20})})]}),g(a.Group,{children:[i.map((m,v)=>o(a.ColorInput,{value:m,onChange:b=>{l(I=>(I.splice(v,1,b),[...I]))},swatches:f,rightSection:o(a.ActionIcon,{onClick:()=>u(v),color:"red",children:o(V.Trash,{size:14})}),sx:{width:"45%"}})),o(a.ActionIcon,{onClick:s,color:"blue",variant:"outline",children:o(V.PlaylistAdd,{size:20})})]})]})}const ja=C.default.forwardRef(Ba);function Wa({value:e,onChange:t},n){const{colorManager:r}=w.useContext(xe),i=C.default.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),l=C.default.useMemo(()=>i.some(s=>s.value===e),[e,i]);return g(a.Group,{position:"apart",spacing:4,ref:n,children:[o(a.TextInput,{placeholder:"Set any color",value:l?"":e,onChange:s=>t(s.currentTarget.value),rightSection:o(a.ColorSwatch,{color:l?"transparent":e,radius:4}),variant:l?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),o(a.Text,{sx:{flexGrow:0},children:"or"}),o(a.Select,{data:i,value:e,onChange:t,variant:l?"default":"filled",placeholder:"Pick a theme color",icon:o(a.ColorSwatch,{color:l?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const De=C.default.forwardRef(Wa),nt=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Ua({label:e,value:t,onChange:n},r){var s,u;const[i,l]=C.default.useState((u=(s=nt.find(d=>d.label===t))==null?void 0:s.value)!=null?u:nt[0].value);return C.default.useEffect(()=>{const d=nt.find(p=>p.value===i);d&&n(d.label)},[i]),g(a.Stack,{spacing:0,mt:"sm",mb:"lg",children:[o(a.Text,{size:"sm",children:e}),o(a.Slider,{label:null,marks:nt,value:i,onChange:l,step:25,placeholder:"Pick a font size",ref:r})]})}const Qa=C.default.forwardRef(Ua);function Ha({label:e,value:t,onChange:n},r){const[i,l]=C.default.useState(Array.isArray(t)?[...t]:[]),s=C.default.useCallback(()=>{l(c=>[...c,""])},[l]),u=C.default.useCallback(c=>{l(f=>(f.splice(c,1),[...f]))},[l]),d=C.default.useMemo(()=>!z.default.isEqual(i,t),[i,t]),p=()=>{n(i.map(c=>c.toString()))};return g(U,{children:[g(a.Group,{position:"left",ref:r,children:[o(a.Text,{children:e}),o(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:o(V.DeviceFloppy,{size:20})})]}),g(a.Group,{children:[i.map((c,f)=>o(a.TextInput,{value:c,onChange:m=>{const v=m.currentTarget.value;l(b=>(b.splice(f,1,v),[...b]))},rightSection:o(a.ActionIcon,{onClick:()=>u(f),color:"red",children:o(V.Trash,{size:14})}),sx:{width:"45%"}})),o(a.ActionIcon,{onClick:s,color:"blue",variant:"outline",children:o(V.PlaylistAdd,{size:20})})]})]})}const Ya=C.default.forwardRef(Ha),Xa=C.default.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,l=(s,u)=>{const d=z.default.cloneDeep(t);z.default.set(d,s,u),n(d)};return g(U,{children:[o(a.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),o(a.Stack,{children:o(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:s=>l("size",s.currentTarget.value)})}),o(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:o(Qa,{label:"Font Weight",value:t.weight,onChange:s=>l("weight",s)})}),o(a.Divider,{my:"xs",label:"Style",labelPosition:"center"}),g(a.Stack,{children:[o(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:s=>l("color.type",s)}),i==="static"&&o(De,{value:t.color.staticColor,onChange:s=>l("color.staticColor",s)}),i==="continuous"&&g(U,{children:[o(Ya,{label:"Value Range",value:t.color.valueRange,onChange:s=>l("color.valueRange",s)}),o(ja,{label:"Color Range",value:t.color.colorRange,onChange:s=>l("color.colorRange",s)})]})]})]})}),rt=C.default.forwardRef(function({value:t,onChange:n,data:r,withStyle:i=!0},l){const s=(u,d)=>{const p=z.default.cloneDeep(t);z.default.set(p,u,d),n(p)};return g(a.Box,{px:"sm",py:"md",ref:l,children:[o(a.Text,{weight:"bold",pb:0,children:t.name}),o(a.Divider,{my:"xs",label:"Data",labelPosition:"center"}),g(a.Group,{grow:!0,noWrap:!0,children:[o(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>s("name",u.currentTarget.value)}),o(Q,{label:"Data Field",required:!0,data:r,value:t.data_field,onChange:u=>s("data_field",u)})]}),o(Na,{label:"Aggregation",value:t.aggregation,onChange:u=>s("aggregation",u)}),o(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),o(Ot,{value:t.formatter,onChange:u=>s("formatter",u)}),i&&o(Xa,{value:t,onChange:n})]})});function Ja(e){const t=Array.from(e).sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function zt(e,t,n){var i,l,s,u;const r=e.map(d=>d[t]);switch(n.type){case"sum":return z.default.sum(r);case"mean":return z.default.mean(r);case"median":return Ja(r);case"max":return(i=z.default.max(r))!=null?i:0;case"min":return(l=z.default.min(r))!=null?l:0;case"quantile":return(s=to.quantile(r,n.config.p))!=null?s:0;default:return(u=e[0])==null?void 0:u[t]}}var gr=function(){},We=function(){};process.env.NODE_ENV!=="production"&&(gr=function(e,t){!e&&typeof console<"u"&&console.warn(t)},We=function(e,t){if(!e)throw new Error(t)});const Ka=(e,t,n)=>Math.min(Math.max(n,e),t),pr=(e,t,n)=>{const r=t-e;return r===0?1:(n-e)/r},Gt=(e,t,n)=>-n*e+n*t+e,fr=(e,t)=>n=>Math.max(Math.min(n,t),e),Ue=e=>e%1?Number(e.toFixed(5)):e,it=/(-)?([\d]*\.?[\d])+/g,Lt=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,Za=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function Qe(e){return typeof e=="string"}const ot={test:e=>typeof e=="number",parse:parseFloat,transform:e=>e},hr=Object.assign(Object.assign({},ot),{transform:fr(0,1)});Object.assign(Object.assign({},ot),{default:1});const He=(e=>({test:t=>Qe(t)&&t.endsWith(e)&&t.split(" ").length===1,parse:parseFloat,transform:t=>`${t}${e}`}))("%");Object.assign(Object.assign({},He),{parse:e=>He.parse(e)/100,transform:e=>He.transform(e*100)});const Nt=(e,t)=>n=>Boolean(Qe(n)&&Za.test(n)&&n.startsWith(e)||t&&Object.prototype.hasOwnProperty.call(n,t)),mr=(e,t,n)=>r=>{if(!Qe(r))return r;const[i,l,s,u]=r.match(it);return{[e]:parseFloat(i),[t]:parseFloat(l),[n]:parseFloat(s),alpha:u!==void 0?parseFloat(u):1}},Pe={test:Nt("hsl","hue"),parse:mr("hue","saturation","lightness"),transform:({hue:e,saturation:t,lightness:n,alpha:r=1})=>"hsla("+Math.round(e)+", "+He.transform(Ue(t))+", "+He.transform(Ue(n))+", "+Ue(hr.transform(r))+")"},el=fr(0,255),qt=Object.assign(Object.assign({},ot),{transform:e=>Math.round(el(e))}),Ae={test:Nt("rgb","red"),parse:mr("red","green","blue"),transform:({red:e,green:t,blue:n,alpha:r=1})=>"rgba("+qt.transform(e)+", "+qt.transform(t)+", "+qt.transform(n)+", "+Ue(hr.transform(r))+")"};function tl(e){let t="",n="",r="",i="";return e.length>5?(t=e.substr(1,2),n=e.substr(3,2),r=e.substr(5,2),i=e.substr(7,2)):(t=e.substr(1,1),n=e.substr(2,1),r=e.substr(3,1),i=e.substr(4,1),t+=t,n+=n,r+=r,i+=i),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(r,16),alpha:i?parseInt(i,16)/255:1}}const Bt={test:Nt("#"),parse:tl,transform:Ae.transform},at={test:e=>Ae.test(e)||Bt.test(e)||Pe.test(e),parse:e=>Ae.test(e)?Ae.parse(e):Pe.test(e)?Pe.parse(e):Bt.parse(e),transform:e=>Qe(e)?e:e.hasOwnProperty("red")?Ae.transform(e):Pe.transform(e)},vr="${c}",yr="${n}";function nl(e){var t,n,r,i;return isNaN(e)&&Qe(e)&&((n=(t=e.match(it))===null||t===void 0?void 0:t.length)!==null&&n!==void 0?n:0)+((i=(r=e.match(Lt))===null||r===void 0?void 0:r.length)!==null&&i!==void 0?i:0)>0}function br(e){typeof e=="number"&&(e=`${e}`);const t=[];let n=0;const r=e.match(Lt);r&&(n=r.length,e=e.replace(Lt,vr),t.push(...r.map(at.parse)));const i=e.match(it);return i&&(e=e.replace(it,yr),t.push(...i.map(ot.parse))),{values:t,numColors:n,tokenised:e}}function Cr(e){return br(e).values}function xr(e){const{values:t,numColors:n,tokenised:r}=br(e),i=t.length;return l=>{let s=r;for(let u=0;u<i;u++)s=s.replace(u<n?vr:yr,u<n?at.transform(l[u]):Ue(l[u]));return s}}const rl=e=>typeof e=="number"?0:e;function il(e){const t=Cr(e);return xr(e)(t.map(rl))}const Sr={test:nl,parse:Cr,createTransformer:xr,getAnimatableNone:il};function jt(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function wr({hue:e,saturation:t,lightness:n,alpha:r}){e/=360,t/=100,n/=100;let i=0,l=0,s=0;if(!t)i=l=s=n;else{const u=n<.5?n*(1+t):n+t-n*t,d=2*n-u;i=jt(d,u,e+1/3),l=jt(d,u,e),s=jt(d,u,e-1/3)}return{red:Math.round(i*255),green:Math.round(l*255),blue:Math.round(s*255),alpha:r}}const ol=(e,t,n)=>{const r=e*e,i=t*t;return Math.sqrt(Math.max(0,n*(i-r)+r))},al=[Bt,Ae,Pe],_r=e=>al.find(t=>t.test(e)),Ir=e=>`'${e}' is not an animatable color. Use the equivalent color code instead.`,Dr=(e,t)=>{let n=_r(e),r=_r(t);We(!!n,Ir(e)),We(!!r,Ir(t));let i=n.parse(e),l=r.parse(t);n===Pe&&(i=wr(i),n=Ae),r===Pe&&(l=wr(l),r=Ae);const s=Object.assign({},i);return u=>{for(const d in s)d!=="alpha"&&(s[d]=ol(i[d],l[d],u));return s.alpha=Gt(i.alpha,l.alpha,u),n.transform(s)}},ll=e=>typeof e=="number",sl=(e,t)=>n=>t(e(n)),Ar=(...e)=>e.reduce(sl);function Mr(e,t){return ll(e)?n=>Gt(e,t,n):at.test(e)?Dr(e,t):Rr(e,t)}const Vr=(e,t)=>{const n=[...e],r=n.length,i=e.map((l,s)=>Mr(l,t[s]));return l=>{for(let s=0;s<r;s++)n[s]=i[s](l);return n}},ul=(e,t)=>{const n=Object.assign(Object.assign({},e),t),r={};for(const i in n)e[i]!==void 0&&t[i]!==void 0&&(r[i]=Mr(e[i],t[i]));return i=>{for(const l in r)n[l]=r[l](i);return n}};function Er(e){const t=Sr.parse(e),n=t.length;let r=0,i=0,l=0;for(let s=0;s<n;s++)r||typeof t[s]=="number"?r++:t[s].hue!==void 0?l++:i++;return{parsed:t,numNumbers:r,numRGB:i,numHSL:l}}const Rr=(e,t)=>{const n=Sr.createTransformer(t),r=Er(e),i=Er(t);return r.numHSL===i.numHSL&&r.numRGB===i.numRGB&&r.numNumbers>=i.numNumbers?Ar(Vr(r.parsed,i.parsed),n):(gr(!0,`Complex values '${e}' and '${t}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`),s=>`${s>0?t:e}`)},dl=(e,t)=>n=>Gt(e,t,n);function cl(e){if(typeof e=="number")return dl;if(typeof e=="string")return at.test(e)?Dr:Rr;if(Array.isArray(e))return Vr;if(typeof e=="object")return ul}function gl(e,t,n){const r=[],i=n||cl(e[0]),l=e.length-1;for(let s=0;s<l;s++){let u=i(e[s],e[s+1]);if(t){const d=Array.isArray(t)?t[s]:t;u=Ar(d,u)}r.push(u)}return r}function pl([e,t],[n]){return r=>n(pr(e,t,r))}function fl(e,t){const n=e.length,r=n-1;return i=>{let l=0,s=!1;if(i<=e[0]?s=!0:i>=e[r]&&(l=r-1,s=!0),!s){let d=1;for(;d<n&&!(e[d]>i||d===r);d++);l=d-1}const u=pr(e[l],e[l+1],i);return t[l](u)}}function hl(e,t,{clamp:n=!0,ease:r,mixer:i}={}){const l=e.length;We(l===t.length,"Both input and output ranges must be the same length"),We(!r||!Array.isArray(r)||r.length===l-1,"Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values."),e[0]>e[l-1]&&(e=[].concat(e),t=[].concat(t),e.reverse(),t.reverse());const s=gl(t,r,i),u=l===2?pl(e,s):fl(e,s);return n?d=>u(Ka(e[0],e[l-1],d)):u}class ml{constructor({valueRange:t,colorRange:n}){$(this,"mapper");this.mapper=hl(t,n)}getColor(t){return this.mapper(t)}}function vl(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function Tr({data_field:e,aggregation:t},n){return zt(n,e,t)}function lt({formatter:e},t){return["string","number"].includes(typeof t)?ae.default(t).format(e):vl(t)}function yl(e,t){return e.type==="static"?e.staticColor:e.type==="continuous"?new ml(e).getColor(t):"black"}function bl(e,t){const n={};return e.forEach(r=>{const{name:i,color:l,data_field:s,aggregation:u,size:d,weight:p}=r,c=zt(t,s,u),f=lt(r,c);n[i]=o(a.Text,{sx:{fontSize:d,display:"inline"},color:yl(l,c),weight:p,children:f})}),n}function Cl(e){return e.split(" ").map(t=>g(U,{children:[t,"\xA0"]}))}function xl(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
40
40
  `,"<br/>").split("<br/>");return n.map((i,l)=>{const s=[Cl(i)];return l!==n.length-1&&s.push(o("br",{})),s}).flat().filter(i=>i!==void 0)}function Wt(e){return xl(e)}function Ut(e,t,n){const r=bl(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(l=>{var p;const s=i.exec(l);if(!s)return Wt(l);const u=r[s[1]];if(!u)return Wt(l);const d=(p=s[2])!=null?p:"";return g(U,{children:[u,Wt(d)]})})}function Sl(e,t){const n={};return e.forEach(r=>{const{name:i,data_field:l,aggregation:s}=r,u=zt(t,l,s);n[i]=lt(r,u)}),n}function Fr(e,t,n){const r=Sl(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(l=>{var p;const s=i.exec(l);if(!s)return l;const u=r[s[1]];if(!u)return l;const d=(p=s[2])!=null?p:"";return`${u}${d}`}).join("")}function wl({context:e}){const{value:t=Pt}=L(e.instanceData,"config"),{template:n,variables:r,align:i}=t,l=w.useMemo(()=>Ut(n,r,e.data),[n,r,e.data]);return o(a.Text,{align:i,children:Object.values(l).map(s=>s)})}function _l({control:e,index:t,remove:n,data:r}){return g(a.Stack,{my:"sm",p:0,sx:{border:"1px solid #eee",borderTopColor:"#333",borderTopWidth:2,position:"relative"},children:[o(S.Controller,{name:`variables.${t}`,control:e,render:({field:i})=>o(rt,{data:r,...i})}),o(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:o(V.Trash,{size:16})})]},t)}function Il({control:e,watch:t,data:n}){const{fields:r,append:i,remove:l}=S.useFieldArray({control:e,name:"variables"}),s=t("variables"),u=r.map((p,c)=>({...p,...s[c]})),d=()=>i(tt());return g(a.Stack,{children:[u.map((p,c)=>o(_l,{control:e,index:c,remove:l,data:n},p.name)),o(a.Group,{position:"center",mt:"xs",children:o(a.Button,{onClick:d,children:"Add a Variable"})})]})}function Dl({context:e}){const t=e.data||[],{value:n,set:r}=L(e.instanceData,"config"),i=C.default.useMemo(()=>{const{align:m,template:v="",variables:b=[]}=_.defaultsDeep({},n,Pt);return{variables:b,template:v,align:m}},[n]),{control:l,handleSubmit:s,watch:u,getValues:d,reset:p}=S.useForm({defaultValues:i});C.default.useEffect(()=>{p(i)},[i]),u(["variables","template"]);const c=d(),f=C.default.useMemo(()=>!z.default.isEqual(c,n),[c,n]);return o(a.Stack,{mt:"md",spacing:"xs",children:g("form",{onSubmit:s(r),children:[g(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[o(a.Text,{weight:500,children:"Stats Configurations"}),o(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:o(V.DeviceFloppy,{size:20})})]}),o(S.Controller,{name:"template",control:l,render:({field:m})=>o(kt,{label:"Template",py:"md",sx:{flexGrow:1},...m})}),o(a.Text,{pb:"sm",pt:"md",size:"sm",children:"Variables"}),o(Il,{control:l,watch:u,data:t})]})})}const Al={createConfig(){return{version:1,config:Pt}},displayName:"Stats",migrator:new Oa,name:"stats",viewRender:wl,configRender:Dl};var Me=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e))(Me||{});const st={columns:[],fontSize:"1rem",highlightOnHover:!1,horizontalSpacing:"1em",id_field:"",striped:!1,use_raw_columns:!1,verticalSpacing:"1em"};/**
41
41
  * react-table
42
42
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/dashboard",
3
- "version": "4.18.0",
3
+ "version": "4.19.0",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public",