@devtable/dashboard 10.23.1 → 10.24.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.
@@ -51,7 +51,7 @@ Check the top-level render call using <`+V+">.")}return E}}function ku(S,E){{if(
51
51
  ${Gu.map(Wu).join("")}
52
52
  </tbody>
53
53
  </table>
54
- `;function fr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function gr(e,t){try{return fr(e,t)}catch(n){return console.error(n),n.message}}function Ru({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},Tt)}catch(n){return console.error(n),e}}function Yu(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,Tt)}catch(n){return console.error(n),t}}function Qu(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Ku(e,t){let n=Qu(e);return n+="&key="+t,Ia.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Ku({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),mt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function Xa(e){qe.baseURL!==e.apiBaseURL&&(qe.baseURL=e.apiBaseURL),e.app_id&&(qe.app_id=e.app_id),e.app_secret&&(qe.app_secret=e.app_secret),e.makeQueryENV&&(qe.makeQueryENV=e.makeQueryENV)}async function Uu({query:e,payload:t},n){if(!e.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=e,c=fr(o,t),d=Ru({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=Yu(u,f),f}async function Xu({type:e,key:t,configString:n},r){return await qe.query(r)({type:e,key:t,query:n},{})}async function mr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function Ja(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class Za{constructor(t){q(this,"rootRef");this.rootRef=re.observable({current:t})}async deleteItem(t){re.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?re.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))re.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else re.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return re.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Aa)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Aa;return this.channels.set(t,r),r}}class Zu{constructor(t){q(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 Ju,instanceData:new Za(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ha(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Za({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Hu=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...Ha(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ec=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...Ha(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},es=(e,t)=>{const n=ct.bezier(e),r=ct.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Cn=e=>{const t=ct.bezier(e);return function(n){return t(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:es(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:es(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:Cn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:Cn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:Cn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:Cn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function dt(e){return new oc(e)}class yr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new yr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ts="10.23.1",lc=Object.freeze(Object.defineProperty({__proto__:null,version:ts},Symbol.toStringTag,{value:"Module"}));class uc{constructor(t){q(this,"staticColors",new Map);q(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 cc{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(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 dc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){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 a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class me extends dc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const j=(e,t)=>{const[n,{setFalse:r}]=U.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=y.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},br={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function L(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function pc(e){return e.includes(".")?L(e):{queryID:"",columnKey:e}}function pt(e,t){var a;const{queryID:n,columnKey:r}=L(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function Ht(e,t){const{queryID:n}=L(t);return n?e[n]:[]}function hc(e){return Object.values(e)[0]}function Sn(e,t){const{queryID:n,columnKey:r}=L(t);return e[r]}ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,Pe.CanvasRenderer]);function fc({context:e}){const{value:t}=j(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,br),h=y.useMemo(()=>Ht(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:L(o),y:L(l),z:L(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const I=x.minBy(h,N=>N[C.columnKey]),B=x.maxBy(h,N=>N[C.columnKey]);return{min:x.get(I,C.columnKey),max:x.get(B,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[C.columnKey]])}]};return t?i(Be,{echarts:ie,option:D,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const ns=y.createContext(null),vr=ns.Provider;function xr(){const e=y.useContext(ns);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ye=()=>xr(),wr=()=>xr(),rs=y.createContext(null),Cr=rs.Provider;function is(){const e=y.useContext(rs);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>is(),we=()=>is(),gc={inEditMode:!1},_n=y.createContext(gc),as=y.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Sr=as.Provider;function ss(){const e=y.useContext(as);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const bt=()=>ss(),nt=()=>ss(),mc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},_r=y.createContext(mc);function os(){const e=y.useContext(_r);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(y.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=nt(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function yc({context:e}){const{value:t,set:n}=j(e.instanceData,"config"),r=x.defaults({},t,br),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(T.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function bc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class vc extends me{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:bc(a,r)}})}}const xc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new vc,name:"bar-3d",viewRender:fc,configRender:yc,createConfig(){return{version:2,config:x.cloneDeep(br)}}};class Fe extends y.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 p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const ze={mantissa:0,output:"number",trimMantissa:!1,average:!1};function wc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(T.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(T.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(T.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const We=y.forwardRef(wc),Qe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
54
+ `;function fr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function gr(e,t){try{return fr(e,t)}catch(n){return console.error(n),n.message}}function Ru({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},Tt)}catch(n){return console.error(n),e}}function Yu(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,Tt)}catch(n){return console.error(n),t}}function Qu(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Ku(e,t){let n=Qu(e);return n+="&key="+t,Ia.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Ku({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),mt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function Xa(e){qe.baseURL!==e.apiBaseURL&&(qe.baseURL=e.apiBaseURL),e.app_id&&(qe.app_id=e.app_id),e.app_secret&&(qe.app_secret=e.app_secret),e.makeQueryENV&&(qe.makeQueryENV=e.makeQueryENV)}async function Uu({query:e,payload:t},n){if(!e.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=e,c=fr(o,t),d=Ru({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=Yu(u,f),f}async function Xu({type:e,key:t,configString:n},r){return await qe.query(r)({type:e,key:t,query:n},{})}async function mr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function Ja(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class Za{constructor(t){q(this,"rootRef");this.rootRef=re.observable({current:t})}async deleteItem(t){re.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?re.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))re.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else re.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return re.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Aa)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Aa;return this.channels.set(t,r),r}}class Zu{constructor(t){q(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 Ju,instanceData:new Za(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ha(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Za({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Hu=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...Ha(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ec=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...Ha(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},es=(e,t)=>{const n=ct.bezier(e),r=ct.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Cn=e=>{const t=ct.bezier(e);return function(n){return t(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:es(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:es(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:Cn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:Cn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:Cn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:Cn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function dt(e){return new oc(e)}class yr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new yr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ts="10.24.0",lc=Object.freeze(Object.defineProperty({__proto__:null,version:ts},Symbol.toStringTag,{value:"Module"}));class uc{constructor(t){q(this,"staticColors",new Map);q(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 cc{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(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 dc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){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 a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class me extends dc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const j=(e,t)=>{const[n,{setFalse:r}]=U.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=y.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},br={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function L(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function pc(e){return e.includes(".")?L(e):{queryID:"",columnKey:e}}function pt(e,t){var a;const{queryID:n,columnKey:r}=L(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function Ht(e,t){const{queryID:n}=L(t);return n?e[n]:[]}function hc(e){return Object.values(e)[0]}function Sn(e,t){const{queryID:n,columnKey:r}=L(t);return e[r]}ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,Pe.CanvasRenderer]);function fc({context:e}){const{value:t}=j(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,br),h=y.useMemo(()=>Ht(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:L(o),y:L(l),z:L(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const I=x.minBy(h,N=>N[C.columnKey]),B=x.maxBy(h,N=>N[C.columnKey]);return{min:x.get(I,C.columnKey),max:x.get(B,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[C.columnKey]])}]};return t?i(Be,{echarts:ie,option:D,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const ns=y.createContext(null),vr=ns.Provider;function xr(){const e=y.useContext(ns);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ye=()=>xr(),wr=()=>xr(),rs=y.createContext(null),Cr=rs.Provider;function is(){const e=y.useContext(rs);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>is(),we=()=>is(),gc={inEditMode:!1},_n=y.createContext(gc),as=y.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Sr=as.Provider;function ss(){const e=y.useContext(as);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const bt=()=>ss(),nt=()=>ss(),mc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},_r=y.createContext(mc);function os(){const e=y.useContext(_r);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(y.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=nt(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function yc({context:e}){const{value:t,set:n}=j(e.instanceData,"config"),r=x.defaults({},t,br),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(T.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function bc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class vc extends me{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:bc(a,r)}})}}const xc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new vc,name:"bar-3d",viewRender:fc,configRender:yc,createConfig(){return{version:2,config:x.cloneDeep(br)}}};class Fe extends y.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 p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const ze={mantissa:0,output:"number",trimMantissa:!1,average:!1};function wc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(T.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(T.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(T.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const We=y.forwardRef(wc),Qe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
55
55
  `)},ls={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Sc,configRender:Cc,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Cc(e){return i(P,{})}function Sc(e){return i(s.Text,{children:"Click chart's series"})}const _c=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],kn=y.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(t);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[e&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:_c,value:t.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),at=y.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},a=o=>{t({...e,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(kn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),i(kn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:a})]})}),je={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function st({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
56
56
  max-width: ${t}px;
57
57
  word-break: ${n};
@@ -437,8 +437,8 @@ Check the top-level render call using <`+V+">.")}return E}}function ku(S,E){{if(
437
437
  <tbody>${g.join("")}</tbody>
438
438
  </table>
439
439
  `}}}function n1(e,t){const n=Gt(e.heat_block.min,t),r=Gt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function r1(e,t,n){const r=L(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=rt(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function i1(e,t,n){const r=L(e.x_axis.data_key),a=L(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=rt(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const a1={tooltip:{confine:!0}};function s1(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=ft(c,t);return u[c.name]=Je(c,d),u},{}),a=UC(e),o=XC(e),l={xAxis:r1(e,t,a.x_axis),yAxis:i1(e,t,a.y_axis),series:ZC(e,t),tooltip:t1(e,t,a,o),grid:JC(e),visualMap:n1(e,r)};return x.defaultsDeep({},l,a1)}function o1(e){return i(P,{})}function l1(e){return i(s.Text,{children:"Click heat block"})}const Go={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:l1,configRender:o1,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};ie.use([F.DataZoomComponent,pe.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,Pe.CanvasRenderer]);function u1({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const h=L(e.x_axis.data_key),g=L(e.y_axis.data_key);return x.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,Go.id),c=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>s1(e,t,o),[e,t]);return!n||!r?null:i(Be,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function c1({context:e,instance:t}){const n=Ue({vizManager:e.vizManager,instance:t}),{value:r}=j(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Ci),[r]),l=e.data,{width:u,height:c}=e.viewport;return i(u1,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})}class d1 extends me{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const p1={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new d1,name:"merico-heatmap",viewRender:c1,configRender:KC,createConfig:()=>({version:1,config:Ci}),triggers:[Go]},h1=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),f1=[tc,nc,ac,ic,rc,sc],Wo=()=>({id:"dashboard",version:ts,manifest:{viz:[hi,tx,S0,Eb,Sx,_y,Yw,xc,qh,Xg,Em,sw,dy,Dg,Wv,Ky,Sb,z0,_C,p1,VC,ef],color:[...h1,...f1]}}),dn=new cc,Ce={pluginManager:dt("pluginManager"),vizManager:dt("vizManager"),colorManager:dt("colorManager"),instanceScope:{panelModel:dt("panelModel"),vizInstance:dt("vizInstance"),interactionManager:dt("interactionManager"),migrator:dt("migrator"),operationManager:dt("operationManager"),triggerManager:dt("triggerManager")}},Si=()=>{try{dn.install(Wo())}catch{}const e=new Zu(dn),t=new uc(dn);return{pluginManager:dn,vizManager:e,colorManager:t}},ut=y.createContext(Si());try{dn.install(Wo())}catch{}const _i=y.createContext(null);function Hn(e){const t=y.useContext(_i),n=U.useCreation(()=>e.configure(t||new yr),[e.configure]),r=U.usePrevious(n);return r&&r!==n&&r.dispose(),i(_i.Provider,{value:n,children:e.children})}function jo(){return y.useContext(_i)}const g1={viewPanelInFullScreen:x.noop,inFullScreen:!1},er=y.createContext(g1),m1=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Nn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i($.IconInfoCircle,{size:16,color:"gray"})})}),y1=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(m1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Ro=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?Y(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&Y(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(Lu.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(T.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),b1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),Yo=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),v1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f})=>{const{classes:h,cx:g}=b1({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[m,C]=y.useState(!1),w=N=>{C(N)},_=m&&(u==null?void 0:u.length)>0,[D,I]=y.useState(""),B=y.useMemo(()=>{if(!D)return d;const N=D.toLowerCase(),O=z=>{var A;return((A=z.description)==null?void 0:A.toLowerCase().includes(N))||z.label.toLowerCase().includes(N)};return d.filter(O)},[D,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ra,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(Yo,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:N=>`${N.length} selected`,searchValue:D,onSearch:I,filterOption:!1,children:B.map(N=>p(Ra.Option,{title:N.label,children:[i(s.Text,{size:"sm","data-role":"label",children:N.label}),N.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:N.description})]},N.value))})]})},x1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=we(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(v1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),w1=y.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),C1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=we(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:w1})});function S1({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const _1=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),k1=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i(_1,{rotate:e?"0":"-90",onClick:r,...a})),T1=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),D1=({onClick:e,...t})=>i(T1,{onClick:e,...t}),M1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),I1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f})=>{const{classes:h,cx:g}=M1({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[m,C]=y.useState(!1),w=D=>{C(D)},_=m&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ya,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:k1,treeIcon:D1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(Yo,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Ya.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:D=>`${D.length} selected`})]})},A1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(I1,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e})}),z1=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(C1,{...r,...a,config:t});case"multi-select":return i(x1,{...r,...a,config:t});case"tree-select":return i(A1,{...r,...a,config:t});case"text-input":return i(S1,{...r,...a,config:t});case"date-range":return i(Ro,{...r,...a,config:t});case"checkbox":return i(y1,{...r,...a,config:t});default:return null}}),Qo=k.observer(y.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(z1,{filter:e,formFieldProps:t})})})));function E1(e){const t=le();y.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const Ko=k.observer(function({view:t}){const n=we(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),E1(l);const u=n.filters.visibleInView(t.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(C,w)=>{m(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(Qo,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),Uo=b.types.model("MockContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function Xo(e){return{current:e}}const $1=b.types.model("PanelLayoutMeta",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),L1=b.types.model("PanelStyleBorderMeta",{enabled:b.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),O1=b.types.model("PanelStyleMeta",{border:L1}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),P1=b.types.model("VariableMeta",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}),b.types.model({type:b.types.literal("custom"),config:b.types.model({func:b.types.string})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),B1=b.types.model("PanelVizMeta",{type:b.types.string,conf:b.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),V1=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:$1,queryIDs:b.types.array(b.types.string),viz:B1,style:O1,variables:b.types.optional(b.types.array(P1),[])}).views(e=>({get json(){const{id:t,title:n,description:r,queryIDs:a}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:n,layout:e.layout.json,queryIDs:[...a],variables:e.variables.map(o=>o.json),description:r}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=b.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=b.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),tr=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return re.toJS(t)});var Se=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Se||{});const N1=b.types.model("QueryMeta",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[Se.Postgresql,Se.MySQL,Se.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Se.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return tr({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),q1=b.types.model("SQLSnippetMeta",{key:b.types.string,value:b.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var _e=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(_e||{});const Jo=b.types.model("FilterCheckboxConfigMeta",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),F1=()=>Jo.create({_name:"checkbox",description:"",default_value:!1});function Zo(e,t){return e.map(n=>{try{return n?Y.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const G1=b.types.model("FilterDateRangeConfigMeta",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Zo(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return Y(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return Y(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=b.getParent(e);b.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Ho=b.types.snapshotProcessor(G1,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:Y.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:Zo(t,n.inputFormat)}}}),W1=()=>Ho.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),j1=b.types.model({label:b.types.string,value:b.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),ki=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(j1),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),el=b.types.compose("FilterMultiSelectConfigMeta",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),ki).views(e=>({get json(){const{_name:t,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=e;return tr({_name:t,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>re.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),R1=()=>el.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),tl=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,required:b.types.boolean,width:b.types.optional(b.types.string,"")}),ki).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return tr({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t},getSelectOption(t){return e.options.find(n=>n.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.default_value}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>re.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Y1=()=>tl.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),nl=b.types.model("FilterTextInputConfigMeta",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),rl=()=>nl.create({_name:"text-input",required:!1,default_value:""});function Q1(e){return Ou.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function K1(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:t.label},t.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const il=b.types.compose("FilterTreeSelectConfigMeta",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),ki).views(e=>({get json(){const{_name:t,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=e;return{_name:t,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id),n=K1(t);return Q1(n)},get errorMessage(){const{error:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){const t=b.getParent(e,1).key;b.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){b.addDisposer(e,re.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),U1=()=>il.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),al=b.types.model("FilterMeta",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[_e.Select,_e.MultiSelect,_e.TreeSelect,_e.TextInput,_e.Checkbox,_e.DateRange]),config:b.types.union(tl,el,il,nl,Jo,Ho)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==_e.TreeSelect},get auto_submit_supported(){return[_e.Select,_e.Checkbox,_e.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:re.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case _e.Select:e.config=Y1();break;case _e.MultiSelect:e.config=R1();break;case _e.TreeSelect:e.config=U1();break;case _e.TextInput:e.config=rl();break;case _e.Checkbox:e.config=F1();break;case _e.DateRange:e.config=W1();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var R=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(R||{});const sl=b.types.model("ViewDivisionConfig",{_name:b.types.literal(R.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),X1=()=>sl.create({_name:R.Division}),J1=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=b.getParent(e,2),a=b.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),Ti={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
440
- `)},ol=b.types.model("ViewModalConfig",{_name:b.types.literal(R.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(J1,Ti)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Z1=()=>ol.create({_name:R.Modal,width:"90vw",height:"90vh"}),H1=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),ll=b.types.model("ViewTabsConfig",{_name:b.types.literal(R.Modal),tabs:b.types.optional(b.types.array(H1),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=Me.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),eS=()=>ll.create({_name:R.Modal,tabs:[]}),tS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[R.Division,R.Modal,R.Tabs]),config:b.types.union(sl,ol,ll),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case R.Division:e.config=X1();break;case R.Modal:e.config=Z1();break;case R.Tabs:e.config=eS();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),ul=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[Se.HTTP,Se.MySQL,Se.Postgresql]),key:b.types.string,config:b.types.frozen()}),nS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(ul),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),rS=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),cl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(rS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Di=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function dl(e){return Di.create({current:e})}const pl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(tS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>tr(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function iS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const hl=V1.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data.toJSON(),t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData())},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function aS(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:hi.name,conf:hi.createConfig()},style:{border:{enabled:!0}}}}const fl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(hl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function gl(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:Y.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function sS(e){return e.reduce((t,n)=>(t[n.key]=gl(n.config.default_value,n.config),t),{})}const ml=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(al),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function yl(e){return{current:e,values:sS(e)}}const oS=N1.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}}}));function lS(e,t){return new Function(`return ${e}`)()(t,Tt)}function uS(e,t,n){return lS(e,{context:t,filters:n})}function cS(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,Tt)}catch(n){return console.error(n),t}}function dS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,Tt)}function pS(e,t){return e?new Function(`return ${e}`)()(t,Tt):t}const hS=b.types.compose("QueryRenderModel",oS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.array(b.types.frozen()),[]),error:b.types.frozen()})).views(e=>({get formattedSQL(){const t=b.getRoot(e).content.payloadForSQL;return gr(e.sql,t)},get typedAsSQL(){return[Se.Postgresql,Se.MySQL].includes(e.type)},get typedAsHTTP(){return[Se.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return b.getRoot(e).datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=b.getRoot(e).content.payloadForSQL,{name:r,pre_process:a}=e.json,o=uS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=b.getRoot(e).content.payloadForSQL;e.data=yield*b.toGenerator(Uu({payload:n,title:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!mt.isCancel(n)){e.data.length=0;const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=cS(e.datasource,o);const l=yield*b.toGenerator(Xu({type:n,key:r,configString:JSON.stringify(o)},e.controller.signal));let u=dS(e.datasource,l);u=pS(a,u),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!mt.isCancel(n)){e.data.length=0;const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:()=>e.typedAsHTTP?e.runHTTP():e.runSQL(),beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>{var t,n;return e.typedAsHTTP?`${e.id}--${e.key}--${e.reQueryKey}--${(t=e.datasource)==null?void 0:t.id}`:`${e.id}--${e.key}--${e.formattedSQL}--${e.pre_process}--${e.post_process}--${(n=e.datasource)==null?void 0:n.id}`},e.fetchData,{fireImmediately:!0,delay:0}))}})),bl="\uFEFF";function fS(e,t){const n=new Blob([bl+t],{type:"text/csv"});hr.saveAs(n,`${e}.csv`)}function vl(e,t){const n=new Blob([t],{type:"application/json"});hr.saveAs(n,`${e}.json`)}function xl(e){const t=new Pu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,Cl(r))}),t.generateAsync({type:"blob"}).then(n=>{hr.saveAs(n,"dashboard_data.zip")})}function wl(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function Cl(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],n=Object.keys(e[0]).map(wl);return t.push(n.join(",")),e.forEach(r=>{const a=Object.values(r).map(wl).join(",");t.push(a)}),bl+t.join(`
441
- `)}const Sl=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(hS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));xl(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o.toJSON()}));xl(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=Cl(a);fS(r,o)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData()}}));function gS(e){return{current:e}}const mS=q1.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),_l=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(mS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function yS(e){return{current:e}}function nr(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=fr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class bS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),re.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const vS=e=>new bS(e),xS=k.observer(({view:e})=>{const t=ye(),n=le(),r=et.useModals(),{panel:a,downloadPanelScreenshot:o}=nt(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(er),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(l)},[l,u]),m=!c&&e.type!==R.Modal;return i(P,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(T.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(T.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i($.IconCamera,{size:14}),children:"Screenshot"}),m&&i(s.Menu.Item,{onClick:g,icon:i(T.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(T.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(T.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(T.Trash,{size:14}),children:"Delete"})]})]})})})});function wS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Mi=k.observer(()=>{const[e,t]=y.useState(!1),{panel:n}=bt();return wS(n.description)?null:p(P,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Nn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(T.InfoCircle,{size:20})})})]})}),HM="",eI="",CS=k.observer(function(){const{panel:t}=bt(),{title:n}=t;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function SS(e){const t=y.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;Qa.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var kl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(kl||{}),rr=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(rr||{});class _S{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(Ce.instanceScope.panelModel),this.vizInstance=t.getRequired(Ce.instanceScope.vizInstance),this.operationManager=t.getRequired(Ce.instanceScope.operationManager),this.triggerManager=t.getRequired(Ce.instanceScope.triggerManager),this.vizManager=t.getRequired(Ce.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Tl(e){const{panel:t}=bt();return y.useCallback(n=>{const r=n.getRequired(Ce.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(Ce.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(Ce.instanceScope.interactionManager,o=>{const l=o.getRequired(Ce.instanceScope.vizInstance);return new Dr(l,a,Tn)}).provideFactory(Ce.instanceScope.operationManager,o=>o.getRequired(Ce.instanceScope.interactionManager).operationManager).provideFactory(Ce.instanceScope.triggerManager,o=>o.getRequired(Ce.instanceScope.interactionManager).triggerManager).provideValue(Ce.instanceScope.panelModel,t).provideFactory(Ce.instanceScope.migrator,o=>new _S(o))},[e.viz.type,e.viz.conf])}function Dl(e){const[t,n]=y.useState(!1),r=jo().getRequired(Ce.instanceScope.migrator);return U.useAsyncEffect(async()=>{const a=r.status===rr.notStarted;n(r.status===rr.done),r.status===rr.notStarted&&r.runMigration().then(o=>{o===kl.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Ml(e,t){const n=jo().getRequired(Ce.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function kS({setVizConf:e,...t}){const{panel:n}=t,r=Ml(e,n),a=Dl(()=>{bn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return U.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(ec,{...t}):i(s.Text,{children:"Checking update..."})}function TS(e){const{panel:t,setVizConf:n}=e;Ml(n,t);const{inEditMode:r}=y.useContext(_n);return Dl(()=>{r&&bn.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Hu,{...e}):i(s.Text,{children:"Checking update"})}const tI="";function DS(e,t){const{vizManager:n}=y.useContext(ut),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=bt(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:t},f=Tl(d);try{return n.resolveComponent(r.type),i(Hn,{configure:f,children:i(TS,{setVizConf:r.setConf,panel:d,data:e,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const Il=k.observer(function({data:t}){const{ref:n,width:r,height:a}=Me.useElementSize(),o=DS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:l&&i(Fe,{children:o})})}),Al=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Ii=k.observer(({panel:e,height:t})=>p(s.Flex,{direction:"column",sx:{height:t,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(Al,{panel:e}),e.canRenderViz&&i(Il,{data:e.data})]})),MS={border:"1px solid #e9ecef"},zl=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=SS(e),o=e.title?"calc(100% - 25px - 5px)":"100%";return i(Sr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:"panel-root",ref:r,p:5,pt:0,sx:{...MS,...t},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(Mi,{})}),n,i(CS,{}),i(Ii,{panel:e,height:o})]})})}),IS={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function AS(e){return e.style.border.enabled?{}:IS}const El=k.observer(function({panel:t,view:n}){const r=AS(t);return i(zl,{panel:t,panelStyle:r,dropdownContent:i(xS,{view:n})})});function zS(e){return!["richText","button"].includes(e)}const ES=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=bt(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=y.useContext(er),l=y.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==R.Modal;return zS(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(T.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(T.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i($.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(T.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function $S(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ai=k.observer(({panel:e,view:t})=>{const n=$S(e);return i(zl,{panel:e,panelStyle:n,dropdownContent:i(ES,{view:t})})}),LS={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},$l=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(T.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:LS,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Ai,{view:t,panel:n})})})});function Ll(e,t,n){const{panels:r}=we(),a=e.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(t)?t:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const nI="",OS=y.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(T.ArrowsMove,{size:16})})),PS=y.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(T.ChevronDownRight,{size:16})})),BS=vn.WidthProvider(vn),VS=k.observer(({view:e,className:t="layout"})=>{const n=we(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(BS,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(PS,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(OS,{h:u.layout.h}),i(El,{view:e,panel:u})]},u.id))})}),NS=vn.WidthProvider(vn),qS=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=we().panels.panelsByIDs(t.panelIDs);return i(NS,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(Ai,{view:t,panel:o})},o.id))})});function zi(e){const t=y.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;Qa.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const FS=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=U.useBoolean(!1),a=wr(),o=we(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;vl(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i($.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i($.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i($.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i($.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Ol=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=zi(t);return p(P,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(FS,{downloadScreenShot:a})]})}),Pl=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i($.IconCamera,{size:14})})),GS=k.observer(({children:e,view:t})=>{const n=we(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=zi(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Pl,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),WS=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},jS=k.observer(({view:e})=>{const t=we(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,defaultValue:n.tabs.length>0?n.tabs[0].id:"0",styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:WS(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(ir,{view:a})},r.id):null})]})}),RS=k.observer(({view:e,children:t})=>{switch(e.type){case R.Modal:return i(GS,{view:e,children:t});case R.Tabs:return i(jS,{view:e});case R.Division:default:return i(Ol,{view:e,children:t})}}),YS=k.observer(({children:e,view:t})=>i(Ol,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function Bl(e){return e.replace(/(vw|vh)/,"%")}const QS=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=y.useMemo(()=>({width:Bl(n.width),height:Bl(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=zi(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Pl,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),KS=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},US=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},XS=k.observer(({view:e})=>{const t=et.useModals(),n=le(),r=y.useMemo(()=>n.views.options.filter(u=>u.type===R.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,defaultValue:a.tabs.length>0?a.tabs[0].id:"0",styles:KS(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:US(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(T.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i($.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i($.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(ir,{view:d})]},u.id)})]})}),JS=k.observer(({view:e,children:t})=>{switch(e.type){case R.Modal:return i(QS,{view:e,children:t});case R.Tabs:return i(XS,{view:e});case R.Division:default:return i(YS,{view:e,children:t})}}),Vl=k.observer(function({view:t}){return i(er.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(JS,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Ko,{view:t})}),i(VS,{view:t})]})})})})}),ir=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=os(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Ll(t,n,r);return i(er.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===R.Modal?"0 !important":"100%"},children:[l&&i($l,{view:t,panel:u,exitFullScreen:o}),i(RS,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Ko,{view:t})}),!l&&i(qS,{view:t})]})})]})})});var Nl=(e=>(e.Use="use",e.Edit="edit",e))(Nl||{});const ZS={[R.Division]:"Division",[R.Tabs]:"Tabs",[R.Modal]:"Modal"},ql={[R.Division]:"rgba(255, 0, 0, 0.2)",[R.Modal]:"rgba(0, 0, 0, 0.2)",[R.Tabs]:"rgba(255, 200, 100, 0.4)"},HS={[R.Division]:"#ff4000",[R.Modal]:"#000",[R.Tabs]:"#ffad18"},e_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:R.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function t_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Fl=b.types.compose("FiltersModel",ml,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===_e.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){t_(e.current,al,(n,r)=>{if(n==="setType"){const a=gl(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Gl=Sl.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))}})),Wl=_l.views(e=>({get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),n_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=b.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;if(n===Se.MySQL)return`
440
+ `)},ol=b.types.model("ViewModalConfig",{_name:b.types.literal(R.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(J1,Ti)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Z1=()=>ol.create({_name:R.Modal,width:"90vw",height:"90vh"}),H1=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),ll=b.types.model("ViewTabsConfig",{_name:b.types.literal(R.Modal),tabs:b.types.optional(b.types.array(H1),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=Me.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),eS=()=>ll.create({_name:R.Modal,tabs:[]}),tS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[R.Division,R.Modal,R.Tabs]),config:b.types.union(sl,ol,ll),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case R.Division:e.config=X1();break;case R.Modal:e.config=Z1();break;case R.Tabs:e.config=eS();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),ul=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[Se.HTTP,Se.MySQL,Se.Postgresql]),key:b.types.string,config:b.types.frozen()}),nS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(ul),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),rS=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),cl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(rS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Di=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function dl(e){return Di.create({current:e})}const pl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(tS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>tr(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function iS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const hl=V1.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData())},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function aS(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:hi.name,conf:hi.createConfig()},style:{border:{enabled:!0}}}}const fl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(hl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function gl(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:Y.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function sS(e){return e.reduce((t,n)=>(t[n.key]=gl(n.config.default_value,n.config),t),{})}const ml=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(al),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function yl(e){return{current:e,values:sS(e)}}const oS=N1.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}}}));function lS(e,t){return new Function(`return ${e}`)()(t,Tt)}function uS(e,t,n){return lS(e,{context:t,filters:n})}function cS(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,Tt)}catch(n){return console.error(n),t}}function dS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,Tt)}function pS(e,t){return e?new Function(`return ${e}`)()(t,Tt):t}const hS=b.types.compose("QueryRenderModel",oS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.frozen([]),[]),error:b.types.frozen()})).views(e=>({get formattedSQL(){const t=b.getRoot(e).content.payloadForSQL;return gr(e.sql,t)},get typedAsSQL(){return[Se.Postgresql,Se.MySQL].includes(e.type)},get typedAsHTTP(){return[Se.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return b.getRoot(e).datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=b.getRoot(e).content.payloadForSQL,{name:r,pre_process:a}=e.json,o=uS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=b.getRoot(e).content.payloadForSQL;e.data=yield*b.toGenerator(Uu({payload:n,title:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!mt.isCancel(n)){e.data.length=0;const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=cS(e.datasource,o);const l=yield*b.toGenerator(Xu({type:n,key:r,configString:JSON.stringify(o)},e.controller.signal));let u=dS(e.datasource,l);u=pS(a,u),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!mt.isCancel(n)){e.data.length=0;const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:()=>e.typedAsHTTP?e.runHTTP():e.runSQL(),beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>{var t,n;return e.typedAsHTTP?`${e.id}--${e.key}--${e.reQueryKey}--${(t=e.datasource)==null?void 0:t.id}`:`${e.id}--${e.key}--${e.formattedSQL}--${e.pre_process}--${e.post_process}--${(n=e.datasource)==null?void 0:n.id}`},e.fetchData,{fireImmediately:!0,delay:0}))}})),bl="\uFEFF";function fS(e,t){const n=new Blob([bl+t],{type:"text/csv"});hr.saveAs(n,`${e}.csv`)}function vl(e,t){const n=new Blob([t],{type:"application/json"});hr.saveAs(n,`${e}.json`)}function xl(e){const t=new Pu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,Cl(r))}),t.generateAsync({type:"blob"}).then(n=>{hr.saveAs(n,"dashboard_data.zip")})}function wl(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function Cl(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],n=Object.keys(e[0]).map(wl);return t.push(n.join(",")),e.forEach(r=>{const a=Object.values(r).map(wl).join(",");t.push(a)}),bl+t.join(`
441
+ `)}const Sl=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(hS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));xl(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));xl(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=Cl(a);fS(r,o)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData()}}));function gS(e){return{current:e}}const mS=q1.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),_l=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(mS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function yS(e){return{current:e}}function nr(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=fr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class bS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),re.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const vS=e=>new bS(e),xS=k.observer(({view:e})=>{const t=ye(),n=le(),r=et.useModals(),{panel:a,downloadPanelScreenshot:o}=nt(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(er),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(l)},[l,u]),m=!c&&e.type!==R.Modal;return i(P,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(T.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(T.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i($.IconCamera,{size:14}),children:"Screenshot"}),m&&i(s.Menu.Item,{onClick:g,icon:i(T.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(T.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(T.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(T.Trash,{size:14}),children:"Delete"})]})]})})})});function wS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Mi=k.observer(()=>{const[e,t]=y.useState(!1),{panel:n}=bt();return wS(n.description)?null:p(P,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Nn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(T.InfoCircle,{size:20})})})]})}),HM="",eI="",CS=k.observer(function(){const{panel:t}=bt(),{title:n}=t;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function SS(e){const t=y.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;Qa.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var kl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(kl||{}),rr=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(rr||{});class _S{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(Ce.instanceScope.panelModel),this.vizInstance=t.getRequired(Ce.instanceScope.vizInstance),this.operationManager=t.getRequired(Ce.instanceScope.operationManager),this.triggerManager=t.getRequired(Ce.instanceScope.triggerManager),this.vizManager=t.getRequired(Ce.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Tl(e){const{panel:t}=bt();return y.useCallback(n=>{const r=n.getRequired(Ce.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(Ce.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(Ce.instanceScope.interactionManager,o=>{const l=o.getRequired(Ce.instanceScope.vizInstance);return new Dr(l,a,Tn)}).provideFactory(Ce.instanceScope.operationManager,o=>o.getRequired(Ce.instanceScope.interactionManager).operationManager).provideFactory(Ce.instanceScope.triggerManager,o=>o.getRequired(Ce.instanceScope.interactionManager).triggerManager).provideValue(Ce.instanceScope.panelModel,t).provideFactory(Ce.instanceScope.migrator,o=>new _S(o))},[e.viz.type,e.viz.conf])}function Dl(e){const[t,n]=y.useState(!1),r=jo().getRequired(Ce.instanceScope.migrator);return U.useAsyncEffect(async()=>{const a=r.status===rr.notStarted;n(r.status===rr.done),r.status===rr.notStarted&&r.runMigration().then(o=>{o===kl.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Ml(e,t){const n=jo().getRequired(Ce.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function kS({setVizConf:e,...t}){const{panel:n}=t,r=Ml(e,n),a=Dl(()=>{bn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return U.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(ec,{...t}):i(s.Text,{children:"Checking update..."})}function TS(e){const{panel:t,setVizConf:n}=e;Ml(n,t);const{inEditMode:r}=y.useContext(_n);return Dl(()=>{r&&bn.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Hu,{...e}):i(s.Text,{children:"Checking update"})}const tI="";function DS(e,t){const{vizManager:n}=y.useContext(ut),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=bt(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:t},f=Tl(d);try{return n.resolveComponent(r.type),i(Hn,{configure:f,children:i(TS,{setVizConf:r.setConf,panel:d,data:e,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const Il=k.observer(function({data:t}){const{ref:n,width:r,height:a}=Me.useElementSize(),o=DS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:l&&i(Fe,{children:o})})}),Al=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Ii=k.observer(({panel:e,height:t})=>p(s.Flex,{direction:"column",sx:{height:t,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(Al,{panel:e}),e.canRenderViz&&i(Il,{data:e.data})]})),MS={border:"1px solid #e9ecef"},zl=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=SS(e),o=e.title?"calc(100% - 25px - 5px)":"100%";return i(Sr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:"panel-root",ref:r,p:5,pt:0,sx:{...MS,...t},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(Mi,{})}),n,i(CS,{}),i(Ii,{panel:e,height:o})]})})}),IS={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function AS(e){return e.style.border.enabled?{}:IS}const El=k.observer(function({panel:t,view:n}){const r=AS(t);return i(zl,{panel:t,panelStyle:r,dropdownContent:i(xS,{view:n})})});function zS(e){return!["richText","button"].includes(e)}const ES=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=bt(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=y.useContext(er),l=y.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==R.Modal;return zS(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(T.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(T.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i($.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(T.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function $S(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ai=k.observer(({panel:e,view:t})=>{const n=$S(e);return i(zl,{panel:e,panelStyle:n,dropdownContent:i(ES,{view:t})})}),LS={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},$l=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(T.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:LS,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Ai,{view:t,panel:n})})})});function Ll(e,t,n){const{panels:r}=we(),a=e.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(t)?t:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const nI="",OS=y.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(T.ArrowsMove,{size:16})})),PS=y.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(T.ChevronDownRight,{size:16})})),BS=vn.WidthProvider(vn),VS=k.observer(({view:e,className:t="layout"})=>{const n=we(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(BS,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(PS,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(OS,{h:u.layout.h}),i(El,{view:e,panel:u})]},u.id))})}),NS=vn.WidthProvider(vn),qS=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=we().panels.panelsByIDs(t.panelIDs);return i(NS,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(Ai,{view:t,panel:o})},o.id))})});function zi(e){const t=y.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;Qa.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const FS=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=U.useBoolean(!1),a=wr(),o=we(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;vl(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i($.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i($.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i($.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i($.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Ol=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=zi(t);return p(P,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(FS,{downloadScreenShot:a})]})}),Pl=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i($.IconCamera,{size:14})})),GS=k.observer(({children:e,view:t})=>{const n=we(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=zi(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Pl,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),WS=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},jS=k.observer(({view:e})=>{const t=we(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,defaultValue:n.tabs.length>0?n.tabs[0].id:"0",styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:WS(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(ir,{view:a})},r.id):null})]})}),RS=k.observer(({view:e,children:t})=>{switch(e.type){case R.Modal:return i(GS,{view:e,children:t});case R.Tabs:return i(jS,{view:e});case R.Division:default:return i(Ol,{view:e,children:t})}}),YS=k.observer(({children:e,view:t})=>i(Ol,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function Bl(e){return e.replace(/(vw|vh)/,"%")}const QS=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=y.useMemo(()=>({width:Bl(n.width),height:Bl(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=zi(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Pl,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),KS=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},US=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},XS=k.observer(({view:e})=>{const t=et.useModals(),n=le(),r=y.useMemo(()=>n.views.options.filter(u=>u.type===R.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,defaultValue:a.tabs.length>0?a.tabs[0].id:"0",styles:KS(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:US(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(T.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i($.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i($.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(ir,{view:d})]},u.id)})]})}),JS=k.observer(({view:e,children:t})=>{switch(e.type){case R.Modal:return i(QS,{view:e,children:t});case R.Tabs:return i(XS,{view:e});case R.Division:default:return i(YS,{view:e,children:t})}}),Vl=k.observer(function({view:t}){return i(er.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(JS,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Ko,{view:t})}),i(VS,{view:t})]})})})})}),ir=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=os(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Ll(t,n,r);return i(er.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===R.Modal?"0 !important":"100%"},children:[l&&i($l,{view:t,panel:u,exitFullScreen:o}),i(RS,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Ko,{view:t})}),!l&&i(qS,{view:t})]})})]})})});var Nl=(e=>(e.Use="use",e.Edit="edit",e))(Nl||{});const ZS={[R.Division]:"Division",[R.Tabs]:"Tabs",[R.Modal]:"Modal"},ql={[R.Division]:"rgba(255, 0, 0, 0.2)",[R.Modal]:"rgba(0, 0, 0, 0.2)",[R.Tabs]:"rgba(255, 200, 100, 0.4)"},HS={[R.Division]:"#ff4000",[R.Modal]:"#000",[R.Tabs]:"#ffad18"},e_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:R.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function t_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Fl=b.types.compose("FiltersModel",ml,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===_e.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){t_(e.current,al,(n,r)=>{if(n==="setType"){const a=gl(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Gl=Sl.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))}})),Wl=_l.views(e=>({get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),n_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=b.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;if(n===Se.MySQL)return`
442
442
  SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
443
443
  FROM information_schema.columns
444
444
  WHERE table_name = '${r}' AND table_schema = '${a}'
@@ -501,7 +501,7 @@ Check the top-level render call using <`+V+">.")}return E}}function ku(S,E){{if(
501
501
  `},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
502
502
  SELECT count(*) AS total
503
503
  FROM ${n}.${t}
504
- `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,re.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),a_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get sql(){const t=b.getParent(e,1).type;return t===Se.MySQL||t===Se.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),s_=b.types.compose("DataSourceModel",ul,b.types.model({tables:b.types.optional(a_,{}),columns:b.types.optional(n_,{}),tableData:b.types.optional(i_,{}),indexes:b.types.optional(r_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(qe.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!mt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(qe.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(r){if(mt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(qe.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(mt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(qe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(qe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(mt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,re.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),o_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(s_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function ar(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function l_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const u_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:$.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:$.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:$.IconFilter,children:[...n.options,ar("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:$.IconCopy,children:[...a.options,ar("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:$.IconDatabase,children:[...o.options,ar("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:$.IconBoxMultiple,children:[...r.editorOptions,ar("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=l_(t);n&&e.setPath(n)}})),jl=hl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),Rl=b.types.compose("PanelsModel",fl,b.types.model({list:b.types.optional(b.types.array(jl),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),Yl=b.types.compose("ViewsModel",pl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,R.Division,R.Division,{_name:R.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Ei(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const c_=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Fl,queries:Gl,sqlSnippets:Wl,views:Yl,panels:Rl,mock_context:Uo,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:nr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:nr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({findQueryUsage(t){const n=e.panels.idMap,r=e.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(t))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=e.views.idMap,o=e.filters.current.filter(l=>x.get(l,"config.options_query_id")===t).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(e=>({duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(aS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,Ei(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),$i=b.types.snapshotProcessor(c_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function d_(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function Ql({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return $i.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:yl(u),queries:{current:f},sqlSnippets:{current:h},mock_context:Xo(g),views:Ei(c),panels:{list:d}})}const Kl=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:$i,content_id:b.types.string,datasources:o_,globalSQLSnippets:cl,context:Di,editor:u_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function Ul({id:e,name:t,group:n,content_id:r},a,o,l,u){return Kl.create({id:e,name:t,group:n,content_id:r,content:Ql(a),datasources:{list:o},globalSQLSnippets:{list:l},context:dl(u),editor:{}})}function Xl(e,t){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function Jl(e){return y.useCallback(t=>t.provideValue(Ce.pluginManager,e.pluginManager).provideValue(Ce.vizManager,e.vizManager).provideValue(Ce.colorManager,e.colorManager),[])}const rI="",p_=k.observer(()=>{const e=wr(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;vl(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i($.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i($.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i($.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),h_=k.observer(({saveDashboardChanges:e})=>{const t=et.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i($.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i($.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i($.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i($.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),f_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Bu.useNavigate(),r=ye(),a=()=>{n(`/dashboard/${r.id}`)},o=et.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i($.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i($.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(h_,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(p_,{})]})]})})}),g_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},m_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===R.Tabs;return i(s.Box,{sx:g_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i($.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),y_=k.observer(e=>p(P,{children:[i(f_,{...e}),i(m_,{})]})),iI="";function b_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:C}=m;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function v_(e,t){const n=e.filters.keyLabelMap;return{edges:b_(e.panels.list,t,n),edgeNodes:[]}}function Zl(e,t,n){return e*t+e*n}function x_(e,t,n){return e*t+(e-1)*n}const sr=25,Li=40,Hl=25,Oi=350,w_=150,C_=150,eu=150,tu=300,or=40,nu=25,S_=300;function __(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=Zl(u,or,nu)+Li,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:sr,y:c},sourcePosition:$e.Position.Right,targetPosition:$e.Position.Left,style:{width:tu,height:or}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:sr,y:c},sourcePosition:$e.Position.Right,targetPosition:$e.Position.Left,style:{width:tu,height:or}})})}),r}const k_={[R.Division]:"Div",[R.Modal]:"Modal",[R.Tabs]:"Tabs"},T_=ql;function D_(e){return e.current.map((n,r)=>{const a=x_(n.panelIDs.length,or,nu)+Li+Hl;let o=[];return n.type===R.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${k_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:$e.Position.Right,targetPosition:$e.Position.Left,className:"light",style:{backgroundColor:T_[n.type],width:Oi,height:a}}})}function M_(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==R.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function I_(e){const t=D_(e.views);M_(t);const n=__(e.views,e.panels.list);return[...t,...n]}function A_({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==R.Tabs||(r.sourcePosition=$e.Position.Bottom,r.style.width=Oi+sr*2,r.style.height=Hl+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=sr;const u=l.style.height;return a+u+20},Li))})}function z_({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function E_({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+S_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=$e.Position.Left,l.targetPosition=$e.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+eu}})}function $_({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=Zl(u,Oi,C_),l.position.y=0-w_-eu})}function L_({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return $_(r),z_(r),A_(r),E_(r),{nodes:t,edges:n}}function O_(e){const t=I_(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=v_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return L_(u)}const aI="",Pi={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i($.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i($.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i($.IconCircleOff,{size:14})})};function P_(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Pi[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Pi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Pi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const B_=y.memo(({data:e,isConnectable:t,sourcePosition:n=$e.Position.Right,targetPosition:r=$e.Position.Left,...a})=>{const o=y.useMemo(()=>P_(e.interactions),[e.interactions]);return p(P,{children:[i($e.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(T.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i($e.Handle,{type:"source",position:n,isConnectable:t})]})}),sI="",V_={interaction:B_},N_=k.observer(()=>{const e=we(),{edges:t,nodes:n}=O_(e);return p($e,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:V_,children:[i($e.MiniMap,{}),i($e.Controls,{}),i($e.Background,{})]})}),q_=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(N_,{})})),F_={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function G_({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i($.IconAdjustments,{size:16})})})]})}const W_=k.observer(()=>{const e=ye(),t=le(),n=y.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(G_,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),j_=k.observer(()=>{const e=ye(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...F_,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i($.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i($.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i($.IconLink,{size:18})})})]}),i(q_,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(W_,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i($.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),R_=k.observer(function({config:t}){return p(P,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(oi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),Y_=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Q_=k.observer(function({config:t}){return p(P,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:Y_,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(Ro,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Bi=k.observer(({value:e,onChange:t})=>{const n=le(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),K_=`
504
+ `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,re.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),a_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get sql(){const t=b.getParent(e,1).type;return t===Se.MySQL||t===Se.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),s_=b.types.compose("DataSourceModel",ul,b.types.model({tables:b.types.optional(a_,{}),columns:b.types.optional(n_,{}),tableData:b.types.optional(i_,{}),indexes:b.types.optional(r_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(qe.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!mt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(qe.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(r){if(mt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(qe.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(mt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(qe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(qe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(mt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,re.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,re.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),o_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(s_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function ar(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function l_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const u_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:$.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:$.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:$.IconFilter,children:[...n.options,ar("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:$.IconCopy,children:[...a.options,ar("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:$.IconDatabase,children:[...o.options,ar("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:$.IconBoxMultiple,children:[...r.editorOptions,ar("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=l_(t);n&&e.setPath(n)}})),jl=hl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),Rl=b.types.compose("PanelsModel",fl,b.types.model({list:b.types.optional(b.types.array(jl),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),Yl=b.types.compose("ViewsModel",pl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,R.Division,R.Division,{_name:R.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Ei(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const c_=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Fl,queries:Gl,sqlSnippets:Wl,views:Yl,panels:Rl,mock_context:Uo,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:nr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:nr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({findQueryUsage(t){const n=e.panels.idMap,r=e.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(t))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=e.views.idMap,o=e.filters.current.filter(l=>x.get(l,"config.options_query_id")===t).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(e=>({duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(aS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,Ei(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),$i=b.types.snapshotProcessor(c_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function d_(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function Ql({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return $i.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:yl(u),queries:{current:f},sqlSnippets:{current:h},mock_context:Xo(g),views:Ei(c),panels:{list:d}})}const Kl=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:$i,content_id:b.types.string,datasources:o_,globalSQLSnippets:cl,context:Di,editor:u_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function Ul({id:e,name:t,group:n,content_id:r},a,o,l,u){return Kl.create({id:e,name:t,group:n,content_id:r,content:Ql(a),datasources:{list:o},globalSQLSnippets:{list:l},context:dl(u),editor:{}})}function Xl(e,t){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function Jl(e){return y.useCallback(t=>t.provideValue(Ce.pluginManager,e.pluginManager).provideValue(Ce.vizManager,e.vizManager).provideValue(Ce.colorManager,e.colorManager),[])}const rI="",p_=k.observer(()=>{const e=wr(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;vl(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i($.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i($.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i($.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),h_=k.observer(({saveDashboardChanges:e})=>{const t=et.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i($.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i($.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i($.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i($.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),f_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Bu.useNavigate(),r=ye(),a=()=>{n(`/dashboard/${r.id}`)},o=et.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i($.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i($.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(h_,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(p_,{})]})]})})}),g_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},m_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===R.Tabs;return i(s.Box,{sx:g_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i($.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),y_=k.observer(e=>p(P,{children:[i(f_,{...e}),i(m_,{})]})),iI="";function b_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:C}=m;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function v_(e,t){const n=e.filters.keyLabelMap;return{edges:b_(e.panels.list,t,n),edgeNodes:[]}}function Zl(e,t,n){return e*t+e*n}function x_(e,t,n){return e*t+(e-1)*n}const sr=25,Li=40,Hl=25,Oi=350,w_=150,C_=150,eu=150,tu=300,or=40,nu=25,S_=300;function __(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=Zl(u,or,nu)+Li,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:sr,y:c},sourcePosition:$e.Position.Right,targetPosition:$e.Position.Left,style:{width:tu,height:or}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:sr,y:c},sourcePosition:$e.Position.Right,targetPosition:$e.Position.Left,style:{width:tu,height:or}})})}),r}const k_={[R.Division]:"Div",[R.Modal]:"Modal",[R.Tabs]:"Tabs"},T_=ql;function D_(e){return e.current.map((n,r)=>{const a=x_(n.panelIDs.length,or,nu)+Li+Hl;let o=[];return n.type===R.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${k_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:$e.Position.Right,targetPosition:$e.Position.Left,className:"light",style:{backgroundColor:T_[n.type],width:Oi,height:a}}})}function M_(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==R.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function I_(e){const t=D_(e.views);M_(t);const n=__(e.views,e.panels.list);return[...t,...n]}function A_({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==R.Tabs||(r.sourcePosition=$e.Position.Bottom,r.style.width=Oi+sr*2,r.style.height=Hl+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=sr;const u=l.style.height;return a+u+20},Li))})}function z_({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function E_({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+S_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=$e.Position.Left,l.targetPosition=$e.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+eu}})}function $_({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=Zl(u,Oi,C_),l.position.y=0-w_-eu})}function L_({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return $_(r),z_(r),A_(r),E_(r),{nodes:t,edges:n}}function O_(e){const t=I_(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=v_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return L_(u)}const aI="",Pi={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i($.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i($.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i($.IconCircleOff,{size:14})})};function P_(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Pi[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Pi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Pi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const B_=y.memo(({data:e,isConnectable:t,sourcePosition:n=$e.Position.Right,targetPosition:r=$e.Position.Left,...a})=>{const o=y.useMemo(()=>P_(e.interactions),[e.interactions]);return p(P,{children:[i($e.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(T.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i($e.Handle,{type:"source",position:n,isConnectable:t})]})}),sI="",V_={interaction:B_},N_=k.observer(()=>{const e=we(),{edges:t,nodes:n}=O_(e);return p($e,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:V_,children:[i($e.MiniMap,{}),i($e.Controls,{}),i($e.Background,{})]})}),q_=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(N_,{})})),F_={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function G_({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i($.IconAdjustments,{size:16})})})]})}const W_=k.observer(()=>{const e=ye(),t=le(),n=y.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(G_,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),j_=k.observer(()=>{const e=ye(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...F_,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i($.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i($.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i($.IconLink,{size:18})})})]}),i(q_,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(W_,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i($.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),R_=k.observer(function({config:t}){return p(P,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(oi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),Y_=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Q_=k.observer(function({config:t}){return p(P,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:Y_,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(Ro,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Bi=k.observer(({value:e,onChange:t})=>{const n=le(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),K_=`
505
505
  // row
506
506
  {
507
507
  label: string;
@@ -533,4 +533,4 @@ WHERE
533
533
  `),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
534
534
  `)},sT=k.observer(({queryModel:e})=>e.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(qi,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:pu.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:pu.post})})]}):null),oT=k.observer(({queryID:e,usage:t})=>{const n=ye().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:t.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Fi=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{t==null||t(u??"")},l=!t;return i(Ae,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},lT=({value:e,onChange:t,defaultValue:n})=>{const[r,a]=y.useState(e),o=()=>{t(r)},l=()=>{a(e)},u=()=>{a(n)};y.useEffect(()=>{a(e)},[e]);const c=r!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(s.Button,{onClick:u,size:"xs",variant:"default",leftIcon:i($.IconPlayerSkipBack,{size:16}),children:"Reset to default"})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:l,color:"red",size:"xs",disabled:!c,leftIcon:i($.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:o,disabled:!c,leftIcon:i($.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(Fi,{height:"100%",value:r,onChange:a,theme:"sql-dark",defaultLanguage:"sql"})]})},uT=({value:e,height:t="200px",defaultLanguage:n="sql"})=>i(Ae,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),cT=k.observer(({value:e})=>{const n=we().payloadForSQL,r=y.useMemo(()=>gr(e,n),[e,n]);return i(uT,{height:"100%",value:r})}),hu={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
535
535
  `),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
536
- `)},dT=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(qi,{}),e.datasource&&i(uu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(lT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(cT,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:hu.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:hu.post})})]}):null),lr={height:"calc(100% - 44px)",padding:0},pT=k.observer(({queryModel:e})=>{const t=le(),n=y.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(nT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:lr,children:i(s.Stack,{sx:{height:"100%"},children:i(dT,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:lr,children:i(s.Stack,{sx:{height:"100%"},children:i(sT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...lr,overflow:"hidden"},children:i(Vi,{id:e.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...lr,overflow:"hidden"},children:i(oT,{queryID:e.id,usage:o})})]})})}),hT=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(pT,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),fT=k.observer(({value:e})=>{const n=we().payloadForSQL,r=y.useMemo(()=>gr(e,n),[e,n]);return i(Fi,{height:"100%",value:r})}),gT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=y.useState(e.value),g=()=>{e.setValue(f)};y.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=f!==e.value,C=et.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(T.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(qi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(T.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Fi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(fT,{value:f})})]})]})}),mT=k.observer(({id:e})=>{const t=ye(),n=le(),r=y.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(gT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),yT=k.observer(({view:e})=>!e||e.type!==R.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),bT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],vT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],xT=k.observer(({view:e})=>{if(!e||e.type!==R.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:bT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:vT}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),wT=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},CT=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=U.useBoolean(),[o,l]=y.useState(e??Ti),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(Ti.func_content)};return p(P,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(T.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(wT,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},ST=k.observer(({view:e})=>{if(!e||e.type!==R.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(CT,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),_T=k.observer(({view:e})=>p(P,{children:[i(yT,{view:e}),i(ST,{view:e}),i(xT,{view:e})]})),kT=[{label:"Division",value:R.Division},{label:"Modal",value:R.Modal},{label:"Tabs",value:R.Tabs}],TT=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:kT}),i(_T,{view:e})]}):null),DT=k.observer(({id:e})=>{const t=et.useModals(),n=ye(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(T.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(TT,{view:a})})]})});function MT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function IT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function AT(e){return e.length===2&&e[0]==="_FILTERS_"}function zT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function ET(e){return e.length===2&&e[0]==="_QUERIES_"}function $T(e){return e.length===2&&e[0]==="_VIEWS_"}function LT(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const OT=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(du,{})})),PT=k.observer(()=>{const e=ye().editor,t=e.path;return MT(t)?i(OT,{}):IT(t)?i(sk,{}):AT(t)?i(s.Box,{p:"xs",pl:20,children:i(ak,{id:t[1]})}):zT(t)?i(mT,{id:t[1]}):ET(t)?i(hT,{id:t[1]}):$T(t)?i(s.Box,{p:"xs",pl:20,children:i(DT,{id:t[1]})}):LT(t)?i(Ok,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),BT=k.observer(()=>i(PT,{})),VT=k.observer(()=>{const e=ye(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:_e.TextInput,config:rl(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),NT=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===R.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),qT=k.observer(()=>{const e=ye(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Se.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),FT=k.observer(()=>{const e=ye(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),GT=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),WT=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(VT,{}):e==="_Add_A_SQL_SNIPPET_"?i(FT,{}):e==="_Add_A_QUERY_"?i(qT,{}):e==="_Add_A_VIEW_"?i(GT,{}):e==="_Add_A_PANEL_"?i(NT,{parentID:t}):null),fu=k.observer(({option:e})=>{var d;const t=ye().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(WT,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(fu,{option:f},f.value))},e.label)}),jT=k.observer(()=>{const e=ye();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(fu,{option:t},t.value))})}),RT=k.observer(()=>{const e=ye();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(jT,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i($.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),YT={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},QT=k.observer(()=>{const e=ye().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(RT,{}),styles:YT,children:i(BT,{})})})}),KT=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function UT(e){y.useEffect(()=>{if(Ae.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=KT(e);Ae.loader.config({paths:{vs:n}}),Ae.loader.init().then(r=>console.log("monaco instance:",r))},[])}so();const XT={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},JT=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{UT(o.monacoPath),Xa(o);const{data:d=[]}=U.useRequest(mr),{data:f=[]}=U.useRequest(Ja),h=y.useMemo(()=>Ul(t,n,d,f,e),[t,n]);y.useImperativeHandle(c,()=>h,[h]),Xl(h.content,!0),y.useEffect(()=>{h.context.replace(e)},[e]),y.useEffect(()=>{h.datasources.replace(d)},[d]),y.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),y.useEffect(()=>re.reaction(()=>re.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},m=U.useCreation(Si,[]),C=Jl(m);return i(et.ModalsProvider,{children:i(vr,{value:h,children:i(Cr,{value:h.content,children:i(_n.Provider,{value:{inEditMode:!0},children:i(ut.Provider,{value:m,children:p(Hn,{configure:C,children:[i(s.AppShell,{padding:0,header:i(y_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(j_,{}),styles:XT,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Vl,{view:w},w.id))})}),i(QT,{})]})})})})})})},ZT=k.observer(y.forwardRef(JT)),oI="",gu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:ml,queries:Sl,sqlSnippets:_l,views:pl,panels:fl,mock_context:Uo}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:nr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:nr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function HT({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return gu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:yl(u),queries:gS(f),sqlSnippets:yS(h),mock_context:Xo(g),views:iS(c),panels:{list:d}})}const eD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:gu,content_id:b.types.string,datasources:nS,globalSQLSnippets:cl,context:Di});function tD({id:e,name:t,group:n,content_id:r},a,o,l,u){return eD.create({id:e,name:t,group:n,content_id:r,content:HT(a),datasources:{list:o},globalSQLSnippets:{list:l},context:dl(u)})}so();const nD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Xa(a);const{data:u=[]}=U.useRequest(mr),{data:c=[]}=U.useRequest(Ja),d=y.useMemo(()=>tD(t,n,u,c,e),[t,n]);Xl(d.content,!1),y.useEffect(()=>{d.context.replace(e)},[e]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=U.useCreation(Si,[]),h=Jl(f);return i(et.ModalsProvider,{children:i(vr,{value:d,children:i(Cr,{value:d.content,children:i(_r.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(_n.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ut.Provider,{value:f,children:i(Hn,{configure:h,children:d.content.views.visibleViews.map(g=>i(ir,{view:g},g.id))})})})})})})})})});var Gi={},rD={get exports(){return Gi},set exports(e){Gi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(rD);const iD=Gi;var Wi={},aD={get exports(){return Wi},set exports(e){Wi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(aD);const sD=Wi;var ji={},oD={get exports(){return ji},set exports(e){ji=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,C){return this.$utils().u(g)?this[m]:this.$set(C,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(oD);const lD=ji;var Ri={},uD={get exports(){return Ri},set exports(e){Ri=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(uD);const cD=Ri;var Yi={},dD={get exports(){return Yi},set exports(e){Yi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[m]||l[m];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(dD);const pD=Yi;var Qi={},hD={get exports(){return Qi},set exports(e){Qi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var D=_.match(/([+-]|\d\d)/g),I=60*D[1]+(+D[2]||0);return I===0?0:D[0]==="+"?-I:I}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var D,I=u.meridiem;if(I){for(var B=1;B<=24;B+=1)if(w.indexOf(I(B,0,_))>-1){D=B>12;break}}else D=w===(_?"pm":"PM");return D},m={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,D=w.match(/\d+/);if(this.day=D[0],_)for(var I=1;I<=31;I+=1)_(I).replace(/\[|\]/g,"")===w&&(this.day=I)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),D=(h("monthsShort")||_.map(function(I){return I.slice(0,3)})).indexOf(w)+1;if(D<1)throw new Error;this.month=D%12||D}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,D;_=w,D=u&&u.formats;for(var I=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(X,Q,H){var oe=H&&H.toUpperCase();return Q||D[H]||n[H]||D[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(ue,be,Ee){return be||Ee.slice(1)})})).match(r),B=I.length,N=0;N<B;N+=1){var O=I[N],z=m[O],A=z&&z[0],G=z&&z[1];I[N]=G?{regex:A,parser:G}:O.replace(/^\[|\]$/g,"")}return function(X){for(var Q={},H=0,oe=0;H<B;H+=1){var ue=I[H];if(typeof ue=="string")oe+=ue.length;else{var be=ue.regex,Ee=ue.parser,fe=X.slice(oe),ve=be.exec(fe)[0];Ee.call(Q,ve),X=X.replace(ve,"")}}return function(ge){var Oe=ge.afternoon;if(Oe!==void 0){var Ze=ge.hours;Oe?Ze<12&&(ge.hours+=12):Ze===12&&(ge.hours=0),delete ge.afternoon}}(Q),Q}}return function(w,_,D){D.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var I=_.prototype,B=I.parse;I.parse=function(N){var O=N.date,z=N.utc,A=N.args;this.$u=z;var G=A[1];if(typeof G=="string"){var X=A[2]===!0,Q=A[3]===!0,H=X||Q,oe=A[2];Q&&(oe=A[2]),u=this.$locale(),!X&&oe&&(u=D.Ls[oe]),this.$d=function(fe,ve,ge){try{if(["x","X"].indexOf(ve)>-1)return new Date((ve==="X"?1e3:1)*fe);var Oe=C(ve)(fe),Ze=Oe.year,$t=Oe.month,ur=Oe.day,cr=Oe.hours,Ca=Oe.minutes,Sa=Oe.seconds,hn=Oe.milliseconds,jt=Oe.zone,wt=new Date,Lt=ur||(Ze||$t?1:wt.getDate()),Ct=Ze||wt.getFullYear(),Rt=0;Ze&&!$t||(Rt=$t>0?$t-1:wt.getMonth());var Yt=cr||0,fn=Ca||0,gn=Sa||0,St=hn||0;return jt?new Date(Date.UTC(Ct,Rt,Lt,Yt,fn,gn,St+60*jt.offset*1e3)):ge?new Date(Date.UTC(Ct,Rt,Lt,Yt,fn,gn,St)):new Date(Ct,Rt,Lt,Yt,fn,gn,St)}catch{return new Date("")}}(O,G,z),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),H&&O!=this.format(G)&&(this.$d=new Date("")),u={}}else if(G instanceof Array)for(var ue=G.length,be=1;be<=ue;be+=1){A[1]=G[be-1];var Ee=D.apply(this,A);if(Ee.isValid()){this.$d=Ee.$d,this.$L=Ee.$L,this.init();break}be===ue&&(this.$d=new Date(""))}else B.call(this,N)}}})})(hD);const fD=Qi;var Ki={},gD={get exports(){return Ki},set exports(e){Ki=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(gD);const mD=Ki;var Ui={},yD={get exports(){return Ui},set exports(e){Ui=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function(O){return O instanceof N},C=function(O,z,A){return new N(O,A,z.$l)},w=function(O){return r.p(O)+"s"},_=function(O){return O<0},D=function(O){return _(O)?Math.ceil(O):Math.floor(O)},I=function(O){return Math.abs(O)},B=function(O,z){return O?_(O)?{negative:!0,format:""+I(O)+z}:{negative:!1,format:""+O+z}:{negative:!1,format:""}},N=function(){function O(A,G,X){var Q=this;if(this.$d={},this.$l=X,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),G)return C(A*g[w(G)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(ue){Q.$d[w(ue)]=A[ue]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var oe=H.slice(2).map(function(ue){return ue!=null?Number(ue):0});return this.$d.years=oe[0],this.$d.months=oe[1],this.$d.weeks=oe[2],this.$d.days=oe[3],this.$d.hours=oe[4],this.$d.minutes=oe[5],this.$d.seconds=oe[6],this.calMilliseconds(),this}}return this}var z=O.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(G,X){return G+(A.$d[X]||0)*g[X]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=D(A/d),A%=d,this.$d.months=D(A/f),A%=f,this.$d.days=D(A/u),A%=u,this.$d.hours=D(A/l),A%=l,this.$d.minutes=D(A/o),A%=o,this.$d.seconds=D(A/a),A%=a,this.$d.milliseconds=A},z.toISOString=function(){var A=B(this.$d.years,"Y"),G=B(this.$d.months,"M"),X=+this.$d.days||0;this.$d.weeks&&(X+=7*this.$d.weeks);var Q=B(X,"D"),H=B(this.$d.hours,"H"),oe=B(this.$d.minutes,"M"),ue=this.$d.seconds||0;this.$d.milliseconds&&(ue+=this.$d.milliseconds/1e3);var be=B(ue,"S"),Ee=A.negative||G.negative||Q.negative||H.negative||oe.negative||be.negative,fe=H.format||oe.format||be.format?"T":"",ve=(Ee?"-":"")+"P"+A.format+G.format+Q.format+fe+H.format+oe.format+be.format;return ve==="P"||ve==="-P"?"P0D":ve},z.toJSON=function(){return this.toISOString()},z.format=function(A){var G=A||"YYYY-MM-DDTHH:mm:ss",X={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return G.replace(c,function(Q,H){return H||String(X[Q])})},z.as=function(A){return this.$ms/g[w(A)]},z.get=function(A){var G=this.$ms,X=w(A);return X==="milliseconds"?G%=1e3:G=X==="weeks"?D(G/g[X]):this.$d[X],G===0?0:G},z.add=function(A,G,X){var Q;return Q=G?A*g[w(G)]:m(A)?A.$ms:C(A,this).$ms,C(this.$ms+Q*(X?-1:1),this)},z.subtract=function(A,G){return this.add(A,G,!0)},z.locale=function(A){var G=this.clone();return G.$l=A,G},z.clone=function(){return C(this.$ms,this)},z.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},z.milliseconds=function(){return this.get("milliseconds")},z.asMilliseconds=function(){return this.as("milliseconds")},z.seconds=function(){return this.get("seconds")},z.asSeconds=function(){return this.as("seconds")},z.minutes=function(){return this.get("minutes")},z.asMinutes=function(){return this.as("minutes")},z.hours=function(){return this.get("hours")},z.asHours=function(){return this.as("hours")},z.days=function(){return this.get("days")},z.asDays=function(){return this.as("days")},z.weeks=function(){return this.get("weeks")},z.asWeeks=function(){return this.as("weeks")},z.months=function(){return this.get("months")},z.asMonths=function(){return this.as("months")},z.years=function(){return this.get("years")},z.asYears=function(){return this.as("years")},O}();return function(O,z,A){n=A,r=A().$utils(),A.duration=function(Q,H){var oe=A.locale();return C(Q,{$l:oe},H)},A.isDuration=m;var G=z.prototype.add,X=z.prototype.subtract;z.prototype.add=function(Q,H){return m(Q)&&(Q=Q.asMilliseconds()),G.bind(this)(Q,H)},z.prototype.subtract=function(Q,H){return m(Q)&&(Q=Q.asMilliseconds()),X.bind(this)(Q,H)}}})})(yD);const bD=Ui;var Xi={},vD={get exports(){return Xi},set exports(e){Xi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(vD);const xD=Xi;var Ji={},wD={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(wD);const CD=Ji;var Zi={},SD={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(SD);const _D=Zi;var Hi={},kD={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(kD);const TD=Hi;var ea={},DD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(DD);const MD=ea;var ta={},ID={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(ID);const AD=ta;var na={},zD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(zD);const ED=na;var ra={},$D={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})($D);const LD=ra;var ia={},OD={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(OD);const PD=ia;var aa={},BD={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(BD);const VD=aa;var sa={},ND={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,C,w){var _=h.name?h:h.$locale(),D=l(_[g]),I=l(_[m]),B=D||I.map(function(O){return O.slice(0,C)});if(!w)return B;var N=_.weekStart;return B.map(function(O,z){return B[(z+(N||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(ND);const qD=sa;var oa={},FD={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(D,I,B){return I||B.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(FD);const GD=oa;var la={},WD={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(WD);const jD=la;var ua={},RD={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var D=w?a.utc():a();Object.keys(C).forEach(function(X){var Q,H;_[Q=X,H=o.$utils().p(Q),H==="date"?"day":H]=C[X]});var I=_.day||(_.year||_.month>=0?1:D.date()),B=_.year||D.year(),N=_.month>=0?_.month:_.year||_.day?0:D.month(),O=_.hour||0,z=_.minute||0,A=_.second||0,G=_.millisecond||0;return w?new Date(Date.UTC(B,N,I,O,z,A,G)):new Date(B,N,I,O,z,A,G)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,C,w){w===void 0&&(w=1);var _=Object.keys(m),D=this;return _.forEach(function(I){D=g.bind(D)(m[I]*w,I)}),D};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(RD);const YD=ua;var ca={},QD={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(QD);const KD=ca;var da={},UD={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(UD);const XD=da;var pa={},JD={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(JD);const ZD=pa;var ha={},HD={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var C,w,_,D=h.$locale().relativeTime||l,I=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],B=I.length,N=0;N<B;N+=1){var O=I[N];O.d&&(C=g?a(d).diff(h,O.d,!0):h.diff(d,O.d,!0));var z=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,z<=O.r||!O.r){z<=1&&N>0&&(O=I[N-1]);var A=D[O.l];m&&(z=m(""+z)),w=typeof A=="string"?A.replace("%d",z):A(z,f,O.l,_);break}}if(f)return w;var G=_?D.future:D.past;return typeof G=="function"?G(w):G.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(HD);const eM=ha;var fa={},tM={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(D,I){I===void 0&&(I={});var B=I.timeZoneName||"short",N=D+"|"+B,O=r[N];return O||(O=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:B}),r[N]=O),O}(m,C);return _.formatToParts(w)},d=function(g,m){for(var C=c(g,m),w=[],_=0;_<C.length;_+=1){var D=C[_],I=D.type,B=D.value,N=n[I];N>=0&&(w[N]=parseInt(B,10))}var O=w[3],z=O===24?0:O,A=w[0]+"-"+w[1]+"-"+w[2]+" "+z+":"+w[4]+":"+w[5]+":000",G=+g;return(l.utc(A).valueOf()-(G-=G%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),D=Math.round((w-new Date(_))/1e3/60),I=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-D,!0);if(m){var B=I.utcOffset();I=I.add(C-B,"minute")}return I.$x.$timezone=g,I},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),m,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,C){var w=C&&m,_=C||m||u,D=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var I=function(z,A,G){var X=z-60*A*1e3,Q=d(X,G);if(A===Q)return[X,A];var H=d(X-=60*(Q-A)*1e3,G);return Q===H?[X,Q]:[z-60*Math.min(Q,H)*1e3,Math.max(Q,H)]}(l.utc(g,w).valueOf(),D,_),B=I[0],N=I[1],O=l(B).utcOffset(N);return O.$x.$timezone=_,O},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(tM);const nM=fa;var ga={},rM={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(rM);const iM=ga;var ma={},aM={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(aM);const sM=ma;var ya={},oM={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(oM);const lM=ya;var ba={},uM={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var D=this.$utils().u;if(D(w))return this.$u?0:D(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function(O){O===void 0&&(O="");var z=O.match(r);if(!z)return null;var A=(""+z[0]).match(a)||["-",0,0],G=A[0],X=60*+A[1]+ +A[2];return X===0?0:G==="+"?X:-X}(w),w===null))return this;var I=Math.abs(w)<=16?60*w:w,B=this;if(_)return B.$offset=I,B.$u=w===0,B;if(w!==0){var N=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(B=this.local().add(I+N,n)).$offset=I,B.$x.$localOffset=N}else B=this.utc();return B};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var m=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var C=c.diff;c.diff=function(w,_,D){if(w&&this.$u===w.$u)return C.call(this,w,_,D);var I=this.local(),B=u(w).local();return C.call(I,B,_,D)}}})})(uM);const cM=ba;var va={},dM={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(dM);const pM=va;var xa={},hM={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(hM);const fM=xa;var wa={},gM={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(gM);const mM=wa;Y.extend(iD),Y.extend(sD),Y.extend(lD),Y.extend(cD),Y.extend(pD),Y.extend(fD),Y.extend(mD),Y.extend(bD),Y.extend(xD),Y.extend(CD),Y.extend(_D),Y.extend(AD),Y.extend(ED),Y.extend(LD),Y.extend(PD),Y.extend(VD),Y.extend(TD),Y.extend(MD),Y.extend(qD),Y.extend(GD),Y.extend(jD),Y.extend(YD),Y.extend(KD),Y.extend(XD),Y.extend(ZD),Y.extend(eM),Y.extend(nM),Y.extend(iM),Y.extend(sM),Y.extend(lM),Y.extend(cM),Y.extend(fM),Y.extend(mM),Y.extend(pM),Y.tz.setDefault("UTC");const yM=()=>Promise.resolve().then(()=>lc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));M.ContentModel=$i,M.ContentModelContextProvider=Cr,M.DashboardEditor=ZT,M.DashboardFilterType=_e,M.DashboardMode=Nl,M.DashboardModel=Kl,M.DashboardModelContextProvider=vr,M.DashboardViewEditor=Vl,M.DashboardViewRender=ir,M.DescriptionPopover=Mi,M.FiltersModel=Fl,M.FullScreenPanel=$l,M.FullScreenPanelContext=_r,M.LayoutStateContext=_n,M.Panel=El,M.PanelContextProvider=Sr,M.PanelErrorOrStateMessage=Al,M.PanelModel=jl,M.PanelRender=Ai,M.PanelVizSection=Ii,M.PanelsModel=Rl,M.QueriesModel=Gl,M.ReadOnlyDashboard=nD,M.SQLSnippetsModel=Wl,M.ViewComponentTypeBackground=ql,M.ViewComponentTypeColor=HS,M.ViewComponentTypeName=ZS,M.ViewsModel=Yl,M.Viz=Il,M.applyPartialDashboard=d_,M.createContentModel=Ql,M.createDashboardModel=Ul,M.getInitialDashboardViewsModel=Ei,M.getVersion=yM,M.initialDashboardContent=e_,M.useDashboardContext=xr,M.useEditContentModelContext=le,M.useEditDashboardContext=ye,M.useEditPanelContext=nt,M.useFullScreenPanelContext=os,M.usePanelFullScreen=Ll,M.useRenderContentModelContext=we,M.useRenderDashboardContext=wr,M.useRenderPanelContext=bt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
536
+ `)},dT=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(qi,{}),e.datasource&&i(uu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(lT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(cT,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:hu.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:hu.post})})]}):null),lr={height:"calc(100% - 44px)",padding:0},pT=k.observer(({queryModel:e})=>{const t=le(),n=y.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(nT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:lr,children:i(s.Stack,{sx:{height:"100%"},children:i(dT,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:lr,children:i(s.Stack,{sx:{height:"100%"},children:i(sT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...lr,overflow:"hidden"},children:i(Vi,{id:e.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...lr,overflow:"hidden"},children:i(oT,{queryID:e.id,usage:o})})]})})}),hT=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(pT,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),fT=k.observer(({value:e})=>{const n=we().payloadForSQL,r=y.useMemo(()=>gr(e,n),[e,n]);return i(Fi,{height:"100%",value:r})}),gT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=y.useState(e.value),g=()=>{e.setValue(f)};y.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=f!==e.value,C=et.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(T.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(qi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(T.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Fi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(fT,{value:f})})]})]})}),mT=k.observer(({id:e})=>{const t=ye(),n=le(),r=y.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(gT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),yT=k.observer(({view:e})=>!e||e.type!==R.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),bT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],vT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],xT=k.observer(({view:e})=>{if(!e||e.type!==R.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:bT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:vT}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),wT=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},CT=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=U.useBoolean(),[o,l]=y.useState(e??Ti),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(Ti.func_content)};return p(P,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(T.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(wT,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},ST=k.observer(({view:e})=>{if(!e||e.type!==R.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(CT,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),_T=k.observer(({view:e})=>p(P,{children:[i(yT,{view:e}),i(ST,{view:e}),i(xT,{view:e})]})),kT=[{label:"Division",value:R.Division},{label:"Modal",value:R.Modal},{label:"Tabs",value:R.Tabs}],TT=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:kT}),i(_T,{view:e})]}):null),DT=k.observer(({id:e})=>{const t=et.useModals(),n=ye(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(T.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(TT,{view:a})})]})});function MT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function IT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function AT(e){return e.length===2&&e[0]==="_FILTERS_"}function zT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function ET(e){return e.length===2&&e[0]==="_QUERIES_"}function $T(e){return e.length===2&&e[0]==="_VIEWS_"}function LT(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const OT=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(du,{})})),PT=k.observer(()=>{const e=ye().editor,t=e.path;return MT(t)?i(OT,{}):IT(t)?i(sk,{}):AT(t)?i(s.Box,{p:"xs",pl:20,children:i(ak,{id:t[1]})}):zT(t)?i(mT,{id:t[1]}):ET(t)?i(hT,{id:t[1]}):$T(t)?i(s.Box,{p:"xs",pl:20,children:i(DT,{id:t[1]})}):LT(t)?i(Ok,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),BT=k.observer(()=>i(PT,{})),VT=k.observer(()=>{const e=ye(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:_e.TextInput,config:rl(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),NT=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===R.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),qT=k.observer(()=>{const e=ye(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Se.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),FT=k.observer(()=>{const e=ye(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),GT=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i($.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),WT=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(VT,{}):e==="_Add_A_SQL_SNIPPET_"?i(FT,{}):e==="_Add_A_QUERY_"?i(qT,{}):e==="_Add_A_VIEW_"?i(GT,{}):e==="_Add_A_PANEL_"?i(NT,{parentID:t}):null),fu=k.observer(({option:e})=>{var d;const t=ye().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(WT,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(fu,{option:f},f.value))},e.label)}),jT=k.observer(()=>{const e=ye();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(fu,{option:t},t.value))})}),RT=k.observer(()=>{const e=ye();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(jT,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i($.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),YT={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},QT=k.observer(()=>{const e=ye().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(RT,{}),styles:YT,children:i(BT,{})})})}),KT=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function UT(e){y.useEffect(()=>{if(Ae.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=KT(e);Ae.loader.config({paths:{vs:n}}),Ae.loader.init().then(r=>console.log("monaco instance:",r))},[])}so();const XT={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},JT=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{UT(o.monacoPath),Xa(o);const{data:d=[]}=U.useRequest(mr),{data:f=[]}=U.useRequest(Ja),h=y.useMemo(()=>Ul(t,n,d,f,e),[t,n]);y.useImperativeHandle(c,()=>h,[h]),Xl(h.content,!0),y.useEffect(()=>{h.context.replace(e)},[e]),y.useEffect(()=>{h.datasources.replace(d)},[d]),y.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),y.useEffect(()=>re.reaction(()=>re.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},m=U.useCreation(Si,[]),C=Jl(m);return i(et.ModalsProvider,{children:i(vr,{value:h,children:i(Cr,{value:h.content,children:i(_n.Provider,{value:{inEditMode:!0},children:i(ut.Provider,{value:m,children:p(Hn,{configure:C,children:[i(s.AppShell,{padding:0,header:i(y_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(j_,{}),styles:XT,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Vl,{view:w},w.id))})}),i(QT,{})]})})})})})})},ZT=k.observer(y.forwardRef(JT)),oI="",gu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:ml,queries:Sl,sqlSnippets:_l,views:pl,panels:fl,mock_context:Uo}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:nr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:nr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function HT({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return gu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:yl(u),queries:gS(f),sqlSnippets:yS(h),mock_context:Xo(g),views:iS(c),panels:{list:d}})}const eD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:gu,content_id:b.types.string,datasources:nS,globalSQLSnippets:cl,context:Di});function tD({id:e,name:t,group:n,content_id:r},a,o,l,u){return eD.create({id:e,name:t,group:n,content_id:r,content:HT(a),datasources:{list:o},globalSQLSnippets:{list:l},context:dl(u)})}so();const nD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Xa(a);const{data:u=[]}=U.useRequest(mr),{data:c=[]}=U.useRequest(Ja),d=y.useMemo(()=>tD(t,n,u,c,e),[t,n]);Xl(d.content,!1),y.useEffect(()=>{d.context.replace(e)},[e]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=U.useCreation(Si,[]),h=Jl(f);return i(et.ModalsProvider,{children:i(vr,{value:d,children:i(Cr,{value:d.content,children:i(_r.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(_n.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ut.Provider,{value:f,children:i(Hn,{configure:h,children:d.content.views.visibleViews.map(g=>i(ir,{view:g},g.id))})})})})})})})})});var Gi={},rD={get exports(){return Gi},set exports(e){Gi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(rD);const iD=Gi;var Wi={},aD={get exports(){return Wi},set exports(e){Wi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(aD);const sD=Wi;var ji={},oD={get exports(){return ji},set exports(e){ji=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,C){return this.$utils().u(g)?this[m]:this.$set(C,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(oD);const lD=ji;var Ri={},uD={get exports(){return Ri},set exports(e){Ri=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(uD);const cD=Ri;var Yi={},dD={get exports(){return Yi},set exports(e){Yi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[m]||l[m];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(dD);const pD=Yi;var Qi={},hD={get exports(){return Qi},set exports(e){Qi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var D=_.match(/([+-]|\d\d)/g),I=60*D[1]+(+D[2]||0);return I===0?0:D[0]==="+"?-I:I}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var D,I=u.meridiem;if(I){for(var B=1;B<=24;B+=1)if(w.indexOf(I(B,0,_))>-1){D=B>12;break}}else D=w===(_?"pm":"PM");return D},m={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,D=w.match(/\d+/);if(this.day=D[0],_)for(var I=1;I<=31;I+=1)_(I).replace(/\[|\]/g,"")===w&&(this.day=I)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),D=(h("monthsShort")||_.map(function(I){return I.slice(0,3)})).indexOf(w)+1;if(D<1)throw new Error;this.month=D%12||D}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,D;_=w,D=u&&u.formats;for(var I=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(X,Q,H){var oe=H&&H.toUpperCase();return Q||D[H]||n[H]||D[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(ue,be,Ee){return be||Ee.slice(1)})})).match(r),B=I.length,N=0;N<B;N+=1){var O=I[N],z=m[O],A=z&&z[0],G=z&&z[1];I[N]=G?{regex:A,parser:G}:O.replace(/^\[|\]$/g,"")}return function(X){for(var Q={},H=0,oe=0;H<B;H+=1){var ue=I[H];if(typeof ue=="string")oe+=ue.length;else{var be=ue.regex,Ee=ue.parser,fe=X.slice(oe),ve=be.exec(fe)[0];Ee.call(Q,ve),X=X.replace(ve,"")}}return function(ge){var Oe=ge.afternoon;if(Oe!==void 0){var Ze=ge.hours;Oe?Ze<12&&(ge.hours+=12):Ze===12&&(ge.hours=0),delete ge.afternoon}}(Q),Q}}return function(w,_,D){D.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var I=_.prototype,B=I.parse;I.parse=function(N){var O=N.date,z=N.utc,A=N.args;this.$u=z;var G=A[1];if(typeof G=="string"){var X=A[2]===!0,Q=A[3]===!0,H=X||Q,oe=A[2];Q&&(oe=A[2]),u=this.$locale(),!X&&oe&&(u=D.Ls[oe]),this.$d=function(fe,ve,ge){try{if(["x","X"].indexOf(ve)>-1)return new Date((ve==="X"?1e3:1)*fe);var Oe=C(ve)(fe),Ze=Oe.year,$t=Oe.month,ur=Oe.day,cr=Oe.hours,Ca=Oe.minutes,Sa=Oe.seconds,hn=Oe.milliseconds,jt=Oe.zone,wt=new Date,Lt=ur||(Ze||$t?1:wt.getDate()),Ct=Ze||wt.getFullYear(),Rt=0;Ze&&!$t||(Rt=$t>0?$t-1:wt.getMonth());var Yt=cr||0,fn=Ca||0,gn=Sa||0,St=hn||0;return jt?new Date(Date.UTC(Ct,Rt,Lt,Yt,fn,gn,St+60*jt.offset*1e3)):ge?new Date(Date.UTC(Ct,Rt,Lt,Yt,fn,gn,St)):new Date(Ct,Rt,Lt,Yt,fn,gn,St)}catch{return new Date("")}}(O,G,z),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),H&&O!=this.format(G)&&(this.$d=new Date("")),u={}}else if(G instanceof Array)for(var ue=G.length,be=1;be<=ue;be+=1){A[1]=G[be-1];var Ee=D.apply(this,A);if(Ee.isValid()){this.$d=Ee.$d,this.$L=Ee.$L,this.init();break}be===ue&&(this.$d=new Date(""))}else B.call(this,N)}}})})(hD);const fD=Qi;var Ki={},gD={get exports(){return Ki},set exports(e){Ki=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(gD);const mD=Ki;var Ui={},yD={get exports(){return Ui},set exports(e){Ui=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function(O){return O instanceof N},C=function(O,z,A){return new N(O,A,z.$l)},w=function(O){return r.p(O)+"s"},_=function(O){return O<0},D=function(O){return _(O)?Math.ceil(O):Math.floor(O)},I=function(O){return Math.abs(O)},B=function(O,z){return O?_(O)?{negative:!0,format:""+I(O)+z}:{negative:!1,format:""+O+z}:{negative:!1,format:""}},N=function(){function O(A,G,X){var Q=this;if(this.$d={},this.$l=X,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),G)return C(A*g[w(G)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(ue){Q.$d[w(ue)]=A[ue]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var oe=H.slice(2).map(function(ue){return ue!=null?Number(ue):0});return this.$d.years=oe[0],this.$d.months=oe[1],this.$d.weeks=oe[2],this.$d.days=oe[3],this.$d.hours=oe[4],this.$d.minutes=oe[5],this.$d.seconds=oe[6],this.calMilliseconds(),this}}return this}var z=O.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(G,X){return G+(A.$d[X]||0)*g[X]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=D(A/d),A%=d,this.$d.months=D(A/f),A%=f,this.$d.days=D(A/u),A%=u,this.$d.hours=D(A/l),A%=l,this.$d.minutes=D(A/o),A%=o,this.$d.seconds=D(A/a),A%=a,this.$d.milliseconds=A},z.toISOString=function(){var A=B(this.$d.years,"Y"),G=B(this.$d.months,"M"),X=+this.$d.days||0;this.$d.weeks&&(X+=7*this.$d.weeks);var Q=B(X,"D"),H=B(this.$d.hours,"H"),oe=B(this.$d.minutes,"M"),ue=this.$d.seconds||0;this.$d.milliseconds&&(ue+=this.$d.milliseconds/1e3);var be=B(ue,"S"),Ee=A.negative||G.negative||Q.negative||H.negative||oe.negative||be.negative,fe=H.format||oe.format||be.format?"T":"",ve=(Ee?"-":"")+"P"+A.format+G.format+Q.format+fe+H.format+oe.format+be.format;return ve==="P"||ve==="-P"?"P0D":ve},z.toJSON=function(){return this.toISOString()},z.format=function(A){var G=A||"YYYY-MM-DDTHH:mm:ss",X={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return G.replace(c,function(Q,H){return H||String(X[Q])})},z.as=function(A){return this.$ms/g[w(A)]},z.get=function(A){var G=this.$ms,X=w(A);return X==="milliseconds"?G%=1e3:G=X==="weeks"?D(G/g[X]):this.$d[X],G===0?0:G},z.add=function(A,G,X){var Q;return Q=G?A*g[w(G)]:m(A)?A.$ms:C(A,this).$ms,C(this.$ms+Q*(X?-1:1),this)},z.subtract=function(A,G){return this.add(A,G,!0)},z.locale=function(A){var G=this.clone();return G.$l=A,G},z.clone=function(){return C(this.$ms,this)},z.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},z.milliseconds=function(){return this.get("milliseconds")},z.asMilliseconds=function(){return this.as("milliseconds")},z.seconds=function(){return this.get("seconds")},z.asSeconds=function(){return this.as("seconds")},z.minutes=function(){return this.get("minutes")},z.asMinutes=function(){return this.as("minutes")},z.hours=function(){return this.get("hours")},z.asHours=function(){return this.as("hours")},z.days=function(){return this.get("days")},z.asDays=function(){return this.as("days")},z.weeks=function(){return this.get("weeks")},z.asWeeks=function(){return this.as("weeks")},z.months=function(){return this.get("months")},z.asMonths=function(){return this.as("months")},z.years=function(){return this.get("years")},z.asYears=function(){return this.as("years")},O}();return function(O,z,A){n=A,r=A().$utils(),A.duration=function(Q,H){var oe=A.locale();return C(Q,{$l:oe},H)},A.isDuration=m;var G=z.prototype.add,X=z.prototype.subtract;z.prototype.add=function(Q,H){return m(Q)&&(Q=Q.asMilliseconds()),G.bind(this)(Q,H)},z.prototype.subtract=function(Q,H){return m(Q)&&(Q=Q.asMilliseconds()),X.bind(this)(Q,H)}}})})(yD);const bD=Ui;var Xi={},vD={get exports(){return Xi},set exports(e){Xi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(vD);const xD=Xi;var Ji={},wD={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(wD);const CD=Ji;var Zi={},SD={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(SD);const _D=Zi;var Hi={},kD={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(kD);const TD=Hi;var ea={},DD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(DD);const MD=ea;var ta={},ID={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(ID);const AD=ta;var na={},zD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(zD);const ED=na;var ra={},$D={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})($D);const LD=ra;var ia={},OD={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(OD);const PD=ia;var aa={},BD={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(BD);const VD=aa;var sa={},ND={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,C,w){var _=h.name?h:h.$locale(),D=l(_[g]),I=l(_[m]),B=D||I.map(function(O){return O.slice(0,C)});if(!w)return B;var N=_.weekStart;return B.map(function(O,z){return B[(z+(N||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(ND);const qD=sa;var oa={},FD={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(D,I,B){return I||B.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(FD);const GD=oa;var la={},WD={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(WD);const jD=la;var ua={},RD={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var D=w?a.utc():a();Object.keys(C).forEach(function(X){var Q,H;_[Q=X,H=o.$utils().p(Q),H==="date"?"day":H]=C[X]});var I=_.day||(_.year||_.month>=0?1:D.date()),B=_.year||D.year(),N=_.month>=0?_.month:_.year||_.day?0:D.month(),O=_.hour||0,z=_.minute||0,A=_.second||0,G=_.millisecond||0;return w?new Date(Date.UTC(B,N,I,O,z,A,G)):new Date(B,N,I,O,z,A,G)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,C,w){w===void 0&&(w=1);var _=Object.keys(m),D=this;return _.forEach(function(I){D=g.bind(D)(m[I]*w,I)}),D};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(RD);const YD=ua;var ca={},QD={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(QD);const KD=ca;var da={},UD={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(UD);const XD=da;var pa={},JD={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(JD);const ZD=pa;var ha={},HD={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var C,w,_,D=h.$locale().relativeTime||l,I=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],B=I.length,N=0;N<B;N+=1){var O=I[N];O.d&&(C=g?a(d).diff(h,O.d,!0):h.diff(d,O.d,!0));var z=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,z<=O.r||!O.r){z<=1&&N>0&&(O=I[N-1]);var A=D[O.l];m&&(z=m(""+z)),w=typeof A=="string"?A.replace("%d",z):A(z,f,O.l,_);break}}if(f)return w;var G=_?D.future:D.past;return typeof G=="function"?G(w):G.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(HD);const eM=ha;var fa={},tM={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(D,I){I===void 0&&(I={});var B=I.timeZoneName||"short",N=D+"|"+B,O=r[N];return O||(O=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:B}),r[N]=O),O}(m,C);return _.formatToParts(w)},d=function(g,m){for(var C=c(g,m),w=[],_=0;_<C.length;_+=1){var D=C[_],I=D.type,B=D.value,N=n[I];N>=0&&(w[N]=parseInt(B,10))}var O=w[3],z=O===24?0:O,A=w[0]+"-"+w[1]+"-"+w[2]+" "+z+":"+w[4]+":"+w[5]+":000",G=+g;return(l.utc(A).valueOf()-(G-=G%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),D=Math.round((w-new Date(_))/1e3/60),I=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-D,!0);if(m){var B=I.utcOffset();I=I.add(C-B,"minute")}return I.$x.$timezone=g,I},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),m,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,C){var w=C&&m,_=C||m||u,D=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var I=function(z,A,G){var X=z-60*A*1e3,Q=d(X,G);if(A===Q)return[X,A];var H=d(X-=60*(Q-A)*1e3,G);return Q===H?[X,Q]:[z-60*Math.min(Q,H)*1e3,Math.max(Q,H)]}(l.utc(g,w).valueOf(),D,_),B=I[0],N=I[1],O=l(B).utcOffset(N);return O.$x.$timezone=_,O},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(tM);const nM=fa;var ga={},rM={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(rM);const iM=ga;var ma={},aM={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(aM);const sM=ma;var ya={},oM={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(oM);const lM=ya;var ba={},uM={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var D=this.$utils().u;if(D(w))return this.$u?0:D(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function(O){O===void 0&&(O="");var z=O.match(r);if(!z)return null;var A=(""+z[0]).match(a)||["-",0,0],G=A[0],X=60*+A[1]+ +A[2];return X===0?0:G==="+"?X:-X}(w),w===null))return this;var I=Math.abs(w)<=16?60*w:w,B=this;if(_)return B.$offset=I,B.$u=w===0,B;if(w!==0){var N=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(B=this.local().add(I+N,n)).$offset=I,B.$x.$localOffset=N}else B=this.utc();return B};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var m=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var C=c.diff;c.diff=function(w,_,D){if(w&&this.$u===w.$u)return C.call(this,w,_,D);var I=this.local(),B=u(w).local();return C.call(I,B,_,D)}}})})(uM);const cM=ba;var va={},dM={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(dM);const pM=va;var xa={},hM={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(hM);const fM=xa;var wa={},gM={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(gM);const mM=wa;Y.extend(iD),Y.extend(sD),Y.extend(lD),Y.extend(cD),Y.extend(pD),Y.extend(fD),Y.extend(mD),Y.extend(bD),Y.extend(xD),Y.extend(CD),Y.extend(_D),Y.extend(AD),Y.extend(ED),Y.extend(LD),Y.extend(PD),Y.extend(VD),Y.extend(TD),Y.extend(MD),Y.extend(qD),Y.extend(GD),Y.extend(jD),Y.extend(YD),Y.extend(KD),Y.extend(XD),Y.extend(ZD),Y.extend(eM),Y.extend(nM),Y.extend(iM),Y.extend(sM),Y.extend(lM),Y.extend(cM),Y.extend(fM),Y.extend(mM),Y.extend(pM),Y.tz.setDefault("UTC");const yM=()=>Promise.resolve().then(()=>lc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));M.ContentModel=$i,M.ContentModelContextProvider=Cr,M.DashboardEditor=ZT,M.DashboardFilterType=_e,M.DashboardMode=Nl,M.DashboardModel=Kl,M.DashboardModelContextProvider=vr,M.DashboardViewEditor=Vl,M.DashboardViewRender=ir,M.DescriptionPopover=Mi,M.FiltersModel=Fl,M.FullScreenPanel=$l,M.FullScreenPanelContext=_r,M.LayoutStateContext=_n,M.Panel=El,M.PanelContextProvider=Sr,M.PanelErrorOrStateMessage=Al,M.PanelModel=jl,M.PanelRender=Ai,M.PanelVizSection=Ii,M.PanelsModel=Rl,M.QueriesModel=Gl,M.ReadOnlyDashboard=nD,M.SQLSnippetsModel=Wl,M.ViewComponentTypeBackground=ql,M.ViewComponentTypeColor=HS,M.ViewComponentTypeName=ZS,M.ViewsModel=Yl,M.Viz=Il,M.applyPartialDashboard=d_,M.createContentModel=Ql,M.createDashboardModel=Ul,M.getInitialDashboardViewsModel=Ei,M.getVersion=yM,M.initialDashboardContent=e_,M.useDashboardContext=xr,M.useEditContentModelContext=le,M.useEditDashboardContext=ye,M.useEditPanelContext=nt,M.useFullScreenPanelContext=os,M.usePanelFullScreen=Ll,M.useRenderContentModelContext=we,M.useRenderDashboardContext=wr,M.useRenderPanelContext=bt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});