@devtable/dashboard 9.19.1 → 9.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(k,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("mobx-state-tree"),require("performant-array-to-tree"),require("jszip"),require("file-saver"),require("@tabler/icons"),require("@mantine/hooks"),require("@tanstack/react-table"),require("react-virtual"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@mantine/notifications"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","mobx-state-tree","performant-array-to-tree","jszip","file-saver","@tabler/icons","@mantine/hooks","@tanstack/react-table","react-virtual","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","react-hook-form","tabler-icons-react","echarts/charts","@mantine/notifications","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],m):(k=typeof globalThis<"u"?globalThis:k||self,m(k.dashboard={},k.react,k["@mantine/core"],k["@mantine/modals"],k.ahooks,k.mobx,k["mobx-react-lite"],k.CryptoJS,k.dayjs,k._,k.numbro,k["d3-array"],k.mathjs,k["@faker-js/faker"],k.axios,k["mobx-state-tree"],k["performant-array-to-tree"],k.jszip,k["file-saver"],k["@tabler/icons"],k["@mantine/hooks"],k["@tanstack/react-table"],k["react-virtual"],k.eventemitter2,k["chroma-js"],k["echarts-gl"],k["echarts/core"],k["echarts/components"],k["echarts/renderers"],k["echarts-for-react/lib/core"],k["react-hook-form"],k["tabler-icons-react"],k["echarts/charts"],k["@mantine/notifications"],k.popmotion,k["@monaco-editor/react"],k["d3-regression"],k["@mantine/prism"],k["@mantine/tiptap"],k["@tiptap/extension-color"],k["@tiptap/extension-highlight"],k["@tiptap/extension-placeholder"],k["@tiptap/extension-subscript"],k["@tiptap/extension-superscript"],k["@tiptap/extension-text-align"],k["@tiptap/extension-text-style"],k["@tiptap/extension-table"],k["@tiptap/extension-table-cell"],k["@tiptap/extension-table-header"],k["@tiptap/extension-table-row"],k["@tiptap/extension-underline"],k["@tiptap/react"],k["@tiptap/starter-kit"],k["@mantine/dates"],k["rc-select"],k["rc-tree-select"],k["react-grid-layout"],k["react-router-dom"],k.reactflow))})(this,function(k,m,a,Ve,X,ie,T,vi,Y,v,ee,_t,bo,vo,Ze,y,xo,Co,xn,L,we,Be,wo,xi,Re,k1,_o,G,Ae,ze,x,D,ce,qt,ct,De,So,st,Z,Ci,wi,_i,Si,Ti,Di,ki,Ii,Mi,$i,Ai,zi,Ei,Li,To,Pi,Oi,Nt,Do,_e){"use strict";var T1=Object.defineProperty;var D1=(k,m,a)=>m in k?T1(k,m,{enumerable:!0,configurable:!0,writable:!0,value:a}):k[m]=a;var V=(k,m,a)=>(D1(k,typeof m!="symbol"?m+"":m,a),a);function Gt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ko=Gt(_t),Ft=Gt(bo),oe=Gt(_o),Je=Gt(So);var te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},St={},Io={get exports(){return St},set exports(e){St=e}},Tt={};/**
1
+ (function(k,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("mobx-state-tree"),require("performant-array-to-tree"),require("jszip"),require("file-saver"),require("@tabler/icons"),require("@mantine/hooks"),require("@tanstack/react-table"),require("react-virtual"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@mantine/notifications"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","mobx-state-tree","performant-array-to-tree","jszip","file-saver","@tabler/icons","@mantine/hooks","@tanstack/react-table","react-virtual","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","react-hook-form","tabler-icons-react","echarts/charts","@mantine/notifications","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],m):(k=typeof globalThis<"u"?globalThis:k||self,m(k.dashboard={},k.react,k["@mantine/core"],k["@mantine/modals"],k.ahooks,k.mobx,k["mobx-react-lite"],k.CryptoJS,k.dayjs,k._,k.numbro,k["d3-array"],k.mathjs,k["@faker-js/faker"],k.axios,k["mobx-state-tree"],k["performant-array-to-tree"],k.jszip,k["file-saver"],k["@tabler/icons"],k["@mantine/hooks"],k["@tanstack/react-table"],k["react-virtual"],k.eventemitter2,k["chroma-js"],k["echarts-gl"],k["echarts/core"],k["echarts/components"],k["echarts/renderers"],k["echarts-for-react/lib/core"],k["react-hook-form"],k["tabler-icons-react"],k["echarts/charts"],k["@mantine/notifications"],k.popmotion,k["@monaco-editor/react"],k["d3-regression"],k["@mantine/prism"],k["@mantine/tiptap"],k["@tiptap/extension-color"],k["@tiptap/extension-highlight"],k["@tiptap/extension-placeholder"],k["@tiptap/extension-subscript"],k["@tiptap/extension-superscript"],k["@tiptap/extension-text-align"],k["@tiptap/extension-text-style"],k["@tiptap/extension-table"],k["@tiptap/extension-table-cell"],k["@tiptap/extension-table-header"],k["@tiptap/extension-table-row"],k["@tiptap/extension-underline"],k["@tiptap/react"],k["@tiptap/starter-kit"],k["@mantine/dates"],k["rc-select"],k["rc-tree-select"],k["react-grid-layout"],k["react-router-dom"],k.reactflow))})(this,function(k,m,a,Ve,X,ie,T,vi,Y,v,ee,_t,bo,vo,Ze,y,xo,Co,xn,L,we,Be,wo,xi,Re,k1,_o,G,Ae,ze,x,D,ce,Bt,ct,De,So,st,Z,Ci,wi,_i,Si,Ti,Di,ki,Ii,Mi,$i,Ai,zi,Ei,Li,To,Pi,Oi,qt,Do,_e){"use strict";var T1=Object.defineProperty;var D1=(k,m,a)=>m in k?T1(k,m,{enumerable:!0,configurable:!0,writable:!0,value:a}):k[m]=a;var V=(k,m,a)=>(D1(k,typeof m!="symbol"?m+"":m,a),a);function Nt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ko=Nt(_t),Gt=Nt(bo),oe=Nt(_o),Je=Nt(So);var te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},St={},Io={get exports(){return St},set exports(e){St=e}},Tt={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -14,17 +14,17 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Bi;function $o(){return Bi||(Bi=1,process.env.NODE_ENV!=="production"&&function(){var e=m,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),b=Symbol.for("react.offscreen"),_=Symbol.iterator,C="@@iterator";function S(w){if(w===null||typeof w!="object")return null;var M=_&&w[_]||w[C];return typeof M=="function"?M:null}var I=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function $(w){{for(var M=arguments.length,E=new Array(M>1?M-1:0),Q=1;Q<M;Q++)E[Q-1]=arguments[Q];q("error",w,E)}}function q(w,M,E){{var Q=I.ReactDebugCurrentFrame,ae=Q.getStackAddendum();ae!==""&&(M+="%s",E=E.concat([ae]));var ue=E.map(function(re){return String(re)});ue.unshift("Warning: "+M),Function.prototype.apply.call(console[w],console,ue)}}var N=!1,P=!1,z=!1,A=!1,F=!1,K;K=Symbol.for("react.module.reference");function R(w){return!!(typeof w=="string"||typeof w=="function"||w===i||w===o||F||w===s||w===p||w===f||A||w===b||N||P||z||typeof w=="object"&&w!==null&&(w.$$typeof===g||w.$$typeof===h||w.$$typeof===l||w.$$typeof===u||w.$$typeof===c||w.$$typeof===K||w.getModuleId!==void 0))}function ne(w,M,E){var Q=w.displayName;if(Q)return Q;var ae=M.displayName||M.name||"";return ae!==""?E+"("+ae+")":E}function se(w){return w.displayName||"Context"}function le(w){if(w==null)return null;if(typeof w.tag=="number"&&$("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof w=="function")return w.displayName||w.name||null;if(typeof w=="string")return w;switch(w){case i:return"Fragment";case n:return"Portal";case o:return"Profiler";case s:return"StrictMode";case p:return"Suspense";case f:return"SuspenseList"}if(typeof w=="object")switch(w.$$typeof){case u:var M=w;return se(M)+".Consumer";case l:var E=w;return se(E._context)+".Provider";case c:return ne(w,w.render,"ForwardRef");case h:var Q=w.displayName||null;return Q!==null?Q:le(w.type)||"Memo";case g:{var ae=w,ue=ae._payload,re=ae._init;try{return le(re(ue))}catch{return null}}}return null}var fe=Object.assign,Ce=0,pe,ye,ge,Ie,Pe,lt,yn;function bn(){}bn.__reactDisabledLog=!0;function pi(){{if(Ce===0){pe=console.log,ye=console.info,ge=console.warn,Ie=console.error,Pe=console.group,lt=console.groupCollapsed,yn=console.groupEnd;var w={configurable:!0,enumerable:!0,value:bn,writable:!0};Object.defineProperties(console,{info:w,log:w,warn:w,error:w,group:w,groupCollapsed:w,groupEnd:w})}Ce++}}function hi(){{if(Ce--,Ce===0){var w={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:fe({},w,{value:pe}),info:fe({},w,{value:ye}),warn:fe({},w,{value:ge}),error:fe({},w,{value:Ie}),group:fe({},w,{value:Pe}),groupCollapsed:fe({},w,{value:lt}),groupEnd:fe({},w,{value:yn})})}Ce<0&&$("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Lt=I.ReactCurrentDispatcher,bt;function rt(w,M,E){{if(bt===void 0)try{throw Error()}catch(ae){var Q=ae.stack.trim().match(/\n( *(at )?)/);bt=Q&&Q[1]||""}return`
18
- `+bt+w}}var ut=!1,it;{var vt=typeof WeakMap=="function"?WeakMap:Map;it=new vt}function xt(w,M){if(!w||ut)return"";{var E=it.get(w);if(E!==void 0)return E}var Q;ut=!0;var ae=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ue;ue=Lt.current,Lt.current=null,pi();try{if(M){var re=function(){throw Error()};if(Object.defineProperty(re.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(re,[])}catch(Xe){Q=Xe}Reflect.construct(w,[],re)}else{try{re.call()}catch(Xe){Q=Xe}w.call(re.prototype)}}else{try{throw Error()}catch(Xe){Q=Xe}w()}}catch(Xe){if(Xe&&Q&&typeof Xe.stack=="string"){for(var H=Xe.stack.split(`
17
+ */var Bi;function $o(){return Bi||(Bi=1,process.env.NODE_ENV!=="production"&&function(){var e=m,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),b=Symbol.for("react.offscreen"),_=Symbol.iterator,C="@@iterator";function S(w){if(w===null||typeof w!="object")return null;var M=_&&w[_]||w[C];return typeof M=="function"?M:null}var I=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function $(w){{for(var M=arguments.length,E=new Array(M>1?M-1:0),Q=1;Q<M;Q++)E[Q-1]=arguments[Q];q("error",w,E)}}function q(w,M,E){{var Q=I.ReactDebugCurrentFrame,ae=Q.getStackAddendum();ae!==""&&(M+="%s",E=E.concat([ae]));var ue=E.map(function(re){return String(re)});ue.unshift("Warning: "+M),Function.prototype.apply.call(console[w],console,ue)}}var N=!1,P=!1,z=!1,A=!1,F=!1,K;K=Symbol.for("react.module.reference");function R(w){return!!(typeof w=="string"||typeof w=="function"||w===i||w===o||F||w===s||w===p||w===f||A||w===b||N||P||z||typeof w=="object"&&w!==null&&(w.$$typeof===g||w.$$typeof===h||w.$$typeof===l||w.$$typeof===u||w.$$typeof===c||w.$$typeof===K||w.getModuleId!==void 0))}function ne(w,M,E){var Q=w.displayName;if(Q)return Q;var ae=M.displayName||M.name||"";return ae!==""?E+"("+ae+")":E}function se(w){return w.displayName||"Context"}function le(w){if(w==null)return null;if(typeof w.tag=="number"&&$("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof w=="function")return w.displayName||w.name||null;if(typeof w=="string")return w;switch(w){case i:return"Fragment";case n:return"Portal";case o:return"Profiler";case s:return"StrictMode";case p:return"Suspense";case f:return"SuspenseList"}if(typeof w=="object")switch(w.$$typeof){case u:var M=w;return se(M)+".Consumer";case l:var E=w;return se(E._context)+".Provider";case c:return ne(w,w.render,"ForwardRef");case h:var Q=w.displayName||null;return Q!==null?Q:le(w.type)||"Memo";case g:{var ae=w,ue=ae._payload,re=ae._init;try{return le(re(ue))}catch{return null}}}return null}var fe=Object.assign,Ce=0,pe,ye,ge,Ie,Pe,lt,yn;function bn(){}bn.__reactDisabledLog=!0;function pi(){{if(Ce===0){pe=console.log,ye=console.info,ge=console.warn,Ie=console.error,Pe=console.group,lt=console.groupCollapsed,yn=console.groupEnd;var w={configurable:!0,enumerable:!0,value:bn,writable:!0};Object.defineProperties(console,{info:w,log:w,warn:w,error:w,group:w,groupCollapsed:w,groupEnd:w})}Ce++}}function hi(){{if(Ce--,Ce===0){var w={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:fe({},w,{value:pe}),info:fe({},w,{value:ye}),warn:fe({},w,{value:ge}),error:fe({},w,{value:Ie}),group:fe({},w,{value:Pe}),groupCollapsed:fe({},w,{value:lt}),groupEnd:fe({},w,{value:yn})})}Ce<0&&$("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Et=I.ReactCurrentDispatcher,bt;function rt(w,M,E){{if(bt===void 0)try{throw Error()}catch(ae){var Q=ae.stack.trim().match(/\n( *(at )?)/);bt=Q&&Q[1]||""}return`
18
+ `+bt+w}}var ut=!1,it;{var vt=typeof WeakMap=="function"?WeakMap:Map;it=new vt}function xt(w,M){if(!w||ut)return"";{var E=it.get(w);if(E!==void 0)return E}var Q;ut=!0;var ae=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ue;ue=Et.current,Et.current=null,pi();try{if(M){var re=function(){throw Error()};if(Object.defineProperty(re.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(re,[])}catch(Xe){Q=Xe}Reflect.construct(w,[],re)}else{try{re.call()}catch(Xe){Q=Xe}w.call(re.prototype)}}else{try{throw Error()}catch(Xe){Q=Xe}w()}}catch(Xe){if(Xe&&Q&&typeof Xe.stack=="string"){for(var H=Xe.stack.split(`
19
19
  `),$e=Q.stack.split(`
20
20
  `),be=H.length-1,xe=$e.length-1;be>=1&&xe>=0&&H[be]!==$e[xe];)xe--;for(;be>=1&&xe>=0;be--,xe--)if(H[be]!==$e[xe]){if(be!==1||xe!==1)do if(be--,xe--,xe<0||H[be]!==$e[xe]){var Oe=`
21
- `+H[be].replace(" at new "," at ");return w.displayName&&Oe.includes("<anonymous>")&&(Oe=Oe.replace("<anonymous>",w.displayName)),typeof w=="function"&&it.set(w,Oe),Oe}while(be>=1&&xe>=0);break}}}finally{ut=!1,Lt.current=ue,hi(),Error.prepareStackTrace=ae}var wt=w?w.displayName||w.name:"",yo=wt?rt(wt):"";return typeof w=="function"&&it.set(w,yo),yo}function Pt(w,M,E){return xt(w,!1)}function Ot(w){var M=w.prototype;return!!(M&&M.isReactComponent)}function at(w,M,E){if(w==null)return"";if(typeof w=="function")return xt(w,Ot(w));if(typeof w=="string")return rt(w);switch(w){case p:return rt("Suspense");case f:return rt("SuspenseList")}if(typeof w=="object")switch(w.$$typeof){case c:return Pt(w.render);case h:return at(w.type,M,E);case g:{var Q=w,ae=Q._payload,ue=Q._init;try{return at(ue(ae),M,E)}catch{}}}return""}var Vt=Object.prototype.hasOwnProperty,io={},ao=I.ReactDebugCurrentFrame;function vn(w){if(w){var M=w._owner,E=at(w.type,w._source,M?M.type:null);ao.setExtraStackFrame(E)}else ao.setExtraStackFrame(null)}function a1(w,M,E,Q,ae){{var ue=Function.call.bind(Vt);for(var re in w)if(ue(w,re)){var H=void 0;try{if(typeof w[re]!="function"){var $e=Error((Q||"React class")+": "+E+" type `"+re+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof w[re]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw $e.name="Invariant Violation",$e}H=w[re](M,re,Q,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(be){H=be}H&&!(H instanceof Error)&&(vn(ae),$("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Q||"React class",E,re,typeof H),vn(null)),H instanceof Error&&!(H.message in io)&&(io[H.message]=!0,vn(ae),$("Failed %s type: %s",E,H.message),vn(null))}}}var s1=Array.isArray;function fi(w){return s1(w)}function o1(w){{var M=typeof Symbol=="function"&&Symbol.toStringTag,E=M&&w[Symbol.toStringTag]||w.constructor.name||"Object";return E}}function l1(w){try{return so(w),!1}catch{return!0}}function so(w){return""+w}function oo(w){if(l1(w))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",o1(w)),so(w)}var Bt=I.ReactCurrentOwner,u1={key:!0,ref:!0,__self:!0,__source:!0},lo,uo,gi;gi={};function c1(w){if(Vt.call(w,"ref")){var M=Object.getOwnPropertyDescriptor(w,"ref").get;if(M&&M.isReactWarning)return!1}return w.ref!==void 0}function d1(w){if(Vt.call(w,"key")){var M=Object.getOwnPropertyDescriptor(w,"key").get;if(M&&M.isReactWarning)return!1}return w.key!==void 0}function p1(w,M){if(typeof w.ref=="string"&&Bt.current&&M&&Bt.current.stateNode!==M){var E=le(Bt.current.type);gi[E]||($('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',le(Bt.current.type),w.ref),gi[E]=!0)}}function h1(w,M){{var E=function(){lo||(lo=!0,$("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(w,"key",{get:E,configurable:!0})}}function f1(w,M){{var E=function(){uo||(uo=!0,$("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(w,"ref",{get:E,configurable:!0})}}var g1=function(w,M,E,Q,ae,ue,re){var H={$$typeof:t,type:w,key:M,ref:E,props:re,_owner:ue};return H._store={},Object.defineProperty(H._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(H,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Q}),Object.defineProperty(H,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ae}),Object.freeze&&(Object.freeze(H.props),Object.freeze(H)),H};function m1(w,M,E,Q,ae){{var ue,re={},H=null,$e=null;E!==void 0&&(oo(E),H=""+E),d1(M)&&(oo(M.key),H=""+M.key),c1(M)&&($e=M.ref,p1(M,ae));for(ue in M)Vt.call(M,ue)&&!u1.hasOwnProperty(ue)&&(re[ue]=M[ue]);if(w&&w.defaultProps){var be=w.defaultProps;for(ue in be)re[ue]===void 0&&(re[ue]=be[ue])}if(H||$e){var xe=typeof w=="function"?w.displayName||w.name||"Unknown":w;H&&h1(re,xe),$e&&f1(re,xe)}return g1(w,H,$e,ae,Q,Bt.current,re)}}var mi=I.ReactCurrentOwner,co=I.ReactDebugCurrentFrame;function Ct(w){if(w){var M=w._owner,E=at(w.type,w._source,M?M.type:null);co.setExtraStackFrame(E)}else co.setExtraStackFrame(null)}var yi;yi=!1;function bi(w){return typeof w=="object"&&w!==null&&w.$$typeof===t}function po(){{if(mi.current){var w=le(mi.current.type);if(w)return`
21
+ `+H[be].replace(" at new "," at ");return w.displayName&&Oe.includes("<anonymous>")&&(Oe=Oe.replace("<anonymous>",w.displayName)),typeof w=="function"&&it.set(w,Oe),Oe}while(be>=1&&xe>=0);break}}}finally{ut=!1,Et.current=ue,hi(),Error.prepareStackTrace=ae}var wt=w?w.displayName||w.name:"",yo=wt?rt(wt):"";return typeof w=="function"&&it.set(w,yo),yo}function Lt(w,M,E){return xt(w,!1)}function Pt(w){var M=w.prototype;return!!(M&&M.isReactComponent)}function at(w,M,E){if(w==null)return"";if(typeof w=="function")return xt(w,Pt(w));if(typeof w=="string")return rt(w);switch(w){case p:return rt("Suspense");case f:return rt("SuspenseList")}if(typeof w=="object")switch(w.$$typeof){case c:return Lt(w.render);case h:return at(w.type,M,E);case g:{var Q=w,ae=Q._payload,ue=Q._init;try{return at(ue(ae),M,E)}catch{}}}return""}var Ot=Object.prototype.hasOwnProperty,io={},ao=I.ReactDebugCurrentFrame;function vn(w){if(w){var M=w._owner,E=at(w.type,w._source,M?M.type:null);ao.setExtraStackFrame(E)}else ao.setExtraStackFrame(null)}function a1(w,M,E,Q,ae){{var ue=Function.call.bind(Ot);for(var re in w)if(ue(w,re)){var H=void 0;try{if(typeof w[re]!="function"){var $e=Error((Q||"React class")+": "+E+" type `"+re+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof w[re]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw $e.name="Invariant Violation",$e}H=w[re](M,re,Q,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(be){H=be}H&&!(H instanceof Error)&&(vn(ae),$("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Q||"React class",E,re,typeof H),vn(null)),H instanceof Error&&!(H.message in io)&&(io[H.message]=!0,vn(ae),$("Failed %s type: %s",E,H.message),vn(null))}}}var s1=Array.isArray;function fi(w){return s1(w)}function o1(w){{var M=typeof Symbol=="function"&&Symbol.toStringTag,E=M&&w[Symbol.toStringTag]||w.constructor.name||"Object";return E}}function l1(w){try{return so(w),!1}catch{return!0}}function so(w){return""+w}function oo(w){if(l1(w))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",o1(w)),so(w)}var Vt=I.ReactCurrentOwner,u1={key:!0,ref:!0,__self:!0,__source:!0},lo,uo,gi;gi={};function c1(w){if(Ot.call(w,"ref")){var M=Object.getOwnPropertyDescriptor(w,"ref").get;if(M&&M.isReactWarning)return!1}return w.ref!==void 0}function d1(w){if(Ot.call(w,"key")){var M=Object.getOwnPropertyDescriptor(w,"key").get;if(M&&M.isReactWarning)return!1}return w.key!==void 0}function p1(w,M){if(typeof w.ref=="string"&&Vt.current&&M&&Vt.current.stateNode!==M){var E=le(Vt.current.type);gi[E]||($('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',le(Vt.current.type),w.ref),gi[E]=!0)}}function h1(w,M){{var E=function(){lo||(lo=!0,$("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(w,"key",{get:E,configurable:!0})}}function f1(w,M){{var E=function(){uo||(uo=!0,$("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(w,"ref",{get:E,configurable:!0})}}var g1=function(w,M,E,Q,ae,ue,re){var H={$$typeof:t,type:w,key:M,ref:E,props:re,_owner:ue};return H._store={},Object.defineProperty(H._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(H,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Q}),Object.defineProperty(H,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ae}),Object.freeze&&(Object.freeze(H.props),Object.freeze(H)),H};function m1(w,M,E,Q,ae){{var ue,re={},H=null,$e=null;E!==void 0&&(oo(E),H=""+E),d1(M)&&(oo(M.key),H=""+M.key),c1(M)&&($e=M.ref,p1(M,ae));for(ue in M)Ot.call(M,ue)&&!u1.hasOwnProperty(ue)&&(re[ue]=M[ue]);if(w&&w.defaultProps){var be=w.defaultProps;for(ue in be)re[ue]===void 0&&(re[ue]=be[ue])}if(H||$e){var xe=typeof w=="function"?w.displayName||w.name||"Unknown":w;H&&h1(re,xe),$e&&f1(re,xe)}return g1(w,H,$e,ae,Q,Vt.current,re)}}var mi=I.ReactCurrentOwner,co=I.ReactDebugCurrentFrame;function Ct(w){if(w){var M=w._owner,E=at(w.type,w._source,M?M.type:null);co.setExtraStackFrame(E)}else co.setExtraStackFrame(null)}var yi;yi=!1;function bi(w){return typeof w=="object"&&w!==null&&w.$$typeof===t}function po(){{if(mi.current){var w=le(mi.current.type);if(w)return`
22
22
 
23
23
  Check the render method of \``+w+"`."}return""}}function y1(w){{if(w!==void 0){var M=w.fileName.replace(/^.*[\\\/]/,""),E=w.lineNumber;return`
24
24
 
25
25
  Check your code at `+M+":"+E+"."}return""}}var ho={};function b1(w){{var M=po();if(!M){var E=typeof w=="string"?w:w.displayName||w.name;E&&(M=`
26
26
 
27
- Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(!w._store||w._store.validated||w.key!=null)return;w._store.validated=!0;var E=b1(M);if(ho[E])return;ho[E]=!0;var Q="";w&&w._owner&&w._owner!==mi.current&&(Q=" It was passed a child from "+le(w._owner.type)+"."),Ct(w),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,Q),Ct(null)}}function go(w,M){{if(typeof w!="object")return;if(fi(w))for(var E=0;E<w.length;E++){var Q=w[E];bi(Q)&&fo(Q,M)}else if(bi(w))w._store&&(w._store.validated=!0);else if(w){var ae=S(w);if(typeof ae=="function"&&ae!==w.entries)for(var ue=ae.call(w),re;!(re=ue.next()).done;)bi(re.value)&&fo(re.value,M)}}}function v1(w){{var M=w.type;if(M==null||typeof M=="string")return;var E;if(typeof M=="function")E=M.propTypes;else if(typeof M=="object"&&(M.$$typeof===c||M.$$typeof===h))E=M.propTypes;else return;if(E){var Q=le(M);a1(E,w.props,"prop",Q,w)}else if(M.PropTypes!==void 0&&!yi){yi=!0;var ae=le(M);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ae||"Unknown")}typeof M.getDefaultProps=="function"&&!M.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function x1(w){{for(var M=Object.keys(w.props),E=0;E<M.length;E++){var Q=M[E];if(Q!=="children"&&Q!=="key"){Ct(w),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),Ct(null);break}}w.ref!==null&&(Ct(w),$("Invalid attribute `ref` supplied to `React.Fragment`."),Ct(null))}}function mo(w,M,E,Q,ae,ue){{var re=R(w);if(!re){var H="";(w===void 0||typeof w=="object"&&w!==null&&Object.keys(w).length===0)&&(H+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var $e=y1(ae);$e?H+=$e:H+=po();var be;w===null?be="null":fi(w)?be="array":w!==void 0&&w.$$typeof===t?(be="<"+(le(w.type)||"Unknown")+" />",H=" Did you accidentally export a JSX literal instead of a component?"):be=typeof w,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",be,H)}var xe=m1(w,M,E,ae,ue);if(xe==null)return xe;if(re){var Oe=M.children;if(Oe!==void 0)if(Q)if(fi(Oe)){for(var wt=0;wt<Oe.length;wt++)go(Oe[wt],w);Object.freeze&&Object.freeze(Oe)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else go(Oe,w)}return w===i?x1(xe):v1(xe),xe}}function C1(w,M,E){return mo(w,M,E,!0)}function w1(w,M,E){return mo(w,M,E,!1)}var _1=w1,S1=C1;Dt.Fragment=i,Dt.jsx=_1,Dt.jsxs=S1}()),Dt}(function(e){process.env.NODE_ENV==="production"?e.exports=Mo():e.exports=$o()})(Io);const B=St.Fragment,r=St.jsx,d=St.jsxs,dt={CryptoJS:vi,d3Array:ko,dayjs:Y,lodash:v,numbro:ee,mathjs:Ft,faker:vo.faker},Ao=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.0"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.7.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"}],zo=e=>`
27
+ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(!w._store||w._store.validated||w.key!=null)return;w._store.validated=!0;var E=b1(M);if(ho[E])return;ho[E]=!0;var Q="";w&&w._owner&&w._owner!==mi.current&&(Q=" It was passed a child from "+le(w._owner.type)+"."),Ct(w),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,Q),Ct(null)}}function go(w,M){{if(typeof w!="object")return;if(fi(w))for(var E=0;E<w.length;E++){var Q=w[E];bi(Q)&&fo(Q,M)}else if(bi(w))w._store&&(w._store.validated=!0);else if(w){var ae=S(w);if(typeof ae=="function"&&ae!==w.entries)for(var ue=ae.call(w),re;!(re=ue.next()).done;)bi(re.value)&&fo(re.value,M)}}}function v1(w){{var M=w.type;if(M==null||typeof M=="string")return;var E;if(typeof M=="function")E=M.propTypes;else if(typeof M=="object"&&(M.$$typeof===c||M.$$typeof===h))E=M.propTypes;else return;if(E){var Q=le(M);a1(E,w.props,"prop",Q,w)}else if(M.PropTypes!==void 0&&!yi){yi=!0;var ae=le(M);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ae||"Unknown")}typeof M.getDefaultProps=="function"&&!M.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function x1(w){{for(var M=Object.keys(w.props),E=0;E<M.length;E++){var Q=M[E];if(Q!=="children"&&Q!=="key"){Ct(w),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),Ct(null);break}}w.ref!==null&&(Ct(w),$("Invalid attribute `ref` supplied to `React.Fragment`."),Ct(null))}}function mo(w,M,E,Q,ae,ue){{var re=R(w);if(!re){var H="";(w===void 0||typeof w=="object"&&w!==null&&Object.keys(w).length===0)&&(H+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var $e=y1(ae);$e?H+=$e:H+=po();var be;w===null?be="null":fi(w)?be="array":w!==void 0&&w.$$typeof===t?(be="<"+(le(w.type)||"Unknown")+" />",H=" Did you accidentally export a JSX literal instead of a component?"):be=typeof w,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",be,H)}var xe=m1(w,M,E,ae,ue);if(xe==null)return xe;if(re){var Oe=M.children;if(Oe!==void 0)if(Q)if(fi(Oe)){for(var wt=0;wt<Oe.length;wt++)go(Oe[wt],w);Object.freeze&&Object.freeze(Oe)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else go(Oe,w)}return w===i?x1(xe):v1(xe),xe}}function C1(w,M,E){return mo(w,M,E,!0)}function w1(w,M,E){return mo(w,M,E,!1)}var _1=w1,S1=C1;Dt.Fragment=i,Dt.jsx=_1,Dt.jsxs=S1}()),Dt}(function(e){process.env.NODE_ENV==="production"?e.exports=Mo():e.exports=$o()})(Io);const B=St.Fragment,r=St.jsx,d=St.jsxs,dt={CryptoJS:vi,d3Array:ko,dayjs:Y,lodash:v,numbro:ee,mathjs:Gt,faker:vo.faker},Ao=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.0"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.7.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"}],zo=e=>`
28
28
  <tr>
29
29
  <td><code>${e.name}</code></td>
30
30
  <td>
@@ -51,8 +51,8 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
51
51
  ${Ao.map(zo).join("")}
52
52
  </tbody>
53
53
  </table>
54
- `;function Cn(e,t){const n=Object.keys(t),i=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...i)}catch(s){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):s}}function wn(e,t){try{return Cn(e,t)}catch(n){return console.error(n),n.message}}function Lo({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},dt)}catch(n){return console.error(n),e}}function Po(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,dt)}catch(n){return console.error(n),t}}function Oo(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s!="authentication"&&e[s])n.push(t[i]+"="+(typeof e[s]=="object"?JSON.stringify(e[s]):e[s]));else{const o=Object.keys(e[s]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[s][u]&&n.push(o[l]+"="+(typeof e[s][u]=="object"?JSON.stringify(e[s][u]):e[s][u]))}}}return n.sort().join("&")}function Vo(e,t){let n=Oo(e);return n+="&key="+t,vi.MD5(n).toString().toUpperCase()}const Ee={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:Vo({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,i,s={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":s.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...s.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?i:s.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=s.string?JSON.stringify(i):i,u.data.authentication=this.getAuthentication(u.data)),Ze(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var i;return t.env||(t.env=((i=this.makeQueryENV)==null?void 0:i.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function qi(e){Ee.baseURL!==e.apiBaseURL&&(Ee.baseURL=e.apiBaseURL),e.app_id&&(Ee.app_id=e.app_id),e.app_secret&&(Ee.app_secret=e.app_secret),e.makeQueryENV&&(Ee.makeQueryENV=e.makeQueryENV)}async function Bo({query:e,payload:t},n){if(!e.sql)return[];const{type:i,key:s,sql:o,pre_process:l,post_process:u}=e,c=Cn(o,t),p=Lo({sql:c,pre_process:l});let f=await Ee.query(n)({type:i,key:s,query:p},{});return f=Po(u,f),f}async function qo({type:e,key:t,configString:n},i){return await Ee.query(i)({type:e,key:t,query:n},{})}async function _n(){try{return(await Ee.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 Ni(){try{return(await Ee.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}const Gi=m.createContext(null),Sn=Gi.Provider;function U(){const e=m.useContext(Gi);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const No={layoutFrozen:!1,freezeLayout:v.noop,inEditMode:!1},He=m.createContext(No),Fi=m.createContext(null),Tn=Fi.Provider;function de(){const e=m.useContext(Fi);if(!e)throw new Error("Please use ModelContextProvider");return e}function Wi(e,t){m.useEffect(()=>{const n=i=>{console.log(i);const{viewID:s}=i.detail;if(!s){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(s),t&&e.views.setIDOfVIE(s)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),m.useEffect(()=>{const n=i=>{console.log(i);const{dictionary:s,payload:o}=i.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(s).forEach(([l,u])=>{e.filters.setValueByKey(l,v.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),m.useEffect(()=>{function n(s){return Array.isArray(s)?[]:typeof s=="object"?{}:typeof s=="boolean"?!1:typeof s=="string"?"":typeof s=="number"?0:s}const i=s=>{console.log(s);const{filter_keys:o}=s.detail;o.forEach(l=>{const u=v.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",i),()=>{window.removeEventListener("clear-filter-values",i)}},[e]),m.useEffect(()=>{const n=i=>{console.log(i);const{urlTemplate:s,openInNewTab:o,enableEncoding:l=!1,payload:u}=i.detail;if(!s){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return v.cloneDeepWith(h,b=>{if(l&&typeof b=="string")return encodeURIComponent(b)})}const f=v.template(s||"")(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])}const ji=y.types.model("FilterConfigModel_Checkbox",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:i}=e;return{_name:t,description:n,default_value:i}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Go=()=>ji.create({_name:"checkbox",description:"",default_value:!1});var he=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(he||{}),Se=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(Se||{});y.types.model({type:y.types.enumeration("DataSourceType",[he.Postgresql,he.MySQL,he.HTTP]),key:y.types.string,sql:y.types.string});function Yi(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 Fo=y.types.model("FilterConfigModel_DateRange",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:i,clearable:s,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:i,clearable:s,inputFormat:o,default_value:Yi(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=y.getParent(e);y.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}})),Ri=y.types.snapshotProcessor(Fo,{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:Yi(t,n.inputFormat)}}}),Wo=()=>Ri.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),jo=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Dn=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(jo),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.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:i}=y.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??""}})),Wt=e=>v.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return ie.toJS(t)}),Qi=y.types.compose("FilterConfigModel_MultiSelect",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),Dn).views(e=>({get json(){const{_name:t,default_value:n,min_width:i,static_options:s,options_query_id:o,default_selection_count:l}=e;return Wt({_name:t,min_width:i,default_value:n,static_options:s,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=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,n=y.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>ie.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Yo=()=>Qi.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function Ro(e){return xo.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function Qo(e){return e.map(t=>{const{label:n,description:i,...s}=t,o={...s,filterBasis:`${n}___${i??""}`,description:i,label:n};return i&&(o.label=m.createElement("div",{},[m.createElement(a.Text,{key:0,title:t.label},t.label),m.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const Ui=y.types.compose("FilterConfigModel_TreeSelect",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),Dn).views(e=>({get json(){const{_name:t,default_value:n,min_width:i,static_options:s,options_query_id:o,default_selection_count:l}=e;return{_name:t,min_width:i,default_value:n,static_options:s,options_query_id:o,default_selection_count:l}},get treeData(){const{data:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id),n=Qo(t);return Ro(n)},get errorMessage(){const{error:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=y.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(i=>i.value):[]}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){const t=y.getParent(e,1).key;y.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){y.addDisposer(e,ie.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Uo=()=>Ui.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ki=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),Dn).views(e=>({get json(){const{_name:t,default_value:n,required:i,width:s,static_options:o,options_query_id:l,default_selection_count:u}=e;return Wt({_name:t,width:s,required:i,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),Ko=()=>Ki.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Xi=y.types.model("FilterConfigModel_TextInput",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:i}=e;return{_name:t,required:n,default_value:i}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),Zi=()=>Xi.create({_name:"text-input",required:!1,default_value:""}),kn=y.types.model("FilterModel",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[Se.Select,Se.MultiSelect,Se.TreeSelect,Se.TextInput,Se.Checkbox,Se.DateRange]),config:y.types.union(Ki,Qi,Ui,Xi,ji,Ri)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==Se.TreeSelect},get auto_submit_supported(){return[Se.Select,Se.Checkbox,Se.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:i,order:s,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:i,order:s,config:c.json,auto_submit:l,visibleInViewsIDs:ie.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.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 Se.Select:e.config=Ko();break;case Se.MultiSelect:e.config=Yo();break;case Se.TreeSelect:e.config=Uo();break;case Se.TextInput:e.config=Zi();break;case Se.Checkbox:e.config=Go();break;case Se.DateRange:e.config=Wo();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));function Ji(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(i=>i===null?i:Y.tz(i,"UTC").format(t.inputFormat)??i)}catch(n){return console.error(n),e}return e}function Xo(e){return e.reduce((t,n)=>(t[n.key]=Ji(n.config.default_value,n.config),t),{})}function Zo(e,t,n){y.addDisposer(e,y.addMiddleware(e,(i,s)=>{s(i,()=>{y.getType(i.context)===t&&i.type==="action"&&n(i.name,i.context)})}))}const Hi=y.types.model("FiltersModel",{current:y.types.optional(y.types.array(kn),[]),values:y.types.optional(y.types.frozen(),{}),previewValues:y.types.optional(y.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 v.sortBy(e.current,"order")},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))},get empty(){return e.current.length===0},visibleInView(t){return v.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),{})}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(i=>i.id===t);n>=0&&e.current.splice(n,1)},setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){Zo(e.current,kn,(n,i)=>{if(n==="setType"){const s=Ji(i.config.default_value,i.config);e.setValueByKey(i.key,s),e.updatePreviewValues({...e.previewValues,[i.key]:s})}})}return{afterCreate(){t()}}});function ea(e){return{current:e,values:Xo(e)}}const ta="\uFEFF";function Jo(e,t){const n=new Blob([ta+t],{type:"text/csv"});xn.saveAs(n,`${e}.csv`)}function Ho(e,t){const n=new Blob([t],{type:"application/json"});xn.saveAs(n,`${e}.json`)}function na(e){const t=new Co;e.forEach(({id:n,data:i})=>{t.file(`${n}.csv`,ia(i))}),t.generateAsync({type:"blob"}).then(n=>{xn.saveAs(n,"dashboard_data.zip")})}function ra(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function ia(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],n=Object.keys(e[0]).map(ra);return t.push(n.join(",")),e.forEach(i=>{const s=Object.values(i).map(ra).join(",");t.push(s)}),ta+t.join(`
55
- `)}const el=y.types.model("QueryModel",{id:y.types.string,name:y.types.string,type:y.types.enumeration("DataSourceType",[he.Postgresql,he.MySQL,he.HTTP]),key:y.types.string,sql:y.types.string,pre_process:y.types.optional(y.types.string,""),post_process:y.types.optional(y.types.string,""),run_by:y.types.optional(y.types.array(y.types.string),[]),react_to:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===he.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:i,key:s,sql:o,run_by:l,react_to:u,pre_process:c,post_process:p}=e;return Wt({id:t,key:s,sql:o,name:n,type:i,run_by:l,react_to:u,pre_process:c,post_process:p})},get conditionOptions(){if(!y.isAlive(e))return[];const{context:t,filters:n}=y.getRoot(e).content.payloadForSQL,i=Object.keys({...t}).map(l=>`context.${l}`),s=Object.keys(n).map(l=>`filters.${l}`);return[...i,...s].map(l=>({label:l.split(".")[1],value:l,group:v.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!y.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=y.getRoot(e).content.payloadForSQL;return t.filter(i=>{const s=v.get(n,i);return Array.isArray(s)?s.length===0:typeof s=="number"?Number.isNaN(s):!s})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=y.getRoot(e).content.payloadForSQL,i=[...t].reduce((s,o)=>(s[o]=v.get(n,o),s),{});return JSON.stringify(i)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=y.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(s=>s.startsWith("context.")).map(s=>s.split("context.")[0]),i=e.unmetRunByConditions.filter(s=>s.startsWith("filters.")).map(s=>v.get({filters:t},s)).filter(s=>!!s);return{context:n,filters:i}}})).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}}));function tl(e,t){return new Function(`return ${e}`)()(t,dt)}function nl(e,t,n){return tl(e,{context:t,filters:n})}function rl(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,dt)}catch(n){return console.error(n),t}}function il(e,t){return new Function(`return ${e.config.processing.post}`)()(t,dt)}function al(e,t){return e?new Function(`return ${e}`)()(t,dt):t}const aa=y.types.compose("QueryModel",el,y.types.model({state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),data:y.types.optional(y.types.array(y.types.frozen()),[]),error:y.types.frozen()})).views(e=>({get formattedSQL(){const t=y.getRoot(e).content.payloadForSQL;return wn(e.sql,t)},get typedAsSQL(){return[he.Postgresql,he.MySQL].includes(e.type)},get typedAsHTTP(){return[he.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return y.getRoot(e).datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=y.getRoot(e).content.payloadForSQL,{name:i,pre_process:s}=e.json,o=nl(s,t,n);return console.groupCollapsed(`Request config for: ${i}`),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 i=[];return t.length>0&&i.push(`context: ${t.join(", ")}`),n.length>0&&i.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:y.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=y.getRoot(e).content.payloadForSQL;e.data=yield*y.toGenerator(Bo({payload:n,title:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!Ze.isCancel(n)){e.data.length=0;const i=v.get(n,"message","unkown error");e.error=v.get(n,"response.data.detail.message",i),e.state="error"}}}}),runHTTP:y.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:i,post_process:s}=e.json;let o=JSON.parse(e.httpConfigString);o=rl(e.datasource,o);const l=yield*y.toGenerator(qo({type:n,key:i,configString:JSON.stringify(o)},e.controller.signal));let u=il(e.datasource,l);u=al(s,u),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!Ze.isCancel(n)){e.data.length=0;const i=v.get(n,"message","unkown error");e.error=v.get(n,"response.data.detail.message",i),e.state="error"}}}})})).actions(e=>({fetchData:()=>e.typedAsHTTP?e.runHTTP():e.runSQL(),beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.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}))}})),sa=y.types.model("QueriesModel",{current:y.types.optional(y.types.array(aa),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return v.sortBy(t,n=>n.label.toLowerCase())}})).views(e=>({get json(){return e.current.filter(t=>t.id).map(t=>t.json)}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},downloadAllData(){const t=e.current.map(({name:n,data:i})=>({id:n,data:i.toJSON()}));na(t)},downloadDataByQueryIDs(t){const n=new Set(t),i=e.current.filter(s=>n.has(s.id)).map(({name:s,data:o})=>({id:s,data:o.toJSON()}));na(i)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:i,data:s}=n,o=ia(s);Jo(i,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()},removeQuery(t){const n=e.current.find(i=>i.id===t);n&&(y.detach(n),e.current.remove(n))}})),oa=y.types.model("SQLSnippetModel",{key:y.types.string,value:y.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}},isADuplicatedKey(t){return!t||t===e.key?!1:!!y.getParent(e,2).findByKey(t)}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}})),la=y.types.model("SQLSnippetsModel",{current:y.types.optional(y.types.array(oa),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return v.sortBy(t,n=>n.label.toLowerCase())},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)}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(i=>i.key===t);n>=0&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),ua=y.types.model("ContextModel",{current:y.types.optional(y.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}})),sl=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=y.getParent(e,1),{type:n,table_name:i,table_schema:s}=t;if(n===he.MySQL)return`
54
+ `;function Cn(e,t){const n=Object.keys(t),i=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...i)}catch(s){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):s}}function wn(e,t){try{return Cn(e,t)}catch(n){return console.error(n),n.message}}function Lo({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},dt)}catch(n){return console.error(n),e}}function Po(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,dt)}catch(n){return console.error(n),t}}function Oo(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s!="authentication"&&e[s])n.push(t[i]+"="+(typeof e[s]=="object"?JSON.stringify(e[s]):e[s]));else{const o=Object.keys(e[s]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[s][u]&&n.push(o[l]+"="+(typeof e[s][u]=="object"?JSON.stringify(e[s][u]):e[s][u]))}}}return n.sort().join("&")}function Vo(e,t){let n=Oo(e);return n+="&key="+t,vi.MD5(n).toString().toUpperCase()}const Ee={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:Vo({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,i,s={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":s.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...s.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?i:s.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=s.string?JSON.stringify(i):i,u.data.authentication=this.getAuthentication(u.data)),Ze(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var i;return t.env||(t.env=((i=this.makeQueryENV)==null?void 0:i.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function qi(e){Ee.baseURL!==e.apiBaseURL&&(Ee.baseURL=e.apiBaseURL),e.app_id&&(Ee.app_id=e.app_id),e.app_secret&&(Ee.app_secret=e.app_secret),e.makeQueryENV&&(Ee.makeQueryENV=e.makeQueryENV)}async function Bo({query:e,payload:t},n){if(!e.sql)return[];const{type:i,key:s,sql:o,pre_process:l,post_process:u}=e,c=Cn(o,t),p=Lo({sql:c,pre_process:l});let f=await Ee.query(n)({type:i,key:s,query:p},{});return f=Po(u,f),f}async function qo({type:e,key:t,configString:n},i){return await Ee.query(i)({type:e,key:t,query:n},{})}async function _n(){try{return(await Ee.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 Ni(){try{return(await Ee.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}const Gi=m.createContext(null),Sn=Gi.Provider;function U(){const e=m.useContext(Gi);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const No={layoutFrozen:!1,freezeLayout:v.noop,inEditMode:!1},He=m.createContext(No),Fi=m.createContext(null),Tn=Fi.Provider;function de(){const e=m.useContext(Fi);if(!e)throw new Error("Please use ModelContextProvider");return e}function Wi(e,t){m.useEffect(()=>{const n=i=>{console.log(i);const{viewID:s}=i.detail;if(!s){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(s),t&&e.views.setIDOfVIE(s)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),m.useEffect(()=>{const n=i=>{console.log(i);const{dictionary:s,payload:o}=i.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(s).forEach(([l,u])=>{e.filters.setValueByKey(l,v.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),m.useEffect(()=>{function n(s){return Array.isArray(s)?[]:typeof s=="object"?{}:typeof s=="boolean"?!1:typeof s=="string"?"":typeof s=="number"?0:s}const i=s=>{console.log(s);const{filter_keys:o}=s.detail;o.forEach(l=>{const u=v.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",i),()=>{window.removeEventListener("clear-filter-values",i)}},[e]),m.useEffect(()=>{const n=i=>{console.log(i);const{urlTemplate:s,openInNewTab:o,enableEncoding:l=!1,payload:u}=i.detail;if(!s){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return v.cloneDeepWith(h,b=>{if(l&&typeof b=="string")return encodeURIComponent(b)})}const f=v.template(s||"")(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])}const ji=y.types.model("FilterConfigModel_Checkbox",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:i}=e;return{_name:t,description:n,default_value:i}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Go=()=>ji.create({_name:"checkbox",description:"",default_value:!1});var he=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(he||{}),Se=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(Se||{});y.types.model({type:y.types.enumeration("DataSourceType",[he.Postgresql,he.MySQL,he.HTTP]),key:y.types.string,sql:y.types.string});function Yi(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 Fo=y.types.model("FilterConfigModel_DateRange",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:i,clearable:s,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:i,clearable:s,inputFormat:o,default_value:Yi(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=y.getParent(e);y.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}})),Ri=y.types.snapshotProcessor(Fo,{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:Yi(t,n.inputFormat)}}}),Wo=()=>Ri.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),jo=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Dn=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(jo),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.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:i}=y.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??""}})),Ft=e=>v.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return ie.toJS(t)}),Qi=y.types.compose("FilterConfigModel_MultiSelect",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),Dn).views(e=>({get json(){const{_name:t,default_value:n,min_width:i,static_options:s,options_query_id:o,default_selection_count:l}=e;return Ft({_name:t,min_width:i,default_value:n,static_options:s,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=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,n=y.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>ie.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Yo=()=>Qi.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function Ro(e){return xo.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function Qo(e){return e.map(t=>{const{label:n,description:i,...s}=t,o={...s,filterBasis:`${n}___${i??""}`,description:i,label:n};return i&&(o.label=m.createElement("div",{},[m.createElement(a.Text,{key:0,title:t.label},t.label),m.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const Ui=y.types.compose("FilterConfigModel_TreeSelect",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),Dn).views(e=>({get json(){const{_name:t,default_value:n,min_width:i,static_options:s,options_query_id:o,default_selection_count:l}=e;return{_name:t,min_width:i,default_value:n,static_options:s,options_query_id:o,default_selection_count:l}},get treeData(){const{data:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id),n=Qo(t);return Ro(n)},get errorMessage(){const{error:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=y.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(i=>i.value):[]}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){const t=y.getParent(e,1).key;y.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){y.addDisposer(e,ie.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Uo=()=>Ui.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ki=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),Dn).views(e=>({get json(){const{_name:t,default_value:n,required:i,width:s,static_options:o,options_query_id:l,default_selection_count:u}=e;return Ft({_name:t,width:s,required:i,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),Ko=()=>Ki.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Xi=y.types.model("FilterConfigModel_TextInput",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:i}=e;return{_name:t,required:n,default_value:i}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),Zi=()=>Xi.create({_name:"text-input",required:!1,default_value:""}),kn=y.types.model("FilterModel",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[Se.Select,Se.MultiSelect,Se.TreeSelect,Se.TextInput,Se.Checkbox,Se.DateRange]),config:y.types.union(Ki,Qi,Ui,Xi,ji,Ri)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==Se.TreeSelect},get auto_submit_supported(){return[Se.Select,Se.Checkbox,Se.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:i,order:s,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:i,order:s,config:c.json,auto_submit:l,visibleInViewsIDs:ie.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.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 Se.Select:e.config=Ko();break;case Se.MultiSelect:e.config=Yo();break;case Se.TreeSelect:e.config=Uo();break;case Se.TextInput:e.config=Zi();break;case Se.Checkbox:e.config=Go();break;case Se.DateRange:e.config=Wo();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));function Ji(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(i=>i===null?i:Y.tz(i,"UTC").format(t.inputFormat)??i)}catch(n){return console.error(n),e}return e}function Xo(e){return e.reduce((t,n)=>(t[n.key]=Ji(n.config.default_value,n.config),t),{})}function Zo(e,t,n){y.addDisposer(e,y.addMiddleware(e,(i,s)=>{s(i,()=>{y.getType(i.context)===t&&i.type==="action"&&n(i.name,i.context)})}))}const Hi=y.types.model("FiltersModel",{current:y.types.optional(y.types.array(kn),[]),values:y.types.optional(y.types.frozen(),{}),previewValues:y.types.optional(y.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 v.sortBy(e.current,"order")},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))},get empty(){return e.current.length===0},visibleInView(t){return v.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),{})}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(i=>i.id===t);n>=0&&e.current.splice(n,1)},setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){Zo(e.current,kn,(n,i)=>{if(n==="setType"){const s=Ji(i.config.default_value,i.config);e.setValueByKey(i.key,s),e.updatePreviewValues({...e.previewValues,[i.key]:s})}})}return{afterCreate(){t()}}});function ea(e){return{current:e,values:Xo(e)}}const ta="\uFEFF";function Jo(e,t){const n=new Blob([ta+t],{type:"text/csv"});xn.saveAs(n,`${e}.csv`)}function Ho(e,t){const n=new Blob([t],{type:"application/json"});xn.saveAs(n,`${e}.json`)}function na(e){const t=new Co;e.forEach(({id:n,data:i})=>{t.file(`${n}.csv`,ia(i))}),t.generateAsync({type:"blob"}).then(n=>{xn.saveAs(n,"dashboard_data.zip")})}function ra(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function ia(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],n=Object.keys(e[0]).map(ra);return t.push(n.join(",")),e.forEach(i=>{const s=Object.values(i).map(ra).join(",");t.push(s)}),ta+t.join(`
55
+ `)}const el=y.types.model("QueryModel",{id:y.types.string,name:y.types.string,type:y.types.enumeration("DataSourceType",[he.Postgresql,he.MySQL,he.HTTP]),key:y.types.string,sql:y.types.string,pre_process:y.types.optional(y.types.string,""),post_process:y.types.optional(y.types.string,""),run_by:y.types.optional(y.types.array(y.types.string),[]),react_to:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===he.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:i,key:s,sql:o,run_by:l,react_to:u,pre_process:c,post_process:p}=e;return Ft({id:t,key:s,sql:o,name:n,type:i,run_by:l,react_to:u,pre_process:c,post_process:p})},get conditionOptions(){if(!y.isAlive(e))return[];const{context:t,filters:n}=y.getRoot(e).content.payloadForSQL,i=Object.keys({...t}).map(l=>`context.${l}`),s=Object.keys(n).map(l=>`filters.${l}`);return[...i,...s].map(l=>({label:l.split(".")[1],value:l,group:v.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!y.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=y.getRoot(e).content.payloadForSQL;return t.filter(i=>{const s=v.get(n,i);return Array.isArray(s)?s.length===0:typeof s=="number"?Number.isNaN(s):!s})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=y.getRoot(e).content.payloadForSQL,i=[...t].reduce((s,o)=>(s[o]=v.get(n,o),s),{});return JSON.stringify(i)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=y.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(s=>s.startsWith("context.")).map(s=>s.split("context.")[0]),i=e.unmetRunByConditions.filter(s=>s.startsWith("filters.")).map(s=>v.get({filters:t},s)).filter(s=>!!s);return{context:n,filters:i}}})).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}}));function tl(e,t){return new Function(`return ${e}`)()(t,dt)}function nl(e,t,n){return tl(e,{context:t,filters:n})}function rl(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,dt)}catch(n){return console.error(n),t}}function il(e,t){return new Function(`return ${e.config.processing.post}`)()(t,dt)}function al(e,t){return e?new Function(`return ${e}`)()(t,dt):t}const aa=y.types.compose("QueryModel",el,y.types.model({state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),data:y.types.optional(y.types.array(y.types.frozen()),[]),error:y.types.frozen()})).views(e=>({get formattedSQL(){const t=y.getRoot(e).content.payloadForSQL;return wn(e.sql,t)},get typedAsSQL(){return[he.Postgresql,he.MySQL].includes(e.type)},get typedAsHTTP(){return[he.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return y.getRoot(e).datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=y.getRoot(e).content.payloadForSQL,{name:i,pre_process:s}=e.json,o=nl(s,t,n);return console.groupCollapsed(`Request config for: ${i}`),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 i=[];return t.length>0&&i.push(`context: ${t.join(", ")}`),n.length>0&&i.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:y.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=y.getRoot(e).content.payloadForSQL;e.data=yield*y.toGenerator(Bo({payload:n,title:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!Ze.isCancel(n)){e.data.length=0;const i=v.get(n,"message","unkown error");e.error=v.get(n,"response.data.detail.message",i),e.state="error"}}}}),runHTTP:y.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:i,post_process:s}=e.json;let o=JSON.parse(e.httpConfigString);o=rl(e.datasource,o);const l=yield*y.toGenerator(qo({type:n,key:i,configString:JSON.stringify(o)},e.controller.signal));let u=il(e.datasource,l);u=al(s,u),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!Ze.isCancel(n)){e.data.length=0;const i=v.get(n,"message","unkown error");e.error=v.get(n,"response.data.detail.message",i),e.state="error"}}}})})).actions(e=>({fetchData:()=>e.typedAsHTTP?e.runHTTP():e.runSQL(),beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.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}))}})),sa=y.types.model("QueriesModel",{current:y.types.optional(y.types.array(aa),[])}).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 options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return v.sortBy(t,n=>n.label.toLowerCase())}})).views(e=>({get json(){return e.current.filter(t=>t.id).map(t=>t.json)}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},downloadAllData(){const t=e.current.map(({name:n,data:i})=>({id:n,data:i.toJSON()}));na(t)},downloadDataByQueryIDs(t){const n=new Set(t),i=e.current.filter(s=>n.has(s.id)).map(({name:s,data:o})=>({id:s,data:o.toJSON()}));na(i)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:i,data:s}=n,o=ia(s);Jo(i,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()},removeQuery(t){const n=e.current.find(i=>i.id===t);n&&(y.detach(n),e.current.remove(n))}})),oa=y.types.model("SQLSnippetModel",{key:y.types.string,value:y.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}},isADuplicatedKey(t){return!t||t===e.key?!1:!!y.getParent(e,2).findByKey(t)}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}})),la=y.types.model("SQLSnippetsModel",{current:y.types.optional(y.types.array(oa),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return v.sortBy(t,n=>n.label.toLowerCase())},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)}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(i=>i.key===t);n>=0&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),ua=y.types.model("ContextModel",{current:y.types.optional(y.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}})),sl=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=y.getParent(e,1),{type:n,table_name:i,table_schema:s}=t;if(n===he.MySQL)return`
56
56
  SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
57
57
  FROM information_schema.columns
58
58
  WHERE table_name = '${i}' AND table_schema = '${s}'
@@ -115,15 +115,15 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
115
115
  `},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
116
116
  SELECT count(*) AS total
117
117
  FROM ${n}.${t}
118
- `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(e,ie.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),cl=y.types.model("DataSourceModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[he.HTTP,he.MySQL,he.Postgresql]),key:y.types.string,config:y.types.frozen(),tables:y.types.optional(ll,{}),columns:y.types.optional(sl,{}),tableData:y.types.optional(ul,{}),indexes:y.types.optional(ol,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.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=y.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const i=yield*y.toGenerator(Ee.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=v.groupBy(i,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(i){if(!Ze.isCancel(i)){e.tables.data={};const s=v.get(i,"message","unkown error");e.tables.error=v.get(i,"response.data.detail.message",s),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:y.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*y.toGenerator(Ee.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(i){if(Ze.isCancel(i))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const s=v.get(i,"message","unkown error");e.columns.error=v.get(i,"response.data.detail.message",s),e.columns.state="error"}}}),loadIndexes:y.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*y.toGenerator(Ee.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(i){if(Ze.isCancel(i))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const s=v.get(i,"message","unkown error");e.indexes.error=v.get(i,"response.data.detail.message",s),e.indexes.state="error"}}}),loadTableData:y.flow(function*(){var i;(i=e.controllers.tableData)==null||i.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*y.toGenerator(Ee.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:s}]=yield*y.toGenerator(Ee.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(s),n.state="idle",n.error=null}catch(s){if(Ze.isCancel(s))n.state="idle",n.error=null;else{n.data=[];const o=v.get(s,"message","unkown error");n.error=v.get(s,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(e,ie.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),dl=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(cl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(i=>i.key===n&&i.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 jt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function pl(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 hl=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=y.getRoot(e),{filters:n,views:i,sqlSnippets:s,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:L.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:L.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:L.IconFilter,children:[...n.options,jt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...s.options,jt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,jt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...i.editorOptions,jt("_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=pl(t);n&&e.setPath(n)}})),fl=y.types.model("MockContextModel",{current:y.types.optional(y.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}})),gl=y.types.model("VariableModel",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}))}).views(e=>({get json(){const{name:t,size:n,weight:i,color:s,formatter:o,data_field:l,aggregation:u}=e;return v.cloneDeep({name:t,size:n,color:s,weight:i,formatter:o,data_field:l,aggregation:u})}}));class ml{constructor(t){V(this,"origin");V(this,"copy");this.origin=t,this.copy=y.clone(t),ie.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!v.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(t){y.applySnapshot(this.copy,t)}}const yl=e=>new ml(e);class bl{constructor(){V(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,i){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 s=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=v.orderBy(s,"version","asc");if(((l=v.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,i),n)}}class me extends bl{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(i,s)=>({version:t,...n(i,s)}))}async migrate({configData:t,panelModel:n}){const i=await t.getItem(null),s=v.get(i,"version",0),o=this.run({from:s,to:this.VERSION},i,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return v.get(n,"version",0)<this.VERSION}}var qe=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(qe||{});const ca=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
119
- `),In={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class pt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,v.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:v.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[t]:n})}return await this.getItem(t)}watchItem(t,n,i){return t===null?this.root.watchItem(this.path,(s,o)=>{n(s,o)},i):this.root.watchItem(this.path,(s,o)=>{const l=v.get(s,t),u=v.get(o,t);l!==u&&n(l,u)},i)}}class Mn{constructor(t,n,i){V(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=i,this.attachmentStorage=new pt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new pt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new pt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(v.values(t).map(n=>this.constructInstance(new pt(this.attachmentStorage,n.id))))}}class da{constructor(t){V(this,"rootRef");this.rootRef=ie.observable({current:t})}async deleteItem(t){ie.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?ie.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(v.isObject(n))ie.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ie.runInAction(()=>{v.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,i){return ie.reaction(()=>this.getValueFromRoot(t),(s,o)=>{n(s,o)},{requiresObservable:!0,fireImmediately:v.get(i,"fireImmediately",!1)})}}class vl{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new xi)}getChannel(t){const n=this.channels.get(t);if(n)return n;const i=new xi;return this.channels.set(t,i),i}}class xl{constructor(t){V(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 i={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new vl,instanceData:new da(t.viz.conf)};return this.instances.set(t.id,i),i}}function pa(e,t,n,i){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new da({}),colorPalette:{getColor(){return()=>""}},data:t,variables:i}}const Cl=e=>{const{panel:t,vizManager:n,data:i,variables:s}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...pa(l,i,n,s),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return r(c,{context:u,instance:l,...v.omit(e,["panel","vizManager","data"])})},wl=e=>{const{vizManager:t,panel:n,panelInfoEditor:i,data:s,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...pa(u,s,t,o),panelInfoEditor:i},p=l.configRender;return r(p,{context:c,instance:u,...v.omit(e,["panel","vizManager","data","panelInfoEditor"])})},ha=(e,t)=>{const n=Re.bezier(e),i=Re.bezier(t);return function(s){return s<50?n(s*2/100).hex():i((s-50)*2/100).hex()}},Yt=e=>{const t=Re.bezier(e);return function(n){return t(n/100).hex()}},_l={type:"interpolation",displayName:"Red / Green",getColor:ha(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Sl={type:"interpolation",displayName:"Yellow / Blue",getColor:ha(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Tl={type:"interpolation",displayName:"Red",getColor:Yt(["#fff7f1","darkred"]),name:"red",category:"sequential"},Dl={type:"interpolation",displayName:"Green",getColor:Yt(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},kl={type:"interpolation",displayName:"Blue",getColor:Yt(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Il={type:"interpolation",displayName:"Orange",getColor:Yt(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Ml{constructor(t){V(this,"symbol");this.symbol=Symbol(t)}}function Qe(e){return new Ml(e)}class $n{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const t=new $n;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 i=n(this);return this.instanceRegistry.set(t.symbol,i),i}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=v.get(t,"dispose");v.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const fa="@devtable/dashboard",An="9.19.1",ga="Apache-2.0",ma={access:"public",registry:"https://registry.npmjs.org/"},ya=["dist"],ba="./dist/dashboard.umd.js",va="./dist/dashboard.es.js",xa="./dist/index.d.ts",Ca={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},wa={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},_a={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5",mathjs:"11.8.0","monaco-editor":"0.36.0","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-select":"14.1.0","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},Sa={"@emotion/babel-plugin":"11.11.0","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@testing-library/cypress":"^9.0.0","@testing-library/jest-dom":"^5.16.4","@testing-library/react":"^13.3.0","@testing-library/react-hooks":"^8.0.1","@testing-library/user-event":"^14.3.0","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.4","@types/eventemitter2":"^4.1.0","@types/file-saver":"2.0.5","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2",ahooks:"^3.3.11",ajv:"8.12.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^12.9.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",jsdom:"^20.0.0","jsdom-testing-mocks":"^1.5.0",lodash:"^4.17.21",lowlight:"^2.8.0",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","rollup-plugin-visualizer":"5.9.0","tabler-icons-react":"^1.48.0",typescript:"^4.6.3","vite-plugin-static-copy":"0.13.1"},Ta={"@emotion/react":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@tanstack/react-table":"^8.5.13","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","crypto-js":"^4.1.1","d3-array":"3.2.3","d3-regression":"1.3.10",dayjs:"1.11.7",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",eventemitter2:"^6.4.6",jszip:"3.10.1",lodash:"^4.17.21",lowlight:"^2.8.0",mobx:"^6.6.1","mobx-react-lite":"^3.4.0","mobx-state-tree":"^5.1.5",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","react-router-dom":"^6.3.0","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},$l=Object.freeze(Object.defineProperty({__proto__:null,default:{name:fa,version:An,license:ga,publishConfig:ma,files:ya,main:ba,module:va,types:xa,exports:Ca,scripts:wa,dependencies:_a,devDependencies:Sa,peerDependencies:Ta},dependencies:_a,devDependencies:Sa,exports:Ca,files:ya,license:ga,main:ba,module:va,name:fa,peerDependencies:Ta,publishConfig:ma,scripts:wa,types:xa,version:An},Symbol.toStringTag,{value:"Module"}));class Al{constructor(t){V(this,"staticColors",new Map);V(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(i=>{this.register(i)})})}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 zl{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(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())}}const W=(e,t)=>{const[n,{setFalse:i}]=X.useBoolean(!0),[s,o]=m.useState();m.useEffect(()=>(e.getItem(t).then(u=>{o(u),i()}),e.watchItem(t,u=>{o(u)})));const l=m.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:s,set:l}},zn={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 O(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Ue(e,t){var s;const{queryID:n,columnKey:i}=O(t);return n?i?((s=e[n])==null?void 0:s.map(o=>o[i]))??[]:e[n]:[]}function kt(e,t){const{queryID:n}=O(t);return n?e[n]:[]}function El(e){return Object.values(e)[0]}function Rt(e,t){const{queryID:n,columnKey:i}=O(t);return e[i]}oe.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function Ll({context:e}){const{value:t}=W(e.instanceData,"config"),n=e.data,{width:i,height:s}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:p,zAxis3D:f}=v.defaults({},t,zn),h=m.useMemo(()=>kt(n,o),[n,o]),{x:g,y:b,z:_}=m.useMemo(()=>({x:O(o),y:O(l),z:O(u)}),[o,l,u]),{min:C,max:S}=m.useMemo(()=>{const $=v.minBy(h,N=>N[_.columnKey]),q=v.maxBy(h,N=>N[_.columnKey]);return{min:v.get($,_.columnKey),max:v.get(q,_.columnKey)}},[h,_]),I={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:S,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:p,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map($=>[$[g.columnKey],$[b.columnKey],$[_.columnKey]])}]};return t?r(ze,{echarts:oe,option:I,style:{width:i,height:s},notMerge:!0,theme:"merico-light"}):null}const Da=m.createContext({panel:null,data:{},loading:!1,errors:[]}),En=Da.Provider;function Te(){const e=m.useContext(Da);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Pl={fullScreenPanelID:"",setFullScreenPanelID:v.noop},Ln=m.createContext(Pl);function ka(){const e=m.useContext(Ln);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const j=T.observer(m.forwardRef(({label:e,required:t,value:n,onChange:i,clearable:s=!1,sx:o,...l},u)=>{const{panel:c}=Te(),p=m.useMemo(()=>{const f=[...c.dataFieldOptions];return s&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return r(a.Select,{ref:u,label:e,data:p,value:n,onChange:i,required:t,sx:o,...l})}));function Ol({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=v.defaults({},t,zn),{control:s,handleSubmit:o,reset:l}=x.useForm({defaultValues:i});return m.useEffect(()=>{l(i)},[t]),t?r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[r(a.Text,{children:"X Axis"}),d(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(x.Controller,{name:"x_axis_data_key",control:s,render:({field:u})=>r(j,{label:"Data Field",required:!0,...u})}),r(x.Controller,{name:"xAxis3D.name",control:s,render:({field:u})=>r(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(a.Text,{mt:"lg",children:"Y Axis"}),d(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(x.Controller,{name:"y_axis_data_key",control:s,render:({field:u})=>r(j,{label:"Data Field",required:!0,...u})}),r(x.Controller,{name:"yAxis3D.name",control:s,render:({field:u})=>r(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(a.Text,{mt:"lg",children:"Z Axis"}),d(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(x.Controller,{name:"z_axis_data_key",control:s,render:({field:u})=>r(j,{label:"Data Field",required:!0,...u})}),r(x.Controller,{name:"zAxis3D.name",control:s,render:({field:u})=>r(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:d(a.Button,{color:"blue",type:"submit",children:[r(D.DeviceFloppy,{size:20}),r(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Vl(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis_data_key:s,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:i(s),y_axis_data_key:i(o),z_axis_data_key:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Bl extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:s}=n;return{...n,version:2,config:Vl(s,i)}})}}const ql={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Bl,name:"bar-3d",viewRender:Ll,configRender:Ol,createConfig(){return{version:2,config:v.cloneDeep(zn)}}};class Le extends m.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 d(a.Box,{children:[r(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),r(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const ke={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Nl({value:e,onChange:t},n){const i=u=>{t({...e,output:u})},s=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 d(a.Stack,{ref:n,children:[d(a.Group,{grow:!0,children:[r(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),r(a.Switch,{label:d(a.Stack,{spacing:0,children:[r(a.Text,{children:"Average"}),r(a.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"}}})]}),d(a.Group,{grow:!0,children:[r(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:s}),r(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),d(a.Stack,{spacing:0,children:[r(a.Text,{weight:"bold",children:"Preview"}),r(Le,{children:d(a.Group,{position:"apart",children:[d(a.Text,{size:12,color:"gray",children:["123456789 ",r(D.ArrowRight,{size:9})," ",ee(123456789).format(e)]}),d(a.Text,{size:12,color:"gray",children:["1234 ",r(D.ArrowRight,{size:9})," ",ee(1234).format(e)]}),d(a.Text,{size:12,color:"gray",children:["0.1234 ",r(D.ArrowRight,{size:9})," ",ee(.1234).format(e)]})]})})]})]})}const Ne=m.forwardRef(Nl),Fe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
120
- `)},Ia={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Fl,configRender:Gl,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 Gl(e){return r(B,{})}function Fl(e){return r(a.Text,{children:"Click chart's series"})}const Wl=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Qt=m.forwardRef(({sectionTitle:e,value:t,onChange:n},i)=>{const s=o=>l=>{const u=v.cloneDeep(t);v.set(u,o,l),n(u)};return d(a.Stack,{spacing:0,children:[e&&r(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:s("width")}),r(a.Select,{label:"Overflow",data:Wl,value:t.overflow,onChange:s("overflow")}),r(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),et=m.forwardRef(({value:e,onChange:t},n)=>{const i=o=>{t({...e,on_axis:o})},s=o=>{t({...e,in_tooltip:o})};return d(a.Stack,{ref:n,spacing:0,children:[r(Qt,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:i}),r(Qt,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:s})]})}),Ge={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function tt({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],i=e==="truncate"?"nowrap":"initial",s={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
118
+ `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(e,ie.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),cl=y.types.model("DataSourceModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[he.HTTP,he.MySQL,he.Postgresql]),key:y.types.string,config:y.types.frozen(),tables:y.types.optional(ll,{}),columns:y.types.optional(sl,{}),tableData:y.types.optional(ul,{}),indexes:y.types.optional(ol,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.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=y.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const i=yield*y.toGenerator(Ee.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=v.groupBy(i,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(i){if(!Ze.isCancel(i)){e.tables.data={};const s=v.get(i,"message","unkown error");e.tables.error=v.get(i,"response.data.detail.message",s),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:y.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*y.toGenerator(Ee.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(i){if(Ze.isCancel(i))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const s=v.get(i,"message","unkown error");e.columns.error=v.get(i,"response.data.detail.message",s),e.columns.state="error"}}}),loadIndexes:y.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*y.toGenerator(Ee.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(i){if(Ze.isCancel(i))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const s=v.get(i,"message","unkown error");e.indexes.error=v.get(i,"response.data.detail.message",s),e.indexes.state="error"}}}),loadTableData:y.flow(function*(){var i;(i=e.controllers.tableData)==null||i.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*y.toGenerator(Ee.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:s}]=yield*y.toGenerator(Ee.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(s),n.state="idle",n.error=null}catch(s){if(Ze.isCancel(s))n.state="idle",n.error=null;else{n.data=[];const o=v.get(s,"message","unkown error");n.error=v.get(s,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){y.addDisposer(e,ie.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(e,ie.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),dl=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(cl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(i=>i.key===n&&i.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 Wt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function pl(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 hl=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=y.getRoot(e),{filters:n,views:i,sqlSnippets:s,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:L.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:L.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:L.IconFilter,children:[...n.options,Wt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...s.options,Wt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,Wt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...i.editorOptions,Wt("_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=pl(t);n&&e.setPath(n)}})),fl=y.types.model("MockContextModel",{current:y.types.optional(y.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}})),gl=y.types.model("VariableModel",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}))}).views(e=>({get json(){const{name:t,size:n,weight:i,color:s,formatter:o,data_field:l,aggregation:u}=e;return v.cloneDeep({name:t,size:n,color:s,weight:i,formatter:o,data_field:l,aggregation:u})}}));class ml{constructor(t){V(this,"origin");V(this,"copy");this.origin=t,this.copy=y.clone(t),ie.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!v.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(t){y.applySnapshot(this.copy,t)}}const yl=e=>new ml(e);class bl{constructor(){V(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,i){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 s=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=v.orderBy(s,"version","asc");if(((l=v.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,i),n)}}class me extends bl{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(i,s)=>({version:t,...n(i,s)}))}async migrate({configData:t,panelModel:n}){const i=await t.getItem(null),s=v.get(i,"version",0),o=this.run({from:s,to:this.VERSION},i,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return v.get(n,"version",0)<this.VERSION}}var qe=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(qe||{});const ca=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
119
+ `),In={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class pt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,v.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:v.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[t]:n})}return await this.getItem(t)}watchItem(t,n,i){return t===null?this.root.watchItem(this.path,(s,o)=>{n(s,o)},i):this.root.watchItem(this.path,(s,o)=>{const l=v.get(s,t),u=v.get(o,t);l!==u&&n(l,u)},i)}}class Mn{constructor(t,n,i){V(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=i,this.attachmentStorage=new pt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new pt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new pt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(v.values(t).map(n=>this.constructInstance(new pt(this.attachmentStorage,n.id))))}}class da{constructor(t){V(this,"rootRef");this.rootRef=ie.observable({current:t})}async deleteItem(t){ie.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?ie.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(v.isObject(n))ie.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ie.runInAction(()=>{v.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,i){return ie.reaction(()=>this.getValueFromRoot(t),(s,o)=>{n(s,o)},{requiresObservable:!0,fireImmediately:v.get(i,"fireImmediately",!1)})}}class vl{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new xi)}getChannel(t){const n=this.channels.get(t);if(n)return n;const i=new xi;return this.channels.set(t,i),i}}class xl{constructor(t){V(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 i={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new vl,instanceData:new da(t.viz.conf)};return this.instances.set(t.id,i),i}}function pa(e,t,n,i){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new da({}),colorPalette:{getColor(){return()=>""}},data:t,variables:i}}const Cl=e=>{const{panel:t,vizManager:n,data:i,variables:s}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...pa(l,i,n,s),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return r(c,{context:u,instance:l,...v.omit(e,["panel","vizManager","data"])})},wl=e=>{const{vizManager:t,panel:n,panelInfoEditor:i,data:s,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...pa(u,s,t,o),panelInfoEditor:i},p=l.configRender;return r(p,{context:c,instance:u,...v.omit(e,["panel","vizManager","data","panelInfoEditor"])})},ha=(e,t)=>{const n=Re.bezier(e),i=Re.bezier(t);return function(s){return s<50?n(s*2/100).hex():i((s-50)*2/100).hex()}},jt=e=>{const t=Re.bezier(e);return function(n){return t(n/100).hex()}},_l={type:"interpolation",displayName:"Red / Green",getColor:ha(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Sl={type:"interpolation",displayName:"Yellow / Blue",getColor:ha(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Tl={type:"interpolation",displayName:"Red",getColor:jt(["#fff7f1","darkred"]),name:"red",category:"sequential"},Dl={type:"interpolation",displayName:"Green",getColor:jt(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},kl={type:"interpolation",displayName:"Blue",getColor:jt(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Il={type:"interpolation",displayName:"Orange",getColor:jt(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Ml{constructor(t){V(this,"symbol");this.symbol=Symbol(t)}}function Qe(e){return new Ml(e)}class $n{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const t=new $n;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 i=n(this);return this.instanceRegistry.set(t.symbol,i),i}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=v.get(t,"dispose");v.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const fa="@devtable/dashboard",An="9.19.3",ga="Apache-2.0",ma={access:"public",registry:"https://registry.npmjs.org/"},ya=["dist"],ba="./dist/dashboard.umd.js",va="./dist/dashboard.es.js",xa="./dist/index.d.ts",Ca={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},wa={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},_a={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5",mathjs:"11.8.0","monaco-editor":"0.36.0","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-select":"14.1.0","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},Sa={"@emotion/babel-plugin":"11.11.0","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@testing-library/cypress":"^9.0.0","@testing-library/jest-dom":"^5.16.4","@testing-library/react":"^13.3.0","@testing-library/react-hooks":"^8.0.1","@testing-library/user-event":"^14.3.0","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.4","@types/eventemitter2":"^4.1.0","@types/file-saver":"2.0.5","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2",ahooks:"^3.3.11",ajv:"8.12.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^12.9.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",jsdom:"^20.0.0","jsdom-testing-mocks":"^1.5.0",lodash:"^4.17.21",lowlight:"^2.8.0",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","rollup-plugin-visualizer":"5.9.0","tabler-icons-react":"^1.48.0",typescript:"^4.6.3","vite-plugin-static-copy":"0.13.1"},Ta={"@emotion/react":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@tanstack/react-table":"^8.5.13","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","crypto-js":"^4.1.1","d3-array":"3.2.3","d3-regression":"1.3.10",dayjs:"1.11.7",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",eventemitter2:"^6.4.6",jszip:"3.10.1",lodash:"^4.17.21",lowlight:"^2.8.0",mobx:"^6.6.1","mobx-react-lite":"^3.4.0","mobx-state-tree":"^5.1.5",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","react-router-dom":"^6.3.0","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},$l=Object.freeze(Object.defineProperty({__proto__:null,default:{name:fa,version:An,license:ga,publishConfig:ma,files:ya,main:ba,module:va,types:xa,exports:Ca,scripts:wa,dependencies:_a,devDependencies:Sa,peerDependencies:Ta},dependencies:_a,devDependencies:Sa,exports:Ca,files:ya,license:ga,main:ba,module:va,name:fa,peerDependencies:Ta,publishConfig:ma,scripts:wa,types:xa,version:An},Symbol.toStringTag,{value:"Module"}));class Al{constructor(t){V(this,"staticColors",new Map);V(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(i=>{this.register(i)})})}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 zl{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(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())}}const W=(e,t)=>{const[n,{setFalse:i}]=X.useBoolean(!0),[s,o]=m.useState();m.useEffect(()=>(e.getItem(t).then(u=>{o(u),i()}),e.watchItem(t,u=>{o(u)})));const l=m.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:s,set:l}},zn={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 O(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Ue(e,t){var s;const{queryID:n,columnKey:i}=O(t);return n?i?((s=e[n])==null?void 0:s.map(o=>o[i]))??[]:e[n]:[]}function kt(e,t){const{queryID:n}=O(t);return n?e[n]:[]}function El(e){return Object.values(e)[0]}function Yt(e,t){const{queryID:n,columnKey:i}=O(t);return e[i]}oe.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function Ll({context:e}){const{value:t}=W(e.instanceData,"config"),n=e.data,{width:i,height:s}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:p,zAxis3D:f}=v.defaults({},t,zn),h=m.useMemo(()=>kt(n,o),[n,o]),{x:g,y:b,z:_}=m.useMemo(()=>({x:O(o),y:O(l),z:O(u)}),[o,l,u]),{min:C,max:S}=m.useMemo(()=>{const $=v.minBy(h,N=>N[_.columnKey]),q=v.maxBy(h,N=>N[_.columnKey]);return{min:v.get($,_.columnKey),max:v.get(q,_.columnKey)}},[h,_]),I={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:S,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:p,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map($=>[$[g.columnKey],$[b.columnKey],$[_.columnKey]])}]};return t?r(ze,{echarts:oe,option:I,style:{width:i,height:s},notMerge:!0,theme:"merico-light"}):null}const Da=m.createContext({panel:null,data:{},loading:!1,errors:[]}),En=Da.Provider;function Te(){const e=m.useContext(Da);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Pl={fullScreenPanelID:"",setFullScreenPanelID:v.noop},Ln=m.createContext(Pl);function ka(){const e=m.useContext(Ln);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const j=T.observer(m.forwardRef(({label:e,required:t,value:n,onChange:i,clearable:s=!1,sx:o,...l},u)=>{const{panel:c}=Te(),p=m.useMemo(()=>{const f=[...c.dataFieldOptions];return s&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return r(a.Select,{ref:u,label:e,data:p,value:n,onChange:i,required:t,sx:o,...l})}));function Ol({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=v.defaults({},t,zn),{control:s,handleSubmit:o,reset:l}=x.useForm({defaultValues:i});return m.useEffect(()=>{l(i)},[t]),t?r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[r(a.Text,{children:"X Axis"}),d(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(x.Controller,{name:"x_axis_data_key",control:s,render:({field:u})=>r(j,{label:"Data Field",required:!0,...u})}),r(x.Controller,{name:"xAxis3D.name",control:s,render:({field:u})=>r(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(a.Text,{mt:"lg",children:"Y Axis"}),d(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(x.Controller,{name:"y_axis_data_key",control:s,render:({field:u})=>r(j,{label:"Data Field",required:!0,...u})}),r(x.Controller,{name:"yAxis3D.name",control:s,render:({field:u})=>r(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(a.Text,{mt:"lg",children:"Z Axis"}),d(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(x.Controller,{name:"z_axis_data_key",control:s,render:({field:u})=>r(j,{label:"Data Field",required:!0,...u})}),r(x.Controller,{name:"zAxis3D.name",control:s,render:({field:u})=>r(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:d(a.Button,{color:"blue",type:"submit",children:[r(D.DeviceFloppy,{size:20}),r(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Vl(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis_data_key:s,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:i(s),y_axis_data_key:i(o),z_axis_data_key:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Bl extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:s}=n;return{...n,version:2,config:Vl(s,i)}})}}const ql={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Bl,name:"bar-3d",viewRender:Ll,configRender:Ol,createConfig(){return{version:2,config:v.cloneDeep(zn)}}};class Le extends m.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 d(a.Box,{children:[r(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),r(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const ke={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Nl({value:e,onChange:t},n){const i=u=>{t({...e,output:u})},s=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 d(a.Stack,{ref:n,children:[d(a.Group,{grow:!0,children:[r(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),r(a.Switch,{label:d(a.Stack,{spacing:0,children:[r(a.Text,{children:"Average"}),r(a.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"}}})]}),d(a.Group,{grow:!0,children:[r(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:s}),r(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),d(a.Stack,{spacing:0,children:[r(a.Text,{weight:"bold",children:"Preview"}),r(Le,{children:d(a.Group,{position:"apart",children:[d(a.Text,{size:12,color:"gray",children:["123456789 ",r(D.ArrowRight,{size:9})," ",ee(123456789).format(e)]}),d(a.Text,{size:12,color:"gray",children:["1234 ",r(D.ArrowRight,{size:9})," ",ee(1234).format(e)]}),d(a.Text,{size:12,color:"gray",children:["0.1234 ",r(D.ArrowRight,{size:9})," ",ee(.1234).format(e)]})]})})]})]})}const Ne=m.forwardRef(Nl),Fe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
120
+ `)},Ia={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Fl,configRender:Gl,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 Gl(e){return r(B,{})}function Fl(e){return r(a.Text,{children:"Click chart's series"})}const Wl=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Rt=m.forwardRef(({sectionTitle:e,value:t,onChange:n},i)=>{const s=o=>l=>{const u=v.cloneDeep(t);v.set(u,o,l),n(u)};return d(a.Stack,{spacing:0,children:[e&&r(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:s("width")}),r(a.Select,{label:"Overflow",data:Wl,value:t.overflow,onChange:s("overflow")}),r(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),et=m.forwardRef(({value:e,onChange:t},n)=>{const i=o=>{t({...e,on_axis:o})},s=o=>{t({...e,in_tooltip:o})};return d(a.Stack,{ref:n,spacing:0,children:[r(Rt,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:i}),r(Rt,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:s})]})}),Ge={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function tt({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],i=e==="truncate"?"nowrap":"initial",s={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
121
121
  max-width: ${t}px;
122
122
  word-break: ${n};
123
123
  white-space: ${i};
124
124
  overflow: hidden;
125
125
  text-overflow: ${s};
126
- `}function Ke(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const Pn={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Fe},overflow:Ge}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:ke},tooltip:{metrics:[]},color:"#228be6",reference_lines:[]},We=(e,t)=>{const[n,i]=m.useState([]);return m.useEffect(()=>e.watchTriggerSnapshotList(s=>i(s.filter(o=>o.schemaRef===t))),[]),n},Ma=e=>{const{title:t="Variables",variables:n}=e,i=we.useClipboard(),s=o=>{i.copy(o),qt.showNotification({color:"green",message:"Copied to clipboard"})};return d(a.Paper,{withBorder:!0,p:"sm",children:[r(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),r(a.Stack,{style:{maxHeight:"500px"},children:n.map(o=>d(a.Text,{size:"sm",children:[d(a.Code,{color:"teal",children:["// ",o.description]}),r("br",{}),d(a.Code,{onClick:()=>s(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class jl{constructor(t,n){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=t,this.instance=n,ie.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const i=await this.operationManager.retrieveTrigger(t),s=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ie.runInAction(()=>{this.operationId=t,this.operation=i,this.operationSchema=s,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Yl(e){return!!e.operationId}const Rl=T.observer(({model:e,onClick:t})=>{var i;const n=(i=e.operationSchema)==null?void 0:i.displayName;return r(a.Button,{variant:"outline",onClick:t,children:n})}),Ql=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return m.createElement(e.operationSchema.configRender,t)});function Ul({model:e}){const t=e.schemaList,n=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return r(a.Select,{label:"Operation",data:n,onChange:i,value:e.operationSchema.id})}const Kl=T.observer(e=>{const[t,{setTrue:n,setFalse:i}]=X.useBoolean(!1),{operationManager:s,operationId:o,instance:l,variables:u}=e,c=X.useCreation(()=>new jl(s,l),[s,l]);return X.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),Yl(c)?d(B,{children:[r(Rl,{model:c,onClick:n}),r(a.Modal,{size:600,opened:t,onClose:i,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:d(a.Stack,{children:[r(Ul,{model:c}),d(a.Tabs,{defaultValue:"settings",children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"settings",children:"Settings"}),r(a.Tabs.Tab,{value:"variables",children:"Variables"})]}),r(a.Tabs.Panel,{value:"settings",pt:10,children:r(Ql,{model:c})}),r(a.Tabs.Panel,{value:"variables",pt:10,children:r(Ma,{title:"Variables",variables:c.variables})})]})]})})]}):null});class Xl{constructor(t,n){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=t,this.instance=n,ie.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const i=await this.triggerManager.retrieveTrigger(t),s=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ie.runInAction(()=>{this.triggerId=t,this.trigger=i,this.triggerSchema=s,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Zl(this)}}function Zl(e){return!!e.triggerId&&!!e.triggerSchema}function Jl(e,t){return X.useCreation(()=>new Xl(e,t),[e,t])}const Hl=T.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,i={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return r(a.Button,{variant:"outline",onClick:t,children:m.createElement(n,i)})}),eu=T.observer(({model:e})=>{const t=e.schemaList,n=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return r(a.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:i})}),tu=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return m.createElement(e.triggerSchema.configRender,t)}),nu=T.observer(e=>{const[t,{setTrue:n,setFalse:i}]=X.useBoolean(!1),s=e.model;return d(B,{children:[r(a.Modal,{opened:t,onClose:i,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:d(a.Stack,{children:[r(eu,{model:s}),r(tu,{model:s}),r(Ma,{title:"Payload",variables:s.triggerSchema.payload})]})}),r(Hl,{onClick:n,model:s})]})});function ru(e,t){const[n,i]=m.useState([]);return X.useAsyncEffect(async()=>{const s=await e.getInteractionList();i(s)},[t,e]),n}const iu=T.observer(({item:e,manager:t,instance:n,sampleData:i,variables:s,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=Jl(t.triggerManager,n);if(X.useAsyncEffect(async()=>{await c.configTrigger(l,i)},[c,l,i]),c.isReady()){const p=[...c.triggerSchema.payload,...s];return d(a.Group,{children:[r(nu,{model:c}),r(Kl,{instance:n,operationId:u,variables:p,operationManager:t.operationManager}),r(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:r(D.Trash,{size:16})})]})}return null}),au=e=>{const[t,n]=m.useState(0),{interactionManager:i,instance:s,sampleData:o,variables:l}=e,u=ru(i,t),c=async()=>{const g=await i.triggerManager.createOrGetTrigger(we.randomId(),i.triggerManager.getTriggerSchemaList()[0]),b=await i.operationManager.createOrGetOperation(we.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(g,b),n(_=>_+1)};async function p(g){await i.removeInteraction(g.id),n(b=>b+1)}const{data:f=0,loading:h}=X.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return d(a.Stack,{children:[r(a.LoadingOverlay,{visible:h}),f===0&&r(a.Alert,{icon:r(D.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>r(iu,{onRemove:p,instance:s,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),r(a.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},su=()=>{const{panel:e,data:t}=Te(),n=e.viz,{vizManager:i}=m.useContext(je),s=e.json,o=X.useCreation(()=>i.getOrCreateInstance(s),[i,s]),l=X.useCreation(()=>new hr(o,i.resolveComponent(n.type),ln),[o,n.type]);return m.useEffect(()=>o.instanceData.watchItem(null,v.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:l,sampleData:t,variables:[]}},ou=()=>{const e=su();return r(au,{...e})},$a="__TRIGGERS";class lu{constructor(t,n){V(this,"attachments");this.instance=t,this.component=n;const i=async s=>{const{id:o,schemaRef:l}=await s.getItem(null);return{id:o,schemaRef:l,triggerData:new pt(s,"data")}};this.attachments=new Mn(t,$a,i)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem($a,n=>{const i=v.values(n).map(s=>({id:v.get(s,"id"),schemaRef:v.get(s,"schemaRef"),config:ie.toJS(v.get(s,"data.config"))}));t(i)},{fireImmediately:!0})}async createOrGetTrigger(t,n,i={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||i.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async i=>{const s=this.getTriggerSchemaList().find(u=>u.id===i.schemaRef),o=s==null?void 0:s.migrator,l={configData:i.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(i=>i.filter(s=>s))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}function ht({enabled:e,func_content:t}){return(n,i)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),n}}}function uu(e,t){return Object.entries(e).map(([i,s])=>{const o=s.map(S=>S[t]).sort((S,I)=>S-I),l=_t.quantile(o,.25)??0,u=_t.quantile(o,.5)??0,c=_t.quantile(o,.75)??0,p=c-l,f=l-1.5*p,h=c+1.5*p,g=Math.max(o[0],f),b=Math.min(v.last(o)??0,h),_=s.filter(S=>{const I=S[t];return I<g||I>b}).map(S=>[i,S[t],S]);return{name:i,min:g,q1:l,median:u,q3:c,max:b,outliers:_}})}function cu(e,t){const{x_axis:n,y_axis:i}=e;if(!n.data_key||!i.data_key)return[];const s=O(n.data_key),o=O(i.data_key);if(s.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=v.groupBy(t[s.queryID],s.columnKey),u=uu(l,o.columnKey),c=u.map(p=>p.outliers).flat();return[{source:u},{source:c}]}function du({config:e}){return{show:!0,top:0,right:10,type:"scroll",data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const On=["max","q3","median","q1","min"];function pu(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:On,x:"name",itemName:["name"],tooltip:On}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function hu(e){const{outliers:t,min:n,max:i}=e,s=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>i).length,l=(u,c)=>`
126
+ `}function Ke(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const Pn={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Fe},overflow:Ge}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:ke},tooltip:{metrics:[]},color:"#228be6",reference_lines:[]},We=(e,t)=>{const[n,i]=m.useState([]);return m.useEffect(()=>e.watchTriggerSnapshotList(s=>i(s.filter(o=>o.schemaRef===t))),[]),n},Ma=e=>{const{title:t="Variables",variables:n}=e,i=we.useClipboard(),s=o=>{i.copy(o),Bt.showNotification({color:"green",message:"Copied to clipboard"})};return d(a.Paper,{withBorder:!0,p:"sm",children:[r(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),r(a.Stack,{style:{maxHeight:"500px"},children:n.map(o=>d(a.Text,{size:"sm",children:[d(a.Code,{color:"teal",children:["// ",o.description]}),r("br",{}),d(a.Code,{onClick:()=>s(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class jl{constructor(t,n){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=t,this.instance=n,ie.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const i=await this.operationManager.retrieveTrigger(t),s=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ie.runInAction(()=>{this.operationId=t,this.operation=i,this.operationSchema=s,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Yl(e){return!!e.operationId}const Rl=T.observer(({model:e,onClick:t})=>{var i;const n=(i=e.operationSchema)==null?void 0:i.displayName;return r(a.Button,{variant:"outline",onClick:t,children:n})}),Ql=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return m.createElement(e.operationSchema.configRender,t)});function Ul({model:e}){const t=e.schemaList,n=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return r(a.Select,{label:"Operation",data:n,onChange:i,value:e.operationSchema.id})}const Kl=T.observer(e=>{const[t,{setTrue:n,setFalse:i}]=X.useBoolean(!1),{operationManager:s,operationId:o,instance:l,variables:u}=e,c=X.useCreation(()=>new jl(s,l),[s,l]);return X.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),Yl(c)?d(B,{children:[r(Rl,{model:c,onClick:n}),r(a.Modal,{size:600,opened:t,onClose:i,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:d(a.Stack,{children:[r(Ul,{model:c}),d(a.Tabs,{defaultValue:"settings",children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"settings",children:"Settings"}),r(a.Tabs.Tab,{value:"variables",children:"Variables"})]}),r(a.Tabs.Panel,{value:"settings",pt:10,children:r(Ql,{model:c})}),r(a.Tabs.Panel,{value:"variables",pt:10,children:r(Ma,{title:"Variables",variables:c.variables})})]})]})})]}):null});class Xl{constructor(t,n){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=t,this.instance=n,ie.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const i=await this.triggerManager.retrieveTrigger(t),s=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ie.runInAction(()=>{this.triggerId=t,this.trigger=i,this.triggerSchema=s,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Zl(this)}}function Zl(e){return!!e.triggerId&&!!e.triggerSchema}function Jl(e,t){return X.useCreation(()=>new Xl(e,t),[e,t])}const Hl=T.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,i={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return r(a.Button,{variant:"outline",onClick:t,children:m.createElement(n,i)})}),eu=T.observer(({model:e})=>{const t=e.schemaList,n=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return r(a.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:i})}),tu=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return m.createElement(e.triggerSchema.configRender,t)}),nu=T.observer(e=>{const[t,{setTrue:n,setFalse:i}]=X.useBoolean(!1),s=e.model;return d(B,{children:[r(a.Modal,{opened:t,onClose:i,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:d(a.Stack,{children:[r(eu,{model:s}),r(tu,{model:s}),r(Ma,{title:"Payload",variables:s.triggerSchema.payload})]})}),r(Hl,{onClick:n,model:s})]})});function ru(e,t){const[n,i]=m.useState([]);return X.useAsyncEffect(async()=>{const s=await e.getInteractionList();i(s)},[t,e]),n}const iu=T.observer(({item:e,manager:t,instance:n,sampleData:i,variables:s,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=Jl(t.triggerManager,n);if(X.useAsyncEffect(async()=>{await c.configTrigger(l,i)},[c,l,i]),c.isReady()){const p=[...c.triggerSchema.payload,...s];return d(a.Group,{children:[r(nu,{model:c}),r(Kl,{instance:n,operationId:u,variables:p,operationManager:t.operationManager}),r(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:r(D.Trash,{size:16})})]})}return null}),au=e=>{const[t,n]=m.useState(0),{interactionManager:i,instance:s,sampleData:o,variables:l}=e,u=ru(i,t),c=async()=>{const g=await i.triggerManager.createOrGetTrigger(we.randomId(),i.triggerManager.getTriggerSchemaList()[0]),b=await i.operationManager.createOrGetOperation(we.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(g,b),n(_=>_+1)};async function p(g){await i.removeInteraction(g.id),n(b=>b+1)}const{data:f=0,loading:h}=X.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return d(a.Stack,{children:[r(a.LoadingOverlay,{visible:h}),f===0&&r(a.Alert,{icon:r(D.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>r(iu,{onRemove:p,instance:s,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),r(a.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},su=()=>{const{panel:e,data:t}=Te(),n=e.viz,{vizManager:i}=m.useContext(je),s=e.json,o=X.useCreation(()=>i.getOrCreateInstance(s),[i,s]),l=X.useCreation(()=>new hr(o,i.resolveComponent(n.type),on),[o,n.type]);return m.useEffect(()=>o.instanceData.watchItem(null,v.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:l,sampleData:t,variables:[]}},ou=()=>{const e=su();return r(au,{...e})},$a="__TRIGGERS";class lu{constructor(t,n){V(this,"attachments");this.instance=t,this.component=n;const i=async s=>{const{id:o,schemaRef:l}=await s.getItem(null);return{id:o,schemaRef:l,triggerData:new pt(s,"data")}};this.attachments=new Mn(t,$a,i)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem($a,n=>{const i=v.values(n).map(s=>({id:v.get(s,"id"),schemaRef:v.get(s,"schemaRef"),config:ie.toJS(v.get(s,"data.config"))}));t(i)},{fireImmediately:!0})}async createOrGetTrigger(t,n,i={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||i.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async i=>{const s=this.getTriggerSchemaList().find(u=>u.id===i.schemaRef),o=s==null?void 0:s.migrator,l={configData:i.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(i=>i.filter(s=>s))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}function ht({enabled:e,func_content:t}){return(n,i)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),n}}}function uu(e,t){return Object.entries(e).map(([i,s])=>{const o=s.map(S=>S[t]).sort((S,I)=>S-I),l=_t.quantile(o,.25)??0,u=_t.quantile(o,.5)??0,c=_t.quantile(o,.75)??0,p=c-l,f=l-1.5*p,h=c+1.5*p,g=Math.max(o[0],f),b=Math.min(v.last(o)??0,h),_=s.filter(S=>{const I=S[t];return I<g||I>b}).map(S=>[i,S[t],S]);return{name:i,min:g,q1:l,median:u,q3:c,max:b,outliers:_}})}function cu(e,t){const{x_axis:n,y_axis:i}=e;if(!n.data_key||!i.data_key)return[];const s=O(n.data_key),o=O(i.data_key);if(s.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=v.groupBy(t[s.queryID],s.columnKey),u=uu(l,o.columnKey),c=u.map(p=>p.outliers).flat();return[{source:u},{source:c}]}function du({config:e}){return{show:!0,top:0,right:10,type:"scroll",data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const On=["max","q3","median","q1","min"];function pu(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:On,x:"name",itemName:["name"],tooltip:On}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function hu(e){const{outliers:t,min:n,max:i}=e,s=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>i).length,l=(u,c)=>`
127
127
  <tr>
128
128
  <th style="text-align: right; padding: 0 1em;">${u}</th>
129
129
  <td style="text-align: left; padding: 0 1em;">
@@ -162,8 +162,8 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
162
162
  ${i.join("")}
163
163
  </tbody>
164
164
  </table>
165
- `}const yu=e=>t=>{const{componentSubType:n,value:i}=t;return n==="scatter"?mu(e,i):fu(e,i)};function bu({config:e}){return{trigger:"item",confine:!0,formatter:yu(e)}}const It=m.forwardRef(function({value:t,onChange:n,...i},s){return r(a.TextInput,{ref:s,value:t,onChange:n,...i})}),vu=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function xu({label:e,value:t,onChange:n,pt:i="sm"},s){m.useEffect(()=>{typeof t=="string"&&(console.log(t),n({type:t,config:{}}))},[t,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})};return d(a.Group,{grow:!0,noWrap:!0,pt:i,children:[r(a.Select,{ref:s,label:e,data:vu,value:t.type,onChange:o}),t.type==="quantile"&&r(a.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Ut=m.forwardRef(xu);function Cu({label:e,value:t,onChange:n},i){const[s,o]=m.useState(Array.isArray(t)?[...t]:[]),l=m.useCallback(()=>{o(g=>[...g,""])},[o]),u=m.useCallback(g=>{o(b=>(b.splice(g,1),[...b]))},[o]),c=m.useMemo(()=>!v.isEqual(s,t),[s,t]),p=()=>{n(s.map(g=>g.toString()))},f=a.useMantineTheme(),h=m.useMemo(()=>Object.entries(f.colors).map(([g,b])=>b[6]),[f]);return d(B,{children:[d(a.Group,{position:"left",ref:i,children:[r(a.Text,{children:e}),r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:p,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Group,{children:[s.map((g,b)=>r(a.ColorInput,{value:g,onChange:_=>{o(C=>(C.splice(b,1,_),[...C]))},swatches:h,rightSection:r(a.ActionIcon,{onClick:()=>u(b),color:"red",children:r(D.Trash,{size:14})}),sx:{width:"45%"}})),r(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:r(D.PlaylistAdd,{size:20})})]})]})}const wu=m.forwardRef(Cu);function _u({value:e,onChange:t},n){const{colorManager:i}=m.useContext(je),s=m.useMemo(()=>i.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[i]),o=m.useMemo(()=>s.some(l=>l.value===e),[e,s]);return d(a.Group,{position:"apart",spacing:4,ref:n,children:[r(a.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:r(a.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),r(a.Text,{sx:{flexGrow:0},children:"or"}),r(a.Select,{data:s,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:r(a.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Me=m.forwardRef(_u),Kt=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Su({label:e,value:t,onChange:n},i){var l;const[s,o]=m.useState(((l=Kt.find(u=>u.label===t))==null?void 0:l.value)??Kt[0].value);return m.useEffect(()=>{const u=Kt.find(c=>c.value===s);u&&n(u.label)},[s]),d(a.Stack,{spacing:0,mt:"sm",mb:"lg",children:[r(a.Text,{size:"sm",children:e}),r(a.Slider,{label:null,marks:Kt,value:s,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:i})]})}const Aa=m.forwardRef(Su);function Tu({label:e,value:t,onChange:n,type:i},s){const[o,l]=m.useState(Array.isArray(t)?[...t]:[]),u=m.useCallback(()=>{l(h=>[...h,""])},[l]),c=m.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),p=m.useMemo(()=>!v.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>i==="number"?Number(h):h.toString()))};return d(B,{children:[d(a.Group,{position:"left",ref:s,children:[r(a.Text,{children:e}),r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!p,onClick:f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Group,{children:[o.map((h,g)=>r(a.TextInput,{type:i,value:h,onChange:b=>{const _=b.currentTarget.value;l(C=>(C.splice(g,1,_),[...C]))},rightSection:r(a.ActionIcon,{onClick:()=>c(g),color:"red",children:r(D.Trash,{size:14})}),sx:{width:"45%"}})),r(a.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:r(D.PlaylistAdd,{size:20})})]})]})}const Du=m.forwardRef(Tu),za=m.forwardRef(function({value:t,onChange:n},i){const s=t.color.type,o=(l,u)=>{const c=v.cloneDeep(t);v.set(c,l,u),n(c)};return d(B,{children:[r(a.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),r(a.Stack,{children:r(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:l=>o("size",l.currentTarget.value)})}),r(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:r(Aa,{label:"Font Weight",value:t.weight,onChange:l=>o("weight",l)})}),r(a.Divider,{my:"xs",label:"Style",labelPosition:"center"}),d(a.Stack,{children:[r(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l=>o("color.type",l)}),s==="static"&&r(Me,{value:t.color.staticColor,onChange:l=>o("color.staticColor",l)}),s==="continuous"&&d(B,{children:[r(Du,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:l=>o("color.valueRange",l)}),r(wu,{label:"Color Range",value:t.color.colorRange,onChange:l=>o("color.colorRange",l)})]})]})]})});m.forwardRef(function({value:t,onChange:n,withStyle:i=!0},s){const o=(l,u)=>{const c=v.cloneDeep(t);v.set(c,l,u),n(c)};return d(a.Box,{px:"sm",py:"md",ref:s,children:[r(a.Text,{weight:"bold",pb:0,children:t.name}),r(a.Divider,{my:"xs",label:"Data",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>o("name",l.currentTarget.value)}),r(j,{label:"Data Field",required:!0,value:t.data_field,onChange:l=>o("data_field",l)})]}),r(Ut,{label:"Aggregation",value:t.aggregation,onChange:l=>o("aggregation",l)}),r(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),r(Ne,{value:t.formatter,onChange:l=>o("formatter",l)}),i&&r(za,{value:t,onChange:n})]})});const ft={type:"none",config:{}};function ku(e){const t=Array.from(e).sort((i,s)=>i-s),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function Iu(e){const t=Number(e);return isFinite(t)?t:0}function Mu(e,t){switch(t.type){case"sum":return v.sum(e);case"mean":return v.mean(e);case"median":return ku(e);case"max":return v.max(e)??0;case"min":return v.min(e)??0;case"quantile":return _t.quantile(e,t.config.p)??0;case"CV":const n=Ft.std(...e),i=Ft.mean(...e);return i?n/i:"N/A";case"std":return Ft.std(...e);default:return e}}function Vn(e,t){const n=e.map(Iu);return Mu(n,t)}function Bn(e,t,n){try{return Vn(Ue(e,t),n)}catch(i){return console.error(i),null}}class $u{constructor({valueRange:t,colorRange:n}){V(this,"mapper");this.mapper=ct.interpolate(t,n)}getColor(t){return this.mapper(t)}}function Au(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function gt({data_field:e,aggregation:t},n){return Bn(n,e,t)}function nt({formatter:e},t){if(!["string","number"].includes(typeof t))return Au(t);try{return ee(t).format(e)}catch(n){return console.error(n),t}}function zu(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new $u(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function Ea(e,t){const{color:n,data_field:i,aggregation:s,size:o,weight:l}=e,u=Bn(t,i,s),c=nt(e,u);return r(a.Text,{sx:{fontSize:o,display:"inline"},color:zu(n,u),weight:l,children:c})}function Eu(e,t){const n={};return e.forEach(i=>{const s=i.name;n[s]=Ea(i,t)}),n}function Lu(e){return e.split(" ").map((t,n)=>d(m.Fragment,{children:[t," "]},n))}function Pu(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
166
- `,"<br/>").split("<br/>");return n.map((s,o)=>{const l=[Lu(s)];return o!==n.length-1&&l.push(r("br",{},`br-${o}`)),l}).flat().filter(s=>s!==void 0)}function qn(e){return Pu(e)}function Mt(e,t,n){const i=Eu(t,n),s=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=s.exec(o);if(!u)return qn(o);const c=i[u[1]];if(!c)return qn(o);const p=u[2]??"";return d(m.Fragment,{children:[c,qn(p)]},`${o}-${l}`)})}function Ou(e,t){const n={};return e.forEach(i=>{const{name:s,data_field:o,aggregation:l}=i,u=Bn(t,o,l);n[s]=nt(i,u)}),n}function Xt(e,t,n){const i=Ou(t,n),s=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=s.exec(o);if(!l)return o;const u=i[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function Vu(e,t,n){const i=t.reduce((s,o)=>{const l=gt(o,n);return s[o.name]=nt(o,l),s},{});return e.map(s=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:s.name,yAxis:Number(i[s.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Xt(s.template,t,n)},position:"insideEndTop"}}}))}function Bu({config:e,data:t,variables:n}){const{x_axis:i,y_axis:s,reference_lines:o}=e,l=cu(e,t),u=Ke(i.axisLabel.overflow.on_axis),c=pu(e);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:du({config:e}),tooltip:bu({config:e}),xAxis:[{type:"category",name:i.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...i.axisLabel,...u,formatter:ht(i.axisLabel.formatter)}}],yAxis:[{name:s.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(p){return ee(p).format(s.label_formatter)}}}],series:[...c,...Vu(o,n,t)]}}function ot(e,t){return m.useMemo(()=>{const{queryID:n,columnKey:i}=O(t);return v.keyBy(e[n],i)},[e,t])}oe.use([G.DataZoomComponent,ce.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function qu({context:e,instance:t}){const{value:n}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,{width:o,height:l}=e.viewport,u=v.defaults({},n,Pn),c=Ye({vizManager:e.vizManager,instance:t}),p=We(c.triggerManager,Ia.id),f=ot(s,u.x_axis.data_key),h=m.useCallback(_=>{const C=v.get(f,_.name,{error:"rowData is not found"});p.forEach(S=>{c.runInteraction(S.id,{..._,rowData:C})})},[f,p,c]),g=m.useMemo(()=>({click:h}),[h]),b=m.useMemo(()=>Bu({config:u,data:s,variables:i}),[u,s,i]);return!n||!o||!l?null:r(ze,{echarts:oe,option:b,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})}function Nu({control:e,index:t,remove:n,variableOptions:i}){return d(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:s})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...s})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:s})=>r(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...s})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:s})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...s})}),r(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:r(D.Trash,{size:16})})]},t)}function Gu({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((f,h)=>({...f,...l[h]})),c=()=>s({name:"",template:"",variable_key:""}),p=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return d(a.Stack,{children:[u.map((f,h)=>r(Nu,{control:e,index:h,remove:o,variableOptions:p},f.id)),r(a.Group,{position:"center",mt:"xs",children:r(a.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Fu=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Zt=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:_}=l,C={enabled:b,func_content:_};u(C),t(C)},f=()=>{o(),u(e)},h=b=>{u(_=>({..._,func_content:b}))},g=()=>{h(Fe.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),r(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Fu,{value:l.func_content,onChange:h,disabled:!l.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:g,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:p,children:"OK"})]})]})]})})]})}),Wu=({control:e,watch:t})=>(t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Zt,{...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})),ju=({control:e,watch:t})=>(t(["y_axis"]),d(B,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),r(x.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>r(Ne,{...n})})]})]})),Yu=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ru=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(Yu,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function Qu({control:e,watch:t}){return r(a.Stack,{children:r(Ru,{control:e,watch:t})})}function Uu({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaults({},t,Pn),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,t),[f,t]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),r(a.Tabs.Tab,{value:"Style",children:"Style"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Wu,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(ju,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(Qu,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Style",children:d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:"color",control:o,render:({field:g})=>r(Me,{...g})})]})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(Gu,{variables:i,control:o,watch:u})})]})]})})}function Ku(e){return v.omit(e,"variables")}function Xu(e){const{label_formatter:t=ke,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Zu(e){const t={rotate:0,formatter:{...Fe}},{axisLabel:n=t,...i}=e.x_axis;return{...e,x_axis:{...i,axisLabel:n}}}function Ju(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return v.defaultsDeep(t,e)}function Hu(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return v.defaultsDeep(i,e)}function ec(e){const t={tooltip:{metrics:[]}};return v.defaultsDeep(t,e)}function tc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},y_axis:{...o,data_key:i(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class nc extends me{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:i})=>{const{config:s}=n;return(s.variables||[]).forEach(l=>{i.variables.find(u=>u.name===l.name)||i.addVariable(l)}),{...n,version:2,config:Ku(s)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:Xu(i)}}),this.version(4,n=>{const{config:i}=n;return{...n,version:4,config:Zu(i)}}),this.version(5,n=>{const{config:i}=n;return{...n,version:5,config:Ju(i)}}),this.version(6,n=>{const{config:i}=n;return{...n,version:6,config:Hu(i)}}),this.version(7,n=>{const{config:i}=n;return{...n,version:7,config:ec(i)}}),this.version(8,(n,i)=>{const{config:s}=n;return{...n,version:8,config:tc(s,i)}})}}const rc={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new nc,name:"boxplot",viewRender:qu,configRender:Uu,createConfig(){return{version:8,config:v.cloneDeep(Pn)}},triggers:[Ia]},La={id:"builtin:button:click-button",displayName:"Click Button",nameRender:ac,configRender:ic,payload:[]};function ic(e){return r(B,{})}function ac(e){return r(a.Text,{children:"Click this button"})}const Nn={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},sc={left:"flex-start",center:"center",right:"flex-end"},oc={top:"flex-start",center:"center",bottom:"flex-end"},lc=T.observer(({context:e,instance:t})=>{const n=Ye({vizManager:e.vizManager,instance:t}),i=We(n.triggerManager,La.id),s=U(),{value:o}=W(e.instanceData,"config"),l=m.useMemo(()=>v.defaultsDeep({},o,Nn),[o]),{content:u,horizontal_align:c,vertical_align:p,...f}=l,{width:h,height:g}=e.viewport,b=s.payloadForSQL,_=()=>{i.forEach(C=>{n.runInteraction(C.id,{})})};return r(a.Center,{sx:{width:h,height:g,justifyContent:sc[c],alignItems:oc[p]},children:r(a.Button,{...f,onClick:_,children:v.template(u)(b)})})}),uc=({value:e,onChange:t,label:n})=>{const i=a.useMantineTheme(),s=m.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return d(a.Stack,{spacing:2,children:[r(a.Text,{size:14,sx:{fontWeight:500},children:n}),r(a.Group,{position:"left",spacing:"xs",children:Object.keys(i.colors).map(l=>{const u=i.colors[l][6];return r(a.ColorSwatch,{color:u,onClick:s(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&r(a.CheckIcon,{width:10,color:"white"})},l)})})]})},cc=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),dc=({label:e,value:t,onChange:n})=>r(a.Select,{data:cc,label:e,value:t,onChange:n}),pc=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],hc=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fc=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function gc({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Nn),[t]),s=i;m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Stack,{children:[r(x.Controller,{control:o,name:"content",render:({field:g})=>r(a.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),r(a.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{control:o,name:"variant",render:({field:g})=>r(a.Select,{label:"Variant",data:pc,...g})}),r(x.Controller,{control:o,name:"color",render:({field:g})=>r(uc,{label:"Theme",...g})})]}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{control:o,name:"size",render:({field:g})=>r(dc,{label:"Size",...g})}),r(x.Controller,{control:o,name:"compact",render:({field:g})=>r(a.Checkbox,{label:"Compact",checked:g.value,onChange:b=>g.onChange(b.currentTarget.checked),mt:26})})]}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{control:o,name:"horizontal_align",render:({field:g})=>r(a.Select,{label:"Horizontal Alignment",data:hc,...g})}),r(x.Controller,{control:o,name:"vertical_align",render:({field:g})=>r(a.Select,{label:"Vertical Alignment",data:fc,...g})})]})]})]})}class mc extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:i="left",vertical_align:s="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:i,vertical_align:s}}})}}const yc={displayName:"Button",displayGroup:"Others",migrator:new mc,name:"button",viewRender:lc,configRender:gc,createConfig(){return{version:2,config:v.cloneDeep(Nn)}},triggers:[La]},Gn={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:vc,configRender:bc,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",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"}]};function bc(e){return r(B,{})}function vc(e){return r(a.Text,{children:"Click chart's series"})}const mt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Fn={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Fe},overflow:Ge}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:ke}],reference_lines:[],reference_areas:[],dataZoom:mt};function Wn(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function xc(e){const t=e.y_axes.some(s=>!!s.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let i=5;return e.x_axis_name&&(i+=15),e.series.some(s=>!s.hide_in_legend)&&(i+=20),{top:n,right:15,bottom:i,left:20,containLabel:!0}}function Cc(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function wc(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function _c(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:i})=>({name:n,icon:wc(i),...Cc(i)})),t}function Jt(e,t){switch(e.config.method){case"linear":return[...Je.regressionLinear()(t)];case"exponential":return[...Je.regressionExp()(t)];case"logarithmic":return[...Je.regressionLog()(t)];case"polynomial":return[...Je.regressionPoly().order(e.config.order)(t)];default:return[]}}function Sc(e,t,n,i){const{transform:s,plot:o}=e,l={...o,name:t,data:Jt(s,i),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Tc({regressions:e=[],x_axis_data_key:t},n){const i=[];if(Object.keys(n).length===0)return i;function s(o,l,u,c){const p=Sc(o,l,u,c);i.push(p)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=Ue(n,o.y_axis_data_key).map((g,b)=>[b,Number(g)]);s(o,l,"",h);return}const{columnKey:c}=O(o.y_axis_data_key),p=v.groupBy(kt(n,o.y_axis_data_key),u);Object.entries(p).forEach(([f,h])=>{const g=h.map((_,C)=>[C,Number(_[c])]);s(o,f,f,g)})}),i}function Dc(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function kc(e,t,n,i){return e.map(s=>{const o=s.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,yAxisIndex:s.yAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[l]:Number(n[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Xt(s.template,t,i):""},position:u}}}})}function Ic({type:e,...t},n,i,s){if(!e)return 10;if(e==="static"){const{size:p}=t;return p}const{func_content:o}=t,{queryID:l,columnKey:u}=O(i),c=v.keyBy(kt(n,l),u);return(p,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:s},{lodash:v,interpolate:ct.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function jn(e,t,n){const i=Ue(e,t),s=Ue(e,n);return v.zip(i,s)}function Mc(e,t,n,i){const s=jn(t,n,i);return v.unionBy(s,e,0)}function $c({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:i,valueTypedXAxis:s}){return s?Mc(e,t,n,i):Ue(t,i)}function Ac({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:i,y_axis_data_key:s,valueTypedXAxis:o}){if(!n||n.type==="none")return $c({dataTemplate:e,data:t,x_axis_data_key:i,y_axis_data_key:s,valueTypedXAxis:o});const l=jn(t,i,s),u=v.groupBy(l,"0");return e.map(([p])=>{const h=u[p].map(b=>b[1]),g=Vn(h,n);return[p,g]})}function zc({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:i}){const{queryID:s,columnKey:o}=O(e),l=v.groupBy(t[s],o);return Object.entries(l).forEach(([u,c])=>{l[u]=jn({[s]:c},n,i)}),l}function Ec({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:i,label_position:s,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:p,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...b},_,C,S,I){const $=t.type!=="category",q={label:{show:!!s,position:s,formatter:I[i??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:i,stack:c,color:p,symbolSize:Ic(h,C,e,S),hide_in_legend:g,labelLayout:{hideOverlap:!0},...b};if(f&&(q.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return q.data=Ac({dataTemplate:_,data:C,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:$}),q;const N=zc({group_by_key:l,data:C,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(N).map(([P,z])=>{const A=v.cloneDeep(q);return A.name=P,A.color=void 0,A.data=z,A})}function Lc(e,t,n,i,s,o){const l=t.map(c=>[c,0]);return e.series.map(c=>Ec(e,c,l,n,o,i)).flat().concat(kc(e.reference_lines,s,o,n)).concat(Dc(e.reference_areas,o))}function Pc(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:i,axisIndex:s}=n;return ht(t.x_axis.axisLabel.formatter)(i,s)}function Oc(e,t,n){const i=t.reduce((s,{yAxisIndex:o,name:l})=>(s[l]=o,s),{});return{trigger:"axis",confine:!0,formatter:function(s){const o=Array.isArray(s)?s:[s];if(o.length===0)return"";const l=o.map(({seriesName:p,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!p)return h;const g=i[p],b=n[g]??n.default;return`
165
+ `}const yu=e=>t=>{const{componentSubType:n,value:i}=t;return n==="scatter"?mu(e,i):fu(e,i)};function bu({config:e}){return{trigger:"item",confine:!0,formatter:yu(e)}}const It=m.forwardRef(function({value:t,onChange:n,...i},s){return r(a.TextInput,{ref:s,value:t,onChange:n,...i})}),vu=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function xu({label:e,value:t,onChange:n,pt:i="sm"},s){m.useEffect(()=>{typeof t=="string"&&(console.log(t),n({type:t,config:{}}))},[t,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})};return d(a.Group,{grow:!0,noWrap:!0,pt:i,children:[r(a.Select,{ref:s,label:e,data:vu,value:t.type,onChange:o}),t.type==="quantile"&&r(a.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Qt=m.forwardRef(xu);function Cu({label:e,value:t,onChange:n},i){const[s,o]=m.useState(Array.isArray(t)?[...t]:[]),l=m.useCallback(()=>{o(g=>[...g,""])},[o]),u=m.useCallback(g=>{o(b=>(b.splice(g,1),[...b]))},[o]),c=m.useMemo(()=>!v.isEqual(s,t),[s,t]),p=()=>{n(s.map(g=>g.toString()))},f=a.useMantineTheme(),h=m.useMemo(()=>Object.entries(f.colors).map(([g,b])=>b[6]),[f]);return d(B,{children:[d(a.Group,{position:"left",ref:i,children:[r(a.Text,{children:e}),r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:p,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Group,{children:[s.map((g,b)=>r(a.ColorInput,{value:g,onChange:_=>{o(C=>(C.splice(b,1,_),[...C]))},swatches:h,rightSection:r(a.ActionIcon,{onClick:()=>u(b),color:"red",children:r(D.Trash,{size:14})}),sx:{width:"45%"}})),r(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:r(D.PlaylistAdd,{size:20})})]})]})}const wu=m.forwardRef(Cu);function _u({value:e,onChange:t},n){const{colorManager:i}=m.useContext(je),s=m.useMemo(()=>i.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[i]),o=m.useMemo(()=>s.some(l=>l.value===e),[e,s]);return d(a.Group,{position:"apart",spacing:4,ref:n,children:[r(a.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:r(a.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),r(a.Text,{sx:{flexGrow:0},children:"or"}),r(a.Select,{data:s,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:r(a.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Me=m.forwardRef(_u),Ut=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Su({label:e,value:t,onChange:n},i){var l;const[s,o]=m.useState(((l=Ut.find(u=>u.label===t))==null?void 0:l.value)??Ut[0].value);return m.useEffect(()=>{const u=Ut.find(c=>c.value===s);u&&n(u.label)},[s]),d(a.Stack,{spacing:0,mt:"sm",mb:"lg",children:[r(a.Text,{size:"sm",children:e}),r(a.Slider,{label:null,marks:Ut,value:s,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:i})]})}const Aa=m.forwardRef(Su);function Tu({label:e,value:t,onChange:n,type:i},s){const[o,l]=m.useState(Array.isArray(t)?[...t]:[]),u=m.useCallback(()=>{l(h=>[...h,""])},[l]),c=m.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),p=m.useMemo(()=>!v.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>i==="number"?Number(h):h.toString()))};return d(B,{children:[d(a.Group,{position:"left",ref:s,children:[r(a.Text,{children:e}),r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!p,onClick:f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Group,{children:[o.map((h,g)=>r(a.TextInput,{type:i,value:h,onChange:b=>{const _=b.currentTarget.value;l(C=>(C.splice(g,1,_),[...C]))},rightSection:r(a.ActionIcon,{onClick:()=>c(g),color:"red",children:r(D.Trash,{size:14})}),sx:{width:"45%"}})),r(a.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:r(D.PlaylistAdd,{size:20})})]})]})}const Du=m.forwardRef(Tu),za=m.forwardRef(function({value:t,onChange:n},i){const s=t.color.type,o=(l,u)=>{const c=v.cloneDeep(t);v.set(c,l,u),n(c)};return d(B,{children:[r(a.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),r(a.Stack,{children:r(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:l=>o("size",l.currentTarget.value)})}),r(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:r(Aa,{label:"Font Weight",value:t.weight,onChange:l=>o("weight",l)})}),r(a.Divider,{my:"xs",label:"Style",labelPosition:"center"}),d(a.Stack,{children:[r(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l=>o("color.type",l)}),s==="static"&&r(Me,{value:t.color.staticColor,onChange:l=>o("color.staticColor",l)}),s==="continuous"&&d(B,{children:[r(Du,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:l=>o("color.valueRange",l)}),r(wu,{label:"Color Range",value:t.color.colorRange,onChange:l=>o("color.colorRange",l)})]})]})]})});m.forwardRef(function({value:t,onChange:n,withStyle:i=!0},s){const o=(l,u)=>{const c=v.cloneDeep(t);v.set(c,l,u),n(c)};return d(a.Box,{px:"sm",py:"md",ref:s,children:[r(a.Text,{weight:"bold",pb:0,children:t.name}),r(a.Divider,{my:"xs",label:"Data",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>o("name",l.currentTarget.value)}),r(j,{label:"Data Field",required:!0,value:t.data_field,onChange:l=>o("data_field",l)})]}),r(Qt,{label:"Aggregation",value:t.aggregation,onChange:l=>o("aggregation",l)}),r(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),r(Ne,{value:t.formatter,onChange:l=>o("formatter",l)}),i&&r(za,{value:t,onChange:n})]})});const ft={type:"none",config:{}};function ku(e){const t=Array.from(e).sort((i,s)=>i-s),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function Iu(e){const t=Number(e);return isFinite(t)?t:0}function Mu(e,t){switch(t.type){case"sum":return v.sum(e);case"mean":return v.mean(e);case"median":return ku(e);case"max":return v.max(e)??0;case"min":return v.min(e)??0;case"quantile":return _t.quantile(e,t.config.p)??0;case"CV":const n=Gt.std(...e),i=Gt.mean(...e);return i?n/i:"N/A";case"std":return Gt.std(...e);default:return e}}function Vn(e,t){const n=e.map(Iu);return Mu(n,t)}function Bn(e,t,n){try{return Vn(Ue(e,t),n)}catch(i){return console.error(i),null}}class $u{constructor({valueRange:t,colorRange:n}){V(this,"mapper");this.mapper=ct.interpolate(t,n)}getColor(t){return this.mapper(t)}}function Au(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function gt({data_field:e,aggregation:t},n){return Bn(n,e,t)}function nt({formatter:e},t){if(!["string","number"].includes(typeof t))return Au(t);try{return ee(t).format(e)}catch(n){return console.error(n),t}}function zu(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new $u(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function Ea(e,t){const{color:n,data_field:i,aggregation:s,size:o,weight:l}=e,u=Bn(t,i,s),c=nt(e,u);return r(a.Text,{sx:{fontSize:o,display:"inline"},color:zu(n,u),weight:l,children:c})}function Eu(e,t){const n={};return e.forEach(i=>{const s=i.name;n[s]=Ea(i,t)}),n}function Lu(e){return e.split(" ").map((t,n)=>d(m.Fragment,{children:[t," "]},n))}function Pu(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
166
+ `,"<br/>").split("<br/>");return n.map((s,o)=>{const l=[Lu(s)];return o!==n.length-1&&l.push(r("br",{},`br-${o}`)),l}).flat().filter(s=>s!==void 0)}function qn(e){return Pu(e)}function Mt(e,t,n){const i=Eu(t,n),s=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=s.exec(o);if(!u)return qn(o);const c=i[u[1]];if(!c)return qn(o);const p=u[2]??"";return d(m.Fragment,{children:[c,qn(p)]},`${o}-${l}`)})}function Ou(e,t){const n={};return e.forEach(i=>{const{name:s,data_field:o,aggregation:l}=i,u=Bn(t,o,l);n[s]=nt(i,u)}),n}function Kt(e,t,n){const i=Ou(t,n),s=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=s.exec(o);if(!l)return o;const u=i[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function Vu(e,t,n){const i=t.reduce((s,o)=>{const l=gt(o,n);return s[o.name]=nt(o,l),s},{});return e.map(s=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:s.name,yAxis:Number(i[s.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Kt(s.template,t,n)},position:"insideEndTop"}}}))}function Bu({config:e,data:t,variables:n}){const{x_axis:i,y_axis:s,reference_lines:o}=e,l=cu(e,t),u=Ke(i.axisLabel.overflow.on_axis),c=pu(e);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:du({config:e}),tooltip:bu({config:e}),xAxis:[{type:"category",name:i.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...i.axisLabel,...u,formatter:ht(i.axisLabel.formatter)}}],yAxis:[{name:s.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(p){return ee(p).format(s.label_formatter)}}}],series:[...c,...Vu(o,n,t)]}}function ot(e,t){return m.useMemo(()=>{const{queryID:n,columnKey:i}=O(t);return v.keyBy(e[n],i)},[e,t])}oe.use([G.DataZoomComponent,ce.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function qu({context:e,instance:t}){const{value:n}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,{width:o,height:l}=e.viewport,u=v.defaults({},n,Pn),c=Ye({vizManager:e.vizManager,instance:t}),p=We(c.triggerManager,Ia.id),f=ot(s,u.x_axis.data_key),h=m.useCallback(_=>{const C=v.get(f,_.name,{error:"rowData is not found"});p.forEach(S=>{c.runInteraction(S.id,{..._,rowData:C})})},[f,p,c]),g=m.useMemo(()=>({click:h}),[h]),b=m.useMemo(()=>Bu({config:u,data:s,variables:i}),[u,s,i]);return!n||!o||!l?null:r(ze,{echarts:oe,option:b,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})}function Nu({control:e,index:t,remove:n,variableOptions:i}){return d(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:s})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...s})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:s})=>r(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...s})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:s})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...s})}),r(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:r(D.Trash,{size:16})})]},t)}function Gu({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((f,h)=>({...f,...l[h]})),c=()=>s({name:"",template:"",variable_key:""}),p=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return d(a.Stack,{children:[u.map((f,h)=>r(Nu,{control:e,index:h,remove:o,variableOptions:p},f.id)),r(a.Group,{position:"center",mt:"xs",children:r(a.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Fu=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Xt=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:_}=l,C={enabled:b,func_content:_};u(C),t(C)},f=()=>{o(),u(e)},h=b=>{u(_=>({..._,func_content:b}))},g=()=>{h(Fe.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),r(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Fu,{value:l.func_content,onChange:h,disabled:!l.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:g,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:p,children:"OK"})]})]})]})})]})}),Wu=({control:e,watch:t})=>(t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xt,{...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})),ju=({control:e,watch:t})=>(t(["y_axis"]),d(B,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),r(x.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>r(Ne,{...n})})]})]})),Yu=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ru=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(Yu,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function Qu({control:e,watch:t}){return r(a.Stack,{children:r(Ru,{control:e,watch:t})})}function Uu({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaults({},t,Pn),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,t),[f,t]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),r(a.Tabs.Tab,{value:"Style",children:"Style"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Wu,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(ju,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(Qu,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Style",children:d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:"color",control:o,render:({field:g})=>r(Me,{...g})})]})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(Gu,{variables:i,control:o,watch:u})})]})]})})}function Ku(e){return v.omit(e,"variables")}function Xu(e){const{label_formatter:t=ke,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Zu(e){const t={rotate:0,formatter:{...Fe}},{axisLabel:n=t,...i}=e.x_axis;return{...e,x_axis:{...i,axisLabel:n}}}function Ju(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return v.defaultsDeep(t,e)}function Hu(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return v.defaultsDeep(i,e)}function ec(e){const t={tooltip:{metrics:[]}};return v.defaultsDeep(t,e)}function tc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},y_axis:{...o,data_key:i(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class nc extends me{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:i})=>{const{config:s}=n;return(s.variables||[]).forEach(l=>{i.variables.find(u=>u.name===l.name)||i.addVariable(l)}),{...n,version:2,config:Ku(s)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:Xu(i)}}),this.version(4,n=>{const{config:i}=n;return{...n,version:4,config:Zu(i)}}),this.version(5,n=>{const{config:i}=n;return{...n,version:5,config:Ju(i)}}),this.version(6,n=>{const{config:i}=n;return{...n,version:6,config:Hu(i)}}),this.version(7,n=>{const{config:i}=n;return{...n,version:7,config:ec(i)}}),this.version(8,(n,i)=>{const{config:s}=n;return{...n,version:8,config:tc(s,i)}})}}const rc={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new nc,name:"boxplot",viewRender:qu,configRender:Uu,createConfig(){return{version:8,config:v.cloneDeep(Pn)}},triggers:[Ia]},La={id:"builtin:button:click-button",displayName:"Click Button",nameRender:ac,configRender:ic,payload:[]};function ic(e){return r(B,{})}function ac(e){return r(a.Text,{children:"Click this button"})}const Nn={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},sc={left:"flex-start",center:"center",right:"flex-end"},oc={top:"flex-start",center:"center",bottom:"flex-end"},lc=T.observer(({context:e,instance:t})=>{const n=Ye({vizManager:e.vizManager,instance:t}),i=We(n.triggerManager,La.id),s=U(),{value:o}=W(e.instanceData,"config"),l=m.useMemo(()=>v.defaultsDeep({},o,Nn),[o]),{content:u,horizontal_align:c,vertical_align:p,...f}=l,{width:h,height:g}=e.viewport,b=s.payloadForSQL,_=()=>{i.forEach(C=>{n.runInteraction(C.id,{})})};return r(a.Center,{sx:{width:h,height:g,justifyContent:sc[c],alignItems:oc[p]},children:r(a.Button,{...f,onClick:_,children:v.template(u)(b)})})}),uc=({value:e,onChange:t,label:n})=>{const i=a.useMantineTheme(),s=m.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return d(a.Stack,{spacing:2,children:[r(a.Text,{size:14,sx:{fontWeight:500},children:n}),r(a.Group,{position:"left",spacing:"xs",children:Object.keys(i.colors).map(l=>{const u=i.colors[l][6];return r(a.ColorSwatch,{color:u,onClick:s(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&r(a.CheckIcon,{width:10,color:"white"})},l)})})]})},cc=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),dc=({label:e,value:t,onChange:n})=>r(a.Select,{data:cc,label:e,value:t,onChange:n}),pc=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],hc=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fc=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function gc({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Nn),[t]),s=i;m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Stack,{children:[r(x.Controller,{control:o,name:"content",render:({field:g})=>r(a.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),r(a.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{control:o,name:"variant",render:({field:g})=>r(a.Select,{label:"Variant",data:pc,...g})}),r(x.Controller,{control:o,name:"color",render:({field:g})=>r(uc,{label:"Theme",...g})})]}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{control:o,name:"size",render:({field:g})=>r(dc,{label:"Size",...g})}),r(x.Controller,{control:o,name:"compact",render:({field:g})=>r(a.Checkbox,{label:"Compact",checked:g.value,onChange:b=>g.onChange(b.currentTarget.checked),mt:26})})]}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{control:o,name:"horizontal_align",render:({field:g})=>r(a.Select,{label:"Horizontal Alignment",data:hc,...g})}),r(x.Controller,{control:o,name:"vertical_align",render:({field:g})=>r(a.Select,{label:"Vertical Alignment",data:fc,...g})})]})]})]})}class mc extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:i="left",vertical_align:s="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:i,vertical_align:s}}})}}const yc={displayName:"Button",displayGroup:"Others",migrator:new mc,name:"button",viewRender:lc,configRender:gc,createConfig(){return{version:2,config:v.cloneDeep(Nn)}},triggers:[La]},Gn={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:vc,configRender:bc,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",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"}]};function bc(e){return r(B,{})}function vc(e){return r(a.Text,{children:"Click chart's series"})}const mt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Fn={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Fe},overflow:Ge}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:ke}],reference_lines:[],reference_areas:[],dataZoom:mt};function Wn(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function xc(e){const t=e.y_axes.some(s=>!!s.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let i=5;return e.x_axis_name&&(i+=15),e.series.some(s=>!s.hide_in_legend)&&(i+=20),{top:n,right:15,bottom:i,left:20,containLabel:!0}}function Cc(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function wc(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function _c(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:i})=>({name:n,icon:wc(i),...Cc(i)})),t}function Zt(e,t){switch(e.config.method){case"linear":return[...Je.regressionLinear()(t)];case"exponential":return[...Je.regressionExp()(t)];case"logarithmic":return[...Je.regressionLog()(t)];case"polynomial":return[...Je.regressionPoly().order(e.config.order)(t)];default:return[]}}function Sc(e,t,n,i){const{transform:s,plot:o}=e,l={...o,name:t,data:Zt(s,i),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Tc({regressions:e=[],x_axis_data_key:t},n){const i=[];if(Object.keys(n).length===0)return i;function s(o,l,u,c){const p=Sc(o,l,u,c);i.push(p)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=Ue(n,o.y_axis_data_key).map((g,b)=>[b,Number(g)]);s(o,l,"",h);return}const{columnKey:c}=O(o.y_axis_data_key),p=v.groupBy(kt(n,o.y_axis_data_key),u);Object.entries(p).forEach(([f,h])=>{const g=h.map((_,C)=>[C,Number(_[c])]);s(o,f,f,g)})}),i}function Dc(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function kc(e,t,n,i){return e.map(s=>{const o=s.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,yAxisIndex:s.yAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[l]:Number(n[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Kt(s.template,t,i):""},position:u}}}})}function Ic({type:e,...t},n,i,s){if(!e)return 10;if(e==="static"){const{size:p}=t;return p}const{func_content:o}=t,{queryID:l,columnKey:u}=O(i),c=v.keyBy(kt(n,l),u);return(p,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:s},{lodash:v,interpolate:ct.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function jn(e,t,n){const i=Ue(e,t),s=Ue(e,n);return v.zip(i,s)}function Mc(e,t,n,i){const s=jn(t,n,i);return v.unionBy(s,e,0)}function $c({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:i,valueTypedXAxis:s}){return s?Mc(e,t,n,i):Ue(t,i)}function Ac({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:i,y_axis_data_key:s,valueTypedXAxis:o}){if(!n||n.type==="none")return $c({dataTemplate:e,data:t,x_axis_data_key:i,y_axis_data_key:s,valueTypedXAxis:o});const l=jn(t,i,s),u=v.groupBy(l,"0");return e.map(([p])=>{const h=u[p].map(b=>b[1]),g=Vn(h,n);return[p,g]})}function zc({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:i}){const{queryID:s,columnKey:o}=O(e),l=v.groupBy(t[s],o);return Object.entries(l).forEach(([u,c])=>{l[u]=jn({[s]:c},n,i)}),l}function Ec({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:i,label_position:s,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:p,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...b},_,C,S,I){const $=t.type!=="category",q={label:{show:!!s,position:s,formatter:I[i??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:i,stack:c,color:p,symbolSize:Ic(h,C,e,S),hide_in_legend:g,labelLayout:{hideOverlap:!0},...b};if(f&&(q.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return q.data=Ac({dataTemplate:_,data:C,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:$}),q;const N=zc({group_by_key:l,data:C,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(N).map(([P,z])=>{const A=v.cloneDeep(q);return A.name=P,A.color=void 0,A.data=z,A})}function Lc(e,t,n,i,s,o){const l=t.map(c=>[c,0]);return e.series.map(c=>Ec(e,c,l,n,o,i)).flat().concat(kc(e.reference_lines,s,o,n)).concat(Dc(e.reference_areas,o))}function Pc(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:i,axisIndex:s}=n;return ht(t.x_axis.axisLabel.formatter)(i,s)}function Oc(e,t,n){const i=t.reduce((s,{yAxisIndex:o,name:l})=>(s[l]=o,s),{});return{trigger:"axis",confine:!0,formatter:function(s){const o=Array.isArray(s)?s:[s];if(o.length===0)return"";const l=o.map(({seriesName:p,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!p)return h;const g=i[p],b=n[g]??n.default;return`
167
167
  <tr>
168
168
  <td>${f}</td>
169
169
  <th style="text-align: right; padding: 0 1em;">${p}</th>
@@ -179,7 +179,7 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
179
179
  </tbody>
180
180
  </table>
181
181
  `}}}function Vc(e){return e.y_axes.reduce((n,{label_formatter:i},s)=>(n[s]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!i)return u;try{return ee(u).format(i)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Bc(e,t){const n={};return t.map(i=>{const s=gt(i,e);n[i.name]=nt(i,s)}),n}function qc(e,t){const{overflow:n,...i}=e.x_axis.axisLabel,s=Ke(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...i,...s,formatter:ht(i.formatter)}}]}function Nc(e,t){return e.y_axes.map(({nameAlignment:n,min:i,max:s,show:o,...l},u)=>{let c=l.position;return c||(c=u>0?"right":"left"),{...l,show:o,min:i||void 0,max:s||void 0,position:c,axisLabel:{show:o,formatter:t[u]??t.default},axisLine:{show:o},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:o?15:0,splitLine:{show:!1}}})}const Gc={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Fc(e,t,n){const i=Bc(t,n),s=Vc(e),o=v.uniq(Ue(t,e.x_axis_data_key)),l=Lc(e,o,t,s,n,i),u=Tc(e,t),c={xAxis:qc(e,o),yAxis:Nc(e,s),series:[...l,...u],tooltip:Oc(e,l,s),grid:xc(e),legend:_c(l),dataZoom:Wn(e.dataZoom)};return v.defaultsDeep({},c,Gc)}function Pa(e){const t=e.getModel(),n=t.getSeries().map(i=>{if(!i.option.custom)return i.option;const s=t.getColorFromPalette(i.option.custom.targetSeries,null);return i.option.color=s,i.option});e.setOption({...e.getOption(),series:n})}oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Oa(e){return e.trim().length>0}function Wc({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.x_axis_data_key),u=We(s.triggerManager,Gn.id),c=m.useCallback(b=>{const _=v.get(l,b.name,{error:"rowData is not found"});u.forEach(C=>{s.runInteraction(C.id,{...b,rowData:_})})},[l,u,s]),p=m.useMemo(()=>Fc(e,t,o),[e,t]),f=m.useRef(),h=m.useMemo(()=>({click:c}),[c]),g=b=>{f.current=b,Pa(b)};return m.useEffect(()=>{f.current&&Pa(f.current)},[p]),!n||!i?null:r(ze,{echarts:oe,option:p,style:{width:n,height:i},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function jc({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,Fn),[i]),l=e.data,{width:u,height:c}=e.viewport,{ref:p,height:f}=we.useElementSize(),{ref:h,height:g}=we.useElementSize(),b=m.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Mt(C.top,s,l),bottom:Mt(C.bottom,s,l)}},[o,l]),_=Math.max(0,c-f-g);return d(a.Box,{children:[r(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Oa(o.stats.templates.top)?"block":"none"},children:Object.values(b.top).map((C,S)=>r(m.Fragment,{children:C},S))}),r(Wc,{variables:s,width:u,height:_,data:l,conf:o,interactionManager:n}),r(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Oa(o.stats.templates.bottom)?"block":"none"},children:Object.values(b.bottom).map((C,S)=>r(m.Fragment,{children:C},S))})]})}const Yn=m.forwardRef(({value:e,onChange:t},n)=>{const i=s=>o=>{t({...e,[s]:o})};return d(a.Stack,{children:[r(a.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),d(a.Group,{children:[r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:s=>i("x_axis_scroll")(s.currentTarget.checked)})}),r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:s=>i("y_axis_scroll")(s.currentTarget.checked)})})]}),r(a.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),d(a.Group,{children:[r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:s=>i("x_axis_slider")(s.currentTarget.checked)})}),r(a.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:s=>i("y_axis_slider")(s.currentTarget.checked)})})})]})]})}),Yc=[{label:"Rectangle",value:"rectangle"}],Rc=[{label:"Horizontal",value:"horizontal"}];function Qc({control:e,index:t,remove:n,variableOptions:i}){return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:s})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),r(x.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:s})=>r(a.TextInput,{label:"Color",required:!0,sx:{flex:1},...s})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:s})=>r(a.Select,{label:"Type",required:!0,data:Yc,sx:{flex:1},...s})}),r(x.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:s})=>r(a.Select,{label:"Direction",required:!0,data:Rc,sx:{flex:1},...s})})]}),r(a.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:s})=>r(a.Select,{label:"Upper Boundary",required:!0,data:i,sx:{flex:1},...s})}),r(x.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:s})=>r(a.Select,{label:"Lower Boundary",required:!0,data:i,sx:{flex:1},...s})})]}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]},t)}function Uc({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=i.map((f,h)=>({...f,...l[h]})),c=()=>s({name:"",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),p=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[d(a.Tabs.List,{children:[u.map((f,h)=>r(a.Tabs.Tab,{value:h.toString(),children:h+1},h)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>r(a.Tabs.Panel,{value:h.toString(),children:r(Qc,{control:e,index:h,remove:o,variableOptions:p})},h))]})}const Kc=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Xc=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Zc({control:e,index:t,remove:n,watch:i,variableOptions:s,yAxisOptions:o}){const l=i(`reference_lines.${t}.orientation`);return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>r(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...u})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(a.Group,{grow:!0,children:[d(a.Stack,{children:[r(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>r(a.Select,{label:"Orientation",data:Xc,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(x.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...p}})=>r(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...p,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>r(a.Select,{label:"Line Type",data:Kc,sx:{flexGrow:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>r(Me,{...u})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>r(a.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Jc({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{s({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},b)=>({label:g,value:b.toString()})),[f]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((g,b)=>r(a.Tabs.Tab,{value:b.toString(),children:b+1},b)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(a.Tabs.Panel,{value:b.toString(),children:r(Zc,{control:e,index:b,remove:o,watch:t,variableOptions:p,yAxisOptions:h})},b))]})}const Hc=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],ed=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function td({control:e,regressionItem:t,index:n,remove:i,yAxisOptions:s}){const o=t.transform.config.method;return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,children:[r(x.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),r(x.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>r(j,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),r(x.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>r(a.Select,{label:"Y Axis",data:s,disabled:s.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:p=>{if(!p){u(0);return}u(Number(p))},sx:{flex:1}})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>r(a.Select,{label:"Method",data:Hc,sx:{flex:1},...l})}),o==="polynomial"&&r(x.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>r(a.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>r(a.Select,{label:"Line Type",data:ed,sx:{flexGrow:1},...l})}),r(x.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>r(Me,{...l})})]}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function nd({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=m.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),p=()=>i({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((f,h)=>r(a.Tabs.Tab,{value:h.toString(),children:h+1},h)),r(a.Tabs.Tab,{onClick:p,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>r(a.Tabs.Panel,{value:h.toString(),children:r(td,{regressionItem:f,control:e,index:h,remove:s,yAxisOptions:c},h)},h))]})}const Rn={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
182
- `)}},rd=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function id({control:e,index:t,seriesItem:n}){const i=!!n.barWidth.trim();return d(B,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.stack`,control:e,render:({field:s})=>r(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barGap`,control:e,render:({field:s})=>r(a.Select,{label:"Bar Gap",data:rd,sx:{flexGrow:1},...s})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...s})})]})]})}const ad=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{children:r(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},sd=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e),u=()=>{s();const{type:h,func_content:g}=o,b={type:h,func_content:g};l(b),t(b)},c=()=>{s(),l(e)},p=h=>{l(g=>({...g,func_content:h}))},f=()=>{p(Rn.dynamic.func_content)};return d(B,{children:[r(a.Box,{sx:{width:"50%"},children:r(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(ad,{value:o.func_content,onChange:p}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},od=({value:e,onChange:t})=>e.type!=="dynamic"?null:r(sd,{value:e,onChange:t}),ld=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=i=>{t({...e,size:i})};return r(B,{children:r(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},ud=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Va=m.forwardRef(({label:e="Size",value:t,onChange:n},i)=>{const s=o=>{n({...Rn[o]})};return d(a.SimpleGrid,{cols:2,children:[r(a.Select,{ref:i,label:e,data:ud,value:t.type,onChange:s,sx:{flexGrow:1}}),r(ld,{value:t,onChange:n}),r(od,{value:t,onChange:n})]})}),cd=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],dd=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function pd({control:e,index:t,seriesItem:n}){const i=n.showSymbol;return d(B,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:s})=>r(a.Select,{label:"Line Type",data:dd,sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:s})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...s})})]}),d(a.Group,{grow:!0,align:"center",children:[r(x.Controller,{name:`series.${t}.step`,control:e,render:({field:s})=>r(a.Select,{label:"Step",data:cd,sx:{flexGrow:1,maxWidth:"48%"},...s,value:String(s.value),onChange:o=>{const l=o==="false"?!1:o;s.onChange(l)}})}),d(a.Stack,{children:[r(x.Controller,{name:`series.${t}.smooth`,control:e,render:({field:s})=>r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Smooth Line",checked:s.value,onChange:o=>s.onChange(o.currentTarget.checked)})})}),r(x.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:s})=>r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Display Name on Line",checked:s.value??!1,onChange:o=>s.onChange(o.currentTarget.checked)})})})]})]}),d(a.Stack,{children:[r(x.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:s})=>r(a.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:r(a.Switch,{label:"Show Symbol on Line",checked:s.value,onChange:o=>s.onChange(o.currentTarget.checked)})})}),i&&r(x.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:s})=>r(Va,{label:"Symbol Size",...s})})]})]})}function hd({control:e,index:t}){return r(x.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>r(Va,{label:"Size",...n})})}const fd=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function gd({control:e,index:t,remove:n,seriesItem:i,yAxisOptions:s}){const o=i.type;return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[r(a.Stack,{children:r(x.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>r(a.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),r(x.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>r(a.Select,{label:"Y Axis",data:s,disabled:s.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:p=>{if(!p){u(0);return}u(Number(p))},sx:{flex:1}})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),r(x.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>r(Ut,{label:"Aggregation on Value",value:l.value??ft,onChange:l.onChange,pt:0})})]}),r(a.Group,{grow:!0,children:r(x.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>r(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&r(pd,{index:t,control:e,seriesItem:i}),o==="bar"&&r(id,{index:t,control:e,seriesItem:i}),o==="scatter"&&r(hd,{index:t,control:e}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>r(a.Select,{label:"Label Position",data:fd,...l})}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>r(Me,{...l})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>r(a.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function md({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:we.randomId(),showSymbol:!1,symbolSize:Rn.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};i(f)},c=t("y_axes"),p=m.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((f,h)=>r(a.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>r(a.Tabs.Panel,{value:h.toString(),children:r(gd,{control:e,index:h,remove:s,seriesItem:f,yAxisOptions:p},f.id)},f.id))]})}function yd({control:e,watch:t}){return t("stats"),r(a.Stack,{children:d(a.Stack,{spacing:0,children:[r(x.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>r(It,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),r(x.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>r(It,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const bd=()=>d(a.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[r(a.Text,{children:"X Axis Data Type"}),d(a.HoverCard,{width:340,shadow:"md",position:"top",children:[r(a.HoverCard.Target,{children:r(a.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:r(L.IconInfoCircle,{})})}),r(a.HoverCard.Dropdown,{children:d(a.Text,{size:"sm",children:["Click",r(a.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),vd=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function xd({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),d(a.Stack,{children:[r(x.Controller,{name:"x_axis_name",control:e,render:({field:n})=>r(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>r(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.type",control:e,render:({field:n})=>r(a.Select,{label:r(bd,{}),required:!0,data:vd,sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Zt,{...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}const Cd=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],wd=[{label:"left",value:"left"},{label:"right",value:"right"}];function _d({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:i})=>r(a.Select,{label:"Align",required:!0,data:Cd,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:i})=>r(a.Select,{label:"Position",required:!0,data:wd,sx:{flex:1},...i})})}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:i})=>r(a.TextInput,{label:"Min",...i})}),r(x.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:i})=>r(a.TextInput,{label:"Max",...i})})]})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:i})=>r(a.Checkbox,{label:"Visible",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),r(a.Button,{mt:20,leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Sd({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,p)=>({...c,...o[p]})),u=()=>i({name:"",label_formatter:ke,min:"",max:"",show:!0});return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map((c,p)=>r(a.Tabs.Tab,{value:p.toString(),children:p+1},p)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,p)=>r(a.Tabs.Panel,{value:p.toString(),children:r(_d,{control:e,index:p,remove:s})},p))]})}function Td({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaultsDeep({},t,Fn),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,s),[f,s]);return u(["dataZoom"]),r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),r(a.Tabs.Tab,{value:"Series",children:"Series"}),r(a.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),r(a.Tabs.Tab,{value:"Stats",children:"Stats"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),r(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),r(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(xd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axes",children:r(Sd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Series",children:r(md,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Regression Lines",children:r(nd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Stats",children:r(yd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(Jc,{variables:i,control:o,watch:u})}),r(a.Tabs.Panel,{value:"Reference Areas",children:r(Uc,{variables:i,control:o,watch:u})}),r(a.Tabs.Panel,{value:"Zooming",children:r(x.Controller,{name:"dataZoom",control:o,render:({field:g})=>r(Yn,{...g})})})]})]})})}function Dd(e){const t=v.cloneDeep(v.omit(e,"variables"));return t.stats=v.omit(t.stats,"variables"),t}function kd(e){const{rotate:t,formatter:n=Fe}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Id(e){const{dataZoom:t=mt,...n}=e;return{...n,dataZoom:t}}function Md(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return v.defaultsDeep(t,e)}function $d(e){const t=e.reference_lines.map(n=>{const{lineStyle:i={type:"dashed",width:1,color:Re.random().css()},show_in_legend:s=!1}=n;return{...n,lineStyle:i,show_in_legend:s}});return{...e,reference_lines:t}}function Ad(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:i=0}=n;return{...n,yAxisIndex:i}});return{...e,reference_lines:t}}function zd(e){const t=e.series.map(n=>{const{aggregation_on_group:i=ft}=n;return{...n,aggregation_on_group:i}});return{...e,series:t}}function Ed(e){const t=e.series.map(n=>{const{aggregation_on_value:i=ft}=n;return{...n,aggregation_on_value:i}});return{...e,series:t}}function Ld(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return v.defaultsDeep(i,e)}function Pd(e){const{series:t,...n}=e;return{...n,series:t.map(i=>{const{barMinWidth:s,barWidth:o,barMaxWidth:l}=i;return s?{...i,barMinWidth:s,barWidth:"",barMaxWidth:l??o}:{...i,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function Od(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(i=>{const{min:s="",max:o=""}=i;return{...i,min:s,max:o}})}}function Vd(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(i=>{const{nameAlignment:s="left"}=i;return{...i,nameAlignment:s}})}}function Bd(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(i=>{const{show:s=!0}=i;return{...i,show:s}})}}function qd(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(i=>{const{group_by_key:s=""}=i;return{...i,group_by_key:s}})}}function Nd(e){const{series:t,y_axes:n,...i}=e;return{...i,series:t.map(s=>{const{hide_in_legend:o=!1,aggregation_on_value:l=ft}=s;return{...s,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(s=>{const{min:o="",max:l="",show:u=!0}=s;return{...s,min:o,max:l,show:u}})}}function Gd(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Fd(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis_data_key:s,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:i(s),series:o.map(c=>({...c,y_axis_data_key:i(c.y_axis_data_key),group_by_key:i(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:i(c.y_axis_data_key),group_by_key:i(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wd extends me{constructor(){super(...arguments);V(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:i})=>{const{config:s}=n;return(s.variables||[]).forEach(u=>{i.variables.find(c=>c.name===u.name)||i.addVariable(u)}),(v.get(s,"stats.variables")||[]).forEach(u=>{i.variables.find(c=>c.name===u.name)||i.addVariable(u)}),{...n,version:2,config:Dd(s)}}),this.version(3,n=>({...n,version:3,config:kd(n.config)})),this.version(4,n=>({...n,version:4,config:Id(n.config)})),this.version(5,n=>({...n,version:5,config:Md(n.config)})),this.version(6,n=>({...n,version:6,config:$d(n.config)})),this.version(7,n=>({...n,version:7,config:Ad(n.config)})),this.version(8,n=>({...n,version:8,config:zd(n.config)})),this.version(9,n=>({...n,version:9,config:Ed(n.config)})),this.version(10,n=>({...n,version:10,config:Ld(n.config)})),this.version(11,n=>({...n,version:11,config:Pd(n.config)})),this.version(12,n=>({...n,version:12,config:Od(n.config)})),this.version(13,n=>({...n,version:13,config:Vd(n.config)})),this.version(14,n=>({...n,version:14,config:Bd(n.config)})),this.version(15,n=>({...n,version:15,config:qd(n.config)})),this.version(16,n=>({...n,version:16,config:Nd(n.config)})),this.version(17,n=>({...n,version:17,config:Gd(n.config)})),this.version(18,(n,i)=>({...n,version:18,config:Fd(n.config,i)}))}}const jd={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Wd,name:"cartesian",viewRender:jc,configRender:Td,createConfig(){return{version:18,config:v.cloneDeep(Fn)}},triggers:[Gn]};function Yd(e){if(e.enable_value)return e.value}function Rd(e){if(e.enable_value)return e.value}function Qd(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,i={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&v.get(i,n)&&n===e.funnelAlign&&v.set(i,n,t),i}function Ud(e,t){return e.series.map(n=>{const{level_name_data_key:i,level_value_data_key:s,axisLabel:o,min:l,max:u,funnelAlign:c,orient:p,...f}=n;if(!i||!s)return{};const h=O(i),g=O(s),b=t[h.queryID].map(C=>({name:C[h.columnKey],value:C[g.columnKey]})),_=Ke(o.overflow.on_axis);return{type:"funnel",...Qd(n),min:Yd(l),max:Rd(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,..._},orient:p,funnelAlign:p==="horizontal"?"center":c,data:b}})}function Kd({conf:e,params:t,max:n}){const{name:i,value:s}=t.data,o=ee(s/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${i}`,value:`${s} (${o})`,style:{label:"",value:""}}]}function Xd(e,t){var o;const n=O(e.series[0].level_name_data_key),i=O(e.series[0].level_value_data_key),s=(o=v.maxBy(t[n.queryID],i.columnKey))==null?void 0:o[i.columnKey];return l=>{const c=Kd({conf:e,params:l,max:s}).map(f=>`
182
+ `)}},rd=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function id({control:e,index:t,seriesItem:n}){const i=!!n.barWidth.trim();return d(B,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.stack`,control:e,render:({field:s})=>r(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barGap`,control:e,render:({field:s})=>r(a.Select,{label:"Bar Gap",data:rd,sx:{flexGrow:1},...s})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...s})})]})]})}const ad=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{children:r(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},sd=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e),u=()=>{s();const{type:h,func_content:g}=o,b={type:h,func_content:g};l(b),t(b)},c=()=>{s(),l(e)},p=h=>{l(g=>({...g,func_content:h}))},f=()=>{p(Rn.dynamic.func_content)};return d(B,{children:[r(a.Box,{sx:{width:"50%"},children:r(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(ad,{value:o.func_content,onChange:p}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},od=({value:e,onChange:t})=>e.type!=="dynamic"?null:r(sd,{value:e,onChange:t}),ld=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=i=>{t({...e,size:i})};return r(B,{children:r(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},ud=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Va=m.forwardRef(({label:e="Size",value:t,onChange:n},i)=>{const s=o=>{n({...Rn[o]})};return d(a.SimpleGrid,{cols:2,children:[r(a.Select,{ref:i,label:e,data:ud,value:t.type,onChange:s,sx:{flexGrow:1}}),r(ld,{value:t,onChange:n}),r(od,{value:t,onChange:n})]})}),cd=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],dd=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function pd({control:e,index:t,seriesItem:n}){const i=n.showSymbol;return d(B,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:s})=>r(a.Select,{label:"Line Type",data:dd,sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:s})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...s})})]}),d(a.Group,{grow:!0,align:"center",children:[r(x.Controller,{name:`series.${t}.step`,control:e,render:({field:s})=>r(a.Select,{label:"Step",data:cd,sx:{flexGrow:1,maxWidth:"48%"},...s,value:String(s.value),onChange:o=>{const l=o==="false"?!1:o;s.onChange(l)}})}),d(a.Stack,{children:[r(x.Controller,{name:`series.${t}.smooth`,control:e,render:({field:s})=>r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Smooth Line",checked:s.value,onChange:o=>s.onChange(o.currentTarget.checked)})})}),r(x.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:s})=>r(a.Box,{sx:{flexGrow:1},children:r(a.Switch,{label:"Display Name on Line",checked:s.value??!1,onChange:o=>s.onChange(o.currentTarget.checked)})})})]})]}),d(a.Stack,{children:[r(x.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:s})=>r(a.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:r(a.Switch,{label:"Show Symbol on Line",checked:s.value,onChange:o=>s.onChange(o.currentTarget.checked)})})}),i&&r(x.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:s})=>r(Va,{label:"Symbol Size",...s})})]})]})}function hd({control:e,index:t}){return r(x.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>r(Va,{label:"Size",...n})})}const fd=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function gd({control:e,index:t,remove:n,seriesItem:i,yAxisOptions:s}){const o=i.type;return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[r(a.Stack,{children:r(x.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>r(a.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),r(x.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>r(a.Select,{label:"Y Axis",data:s,disabled:s.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:p=>{if(!p){u(0);return}u(Number(p))},sx:{flex:1}})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),r(x.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>r(Qt,{label:"Aggregation on Value",value:l.value??ft,onChange:l.onChange,pt:0})})]}),r(a.Group,{grow:!0,children:r(x.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>r(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&r(pd,{index:t,control:e,seriesItem:i}),o==="bar"&&r(id,{index:t,control:e,seriesItem:i}),o==="scatter"&&r(hd,{index:t,control:e}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>r(a.Select,{label:"Label Position",data:fd,...l})}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>r(Me,{...l})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>r(a.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function md({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:we.randomId(),showSymbol:!1,symbolSize:Rn.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};i(f)},c=t("y_axes"),p=m.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((f,h)=>r(a.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>r(a.Tabs.Panel,{value:h.toString(),children:r(gd,{control:e,index:h,remove:s,seriesItem:f,yAxisOptions:p},f.id)},f.id))]})}function yd({control:e,watch:t}){return t("stats"),r(a.Stack,{children:d(a.Stack,{spacing:0,children:[r(x.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>r(It,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),r(x.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>r(It,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const bd=()=>d(a.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[r(a.Text,{children:"X Axis Data Type"}),d(a.HoverCard,{width:340,shadow:"md",position:"top",children:[r(a.HoverCard.Target,{children:r(a.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:r(L.IconInfoCircle,{})})}),r(a.HoverCard.Dropdown,{children:d(a.Text,{size:"sm",children:["Click",r(a.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),vd=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function xd({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),d(a.Stack,{children:[r(x.Controller,{name:"x_axis_name",control:e,render:({field:n})=>r(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>r(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.type",control:e,render:({field:n})=>r(a.Select,{label:r(bd,{}),required:!0,data:vd,sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xt,{...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}const Cd=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],wd=[{label:"left",value:"left"},{label:"right",value:"right"}];function _d({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:i})=>r(a.Select,{label:"Align",required:!0,data:Cd,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:i})=>r(a.Select,{label:"Position",required:!0,data:wd,sx:{flex:1},...i})})}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:i})=>r(a.TextInput,{label:"Min",...i})}),r(x.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:i})=>r(a.TextInput,{label:"Max",...i})})]})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:i})=>r(a.Checkbox,{label:"Visible",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),r(a.Button,{mt:20,leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Sd({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,p)=>({...c,...o[p]})),u=()=>i({name:"",label_formatter:ke,min:"",max:"",show:!0});return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map((c,p)=>r(a.Tabs.Tab,{value:p.toString(),children:p+1},p)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,p)=>r(a.Tabs.Panel,{value:p.toString(),children:r(_d,{control:e,index:p,remove:s})},p))]})}function Td({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaultsDeep({},t,Fn),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,s),[f,s]);return u(["dataZoom"]),r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),r(a.Tabs.Tab,{value:"Series",children:"Series"}),r(a.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),r(a.Tabs.Tab,{value:"Stats",children:"Stats"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),r(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),r(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(xd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axes",children:r(Sd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Series",children:r(md,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Regression Lines",children:r(nd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Stats",children:r(yd,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(Jc,{variables:i,control:o,watch:u})}),r(a.Tabs.Panel,{value:"Reference Areas",children:r(Uc,{variables:i,control:o,watch:u})}),r(a.Tabs.Panel,{value:"Zooming",children:r(x.Controller,{name:"dataZoom",control:o,render:({field:g})=>r(Yn,{...g})})})]})]})})}function Dd(e){const t=v.cloneDeep(v.omit(e,"variables"));return t.stats=v.omit(t.stats,"variables"),t}function kd(e){const{rotate:t,formatter:n=Fe}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Id(e){const{dataZoom:t=mt,...n}=e;return{...n,dataZoom:t}}function Md(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return v.defaultsDeep(t,e)}function $d(e){const t=e.reference_lines.map(n=>{const{lineStyle:i={type:"dashed",width:1,color:Re.random().css()},show_in_legend:s=!1}=n;return{...n,lineStyle:i,show_in_legend:s}});return{...e,reference_lines:t}}function Ad(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:i=0}=n;return{...n,yAxisIndex:i}});return{...e,reference_lines:t}}function zd(e){const t=e.series.map(n=>{const{aggregation_on_group:i=ft}=n;return{...n,aggregation_on_group:i}});return{...e,series:t}}function Ed(e){const t=e.series.map(n=>{const{aggregation_on_value:i=ft}=n;return{...n,aggregation_on_value:i}});return{...e,series:t}}function Ld(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return v.defaultsDeep(i,e)}function Pd(e){const{series:t,...n}=e;return{...n,series:t.map(i=>{const{barMinWidth:s,barWidth:o,barMaxWidth:l}=i;return s?{...i,barMinWidth:s,barWidth:"",barMaxWidth:l??o}:{...i,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function Od(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(i=>{const{min:s="",max:o=""}=i;return{...i,min:s,max:o}})}}function Vd(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(i=>{const{nameAlignment:s="left"}=i;return{...i,nameAlignment:s}})}}function Bd(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(i=>{const{show:s=!0}=i;return{...i,show:s}})}}function qd(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(i=>{const{group_by_key:s=""}=i;return{...i,group_by_key:s}})}}function Nd(e){const{series:t,y_axes:n,...i}=e;return{...i,series:t.map(s=>{const{hide_in_legend:o=!1,aggregation_on_value:l=ft}=s;return{...s,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(s=>{const{min:o="",max:l="",show:u=!0}=s;return{...s,min:o,max:l,show:u}})}}function Gd(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Fd(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis_data_key:s,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:i(s),series:o.map(c=>({...c,y_axis_data_key:i(c.y_axis_data_key),group_by_key:i(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:i(c.y_axis_data_key),group_by_key:i(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wd extends me{constructor(){super(...arguments);V(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:i})=>{const{config:s}=n;return(s.variables||[]).forEach(u=>{i.variables.find(c=>c.name===u.name)||i.addVariable(u)}),(v.get(s,"stats.variables")||[]).forEach(u=>{i.variables.find(c=>c.name===u.name)||i.addVariable(u)}),{...n,version:2,config:Dd(s)}}),this.version(3,n=>({...n,version:3,config:kd(n.config)})),this.version(4,n=>({...n,version:4,config:Id(n.config)})),this.version(5,n=>({...n,version:5,config:Md(n.config)})),this.version(6,n=>({...n,version:6,config:$d(n.config)})),this.version(7,n=>({...n,version:7,config:Ad(n.config)})),this.version(8,n=>({...n,version:8,config:zd(n.config)})),this.version(9,n=>({...n,version:9,config:Ed(n.config)})),this.version(10,n=>({...n,version:10,config:Ld(n.config)})),this.version(11,n=>({...n,version:11,config:Pd(n.config)})),this.version(12,n=>({...n,version:12,config:Od(n.config)})),this.version(13,n=>({...n,version:13,config:Vd(n.config)})),this.version(14,n=>({...n,version:14,config:Bd(n.config)})),this.version(15,n=>({...n,version:15,config:qd(n.config)})),this.version(16,n=>({...n,version:16,config:Nd(n.config)})),this.version(17,n=>({...n,version:17,config:Gd(n.config)})),this.version(18,(n,i)=>({...n,version:18,config:Fd(n.config,i)}))}}const jd={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Wd,name:"cartesian",viewRender:jc,configRender:Td,createConfig(){return{version:18,config:v.cloneDeep(Fn)}},triggers:[Gn]};function Yd(e){if(e.enable_value)return e.value}function Rd(e){if(e.enable_value)return e.value}function Qd(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,i={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&v.get(i,n)&&n===e.funnelAlign&&v.set(i,n,t),i}function Ud(e,t){return e.series.map(n=>{const{level_name_data_key:i,level_value_data_key:s,axisLabel:o,min:l,max:u,funnelAlign:c,orient:p,...f}=n;if(!i||!s)return{};const h=O(i),g=O(s),b=t[h.queryID].map(C=>({name:C[h.columnKey],value:C[g.columnKey]})),_=Ke(o.overflow.on_axis);return{type:"funnel",...Qd(n),min:Yd(l),max:Rd(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,..._},orient:p,funnelAlign:p==="horizontal"?"center":c,data:b}})}function Kd({conf:e,params:t,max:n}){const{name:i,value:s}=t.data,o=ee(s/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${i}`,value:`${s} (${o})`,style:{label:"",value:""}}]}function Xd(e,t){var o;const n=O(e.series[0].level_name_data_key),i=O(e.series[0].level_value_data_key),s=(o=v.maxBy(t[n.queryID],i.columnKey))==null?void 0:o[i.columnKey];return l=>{const c=Kd({conf:e,params:l,max:s}).map(f=>`
183
183
  <tr>
184
184
  <th style="text-align: right;">
185
185
  <div style="${f.style.label}">${f.label}</div>
@@ -217,7 +217,7 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
217
217
  <tbody>${g.join("")}</tbody>
218
218
  </table>
219
219
  `}}}function Cp(e){return{min:e.heat_block.min??0,max:e.heat_block.max??100,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function wp(e,t,n){const i=O(e.x_axis.data_key),s=v.uniq(t[i.queryID].map(c=>c[i.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=Ke(o.on_axis);return{id:"main-x-axis",type:"category",data:s,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:1}}function _p(e,t,n){const i=O(e.x_axis.data_key),s=O(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=v.uniq(t[i.queryID].map(g=>g[s.columnKey])),{overflow:p,rotate:f}=e.y_axis.axisLabel,h=Ke(p.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:1}}const Sp={tooltip:{confine:!0}};function Tp(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const i=fp(e),s=gp(e),o={xAxis:wp(e,t,i.x_axis),yAxis:_p(e,t,i.y_axis),series:yp(e,t),dataset:[{source:t}],tooltip:xp(e,t,i,s),grid:mp(e),visualMap:Cp(e)};return v.defaultsDeep({},o,Sp)}function Dp(e){return r(B,{})}function kp(e){return r(a.Text,{children:"Click heat block"})}const qa={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:kp,configRender:Dp,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"}]},Kn={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ge,formatter:{...Fe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ge,formatter:{...Fe}}},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:ke},tooltip:{metrics:[]}};oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ae.CanvasRenderer]);function Ip({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=m.useMemo(()=>{const h=O(e.x_axis.data_key),g=O(e.y_axis.data_key);return v.keyBy(t[h.queryID],b=>`${b[h.columnKey]}---${b[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=We(s.triggerManager,qa.id),c=m.useCallback(h=>{const[g,b]=h.value,_=v.get(l,`${g}---${b}`,{error:"rowData is not found"});u.forEach(C=>{s.runInteraction(C.id,{...h,rowData:_})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Tp(e,t),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Mp({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,Kn),[i]),l=e.data,{width:u,height:c}=e.viewport;return r(a.Box,{children:r(Ip,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}function $p({control:e,watch:t}){return t(["heat_block"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"heat_block.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"heat_block.min",control:e,render:({field:n})=>r(a.NumberInput,{label:"Min Value",...n})}),r(x.Controller,{name:"heat_block.max",control:e,render:({field:n})=>r(a.NumberInput,{label:"Max Value",...n})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),r(x.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>r(Ne,{...n})})]})}const Ap=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),zp=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),r(a.Divider,{variant:"dashed",my:10}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(Ap,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function Ep({control:e,watch:t}){return r(zp,{control:e,watch:t})}const Lp=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Pp={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
220
- `)},Na=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:_}=l,C={enabled:b,func_content:_};u(C),t(C)},f=()=>{o(),u(e)},h=b=>{u(_=>({..._,func_content:b}))},g=()=>{h(Pp.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),r(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Lp,{value:l.func_content,onChange:h,disabled:!l.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:g,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:p,children:"OK"})]})]})]})})]})});function Op({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Na,{...n})})]})]})}const Vp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Bp({control:e,watch:t}){return t(["y_axis"]),d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>r(a.Select,{label:"Name Alignment",required:!0,data:Vp,sx:{flex:1},...n})})}),r(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(x.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Na,{...n})})]})]})}function qp({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Kn),[t]),s=m.useMemo(()=>v.cloneDeep(i),[i]);m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Op,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(Bp,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Heat Block",children:r($p,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(Ep,{control:o,watch:u})})]})]})})}function Np(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=p=>p&&`${n}.${p}`,{x_axis:s,y_axis:o,heat_block:l,tooltip:u,...c}=e;return{...c,x_axis:{...s,data_key:i(s.data_key)},y_axis:{...o,data_key:i(o.data_key)},heat_block:{...l,data_key:i(l.data_key)},tooltip:{...u,metrics:u.metrics.map(p=>({...p,data_key:i(p.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Gp extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,i)=>({...n,version:2,config:Np(n.config,i)}))}}const Fp={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Gp,name:"heatmap",viewRender:Mp,configRender:qp,createConfig:()=>({version:2,config:Kn}),triggers:[qa]},Ga={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:jp,configRender:Wp,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Wp(e){return r(B,{})}function jp(e){return r(a.Text,{children:"Click chart's series"})}const Fa={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Xn={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Fe},overflow:Ge}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:ke},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:mt,markLine:Fa};function Ht(e){return ee(e).format({output:"percent",mantissa:0})}function Yp(e){const t=e.value[1];try{return Ht(t)}catch(n){return console.error(n),t}}function Rp(e){function t(n){let i=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?i=n.value[1]:i=n.value),!e.bar.label_formatter)return i;try{return ee(i).format(e.bar.label_formatter)}catch(s){return console.error(s),i}}return{bar:t,line:Yp,lineValue:Ht}}function Qp(e,t,n){const{label_template:i}=e.markLine;if(!i)return"";const s={...e,percentage:t,count:n},o=Object.keys(s),l=Object.values(s);return new Function(...o,`return \`${i}\`;`)(...l)}function Up(e,t){if(t.length===0)return{};const n=t.findIndex(u=>u[1]>=.8);if(n===-1)return{};const i=t[n],s={x:Ht((n+1)/t.length),y:Ht(i[1])},o={left:n+1,right:t.length-n-1},l=i[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:e.markLine.color},label:{formatter:Qp(e,s,o)}}]}:{}}function Kp(e,t,n){const{x_axis:i,data_key:s}=e;if(!i.data_key||!s)return[];const o=O(i.data_key),l=O(s);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[o.queryID].map(h=>[h[o.columnKey],Number(h[l.columnKey])]).sort((h,g)=>g[1]-h[1]),c=u.reduce((h,g)=>h+g[1],0),p=u.reduce((h,g,b)=>{const _=b===0?0:h[b-1][1];return h.push([g[0],_+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=Up(e,p);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:p,markLine:f}]}const Xp=(e,t)=>n=>{const i=Array.isArray(n)?n:[n];if(i.length===0)return"";const s=i.map((u,c)=>{const p=u.seriesName,[f,h]=u.value;if(!p)return h;const g=c===0?t.bar:t.lineValue;return`
220
+ `)},Na=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:_}=l,C={enabled:b,func_content:_};u(C),t(C)},f=()=>{o(),u(e)},h=b=>{u(_=>({..._,func_content:b}))},g=()=>{h(Pp.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),r(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Lp,{value:l.func_content,onChange:h,disabled:!l.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:g,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:p,children:"OK"})]})]})]})})]})});function Op({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Na,{...n})})]})]})}const Vp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Bp({control:e,watch:t}){return t(["y_axis"]),d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>r(a.Select,{label:"Name Alignment",required:!0,data:Vp,sx:{flex:1},...n})})}),r(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(x.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Na,{...n})})]})]})}function qp({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Kn),[t]),s=m.useMemo(()=>v.cloneDeep(i),[i]);m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Op,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(Bp,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Heat Block",children:r($p,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(Ep,{control:o,watch:u})})]})]})})}function Np(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=p=>p&&`${n}.${p}`,{x_axis:s,y_axis:o,heat_block:l,tooltip:u,...c}=e;return{...c,x_axis:{...s,data_key:i(s.data_key)},y_axis:{...o,data_key:i(o.data_key)},heat_block:{...l,data_key:i(l.data_key)},tooltip:{...u,metrics:u.metrics.map(p=>({...p,data_key:i(p.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Gp extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,i)=>({...n,version:2,config:Np(n.config,i)}))}}const Fp={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Gp,name:"heatmap",viewRender:Mp,configRender:qp,createConfig:()=>({version:2,config:Kn}),triggers:[qa]},Ga={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:jp,configRender:Wp,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Wp(e){return r(B,{})}function jp(e){return r(a.Text,{children:"Click chart's series"})}const Fa={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Xn={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Fe},overflow:Ge}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:ke},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:mt,markLine:Fa};function Jt(e){return ee(e).format({output:"percent",mantissa:0})}function Yp(e){const t=e.value[1];try{return Jt(t)}catch(n){return console.error(n),t}}function Rp(e){function t(n){let i=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?i=n.value[1]:i=n.value),!e.bar.label_formatter)return i;try{return ee(i).format(e.bar.label_formatter)}catch(s){return console.error(s),i}}return{bar:t,line:Yp,lineValue:Jt}}function Qp(e,t,n){const{label_template:i}=e.markLine;if(!i)return"";const s={...e,percentage:t,count:n},o=Object.keys(s),l=Object.values(s);return new Function(...o,`return \`${i}\`;`)(...l)}function Up(e,t){if(t.length===0)return{};const n=t.findIndex(u=>u[1]>=.8);if(n===-1)return{};const i=t[n],s={x:Jt((n+1)/t.length),y:Jt(i[1])},o={left:n+1,right:t.length-n-1},l=i[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:e.markLine.color},label:{formatter:Qp(e,s,o)}}]}:{}}function Kp(e,t,n){const{x_axis:i,data_key:s}=e;if(!i.data_key||!s)return[];const o=O(i.data_key),l=O(s);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[o.queryID].map(h=>[h[o.columnKey],Number(h[l.columnKey])]).sort((h,g)=>g[1]-h[1]),c=u.reduce((h,g)=>h+g[1],0),p=u.reduce((h,g,b)=>{const _=b===0?0:h[b-1][1];return h.push([g[0],_+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=Up(e,p);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:p,markLine:f}]}const Xp=(e,t)=>n=>{const i=Array.isArray(n)?n:[n];if(i.length===0)return"";const s=i.map((u,c)=>{const p=u.seriesName,[f,h]=u.value;if(!p)return h;const g=c===0?t.bar:t.lineValue;return`
221
221
  <tr>
222
222
  <th style="text-align: right; padding: 0 1em;">${p}</th>
223
223
  <td style="text-align: left; padding: 0 1em;">${g(h)}</td>
@@ -254,8 +254,8 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
254
254
  name: string;
255
255
  };
256
256
  }
257
- `,oh=()=>{const[e,t]=m.useState(!1);return d(B,{children:[r(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),r(a.Collapse,{in:e,children:r(st.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:sh})})]})};function lh({control:e,watch:t}){return t(["markLine"]),d(a.Stack,{children:[d(a.Stack,{spacing:2,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:"markLine.color",control:e,render:({field:n})=>r(Me,{...n})})]}),d(a.Stack,{spacing:4,children:[r(x.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>r(a.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),r(oh,{})]})]})}function uh({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Zt,{...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}function ch({control:e,watch:t}){return t(["data_key"]),r(a.Stack,{children:r(x.Controller,{name:"data_key",control:e,render:({field:n})=>r(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function dh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaults({},t,Xn),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["x_axis","data_key","bar","line","dataZoom"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,t),[p,t]);return d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Bar",children:"Bar"}),r(a.Tabs.Tab,{value:"Line",children:"Line"}),r(a.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),r(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(uh,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(ch,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Bar",children:r(rh,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Line",children:r(ah,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"80-20 Line",children:r(lh,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Zooming",children:r(x.Controller,{name:"dataZoom",control:s,render:({field:h})=>r(Yn,{...h})})})]})]})}function ph(e){const{dataZoom:t=mt,...n}=e;return{...n,dataZoom:t}}function hh(e){const{markLine:t=Fa,...n}=e;return{...n,markLine:t}}function fh(e){const t=v.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Fe}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function gh(e){const{label_formatter:t=ke}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function mh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return v.defaultsDeep(t,e)}function yh(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return v.defaultsDeep(t,e)}function bh(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return v.defaultsDeep(i,e)}function vh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{x_axis:s,data_key:o,...l}=e;return{...l,x_axis:{...s,data_key:i(s.data_key)},data_key:i(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class xh extends me{constructor(){super(...arguments);V(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:ph(n.config)})),this.version(3,n=>({...n,version:3,config:hh(n.config)})),this.version(4,n=>({...n,version:4,config:fh(n.config)})),this.version(5,n=>({...n,version:5,config:gh(n.config)})),this.version(6,n=>({...n,version:6,config:mh(n.config)})),this.version(7,n=>({...n,version:7,config:yh(n.config)})),this.version(8,n=>({...n,version:8,config:bh(n.config)})),this.version(9,(n,i)=>({...n,version:9,config:vh(n.config,i)}))}}const Ch={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new xh,name:"paretoChart",viewRender:th,configRender:dh,createConfig(){return{version:9,config:v.cloneDeep(Xn)}},triggers:[Ga]},Zn={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function wh(){oe.registerTheme("merico-light",{color:Object.values(Zn.graphics.multiple),visualMap:{color:Object.values(Zn.graphics.depth).reverse()}})}function Wa(){wh()}function*_h(e){const t=Zn.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let i=0;for(;;)yield n[i%n.length],i++}function Sh(e,t,n){const{label_field:i,value_field:s,color_field:o}=e;if(!i||!s||!o)return{};const l=O(i),u=O(s),c=O(o),p=t[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:h[c.columnKey]})),f=_h("multiple");return{type:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
258
- {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const g=h.labelRect.x<n/2,b=h.labelLinePoints;return v.set(b,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:b}},data:p,top:10,bottom:10,left:10,right:10}}function Th(e,t,n){return{tooltip:{show:!0,confine:!0},series:Sh(e,t,n)}}const Jn={label_field:"",value_field:"",color_field:""};oe.use([ce.PieChart,Ae.CanvasRenderer]);function Dh({context:e}){const{value:t}=W(e.instanceData,"config"),n=e.data,{width:i,height:s}=e.viewport,o=m.useMemo(()=>Th(v.defaultsDeep({},t,Jn),n,i),[t,n,i]);return!i||!s?null:r(ze,{echarts:oe,option:o,style:{width:i,height:s},notMerge:!0,theme:"merico-light"})}function kh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Jn),[t]),s=m.useMemo(()=>v.clone(i),[i]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return u(["label_field","value_field","color_field"]),r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Pie Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[r(x.Controller,{control:o,name:"label_field",render:({field:g})=>r(j,{label:"Label Key",required:!0,...g})}),r(x.Controller,{control:o,name:"value_field",render:({field:g})=>r(j,{label:"Value Key",required:!0,...g})}),r(x.Controller,{control:o,name:"color_field",render:({field:g})=>r(j,{label:"Color Key",clearable:!0,...g})})]})]})})}function Ih(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function Mh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{label_field:s,value_field:o,color_field:l}=e;return{label_field:i(s),value_field:i(o),color_field:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class $h extends me{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ih(n.config)})),this.version(3,(n,i)=>({...n,version:3,config:Mh(n.config,i)}))}}const Ah={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new $h,name:"pie",viewRender:Dh,configRender:kh,createConfig(){return{version:3,config:v.cloneDeep(Jn)}}};function zh(e){return r(B,{})}function Eh(e){return r(a.Text,{children:"Click heat block"})}const ja={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:Eh,configRender:zh,payload:[{name:"seriesType",description:"'radar'",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"}]},en={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Ya(e){return e?t=>{try{return ee(t).format(e)}catch(n){return console.error(n),t}}:t=>t}function Lh(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>Ya(e.dimensions[t].formatter)(n)}}function Ph(e){return({name:t,marker:n,value:i})=>{if(i.length===0)return"";const s=i.map((o,l)=>{const u=e.dimensions[l],c=Ya(u.formatter);return`
257
+ `,oh=()=>{const[e,t]=m.useState(!1);return d(B,{children:[r(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),r(a.Collapse,{in:e,children:r(st.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:sh})})]})};function lh({control:e,watch:t}){return t(["markLine"]),d(a.Stack,{children:[d(a.Stack,{spacing:2,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:"markLine.color",control:e,render:({field:n})=>r(Me,{...n})})]}),d(a.Stack,{spacing:4,children:[r(x.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>r(a.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),r(oh,{})]})]})}function uh({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xt,{...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}function ch({control:e,watch:t}){return t(["data_key"]),r(a.Stack,{children:r(x.Controller,{name:"data_key",control:e,render:({field:n})=>r(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function dh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaults({},t,Xn),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["x_axis","data_key","bar","line","dataZoom"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,t),[p,t]);return d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Bar",children:"Bar"}),r(a.Tabs.Tab,{value:"Line",children:"Line"}),r(a.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),r(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(uh,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(ch,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Bar",children:r(rh,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Line",children:r(ah,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"80-20 Line",children:r(lh,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Zooming",children:r(x.Controller,{name:"dataZoom",control:s,render:({field:h})=>r(Yn,{...h})})})]})]})}function ph(e){const{dataZoom:t=mt,...n}=e;return{...n,dataZoom:t}}function hh(e){const{markLine:t=Fa,...n}=e;return{...n,markLine:t}}function fh(e){const t=v.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Fe}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function gh(e){const{label_formatter:t=ke}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function mh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return v.defaultsDeep(t,e)}function yh(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return v.defaultsDeep(t,e)}function bh(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return v.defaultsDeep(i,e)}function vh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{x_axis:s,data_key:o,...l}=e;return{...l,x_axis:{...s,data_key:i(s.data_key)},data_key:i(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class xh extends me{constructor(){super(...arguments);V(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:ph(n.config)})),this.version(3,n=>({...n,version:3,config:hh(n.config)})),this.version(4,n=>({...n,version:4,config:fh(n.config)})),this.version(5,n=>({...n,version:5,config:gh(n.config)})),this.version(6,n=>({...n,version:6,config:mh(n.config)})),this.version(7,n=>({...n,version:7,config:yh(n.config)})),this.version(8,n=>({...n,version:8,config:bh(n.config)})),this.version(9,(n,i)=>({...n,version:9,config:vh(n.config,i)}))}}const Ch={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new xh,name:"paretoChart",viewRender:th,configRender:dh,createConfig(){return{version:9,config:v.cloneDeep(Xn)}},triggers:[Ga]},Zn={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function wh(){oe.registerTheme("merico-light",{color:Object.values(Zn.graphics.multiple),visualMap:{color:Object.values(Zn.graphics.depth).reverse()}})}function Wa(){wh()}function*_h(e){const t=Zn.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let i=0;for(;;)yield n[i%n.length],i++}function Sh(e,t,n){const{label_field:i,value_field:s,color_field:o}=e;if(!i||!s||!o)return{};const l=O(i),u=O(s),c=O(o),p=t[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:h[c.columnKey]})),f=_h("multiple");return{type:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
258
+ {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const g=h.labelRect.x<n/2,b=h.labelLinePoints;return v.set(b,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:b}},data:p,top:10,bottom:10,left:10,right:10}}function Th(e,t,n){return{tooltip:{show:!0,confine:!0},series:Sh(e,t,n)}}const Jn={label_field:"",value_field:"",color_field:""};oe.use([ce.PieChart,Ae.CanvasRenderer]);function Dh({context:e}){const{value:t}=W(e.instanceData,"config"),n=e.data,{width:i,height:s}=e.viewport,o=m.useMemo(()=>Th(v.defaultsDeep({},t,Jn),n,i),[t,n,i]);return!i||!s?null:r(ze,{echarts:oe,option:o,style:{width:i,height:s},notMerge:!0,theme:"merico-light"})}function kh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Jn),[t]),s=m.useMemo(()=>v.clone(i),[i]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return u(["label_field","value_field","color_field"]),r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Pie Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[r(x.Controller,{control:o,name:"label_field",render:({field:g})=>r(j,{label:"Label Key",required:!0,...g})}),r(x.Controller,{control:o,name:"value_field",render:({field:g})=>r(j,{label:"Value Key",required:!0,...g})}),r(x.Controller,{control:o,name:"color_field",render:({field:g})=>r(j,{label:"Color Key",clearable:!0,...g})})]})]})})}function Ih(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function Mh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{label_field:s,value_field:o,color_field:l}=e;return{label_field:i(s),value_field:i(o),color_field:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class $h extends me{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ih(n.config)})),this.version(3,(n,i)=>({...n,version:3,config:Mh(n.config,i)}))}}const Ah={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new $h,name:"pie",viewRender:Dh,configRender:kh,createConfig(){return{version:3,config:v.cloneDeep(Jn)}}};function zh(e){return r(B,{})}function Eh(e){return r(a.Text,{children:"Click heat block"})}const ja={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:Eh,configRender:zh,payload:[{name:"seriesType",description:"'radar'",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"}]},Ht={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Ya(e){return e?t=>{try{return ee(t).format(e)}catch(n){return console.error(n),t}}:t=>t}function Lh(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>Ya(e.dimensions[t].formatter)(n)}}function Ph(e){return({name:t,marker:n,value:i})=>{if(i.length===0)return"";const s=i.map((o,l)=>{const u=e.dimensions[l],c=Ya(u.formatter);return`
259
259
  <tr>
260
260
  <td style="padding-left: 18px;">${u.name}</td>
261
261
  <td style="text-align: right; "><strong>${c(o)}</strong></td>
@@ -283,7 +283,7 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
283
283
  ${s.join("")}
284
284
  </tbody>
285
285
  </table>
286
- `}}const Oh={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Vh=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Bh(e,t){const{series_name_key:n,dimensions:i}=e;if(!n||i.length===0)return{};const s=i.map(({name:c,max:p})=>({name:c,max:p})),o=O(n),l=t[o.queryID].map(c=>({value:i.map(({data_key:p})=>{const f=O(p);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:s,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Ph(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:Lh(e)},color:Vh};return v.merge({},Oh,u)}oe.use([ce.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function qh({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.series_name_key),u=We(s.triggerManager,ja.id),c=m.useCallback(h=>{const g=v.get(l,h.name,{error:"rowData is not found"});u.forEach(b=>{s.runInteraction(b.id,{...h,rowData:g})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Bh(v.defaultsDeep({},e,en),t),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Nh({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,en),[i]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||v.isEmpty(o==null?void 0:o.dimensions)?null:r(a.Box,{children:r(qh,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Gh({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Data Key",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`dimensions.${t}.max`,control:e,render:({field:i})=>r(a.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),r(x.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),r(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:r(D.Trash,{size:16})})]},t)}function Fh({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((g,b)=>({...g,...o[b]})),u=()=>{const g=new Date().getTime().toString();i({id:g,name:g,data_key:"",max:100,formatter:ke})},c=v.get(l,"0.id",null),[p,f]=m.useState(c);m.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{s(g);const b=v.get(l,"0.id",null);f(b)};return d(B,{children:[r(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),d(a.Tabs,{value:p,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map((g,b)=>r(a.Tabs.Tab,{value:g.id,children:g.name?g.name:b+1},b)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,b)=>r(a.Tabs.Panel,{value:g.id,children:r(Gh,{control:e,index:b,remove:h})},b))]})]})}function Wh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,en),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["series_name_key","background","label"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,i),[p,i]);return r("form",{onSubmit:o(n),children:d(a.Stack,{spacing:"xs",children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Radar Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),r(a.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),r(x.Controller,{name:"series_name_key",control:s,render:({field:h})=>r(j,{label:"Series Name Field",required:!0,sx:{flex:1},...h})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"background.enabled",control:s,render:({field:h})=>r(a.Checkbox,{label:"Show background",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})}),r(x.Controller,{name:"label.enabled",control:s,render:({field:h})=>r(a.Checkbox,{label:"Show value label",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})})]}),r(Fh,{control:s,watch:l})]})})}function jh(e){const{dimensions:t=[],...n}=e;function i({name:s="",data_key:o="",max:l=10,formatter:u=ke}){return{name:s,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(i)}}function Yh(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(i=>({...i,id:i.id??i.name}))}}function Rh(e){const t={background:{enabled:!0},label:{enabled:!0}};return v.defaultsDeep(t,e)}function Qh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{series_name_key:s,dimensions:o,...l}=e;return{...l,series_name_key:i(s),dimensions:o.map(u=>({...u,data_key:i(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Uh extends me{constructor(){super(...arguments);V(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:i}=n;return{...n,version:2,config:jh(i)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:Yh(i)}}),this.version(4,n=>{const{config:i}=n;return{...n,version:4,config:Rh(i)}}),this.version(5,(n,i)=>{const{config:s}=n;return{...n,version:5,config:Qh(s,i)}})}}const Kh={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Uh,name:"radar",viewRender:Nh,configRender:Wh,createConfig:()=>({version:5,config:en}),triggers:[ja]};function Xh(e,t){const{plot:n,transform:i}=e.regression;return t.map(s=>({...n,id:`reg-for-${s.name}`,name:s.name,data:Jt(i,s.data),color:s.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:s.name}}))}function Ra(e,t){const n=O(e.x_axis.data_key),i=O(e.regression.y_axis_data_key);return v.uniqBy(t.map(s=>[s[n.columnKey],s[i.columnKey]]),0)}function Zh(e,t){const{plot:n,transform:i}=e.regression,s=Ra(e,t);return[{type:"scatter",name:e.y_axis.name,data:s,symbolSize:4,color:"red",markLine:{...n,data:[Jt(i,s)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Jh(e,t){const{plot:n,transform:i,group_by_key:s}=e.regression,o=O(s),l=v.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const p=Ra(e,c);return{type:"scatter",name:u,data:p,symbolSize:4,markLine:{...n,data:[Jt(i,p)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Hh(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Jh(e,t):Zh(e,t)}function ef(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function tf(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=ef(t);return n.length===0?"":`
286
+ `}}const Oh={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Vh=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Bh(e,t){const{series_name_key:n,dimensions:i}=e;if(!n||i.length===0)return{};const s=i.map(({name:c,max:p})=>({name:c,max:p})),o=O(n),l=t[o.queryID].map(c=>({value:i.map(({data_key:p})=>{const f=O(p);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:s,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Ph(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:Lh(e)},color:Vh};return v.merge({},Oh,u)}oe.use([ce.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function qh({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.series_name_key),u=We(s.triggerManager,ja.id),c=m.useCallback(h=>{const g=v.get(l,h.name,{error:"rowData is not found"});u.forEach(b=>{s.runInteraction(b.id,{...h,rowData:g})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Bh(v.defaultsDeep({},e,Ht),t),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Nh({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,Ht),[i]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||v.isEmpty(o==null?void 0:o.dimensions)?null:r(a.Box,{children:r(qh,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Gh({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Data Key",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`dimensions.${t}.max`,control:e,render:({field:i})=>r(a.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),r(x.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),r(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:r(D.Trash,{size:16})})]},t)}function Fh({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((g,b)=>({...g,...o[b]})),u=()=>{const g=new Date().getTime().toString();i({id:g,name:g,data_key:"",max:100,formatter:ke})},c=v.get(l,"0.id",null),[p,f]=m.useState(c);m.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{s(g);const b=v.get(l,"0.id",null);f(b)};return d(B,{children:[r(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),d(a.Tabs,{value:p,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map((g,b)=>r(a.Tabs.Tab,{value:g.id,children:g.name?g.name:b+1},b)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,b)=>r(a.Tabs.Panel,{value:g.id,children:r(Gh,{control:e,index:b,remove:h})},b))]})]})}function Wh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,Ht),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["series_name_key","background","label"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,i),[p,i]);return r("form",{onSubmit:o(n),children:d(a.Stack,{spacing:"xs",children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Radar Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),r(a.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),r(x.Controller,{name:"series_name_key",control:s,render:({field:h})=>r(j,{label:"Series Name Field",required:!0,sx:{flex:1},...h})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"background.enabled",control:s,render:({field:h})=>r(a.Checkbox,{label:"Show background",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})}),r(x.Controller,{name:"label.enabled",control:s,render:({field:h})=>r(a.Checkbox,{label:"Show value label",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})})]}),r(Fh,{control:s,watch:l})]})})}function jh(e){const{dimensions:t=[],...n}=e;function i({name:s="",data_key:o="",max:l=10,formatter:u=ke}){return{name:s,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(i)}}function Yh(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(i=>({...i,id:i.id??i.name}))}}function Rh(e){const t={background:{enabled:!0},label:{enabled:!0}};return v.defaultsDeep(t,e)}function Qh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{series_name_key:s,dimensions:o,...l}=e;return{...l,series_name_key:i(s),dimensions:o.map(u=>({...u,data_key:i(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Uh extends me{constructor(){super(...arguments);V(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:i}=n;return{...n,version:2,config:jh(i)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:Yh(i)}}),this.version(4,n=>{const{config:i}=n;return{...n,version:4,config:Rh(i)}}),this.version(5,(n,i)=>{const{config:s}=n;return{...n,version:5,config:Qh(s,i)}})}}const Kh={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Uh,name:"radar",viewRender:Nh,configRender:Wh,createConfig:()=>({version:5,config:Ht}),triggers:[ja]};function Xh(e,t){const{plot:n,transform:i}=e.regression;return t.map(s=>({...n,id:`reg-for-${s.name}`,name:s.name,data:Zt(i,s.data),color:s.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:s.name}}))}function Ra(e,t){const n=O(e.x_axis.data_key),i=O(e.regression.y_axis_data_key);return v.uniqBy(t.map(s=>[s[n.columnKey],s[i.columnKey]]),0)}function Zh(e,t){const{plot:n,transform:i}=e.regression,s=Ra(e,t);return[{type:"scatter",name:e.y_axis.name,data:s,symbolSize:4,color:"red",markLine:{...n,data:[Zt(i,s)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Jh(e,t){const{plot:n,transform:i,group_by_key:s}=e.regression,o=O(s),l=v.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const p=Ra(e,c);return{type:"scatter",name:u,data:p,symbolSize:4,markLine:{...n,data:[Zt(i,p)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Hh(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Jh(e,t):Zh(e,t)}function ef(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function tf(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=ef(t);return n.length===0?"":`
287
287
  <table style="width: auto">
288
288
  <thead>
289
289
  <tr>
@@ -302,12 +302,12 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
302
302
  </tr>
303
303
  </tbody>
304
304
  </table>
305
- `}}}function Qa({enabled:e,func_content:t}){return(n,i)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),n}}}function nf(e){const{overflow:t,format:n,formatter:i,...s}=e.x_axis.axisLabel,o=Ke(t.on_axis);return{type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...s,...o,formatter:(l,u)=>{let c=l;try{c=ee(l).format(n)}catch{}return Qa(i)(c,u)}}}}const rf={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function af(e,t){const n=Hh(e,t),i=Xh(e,n),s={xAxis:nf(e),yAxis:{name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...i],tooltip:tf(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return v.defaultsDeep({},s,rf)}function tn(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function sf(e,t,n,i){const{x_axis:s,y_axis:o}=i,l=Je.regressionLinear()(n),{a:u,b:c,rSquared:p}=l;return{name:e,expression:d(a.Group,{position:"center",noWrap:!0,spacing:10,children:[r(a.Text,{children:o.name}),r(a.Text,{children:"="}),r(a.Text,{weight:"bold",color:"red",children:ee(c).format({mantissa:2,trimMantissa:!0})}),r(a.Text,{children:"+"}),r(a.Text,{weight:"bold",color:"red",children:ee(u).format({mantissa:2,trimMantissa:!0})}),r(a.Text,{children:"×"}),r(a.Text,{children:s.name})]}),rSquared:p,adjustedRSquared:tn(p,t.length,1)}}function of(e,t,n,i){const{x_axis:s,y_axis:o}=i,{a:l,b:u,rSquared:c}=Je.regressionExp()(n);return{name:e,expression:d(a.Group,{position:"center",noWrap:!0,spacing:10,children:[r(a.Text,{children:o.name}),r(a.Text,{children:"="}),r(a.Text,{weight:"bold",color:"gray",children:l}),r(a.Text,{children:"×"}),d(a.Group,{position:"left",noWrap:!0,spacing:2,children:[r(a.Text,{children:"Math.exp("}),r(a.Text,{weight:"bold",color:"gray",children:u}),r(a.Text,{children:"×"}),r(a.Text,{children:s.name}),r(a.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:tn(c,t.length,1)}}function lf(e,t,n,i){const{x_axis:s,y_axis:o}=i,{a:l,b:u,rSquared:c}=Je.regressionLog()(n);return{name:e,expression:d(a.Group,{position:"center",noWrap:!0,spacing:10,children:[r(a.Text,{children:o.name}),r(a.Text,{children:"="}),r(a.Text,{weight:"bold",color:"gray",children:l}),r(a.Text,{children:"×"}),d(a.Group,{position:"left",noWrap:!0,spacing:2,children:[r(a.Text,{children:"Math.log("}),r(a.Text,{children:s.name}),r(a.Text,{children:")"}),r(a.Text,{children:"+"}),r(a.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:tn(c,t.length,1)}}function uf(e,t,n,i){const{x_axis:s,y_axis:o,regression:l}=i,u=Je.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:e,expression:"",rSquared:c,adjustedRSquared:tn(c,t.length,1)}}function Ua(e,t,n){const{regression:i,x_axis:s}=n,o=O(s.data_key),l=O(i.y_axis_data_key),u=t.map(c=>[c[o.columnKey],c[l.columnKey]]);return i.transform.config.method==="linear"?sf(e,t,u,n):i.transform.config.method==="exponential"?of(e,t,u,n):i.transform.config.method==="logarithmic"?lf(e,t,u,n):i.transform.config.method==="polynomial"?uf(e,t,u,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function cf(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Ua("",e,t)];const n=O(t.regression.group_by_key),i=v.groupBy(e,n.columnKey);return Object.entries(i).map(([s,o])=>Ua(s,o,t))}const df={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ka({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:i}=e;return t?r(a.Table,{fontSize:14,sx:df,children:d("tbody",{children:[r("tr",{children:r("td",{colSpan:2,children:r(a.Text,{align:"center",children:t})})}),d("tr",{children:[r("td",{children:"R-Sq"}),r("td",{style:{textAlign:"right"},children:ee(n).format({output:"percent",mantissa:1})})]}),d("tr",{children:[r("td",{children:"R-Sq(Adjusted)"}),r("td",{style:{textAlign:"right"},children:ee(i).format({output:"percent",mantissa:1})})]})]})}):r(a.Text,{children:"Unavailable for this regression method"})}function pf({conf:e,queryData:t}){var i;const n=m.useMemo(()=>cf(t,e),[e,t]);return e.regression.group_by_key?(console.log(n),d(a.Tabs,{defaultValue:(i=n[0])==null?void 0:i.name,color:"gray",children:[r(a.Tabs.List,{grow:!0,children:n.map(s=>r(a.Tabs.Tab,{value:s.name,children:s.name},s.name))}),n.map(s=>r(a.Tabs.Panel,{value:s.name,children:r(Ka,{desc:s})},s.name))]})):r(Ka,{desc:n[0]})}function hf({conf:e,queryData:t}){return d(a.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[r(a.HoverCard.Target,{children:r(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:r(L.IconInfoCircle,{size:14}),children:"Regression Info"})}),r(a.HoverCard.Dropdown,{children:r(Le,{children:r(pf,{conf:e,queryData:t})})})]})}function ff(e){return r(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:0,height:"22px",zIndex:1},children:r(hf,{...e})})}const nn={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
306
- `)},Hn={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:ke,overflow:Ge,formatter:{...nn}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};oe.use([G.DataZoomComponent,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function gf({context:e}){const{value:t}=W(e.instanceData,"config"),{width:n,height:i}=e.viewport,s=m.useMemo(()=>{var b;const c=e.data,p=t==null?void 0:t.x_axis.data_key,f=(b=t==null?void 0:t.regression)==null?void 0:b.y_axis_data_key;if(!p||!f)return[];const h=O(p),g=O(f);return c[h.queryID].map(_=>typeof _[g.columnKey]=="number"?_:{..._,[g.columnKey]:Number(_[g.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=m.useMemo(()=>af(v.defaultsDeep({},t,Hn),s),[t,s]),l=m.useRef(null),u=c=>{l.current=c};return!n||!i||!t?null:d(a.Box,{sx:{position:"relative"},children:[r(ff,{conf:t,queryData:s}),r(ze,{echarts:oe,onChartReady:u,option:o,style:{width:n,height:i},notMerge:!0,theme:"merico-light"})]})}const mf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function yf({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),i=t("regression.group_by_key");return d(a.Stack,{children:[r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"regression.name",control:e,render:({field:s})=>r(a.TextInput,{label:"回归线名称",sx:{flex:1},...s})})}),r(x.Controller,{name:"regression.group_by_key",control:e,render:({field:s})=>r(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...s})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"regression.transform.config.method",control:e,render:({field:s})=>r(a.Select,{label:"回归方法",data:mf,sx:{flex:1},...s})}),n==="polynomial"&&r(x.Controller,{name:"regression.transform.config.order",control:e,render:({field:s})=>r(a.NumberInput,{label:"次",sx:{flex:1},...s})})]}),!i&&d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"颜色"}),r(x.Controller,{name:"regression.plot.color",control:e,render:({field:s})=>r(Me,{...s})})]})]})}const bf=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Xa=m.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},i)=>{const[s,{setTrue:o,setFalse:l}]=X.useBoolean(),[u,c]=m.useState(e);m.useEffect(()=>{c(e)},[e]);const p=_=>{c({...u,enabled:_})},f=()=>{l();const{enabled:_,func_content:C}=u,S={enabled:_,func_content:C};c(S),t(S)},h=()=>{l(),c(e)},g=_=>{c(C=>({...C,func_content:_}))},b=()=>{g(nn.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),r(a.Modal,{size:800,title:"Customize label content",opened:s,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:s&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:_=>p(_.currentTarget.checked)}),r(bf,{value:u.func_content,onChange:g,disabled:!u.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:b,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:f,children:"OK"})]})]})]})})]})});function vf({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),r(a.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),r(a.Stack,{children:r(x.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>r(Ne,{...n})})}),r(a.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xa,{triggerButtonText:"自定义标签文案内容",...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}function xf({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),r(a.Stack,{children:d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),r(x.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>r(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Cf({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaults({},t,Hn),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["x_axis","y_axis","regression"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,t),[p,t]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X轴",children:"X轴"}),r(a.Tabs.Tab,{value:"Y轴",children:"Y轴"}),r(a.Tabs.Tab,{value:"回归",children:"回归"})]}),r(a.Tabs.Panel,{value:"X轴",children:r(vf,{watch:l,control:s})}),r(a.Tabs.Panel,{value:"Y轴",children:r(xf,{watch:l,control:s})}),r(a.Tabs.Panel,{value:"回归",children:r(yf,{control:s,watch:l})})]})]})})}function wf(e){const t={x_axis:{axisLabel:{rotate:0,format:ke,overflow:Ge,formatter:nn}},regression:{group_by_key:""}};return v.defaultsDeep(t,e)}function _f(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{x_axis:s,regression:o,...l}=e;return{...l,x_axis:{...s,data_key:i(s.data_key)},regression:{...o,group_by_key:i(o.group_by_key),y_axis_data_key:i(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class Sf extends me{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:wf(n.config)})),this.version(3,(n,i)=>{const{config:s}=n;return{...n,version:3,config:_f(s,i)}})}}const Tf={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new Sf,name:"regressionChart",viewRender:gf,configRender:Cf,createConfig(){return{version:3,config:v.cloneDeep(Hn)}}},rn={content:""},er={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"}},an=({value:e,styles:t={}})=>{const n=Ei.useEditor({extensions:[Li,zi,Z.Link,Ti,Si,wi,Ii.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ai,$i,Mi,Di.configure({types:["heading","paragraph"]}),_i.configure({placeholder:"This is placeholder"}),ki,Ci.Color],content:e,editable:!1});m.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const i=m.useMemo(()=>v.defaultsDeep({},{content:er},t),[t]);return r(Z.RichTextEditor,{editor:n,styles:i,children:r(Z.RichTextEditor.Content,{})})};function Df({context:e}){const{value:t}=W(e.instanceData,"config"),n=m.useMemo(()=>v.defaults({},t,rn),[t]);return n!=null&&n.content?r(an,{value:n.content,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null}function kf(){const{editor:e}=Z.useRichTextEditorContext();return r(Z.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:r(L.IconBorderAll,{stroke:1.5,size:16})})}const tr=m.forwardRef(({value:e,onChange:t,styles:n={},label:i,onSubmit:s},o)=>{const[l,u]=m.useState(e),c=Ei.useEditor({extensions:[Li,zi,Z.Link,Ti,Si,wi,Ii.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ai,$i,Mi,Di.configure({types:["heading","paragraph"]}),_i.configure({placeholder:"This is placeholder"}),ki,Ci.Color],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});m.useEffect(()=>{u(e),c==null||c.commands.setContent(e)},[e]);const p=()=>{t(l),s==null||s()},f=e!==l,h=m.useMemo(()=>v.defaultsDeep({},{content:er},n),[n]);return d(a.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[d(a.Group,{align:"center",children:[r(a.Text,{size:14,fw:500,children:i}),r(a.ActionIcon,{color:"blue",disabled:!f,onClick:p,children:r(L.IconDeviceFloppy,{size:18})})]}),d(Z.RichTextEditor,{editor:c,styles:h,children:[d(Z.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[r(Z.RichTextEditor.ControlsGroup,{children:r(Z.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.Bold,{}),r(Z.RichTextEditor.Italic,{}),r(Z.RichTextEditor.Underline,{}),r(Z.RichTextEditor.Strikethrough,{}),r(Z.RichTextEditor.ClearFormatting,{}),r(Z.RichTextEditor.Highlight,{}),r(Z.RichTextEditor.Code,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.H1,{}),r(Z.RichTextEditor.H2,{}),r(Z.RichTextEditor.H3,{}),r(Z.RichTextEditor.H4,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.Blockquote,{}),r(Z.RichTextEditor.Hr,{}),r(Z.RichTextEditor.BulletList,{}),r(Z.RichTextEditor.OrderedList,{}),r(Z.RichTextEditor.Subscript,{}),r(Z.RichTextEditor.Superscript,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.Link,{}),r(Z.RichTextEditor.Unlink,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.AlignLeft,{}),r(Z.RichTextEditor.AlignCenter,{}),r(Z.RichTextEditor.AlignJustify,{}),r(Z.RichTextEditor.AlignRight,{})]}),r(Z.RichTextEditor.ControlsGroup,{children:r(kf,{})})]}),r(Z.RichTextEditor.Content,{})]})]})});function If({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaults({},t,rn),[t]),{control:s,handleSubmit:o,watch:l,reset:u}=x.useForm({defaultValues:i});l("content"),m.useEffect(()=>{u(i)},[i]);const c=m.useRef(null),p=()=>{var f;return(f=c.current)==null?void 0:f.click()};return r("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:d(a.Stack,{spacing:"xs",sx:{flexGrow:1},children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[r(a.Text,{children:"Content"}),r(a.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:r(D.DeviceFloppy,{size:20})})]}),r(x.Controller,{name:"content",control:s,render:({field:f})=>r(tr,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:p})})]})})}class Mf extends me{constructor(){super(...arguments);V(this,"VERSION",1)}fixMalformedConfig(n){return v.defaults({},n,rn)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const $f={displayName:"Rich Text",displayGroup:"Others",migrator:new Mf,name:"richText",viewRender:Df,configRender:If,createConfig(){return{version:1,config:v.cloneDeep(rn)}}},$t={static:{type:"static",color:Re.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
305
+ `}}}function Qa({enabled:e,func_content:t}){return(n,i)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),n}}}function nf(e){const{overflow:t,format:n,formatter:i,...s}=e.x_axis.axisLabel,o=Ke(t.on_axis);return{type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...s,...o,formatter:(l,u)=>{let c=l;try{c=ee(l).format(n)}catch{}return Qa(i)(c,u)}}}}const rf={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function af(e,t){const n=Hh(e,t),i=Xh(e,n),s={xAxis:nf(e),yAxis:{name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...i],tooltip:tf(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return v.defaultsDeep({},s,rf)}function en(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function sf(e,t,n,i){const{x_axis:s,y_axis:o}=i,l=Je.regressionLinear()(n),{a:u,b:c,rSquared:p}=l;return{name:e,expression:d(a.Group,{position:"center",noWrap:!0,spacing:10,children:[r(a.Text,{children:o.name}),r(a.Text,{children:"="}),r(a.Text,{weight:"bold",color:"red",children:ee(c).format({mantissa:2,trimMantissa:!0})}),r(a.Text,{children:"+"}),r(a.Text,{weight:"bold",color:"red",children:ee(u).format({mantissa:2,trimMantissa:!0})}),r(a.Text,{children:"×"}),r(a.Text,{children:s.name})]}),rSquared:p,adjustedRSquared:en(p,t.length,1)}}function of(e,t,n,i){const{x_axis:s,y_axis:o}=i,{a:l,b:u,rSquared:c}=Je.regressionExp()(n);return{name:e,expression:d(a.Group,{position:"center",noWrap:!0,spacing:10,children:[r(a.Text,{children:o.name}),r(a.Text,{children:"="}),r(a.Text,{weight:"bold",color:"gray",children:l}),r(a.Text,{children:"×"}),d(a.Group,{position:"left",noWrap:!0,spacing:2,children:[r(a.Text,{children:"Math.exp("}),r(a.Text,{weight:"bold",color:"gray",children:u}),r(a.Text,{children:"×"}),r(a.Text,{children:s.name}),r(a.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:en(c,t.length,1)}}function lf(e,t,n,i){const{x_axis:s,y_axis:o}=i,{a:l,b:u,rSquared:c}=Je.regressionLog()(n);return{name:e,expression:d(a.Group,{position:"center",noWrap:!0,spacing:10,children:[r(a.Text,{children:o.name}),r(a.Text,{children:"="}),r(a.Text,{weight:"bold",color:"gray",children:l}),r(a.Text,{children:"×"}),d(a.Group,{position:"left",noWrap:!0,spacing:2,children:[r(a.Text,{children:"Math.log("}),r(a.Text,{children:s.name}),r(a.Text,{children:")"}),r(a.Text,{children:"+"}),r(a.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:en(c,t.length,1)}}function uf(e,t,n,i){const{x_axis:s,y_axis:o,regression:l}=i,u=Je.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:e,expression:"",rSquared:c,adjustedRSquared:en(c,t.length,1)}}function Ua(e,t,n){const{regression:i,x_axis:s}=n,o=O(s.data_key),l=O(i.y_axis_data_key),u=t.map(c=>[c[o.columnKey],c[l.columnKey]]);return i.transform.config.method==="linear"?sf(e,t,u,n):i.transform.config.method==="exponential"?of(e,t,u,n):i.transform.config.method==="logarithmic"?lf(e,t,u,n):i.transform.config.method==="polynomial"?uf(e,t,u,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function cf(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Ua("",e,t)];const n=O(t.regression.group_by_key),i=v.groupBy(e,n.columnKey);return Object.entries(i).map(([s,o])=>Ua(s,o,t))}const df={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ka({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:i}=e;return t?r(a.Table,{fontSize:14,sx:df,children:d("tbody",{children:[r("tr",{children:r("td",{colSpan:2,children:r(a.Text,{align:"center",children:t})})}),d("tr",{children:[r("td",{children:"R-Sq"}),r("td",{style:{textAlign:"right"},children:ee(n).format({output:"percent",mantissa:1})})]}),d("tr",{children:[r("td",{children:"R-Sq(Adjusted)"}),r("td",{style:{textAlign:"right"},children:ee(i).format({output:"percent",mantissa:1})})]})]})}):r(a.Text,{children:"Unavailable for this regression method"})}function pf({conf:e,queryData:t}){var i;const n=m.useMemo(()=>cf(t,e),[e,t]);return e.regression.group_by_key?(console.log(n),d(a.Tabs,{defaultValue:(i=n[0])==null?void 0:i.name,color:"gray",children:[r(a.Tabs.List,{grow:!0,children:n.map(s=>r(a.Tabs.Tab,{value:s.name,children:s.name},s.name))}),n.map(s=>r(a.Tabs.Panel,{value:s.name,children:r(Ka,{desc:s})},s.name))]})):r(Ka,{desc:n[0]})}function hf({conf:e,queryData:t}){return d(a.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[r(a.HoverCard.Target,{children:r(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:r(L.IconInfoCircle,{size:14}),children:"Regression Info"})}),r(a.HoverCard.Dropdown,{children:r(Le,{children:r(pf,{conf:e,queryData:t})})})]})}function ff(e){return r(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:0,height:"22px",zIndex:1},children:r(hf,{...e})})}const tn={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
306
+ `)},Hn={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:ke,overflow:Ge,formatter:{...tn}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};oe.use([G.DataZoomComponent,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer]);function gf({context:e}){const{value:t}=W(e.instanceData,"config"),{width:n,height:i}=e.viewport,s=m.useMemo(()=>{var b;const c=e.data,p=t==null?void 0:t.x_axis.data_key,f=(b=t==null?void 0:t.regression)==null?void 0:b.y_axis_data_key;if(!p||!f)return[];const h=O(p),g=O(f);return c[h.queryID].map(_=>typeof _[g.columnKey]=="number"?_:{..._,[g.columnKey]:Number(_[g.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=m.useMemo(()=>af(v.defaultsDeep({},t,Hn),s),[t,s]),l=m.useRef(null),u=c=>{l.current=c};return!n||!i||!t?null:d(a.Box,{sx:{position:"relative"},children:[r(ff,{conf:t,queryData:s}),r(ze,{echarts:oe,onChartReady:u,option:o,style:{width:n,height:i},notMerge:!0,theme:"merico-light"})]})}const mf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function yf({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),i=t("regression.group_by_key");return d(a.Stack,{children:[r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"regression.name",control:e,render:({field:s})=>r(a.TextInput,{label:"回归线名称",sx:{flex:1},...s})})}),r(x.Controller,{name:"regression.group_by_key",control:e,render:({field:s})=>r(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...s})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"regression.transform.config.method",control:e,render:({field:s})=>r(a.Select,{label:"回归方法",data:mf,sx:{flex:1},...s})}),n==="polynomial"&&r(x.Controller,{name:"regression.transform.config.order",control:e,render:({field:s})=>r(a.NumberInput,{label:"次",sx:{flex:1},...s})})]}),!i&&d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"颜色"}),r(x.Controller,{name:"regression.plot.color",control:e,render:({field:s})=>r(Me,{...s})})]})]})}const bf=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Xa=m.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},i)=>{const[s,{setTrue:o,setFalse:l}]=X.useBoolean(),[u,c]=m.useState(e);m.useEffect(()=>{c(e)},[e]);const p=_=>{c({...u,enabled:_})},f=()=>{l();const{enabled:_,func_content:C}=u,S={enabled:_,func_content:C};c(S),t(S)},h=()=>{l(),c(e)},g=_=>{c(C=>({...C,func_content:_}))},b=()=>{g(tn.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),r(a.Modal,{size:800,title:"Customize label content",opened:s,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:s&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:_=>p(_.currentTarget.checked)}),r(bf,{value:u.func_content,onChange:g,disabled:!u.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:b,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:f,children:"OK"})]})]})]})})]})});function vf({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),r(a.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),r(a.Stack,{children:r(x.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>r(Ne,{...n})})}),r(a.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xa,{triggerButtonText:"自定义标签文案内容",...n})})]}),r(x.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}function xf({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),r(a.Stack,{children:d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),r(x.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>r(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Cf({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaults({},t,Hn),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["x_axis","y_axis","regression"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,t),[p,t]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X轴",children:"X轴"}),r(a.Tabs.Tab,{value:"Y轴",children:"Y轴"}),r(a.Tabs.Tab,{value:"回归",children:"回归"})]}),r(a.Tabs.Panel,{value:"X轴",children:r(vf,{watch:l,control:s})}),r(a.Tabs.Panel,{value:"Y轴",children:r(xf,{watch:l,control:s})}),r(a.Tabs.Panel,{value:"回归",children:r(yf,{control:s,watch:l})})]})]})})}function wf(e){const t={x_axis:{axisLabel:{rotate:0,format:ke,overflow:Ge,formatter:tn}},regression:{group_by_key:""}};return v.defaultsDeep(t,e)}function _f(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{x_axis:s,regression:o,...l}=e;return{...l,x_axis:{...s,data_key:i(s.data_key)},regression:{...o,group_by_key:i(o.group_by_key),y_axis_data_key:i(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class Sf extends me{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:wf(n.config)})),this.version(3,(n,i)=>{const{config:s}=n;return{...n,version:3,config:_f(s,i)}})}}const Tf={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new Sf,name:"regressionChart",viewRender:gf,configRender:Cf,createConfig(){return{version:3,config:v.cloneDeep(Hn)}}},nn={content:""},er={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"}},rn=({value:e,styles:t={}})=>{const n=Ei.useEditor({extensions:[Li,zi,Z.Link,Ti,Si,wi,Ii.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ai,$i,Mi,Di.configure({types:["heading","paragraph"]}),_i.configure({placeholder:"This is placeholder"}),ki,Ci.Color],content:e,editable:!1});m.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const i=m.useMemo(()=>v.defaultsDeep({},{content:er},t),[t]);return r(Z.RichTextEditor,{editor:n,styles:i,children:r(Z.RichTextEditor.Content,{})})};function Df({context:e}){const{value:t}=W(e.instanceData,"config"),n=m.useMemo(()=>v.defaults({},t,nn),[t]);return n!=null&&n.content?r(rn,{value:n.content,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null}function kf(){const{editor:e}=Z.useRichTextEditorContext();return r(Z.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:r(L.IconBorderAll,{stroke:1.5,size:16})})}const tr=m.forwardRef(({value:e,onChange:t,styles:n={},label:i,onSubmit:s},o)=>{const[l,u]=m.useState(e),c=Ei.useEditor({extensions:[Li,zi,Z.Link,Ti,Si,wi,Ii.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ai,$i,Mi,Di.configure({types:["heading","paragraph"]}),_i.configure({placeholder:"This is placeholder"}),ki,Ci.Color],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});m.useEffect(()=>{u(e),c==null||c.commands.setContent(e)},[e]);const p=()=>{t(l),s==null||s()},f=e!==l,h=m.useMemo(()=>v.defaultsDeep({},{content:er},n),[n]);return d(a.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[d(a.Group,{align:"center",children:[r(a.Text,{size:14,fw:500,children:i}),r(a.ActionIcon,{color:"blue",disabled:!f,onClick:p,children:r(L.IconDeviceFloppy,{size:18})})]}),d(Z.RichTextEditor,{editor:c,styles:h,children:[d(Z.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[r(Z.RichTextEditor.ControlsGroup,{children:r(Z.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.Bold,{}),r(Z.RichTextEditor.Italic,{}),r(Z.RichTextEditor.Underline,{}),r(Z.RichTextEditor.Strikethrough,{}),r(Z.RichTextEditor.ClearFormatting,{}),r(Z.RichTextEditor.Highlight,{}),r(Z.RichTextEditor.Code,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.H1,{}),r(Z.RichTextEditor.H2,{}),r(Z.RichTextEditor.H3,{}),r(Z.RichTextEditor.H4,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.Blockquote,{}),r(Z.RichTextEditor.Hr,{}),r(Z.RichTextEditor.BulletList,{}),r(Z.RichTextEditor.OrderedList,{}),r(Z.RichTextEditor.Subscript,{}),r(Z.RichTextEditor.Superscript,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.Link,{}),r(Z.RichTextEditor.Unlink,{})]}),d(Z.RichTextEditor.ControlsGroup,{children:[r(Z.RichTextEditor.AlignLeft,{}),r(Z.RichTextEditor.AlignCenter,{}),r(Z.RichTextEditor.AlignJustify,{}),r(Z.RichTextEditor.AlignRight,{})]}),r(Z.RichTextEditor.ControlsGroup,{children:r(kf,{})})]}),r(Z.RichTextEditor.Content,{})]})]})});function If({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaults({},t,nn),[t]),{control:s,handleSubmit:o,watch:l,reset:u}=x.useForm({defaultValues:i});l("content"),m.useEffect(()=>{u(i)},[i]);const c=m.useRef(null),p=()=>{var f;return(f=c.current)==null?void 0:f.click()};return r("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:d(a.Stack,{spacing:"xs",sx:{flexGrow:1},children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[r(a.Text,{children:"Content"}),r(a.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:r(D.DeviceFloppy,{size:20})})]}),r(x.Controller,{name:"content",control:s,render:({field:f})=>r(tr,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:p})})]})})}class Mf extends me{constructor(){super(...arguments);V(this,"VERSION",1)}fixMalformedConfig(n){return v.defaults({},n,nn)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const $f={displayName:"Rich Text",displayGroup:"Others",migrator:new Mf,name:"richText",viewRender:Df,configRender:If,createConfig(){return{version:1,config:v.cloneDeep(nn)}}},$t={static:{type:"static",color:Re.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
307
307
  `)}},Za={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:zf,configRender:Af,payload:[{name:"seriesType",description:"'scatter'",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"}]};function Af(e){return r(B,{})}function zf(e){return r(a.Text,{children:"Click scatter"})}const Ja={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
308
- `)},Ha={label:Ge.on_axis,tooltip:Ge.in_tooltip},nr={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:$t.static,label_position:"right",label_overflow:Ha},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ja}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:ke,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:mt};function Ef(e){const t=e.y_axes.some(s=>!!s.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let i=5;return e.x_axis.name&&(i+=15),{top:n,bottom:i}}function sn(e,t){if(e)return t[e]??void 0}function Lf({reference_areas:e,variableValueMap:t}){const n=e.map(i=>[{name:i.content.text,value:i.content.text,itemStyle:i.itemStyle,label:i.label,xAxis:sn(i.leftBottomPoint.x_data_key,t),yAxis:sn(i.leftBottomPoint.y_data_key,t)},{xAxis:sn(i.rightTopPoint.x_data_key,t),yAxis:sn(i.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function Pf({type:e,...t},n,i,s){if(!e)return 10;if(e==="static"){const{size:p}=t;return p}const{func_content:o}=t,{queryID:l,columnKey:u}=O(i),c=v.keyBy(kt(n,l),u);return(p,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:s},{lodash:v,interpolate:ct.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function Of({type:e,...t},n){if(!e)return $t.static.color;if(e==="static"){const{color:s}=t;return s}const{func_content:i}=t;return({value:s})=>{try{return new Function(`return ${i}`)()({rowData:s,variables:n},{lodash:v,interpolate:ct.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Vf(e,t,n,i){return e.map(s=>{const o=s.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,yAxisIndex:s.yAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[l]:Number(n[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Xt(s.template,t,i):""},position:u}}}})}function Bf({x_axis:e,scatter:t},n,i,s){const o=O(e.data_key),l=O(t.y_data_key);return{label:{show:!!t.label_position,position:t.label_position,...Ke(t.label_overflow.label),formatter:({value:u})=>u[t.name_data_key]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Of(t.color,i)},symbolSize:Pf(t.symbolSize,n,e.data_key,i),encode:{x:o.columnKey,y:l.columnKey}}}function qf(e,t,n,i,s){return[Bf(e,t,s)].concat(Vf(e.reference_lines,i,s,t)).concat(Lf({reference_areas:e.reference_areas,variableValueMap:s}))}function es({enabled:e,func_content:t}){return(n,i)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),n}}}function ts(e,t,n){const{x_axis:i}=n;return i.axisLabel.formatter.enabled?es(i.axisLabel.formatter)(e,t):e}function Nf(e,t){const{x_axis:n,tooltip:i}=t;if(i.trigger==="item"){const u=Rt(e[0].data,n.data_key);return ts(u,0,t)}const s=e.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!s)return"";const{axisValue:o,axisIndex:l}=s;return ts(o,l,t)}const Gf=e=>{try{return ee(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Ff(e,t){const{scatter:n,tooltip:i}=e;return{confine:!0,trigger:i.trigger,formatter:function(s){const o=t[0]??t.default,l=Array.isArray(s)?s:[s];if(l.length===0)return"";const u=Nf(l,e),c=tt(e.scatter.label_overflow.tooltip),p=l.map(({value:b})=>`
308
+ `)},Ha={label:Ge.on_axis,tooltip:Ge.in_tooltip},nr={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:$t.static,label_position:"right",label_overflow:Ha},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ja}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:ke,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:mt};function Ef(e){const t=e.y_axes.some(s=>!!s.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let i=5;return e.x_axis.name&&(i+=15),{top:n,bottom:i}}function an(e,t){if(e)return t[e]??void 0}function Lf({reference_areas:e,variableValueMap:t}){const n=e.map(i=>[{name:i.content.text,value:i.content.text,itemStyle:i.itemStyle,label:i.label,xAxis:an(i.leftBottomPoint.x_data_key,t),yAxis:an(i.leftBottomPoint.y_data_key,t)},{xAxis:an(i.rightTopPoint.x_data_key,t),yAxis:an(i.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function Pf({type:e,...t},n,i,s){if(!e)return 10;if(e==="static"){const{size:p}=t;return p}const{func_content:o}=t,{queryID:l,columnKey:u}=O(i),c=v.keyBy(kt(n,l),u);return(p,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:s},{lodash:v,interpolate:ct.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function Of({type:e,...t},n){if(!e)return $t.static.color;if(e==="static"){const{color:s}=t;return s}const{func_content:i}=t;return({value:s})=>{try{return new Function(`return ${i}`)()({rowData:s,variables:n},{lodash:v,interpolate:ct.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Vf(e,t,n,i){return e.map(s=>{const o=s.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,yAxisIndex:s.yAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[l]:Number(n[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Kt(s.template,t,i):""},position:u}}}})}function Bf({x_axis:e,scatter:t},n,i,s){const o=O(e.data_key),l=O(t.y_data_key);return{label:{show:!!t.label_position,position:t.label_position,...Ke(t.label_overflow.label),formatter:({value:u})=>u[t.name_data_key]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Of(t.color,i)},symbolSize:Pf(t.symbolSize,n,e.data_key,i),encode:{x:o.columnKey,y:l.columnKey}}}function qf(e,t,n,i,s){return[Bf(e,t,s)].concat(Vf(e.reference_lines,i,s,t)).concat(Lf({reference_areas:e.reference_areas,variableValueMap:s}))}function es({enabled:e,func_content:t}){return(n,i)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),n}}}function ts(e,t,n){const{x_axis:i}=n;return i.axisLabel.formatter.enabled?es(i.axisLabel.formatter)(e,t):e}function Nf(e,t){const{x_axis:n,tooltip:i}=t;if(i.trigger==="item"){const u=Yt(e[0].data,n.data_key);return ts(u,0,t)}const s=e.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!s)return"";const{axisValue:o,axisIndex:l}=s;return ts(o,l,t)}const Gf=e=>{try{return ee(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Ff(e,t){const{scatter:n,tooltip:i}=e;return{confine:!0,trigger:i.trigger,formatter:function(s){const o=t[0]??t.default,l=Array.isArray(s)?s:[s];if(l.length===0)return"";const u=Nf(l,e),c=tt(e.scatter.label_overflow.tooltip),p=l.map(({value:b})=>`
309
309
  <th style="text-align: right; padding-right: 1em">
310
- <div style="${c}">${Rt(b,n.name_data_key)}</div>
310
+ <div style="${c}">${Yt(b,n.name_data_key)}</div>
311
311
  </th>
312
312
  `);p.unshift("<th></th>");const f=[`<tr>
313
313
  <th style="text-align: right;">${e.x_axis.name}</th>
@@ -316,17 +316,17 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
316
316
  <th style="text-align: right;">${e.y_axes[0].name}</th>
317
317
  ${l.map(({value:b})=>`
318
318
  <td style="text-align: right; padding: 0 1em;">
319
- ${o(Rt(b,n.y_data_key))}
319
+ ${o(Yt(b,n.y_data_key))}
320
320
  </td>`).join("")}
321
321
  </tr>`],h=e.tooltip.metrics.map(b=>`<tr>
322
322
  <th style="text-align: right;">${b.name}</th>
323
- ${l.map(({value:_})=>`<td style="text-align: right; padding: 0 1em;">${Gf(Rt(_,b.data_key))}</td>`).join("")}
323
+ ${l.map(({value:_})=>`<td style="text-align: right; padding: 0 1em;">${Gf(Yt(_,b.data_key))}</td>`).join("")}
324
324
  </tr>`);return f.push(...h),`
325
325
  <table style="width: auto">
326
326
  <thead><tr>${p.join("")}</tr></thead>
327
327
  <tbody>${f.join("")}</tbody>
328
328
  </table>
329
- `}}}function Wf(e,t){const n=t.every(s=>!Number.isNaN(Number(s))),{axisLabel:i}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...i,formatter:es(i.formatter)}}]}function jf(e,t){return e.y_axes.map(({nameAlignment:n,min:i,max:s,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,min:i||void 0,max:s||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}function Yf(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Rf(e,t){if(!e.x_axis.data_key)return[];const n=O(e.x_axis.data_key);return[{source:t[n.queryID]}]}const Qf={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function Uf(e,t,n){const i=n.reduce((c,p)=>{const f=gt(p,t);return c[p.name]=nt(p,f),c},{}),s=e.y_axes.reduce((c,{label_formatter:p},f)=>(c[f]=function(g){let b=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?b=g.value[1]:b=g.value),!p)return b;try{return ee(b).format(p)}catch(_){return console.error(_),b}},c),{default:({value:c})=>c}),o=v.uniq(Ue(t,e.x_axis.data_key)),l=qf(e,t,s,n,i),u={xAxis:Wf(e,o),yAxis:jf(e,s),series:l,dataset:Rf(e,t),tooltip:Ff(e,s),grid:Ef(e),legend:Yf(),dataZoom:Wn(e.dataZoom)};return v.defaultsDeep({},u,Qf)}oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function ns(e){return e.trim().length>0}function Kf({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.x_axis.data_key),u=We(s.triggerManager,Za.id),c=m.useCallback(h=>{const g=h.data;u.forEach(b=>{s.runInteraction(b.id,{...h,rowData:g})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Uf(e,t,o),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Xf({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,nr),[i]),l=e.data,{width:u,height:c}=e.viewport,{ref:p,height:f}=we.useElementSize(),{ref:h,height:g}=we.useElementSize(),b=m.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Mt(C.top,s,l),bottom:Mt(C.bottom,s,l)}},[o,l]),_=Math.max(0,c-f-g);return d(a.Box,{children:[r(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:ns(o.stats.templates.top)?"block":"none"},children:Object.values(b.top).map(C=>C)}),r(Kf,{variables:s,width:u,height:_,data:l,conf:o,interactionManager:n}),r(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:ns(o.stats.templates.bottom)?"block":"none"},children:Object.values(b.bottom).map(C=>C)})]})}const Zf=m.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:i,variableOptions:s},o)=>{const l=(u,c)=>{const p=v.cloneDeep(e);v.set(p,u,c),t(p)};return d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),r(Un,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),d(a.Group,{grow:!0,noWrap:!0,children:[n&&r(a.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),i&&r(a.Select,{label:"Y Axis",data:i,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),d(a.Stack,{spacing:0,children:[r(a.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.Select,{icon:r(a.Text,{children:"x"}),data:s,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),r(a.Select,{icon:r(a.Text,{children:"y"}),data:s,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),d(a.Stack,{spacing:0,children:[r(a.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.Select,{icon:r(a.Text,{children:"x"}),data:s,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),r(a.Select,{icon:r(a.Text,{children:"y"}),data:s,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:14,children:"Background Color"}),r(Me,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:14,children:"Text Color"}),r(Me,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function Jf(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function Hf({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{const g=Jf();s(g)},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},b)=>({label:g,value:b.toString()})),[f]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((g,b)=>r(a.Tabs.Tab,{value:b.toString(),children:b+1},b)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(a.Tabs.Panel,{value:b.toString(),children:r(x.Controller,{name:`reference_areas.${b}`,control:e,render:({field:_})=>d(a.Stack,{children:[r(Zf,{variableOptions:p,yAxisOptions:h,..._}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(b),children:"Delete this Reference Area"})]})})},b))]})}const eg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],tg=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function ng({control:e,index:t,remove:n,watch:i,variableOptions:s,yAxisOptions:o}){const l=i(`reference_lines.${t}.orientation`);return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>r(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...u})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(a.Group,{grow:!0,children:[d(a.Stack,{children:[r(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>r(a.Select,{label:"Orientation",data:tg,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(x.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...p}})=>r(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...p,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>r(a.Select,{label:"Line Type",data:eg,sx:{flexGrow:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>r(Me,{...u})})]}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function rg({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:Re.random().css()},show_in_legend:!1,yAxisIndex:0};s(g)},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},b)=>({label:g,value:b.toString()})),[f]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((g,b)=>r(a.Tabs.Tab,{value:b.toString(),children:b+1},b)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(a.Tabs.Panel,{value:b.toString(),children:r(ng,{control:e,index:b,remove:o,watch:t,variableOptions:p,yAxisOptions:h})},b))]})}const ig=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{children:r(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},ag=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e),u=()=>{s();const{type:h,func_content:g}=o,b={type:h,func_content:g};l(b),t(b)},c=()=>{s(),l(e)},p=h=>{l(g=>({...g,func_content:h}))},f=()=>{p($t.dynamic.func_content)};return d(B,{children:[r(a.Box,{sx:{width:"50%"},children:r(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(a.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(ig,{value:o.func_content,onChange:p}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},sg=({value:e,onChange:t})=>e.type!=="dynamic"?null:r(ag,{value:e,onChange:t}),og=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=i=>{t({...e,color:i})};return r(a.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},lg=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ug=m.forwardRef(({label:e="Color",value:t,onChange:n},i)=>{const s=o=>{n({...$t[o]})};return d(a.SimpleGrid,{cols:2,children:[r(a.Select,{ref:i,label:e,data:lg,value:t.type,onChange:s,sx:{flexGrow:1}}),r(og,{value:t,onChange:n}),r(sg,{value:t,onChange:n})]})}),cg=m.forwardRef(({value:e,onChange:t},n)=>{const i=o=>{t({...e,label:o})},s=o=>{t({...e,tooltip:o})};return d(a.Stack,{ref:n,spacing:0,children:[r(Qt,{sectionTitle:"Overflow on Chart",value:e.label,onChange:i}),r(Qt,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:s})]})}),dg=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{children:r(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},rs={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
329
+ `}}}function Wf(e,t){const n=t.every(s=>!Number.isNaN(Number(s))),{axisLabel:i}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...i,formatter:es(i.formatter)}}]}function jf(e,t){return e.y_axes.map(({nameAlignment:n,min:i,max:s,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,min:i||void 0,max:s||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}function Yf(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Rf(e,t){if(!e.x_axis.data_key)return[];const n=O(e.x_axis.data_key);return[{source:t[n.queryID]}]}const Qf={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function Uf(e,t,n){const i=n.reduce((c,p)=>{const f=gt(p,t);return c[p.name]=nt(p,f),c},{}),s=e.y_axes.reduce((c,{label_formatter:p},f)=>(c[f]=function(g){let b=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?b=g.value[1]:b=g.value),!p)return b;try{return ee(b).format(p)}catch(_){return console.error(_),b}},c),{default:({value:c})=>c}),o=v.uniq(Ue(t,e.x_axis.data_key)),l=qf(e,t,s,n,i),u={xAxis:Wf(e,o),yAxis:jf(e,s),series:l,dataset:Rf(e,t),tooltip:Ff(e,s),grid:Ef(e),legend:Yf(),dataZoom:Wn(e.dataZoom)};return v.defaultsDeep({},u,Qf)}oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function ns(e){return e.trim().length>0}function Kf({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.x_axis.data_key),u=We(s.triggerManager,Za.id),c=m.useCallback(h=>{const g=h.data;u.forEach(b=>{s.runInteraction(b.id,{...h,rowData:g})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Uf(e,t,o),[e,t]);return r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Xf({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,nr),[i]),l=e.data,{width:u,height:c}=e.viewport,{ref:p,height:f}=we.useElementSize(),{ref:h,height:g}=we.useElementSize(),b=m.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Mt(C.top,s,l),bottom:Mt(C.bottom,s,l)}},[o,l]),_=Math.max(0,c-f-g);return!u||!c?null:d(a.Box,{children:[r(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:ns(o.stats.templates.top)?"block":"none"},children:Object.values(b.top).map(C=>C)}),r(Kf,{variables:s,width:u,height:_,data:l,conf:o,interactionManager:n}),r(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:ns(o.stats.templates.bottom)?"block":"none"},children:Object.values(b.bottom).map(C=>C)})]})}const Zf=m.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:i,variableOptions:s},o)=>{const l=(u,c)=>{const p=v.cloneDeep(e);v.set(p,u,c),t(p)};return d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),r(Un,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),d(a.Group,{grow:!0,noWrap:!0,children:[n&&r(a.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),i&&r(a.Select,{label:"Y Axis",data:i,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),d(a.Stack,{spacing:0,children:[r(a.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.Select,{icon:r(a.Text,{children:"x"}),data:s,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),r(a.Select,{icon:r(a.Text,{children:"y"}),data:s,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),d(a.Stack,{spacing:0,children:[r(a.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(a.Select,{icon:r(a.Text,{children:"x"}),data:s,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),r(a.Select,{icon:r(a.Text,{children:"y"}),data:s,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:14,children:"Background Color"}),r(Me,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:14,children:"Text Color"}),r(Me,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function Jf(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function Hf({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{const g=Jf();s(g)},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},b)=>({label:g,value:b.toString()})),[f]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((g,b)=>r(a.Tabs.Tab,{value:b.toString(),children:b+1},b)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(a.Tabs.Panel,{value:b.toString(),children:r(x.Controller,{name:`reference_areas.${b}`,control:e,render:({field:_})=>d(a.Stack,{children:[r(Zf,{variableOptions:p,yAxisOptions:h,..._}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(b),children:"Delete this Reference Area"})]})})},b))]})}const eg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],tg=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function ng({control:e,index:t,remove:n,watch:i,variableOptions:s,yAxisOptions:o}){const l=i(`reference_lines.${t}.orientation`);return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>r(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...u})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(a.Group,{grow:!0,children:[d(a.Stack,{children:[r(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>r(a.Select,{label:"Orientation",data:tg,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(x.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...p}})=>r(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...p,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>r(a.Select,{label:"Line Type",data:eg,sx:{flexGrow:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>r(Me,{...u})})]}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function rg({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:Re.random().css()},show_in_legend:!1,yAxisIndex:0};s(g)},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},b)=>({label:g,value:b.toString()})),[f]);return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((g,b)=>r(a.Tabs.Tab,{value:b.toString(),children:b+1},b)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(a.Tabs.Panel,{value:b.toString(),children:r(ng,{control:e,index:b,remove:o,watch:t,variableOptions:p,yAxisOptions:h})},b))]})}const ig=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{children:r(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},ag=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e),u=()=>{s();const{type:h,func_content:g}=o,b={type:h,func_content:g};l(b),t(b)},c=()=>{s(),l(e)},p=h=>{l(g=>({...g,func_content:h}))},f=()=>{p($t.dynamic.func_content)};return d(B,{children:[r(a.Box,{sx:{width:"50%"},children:r(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(a.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(ig,{value:o.func_content,onChange:p}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},sg=({value:e,onChange:t})=>e.type!=="dynamic"?null:r(ag,{value:e,onChange:t}),og=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=i=>{t({...e,color:i})};return r(a.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},lg=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ug=m.forwardRef(({label:e="Color",value:t,onChange:n},i)=>{const s=o=>{n({...$t[o]})};return d(a.SimpleGrid,{cols:2,children:[r(a.Select,{ref:i,label:e,data:lg,value:t.type,onChange:s,sx:{flexGrow:1}}),r(og,{value:t,onChange:n}),r(sg,{value:t,onChange:n})]})}),cg=m.forwardRef(({value:e,onChange:t},n)=>{const i=o=>{t({...e,label:o})},s=o=>{t({...e,tooltip:o})};return d(a.Stack,{ref:n,spacing:0,children:[r(Rt,{sectionTitle:"Overflow on Chart",value:e.label,onChange:i}),r(Rt,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:s})]})}),dg=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{children:r(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},rs={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
330
330
  `)}},pg=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e),u=()=>{s();const{type:h,func_content:g}=o,b={type:h,func_content:g};l(b),t(b)},c=()=>{s(),l(e)},p=h=>{l(g=>({...g,func_content:h}))},f=()=>{p(rs.dynamic.func_content)};return d(B,{children:[r(a.Box,{sx:{width:"50%"},children:r(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(dg,{value:o.func_content,onChange:p}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},hg=({value:e,onChange:t})=>e.type!=="dynamic"?null:r(pg,{value:e,onChange:t}),fg=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=i=>{t({...e,size:i})};return r(B,{children:r(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},gg=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],mg=m.forwardRef(({label:e="Size",value:t,onChange:n},i)=>{const s=o=>{n({...rs[o]})};return d(a.SimpleGrid,{cols:2,children:[r(a.Select,{ref:i,label:e,data:gg,value:t.type,onChange:s,sx:{flexGrow:1}}),r(fg,{value:t,onChange:n}),r(hg,{value:t,onChange:n})]})}),yg=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function bg({control:e,watch:t}){return t(["scatter"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>r(j,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>r(j,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Style",labelPosition:"center"}),r(x.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>r(mg,{label:"Size",...n})}),r(x.Controller,{name:"scatter.color",control:e,render:({field:n})=>r(ug,{...n})}),r(a.Divider,{mb:-15,label:"Label",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>r(a.Select,{label:"Label Position",data:yg,...n})})}),r(x.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>r(cg,{...n})})]})}function vg({control:e,watch:t}){return t("stats"),r(a.Stack,{children:d(a.Stack,{spacing:0,children:[r(x.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>r(It,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),r(x.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>r(It,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const xg=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Cg=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(xg,{control:e,index:g,remove:s},h.id)},h.id))]})]})},wg=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function _g({control:e,watch:t}){return t("tooltip.trigger"),d(a.Stack,{children:[r(x.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>r(a.Select,{label:"Trigger",data:wg,sx:{flexGrow:1},...n})}),r(a.Divider,{variant:"dashed"}),r(Cg,{control:e,watch:t})]})}const Sg=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Tg=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:_}=l,C={enabled:b,func_content:_};u(C),t(C)},f=()=>{o(),u(e)},h=b=>{u(_=>({..._,func_content:b}))},g=()=>{h(Ja.func_content)};return d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),r(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Sg,{value:l.func_content,onChange:h,disabled:!l.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:g,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:p,children:"OK"})]})]})]})})]})});function Dg({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Tg,{...n})})]})]})}const kg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Ig=[{label:"left",value:"left"},{label:"right",value:"right"}];function Mg({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:i})=>r(a.Select,{label:"Align",required:!0,data:kg,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:i})=>r(a.Select,{label:"Position",required:!0,data:Ig,sx:{flex:1},...i})})}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:i})=>r(a.TextInput,{label:"Min",...i})}),r(x.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:i})=>r(a.TextInput,{label:"Max",...i})})]})]}),r(a.Button,{mt:20,leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function $g({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,p)=>({...c,...o[p]})),u=()=>i({name:"",label_formatter:ke});return d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map((c,p)=>r(a.Tabs.Tab,{value:p.toString(),children:p+1},p)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,p)=>r(a.Tabs.Panel,{value:p.toString(),children:r(Mg,{control:e,index:p,remove:s})},p))]})}function Ag(e){return e||{templates:{top:"",bottom:""}}}function zg({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:Ag(t),...n}}function Eg({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaultsDeep({},t,nr),[t]),o=m.useMemo(()=>zg(s),[s]);m.useEffect(()=>{!v.isEqual(s,o)&&(console.log("config malformed, resetting to defaults",s,o),n(o))},[s,o]);const{control:l,handleSubmit:u,watch:c,getValues:p,reset:f}=x.useForm({defaultValues:o});m.useEffect(()=>{f(o)},[o]);const h=p(),g=m.useMemo(()=>!v.isEqual(h,s),[h,s]);return c(["dataZoom"]),r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:u(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),r(a.Tabs.Tab,{value:"Scatter",children:"Scatter"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),r(a.Tabs.Tab,{value:"Stats",children:"Stats"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),r(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),r(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Dg,{control:l,watch:c})}),r(a.Tabs.Panel,{value:"Y Axes",children:r($g,{control:l,watch:c})}),r(a.Tabs.Panel,{value:"Scatter",children:r(bg,{control:l,watch:c})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(_g,{control:l,watch:c})}),r(a.Tabs.Panel,{value:"Stats",children:r(vg,{control:l,watch:c})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(rg,{variables:i,control:l,watch:c})}),r(a.Tabs.Panel,{value:"Reference Areas",children:r(Hf,{variables:i,control:l,watch:c})}),r(a.Tabs.Panel,{value:"Zooming",children:r(x.Controller,{name:"dataZoom",control:l,render:({field:b})=>r(Yn,{...b})})})]})]})})}function Lg(e){const{dataZoom:t=mt,...n}=e;return{...n,dataZoom:t}}function Pg(e){const t={scatter:{label_overflow:Ha}};return v.defaultsDeep(t,e)}function Og(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...$t.static,color:t}}}:e}function Vg(e){const t=e.reference_lines.map(n=>{const{lineStyle:i={type:"dashed",width:1,color:Re.random().css()},show_in_legend:s=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:i,show_in_legend:s,yAxisIndex:o}});return{...e,reference_lines:t}}function Bg(e){const t={tooltip:{trigger:"item"}};return v.defaultsDeep({},e,t)}function qg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,scatter:o,tooltip:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},scatter:{...o,y_data_key:i(o.y_data_key),name_data_key:i(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Ng extends me{constructor(){super(...arguments);V(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:i={metrics:[]},...s}=n.config;return{...n,version:2,config:{...s,tooltip:i}}}),this.version(3,n=>({...n,version:3,config:Lg(n.config)})),this.version(4,n=>{const{config:i}=n;return{...n,version:5,config:Pg(i)}}),this.version(6,n=>{const{config:i}=n;return{...n,version:6,config:Og(i)}}),this.version(7,n=>{const{config:i}=n;return{...n,version:7,config:Vg(i)}}),this.version(8,n=>{const{config:i}=n;return{...n,version:8,config:Bg(i)}}),this.version(9,(n,i)=>{const{config:s}=n;return{...n,version:9,config:qg(s,i)}})}}const Gg={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Ng,name:"scatterChart",viewRender:Xf,configRender:Eg,createConfig(){return{version:9,config:v.cloneDeep(nr)}},triggers:[Za]},rr={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Fg(e){if("variables"in e)return e;const{align:t,size:n,weight:i,color:s,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:s,weight:i,size:n}]}}function Wg(e){return v.omit(e,["variables"])}function jg(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function Yg(e){const t=v.cloneDeep(e),n=v.get(t,"color.valueRange");return n!==void 0&&v.set(t,"color.valueRange",n.map(i=>Number(i))),t}class Rg extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Fg(n)})),this.version(2,(n,{panelModel:i})=>{const{config:s}=n;return(s.variables||[]).forEach(l=>{i.variables.find(u=>u.name===l.name)||i.addVariable(Yg(l))}),{...n,version:2,config:Wg(s)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:jg(i)}})}}const Qg={left:"flex-start",center:"center",right:"flex-end"},Ug={top:"flex-start",center:"center",bottom:"flex-end"},Kg=T.observer(({context:e})=>{const t=U(),{value:n=rr}=W(e.instanceData,"config"),{variables:i}=e,{template:s,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,p=m.useMemo(()=>{try{return v.template(s)(t.payloadForSQL)}catch{return s}},[t.payloadForSQL,s]),f=m.useMemo(()=>Mt(p,i,e.data),[p,i,e.data,e]);return r(a.Center,{sx:{width:u,height:c,justifyContent:Qg[o],alignItems:Ug[l]},children:r(a.Box,{children:Object.values(f).map((h,g)=>r(m.Fragment,{children:h},g))})})}),Xg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Zg=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Jg({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,rr),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["template","horizontal_align","vertical_align"]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,t),[p,t]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{weight:500,children:"Stats Configurations"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),r(x.Controller,{name:"template",control:s,render:({field:h})=>r(It,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),d(a.SimpleGrid,{cols:2,children:[r(x.Controller,{name:"horizontal_align",control:s,render:({field:h})=>r(a.Select,{label:"Horizontal Alignment",data:Xg,...h})}),r(x.Controller,{control:s,name:"vertical_align",render:({field:h})=>r(a.Select,{label:"Vertical Alignment",data:Zg,...h})})]})]})})}const Hg={createConfig(){return{version:3,config:rr}},displayName:"Stats",displayGroup:"Others",migrator:new Rg,name:"stats",viewRender:Kg,configRender:Jg},ir={label_key:"",value_key:"",group_key:"",levels:[]};function em(e){const t=new Set(e.map(i=>i.parent_id)),n=new Set(e.map(i=>i.id));return t.forEach(i=>{i===null||n.has(i)||e.push({id:i,name:i,parent_id:null})}),e}function tm(e){const t=em(e).map(s=>({...s,children:[]})),n=v.keyBy(t,s=>s.id),i=[];return t.forEach(s=>{if(!s.parent_id||!n[s.parent_id]){i.push(s);return}n[s.parent_id].children.push(s)}),i}function nm(e,t){const{label_key:n,value_key:i,group_key:s}=e;if(!n||!i)return[];const o=O(n),l=O(i),u=O(s),c=t[o.queryID].map(p=>({...p,id:p[o.columnKey],parent_id:p[u.columnKey],name:p[o.columnKey],value:p[l.columnKey]?Number(p[l.columnKey]):p[l.columnKey]}));return s?tm(c):c}const rm=e=>({treePathInfo:t,name:n,value:i})=>{if(t.length===1||!e)return n;try{const s=t[t.length-2].value;if(i/s<e)return" "}catch{return n}};function im(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:i,...s}=n.label;return{...n,label:{...s,formatter:rm(i)}}})}function am(){return({treePathInfo:e,name:t,value:n,color:i,marker:s,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
331
331
  <th style="text-align: right; padding: 0 1em;">Value</th>
332
332
  <td style="text-align: left; padding: 0 1em;">${n}</td>
@@ -372,7 +372,7 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
372
372
  </thead>
373
373
  <tbody>${u.join("")}</tbody>
374
374
  </table>
375
- `}}}function Ym(e,t){return{min:e.heat_block.min??0,max:e.heat_block.max??100,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const Rm={tooltip:{confine:!0},grid:{containLabel:!0}},Qm=e=>Y(e).get("year");function Um(e,t){const n=O(e.calendar.data_key),i=t[n.queryID],s=v.groupBy(i,p=>Qm(p[n.columnKey])),o=Object.keys(s),l=i.map(p=>Y(p[n.columnKey]).valueOf()),u=v.min(l),c=v.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:Y(c).diff(u,"day"),dataByYear:s,years:o}}function Km(e,t,n){const i=qm(e),{dateSpan:s,minDate:o,dataByYear:l,years:u}=Um(e,t),c=s<=366,p={calendar:Bm(c,o,u),series:Gm(e,c,l,t),tooltip:jm(e,t,i),visualMap:Ym(e,c),legend:Nm(c,u)};return v.defaultsDeep({},p,Rm)}function Xm(e){return r(B,{})}function Zm(e){return r(a.Text,{children:"Click heat block"})}const os={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Zm,configRender:Xm,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"}]},lr={calendar:{data_key:"",locale:"EN"},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:ke},tooltip:{metrics:[]}};oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ae.CanvasRenderer]);function Jm({name:e},t){const n=t.getOption();n.calendar.forEach(i=>{i.range=e}),t.setOption(n)}function Hm({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.calendar.data_key),u=We(s.triggerManager,os.id),c=m.useCallback(h=>{const[g,b]=h.value,_=v.get(l,g,{error:"rowData is not found"});u.forEach(C=>{s.runInteraction(C.id,{...h,rowData:_})})},[l,u,s]),p=m.useMemo(()=>({click:c,legendselectchanged:Jm}),[c]),f=m.useMemo(()=>Km(e,t),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function ey({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,lr),[i]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:r(a.Box,{children:r(Hm,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}function ty({control:e,watch:t}){return t(["heat_block"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"heat_block.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"heat_block.min",control:e,render:({field:n})=>r(a.NumberInput,{label:"Min Value",...n})}),r(x.Controller,{name:"heat_block.max",control:e,render:({field:n})=>r(a.NumberInput,{label:"Max Value",...n})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),r(x.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>r(Ne,{...n})})]})}const ny=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),ry=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),r(a.Divider,{variant:"dashed",my:10}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(ny,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function iy({control:e,watch:t}){return r(ry,{control:e,watch:t})}const ay=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function sy({control:e,watch:t}){return t(["calendar"]),d(a.Stack,{children:[r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),r(x.Controller,{name:"calendar.locale",control:e,render:({field:n})=>r(a.Select,{label:"Language",required:!0,data:ay,sx:{flex:1},...n})})]})}function oy({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,lr),[t]),s=m.useMemo(()=>v.cloneDeep(i),[i]);m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Calendar Heatmap Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Calendar",children:"Calendar"}),r(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(a.Tabs.Panel,{value:"Calendar",children:r(sy,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Heat Block",children:r(ty,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(iy,{control:o,watch:u})})]})]})})}function ly(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{calendar:s,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...s,data_key:i(s.data_key)},heat_block:{...o,data_key:i(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class uy extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>({...n,version:2,config:ly(n.config,i)}))}}const cy={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new uy,name:"calendarHeatmap",viewRender:ey,configRender:oy,createConfig:()=>({version:1,config:lr}),triggers:[os]},ur={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:ke,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Fe},overflow:Ge},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function dy(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:ke,show:!0}}function py(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:ft,xAxisIndex:"0"}}function hy(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function fy(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const i=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let s=0;return i&&(s+=15),e.series.some(o=>!o.hide_in_legend)&&(s+=20),{top:n,right:5,bottom:s,left:5,containLabel:!0}}function gy(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function my(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:i})=>({name:n,icon:gy(i)})),t}function yy(e,t,n,i){return e.map(s=>{const o=s.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,xAxisIndex:s.xAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[l]:Number(n[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Xt(s.template,t,i):""},position:u}}}})}function on(e,t,n){const i=Ue(e,t),s=Ue(e,n);return v.zip(s,i)}function by(e,t,n,i){const s=on(t,n,i);return v.unionBy(s,e,0)}function vy({dataTemplate:e,data:t,name_data_key:n,value_data_key:i,valueTypedXAxis:s}){return s?by(e,t,n,i):on(t,n,i)}function xy({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:i,value_data_key:s,valueTypedXAxis:o}){if(!n||n.type==="none")return vy({dataTemplate:e,data:t,name_data_key:i,value_data_key:s,valueTypedXAxis:o});const l=on(t,i,s),u=v.groupBy(l,"0");return e.map(([p])=>{const h=u[p].map(b=>b[1]),g=Vn(h,n);return[p,g]})}function Cy({group_by_key:e,data:t,value_data_key:n,name_data_key:i}){const{queryID:s,columnKey:o}=O(e),l=v.groupBy(t[s],o);return Object.entries(l).forEach(([u,c])=>{l[u]=on({[s]:c},i,n)}),l}function wy({y_axis:e},{data_key:t,xAxisIndex:n,label_position:i,name:s,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:p,invisible:f,id:h,...g},b,_,C,S,I){const $={label:{show:!!i,position:i,formatter:I[n??"default"]},name:s,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:p,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===e.data_key)return $.data=xy({dataTemplate:b,data:C,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:_}),$;const q=Cy({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(q).map(([N,P])=>{const z=v.cloneDeep($);return z.name=N,z.color=void 0,z.data=P,z})}function _y(e,t,n,i,s,o,l){const u=t.map(p=>[p,0]);return e.series.map(p=>wy(e,p,u,n,i,l,s)).flat().concat(yy(e.reference_lines,o,l,i))}function Sy(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:i,axisType:s,axisValue:o,axisIndex:l}=n;return s==="yAxis.category"?i:ht(t.y_axis.axisLabel.formatter)(o,l)}function Ty(e,t,n){const i=t.reduce((s,{xAxisIndex:o,name:l})=>(s[l]=o,s),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(s){const o=Array.isArray(s)?s:[s];if(o.length===0)return"";const l=o.map(({seriesName:p,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!p)return h;const g=i[p],b=n[g]??n.default;return`
375
+ `}}}function Ym(e,t){return{min:e.heat_block.min??0,max:e.heat_block.max??100,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const Rm={tooltip:{confine:!0},grid:{containLabel:!0}},Qm=e=>Y(e).get("year");function Um(e,t){const n=O(e.calendar.data_key),i=t[n.queryID],s=v.groupBy(i,p=>Qm(p[n.columnKey])),o=Object.keys(s),l=i.map(p=>Y(p[n.columnKey]).valueOf()),u=v.min(l),c=v.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:Y(c).diff(u,"day"),dataByYear:s,years:o}}function Km(e,t,n){const i=qm(e),{dateSpan:s,minDate:o,dataByYear:l,years:u}=Um(e,t),c=s<=366,p={calendar:Bm(c,o,u),series:Gm(e,c,l,t),tooltip:jm(e,t,i),visualMap:Ym(e,c),legend:Nm(c,u)};return v.defaultsDeep({},p,Rm)}function Xm(e){return r(B,{})}function Zm(e){return r(a.Text,{children:"Click heat block"})}const os={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Zm,configRender:Xm,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"}]},lr={calendar:{data_key:"",locale:"EN"},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:ke},tooltip:{metrics:[]}};oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ae.CanvasRenderer]);function Jm({name:e},t){const n=t.getOption();n.calendar.forEach(i=>{i.range=e}),t.setOption(n)}function Hm({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.calendar.data_key),u=We(s.triggerManager,os.id),c=m.useCallback(h=>{const[g,b]=h.value,_=v.get(l,g,{error:"rowData is not found"});u.forEach(C=>{s.runInteraction(C.id,{...h,rowData:_})})},[l,u,s]),p=m.useMemo(()=>({click:c,legendselectchanged:Jm}),[c]),f=m.useMemo(()=>Km(e,t),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function ey({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,lr),[i]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:r(a.Box,{children:r(Hm,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}function ty({control:e,watch:t}){return t(["heat_block"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"heat_block.name",control:e,render:({field:n})=>r(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"heat_block.min",control:e,render:({field:n})=>r(a.NumberInput,{label:"Min Value",...n})}),r(x.Controller,{name:"heat_block.max",control:e,render:({field:n})=>r(a.NumberInput,{label:"Max Value",...n})})]}),r(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),r(x.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>r(Ne,{...n})})]})}const ny=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),ry=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),r(a.Divider,{variant:"dashed",my:10}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(ny,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function iy({control:e,watch:t}){return r(ry,{control:e,watch:t})}const ay=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function sy({control:e,watch:t}){return t(["calendar"]),d(a.Stack,{children:[r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>r(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),r(x.Controller,{name:"calendar.locale",control:e,render:({field:n})=>r(a.Select,{label:"Language",required:!0,data:ay,sx:{flex:1},...n})})]})}function oy({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,lr),[t]),s=m.useMemo(()=>v.cloneDeep(i),[i]);m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Calendar Heatmap Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Calendar",children:"Calendar"}),r(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(a.Tabs.Panel,{value:"Calendar",children:r(sy,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Heat Block",children:r(ty,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Tooltip",children:r(iy,{control:o,watch:u})})]})]})})}function ly(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{calendar:s,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...s,data_key:i(s.data_key)},heat_block:{...o,data_key:i(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class uy extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>({...n,version:2,config:ly(n.config,i)}))}}const cy={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new uy,name:"calendarHeatmap",viewRender:ey,configRender:oy,createConfig:()=>({version:1,config:lr}),triggers:[os]},ur={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:ke,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Fe},overflow:Ge},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function dy(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:ke,show:!0}}function py(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:ft,xAxisIndex:"0"}}function hy(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function fy(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const i=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let s=0;return i&&(s+=15),e.series.some(o=>!o.hide_in_legend)&&(s+=20),{top:n,right:5,bottom:s,left:5,containLabel:!0}}function gy(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function my(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:i})=>({name:n,icon:gy(i)})),t}function yy(e,t,n,i){return e.map(s=>{const o=s.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,xAxisIndex:s.xAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[l]:Number(n[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Kt(s.template,t,i):""},position:u}}}})}function sn(e,t,n){const i=Ue(e,t),s=Ue(e,n);return v.zip(s,i)}function by(e,t,n,i){const s=sn(t,n,i);return v.unionBy(s,e,0)}function vy({dataTemplate:e,data:t,name_data_key:n,value_data_key:i,valueTypedXAxis:s}){return s?by(e,t,n,i):sn(t,n,i)}function xy({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:i,value_data_key:s,valueTypedXAxis:o}){if(!n||n.type==="none")return vy({dataTemplate:e,data:t,name_data_key:i,value_data_key:s,valueTypedXAxis:o});const l=sn(t,i,s),u=v.groupBy(l,"0");return e.map(([p])=>{const h=u[p].map(b=>b[1]),g=Vn(h,n);return[p,g]})}function Cy({group_by_key:e,data:t,value_data_key:n,name_data_key:i}){const{queryID:s,columnKey:o}=O(e),l=v.groupBy(t[s],o);return Object.entries(l).forEach(([u,c])=>{l[u]=sn({[s]:c},i,n)}),l}function wy({y_axis:e},{data_key:t,xAxisIndex:n,label_position:i,name:s,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:p,invisible:f,id:h,...g},b,_,C,S,I){const $={label:{show:!!i,position:i,formatter:I[n??"default"]},name:s,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:p,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===e.data_key)return $.data=xy({dataTemplate:b,data:C,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:_}),$;const q=Cy({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(q).map(([N,P])=>{const z=v.cloneDeep($);return z.name=N,z.color=void 0,z.data=P,z})}function _y(e,t,n,i,s,o,l){const u=t.map(p=>[p,0]);return e.series.map(p=>wy(e,p,u,n,i,l,s)).flat().concat(yy(e.reference_lines,o,l,i))}function Sy(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:i,axisType:s,axisValue:o,axisIndex:l}=n;return s==="yAxis.category"?i:ht(t.y_axis.axisLabel.formatter)(o,l)}function Ty(e,t,n){const i=t.reduce((s,{xAxisIndex:o,name:l})=>(s[l]=o,s),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(s){const o=Array.isArray(s)?s:[s];if(o.length===0)return"";const l=o.map(({seriesName:p,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!p)return h;const g=i[p],b=n[g]??n.default;return`
376
376
  <tr>
377
377
  <td>${f}</td>
378
378
  <th style="text-align: right; padding: 0 1em;">${p}</th>
@@ -387,7 +387,7 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
387
387
  ${l.join("")}
388
388
  </tbody>
389
389
  </table>
390
- `}}}function Dy(e){return e.x_axes.reduce((n,{label_formatter:i},s)=>(n[s]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!i)return u;try{return ee(u).format(i)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function ky(e,t){const n={};return t.map(i=>{const s=gt(i,e);n[i.name]=nt(i,s)}),n}function Iy(e,t){return e.x_axes.map(({min:n,max:i,...s},o)=>{let l=s.position;return l||(l=o>0?"bottom":"top"),{...s,type:"value",min:n||void 0,max:i||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function My(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:i,...s}=e.y_axis.axisLabel,o=Ke(i.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...s,...o,formatter:ht(s.formatter)},z:5}]}function $y(e,t,n){if(!e.y_axis.data_key)return{};const i=ky(t,n),s=Dy(e),o=O(e.y_axis.data_key),l=v.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=_y(e,l,u,t,s,n,i);return{xAxis:Iy(e,s),yAxis:My(e,l),series:c,tooltip:Ty(e,c,s),grid:fy(e),legend:my(c)}}oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ay({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.y_axis.data_key),u=We(s.triggerManager,Gn.id),c=m.useCallback(h=>{const g=v.get(l,h.name,{error:"rowData is not found"});u.forEach(b=>{s.runInteraction(b.id,{...h,rowData:g})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>$y(e,t,o),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function zy({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,ur),[i]),l=e.data,{width:u,height:c}=e.viewport;return r(a.Box,{children:r(Ay,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}const Ey=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Ly=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Py({control:e,index:t,remove:n,watch:i,variableOptions:s,xAxisOptions:o}){const l=i(`reference_lines.${t}.orientation`);return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>r(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...u})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(a.Group,{grow:!0,children:[d(a.Stack,{children:[r(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>r(a.Select,{label:"Orientation",data:Ly,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(x.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>r(a.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>r(a.Select,{label:"Line Type",data:Ey,sx:{flexGrow:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>r(Me,{...u})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>r(a.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Oy({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((b,_)=>({...b,...l[_]})),c=()=>{const b=hy();s(b)},p=m.useMemo(()=>n.map(b=>({label:b.name,value:b.name})),[n]),f=t("x_axes"),h=m.useMemo(()=>f.map(({name:b},_)=>({label:b,value:_.toString()})),[f]),g=u.length>0?u[0].id:"0";return d(a.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((b,_)=>r(a.Tabs.Tab,{value:b.id,children:b.name},_)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((b,_)=>r(a.Tabs.Panel,{value:b.id,children:r(Py,{control:e,index:_,remove:o,watch:t,variableOptions:p,xAxisOptions:h})},_))]})}function Vy(e){const[t,n]=m.useState(e);return m.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const By=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function qy({control:e,index:t,seriesItem:n}){const i=!!n.barWidth.trim();return d(B,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.stack`,control:e,render:({field:s})=>r(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barGap`,control:e,render:({field:s})=>r(a.Select,{label:"Bar Gap",data:By,sx:{flexGrow:1},...s})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...s})})]})]})}const Ny=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function Gy({control:e,index:t,remove:n,seriesItem:i,xAxisOptions:s}){return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),r(x.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>r(a.Select,{label:"X Axis",data:s,disabled:s.length===0,sx:{flex:1},...o})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),r(x.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>r(Ut,{label:"Aggregation on Value",value:o.value??ft,onChange:o.onChange,pt:0})})]}),r(a.Group,{grow:!0,children:r(x.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>r(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),r(qy,{index:t,control:e,seriesItem:i}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>r(a.Select,{label:"Label Position",data:Ny,...o})}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>r(Me,{...o})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>r(a.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),r(x.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>r(a.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function Fy({control:e,watch:t}){var g;const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((b,_)=>({...b,...o[_]})),u=()=>{const b=py();i(b)},c=t("x_axes"),p=m.useMemo(()=>c.map(({name:b},_)=>({label:b,value:_.toString()})),[c]),{tab:f,setTab:h}=Vy((g=l[0])==null?void 0:g.id);return d(a.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map(b=>r(a.Tabs.Tab,{value:b.id,children:b.name},b.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((b,_)=>r(a.Tabs.Panel,{value:b.id,children:r(Gy,{control:e,index:_,remove:s,seriesItem:b,xAxisOptions:p},b.id)},b.id))]})}const Wy=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function jy({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})})}),r(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:i})=>r(a.Select,{label:"Position",required:!0,data:Wy,sx:{flex:1},...i})})}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:i})=>r(a.TextInput,{label:"Min",...i})}),r(x.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:i})=>r(a.TextInput,{label:"Max",...i})})]})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:i})=>r(a.Checkbox,{label:"Visible",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),r(a.Button,{mt:20,leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function Yy({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((p,f)=>({...p,...o[f]})),u=()=>{const p=dy();i(p)},c=l.length>0?l[0].id:"0";return d(a.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map(p=>r(a.Tabs.Tab,{value:p.id,children:p.name},p.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((p,f)=>r(a.Tabs.Panel,{value:p.id,children:r(jy,{control:e,index:f,remove:s})},p.id))]})}function Ry({control:e,watch:t}){return t(["y_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Zt,{...n})})}),r(x.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}function Qy({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaultsDeep({},t,ur),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]),u([]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,s),[f,s]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Horizontal Bar Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axes",children:"X Axes"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Series",children:"Series"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),r(a.Tabs.Panel,{value:"X Axes",children:r(Yy,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(Ry,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Series",children:r(Fy,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(Oy,{variables:i,control:o,watch:u})})]})]})})}function Uy(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},y_axis:{...o,data_key:i(o.data_key)},series:l.map(c=>({...c,data_key:i(c.data_key),group_by_key:i(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Ky extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:s}=n;return{...n,version:2,config:Uy(s,i)}})}}const Xy={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new Ky,name:"horizontalBarChart",viewRender:zy,configRender:Qy,createConfig:()=>({version:2,config:ur})},cr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...nn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function Zy(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const ls=({value:e})=>{try{return ee(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function Jy(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(s=>{const o=n[s].length,c=(v.countBy(n[s],p=>p.level.diff===0).true??0)/o;return[s,"_y",c]}),label:{show:!0,formatter:ls},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:s,value:o})=>`
390
+ `}}}function Dy(e){return e.x_axes.reduce((n,{label_formatter:i},s)=>(n[s]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!i)return u;try{return ee(u).format(i)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function ky(e,t){const n={};return t.map(i=>{const s=gt(i,e);n[i.name]=nt(i,s)}),n}function Iy(e,t){return e.x_axes.map(({min:n,max:i,...s},o)=>{let l=s.position;return l||(l=o>0?"bottom":"top"),{...s,type:"value",min:n||void 0,max:i||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function My(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:i,...s}=e.y_axis.axisLabel,o=Ke(i.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...s,...o,formatter:ht(s.formatter)},z:5}]}function $y(e,t,n){if(!e.y_axis.data_key)return{};const i=ky(t,n),s=Dy(e),o=O(e.y_axis.data_key),l=v.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=_y(e,l,u,t,s,n,i);return{xAxis:Iy(e,s),yAxis:My(e,l),series:c,tooltip:Ty(e,c,s),grid:fy(e),legend:my(c)}}oe.use([G.DataZoomComponent,ce.BarChart,ce.LineChart,ce.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ay({conf:e,data:t,width:n,height:i,interactionManager:s,variables:o}){const l=ot(t,e.y_axis.data_key),u=We(s.triggerManager,Gn.id),c=m.useCallback(h=>{const g=v.get(l,h.name,{error:"rowData is not found"});u.forEach(b=>{s.runInteraction(b.id,{...h,rowData:g})})},[l,u,s]),p=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>$y(e,t,o),[e,t]);return!n||!i?null:r(ze,{echarts:oe,option:f,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function zy({context:e,instance:t}){const n=Ye({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=m.useMemo(()=>v.defaults({},i,ur),[i]),l=e.data,{width:u,height:c}=e.viewport;return r(a.Box,{children:r(Ay,{variables:s,width:u,height:c,data:l,conf:o,interactionManager:n})})}const Ey=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Ly=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Py({control:e,index:t,remove:n,watch:i,variableOptions:s,xAxisOptions:o}){const l=i(`reference_lines.${t}.orientation`);return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>r(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>r(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...u})})]}),r(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>r(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(a.Group,{grow:!0,children:[d(a.Stack,{children:[r(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>r(a.Select,{label:"Orientation",data:Ly,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(x.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>r(a.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>r(a.Select,{label:"Line Type",data:Ey,sx:{flexGrow:1},...u})}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>r(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>r(Me,{...u})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>r(a.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Oy({control:e,watch:t,variables:n}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=i.map((b,_)=>({...b,...l[_]})),c=()=>{const b=hy();s(b)},p=m.useMemo(()=>n.map(b=>({label:b.name,value:b.name})),[n]),f=t("x_axes"),h=m.useMemo(()=>f.map(({name:b},_)=>({label:b,value:_.toString()})),[f]),g=u.length>0?u[0].id:"0";return d(a.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[u.map((b,_)=>r(a.Tabs.Tab,{value:b.id,children:b.name},_)),r(a.Tabs.Tab,{onClick:c,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),u.map((b,_)=>r(a.Tabs.Panel,{value:b.id,children:r(Py,{control:e,index:_,remove:o,watch:t,variableOptions:p,xAxisOptions:h})},_))]})}function Vy(e){const[t,n]=m.useState(e);return m.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const By=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function qy({control:e,index:t,seriesItem:n}){const i=!!n.barWidth.trim();return d(B,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.stack`,control:e,render:({field:s})=>r(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barGap`,control:e,render:({field:s})=>r(a.Select,{label:"Bar Gap",data:By,sx:{flexGrow:1},...s})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...s})}),r(x.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:s})=>r(a.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...s})})]})]})}const Ny=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function Gy({control:e,index:t,remove:n,seriesItem:i,xAxisOptions:s}){return d(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),r(x.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>r(a.Select,{label:"X Axis",data:s,disabled:s.length===0,sx:{flex:1},...o})})]}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),r(x.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>r(Qt,{label:"Aggregation on Value",value:o.value??ft,onChange:o.onChange,pt:0})})]}),r(a.Group,{grow:!0,children:r(x.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>r(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),r(qy,{index:t,control:e,seriesItem:i}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>r(a.Select,{label:"Label Position",data:Ny,...o})}),d(a.Stack,{spacing:4,children:[r(a.Text,{size:"sm",children:"Color"}),r(x.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>r(Me,{...o})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>r(a.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),r(x.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>r(a.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function Fy({control:e,watch:t}){var g;const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((b,_)=>({...b,...o[_]})),u=()=>{const b=py();i(b)},c=t("x_axes"),p=m.useMemo(()=>c.map(({name:b},_)=>({label:b,value:_.toString()})),[c]),{tab:f,setTab:h}=Vy((g=l[0])==null?void 0:g.id);return d(a.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map(b=>r(a.Tabs.Tab,{value:b.id,children:b.name},b.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((b,_)=>r(a.Tabs.Panel,{value:b.id,children:r(Gy,{control:e,index:_,remove:s,seriesItem:b,xAxisOptions:p},b.id)},b.id))]})}const Wy=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function jy({control:e,index:t,remove:n}){return d(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})})}),r(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:i})=>r(a.Select,{label:"Position",required:!0,data:Wy,sx:{flex:1},...i})})}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(x.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:i})=>r(Ne,{...i})})]}),d(a.Stack,{children:[r(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:i})=>r(a.TextInput,{label:"Min",...i})}),r(x.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:i})=>r(a.TextInput,{label:"Max",...i})})]})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(x.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:i})=>r(a.Checkbox,{label:"Visible",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),r(a.Button,{mt:20,leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function Yy({control:e,watch:t}){const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((p,f)=>({...p,...o[f]})),u=()=>{const p=dy();i(p)},c=l.length>0?l[0].id:"0";return d(a.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[d(a.Tabs.List,{children:[l.map(p=>r(a.Tabs.Tab,{value:p.id,children:p.name},p.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((p,f)=>r(a.Tabs.Panel,{value:p.id,children:r(jy,{control:e,index:f,remove:s})},p.id))]})}function Ry({control:e,watch:t}){return t(["y_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>r(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"y_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xt,{...n})})}),r(x.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>r(et,{...n})})]})}function Qy({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:i}=e,s=m.useMemo(()=>v.defaultsDeep({},t,ur),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]),u([]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,s),[f,s]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Horizontal Bar Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axes",children:"X Axes"}),r(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(a.Tabs.Tab,{value:"Series",children:"Series"}),r(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),r(a.Tabs.Panel,{value:"X Axes",children:r(Yy,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Y Axis",children:r(Ry,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Series",children:r(Fy,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Reference Lines",children:r(Oy,{variables:i,control:o,watch:u})})]})]})})}function Uy(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},y_axis:{...o,data_key:i(o.data_key)},series:l.map(c=>({...c,data_key:i(c.data_key),group_by_key:i(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Ky extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:s}=n;return{...n,version:2,config:Uy(s,i)}})}}const Xy={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new Ky,name:"horizontalBarChart",viewRender:zy,configRender:Qy,createConfig:()=>({version:2,config:ur})},cr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...tn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function Zy(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const ls=({value:e})=>{try{return ee(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function Jy(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(s=>{const o=n[s].length,c=(v.countBy(n[s],p=>p.level.diff===0).true??0)/o;return[s,"_y",c]}),label:{show:!0,formatter:ls},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:s,value:o})=>`
391
391
  <table style="width: auto">
392
392
  <thead>
393
393
  <tr colspan="2">
@@ -466,8 +466,8 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
466
466
  </tr>
467
467
  </tbody>
468
468
  </table>
469
- `}},show_in_legend:!0}))}function rb(e,t,n,i){const s=O(t.data_key),o=t.name,l=n.map(u=>{const c=v.sumBy(i[u],s.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function ib(e,t,n,i){const l={barMinWidth:5,barMaxWidth:20};return[Jy(e,n,i),eb(e,n,i,l),...nb(e,n,i,l),rb(e,t,n,i)]}function ab(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Qa(n.formatter)},axisLine:{show:!1}}]}function sb(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function dr(e){return e==1||e==2?1:dr(e-2)+dr(e-1)}const ob=Array.from(new Array(20),(e,t)=>dr(t+1));function cs(e){return e<=1?e:ob.findIndex(t=>e<=t)-1}function lb(e,t){const{x_axis:n,deviation:i}=e,s=O(n.data_key),o=O(i.data_keys.estimated_value),l=O(i.data_keys.actual_value);return t[s.queryID].map(u=>{const c=cs(u[o.columnKey]),p=cs(u[l.columnKey]),f=c-p;return{...u,level:{estimated:c,actual:p,diff:f}}})}function ub(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function cb(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:ub(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const db={tooltip:{trigger:"axis"}};function pb(e,t){const{deviation:n,metrics:i}=e,s=i.find(l=>l.data_key===t);if(s)return s;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function hb(e,t,n){const i=lb(e,n),s=O(e.x_axis.data_key),o=v.uniqBy(n[s.queryID],s.columnKey).map(f=>f[s.columnKey]),l=v.groupBy(i,s.columnKey),u=pb(e,t),c=ib(e,u,o,l),p={xAxis:ab(e,o),yAxis:sb(u),series:c,grid:Zy(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:cb(c)};return v.defaultsDeep({},p,db)}const fb={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},gb=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:i,metrics:s}=e,o=m.useMemo(()=>{const l=s.map(u=>({label:u.name,value:u.data_key}));return l.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),l},[i,s]);return d(a.Group,{spacing:1,children:[r(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),r(a.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:fb})]})},mb={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function yb(){return d(a.HoverCard,{width:400,shadow:"md",children:[r(a.HoverCard.Target,{children:r(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:r(L.IconInfoCircle,{size:14}),children:"指标说明"})}),r(a.HoverCard.Dropdown,{children:r(a.Table,{fontSize:14,sx:mb,children:d("tbody",{children:[d("tr",{children:[r("th",{children:"估算偏差"}),r("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),d("tr",{children:[r("th",{children:"准确估算比例"}),r("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function bb(e){return d(a.Group,{position:"apart",children:[r(yb,{}),r(gb,{...e})]})}oe.use([ce.BarChart,ce.LineChart,ce.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.VisualMapComponent]);function vb({conf:e,data:t,width:n,height:i,metricKey:s}){const o=m.useMemo(()=>hb(e,s,t),[e,t,s]);return r(ze,{echarts:oe,option:o,style:{width:n,height:i},notMerge:!0,theme:"merico-light"})}function xb({context:e}){const{value:t}=W(e.instanceData,"config"),n=m.useMemo(()=>v.defaults({},t,cr),[t]),i=e.data,{width:s,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:p}=u.data_keys,[f,h]=m.useState(p);if(m.useEffect(()=>{h(_=>_||p)},[p]),!l.data_key||!c||!p||!s||!o)return null;const g=Math.max(s,300),b=Math.max(o,370);return d(a.Box,{sx:{overflow:"hidden",height:b,width:g},children:[r(bb,{conf:n,metricKey:f,setMetricKey:h}),r(vb,{width:g,height:b-30,data:i,conf:n,metricKey:f})]})}function Cb({control:e,watch:t}){return t(["deviation"]),d(a.Stack,{children:[r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"deviation.name",control:e,render:({field:n})=>r(a.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>r(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>r(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const wb=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),_b=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),r(a.Divider,{variant:"dashed",my:10}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(wb,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function Sb({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xa,{...n})})]})]})}function Tb({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,cr),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l([]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,i),[p,i]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Merico Estimation Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),r(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),r(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Sb,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Deviation",children:r(Cb,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Additional Metrics",children:r(_b,{control:s,watch:l})})]})]})})}function Db(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},deviation:{...o,data_keys:{estimated_value:i(o.data_keys.estimated_value),actual_value:i(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:i(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class kb extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:s}=n;return{...n,version:2,config:Db(s,i)}})}}const Ib={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new kb,name:"mericoEstimationChart",viewRender:xb,configRender:Tb,createConfig:()=>({version:2,config:cr})},Mb=[{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"})),$b=[_l,Sl,kl,Dl,Tl,Il],ds=()=>({id:"dashboard",version:An,manifest:{viz:[mr,Hg,Im,$f,Cm,Ah,Xy,ql,rc,hp,Fp,cy,Ch,jd,Gg,Kh,Tf,Om,Ib,yc],color:[...Mb,...$b]}}),At=new zl,ve={pluginManager:Qe("pluginManager"),vizManager:Qe("vizManager"),colorManager:Qe("colorManager"),instanceScope:{panelModel:Qe("panelModel"),vizInstance:Qe("vizInstance"),interactionManager:Qe("interactionManager"),migrator:Qe("migrator"),operationManager:Qe("operationManager"),triggerManager:Qe("triggerManager")}},pr=()=>{try{At.install(ds())}catch{}const e=new xl(At),t=new Al(At);return{pluginManager:At,vizManager:e,colorManager:t}},je=m.createContext(pr());try{At.install(ds())}catch{}function Ab(e,t){const{value:n,set:i}=W(e.operation.operationData,"config"),[s,o]=m.useState(v.defaults({},n,t)),l=async()=>{await i(s)};return m.useEffect(()=>{o(v.defaults({},n,t))},[n]),{config:s,setConfig:o,commit:l}}function zb(e){const{config:t,setConfig:n,commit:i}=Ab(e,{urlTemplate:"",openInNewTab:!0});async function s(){await i()}async function o(u){n({...t,openInNewTab:u}),await i()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return d(a.Stack,{children:[r(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:s}),r(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Eb(e,t){const{urlTemplate:n,openInNewTab:i}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:i,payload:e}}))}class Lb extends me{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Pb={displayName:"Open Link",id:"builtin:op:open-link",configRender:zb,run:Eb,migrator:new Lb,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Ob(e){const{value:t,set:n}=W(e.operationData,"config"),i=s=>void n({template:s});return[(t==null?void 0:t.template)||"",i]}function Vb(e){const[t,n]=Ob(e.operation);return r(a.TextInput,{defaultValue:t,onBlur:i=>n(i.currentTarget.value),label:"console.log"})}async function Bb(e,t){const n=await t.operationData.getItem("config"),i=v.template(n.template||"");console.log("run with payload",e),console.log(i(e))}const qb={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Vb,run:Bb},Nb=T.observer(e=>{const t=U(),{value:n,set:i}=W(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const s=(n==null?void 0:n.viewID)||"",o=l=>void i({viewID:l});return r(a.Select,{defaultValue:s,value:s,onChange:o,label:"View",data:t.views.options})});async function Gb(e,t){const i=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const Fb={displayName:"Open View",id:"builtin:op:open_view",configRender:Nb,run:Gb},Wb={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},jb=({value:e="",onChange:t})=>{const[n,i]=m.useState(e);m.useEffect(()=>{i(e)},[e]);const s=()=>{t(n)};return r(a.TextInput,{size:"xs",label:"",value:n,onChange:o=>i(o.currentTarget.value),sx:{flexGrow:1},rightSection:r(a.ActionIcon,{color:"green",size:"xs",onClick:s,disabled:n===e,children:r(L.IconDeviceFloppy,{})})})},Yb={dictionary:{}},Rb=T.observer(e=>{const t=U(),{value:n=Yb,set:i}=W(e.operation.operationData,"config"),{dictionary:s={}}=n;console.log({value:{...n},dictionary:{...s},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...s};delete c[l],i({dictionary:c});return}i({dictionary:{...s,[l]:u}})};return d(a.Table,{sx:Wb,children:[r("thead",{children:d("tr",{children:[r("th",{children:"Set filter"}),r("th",{children:"with"})]})}),r("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in s;return d("tr",{"data-affected":u,children:[r("td",{children:l.label}),r("td",{children:r(jb,{value:s[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function Qb(e,t){const i=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:e}}))}const Ub={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Rb,run:Qb},Kb={filter_keys:[]},Xb=T.observer(e=>{const t=U(),{value:n=Kb,set:i}=W(e.operation.operationData,"config"),{filter_keys:s=[]}=n,o=u=>{i({filter_keys:[...u]})},l=m.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return r(a.Stack,{spacing:10,children:r(a.MultiSelect,{label:"Select Filters to Clear",data:l,value:s,onChange:o})})});async function Zb(e,t){const i=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:e}}))}const ln=[qb,Pb,Fb,Ub,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Xb,run:Zb}];class Jb{constructor(t,n=ln){V(this,"attachments");this.operations=n;const i=async s=>{const{id:o,schemaRef:l}=await s.getItem(null);return{id:o,schemaRef:l,operationData:new pt(s,"data")}};this.attachments=new Mn(t,"__OPERATIONS",i)}async runOperation(t,n){const i=await this.attachments.getInstance(t);if(!i){console.warn(`Operation '${t}' is not defined`);return}const s=this.tryGetSchema(i.schemaRef);if(!s){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await s.run(n,i)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(s)});return(await Promise.all(n)).some(i=>i)}async runMigration(){const n=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(s)&&await l.migrate(s)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const s=await this.attachments.getInstance(t);return!s||s.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):s}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}class hr{constructor(t,n,i){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new Jb(t,i),this.triggerManager=new lu(t,n);const s=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new Mn(t,"__INTERACTIONS",s)}async addInteraction(t,n){const i=t.id,s=n.id,o=`[${i}]:[${s}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:s})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:i,operationRef:s}=n;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(s)<=1&&await this.operationManager.removeOperation(s),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(i=>i.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(i=>i.triggerRef===t).length}async runInteraction(t,n){const s=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(s.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const Ye=({vizManager:e,instance:t})=>X.useCreation(()=>new hr(t,e.resolveComponent(t.type),ln),[t,e]),ps={left:"flex-start",center:"center",right:"flex-end"},Hb=({header:e,cx:t})=>{const n=v.get(e.column.columnDef.meta,"align","left");return d(a.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:ps[n]},children:[e.isPlaceholder?null:Be.flexRender(e.column.columnDef.header,e.getContext()),r(ev,{direction:e.column.getIsSorted()})]})},ev=({direction:e})=>{switch(e){case"asc":return r(L.IconArrowUp,{size:16});case"desc":return r(L.IconArrowDown,{size:"1em"});default:return null}},fr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:iv,configRender:nv,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},tv={column:""};function hs(e,t){const{value:n}=W(e.instanceData,"config"),i={columnsFromConfig:[],columnsFromData:[]};if(n&&(i.columnsFromConfig=n.columns.map((s,o)=>({label:s.label,value:o.toString()}))),!t)return i;if(n!=null&&n.id_field){const s=kt(t,n.id_field);(s==null?void 0:s.length)>0&&(i.columnsFromData=Object.keys(s[0]).map(o=>({label:o,value:o})))}return i}function nv(e){const{columnsFromConfig:t,columnsFromData:n}=hs(e.instance,e.sampleData),i=t.length>0?t:n,{value:s,set:o}=W(e.trigger.triggerData,"config"),{column:l}=v.defaults({},s,tv),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return r(a.Select,{clearable:!1,data:i,label:"Choose a column",value:l.toString(),onChange:u})}function rv(e,t){return e?v.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function iv(e){const{columnsFromConfig:t}=hs(e.instance),{value:n}=W(e.trigger.triggerData,"config");return r(a.Text,{children:rv(n,t)})}const av=a.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),sv={tableLayout:"fixed","th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}};function fs(e,t,n){return Math.min(Math.max(e,t),n)}class ov{constructor(t){this.steps=t;const n=[],i=new Set;for(const s of t)i.has(s.to)||(n.push(s),i.add(s.to));if(n.sort((s,o)=>s.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(t,n){const i=(n.to-t.to)/(n.from-t.from),s=t.to-i*t.from;return o=>i*o+s}getStepFunctionForValue(t){let n=v.findLastIndex(this.steps,i=>i.from<=t);return n=fs(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return fs(this.getStepFunctionForValue(t)(t),0,100)}}class lv{constructor(t,n,i,s,o){this.getColIndex=t,this.cell=n,this.triggers=i,this.interactionManager=s,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const i of t)this.interactionManager.runInteraction(i.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===fr.id).filter(n=>{const i=this.getColIndex(this.cell),s=v.get(this.cell.column.columnDef.meta,"value_field"),o=v.get(n.config,"column");return o==i||o==s})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(v.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const i=this.colorManager.decodeInterpolation(t.interpolation),o=new ov(t.steps).mapValue(n);return i==null?void 0:i.getColor(o)}}}const uv=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:ps[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function cv(e){return e?Re(e).oklch()[0]>.7?"black":"white":"inherit"}function dv(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:cv(t)}}function yt(e){const t=e.tableCellContext.isClickable(),n=uv({clickable:t,align:e.align});return r("div",{className:n.classes.content,style:{...dv(e)},children:r(a.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:r("span",{title:e.children,children:e.children})})})}function pv(e){return r(yt,{...e,children:e.value})}function hv(e){const t=ee(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return r(yt,{...e,children:t})}function fv(e){const t=ee(e.value).format({thousandSeparated:!0});return r(yt,{...e,children:t})}function gv(e){const t=ee(e.value).format({output:"percent",mantissa:3});return r(yt,{...e,children:t})}function mv(e){const t=e.value,n=e.func_content;if(!n)return r(yt,{...e,children:t});const i=new Function(`return ${n}`)()({value:t});return r(yt,{...e,children:i})}function yv(e){switch(e.type){case qe.string:return r(pv,{...e});case qe.eloc:return r(hv,{...e});case qe.number:return r(fv,{...e});case qe.percentage:return r(gv,{...e});case qe.custom:return r(mv,{...e})}}const bv=e=>{const t=Ye(e),n=We(t.triggerManager,fr.id),{colorManager:i}=m.useContext(je);return m.useCallback(s=>new lv(e.getColIndex,s,n,t,i),[n,t,e.getColIndex])};function vv({context:e,instance:t}){var fe,Ce;const n=e.data,{height:i,width:s}=e.viewport,{value:o=In}=W(e.instanceData,"config"),{id_field:l,use_raw_columns:u,columns:c,...p}=o,{classes:f,cx:h}=av(),g=m.useMemo(()=>{if(!l)return[];const pe=O(l);return n[pe.queryID]},[n,l]),b=m.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(pe=>({id:pe,label:pe,value_field:pe,value_type:qe.string,align:"left"})):c,[u,c,g]),_=bv({getColIndex:m.useCallback(pe=>b.indexOf(pe.column.columnDef.meta),[b]),vizManager:e.vizManager,instance:t}),C=m.useMemo(()=>{const pe=Be.createColumnHelper();return b.map(ge=>{const Ie=O(ge.value_field);return pe.accessor(Ie.columnKey,{cell:Pe=>r(yv,{tableCellContext:_(Pe.cell),value:Pe.getValue(),type:ge.value_type,...ge}),header:ge.label,enableSorting:!0,meta:ge,size:ge.width,minSize:ge.width})})},[b,_]),[S,I]=m.useState([]),$=Be.useReactTable({data:g,state:{sorting:S},onSortingChange:I,columns:C,getCoreRowModel:Be.getCoreRowModel(),getSortedRowModel:Be.getSortedRowModel()}),{rows:q}=$.getRowModel(),N=m.useRef(null),P=wo.useVirtual({parentRef:N,size:q.length,estimateSize:m.useCallback(()=>28,[]),overscan:20}),{virtualItems:z,totalSize:A}=P,F=z.length>0&&((fe=z==null?void 0:z[0])==null?void 0:fe.start)||0,K=z.length>0?A-(((Ce=z==null?void 0:z[z.length-1])==null?void 0:Ce.end)||0):0,R=q.length,ne=R>0,se=ne?i-22:i,le=ne?22:0;return!Array.isArray(g)||g.length===0?r(a.Text,{color:"gray",align:"center",children:"Empty Data"}):d("div",{ref:N,style:{height:i,width:s},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[R>0&&r(a.Box,{className:f.info_bar,sx:{height:22},children:d(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",R]})}),d(a.Table,{sx:{...sv,maxHeight:se},...p,striped:o.striped,children:[r("thead",{className:f.thead,style:{top:le},children:$.getHeaderGroups().map(pe=>r("tr",{children:pe.headers.map(ye=>r("th",{style:{width:ye.getSize()},children:r(Hb,{header:ye,cx:h})},ye.id))},pe.id))}),d("tbody",{children:[F>0&&r("tr",{children:r("td",{style:{height:`${F}px`}})}),z.map(pe=>{const ye=q[pe.index];return r("tr",{children:ye.getVisibleCells().map(ge=>r("td",{children:Be.flexRender(ge.column.columnDef.cell,ge.getContext())},ge.id))},ye.id)}),K>0&&r("tr",{children:r("td",{style:{height:`${K}px`}})})]})]})]})}const gs=a.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),xv=[{from:0,to:0},{from:100,to:100}];class Cv{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");ie.makeAutoObservable(this,{steps:ie.observable},{deep:!1}),ie.reaction(()=>ie.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,i])=>({to:n,from:i})).sort((n,i)=>n.to-i.to||n.from-i.from))}fromProps(t){t.steps.length<2?this.setSteps(xv):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function wv(e){const{onChange:t,color:n,index:i,value:s}=e,{classes:o}=gs(),[l,u]=m.useState(s),[c,{setTrue:p,setFalse:f}]=X.useBoolean(!1),h=i%2===1,g=h&&s!=null,b=!h&&s!=null,_=`map ${s} to color ${i}`,C=()=>{u(s),f()},S=()=>{f(),t==null||t(l)},I=ee(s).format({average:!0});return d("div",{"data-testid":`palette-item-${i}`,className:o.paletteItem,children:[r(a.Text,{title:_,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),d(a.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[r(a.Popover.Target,{children:r("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":Re(n).alpha(.5).hex(),backgroundColor:n}})}),r(a.Popover.Dropdown,{children:d(a.Stack,{children:[r(a.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),d(a.Group,{position:"right",children:[r(a.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),r(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:S,children:"OK"})]})]})})]}),r(a.Text,{title:_,style:{opacity:b?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const _v=T.observer(({model:e})=>{const{classes:t}=gs(),n=v.range(0,13,1).map(i=>100/12*i).map(i=>[e.interpolation.getColor(i),i]);return r("div",{className:t.palette,children:n.map(([i,s],o)=>r(wv,{index:o,color:i,value:e.getStepFromValue(s),onChange:l=>e.changeStep(l,s)},i))})}),Sv=T.observer(function(t){const n=X.useCreation(()=>new Cv,[]);return m.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:r(_v,{model:n})}),Tv=e=>{const{value:t,onChange:n,colorManager:i}=e,s=i.getColorInterpolations(),[o,l]=m.useState(t),u=i.decodeInterpolation(o.interpolation)||s[0],[c,{setTrue:p,setFalse:f}]=X.useBoolean(),h=s.map(S=>({label:S.displayName,value:i.encodeColor(S),group:S.category}));function g(S){S&&l(I=>({...I,interpolation:S}))}const b=()=>{f(),n==null||n(ie.toJS(o))};function _(S){l(I=>({...I,steps:S}))}const C=()=>{f(),l(t)};return d(B,{children:[r(a.Button,{variant:"outline",onClick:p,children:u==null?void 0:u.displayName}),r(a.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&d(a.Stack,{"data-testid":"color-interpolation-modal",children:[r(a.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),r(Sv,{steps:o.steps,interpolation:u,onChange:_}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:b,children:"OK"})]})]})})]})},Dv=["static","interpolation","none"].map(e=>({label:v.capitalize(e),value:e})),kv=[{from:0,to:0},{from:100,to:100}];function ms(e){return e?v.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Iv(e,t){var n;return ms(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Mv(e,t){return v.isObject(t)?t:{steps:kv,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const $v=m.forwardRef((e,t)=>{const{colorManager:n}=m.useContext(je),[i,s]=m.useState(ms(e.value)),[o,l]=m.useState(Iv(n,e.value)),u=X.useLatest(o),[c,p]=m.useState(Mv(n,e.value)),f=X.useLatest(c),h=_=>{var C,S,I;s(_||"none"),_==="static"?(C=e.onChange)==null||C.call(e,u.current):_==="none"||!_?(S=e.onChange)==null||S.call(e,"none"):(I=e.onChange)==null||I.call(e,f.current)},g=_=>{var C;l(_),(C=e.onChange)==null||C.call(e,_)},b=_=>{var C;p(_),(C=e.onChange)==null||C.call(e,_)};return d(a.Stack,{align:"stretch",children:[r(a.Select,{label:"Cell background",value:i||"none",onChange:h,data:Dv}),i==="static"&&r(Me,{value:o,onChange:g}),i==="interpolation"&&r(Tv,{colorManager:n,value:c,onChange:b})]})}),Av={[qe.eloc]:"ELOC"},zv=Object.values(qe).map(e=>({label:v.get(Av,e,v.capitalize(e)),value:e})),Ev=m.forwardRef(({label:e,value:t,onChange:n,sx:i},s)=>r(a.Select,{ref:s,label:e,data:zv,value:t,onChange:n,sx:i})),Lv=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},p=()=>{o(),u(e)},f=()=>{u(ca)};return m.useEffect(()=>{u(e)},[e]),d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Custom Cell Content"}),r(a.Modal,{size:800,title:"Custom cell content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Box,{sx:{position:"relative"},children:r(De,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Pv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],gr=()=>r(a.Text,{color:"dimmed",size:12,children:"px"}),Ov=({control:e,index:t,watch:n,remove:i,column:s})=>{const o=n(`columns.${t}.value_type`);return d(a.Stack,{my:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,children:[r(x.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>r(a.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),r(x.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>r(j,{label:"Value Field",required:!0,...l})})]}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>r(Ev,{label:"Value Type",sx:{flex:1},...l})}),o===qe.custom&&r(x.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>r(Lv,{value:l.value??ca,onChange:u=>l.onChange(u??"")})})]}),r(a.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(a.NumberInput,{hideControls:!0,label:"Min Width",rightSection:r(gr,{}),disabled:!0}),r(x.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>r(a.NumberInput,{hideControls:!0,label:"Width",rightSection:r(gr,{}),...l})}),r(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:r(gr,{}),disabled:!0})]}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>r(a.Select,{label:"Alignment",data:Pv,...l})})}),r(x.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>r($v,{...l})}),r(a.Divider,{mb:4,mt:12,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(t),children:"Delete this column"})]})},Vv=({control:e,watch:t})=>{const{fields:n,append:i,remove:s,update:o}=x.useFieldArray({control:e,name:"columns"}),l=()=>{const c=we.randomId();i({id:c,label:c,value_field:"",value_type:qe.string})};t("columns");const u=t("use_raw_columns");return d(B,{children:[r(x.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>r(a.Switch,{mt:20,label:"Use Original Data Columns",checked:c.value,onChange:p=>c.onChange(p.currentTarget.checked)})}),r(a.Divider,{mt:20,mb:10,variant:"dashed"}),!u&&d(a.Stack,{children:[r(a.Text,{my:0,children:"Custom Columns"}),d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[n.map((c,p)=>r(a.Tabs.Tab,{value:p.toString(),children:p+1},c.id)),r(a.Tabs.Tab,{onClick:l,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,p)=>r(a.Tabs.Panel,{value:p.toString(),children:r(Ov,{control:e,watch:t,index:p,column:c,remove:s},p)},c.id))]})]})]})};function Bv({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),d(a.Stack,{spacing:"xs",children:[d(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[r(x.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>r(a.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>r(a.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),r(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:r(x.Controller,{name:"fontSize",control:e,render:({field:n})=>r(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),d(a.Group,{position:"apart",grow:!0,children:[r(x.Controller,{name:"striped",control:e,render:({field:n})=>r(a.Switch,{label:"Striped",checked:n.value,onChange:i=>n.onChange(i.currentTarget.checked)})}),r(x.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>r(a.Switch,{label:"Highlight on hover",checked:n.value,onChange:i=>n.onChange(i.currentTarget.checked)})})]})]})}function qv({columns:e,...t}){return{...t,columns:e.map(({id:n,...i})=>({id:n??we.randomId(),...i}))}}function Nv({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,In),[t]),s=m.useMemo(()=>qv(i),[i]);m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return u(["id_field"]),d("form",{onSubmit:l(n),children:[d(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Table Config"}),r(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Data",children:"Data"}),r(a.Tabs.Tab,{value:"Style",children:"Style"}),r(a.Tabs.Tab,{value:"Columns",children:"Columns"})]}),r(a.Tabs.Panel,{value:"Data",children:r(x.Controller,{name:"id_field",control:o,render:({field:g})=>r(j,{label:"ID Field",required:!0,...g})})}),r(a.Tabs.Panel,{value:"Style",children:r(Bv,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Columns",children:r(Vv,{control:o,watch:u})})]})]})}function Gv(e){const{columns:t,...n}=e;return{...e,columns:t.map(i=>({...i,align:i.align??"left"}))}}function Fv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{id_field:s,columns:o,...l}=e;return{...l,id_field:i(s),columns:o.map(u=>({...u,value_field:i(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wv extends me{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:i,...s}=n.config;return{...n,version:2,config:{...s,columns:i.map(({id:o,...l})=>({id:o??we.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Gv(n.config)})),this.version(4,(n,i)=>({...n,version:4,config:Fv(n.config,i)}))}}const mr={createConfig(){return{version:4,config:v.cloneDeep(In)}},displayName:"Table",displayGroup:"Others",migrator:new Wv,name:"table",viewRender:vv,configRender:Nv,triggers:[fr]},jv=y.types.model("PanelLayoutModel",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:i,h:s,moved:o}=e;return{h:s,w:i,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:i,w:s,h:o,moved:l}=t;e.x=n,e.y=i,e.w=s,e.h=o,e.moved=!!l,e.static=!!t.static}})),Yv=y.types.model("PanelStyleBorderModel",{enabled:y.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Rv=y.types.model("PanelStyleModel",{border:Yv}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Qv=y.types.model("PanelVizModel",{type:y.types.string,conf:y.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}})),ys=y.types.model({id:y.types.string,title:y.types.string,description:y.types.string,layout:jv,queryIDs:y.types.array(y.types.string),viz:Qv,style:Rv,variables:y.types.optional(y.types.array(gl),[])}).views(e=>({getQuery(t){return y.getParentOfType(e,zt).queries.findByID(t)},get queryIDSet(){return new Set(e.queryIDs)},get queries(){return e.queryIDs.map(t=>y.getParentOfType(e,zt).queries.findByID(t)).filter(t=>!!t)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data.toJSON(),t),{})},get dataStuff(){return this.queries.map(t=>({data:t.data.toJSON(),len:t.data.length,state:t.state,error:t.error}))},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){return this.queries.map(t=>t.stateMessage).filter(t=>!!t)},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:t,title:n,description:i,queryIDs:s}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:n,layout:e.layout.json,queryIDs:[...s],variables:e.variables.map(o=>o.json),description:i}},get dataFieldOptions(){return e.queryIDs.length===0?[]:this.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(s=>({label:s,value:`${t.id}.${s}`,group:t.name}))}).flat()}})).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=y.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=y.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)},removeSelf(){y.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){y.getRoot(e).content.views.findByID(t).removePanelID(e.id),y.getRoot(e).content.views.findByID(n).appendPanelID(e.id),y.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])},refreshData(){e.queries.forEach(t=>t.fetchData())},downloadData(){y.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function bs(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:mr.name,conf:mr.createConfig()},style:{border:{enabled:!0}}}}const vs=y.types.model("PanelsModel",{list:y.types.optional(y.types.array(ys),[])}).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(s=>{const o=e.idMap.get(s);o?n.push(o):console.warn(`Panel is not found, id:${s}`)});const i=n.map(s=>({...s.layout.json,i:s.id}));return{panels:n,layouts:i}}})).views(e=>({editorOptions(t,n){const{panels:i}=e.panelsByIDs(n);i.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const s=i.map(l=>({label:l.title?l.title:v.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return s.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),s}})).actions(e=>({replace(t){e.list=y.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(i=>i.id===t);n!==-1&&e.list.splice(n,1)},duplicateByID(t){const n=e.list.find(s=>s.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const i=new Date().getTime().toString();return e.list.push({...n.json,id:i,layout:{...n.layout,y:1/0,moved:!1}}),i},replaceByIndex(t,n){e.list.splice(t,1,n)}}));var xs=(e=>(e.Use="use",e.Edit="edit",e))(xs||{}),J=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(J||{});const Uv={div:"Division",tabs:"Tabs",modal:"Modal"},Cs={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},Kv={div:"#ff4000",modal:"#000",tabs:"#ffad18"},Xv={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var yr=(e=>(e.Select="select",e.TreeSelect="tree-select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(yr||{});const ws=y.types.model("ViewModel_Division",{_name:y.types.literal(J.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),Zv=()=>ws.create({_name:J.Division}),br={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
470
- `)},Jv=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.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,i=y.getParent(e,2),s=y.getRoot(e);if(!t)return i.name;try{const o={filters:s.content.filters.values,context:s.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),i.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}})),_s=y.types.model("ViewModel_Modal",{_name:y.types.literal(J.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(Jv,br)}).views(e=>({get json(){const{_name:t,width:n,height:i,custom_modal_title:s}=e;return{_name:t,width:n,height:i,custom_modal_title:s.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Hv=()=>_s.create({_name:J.Modal,width:"90vw",height:"90vh"}),ex=y.types.model("ViewModel_Tabs_Tab",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:i,color:s}=e;return{id:t,name:n,color:s,view_id:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Ss=y.types.model("ViewModel_Tabs",{_name:y.types.literal(J.Modal),tabs:y.types.optional(y.types.array(ex),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:i,tabs:s,grow:o}=e;return{grow:o,tabs:s.map(l=>l.json),_name:t,variant:n,orientation:i}}})).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=y.cast(t)},addTab(){const t=we.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),tx=()=>Ss.create({_name:J.Modal,tabs:[]}),Ts=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[J.Division,J.Modal,J.Tabs]),config:y.types.union(ws,_s,Ss),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:i,config:s}=e;return{id:t,name:n,type:i,config:s.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case J.Division:e.config=Zv();break;case J.Modal:e.config=Hv();break;case J.Tabs:e.config=tx();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(i=>i!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})).actions(e=>({})),Ds=y.types.model("ViewsModel",{current:y.types.optional(y.types.array(Ts),[]),visibleViewIDs:y.types.array(y.types.string),idOfVIE:y.types.string}).views(e=>({get json(){return e.current.map(t=>Wt(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 isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},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))},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=y.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=>({replace(t){e.current.replace(t)},addANewView(t,n,i,s){e.current.push({id:t,name:n,type:i,config:s,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(i=>i.id===t);n!==-1&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},appendToVisibles(t){new Set(e.visibleViewIDs.map(i=>i)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=new Date().getTime().toString();e.addANewView(t,J.Division,J.Division,{_name:J.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(i=>i===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function vr(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(s=>{const{_name:o=s.type}=s.config;return{...s,config:{...s.config,_name:o},panelIDs:s.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}function ks(e,t,n,i){return e.reduce((s,o)=>(s[o[t]]=Cn(o[n],i),s),{})}const nx=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:Hi,queries:sa,sqlSnippets:la,views:Ds,panels:vs,mock_context:fl,origin:y.types.maybe(y.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!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=y.getSnapshot(v.get(e,t)).map(i=>v.pick(i,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!v.isEqual(n,v.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get viewsChanged(){const t="views.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!v.isEqual(v.get(e,t),v.get(e.origin,t))},get payloadForSQL(){const t=y.getParent(e).context.current,n=y.getParent(e).globalSQLSnippets,i={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...i,sql_snippets:ks(e.sqlSnippets.current,"key","value",i),global_sql_snippets:ks(n.list,"id","content",i)}},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:i})=>({id:n,data:i})).reduce((n,i)=>(n[i.id]=i.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,i=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}]}))),s=e.views.idMap,o=e.filters.current.filter(l=>v.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=s.get(u))==null?void 0:c.name)??u}})}));return i.concat(o)}})).actions(e=>({duplicatePanelByID(t,n){var s;const i=e.panels.duplicateByID(t);i&&((s=e.views.findByID(n))==null||s.appendPanelID(i))},removePanelByID(t,n){var i;e.panels.removeByID(t),(i=e.views.findByID(n))==null||i.removePanelID(t)},addANewPanel(t){var i;const n=new Date().getTime().toString();e.panels.append(bs(n)),(i=e.views.findByID(t))==null||i.appendPanelID(n)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:i,content:s}=t;if(!s)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:p,sqlSnippets:f,mock_context:h={}}}=s;e.id=n,e.name=i,e.version=o,y.applySnapshot(e.filters.current,l),y.applySnapshot(e.views.current,vr(u).current),y.applySnapshot(e.panels.list,c),y.applySnapshot(e.queries.current,p),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),zt=y.types.snapshotProcessor(nx,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(n=>v.pick(n,["id","key","type","sql"])));return v.defaults({},{queries:{current:t}},e)}});function rx(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function Is({id:e,name:t,dashboard_id:n,create_time:i,update_time:s,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:p,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return zt.create({id:e,name:t,dashboard_id:n,create_time:i,update_time:s,version:l,filters:ea(u),queries:{current:f},sqlSnippets:{current:h},mock_context:{current:g},views:vr(c),panels:{list:p}})}const ix=y.types.model({id:y.types.string,content:y.types.string,create_time:y.types.string,update_time:y.types.string,is_preset:y.types.boolean}),ax=y.types.model("GlobalSQLSnippetsModel",{list:y.types.optional(y.types.array(ix),[])}).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)}})),Ms=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:zt,content_id:y.types.string,datasources:dl,globalSQLSnippets:ax,context:ua,editor:hl}).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:i,name:s,group:o,content_id:l}=t;e.id=i,e.name=s,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function xr({id:e,name:t,group:n,content_id:i},s,o,l,u){return Ms.create({id:e,name:t,group:n,content_id:i,content:Is(s),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:u},editor:{}})}const Cr=m.createContext(null);function un(e){const t=m.useContext(Cr),n=X.useCreation(()=>e.configure(t||new $n),[e.configure]),i=X.usePrevious(n);return i&&i!==n&&i.dispose(),r(Cr.Provider,{value:n,children:e.children})}function $s(){return m.useContext(Cr)}const sx={viewPanelInFullScreen:v.noop,inFullScreen:!1},wr=m.createContext(sx),ox=({description:e,isDescriptionEmpty:t})=>t?null:r(a.Tooltip,{color:"white",label:r(an,{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:r(a.Box,{sx:{height:"16px",alignSelf:"center"},children:r(L.IconInfoCircle,{size:16,color:"gray"})})}),lx=T.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:i,...s},value:o,onChange:l})=>d(a.Box,{children:[r(a.Text,{children:" "}),r(a.Checkbox,{label:d(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[r(a.Box,{sx:{flexGrow:1},children:e}),r(ox,{description:n,isDescriptionEmpty:i})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...s,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),As=T.observer(({label:e,config:t,value:n=[null,null],onChange:i})=>{const s=Array.isArray(n)?n.map(c=>c?Y(c).toDate():null):[null,null],o=c=>{i(c.map(p=>p&&Y(p).format(t.inputFormat)))},l=t.getMinDate(s[0]),u=t.getMaxDate(s[0]);return r(To.DateRangePicker,{label:e,value:s,onChange:o,icon:r(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:l,maxDate:u,styles:{input:{borderColor:"#e9ecef"}},...t})}),ux=a.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":{flexGrow:1}}}})),zs=({errorMessage:e})=>e?r(a.Text,{color:"red",size:12,children:e}):r(a.Text,{color:"dimmed",size:12,children:"Not found"}),cx=({disabled:e,classNames:t,styles:n,unstyled:i,radius:s,style:o,label:l,value:u,onChange:c,options:p,errorMessage:f})=>{const{classes:h,cx:g}=ux({radius:s},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:i}),[b,_]=m.useState(!1),C=N=>{_(N)},S=b&&(u==null?void 0:u.length)>0,[I,$]=m.useState(""),q=m.useMemo(()=>{if(!I)return p;const N=I.toLowerCase(),P=z=>{var A;return((A=z.description)==null?void 0:A.toLowerCase().includes(N))||z.label.toLowerCase().includes(N)};return p.filter(P)},[I,p]);return d(a.Stack,{spacing:3,children:[d(a.Group,{position:"apart",children:[r(a.Text,{className:h.label,children:l}),S&&r(a.Tooltip,{label:`${u.length} selected`,children:r(a.Badge,{children:u.length})})]}),r(Pi,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:C,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>r(a.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:r(zs,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:N=>`${N.length} selected`,searchValue:I,onSearch:$,filterOption:!1,children:q.map(N=>r(Pi.Option,{children:r(a.Group,{noWrap:!0,children:d("div",{children:[r(a.Text,{size:"sm","data-role":"label",children:N.label}),N.description&&r(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:N.description})]})})},N.value))})]})},dx=T.observer(({label:e,config:t,value:n,onChange:i})=>{const s=U(),o=!!t.options_query_id,{state:l,error:u}=s.getDataStuffByID(t.options_query_id),c=l==="loading",p=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>i(g,!1);return r(cx,{label:e,options:t.options,style:{minWidth:"160px",width:p,maxWidth:f?p:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),px=m.forwardRef(({label:e,description:t,...n},i)=>r("div",{ref:i,...n,children:r(a.Group,{noWrap:!0,children:d("div",{children:[r(a.Text,{size:"sm","data-role":"label",children:e}),r(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),hx=T.observer(({label:e,config:t,value:n,onChange:i})=>{const s=U(),o=!!t.options_query_id,{state:l,error:u}=s.getDataStuffByID(t.options_query_id),c=l==="loading";return m.useEffect(()=>{var h;const{default_selection_count:p}=t;if(!p)return;const f=((h=t.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),i(f,!0)},[t.default_selection_count,t.options]),r(a.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:i,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:px})});function fx({label:e,config:t,value:n,onChange:i}){return r(a.TextInput,{label:e,value:n||"",onChange:s=>i(s.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const gx=({rotate:e,onClick:t})=>r("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:r("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"})}),mx=({expanded:e,isLeaf:t,value:n,onClick:i,...s})=>(n==="0-0-value"&&console.log(s),t?r("span",{style:{width:"14px",display:"inline-block"}}):r(gx,{rotate:e?"0":"-90",onClick:i,...s})),yx=({onClick:e})=>d("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:[r("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),r("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),r("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),r("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),bx=({onClick:e,...t})=>r(yx,{onClick:e,...t}),vx=a.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"}}}})),xx=({disabled:e,classNames:t,styles:n,unstyled:i,radius:s,style:o,label:l,value:u,onChange:c,treeData:p,errorMessage:f})=>{const{classes:h,cx:g}=vx({radius:s},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:i}),[b,_]=m.useState(!1),C=I=>{_(I)},S=b&&(u==null?void 0:u.length)>0;return d(a.Stack,{spacing:3,children:[d(a.Group,{position:"apart",children:[r(a.Text,{className:h.label,children:l}),S&&r(a.Tooltip,{label:`${u.length} selected`,children:r(a.Badge,{children:u.length})})]}),r(Oi,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:C,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>r(a.CloseButton,{}),switcherIcon:mx,treeIcon:bx,maxTagTextLength:10,value:u,treeData:p,notFoundContent:r(zs,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Oi.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:I=>`${I.length} selected`})]})},Cx=T.observer(({label:e,config:t,value:n,onChange:i})=>{const{treeData:s,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",p=!!t.options_query_id?o:!1;return r(xx,{disabled:p,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>i(f,!1),treeData:s,errorMessage:l,label:e})}),wx=T.observer(({filter:{type:e,config:t,key:n,...i},formFieldProps:s})=>{switch(e){case"select":return r(hx,{...i,...s,config:t});case"multi-select":return r(dx,{...i,...s,config:t});case"tree-select":return r(Cx,{...i,...s,config:t});case"text-input":return r(fx,{...i,...s,config:t});case"date-range":return r(As,{...i,...s,config:t});case"checkbox":return r(lx,{...i,...s,config:t});default:return null}}),Es=T.observer(m.forwardRef(({filter:e,...t},n)=>r("div",{className:"filter-root",ref:n,children:r(Le,{children:r(wx,{filter:e,formFieldProps:t})})}))),Ls=T.observer(function({view:t}){const n=U(),{control:i,handleSubmit:s,reset:o}=x.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=x.useWatch({control:i});m.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),m.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const u=n.filters.visibleInView(t.id),c=m.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),p=m.useMemo(()=>u.filter(g=>v.get(g,"config.required",!1)),[u]),f=m.useMemo(()=>p.length===0?!1:p.some(g=>!g.requiredAndPass(l[g.key])),[l,p]);if(u.length===0)return null;const h=(g,b)=>(_,C)=>{b(_),(g.should_auto_submit||C)&&n.filters.setValueByKey(g.key,_)};return r("form",{onSubmit:s(n.filters.setValues),children:d(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[r(a.Group,{align:"flex-start",children:u.map(g=>r(x.Controller,{name:g.key,control:i,render:({field:b})=>r(Es,{filter:g,value:b.value,onChange:h(g,b.onChange)})},g.id))}),!c&&r(a.Group,{sx:{alignSelf:"flex-end"},children:r(a.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),$1="";function _x(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Ps=T.observer(()=>{const{freezeLayout:e}=m.useContext(He),[t,n]=m.useState(!1),{panel:i}=Te();return m.useEffect(()=>{e(t)},[t]),_x(i.description)?null:d(B,{children:[r(a.Modal,{opened:t,onClose:()=>n(!1),title:i.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:r(an,{value:i.description,styles:{root:{border:"none"},content:{padding:0}}})}),r(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:r(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(s=>!s),sx:{verticalAlign:"baseline",cursor:"pointer"},children:r(D.InfoCircle,{size:20})})})]})}),Sx=T.observer(({view:e})=>{const t=de(),n=U(),i=Ve.useModals(),{panel:s}=Te(),{id:o}=s,{inEditMode:l}=m.useContext(He),{viewPanelInFullScreen:u,inFullScreen:c}=m.useContext(wr),p=()=>{n.duplicatePanelByID(o,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},h=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),g=m.useCallback(()=>{u(o)},[o,u]),b=!c&&e.type!==J.Modal;return r(B,{children:r(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:d(a.Menu,{withinPortal:!0,children:[r(a.Menu.Target,{children:r(a.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),d(a.Menu.Dropdown,{children:[r(a.Menu.Item,{onClick:s.refreshData,icon:r(D.Refresh,{size:14}),children:"Refresh"}),r(a.Menu.Item,{onClick:s.downloadData,icon:r(D.Download,{size:14}),children:"Download Data"}),b&&r(a.Menu.Item,{onClick:g,icon:r(D.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&d(B,{children:[r(a.Divider,{label:"Edit",labelPosition:"center"}),r(a.Menu.Item,{onClick:f,icon:r(D.Settings,{size:14}),children:"Settings"}),r(a.Menu.Item,{onClick:p,icon:r(D.Copy,{size:14}),children:"Duplicate"}),r(a.Menu.Item,{color:"red",onClick:h,icon:r(D.Trash,{size:14}),children:"Delete"})]})]})]})})})}),A1="",Tx=T.observer(function(){const{panel:t}=Te(),{title:n}=t;return n?r(a.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:r(a.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null}),Dx=T.observer(({panel:e})=>d(a.Stack,{children:[e.queryErrors.map((t,n)=>r(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),e.queryStateMessages.map((t,n)=>r(a.Text,{color:"gray",align:"center",children:t},`${n}-${t}`))]}));var Os=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Os||{}),cn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(cn||{});class kx{constructor(t){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=t.getRequired(ve.instanceScope.panelModel),this.vizInstance=t.getRequired(ve.instanceScope.vizInstance),this.operationManager=t.getRequired(ve.instanceScope.operationManager),this.triggerManager=t.getRequired(ve.instanceScope.triggerManager),this.vizManager=t.getRequired(ve.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 Vs(e){const{panel:t}=Te();return m.useCallback(n=>{const i=n.getRequired(ve.vizManager),s=i.resolveComponent(e.viz.type);return n.createScoped().provideFactory(ve.instanceScope.vizInstance,()=>i.getOrCreateInstance(e)).provideFactory(ve.instanceScope.interactionManager,o=>{const l=o.getRequired(ve.instanceScope.vizInstance);return new hr(l,s,ln)}).provideFactory(ve.instanceScope.operationManager,o=>o.getRequired(ve.instanceScope.interactionManager).operationManager).provideFactory(ve.instanceScope.triggerManager,o=>o.getRequired(ve.instanceScope.interactionManager).triggerManager).provideValue(ve.instanceScope.panelModel,t).provideFactory(ve.instanceScope.migrator,o=>new kx(o))},[e.viz.type,e.viz.conf])}function Bs(e){const[t,n]=m.useState(!1),i=$s().getRequired(ve.instanceScope.migrator);return X.useAsyncEffect(async()=>{const s=i.status===cn.notStarted;n(i.status===cn.done),i.status===cn.notStarted&&i.runMigration().then(o=>{o===Os.migrated&&s&&(e==null||e())}).finally(()=>{n(!0)})},[i]),t}function qs(e,t){const n=$s().getRequired(ve.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,i=>{e(i)})),[e,t.viz.type]),n}function Ix({setVizConf:e,...t}){const{panel:n}=t,i=qs(e,n),s=Bs(()=>{qt.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return X.useAsyncEffect(async()=>{await i.instanceData.setItem(null,n.viz.conf)},[i,n.viz.type]),s?r(wl,{...t}):r(a.Text,{children:"Checking update..."})}function Mx(e){const{panel:t,setVizConf:n}=e;qs(n,t);const{inEditMode:i}=m.useContext(He);return Bs(()=>{i&&qt.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?r(Cl,{...e}):r(a.Text,{children:"Checking update"})}const z1="";function $x(e,t){const{vizManager:n}=m.useContext(je),{panel:{viz:i,title:s,id:o,description:l,queryIDs:u,variables:c}}=Te(),p={title:s,id:o,description:l,queryIDs:u,viz:i,layout:t},f=Vs(p);try{return n.resolveComponent(i.type),r(un,{configure:f,children:r(Mx,{setVizConf:i.setConf,panel:p,data:e,variables:c,vizManager:n})})}catch(h){return console.info(v.get(h,"message")),null}}const Ax=T.observer(function({data:t}){const{ref:n,width:i,height:s}=we.useElementSize(),o=$x(t,{w:i,h:s});return r("div",{className:"viz-root",ref:n,children:r(Le,{children:o})})}),Ns=T.observer(({panel:e,height:t})=>d(a.Flex,{direction:"column",sx:{height:t,position:"relative",width:"100%"},children:[r(a.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&r(Dx,{panel:e}),e.canRenderViz&&r(Ax,{viz:e.viz,data:e.data})]})),zx={border:"1px solid #e9ecef"},Ex={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function Lx(e,t){return e.style.border.enabled?zx:t?Ex:{border:"1px dashed transparent"}}const dn=T.observer(function({panel:t,view:n}){const{inEditMode:i}=m.useContext(He),s=t.title?"calc(100% - 25px - 5px)":"100%",o=Lx(t,i);return r(En,{value:{panel:t,data:t.data,loading:t.dataLoading,errors:t.queryErrors},children:d(a.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[r(a.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:r(Ps,{})}),r(Sx,{view:n}),r(Tx,{}),r(Ns,{panel:t,height:s})]})})}),E1="",Px=m.forwardRef(({h:e},t)=>r(a.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:r(D.ArrowsMove,{size:16})})),Ox=m.forwardRef(({handleAxis:e,...t},n)=>r(a.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:r(D.ChevronDownRight,{size:16})})),Vx=Nt.WidthProvider(Nt),Bx=T.observer(({view:e,className:t="layout"})=>{const n=U(),{panels:i,layouts:s}=n.panels.panelsByIDs(e.panelIDs),o=m.useCallback(u=>{u.forEach(({i:c,...p})=>{const f=n.panels.findByID(c);f&&f.layout.set(p)})},[n]),l=(u,c,p,f)=>{p.h<30&&(p.h=30,f.h=30),p.w<4&&(p.w=4,f.w=4)};return r(Vx,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:s,draggableHandle:".react-grid-customDragHandle",resizeHandle:r(Ox,{}),onResize:l,children:i.map((u,c)=>d("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[r(Px,{h:u.layout.h}),r(dn,{view:e,panel:u})]},u.id))})}),qx=Nt.WidthProvider(Nt),Nx=T.observer(function({view:t,className:n="layout"}){const{panels:i,layouts:s}=U().panels.panelsByIDs(t.panelIDs);return r(qx,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:s,children:i.map(o=>r("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:r(dn,{view:t,panel:o})},o.id))})}),Gx=T.observer(({children:e})=>r(a.Box,{pt:10,pb:100,children:e})),Fx=T.observer(({children:e,view:t})=>{const n=t.config;return r(a.Modal,{size:n.width,overflow:"inside",opened:!0,onClose:v.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),Wx=({variant:e,orientation:t})=>{const n={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},jx=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Yx=T.observer(({children:e,view:t})=>{const n=Ve.useModals(),i=U(),s=m.useMemo(()=>i.views.options.filter(c=>c.type===J.Division),[t.id,i.views.options]),o=t.config,l=c=>n.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(c)},confirmProps:{color:"red"},zIndex:320}),u=o.tabs.length===0;return d(a.Box,{className:"preview-view-tabs",children:[d(a.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:Wx(o),children:[d(a.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>r(a.Tabs.Tab,{value:c.id,sx:jx(c),children:c.name??c.id},c.id)),r(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:r(D.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,p)=>{const f=i.views.findByID(c.view_id);return d(a.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[d(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[r(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),d(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[r(a.TextInput,{label:"Tab Name",value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),r(a.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:s}),r(a.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&d(a.Button,{mt:20,variant:"gradient",leftIcon:r(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>i.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),r(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(p),disabled:u,leftIcon:r(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&r(pn,{view:f})]},c.id)})]}),e]})}),Rx=T.observer(({view:e,children:t})=>{switch(e.type){case J.Modal:return r(Fx,{view:e,children:t});case J.Tabs:return r(Yx,{view:e,children:t});case J.Division:default:return r(Gx,{children:t})}}),Gs=T.observer(function({view:t}){return r(wr.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:r(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:r(Rx,{view:t,children:d(a.Box,{sx:{position:"relative"},children:[r(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:r(Ls,{view:t})}),r(Bx,{view:t})]})})})})}),Qx={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Ux=T.observer(function({view:t,panel:n,exitFullScreen:i}){return r(a.Modal,{opened:!0,fullScreen:!0,onClose:i,title:r(a.Button,{color:"blue",size:"xs",onClick:i,leftIcon:r(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:Qx,children:r(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:r(dn,{view:t,panel:n})})})});function Kx(e,t,n){const{panels:i}=U(),s=e.id==="Main",[o,l]=m.useState(()=>s&&i.findByID(t)?t:null),u=m.useCallback(h=>{l(h),s&&n(h)},[s,n]),c=m.useCallback(()=>{l(null),s&&n("")},[s,n]),p=o?i.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!p,fullScreenPanel:p}}const Xx=T.observer(({children:e})=>r(a.Box,{children:e})),Zx=T.observer(({children:e,view:t})=>{const n=U(),i=t.config,s=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id);return r(a.Modal,{size:i.width,centered:!0,overflow:"inside",opened:s,onClose:o,withCloseButton:!1,title:i.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:i.height,overflow:"auto"}},transitionDuration:0,children:e})}),Jx=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Hx=T.observer(({children:e,view:t})=>{const n=U(),i=t.config;return d(a.Box,{className:"render-view-tabs",children:[d(a.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:{panel:{padding:i.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[r(a.Tabs.List,{grow:i.grow,children:i.tabs.map(s=>r(a.Tabs.Tab,{value:s.id,sx:Jx(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),i.tabs.map(s=>{const o=n.views.findByID(s.view_id);return o?r(a.Tabs.Panel,{value:s.id,children:r(pn,{view:o})},s.id):null})]}),e]})}),e0=T.observer(({view:e,children:t})=>{switch(e.type){case J.Modal:return r(Zx,{view:e,children:t});case J.Tabs:return r(Hx,{view:e,children:t});case J.Division:default:return r(Xx,{children:t})}}),pn=T.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:i}=ka(),{viewPanelInFullScreen:s,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Kx(t,n,i);return r(wr.Provider,{value:{viewPanelInFullScreen:s,inFullScreen:l},children:d(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&r(Ux,{view:t,panel:u,exitFullScreen:o}),r(e0,{view:t,children:d(a.Box,{sx:{position:"relative"},children:[!l&&r(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:r(Ls,{view:t})}),!l&&r(Nx,{view:t})]})})]})})});function _r(e){return m.useCallback(t=>t.provideValue(ve.pluginManager,e.pluginManager).provideValue(ve.vizManager,e.vizManager).provideValue(ve.colorManager,e.colorManager),[])}const t0=T.observer(({headerMenuItems:e=null})=>{const t=de(),n=U(),i=()=>{const s=JSON.stringify(n.json,null,2),o=`${t.name}__${n.name}`;Ho(o,s)};return d(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[r(a.Menu.Target,{children:r(a.ActionIcon,{variant:"light",color:"blue",children:r(L.IconMenu2,{size:14})})}),d(a.Menu.Dropdown,{children:[r(a.Menu.Item,{icon:r(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),r(a.Menu.Item,{icon:r(L.IconCode,{size:14}),onClick:i,children:"Download Schema"}),e]})]})}),n0=T.observer(({saveDashboardChanges:e})=>{const t=Ve.useModals(),n=U(),i=()=>{t.openConfirmModal({title:d(a.Group,{position:"left",children:[r(L.IconAlertTriangle,{size:18,color:"red"}),r(a.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})},s=n.changed;return d(a.Group,{spacing:0,children:[r(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:r(L.IconDeviceFloppy,{size:18}),onClick:e,disabled:!s,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),d(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!s,children:[r(a.Menu.Target,{children:r(a.ActionIcon,{variant:"default",disabled:!s,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:r(L.IconCaretDown,{size:18})})}),r(a.Menu.Dropdown,{children:r(a.Menu.Item,{icon:r(L.IconRecycle,{size:14,color:"red"}),disabled:!s,onClick:i,children:"Revert Changes"})})]})]})}),r0=T.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:n})=>{const i=Do.useNavigate(),s=de(),o=()=>{i(`/dashboard/${s.id}`)},l=Ve.useModals(),u=()=>{l.openConfirmModal({title:d(a.Group,{position:"left",children:[r(L.IconAlertTriangle,{size:18,color:"red"}),r(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=s.content.changed;return r(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:d(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[d(a.Group,{children:[r(a.Button,{size:"xs",color:c?"red":"green",leftIcon:r(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:d(a.Group,{spacing:4,children:["End Editing",r(a.Text,{td:"underline",children:s.name})]})}),r(n0,{saveDashboardChanges:e})]}),d(a.Group,{position:"right",sx:{flexGrow:1},children:[t,r(t0,{headerMenuItems:n})]})]})})}),i0={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},a0=T.observer(()=>{const e=U();return r(a.Box,{sx:i0,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:d(a.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[r(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:r(L.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"}),r(a.Box,{}),r(a.Box,{})]})})}),s0=T.observer(e=>d(B,{children:[r(r0,{...e}),r(a0,{})]})),L1="",P1="";function o0(e,t,n){const i=[];return e.filter(s=>"__INTERACTIONS"in s.viz.conf).forEach((s,o)=>{const l=t[s.id];l.data.interactions=v.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:p}=s.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:b}=h,{config:_}=b;switch(g){case"builtin:op:open-link":let C=_.urlTemplate.substring(0,100);_.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:_.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":i.push({id:`OPERATION--${f}`,source:s.id,target:_.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(_.dictionary).map(S=>({key:S,label:n[S]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:_.filter_keys.map(S=>({key:S,label:n[S]}))});return;default:return}})}),i}function l0(e,t){const n=e.filters.keyLabelMap;return{edges:o0(e.panels.list,t,n),edgeNodes:[]}}function Fs(e,t,n){return e*t+e*n}function u0(e,t,n){return e*t+(e-1)*n}const hn=25,Sr=40,Ws=25,Tr=350,c0=150,d0=150,js=150,Ys=300,fn=40,Rs=25,p0=300;function h0(e,t){const n=v.keyBy(t,s=>s.id),i=[];return e.current.forEach((s,o)=>{s.panelIDs.forEach((l,u)=>{const c=Fs(u,fn,Rs)+Sr,p=n[l];if(!p){i.push({id:l,_node_type:"panel",parentNode:s.id,data:{label:`!: ${l}`},position:{x:hn,y:c},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:Ys,height:fn}});return}const f=p.title.trim()?`${p.title}`:p.viz.type;i.push({id:p.id,_node_type:"panel",parentNode:s.id,data:{label:f},position:{x:hn,y:c},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:Ys,height:fn}})})}),i}const f0={[J.Division]:"Div",[J.Modal]:"Modal",[J.Tabs]:"Tabs"},g0=Cs;function m0(e){return e.current.map((n,i)=>{const s=u0(n.panelIDs.length,fn,Rs)+Sr+Ws;let o=[];return n.type===J.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:`${f0[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,className:"light",style:{backgroundColor:g0[n.type],width:Tr,height:s}}})}function y0(e){const t=v.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==J.Tabs||n._tab_view_ids.forEach(i=>{t[i].parentNode=n.id})})}function b0(e){const t=m0(e.views);y0(t);const n=h0(e.views,e.panels.list);return[...t,...n]}function v0({nodeMap:e,nodes:t,edges:n}){t.forEach(i=>{i._node_type!=="view-root"||i._view_type!==J.Tabs||(i.sourcePosition=_e.Position.Bottom,i.style.width=Tr+hn*2,i.style.height=Ws+i._tab_view_ids.reduce((s,o)=>{const l=e[o];l.position.y=s,l.position.x=hn;const u=l.style.height;return s+u+20},Sr))})}function x0({nodeMap:e,nodes:t,edges:n}){n.filter(i=>i.label==="Open View").forEach(i=>{const s=e[i.source],o=e[i.target];if(!s||!o||!s.parentNode)return;const l=e[s.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((i,s)=>i._node_type==="view-root"&&s._node_type==="view-root"?i._view_level-s._view_level:i._node_type!=="view-root"&&s._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function C0({nodeMap:e,nodes:t,edges:n}){const i={};n.forEach(s=>{if(s.label!=="Open View")return;const o=e[s.source],l=e[s.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,p=Number(v.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+p0,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,b=v.get(i,g,0);l.position.y=b,i[g]=b+p+js}})}function w0({nodeMap:e,nodes:t,edges:n}){const i=new Set,s=new Set;n.forEach(l=>{i.add(l.source),s.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!i.has(l.id)&&!s.has(l.id)).forEach((l,u)=>{l.position.x=Fs(u,Tr,d0),l.position.y=0-c0-js})}function _0({nodeMap:e,nodes:t,edges:n}){const i={nodeMap:e,nodes:t,edges:n};return w0(i),x0(i),v0(i),C0(i),{nodes:t,edges:n}}function S0(e){const t=b0(e),n=v.keyBy(t,c=>c.id),{edges:i,edgeNodes:s}=l0(e,n),o=[...t,...s],l=v.keyBy(o,c=>c.id),u={edges:v.uniqBy(i,c=>c.id),nodes:o,nodeMap:l};return _0(u)}const O1="",Dr={"builtin:op:open-link":r(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:r(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":r(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:r(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":r(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:r(L.IconCircleOff,{size:14})})};function T0(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Dr[n.schemaRef],text:d(a.Group,{spacing:4,children:[r(a.Text,{children:"Open: "}),r(a.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:i,label:s})=>{t.push({key:n.schemaRef+i,icon:Dr[n.schemaRef],text:r(a.Group,{spacing:4,children:d(a.Text,{children:["Set Filter: ",s]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:i,label:s})=>{t.push({key:n.schemaRef+i,icon:Dr[n.schemaRef],text:r(a.Group,{spacing:4,children:d(a.Text,{children:["Clear Filter: ",s]})})})});return}}),t}const D0=m.memo(({data:e,isConnectable:t,sourcePosition:n=_e.Position.Right,targetPosition:i=_e.Position.Left,...s})=>{const o=m.useMemo(()=>T0(e.interactions),[e.interactions]);return d(B,{children:[r(_e.Handle,{type:"target",position:i,isConnectable:t}),r(a.Box,{sx:{position:"absolute",top:0,right:0},children:r(D.ChevronsUpRight,{size:12})}),d(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[r(a.HoverCard.Target,{children:r(a.Text,{children:e.label})}),r(a.HoverCard.Dropdown,{children:r(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>r(a.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),r(_e.Handle,{type:"source",position:n,isConnectable:t})]})}),V1="",k0={interaction:D0},I0=T.observer(()=>{const e=U(),{edges:t,nodes:n}=S0(e);return d(_e,{nodes:n,edges:t,onNodesChange:v.noop,onEdgesChange:v.noop,onConnect:v.noop,className:"interactions-viewer",fitView:!0,nodeTypes:k0,children:[r(_e.MiniMap,{}),r(_e.Controls,{}),r(_e.Background,{})]})}),M0=T.observer(({opened:e,close:t})=>{const{freezeLayout:n}=m.useContext(He);return m.useEffect(()=>{n(e)},[e]),r(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:r(I0,{})})}),$0={"> 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 A0({onClick:e,name:t,active:n,openSettings:i}){return d(a.Box,{sx:{position:"relative"},children:[r(a.UnstyledButton,{sx:s=>({display:"block",width:"100%",padding:s.spacing.xs,borderRadius:0,position:"relative",color:s.black,"&:hover":{backgroundColor:s.colors.gray[0]},backgroundColor:n?s.colors.gray[2]:"transparent"}),children:r(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:r(a.Text,{size:"sm",children:t})})}),n&&r(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:r(a.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:r(L.IconAdjustments,{size:16})})})]})}const z0=T.observer(()=>{const e=de(),t=U(),n=m.useCallback(s=>()=>t.views.setIDOfVIE(s),[t]),i=s=>{e.editor.open(["_VIEWS_",s])};return d(a.Box,{sx:{position:"relative"},children:[t.views.options.map(s=>r(A0,{active:t.views.idOfVIE===s.value,name:s.label,onClick:n(s.value),openSettings:()=>i(s.value)},s.value)),r(a.Divider,{variant:"dashed"}),r(a.Button,{variant:"subtle",rightIcon:r(L.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"})]})}),E0=T.observer(()=>{const e=de(),t=U(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},i=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[s,o]=m.useState(!1),l=()=>o(!0),u=()=>o(!1);return d(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[d(a.Navbar.Section,{children:[d(a.Group,{grow:!0,spacing:0,sx:{...$0,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[r(a.Tooltip,{label:"Filters",withinPortal:!0,children:r(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:r(L.IconFilter,{size:20})})}),r(a.Tooltip,{label:"Queries",withinPortal:!0,children:r(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:r(L.IconDatabase,{size:20})})}),r(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:r(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:r(L.IconLink,{size:20})})})]}),r(M0,{opened:s,close:u})]}),r(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:r(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),r(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:r(z0,{})}),r(a.Navbar.Section,{children:r(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:r(a.Button,{size:"xs",leftIcon:r(L.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),L0=T.observer(function({config:t}){return d(B,{children:[r(a.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),r(tr,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),P0=[{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"}],O0=T.observer(function({config:t}){return d(B,{children:[d(a.Group,{children:[r(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),r(a.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),r(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),r(a.Select,{data:P0,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),r(As,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),r(a.NumberInput,{label:"Max Days",description:d(a.Group,{position:"apart",children:[r(a.Text,{children:"Set 0 to disable."}),d(a.Group,{spacing:4,children:[r(a.Text,{children:"This feature requires"}),r(a.Text,{color:"blue",children:"Clearable"}),r(a.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),kr=T.observer(({value:e,onChange:t})=>{const n=U(),i=m.useMemo(()=>n.queries.options,[n.queries.current]),s=i.length===0;return r(a.Select,{label:"Pick a query",data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:s,error:s?"You need to add a query in Data Settings":void 0})}),V0=`
469
+ `}},show_in_legend:!0}))}function rb(e,t,n,i){const s=O(t.data_key),o=t.name,l=n.map(u=>{const c=v.sumBy(i[u],s.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function ib(e,t,n,i){const l={barMinWidth:5,barMaxWidth:20};return[Jy(e,n,i),eb(e,n,i,l),...nb(e,n,i,l),rb(e,t,n,i)]}function ab(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Qa(n.formatter)},axisLine:{show:!1}}]}function sb(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function dr(e){return e==1||e==2?1:dr(e-2)+dr(e-1)}const ob=Array.from(new Array(20),(e,t)=>dr(t+1));function cs(e){return e<=1?e:ob.findIndex(t=>e<=t)-1}function lb(e,t){const{x_axis:n,deviation:i}=e,s=O(n.data_key),o=O(i.data_keys.estimated_value),l=O(i.data_keys.actual_value);return t[s.queryID].map(u=>{const c=cs(u[o.columnKey]),p=cs(u[l.columnKey]),f=c-p;return{...u,level:{estimated:c,actual:p,diff:f}}})}function ub(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function cb(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:ub(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const db={tooltip:{trigger:"axis"}};function pb(e,t){const{deviation:n,metrics:i}=e,s=i.find(l=>l.data_key===t);if(s)return s;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function hb(e,t,n){const i=lb(e,n),s=O(e.x_axis.data_key),o=v.uniqBy(n[s.queryID],s.columnKey).map(f=>f[s.columnKey]),l=v.groupBy(i,s.columnKey),u=pb(e,t),c=ib(e,u,o,l),p={xAxis:ab(e,o),yAxis:sb(u),series:c,grid:Zy(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:cb(c)};return v.defaultsDeep({},p,db)}const fb={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},gb=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:i,metrics:s}=e,o=m.useMemo(()=>{const l=s.map(u=>({label:u.name,value:u.data_key}));return l.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),l},[i,s]);return d(a.Group,{spacing:1,children:[r(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),r(a.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:fb})]})},mb={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function yb(){return d(a.HoverCard,{width:400,shadow:"md",children:[r(a.HoverCard.Target,{children:r(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:r(L.IconInfoCircle,{size:14}),children:"指标说明"})}),r(a.HoverCard.Dropdown,{children:r(a.Table,{fontSize:14,sx:mb,children:d("tbody",{children:[d("tr",{children:[r("th",{children:"估算偏差"}),r("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),d("tr",{children:[r("th",{children:"准确估算比例"}),r("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function bb(e){return d(a.Group,{position:"apart",children:[r(yb,{}),r(gb,{...e})]})}oe.use([ce.BarChart,ce.LineChart,ce.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ae.CanvasRenderer,G.VisualMapComponent]);function vb({conf:e,data:t,width:n,height:i,metricKey:s}){const o=m.useMemo(()=>hb(e,s,t),[e,t,s]);return r(ze,{echarts:oe,option:o,style:{width:n,height:i},notMerge:!0,theme:"merico-light"})}function xb({context:e}){const{value:t}=W(e.instanceData,"config"),n=m.useMemo(()=>v.defaults({},t,cr),[t]),i=e.data,{width:s,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:p}=u.data_keys,[f,h]=m.useState(p);if(m.useEffect(()=>{h(_=>_||p)},[p]),!l.data_key||!c||!p||!s||!o)return null;const g=Math.max(s,300),b=Math.max(o,370);return d(a.Box,{sx:{overflow:"hidden",height:b,width:g},children:[r(bb,{conf:n,metricKey:f,setMetricKey:h}),r(vb,{width:g,height:b-30,data:i,conf:n,metricKey:f})]})}function Cb({control:e,watch:t}){return t(["deviation"]),d(a.Stack,{children:[r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:"deviation.name",control:e,render:({field:n})=>r(a.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>r(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>r(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const wb=({control:e,index:t,remove:n})=>d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:`metrics.${t}.name`,control:e,render:({field:i})=>r(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(x.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:i})=>r(j,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(a.Divider,{mb:-10,mt:10,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),_b=({control:e,watch:t})=>{const{fields:n,append:i,remove:s}=x.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[p,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),d(B,{children:[d(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(D.InfoCircle,{size:14,color:"#888"}),r(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),r(a.Divider,{variant:"dashed",my:10}),d(a.Tabs,{value:p,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[l.map((h,g)=>r(a.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),r(a.Tabs.Tab,{onClick:u,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>r(a.Tabs.Panel,{value:h.id,children:r(wb,{control:e,index:g,remove:s},h.id)},h.id))]})]})};function Sb({control:e,watch:t}){return t(["x_axis"]),d(a.Stack,{children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>r(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"x_axis.name",control:e,render:({field:n})=>r(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),r(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),d(a.Group,{grow:!0,noWrap:!0,children:[r(x.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>r(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:r(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(x.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>r(Xa,{...n})})]})]})}function Tb({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,cr),[t]),{control:s,handleSubmit:o,watch:l,getValues:u,reset:c}=x.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l([]);const p=u(),f=m.useMemo(()=>!v.isEqual(p,i),[p,i]);return r(a.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Merico Estimation Chart Config"}),r(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),r(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),r(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),r(a.Tabs.Panel,{value:"X Axis",children:r(Sb,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Deviation",children:r(Cb,{control:s,watch:l})}),r(a.Tabs.Panel,{value:"Additional Metrics",children:r(_b,{control:s,watch:l})})]})]})})}function Db(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:s,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...s,data_key:i(s.data_key)},deviation:{...o,data_keys:{estimated_value:i(o.data_keys.estimated_value),actual_value:i(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:i(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class kb extends me{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:s}=n;return{...n,version:2,config:Db(s,i)}})}}const Ib={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new kb,name:"mericoEstimationChart",viewRender:xb,configRender:Tb,createConfig:()=>({version:2,config:cr})},Mb=[{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"})),$b=[_l,Sl,kl,Dl,Tl,Il],ds=()=>({id:"dashboard",version:An,manifest:{viz:[mr,Hg,Im,$f,Cm,Ah,Xy,ql,rc,hp,Fp,cy,Ch,jd,Gg,Kh,Tf,Om,Ib,yc],color:[...Mb,...$b]}}),At=new zl,ve={pluginManager:Qe("pluginManager"),vizManager:Qe("vizManager"),colorManager:Qe("colorManager"),instanceScope:{panelModel:Qe("panelModel"),vizInstance:Qe("vizInstance"),interactionManager:Qe("interactionManager"),migrator:Qe("migrator"),operationManager:Qe("operationManager"),triggerManager:Qe("triggerManager")}},pr=()=>{try{At.install(ds())}catch{}const e=new xl(At),t=new Al(At);return{pluginManager:At,vizManager:e,colorManager:t}},je=m.createContext(pr());try{At.install(ds())}catch{}function Ab(e,t){const{value:n,set:i}=W(e.operation.operationData,"config"),[s,o]=m.useState(v.defaults({},n,t)),l=async()=>{await i(s)};return m.useEffect(()=>{o(v.defaults({},n,t))},[n]),{config:s,setConfig:o,commit:l}}function zb(e){const{config:t,setConfig:n,commit:i}=Ab(e,{urlTemplate:"",openInNewTab:!0});async function s(){await i()}async function o(u){n({...t,openInNewTab:u}),await i()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return d(a.Stack,{children:[r(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:s}),r(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Eb(e,t){const{urlTemplate:n,openInNewTab:i}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:i,payload:e}}))}class Lb extends me{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Pb={displayName:"Open Link",id:"builtin:op:open-link",configRender:zb,run:Eb,migrator:new Lb,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Ob(e){const{value:t,set:n}=W(e.operationData,"config"),i=s=>void n({template:s});return[(t==null?void 0:t.template)||"",i]}function Vb(e){const[t,n]=Ob(e.operation);return r(a.TextInput,{defaultValue:t,onBlur:i=>n(i.currentTarget.value),label:"console.log"})}async function Bb(e,t){const n=await t.operationData.getItem("config"),i=v.template(n.template||"");console.log("run with payload",e),console.log(i(e))}const qb={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Vb,run:Bb},Nb=T.observer(e=>{const t=U(),{value:n,set:i}=W(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const s=(n==null?void 0:n.viewID)||"",o=l=>void i({viewID:l});return r(a.Select,{defaultValue:s,value:s,onChange:o,label:"View",data:t.views.options})});async function Gb(e,t){const i=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const Fb={displayName:"Open View",id:"builtin:op:open_view",configRender:Nb,run:Gb},Wb={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},jb=({value:e="",onChange:t})=>{const[n,i]=m.useState(e);m.useEffect(()=>{i(e)},[e]);const s=()=>{t(n)};return r(a.TextInput,{size:"xs",label:"",value:n,onChange:o=>i(o.currentTarget.value),sx:{flexGrow:1},rightSection:r(a.ActionIcon,{color:"green",size:"xs",onClick:s,disabled:n===e,children:r(L.IconDeviceFloppy,{})})})},Yb={dictionary:{}},Rb=T.observer(e=>{const t=U(),{value:n=Yb,set:i}=W(e.operation.operationData,"config"),{dictionary:s={}}=n;console.log({value:{...n},dictionary:{...s},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...s};delete c[l],i({dictionary:c});return}i({dictionary:{...s,[l]:u}})};return d(a.Table,{sx:Wb,children:[r("thead",{children:d("tr",{children:[r("th",{children:"Set filter"}),r("th",{children:"with"})]})}),r("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in s;return d("tr",{"data-affected":u,children:[r("td",{children:l.label}),r("td",{children:r(jb,{value:s[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function Qb(e,t){const i=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:e}}))}const Ub={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Rb,run:Qb},Kb={filter_keys:[]},Xb=T.observer(e=>{const t=U(),{value:n=Kb,set:i}=W(e.operation.operationData,"config"),{filter_keys:s=[]}=n,o=u=>{i({filter_keys:[...u]})},l=m.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return r(a.Stack,{spacing:10,children:r(a.MultiSelect,{label:"Select Filters to Clear",data:l,value:s,onChange:o})})});async function Zb(e,t){const i=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:e}}))}const on=[qb,Pb,Fb,Ub,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Xb,run:Zb}];class Jb{constructor(t,n=on){V(this,"attachments");this.operations=n;const i=async s=>{const{id:o,schemaRef:l}=await s.getItem(null);return{id:o,schemaRef:l,operationData:new pt(s,"data")}};this.attachments=new Mn(t,"__OPERATIONS",i)}async runOperation(t,n){const i=await this.attachments.getInstance(t);if(!i){console.warn(`Operation '${t}' is not defined`);return}const s=this.tryGetSchema(i.schemaRef);if(!s){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await s.run(n,i)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(s)});return(await Promise.all(n)).some(i=>i)}async runMigration(){const n=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(s)&&await l.migrate(s)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const s=await this.attachments.getInstance(t);return!s||s.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):s}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}class hr{constructor(t,n,i){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new Jb(t,i),this.triggerManager=new lu(t,n);const s=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new Mn(t,"__INTERACTIONS",s)}async addInteraction(t,n){const i=t.id,s=n.id,o=`[${i}]:[${s}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:s})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:i,operationRef:s}=n;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(s)<=1&&await this.operationManager.removeOperation(s),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(i=>i.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(i=>i.triggerRef===t).length}async runInteraction(t,n){const s=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(s.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const Ye=({vizManager:e,instance:t})=>X.useCreation(()=>new hr(t,e.resolveComponent(t.type),on),[t,e]),ps={left:"flex-start",center:"center",right:"flex-end"},Hb=({header:e,cx:t})=>{const n=v.get(e.column.columnDef.meta,"align","left");return d(a.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:ps[n]},children:[e.isPlaceholder?null:Be.flexRender(e.column.columnDef.header,e.getContext()),r(ev,{direction:e.column.getIsSorted()})]})},ev=({direction:e})=>{switch(e){case"asc":return r(L.IconArrowUp,{size:16});case"desc":return r(L.IconArrowDown,{size:"1em"});default:return null}},fr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:iv,configRender:nv,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},tv={column:""};function hs(e,t){const{value:n}=W(e.instanceData,"config"),i={columnsFromConfig:[],columnsFromData:[]};if(n&&(i.columnsFromConfig=n.columns.map((s,o)=>({label:s.label,value:o.toString()}))),!t)return i;if(n!=null&&n.id_field){const s=kt(t,n.id_field);(s==null?void 0:s.length)>0&&(i.columnsFromData=Object.keys(s[0]).map(o=>({label:o,value:o})))}return i}function nv(e){const{columnsFromConfig:t,columnsFromData:n}=hs(e.instance,e.sampleData),i=t.length>0?t:n,{value:s,set:o}=W(e.trigger.triggerData,"config"),{column:l}=v.defaults({},s,tv),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return r(a.Select,{clearable:!1,data:i,label:"Choose a column",value:l.toString(),onChange:u})}function rv(e,t){return e?v.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function iv(e){const{columnsFromConfig:t}=hs(e.instance),{value:n}=W(e.trigger.triggerData,"config");return r(a.Text,{children:rv(n,t)})}const av=a.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),sv={tableLayout:"fixed","th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}};function fs(e,t,n){return Math.min(Math.max(e,t),n)}class ov{constructor(t){this.steps=t;const n=[],i=new Set;for(const s of t)i.has(s.to)||(n.push(s),i.add(s.to));if(n.sort((s,o)=>s.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(t,n){const i=(n.to-t.to)/(n.from-t.from),s=t.to-i*t.from;return o=>i*o+s}getStepFunctionForValue(t){let n=v.findLastIndex(this.steps,i=>i.from<=t);return n=fs(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return fs(this.getStepFunctionForValue(t)(t),0,100)}}class lv{constructor(t,n,i,s,o){this.getColIndex=t,this.cell=n,this.triggers=i,this.interactionManager=s,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const i of t)this.interactionManager.runInteraction(i.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===fr.id).filter(n=>{const i=this.getColIndex(this.cell),s=v.get(this.cell.column.columnDef.meta,"value_field"),o=v.get(n.config,"column");return o==i||o==s})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(v.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const i=this.colorManager.decodeInterpolation(t.interpolation),o=new ov(t.steps).mapValue(n);return i==null?void 0:i.getColor(o)}}}const uv=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:ps[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function cv(e){return e?Re(e).oklch()[0]>.7?"black":"white":"inherit"}function dv(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:cv(t)}}function yt(e){const t=e.tableCellContext.isClickable(),n=uv({clickable:t,align:e.align});return r("div",{className:n.classes.content,style:{...dv(e)},children:r(a.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:r("span",{title:e.children,children:e.children})})})}function pv(e){return r(yt,{...e,children:e.value})}function hv(e){const t=ee(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return r(yt,{...e,children:t})}function fv(e){const t=ee(e.value).format({thousandSeparated:!0});return r(yt,{...e,children:t})}function gv(e){const t=ee(e.value).format({output:"percent",mantissa:3});return r(yt,{...e,children:t})}function mv(e){const t=e.value,n=e.func_content;if(!n)return r(yt,{...e,children:t});const i=new Function(`return ${n}`)()({value:t});return r(yt,{...e,children:i})}function yv(e){switch(e.type){case qe.string:return r(pv,{...e});case qe.eloc:return r(hv,{...e});case qe.number:return r(fv,{...e});case qe.percentage:return r(gv,{...e});case qe.custom:return r(mv,{...e})}}const bv=e=>{const t=Ye(e),n=We(t.triggerManager,fr.id),{colorManager:i}=m.useContext(je);return m.useCallback(s=>new lv(e.getColIndex,s,n,t,i),[n,t,e.getColIndex])};function vv({context:e,instance:t}){var fe,Ce;const n=e.data,{height:i,width:s}=e.viewport,{value:o=In}=W(e.instanceData,"config"),{id_field:l,use_raw_columns:u,columns:c,...p}=o,{classes:f,cx:h}=av(),g=m.useMemo(()=>{if(!l)return[];const pe=O(l);return n[pe.queryID]},[n,l]),b=m.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(pe=>({id:pe,label:pe,value_field:pe,value_type:qe.string,align:"left"})):c,[u,c,g]),_=bv({getColIndex:m.useCallback(pe=>b.indexOf(pe.column.columnDef.meta),[b]),vizManager:e.vizManager,instance:t}),C=m.useMemo(()=>{const pe=Be.createColumnHelper();return b.map(ge=>{const Ie=O(ge.value_field);return pe.accessor(Ie.columnKey,{cell:Pe=>r(yv,{tableCellContext:_(Pe.cell),value:Pe.getValue(),type:ge.value_type,...ge}),header:ge.label,enableSorting:!0,meta:ge,size:ge.width,minSize:ge.width})})},[b,_]),[S,I]=m.useState([]),$=Be.useReactTable({data:g,state:{sorting:S},onSortingChange:I,columns:C,getCoreRowModel:Be.getCoreRowModel(),getSortedRowModel:Be.getSortedRowModel()}),{rows:q}=$.getRowModel(),N=m.useRef(null),P=wo.useVirtual({parentRef:N,size:q.length,estimateSize:m.useCallback(()=>28,[]),overscan:20}),{virtualItems:z,totalSize:A}=P,F=z.length>0&&((fe=z==null?void 0:z[0])==null?void 0:fe.start)||0,K=z.length>0?A-(((Ce=z==null?void 0:z[z.length-1])==null?void 0:Ce.end)||0):0,R=q.length,ne=R>0,se=ne?i-22:i,le=ne?22:0;return!Array.isArray(g)||g.length===0?r(a.Text,{color:"gray",align:"center",children:"Empty Data"}):d("div",{ref:N,style:{height:i,width:s},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[R>0&&r(a.Box,{className:f.info_bar,sx:{height:22},children:d(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",R]})}),d(a.Table,{sx:{...sv,maxHeight:se},...p,striped:o.striped,children:[r("thead",{className:f.thead,style:{top:le},children:$.getHeaderGroups().map(pe=>r("tr",{children:pe.headers.map(ye=>r("th",{style:{width:ye.getSize()},children:r(Hb,{header:ye,cx:h})},ye.id))},pe.id))}),d("tbody",{children:[F>0&&r("tr",{children:r("td",{style:{height:`${F}px`}})}),z.map(pe=>{const ye=q[pe.index];return r("tr",{children:ye.getVisibleCells().map(ge=>r("td",{children:Be.flexRender(ge.column.columnDef.cell,ge.getContext())},ge.id))},ye.id)}),K>0&&r("tr",{children:r("td",{style:{height:`${K}px`}})})]})]})]})}const gs=a.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),xv=[{from:0,to:0},{from:100,to:100}];class Cv{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");ie.makeAutoObservable(this,{steps:ie.observable},{deep:!1}),ie.reaction(()=>ie.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,i])=>({to:n,from:i})).sort((n,i)=>n.to-i.to||n.from-i.from))}fromProps(t){t.steps.length<2?this.setSteps(xv):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function wv(e){const{onChange:t,color:n,index:i,value:s}=e,{classes:o}=gs(),[l,u]=m.useState(s),[c,{setTrue:p,setFalse:f}]=X.useBoolean(!1),h=i%2===1,g=h&&s!=null,b=!h&&s!=null,_=`map ${s} to color ${i}`,C=()=>{u(s),f()},S=()=>{f(),t==null||t(l)},I=ee(s).format({average:!0});return d("div",{"data-testid":`palette-item-${i}`,className:o.paletteItem,children:[r(a.Text,{title:_,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),d(a.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[r(a.Popover.Target,{children:r("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":Re(n).alpha(.5).hex(),backgroundColor:n}})}),r(a.Popover.Dropdown,{children:d(a.Stack,{children:[r(a.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),d(a.Group,{position:"right",children:[r(a.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),r(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:S,children:"OK"})]})]})})]}),r(a.Text,{title:_,style:{opacity:b?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const _v=T.observer(({model:e})=>{const{classes:t}=gs(),n=v.range(0,13,1).map(i=>100/12*i).map(i=>[e.interpolation.getColor(i),i]);return r("div",{className:t.palette,children:n.map(([i,s],o)=>r(wv,{index:o,color:i,value:e.getStepFromValue(s),onChange:l=>e.changeStep(l,s)},i))})}),Sv=T.observer(function(t){const n=X.useCreation(()=>new Cv,[]);return m.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:r(_v,{model:n})}),Tv=e=>{const{value:t,onChange:n,colorManager:i}=e,s=i.getColorInterpolations(),[o,l]=m.useState(t),u=i.decodeInterpolation(o.interpolation)||s[0],[c,{setTrue:p,setFalse:f}]=X.useBoolean(),h=s.map(S=>({label:S.displayName,value:i.encodeColor(S),group:S.category}));function g(S){S&&l(I=>({...I,interpolation:S}))}const b=()=>{f(),n==null||n(ie.toJS(o))};function _(S){l(I=>({...I,steps:S}))}const C=()=>{f(),l(t)};return d(B,{children:[r(a.Button,{variant:"outline",onClick:p,children:u==null?void 0:u.displayName}),r(a.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&d(a.Stack,{"data-testid":"color-interpolation-modal",children:[r(a.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),r(Sv,{steps:o.steps,interpolation:u,onChange:_}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:b,children:"OK"})]})]})})]})},Dv=["static","interpolation","none"].map(e=>({label:v.capitalize(e),value:e})),kv=[{from:0,to:0},{from:100,to:100}];function ms(e){return e?v.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Iv(e,t){var n;return ms(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Mv(e,t){return v.isObject(t)?t:{steps:kv,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const $v=m.forwardRef((e,t)=>{const{colorManager:n}=m.useContext(je),[i,s]=m.useState(ms(e.value)),[o,l]=m.useState(Iv(n,e.value)),u=X.useLatest(o),[c,p]=m.useState(Mv(n,e.value)),f=X.useLatest(c),h=_=>{var C,S,I;s(_||"none"),_==="static"?(C=e.onChange)==null||C.call(e,u.current):_==="none"||!_?(S=e.onChange)==null||S.call(e,"none"):(I=e.onChange)==null||I.call(e,f.current)},g=_=>{var C;l(_),(C=e.onChange)==null||C.call(e,_)},b=_=>{var C;p(_),(C=e.onChange)==null||C.call(e,_)};return d(a.Stack,{align:"stretch",children:[r(a.Select,{label:"Cell background",value:i||"none",onChange:h,data:Dv}),i==="static"&&r(Me,{value:o,onChange:g}),i==="interpolation"&&r(Tv,{colorManager:n,value:c,onChange:b})]})}),Av={[qe.eloc]:"ELOC"},zv=Object.values(qe).map(e=>({label:v.get(Av,e,v.capitalize(e)),value:e})),Ev=m.forwardRef(({label:e,value:t,onChange:n,sx:i},s)=>r(a.Select,{ref:s,label:e,data:zv,value:t,onChange:n,sx:i})),Lv=m.forwardRef(({value:e,onChange:t},n)=>{const[i,{setTrue:s,setFalse:o}]=X.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},p=()=>{o(),u(e)},f=()=>{u(ca)};return m.useEffect(()=>{u(e)},[e]),d(B,{children:[r(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Custom Cell Content"}),r(a.Modal,{size:800,title:"Custom cell content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(a.Stack,{children:[r(a.Box,{sx:{position:"relative"},children:r(De,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:f,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Pv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],gr=()=>r(a.Text,{color:"dimmed",size:12,children:"px"}),Ov=({control:e,index:t,watch:n,remove:i,column:s})=>{const o=n(`columns.${t}.value_type`);return d(a.Stack,{my:0,sx:{position:"relative"},children:[d(a.Group,{grow:!0,children:[r(x.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>r(a.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),r(x.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>r(j,{label:"Value Field",required:!0,...l})})]}),d(a.Group,{grow:!0,children:[r(x.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>r(Ev,{label:"Value Type",sx:{flex:1},...l})}),o===qe.custom&&r(x.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>r(Lv,{value:l.value??ca,onChange:u=>l.onChange(u??"")})})]}),r(a.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),d(a.Group,{grow:!0,children:[r(a.NumberInput,{hideControls:!0,label:"Min Width",rightSection:r(gr,{}),disabled:!0}),r(x.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>r(a.NumberInput,{hideControls:!0,label:"Width",rightSection:r(gr,{}),...l})}),r(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:r(gr,{}),disabled:!0})]}),r(a.Group,{grow:!0,noWrap:!0,children:r(x.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>r(a.Select,{label:"Alignment",data:Pv,...l})})}),r(x.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>r($v,{...l})}),r(a.Divider,{mb:4,mt:12,variant:"dashed"}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(t),children:"Delete this column"})]})},Vv=({control:e,watch:t})=>{const{fields:n,append:i,remove:s,update:o}=x.useFieldArray({control:e,name:"columns"}),l=()=>{const c=we.randomId();i({id:c,label:c,value_field:"",value_type:qe.string})};t("columns");const u=t("use_raw_columns");return d(B,{children:[r(x.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>r(a.Switch,{mt:20,label:"Use Original Data Columns",checked:c.value,onChange:p=>c.onChange(p.currentTarget.checked)})}),r(a.Divider,{mt:20,mb:10,variant:"dashed"}),!u&&d(a.Stack,{children:[r(a.Text,{my:0,children:"Custom Columns"}),d(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(a.Tabs.List,{children:[n.map((c,p)=>r(a.Tabs.Tab,{value:p.toString(),children:p+1},c.id)),r(a.Tabs.Tab,{onClick:l,value:"add",children:r(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,p)=>r(a.Tabs.Panel,{value:p.toString(),children:r(Ov,{control:e,watch:t,index:p,column:c,remove:s},p)},c.id))]})]})]})};function Bv({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),d(a.Stack,{spacing:"xs",children:[d(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[r(x.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>r(a.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),r(x.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>r(a.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),r(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:r(x.Controller,{name:"fontSize",control:e,render:({field:n})=>r(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),d(a.Group,{position:"apart",grow:!0,children:[r(x.Controller,{name:"striped",control:e,render:({field:n})=>r(a.Switch,{label:"Striped",checked:n.value,onChange:i=>n.onChange(i.currentTarget.checked)})}),r(x.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>r(a.Switch,{label:"Highlight on hover",checked:n.value,onChange:i=>n.onChange(i.currentTarget.checked)})})]})]})}function qv({columns:e,...t}){return{...t,columns:e.map(({id:n,...i})=>({id:n??we.randomId(),...i}))}}function Nv({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),i=m.useMemo(()=>v.defaultsDeep({},t,In),[t]),s=m.useMemo(()=>qv(i),[i]);m.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),n(s))},[i,s]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=x.useForm({defaultValues:s});m.useEffect(()=>{p(s)},[s]);const f=c(),h=m.useMemo(()=>!v.isEqual(f,i),[f,i]);return u(["id_field"]),d("form",{onSubmit:l(n),children:[d(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(a.Text,{children:"Table Config"}),r(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(D.DeviceFloppy,{size:20})})]}),d(a.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Data",children:"Data"}),r(a.Tabs.Tab,{value:"Style",children:"Style"}),r(a.Tabs.Tab,{value:"Columns",children:"Columns"})]}),r(a.Tabs.Panel,{value:"Data",children:r(x.Controller,{name:"id_field",control:o,render:({field:g})=>r(j,{label:"ID Field",required:!0,...g})})}),r(a.Tabs.Panel,{value:"Style",children:r(Bv,{control:o,watch:u})}),r(a.Tabs.Panel,{value:"Columns",children:r(Vv,{control:o,watch:u})})]})]})}function Gv(e){const{columns:t,...n}=e;return{...e,columns:t.map(i=>({...i,align:i.align??"left"}))}}function Fv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{id_field:s,columns:o,...l}=e;return{...l,id_field:i(s),columns:o.map(u=>({...u,value_field:i(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wv extends me{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:i,...s}=n.config;return{...n,version:2,config:{...s,columns:i.map(({id:o,...l})=>({id:o??we.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Gv(n.config)})),this.version(4,(n,i)=>({...n,version:4,config:Fv(n.config,i)}))}}const mr={createConfig(){return{version:4,config:v.cloneDeep(In)}},displayName:"Table",displayGroup:"Others",migrator:new Wv,name:"table",viewRender:vv,configRender:Nv,triggers:[fr]},jv=y.types.model("PanelLayoutModel",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:i,h:s,moved:o}=e;return{h:s,w:i,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:i,w:s,h:o,moved:l}=t;e.x=n,e.y=i,e.w=s,e.h=o,e.moved=!!l,e.static=!!t.static}})),Yv=y.types.model("PanelStyleBorderModel",{enabled:y.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Rv=y.types.model("PanelStyleModel",{border:Yv}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Qv=y.types.model("PanelVizModel",{type:y.types.string,conf:y.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}})),ys=y.types.model({id:y.types.string,title:y.types.string,description:y.types.string,layout:jv,queryIDs:y.types.array(y.types.string),viz:Qv,style:Rv,variables:y.types.optional(y.types.array(gl),[])}).views(e=>({get contentModel(){return y.getParentOfType(e,ln)}})).views(e=>({get queryIDSet(){return new Set(e.queryIDs)},get queries(){return e.contentModel.queries.findByIDSet(this.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(){return this.queries.map(t=>t.stateMessage).filter(t=>!!t)},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:t,title:n,description:i,queryIDs:s}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:n,layout:e.layout.json,queryIDs:[...s],variables:e.variables.map(o=>o.json),description:i}},get dataFieldOptions(){return e.queryIDs.length===0?[]:this.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(s=>({label:s,value:`${t.id}.${s}`,group:t.name}))}).flat()}})).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=y.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=y.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)},removeSelf(){y.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){y.getRoot(e).content.views.findByID(t).removePanelID(e.id),y.getRoot(e).content.views.findByID(n).appendPanelID(e.id),y.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])},refreshData(){e.queries.forEach(t=>t.fetchData())},downloadData(){y.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function bs(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:mr.name,conf:mr.createConfig()},style:{border:{enabled:!0}}}}const vs=y.types.model("PanelsModel",{list:y.types.optional(y.types.array(ys),[])}).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(s=>{const o=e.idMap.get(s);o?n.push(o):console.warn(`Panel is not found, id:${s}`)});const i=n.map(s=>({...s.layout.json,i:s.id}));return{panels:n,layouts:i}}})).views(e=>({editorOptions(t,n){const{panels:i}=e.panelsByIDs(n);i.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const s=i.map(l=>({label:l.title?l.title:v.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return s.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),s}})).actions(e=>({replace(t){e.list=y.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(i=>i.id===t);n!==-1&&e.list.splice(n,1)},duplicateByID(t){const n=e.list.find(s=>s.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const i=new Date().getTime().toString();return e.list.push({...n.json,id:i,layout:{...n.layout,y:1/0,moved:!1}}),i},replaceByIndex(t,n){e.list.splice(t,1,n)}}));var xs=(e=>(e.Use="use",e.Edit="edit",e))(xs||{}),J=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(J||{});const Uv={div:"Division",tabs:"Tabs",modal:"Modal"},Cs={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},Kv={div:"#ff4000",modal:"#000",tabs:"#ffad18"},Xv={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var yr=(e=>(e.Select="select",e.TreeSelect="tree-select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(yr||{});const ws=y.types.model("ViewModel_Division",{_name:y.types.literal(J.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),Zv=()=>ws.create({_name:J.Division}),br={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
470
+ `)},Jv=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.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,i=y.getParent(e,2),s=y.getRoot(e);if(!t)return i.name;try{const o={filters:s.content.filters.values,context:s.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),i.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}})),_s=y.types.model("ViewModel_Modal",{_name:y.types.literal(J.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(Jv,br)}).views(e=>({get json(){const{_name:t,width:n,height:i,custom_modal_title:s}=e;return{_name:t,width:n,height:i,custom_modal_title:s.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Hv=()=>_s.create({_name:J.Modal,width:"90vw",height:"90vh"}),ex=y.types.model("ViewModel_Tabs_Tab",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:i,color:s}=e;return{id:t,name:n,color:s,view_id:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Ss=y.types.model("ViewModel_Tabs",{_name:y.types.literal(J.Modal),tabs:y.types.optional(y.types.array(ex),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:i,tabs:s,grow:o}=e;return{grow:o,tabs:s.map(l=>l.json),_name:t,variant:n,orientation:i}}})).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=y.cast(t)},addTab(){const t=we.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),tx=()=>Ss.create({_name:J.Modal,tabs:[]}),Ts=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[J.Division,J.Modal,J.Tabs]),config:y.types.union(ws,_s,Ss),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:i,config:s}=e;return{id:t,name:n,type:i,config:s.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case J.Division:e.config=Zv();break;case J.Modal:e.config=Hv();break;case J.Tabs:e.config=tx();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(i=>i!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})).actions(e=>({})),Ds=y.types.model("ViewsModel",{current:y.types.optional(y.types.array(Ts),[]),visibleViewIDs:y.types.array(y.types.string),idOfVIE:y.types.string}).views(e=>({get json(){return e.current.map(t=>Ft(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 isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},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))},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=y.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=>({replace(t){e.current.replace(t)},addANewView(t,n,i,s){e.current.push({id:t,name:n,type:i,config:s,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(i=>i.id===t);n!==-1&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},appendToVisibles(t){new Set(e.visibleViewIDs.map(i=>i)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=new Date().getTime().toString();e.addANewView(t,J.Division,J.Division,{_name:J.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(i=>i===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function vr(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(s=>{const{_name:o=s.type}=s.config;return{...s,config:{...s.config,_name:o},panelIDs:s.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}function ks(e,t,n,i){return e.reduce((s,o)=>(s[o[t]]=Cn(o[n],i),s),{})}const nx=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:Hi,queries:sa,sqlSnippets:la,views:Ds,panels:vs,mock_context:fl,origin:y.types.maybe(y.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!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=y.getSnapshot(v.get(e,t)).map(i=>v.pick(i,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!v.isEqual(n,v.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get viewsChanged(){const t="views.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!v.isEqual(v.get(e,t),v.get(e.origin,t))},get payloadForSQL(){const t=y.getParent(e).context.current,n=y.getParent(e).globalSQLSnippets,i={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...i,sql_snippets:ks(e.sqlSnippets.current,"key","value",i),global_sql_snippets:ks(n.list,"id","content",i)}},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:i})=>({id:n,data:i})).reduce((n,i)=>(n[i.id]=i.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,i=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}]}))),s=e.views.idMap,o=e.filters.current.filter(l=>v.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=s.get(u))==null?void 0:c.name)??u}})}));return i.concat(o)}})).actions(e=>({duplicatePanelByID(t,n){var s;const i=e.panels.duplicateByID(t);i&&((s=e.views.findByID(n))==null||s.appendPanelID(i))},removePanelByID(t,n){var i;e.panels.removeByID(t),(i=e.views.findByID(n))==null||i.removePanelID(t)},addANewPanel(t){var i;const n=new Date().getTime().toString();e.panels.append(bs(n)),(i=e.views.findByID(t))==null||i.appendPanelID(n)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:i,content:s}=t;if(!s)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:p,sqlSnippets:f,mock_context:h={}}}=s;e.id=n,e.name=i,e.version=o,y.applySnapshot(e.filters.current,l),y.applySnapshot(e.views.current,vr(u).current),y.applySnapshot(e.panels.list,c),y.applySnapshot(e.queries.current,p),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),ln=y.types.snapshotProcessor(nx,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(n=>v.pick(n,["id","key","type","sql"])));return v.defaults({},{queries:{current:t}},e)}});function rx(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function Is({id:e,name:t,dashboard_id:n,create_time:i,update_time:s,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:p,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return ln.create({id:e,name:t,dashboard_id:n,create_time:i,update_time:s,version:l,filters:ea(u),queries:{current:f},sqlSnippets:{current:h},mock_context:{current:g},views:vr(c),panels:{list:p}})}const ix=y.types.model({id:y.types.string,content:y.types.string,create_time:y.types.string,update_time:y.types.string,is_preset:y.types.boolean}),ax=y.types.model("GlobalSQLSnippetsModel",{list:y.types.optional(y.types.array(ix),[])}).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)}})),Ms=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:ln,content_id:y.types.string,datasources:dl,globalSQLSnippets:ax,context:ua,editor:hl}).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:i,name:s,group:o,content_id:l}=t;e.id=i,e.name=s,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function xr({id:e,name:t,group:n,content_id:i},s,o,l,u){return Ms.create({id:e,name:t,group:n,content_id:i,content:Is(s),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:u},editor:{}})}const Cr=m.createContext(null);function un(e){const t=m.useContext(Cr),n=X.useCreation(()=>e.configure(t||new $n),[e.configure]),i=X.usePrevious(n);return i&&i!==n&&i.dispose(),r(Cr.Provider,{value:n,children:e.children})}function $s(){return m.useContext(Cr)}const sx={viewPanelInFullScreen:v.noop,inFullScreen:!1},wr=m.createContext(sx),ox=({description:e,isDescriptionEmpty:t})=>t?null:r(a.Tooltip,{color:"white",label:r(rn,{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:r(a.Box,{sx:{height:"16px",alignSelf:"center"},children:r(L.IconInfoCircle,{size:16,color:"gray"})})}),lx=T.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:i,...s},value:o,onChange:l})=>d(a.Box,{children:[r(a.Text,{children:" "}),r(a.Checkbox,{label:d(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[r(a.Box,{sx:{flexGrow:1},children:e}),r(ox,{description:n,isDescriptionEmpty:i})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...s,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),As=T.observer(({label:e,config:t,value:n=[null,null],onChange:i})=>{const s=Array.isArray(n)?n.map(c=>c?Y(c).toDate():null):[null,null],o=c=>{i(c.map(p=>p&&Y(p).format(t.inputFormat)))},l=t.getMinDate(s[0]),u=t.getMaxDate(s[0]);return r(To.DateRangePicker,{label:e,value:s,onChange:o,icon:r(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:l,maxDate:u,styles:{input:{borderColor:"#e9ecef"}},...t})}),ux=a.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":{flexGrow:1}}}})),zs=({errorMessage:e})=>e?r(a.Text,{color:"red",size:12,children:e}):r(a.Text,{color:"dimmed",size:12,children:"Not found"}),cx=({disabled:e,classNames:t,styles:n,unstyled:i,radius:s,style:o,label:l,value:u,onChange:c,options:p,errorMessage:f})=>{const{classes:h,cx:g}=ux({radius:s},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:i}),[b,_]=m.useState(!1),C=N=>{_(N)},S=b&&(u==null?void 0:u.length)>0,[I,$]=m.useState(""),q=m.useMemo(()=>{if(!I)return p;const N=I.toLowerCase(),P=z=>{var A;return((A=z.description)==null?void 0:A.toLowerCase().includes(N))||z.label.toLowerCase().includes(N)};return p.filter(P)},[I,p]);return d(a.Stack,{spacing:3,children:[d(a.Group,{position:"apart",children:[r(a.Text,{className:h.label,children:l}),S&&r(a.Tooltip,{label:`${u.length} selected`,children:r(a.Badge,{children:u.length})})]}),r(Pi,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:C,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>r(a.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:r(zs,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:N=>`${N.length} selected`,searchValue:I,onSearch:$,filterOption:!1,children:q.map(N=>r(Pi.Option,{children:r(a.Group,{noWrap:!0,children:d("div",{children:[r(a.Text,{size:"sm","data-role":"label",children:N.label}),N.description&&r(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:N.description})]})})},N.value))})]})},dx=T.observer(({label:e,config:t,value:n,onChange:i})=>{const s=U(),o=!!t.options_query_id,{state:l,error:u}=s.getDataStuffByID(t.options_query_id),c=l==="loading",p=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>i(g,!1);return r(cx,{label:e,options:t.options,style:{minWidth:"160px",width:p,maxWidth:f?p:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),px=m.forwardRef(({label:e,description:t,...n},i)=>r("div",{ref:i,...n,children:r(a.Group,{noWrap:!0,children:d("div",{children:[r(a.Text,{size:"sm","data-role":"label",children:e}),r(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),hx=T.observer(({label:e,config:t,value:n,onChange:i})=>{const s=U(),o=!!t.options_query_id,{state:l,error:u}=s.getDataStuffByID(t.options_query_id),c=l==="loading";return m.useEffect(()=>{var h;const{default_selection_count:p}=t;if(!p)return;const f=((h=t.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),i(f,!0)},[t.default_selection_count,t.options]),r(a.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:i,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:px})});function fx({label:e,config:t,value:n,onChange:i}){return r(a.TextInput,{label:e,value:n||"",onChange:s=>i(s.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const gx=({rotate:e,onClick:t})=>r("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:r("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"})}),mx=({expanded:e,isLeaf:t,value:n,onClick:i,...s})=>(n==="0-0-value"&&console.log(s),t?r("span",{style:{width:"14px",display:"inline-block"}}):r(gx,{rotate:e?"0":"-90",onClick:i,...s})),yx=({onClick:e})=>d("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:[r("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),r("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),r("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),r("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),bx=({onClick:e,...t})=>r(yx,{onClick:e,...t}),vx=a.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"}}}})),xx=({disabled:e,classNames:t,styles:n,unstyled:i,radius:s,style:o,label:l,value:u,onChange:c,treeData:p,errorMessage:f})=>{const{classes:h,cx:g}=vx({radius:s},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:i}),[b,_]=m.useState(!1),C=I=>{_(I)},S=b&&(u==null?void 0:u.length)>0;return d(a.Stack,{spacing:3,children:[d(a.Group,{position:"apart",children:[r(a.Text,{className:h.label,children:l}),S&&r(a.Tooltip,{label:`${u.length} selected`,children:r(a.Badge,{children:u.length})})]}),r(Oi,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:C,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>r(a.CloseButton,{}),switcherIcon:mx,treeIcon:bx,maxTagTextLength:10,value:u,treeData:p,notFoundContent:r(zs,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Oi.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:I=>`${I.length} selected`})]})},Cx=T.observer(({label:e,config:t,value:n,onChange:i})=>{const{treeData:s,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",p=!!t.options_query_id?o:!1;return r(xx,{disabled:p,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>i(f,!1),treeData:s,errorMessage:l,label:e})}),wx=T.observer(({filter:{type:e,config:t,key:n,...i},formFieldProps:s})=>{switch(e){case"select":return r(hx,{...i,...s,config:t});case"multi-select":return r(dx,{...i,...s,config:t});case"tree-select":return r(Cx,{...i,...s,config:t});case"text-input":return r(fx,{...i,...s,config:t});case"date-range":return r(As,{...i,...s,config:t});case"checkbox":return r(lx,{...i,...s,config:t});default:return null}}),Es=T.observer(m.forwardRef(({filter:e,...t},n)=>r("div",{className:"filter-root",ref:n,children:r(Le,{children:r(wx,{filter:e,formFieldProps:t})})}))),Ls=T.observer(function({view:t}){const n=U(),{control:i,handleSubmit:s,reset:o}=x.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=x.useWatch({control:i});m.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),m.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const u=n.filters.visibleInView(t.id),c=m.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),p=m.useMemo(()=>u.filter(g=>v.get(g,"config.required",!1)),[u]),f=m.useMemo(()=>p.length===0?!1:p.some(g=>!g.requiredAndPass(l[g.key])),[l,p]);if(u.length===0)return null;const h=(g,b)=>(_,C)=>{b(_),(g.should_auto_submit||C)&&n.filters.setValueByKey(g.key,_)};return r("form",{onSubmit:s(n.filters.setValues),children:d(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[r(a.Group,{align:"flex-start",children:u.map(g=>r(x.Controller,{name:g.key,control:i,render:({field:b})=>r(Es,{filter:g,value:b.value,onChange:h(g,b.onChange)})},g.id))}),!c&&r(a.Group,{sx:{alignSelf:"flex-end"},children:r(a.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),$1="";function _x(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Ps=T.observer(()=>{const{freezeLayout:e}=m.useContext(He),[t,n]=m.useState(!1),{panel:i}=Te();return m.useEffect(()=>{e(t)},[t]),_x(i.description)?null:d(B,{children:[r(a.Modal,{opened:t,onClose:()=>n(!1),title:i.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:r(rn,{value:i.description,styles:{root:{border:"none"},content:{padding:0}}})}),r(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:r(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(s=>!s),sx:{verticalAlign:"baseline",cursor:"pointer"},children:r(D.InfoCircle,{size:20})})})]})}),Sx=T.observer(({view:e})=>{const t=de(),n=U(),i=Ve.useModals(),{panel:s}=Te(),{id:o}=s,{inEditMode:l}=m.useContext(He),{viewPanelInFullScreen:u,inFullScreen:c}=m.useContext(wr),p=()=>{n.duplicatePanelByID(o,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},h=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),g=m.useCallback(()=>{u(o)},[o,u]),b=!c&&e.type!==J.Modal;return r(B,{children:r(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:d(a.Menu,{withinPortal:!0,children:[r(a.Menu.Target,{children:r(a.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),d(a.Menu.Dropdown,{children:[r(a.Menu.Item,{onClick:s.refreshData,icon:r(D.Refresh,{size:14}),children:"Refresh"}),r(a.Menu.Item,{onClick:s.downloadData,icon:r(D.Download,{size:14}),children:"Download Data"}),b&&r(a.Menu.Item,{onClick:g,icon:r(D.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&d(B,{children:[r(a.Divider,{label:"Edit",labelPosition:"center"}),r(a.Menu.Item,{onClick:f,icon:r(D.Settings,{size:14}),children:"Settings"}),r(a.Menu.Item,{onClick:p,icon:r(D.Copy,{size:14}),children:"Duplicate"}),r(a.Menu.Item,{color:"red",onClick:h,icon:r(D.Trash,{size:14}),children:"Delete"})]})]})]})})})}),Tx=T.observer(({panel:e})=>d(a.Stack,{children:[e.queryErrors.map((t,n)=>r(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),e.queryStateMessages.map((t,n)=>r(a.Text,{color:"gray",align:"center",children:t},`${n}-${t}`))]}));var Os=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Os||{}),cn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(cn||{});class Dx{constructor(t){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=t.getRequired(ve.instanceScope.panelModel),this.vizInstance=t.getRequired(ve.instanceScope.vizInstance),this.operationManager=t.getRequired(ve.instanceScope.operationManager),this.triggerManager=t.getRequired(ve.instanceScope.triggerManager),this.vizManager=t.getRequired(ve.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 Vs(e){const{panel:t}=Te();return m.useCallback(n=>{const i=n.getRequired(ve.vizManager),s=i.resolveComponent(e.viz.type);return n.createScoped().provideFactory(ve.instanceScope.vizInstance,()=>i.getOrCreateInstance(e)).provideFactory(ve.instanceScope.interactionManager,o=>{const l=o.getRequired(ve.instanceScope.vizInstance);return new hr(l,s,on)}).provideFactory(ve.instanceScope.operationManager,o=>o.getRequired(ve.instanceScope.interactionManager).operationManager).provideFactory(ve.instanceScope.triggerManager,o=>o.getRequired(ve.instanceScope.interactionManager).triggerManager).provideValue(ve.instanceScope.panelModel,t).provideFactory(ve.instanceScope.migrator,o=>new Dx(o))},[e.viz.type,e.viz.conf])}function Bs(e){const[t,n]=m.useState(!1),i=$s().getRequired(ve.instanceScope.migrator);return X.useAsyncEffect(async()=>{const s=i.status===cn.notStarted;n(i.status===cn.done),i.status===cn.notStarted&&i.runMigration().then(o=>{o===Os.migrated&&s&&(e==null||e())}).finally(()=>{n(!0)})},[i]),t}function qs(e,t){const n=$s().getRequired(ve.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,i=>{e(i)})),[e,t.viz.type]),n}function kx({setVizConf:e,...t}){const{panel:n}=t,i=qs(e,n),s=Bs(()=>{Bt.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return X.useAsyncEffect(async()=>{await i.instanceData.setItem(null,n.viz.conf)},[i,n.viz.type]),s?r(wl,{...t}):r(a.Text,{children:"Checking update..."})}function Ix(e){const{panel:t,setVizConf:n}=e;qs(n,t);const{inEditMode:i}=m.useContext(He);return Bs(()=>{i&&Bt.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?r(Cl,{...e}):r(a.Text,{children:"Checking update"})}const A1="";function Mx(e,t){const{vizManager:n}=m.useContext(je),{panel:{viz:i,title:s,id:o,description:l,queryIDs:u,variables:c}}=Te(),p={title:s,id:o,description:l,queryIDs:u,viz:i,layout:t},f=Vs(p);try{return n.resolveComponent(i.type),r(un,{configure:f,children:r(Ix,{setVizConf:i.setConf,panel:p,data:e,variables:c,vizManager:n})})}catch(h){return console.info(v.get(h,"message")),null}}const $x=T.observer(function({data:t}){const{ref:n,width:i,height:s}=we.useElementSize(),o=Mx(t,{w:i,h:s});return r("div",{className:"viz-root",ref:n,children:i&&s&&r(Le,{children:o})})}),Ns=T.observer(({panel:e,height:t})=>d(a.Flex,{direction:"column",sx:{height:t,position:"relative",width:"100%"},children:[r(a.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&r(Tx,{panel:e}),e.canRenderViz&&r($x,{data:e.data})]})),z1="",Ax=T.observer(function(){const{panel:t}=Te(),{title:n}=t;return n?r(a.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:r(a.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null}),zx={border:"1px solid #e9ecef"},Ex={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function Lx(e,t){return e.style.border.enabled?zx:t?Ex:{border:"1px dashed transparent"}}const dn=T.observer(function({panel:t,view:n}){const{inEditMode:i}=m.useContext(He),s=t.title?"calc(100% - 25px - 5px)":"100%",o=Lx(t,i);return r(En,{value:{panel:t,data:t.data,loading:t.dataLoading,errors:t.queryErrors},children:d(a.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[r(a.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:r(Ps,{})}),r(Sx,{view:n}),r(Ax,{}),r(Ns,{panel:t,height:s})]})})}),E1="",Px=m.forwardRef(({h:e},t)=>r(a.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:r(D.ArrowsMove,{size:16})})),Ox=m.forwardRef(({handleAxis:e,...t},n)=>r(a.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:r(D.ChevronDownRight,{size:16})})),Vx=qt.WidthProvider(qt),Bx=T.observer(({view:e,className:t="layout"})=>{const n=U(),{panels:i,layouts:s}=n.panels.panelsByIDs(e.panelIDs),o=m.useCallback(u=>{u.forEach(({i:c,...p})=>{const f=n.panels.findByID(c);f&&f.layout.set(p)})},[n]),l=(u,c,p,f)=>{p.h<30&&(p.h=30,f.h=30),p.w<4&&(p.w=4,f.w=4)};return r(Vx,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:s,draggableHandle:".react-grid-customDragHandle",resizeHandle:r(Ox,{}),onResize:l,children:i.map((u,c)=>d("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[r(Px,{h:u.layout.h}),r(dn,{view:e,panel:u})]},u.id))})}),qx=qt.WidthProvider(qt),Nx=T.observer(function({view:t,className:n="layout"}){const{panels:i,layouts:s}=U().panels.panelsByIDs(t.panelIDs);return r(qx,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:s,children:i.map(o=>r("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:r(dn,{view:t,panel:o})},o.id))})}),Gx=T.observer(({children:e})=>r(a.Box,{pt:10,pb:100,children:e})),Fx=T.observer(({children:e,view:t})=>{const n=t.config;return r(a.Modal,{size:n.width,overflow:"inside",opened:!0,onClose:v.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),Wx=({variant:e,orientation:t})=>{const n={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},jx=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Yx=T.observer(({children:e,view:t})=>{const n=Ve.useModals(),i=U(),s=m.useMemo(()=>i.views.options.filter(c=>c.type===J.Division),[t.id,i.views.options]),o=t.config,l=c=>n.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(c)},confirmProps:{color:"red"},zIndex:320}),u=o.tabs.length===0;return d(a.Box,{className:"preview-view-tabs",children:[d(a.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:Wx(o),children:[d(a.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>r(a.Tabs.Tab,{value:c.id,sx:jx(c),children:c.name??c.id},c.id)),r(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:r(D.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,p)=>{const f=i.views.findByID(c.view_id);return d(a.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[d(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[r(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),d(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[r(a.TextInput,{label:"Tab Name",value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),r(a.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:s}),r(a.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&d(a.Button,{mt:20,variant:"gradient",leftIcon:r(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>i.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),r(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(p),disabled:u,leftIcon:r(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&r(pn,{view:f})]},c.id)})]}),e]})}),Rx=T.observer(({view:e,children:t})=>{switch(e.type){case J.Modal:return r(Fx,{view:e,children:t});case J.Tabs:return r(Yx,{view:e,children:t});case J.Division:default:return r(Gx,{children:t})}}),Gs=T.observer(function({view:t}){return r(wr.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:r(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:r(Rx,{view:t,children:d(a.Box,{sx:{position:"relative"},children:[r(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:r(Ls,{view:t})}),r(Bx,{view:t})]})})})})}),Qx={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Ux=T.observer(function({view:t,panel:n,exitFullScreen:i}){return r(a.Modal,{opened:!0,fullScreen:!0,onClose:i,title:r(a.Button,{color:"blue",size:"xs",onClick:i,leftIcon:r(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:Qx,children:r(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:r(dn,{view:t,panel:n})})})});function Kx(e,t,n){const{panels:i}=U(),s=e.id==="Main",[o,l]=m.useState(()=>s&&i.findByID(t)?t:null),u=m.useCallback(h=>{l(h),s&&n(h)},[s,n]),c=m.useCallback(()=>{l(null),s&&n("")},[s,n]),p=o?i.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!p,fullScreenPanel:p}}const Xx=T.observer(({children:e})=>r(a.Box,{children:e})),Zx=T.observer(({children:e,view:t})=>{const n=U(),i=t.config,s=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id);return r(a.Modal,{size:i.width,centered:!0,overflow:"inside",opened:s,onClose:o,withCloseButton:!1,title:i.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:i.height,overflow:"auto"}},transitionDuration:0,children:e})}),Jx=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Hx=T.observer(({children:e,view:t})=>{const n=U(),i=t.config;return d(a.Box,{className:"render-view-tabs",children:[d(a.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:{panel:{padding:i.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[r(a.Tabs.List,{grow:i.grow,children:i.tabs.map(s=>r(a.Tabs.Tab,{value:s.id,sx:Jx(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),i.tabs.map(s=>{const o=n.views.findByID(s.view_id);return o?r(a.Tabs.Panel,{value:s.id,children:r(pn,{view:o})},s.id):null})]}),e]})}),e0=T.observer(({view:e,children:t})=>{switch(e.type){case J.Modal:return r(Zx,{view:e,children:t});case J.Tabs:return r(Hx,{view:e,children:t});case J.Division:default:return r(Xx,{children:t})}}),pn=T.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:i}=ka(),{viewPanelInFullScreen:s,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Kx(t,n,i);return r(wr.Provider,{value:{viewPanelInFullScreen:s,inFullScreen:l},children:d(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&r(Ux,{view:t,panel:u,exitFullScreen:o}),r(e0,{view:t,children:d(a.Box,{sx:{position:"relative"},children:[!l&&r(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:r(Ls,{view:t})}),!l&&r(Nx,{view:t})]})})]})})});function _r(e){return m.useCallback(t=>t.provideValue(ve.pluginManager,e.pluginManager).provideValue(ve.vizManager,e.vizManager).provideValue(ve.colorManager,e.colorManager),[])}const t0=T.observer(({headerMenuItems:e=null})=>{const t=de(),n=U(),i=()=>{const s=JSON.stringify(n.json,null,2),o=`${t.name}__${n.name}`;Ho(o,s)};return d(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[r(a.Menu.Target,{children:r(a.ActionIcon,{variant:"light",color:"blue",children:r(L.IconMenu2,{size:14})})}),d(a.Menu.Dropdown,{children:[r(a.Menu.Item,{icon:r(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),r(a.Menu.Item,{icon:r(L.IconCode,{size:14}),onClick:i,children:"Download Schema"}),e]})]})}),n0=T.observer(({saveDashboardChanges:e})=>{const t=Ve.useModals(),n=U(),i=()=>{t.openConfirmModal({title:d(a.Group,{position:"left",children:[r(L.IconAlertTriangle,{size:18,color:"red"}),r(a.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})},s=n.changed;return d(a.Group,{spacing:0,children:[r(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:r(L.IconDeviceFloppy,{size:18}),onClick:e,disabled:!s,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),d(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!s,children:[r(a.Menu.Target,{children:r(a.ActionIcon,{variant:"default",disabled:!s,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:r(L.IconCaretDown,{size:18})})}),r(a.Menu.Dropdown,{children:r(a.Menu.Item,{icon:r(L.IconRecycle,{size:14,color:"red"}),disabled:!s,onClick:i,children:"Revert Changes"})})]})]})}),r0=T.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:n})=>{const i=Do.useNavigate(),s=de(),o=()=>{i(`/dashboard/${s.id}`)},l=Ve.useModals(),u=()=>{l.openConfirmModal({title:d(a.Group,{position:"left",children:[r(L.IconAlertTriangle,{size:18,color:"red"}),r(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=s.content.changed;return r(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:d(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[d(a.Group,{children:[r(a.Button,{size:"xs",color:c?"red":"green",leftIcon:r(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:d(a.Group,{spacing:4,children:["End Editing",r(a.Text,{td:"underline",children:s.name})]})}),r(n0,{saveDashboardChanges:e})]}),d(a.Group,{position:"right",sx:{flexGrow:1},children:[t,r(t0,{headerMenuItems:n})]})]})})}),i0={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},a0=T.observer(()=>{const e=U();return r(a.Box,{sx:i0,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:d(a.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[r(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:r(L.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"}),r(a.Box,{}),r(a.Box,{})]})})}),s0=T.observer(e=>d(B,{children:[r(r0,{...e}),r(a0,{})]})),L1="",P1="";function o0(e,t,n){const i=[];return e.filter(s=>"__INTERACTIONS"in s.viz.conf).forEach((s,o)=>{const l=t[s.id];l.data.interactions=v.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:p}=s.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:b}=h,{config:_}=b;switch(g){case"builtin:op:open-link":let C=_.urlTemplate.substring(0,100);_.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:_.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":i.push({id:`OPERATION--${f}`,source:s.id,target:_.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(_.dictionary).map(S=>({key:S,label:n[S]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:_.filter_keys.map(S=>({key:S,label:n[S]}))});return;default:return}})}),i}function l0(e,t){const n=e.filters.keyLabelMap;return{edges:o0(e.panels.list,t,n),edgeNodes:[]}}function Fs(e,t,n){return e*t+e*n}function u0(e,t,n){return e*t+(e-1)*n}const hn=25,Sr=40,Ws=25,Tr=350,c0=150,d0=150,js=150,Ys=300,fn=40,Rs=25,p0=300;function h0(e,t){const n=v.keyBy(t,s=>s.id),i=[];return e.current.forEach((s,o)=>{s.panelIDs.forEach((l,u)=>{const c=Fs(u,fn,Rs)+Sr,p=n[l];if(!p){i.push({id:l,_node_type:"panel",parentNode:s.id,data:{label:`!: ${l}`},position:{x:hn,y:c},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:Ys,height:fn}});return}const f=p.title.trim()?`${p.title}`:p.viz.type;i.push({id:p.id,_node_type:"panel",parentNode:s.id,data:{label:f},position:{x:hn,y:c},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:Ys,height:fn}})})}),i}const f0={[J.Division]:"Div",[J.Modal]:"Modal",[J.Tabs]:"Tabs"},g0=Cs;function m0(e){return e.current.map((n,i)=>{const s=u0(n.panelIDs.length,fn,Rs)+Sr+Ws;let o=[];return n.type===J.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:`${f0[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,className:"light",style:{backgroundColor:g0[n.type],width:Tr,height:s}}})}function y0(e){const t=v.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==J.Tabs||n._tab_view_ids.forEach(i=>{t[i].parentNode=n.id})})}function b0(e){const t=m0(e.views);y0(t);const n=h0(e.views,e.panels.list);return[...t,...n]}function v0({nodeMap:e,nodes:t,edges:n}){t.forEach(i=>{i._node_type!=="view-root"||i._view_type!==J.Tabs||(i.sourcePosition=_e.Position.Bottom,i.style.width=Tr+hn*2,i.style.height=Ws+i._tab_view_ids.reduce((s,o)=>{const l=e[o];l.position.y=s,l.position.x=hn;const u=l.style.height;return s+u+20},Sr))})}function x0({nodeMap:e,nodes:t,edges:n}){n.filter(i=>i.label==="Open View").forEach(i=>{const s=e[i.source],o=e[i.target];if(!s||!o||!s.parentNode)return;const l=e[s.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((i,s)=>i._node_type==="view-root"&&s._node_type==="view-root"?i._view_level-s._view_level:i._node_type!=="view-root"&&s._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function C0({nodeMap:e,nodes:t,edges:n}){const i={};n.forEach(s=>{if(s.label!=="Open View")return;const o=e[s.source],l=e[s.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,p=Number(v.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+p0,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,b=v.get(i,g,0);l.position.y=b,i[g]=b+p+js}})}function w0({nodeMap:e,nodes:t,edges:n}){const i=new Set,s=new Set;n.forEach(l=>{i.add(l.source),s.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!i.has(l.id)&&!s.has(l.id)).forEach((l,u)=>{l.position.x=Fs(u,Tr,d0),l.position.y=0-c0-js})}function _0({nodeMap:e,nodes:t,edges:n}){const i={nodeMap:e,nodes:t,edges:n};return w0(i),x0(i),v0(i),C0(i),{nodes:t,edges:n}}function S0(e){const t=b0(e),n=v.keyBy(t,c=>c.id),{edges:i,edgeNodes:s}=l0(e,n),o=[...t,...s],l=v.keyBy(o,c=>c.id),u={edges:v.uniqBy(i,c=>c.id),nodes:o,nodeMap:l};return _0(u)}const O1="",Dr={"builtin:op:open-link":r(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:r(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":r(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:r(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":r(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:r(L.IconCircleOff,{size:14})})};function T0(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Dr[n.schemaRef],text:d(a.Group,{spacing:4,children:[r(a.Text,{children:"Open: "}),r(a.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:i,label:s})=>{t.push({key:n.schemaRef+i,icon:Dr[n.schemaRef],text:r(a.Group,{spacing:4,children:d(a.Text,{children:["Set Filter: ",s]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:i,label:s})=>{t.push({key:n.schemaRef+i,icon:Dr[n.schemaRef],text:r(a.Group,{spacing:4,children:d(a.Text,{children:["Clear Filter: ",s]})})})});return}}),t}const D0=m.memo(({data:e,isConnectable:t,sourcePosition:n=_e.Position.Right,targetPosition:i=_e.Position.Left,...s})=>{const o=m.useMemo(()=>T0(e.interactions),[e.interactions]);return d(B,{children:[r(_e.Handle,{type:"target",position:i,isConnectable:t}),r(a.Box,{sx:{position:"absolute",top:0,right:0},children:r(D.ChevronsUpRight,{size:12})}),d(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[r(a.HoverCard.Target,{children:r(a.Text,{children:e.label})}),r(a.HoverCard.Dropdown,{children:r(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>r(a.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),r(_e.Handle,{type:"source",position:n,isConnectable:t})]})}),V1="",k0={interaction:D0},I0=T.observer(()=>{const e=U(),{edges:t,nodes:n}=S0(e);return d(_e,{nodes:n,edges:t,onNodesChange:v.noop,onEdgesChange:v.noop,onConnect:v.noop,className:"interactions-viewer",fitView:!0,nodeTypes:k0,children:[r(_e.MiniMap,{}),r(_e.Controls,{}),r(_e.Background,{})]})}),M0=T.observer(({opened:e,close:t})=>{const{freezeLayout:n}=m.useContext(He);return m.useEffect(()=>{n(e)},[e]),r(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:r(I0,{})})}),$0={"> 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 A0({onClick:e,name:t,active:n,openSettings:i}){return d(a.Box,{sx:{position:"relative"},children:[r(a.UnstyledButton,{sx:s=>({display:"block",width:"100%",padding:s.spacing.xs,borderRadius:0,position:"relative",color:s.black,"&:hover":{backgroundColor:s.colors.gray[0]},backgroundColor:n?s.colors.gray[2]:"transparent"}),children:r(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:r(a.Text,{size:"sm",children:t})})}),n&&r(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:r(a.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:r(L.IconAdjustments,{size:16})})})]})}const z0=T.observer(()=>{const e=de(),t=U(),n=m.useCallback(s=>()=>t.views.setIDOfVIE(s),[t]),i=s=>{e.editor.open(["_VIEWS_",s])};return d(a.Box,{sx:{position:"relative"},children:[t.views.options.map(s=>r(A0,{active:t.views.idOfVIE===s.value,name:s.label,onClick:n(s.value),openSettings:()=>i(s.value)},s.value)),r(a.Divider,{variant:"dashed"}),r(a.Button,{variant:"subtle",rightIcon:r(L.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"})]})}),E0=T.observer(()=>{const e=de(),t=U(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},i=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[s,o]=m.useState(!1),l=()=>o(!0),u=()=>o(!1);return d(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[d(a.Navbar.Section,{children:[d(a.Group,{grow:!0,spacing:0,sx:{...$0,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[r(a.Tooltip,{label:"Filters",withinPortal:!0,children:r(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:r(L.IconFilter,{size:20})})}),r(a.Tooltip,{label:"Queries",withinPortal:!0,children:r(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:r(L.IconDatabase,{size:20})})}),r(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:r(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:r(L.IconLink,{size:20})})})]}),r(M0,{opened:s,close:u})]}),r(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:r(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),r(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:r(z0,{})}),r(a.Navbar.Section,{children:r(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:r(a.Button,{size:"xs",leftIcon:r(L.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),L0=T.observer(function({config:t}){return d(B,{children:[r(a.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),r(tr,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),P0=[{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"}],O0=T.observer(function({config:t}){return d(B,{children:[d(a.Group,{children:[r(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),r(a.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),r(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),r(a.Select,{data:P0,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),r(As,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),r(a.NumberInput,{label:"Max Days",description:d(a.Group,{position:"apart",children:[r(a.Text,{children:"Set 0 to disable."}),d(a.Group,{spacing:4,children:[r(a.Text,{children:"This feature requires"}),r(a.Text,{color:"blue",children:"Clearable"}),r(a.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),kr=T.observer(({value:e,onChange:t})=>{const n=U(),i=m.useMemo(()=>n.queries.options,[n.queries.current]),s=i.length===0;return r(a.Select,{label:"Pick a query",data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:s,error:s?"You need to add a query in Data Settings":void 0})}),V0=`
471
471
  // row
472
472
  {
473
473
  label: string;
@@ -482,7 +482,7 @@ Check the top-level render call using <`+E+">.")}return M}}function fo(w,M){{if(
482
482
  parent_value: string;
483
483
  description?: string;
484
484
  }
485
- `,F0=()=>{const[e,t]=m.useState(!1);return d(B,{children:[r(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),r(a.Collapse,{in:e,children:r(st.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:G0})})]})},W0=T.observer(function({config:t}){return d(B,{children:[r(a.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),r(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),r(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),r(kr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),r(F0,{})]})}),j0=T.observer(function({filter:t}){const[n,i]=m.useState(t.plainDefaultValue);return m.useEffect(()=>{i(t.plainDefaultValue)},[t]),d(a.Box,{sx:{maxWidth:"480px"},children:[r(a.Text,{pb:"md",color:"gray",children:"Preview"}),r(Es,{filter:t,value:n,onChange:i}),r(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),r(st.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Y0={select:q0,"multi-select":B0,"tree-select":W0,"text-input":N0,checkbox:L0,"date-range":O0},R0=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],Q0=T.observer(function({filter:t}){const n=U(),i=m.useMemo(()=>Y0[t.type],[t.type]);return d(a.Group,{grow:!0,spacing:20,align:"top",children:[d(a.Box,{sx:{maxWidth:"600px"},children:[r(a.Text,{pb:"md",color:"gray",children:"Edit"}),d(a.Stack,{children:[d(a.Group,{noWrap:!0,children:[r(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&r(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:s=>t.setAutoSubmit(s.currentTarget.checked),mt:22})]}),r(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),r(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:s=>{t.setKey(s.currentTarget.value)}}),r(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:s=>{t.setLabel(s.currentTarget.value)}}),r(a.Select,{label:"Widget",data:R0,required:!0,value:t.type,onChange:t.setType}),r(i,{config:t.config})]})]}),r(j0,{filter:t})]})}),U0=T.observer(({id:e})=>{const t=Ve.useModals(),n=de(),i=U();if(e==="")return null;const s=i.filters.findByID(e);if(!s)return d(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return d(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[r(a.Group,{position:"right",pt:10,children:r(a.Button,{size:"xs",color:"red",leftIcon:r(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),r(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:r(Q0,{filter:s})})]})}),K0=T.observer(()=>{const e=U(),[t,n]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){qt.showNotification({title:"Failed",message:o.message,color:"red"})}},s=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return d(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[r(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:r(a.Text,{weight:500,children:"Mock Context"})}),d(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[d(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[r(a.Text,{children:"A valid json string is required"}),r(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!s,onClick:i,children:r(D.DeviceFloppy,{size:20})})]})]})}),X0=T.observer(()=>{const{panel:e}=Te();return r(tr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Z0=T.observer(()=>{const{panel:e}=Te(),{style:t}=e;return r(B,{children:r(a.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})})}),J0=T.observer(()=>{const{panel:e}=Te(),{title:t,setTitle:n}=e,[i,s]=we.useInputState(t),o=t!==i,l=m.useCallback(()=>{o&&n(i)},[o,i]);return m.useEffect(()=>{s(t)},[t]),r(a.TextInput,{value:i,onChange:s,label:d(a.Group,{children:[r(a.Text,{children:"Panel Title"}),r(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:r(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function H0(){return d(a.Stack,{sx:{height:"100%"},children:[r(a.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),r(Z0,{}),r(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),r(J0,{}),r(X0,{})]})}const eC=({queryID:e})=>{const t=U(),{state:n,error:i}=t.getDataStuffByID(e),s=m.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:i?r(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):s!=null&&s.stateMessage?r(a.Text,{color:"gray",align:"center",children:s.stateMessage}):null},tC={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Us({data:e}){const t=m.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const i=Be.createColumnHelper();return Object.keys(e[0]).map(s=>i.accessor(s,{cell:o=>o.getValue()}))},[e]),n=Be.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Be.getCoreRowModel()});return e.length===0?r(a.Box,{sx:{height:"5em"}}):r(Le,{children:d(a.Table,{sx:tC,children:[r("thead",{children:n.getHeaderGroups().map(i=>r("tr",{children:i.headers.map(s=>d("th",{style:{width:s.getSize()},children:[s.isPlaceholder?null:Be.flexRender(s.column.columnDef.header,s.getContext()),r(a.ActionIcon,{onMouseDown:s.getResizeHandler(),onTouchStart:s.getResizeHandler(),className:`resizer ${s.column.getIsResizing()?"isResizing":""}`,children:r(D.ArrowBarToRight,{})})]},s.id))},i.id))}),r("tbody",{children:n.getRowModel().rows.map(i=>r("tr",{children:i.getVisibleCells().map(s=>r("td",{children:r(Le,{children:Be.flexRender(s.column.columnDef.cell,s.getContext())})},s.id))},i.id))})]})})}const Ir=T.observer(function({id:t,moreActions:n=null}){const i=U(),{data:s,state:o}=i.getDataStuffByID(t),l=o==="loading",u=()=>{i.queries.refetchDataByQueryID(t)},c=()=>{i.queries.downloadDataByQueryID(t)},p=m.useMemo(()=>Array.isArray(s)?s.slice(0,10):[],[s]),f=!Array.isArray(s)||s.length===0;return d(a.Stack,{sx:{border:"1px solid #eee"},children:[d(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[d(a.Group,{position:"left",children:[r(a.Text,{weight:500,children:"Preview Data"}),s.length>10&&d(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",s.length]})]}),d(a.Group,{pr:15,children:[n,r(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:r(D.Refresh,{size:16})}),r(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:r(D.Download,{size:16})})]})]}),d(a.Box,{sx:{position:"relative",overflow:"auto"},children:[r(a.LoadingOverlay,{visible:l}),r(eC,{queryID:t}),r(Us,{data:p})]})]})}),nC=T.observer(function(){const t=de(),n=U(),{panel:i}=Te(),[s,o]=m.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return d(B,{children:[r(a.Drawer,{opened:s,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:"xl",zIndex:320,children:r(a.Checkbox.Group,{orientation:"vertical",value:[...i.queryIDs],onChange:i.setQueryIDs,children:n.queries.options.map(u=>r(a.Checkbox,{label:u.label,value:u.value},u.value))})}),d(a.Stack,{spacing:6,children:[r(a.Group,{position:"right",children:r(a.Button,{variant:"light",size:"sm",leftIcon:r(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),i.queryIDs.length===1&&r(Ir,{id:i.queryIDs[0],moreActions:r(a.Tooltip,{label:"Open this query",children:r(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(i.queryIDs[0]),children:r(L.IconArrowCurveRight,{size:16})})})}),i.queryIDs.length>1&&d(a.Tabs,{defaultValue:i.queryIDs[0],children:[r(a.Tabs.List,{children:i.queries.map(u=>r(a.Tabs.Tab,{value:u.id,children:u.name},u.id))}),i.queries.map(u=>r(a.Tabs.Panel,{value:u.id,children:r(Ir,{id:u.id,moreActions:r(a.Tooltip,{label:"Open this query",children:r(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:r(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),rC=T.observer(()=>{const{panel:e}=Te();return r(Le,{children:r(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:d(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[d(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[r(a.Group,{children:r(Ps,{})}),r(a.Group,{grow:!0,position:"center",children:r(a.Text,{lineClamp:1,weight:"bold",children:e.title})}),r(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),r(a.Group,{px:5,pb:5,sx:{flexGrow:1},children:r(Ns,{panel:e,height:"410px"})})]})})})}),Mr={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{}},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class iC{constructor(t){V(this,"panel");V(this,"selected");this.panel=t,ie.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Mr.name)).length;this.panel.addVariable(v.cloneDeep({...Mr,name:`${Mr.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const i=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[i]}}}function aC(){const{panel:e}=Te();return X.useCreation(()=>new iC(e),[e])}const Ks=a.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),sC=m.forwardRef(function({value:t,onChange:n,data:i,withStyle:s=!0},o){const l=(u,c)=>{const p=v.cloneDeep(t);v.set(p,u,c),n(p)};return d(a.Box,{px:"sm",py:"md",ref:o,children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),r(j,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),r(Ut,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),r(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),r(Ne,{value:t.formatter,onChange:u=>l("formatter",u)}),s&&r(za,{value:t,onChange:n})]})}),oC=e=>{const{uiModel:t}=e;return r(a.Stack,{className:"var-list",children:t.variables.map(n=>r(a.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},lC=T.observer(oC),uC=({variable:e,data:t})=>r(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:r(a.Paper,{withBorder:!0,p:"md",children:Ea(e,t)})}),cC=T.observer(uC),dC=e=>{const t=X.useCreation(()=>yl(e.variable),[e.variable]),{classes:n}=Ks(),{data:i}=Te();return d(a.Group,{style:{height:"100%"},align:"start",children:[d(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[d(a.Group,{position:"right",children:[r(a.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:r(L.IconDeviceFloppy,{size:18})}),r(a.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:r(L.IconTrash,{size:18})})]}),r(sC,{value:y.getSnapshot(t.copy),onChange:t.update,data:i})]}),r(cC,{variable:y.getSnapshot(t.copy),data:i})]})},pC=T.observer(dC),hC=()=>{const e=aC(),{classes:t}=Ks();return d(a.Group,{className:t.root,noWrap:!0,align:"start",children:[r(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:d(a.Stack,{justify:"space-between",children:[r(a.Box,{className:"var-list-actions",children:r(a.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),r(lC,{uiModel:e})]})}),e.selected?r(B,{children:r(pC,{uiModel:e,variable:e.selected})}):r("span",{children:"Select or create a new variable on right side"})]})},fC=T.observer(hC);function gC(){const{vizManager:e}=m.useContext(je);return m.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return v.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const mC=T.observer(({value:e,submit:t})=>{const[n,i]=we.useInputState(e);m.useEffect(()=>{i(e)},[e]);const s=gC(),o=e!==n;return r(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:i,data:s,rightSection:r(a.ActionIcon,{disabled:!o,onClick:()=>t(n),children:r(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Xs=[];function yC(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function bC(){const{data:e,panel:{variables:t,viz:n,title:i,queryIDs:s,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:p,id:f}}=Te(),{vizManager:h}=m.useContext(je),g={title:i,description:o,viz:n,queryIDs:s,id:f},b={setDescription:l,addQueryID:c,removeQueryID:p,setTitle:u},_=Vs(g);try{return h.resolveComponent(g.viz.type),r(un,{configure:_,children:r(Ix,{variables:t,setVizConf:n.setConf,panel:g,panelInfoEditor:b,vizManager:h,data:e})})}catch(C){return console.info(v.get(C,"message")),null}}const vC=T.observer(()=>{const{data:e,panel:{viz:t}}=Te(),{vizManager:n}=m.useContext(je),i=m.useCallback(p=>{if(p===t.type)return;const f=yC(n,p);t.setType(p),t.setConf(f||{})},[t.type]),s=p=>{try{t.setConf(JSON.parse(p))}catch(f){console.error(f)}},o=m.useMemo(()=>{var p;return(p=Xs.find(f=>f.value===t.type))==null?void 0:p.Panel},[t.type,Xs]),l=bC(),u=o?m.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return d(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[r(mC,{submit:i,value:t.type}),d(Le,{children:[r(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&r(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})]})}),xC=T.observer(({panel:e,sourceViewID:t})=>{const n=U(),[i,s]=m.useState(t);m.useEffect(()=>{s(t)},[t]);const[o,{open:l,close:u}]=we.useDisclosure(!1),c=()=>{e.moveToView(t,i),u()};return d(B,{children:[r(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:r(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),r(a.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,overflow:"inside",children:d(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[r(a.Radio.Group,{value:i,onChange:s,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:r(a.Stack,{spacing:"xs",children:n.views.options.map(p=>r(a.Radio,{value:p.value,label:p.label},p.value))})}),d(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[r(a.Button,{size:"xs",color:"red",leftIcon:r(L.IconX,{size:14}),onClick:u,children:"Cancel"}),r(a.Button,{size:"xs",color:"blue",leftIcon:r(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:i===t,children:"Confirm"})]})]})})]})}),CC={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},Zs=({children:e})=>d(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[r(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),r(rC,{})]});function wC(e){return!["richText","button"].includes(e)}const _C=T.observer(({panel:e})=>{const t=Ve.useModals(),n=de(),i=U(),[s,o]=m.useState("Data"),l=e.queries,c=wC(e.viz.type)&&e.dataLoading,p=c||e.queryErrors.length>0||e.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];m.useEffect(()=>{o(b=>p&&b==="Visualization"?"Data":b)},[e.id,p]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return d(En,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors},children:[d(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[d(a.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),d(a.Group,{position:"right",noWrap:!0,children:[r(xC,{panel:e,sourceViewID:f}),r(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:r(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),d(a.Tabs,{value:s,onTabChange:o,keepMounted:!1,styles:CC,children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),r(a.Tabs.Tab,{value:"Panel",children:"Panel"}),r(a.Tabs.Tab,{value:"Variables",disabled:p,children:r(a.Tooltip,{label:"Requires data",disabled:!p,withinPortal:!0,zIndex:310,children:r(a.Text,{children:"Variables"})})}),r(a.Tabs.Tab,{value:"Visualization",disabled:p,children:r(a.Tooltip,{label:"Requires data",disabled:!p,withinPortal:!0,zIndex:310,children:r(a.Text,{children:"Visualization"})})}),r(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),d(a.Tabs.Panel,{value:"Data",children:[r(a.LoadingOverlay,{visible:c,exitTransitionDuration:0}),r(nC,{})]}),r(a.Tabs.Panel,{value:"Panel",children:r(Zs,{children:r(H0,{})})}),r(a.Tabs.Panel,{value:"Variables",children:r(fC,{})}),r(a.Tabs.Panel,{value:"Visualization",children:r(Le,{children:r(Zs,{children:r(vC,{})})})}),r(a.Tabs.Panel,{value:"Interactions",children:r(Le,{children:r(ou,{})})})]})]})}),SC=T.observer(({viewID:e,panelID:t})=>{const n=U();if(!n.views.findByID(e))return d(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const s=n.panels.findByID(t);return s?r(_C,{panel:s}):d(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Js=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:i,spacing:s=16,pl:o=0})=>d(a.Stack,{spacing:s,mt:6,pl:o,children:[Array.from(new Array(i-1),(l,u)=>r(a.Skeleton,{width:e,height:n,radius:"xs"},u)),r(a.Skeleton,{width:t,height:n,radius:"xs"})]}),Et=({value:e})=>e===null||e===""?null:r(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:r(a.ActionIcon,{children:r(L.IconInfoCircle,{size:14})})}),TC=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?r(a.Tooltip,{label:n,disabled:!n,children:r(a.Badge,{children:t})}):null},DC=T.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?r(Js,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:d(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{width:50}}),r("col",{style:{minWidth:300}}),r("col",{style:{width:30}}),r("col",{style:{width:70}}),r("col",{style:{minWidth:300}}),r("col",{style:{minWidth:80,width:80}}),r("col",{style:{minWidth:120,width:120}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"#"}),r("th",{children:"Column Name"}),r("th",{}),r("th",{}),r("th",{children:"Type"}),r("th",{children:"Nullable"}),r("th",{children:"Default Value"})]})}),r("tbody",{children:t.data.map(n=>d("tr",{children:[r("td",{children:n.ordinal_position}),r("td",{children:n.column_name}),r("td",{children:r(Et,{value:n.column_comment})}),r("td",{children:r(TC,{column:n})}),r("td",{children:n.column_type}),r("td",{children:n.is_nullable}),r("td",{children:r(Et,{value:n.column_default})})]},n.column_name))})]})}),kC=T.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return d(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{width:100}}),r("col",{style:{minWidth:300}}),r("col",{style:{width:150}}),r("col",{style:{width:150}}),r("col",{style:{width:250}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"Index Length"}),r("th",{children:"Index Name"}),r("th",{children:"Index Algorithm"}),r("th",{children:"Unique"}),r("th",{children:"Column Name"})]})}),r("tbody",{children:n.map(i=>d("tr",{children:[r("td",{children:i.index_length}),r("td",{children:i.index_name}),r("td",{children:i.index_algorithm}),r("td",{children:i.is_unique?"YES":"NO"}),r("td",{children:i.column_name})]},i.index_name))})]})}),IC=T.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return d(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{minWidth:300}}),r("col",{style:{width:150}}),r("col",{style:{width:100}}),r("col",{style:{width:100}}),r("col",{style:{width:100}}),r("col",{style:{width:100}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"Index Name"}),r("th",{children:"Index Algorithm"}),r("th",{children:"Unique"}),r("th",{children:"Definition"}),r("th",{children:"Condition"}),r("th",{children:"Comment"})]})}),r("tbody",{children:n.map(i=>d("tr",{children:[r("td",{children:i.index_name}),r("td",{children:i.index_algorithm}),r("td",{children:i.is_unique?"YES":"NO"}),r("td",{children:r(Et,{value:i.index_definition})}),r("td",{children:r(Et,{value:i.condition})}),r("td",{children:r(Et,{value:i.comment})})]},i.index_name))})]})}),MC=T.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===he.MySQL?r(kC,{dataSource:e}):e.type===he.Postgresql?r(IC,{dataSource:e}):null}),$C=T.observer(({dataSource:e})=>d(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[r(Le,{children:r(DC,{dataSource:e})}),r(Le,{children:r(MC,{dataSource:e})})]}));function AC({table_type:e}){return e==="VIEW"?r(L.IconEye,{size:14}):e==="BASE TABLE"?r(L.IconTable,{size:14}):null}const zC=T.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?r(Js,{height:"24px",lastWidth:"50%",count:15}):r(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,i])=>r(a.NavLink,{label:n,icon:r(L.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:i.map(s=>r(a.NavLink,{label:s.table_name,icon:r(AC,{table_type:s.table_type}),onClick:()=>{e.setKeywords(n,s.table_name)},active:e.table_name===s.table_name},s.table_name))},n))})}),EC=({visible:e})=>r(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:r(a.LoadingOverlay,{visible:e})}),LC=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],PC={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},OC=T.observer(({dataSource:e})=>{const{tableData:t}=e;return d(a.Group,{pt:10,px:10,position:"apart",children:[d(a.Group,{position:"left",children:[t.maxPage>1&&r(a.Pagination,{size:"sm",page:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{item:{height:"30px"}}}),r(a.Select,{icon:r(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:PC,data:LC,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),r(a.Group,{position:"right",children:d(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),VC=T.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?r(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?r(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?r(EC,{visible:!0}):d(Le,{children:[r(OC,{dataSource:e}),d(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[r(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),r(Us,{data:t.data})]})]})}),BC={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},qC=T.observer(({dataSource:e})=>(m.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?r(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):d(a.Flex,{sx:{height:"100%"},children:[r(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:r(Le,{children:r(zC,{dataSource:e})})}),d(a.Tabs,{defaultValue:"structure",styles:BC,children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"structure",icon:r(L.IconColumns,{size:14}),children:"Structure"}),r(a.Tabs.Tab,{value:"data",icon:r(L.IconDatabase,{size:14}),children:"Data"})]}),r(a.Tabs.Panel,{value:"structure",children:r($C,{dataSource:e})}),r(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:r(VC,{dataSource:e})})]})]}))),NC={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Hs=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,i]=m.useState(!1);return e.type==="http"?null:d(B,{children:[r(a.Modal,{opened:n,onClose:()=>i(!1),title:d(a.Group,{position:"apart",sx:{flexGrow:1},children:[r(a.Text,{fw:500,children:"Explorer Data Source"}),d(a.Group,{spacing:7,children:[r(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),r(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:NC,children:r(a.Box,{sx:{height:"calc(100vh - 220px)"},children:r(qC,{dataSource:e})})}),r(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),GC=m.forwardRef(({label:e,type:t,...n},i)=>d(a.Group,{position:"apart",ref:i,...n,children:[r(a.Text,{children:e}),r(a.Text,{children:t})]})),FC=T.observer(({value:e,onChange:t})=>{const n=de(),{data:i=[],loading:s}=X.useRequest(_n,{refreshDeps:[]},[]),o=m.useMemo(()=>i.map(p=>({label:p.key,value:p.key,type:p.type})),[i]),l=m.useMemo(()=>o.reduce((p,f)=>(p[f.value]=f.type,p),{}),[o]),u=p=>{p!==null&&t({key:p,type:l[p]})},c=m.useMemo(()=>n.datasources.find(e),[n,e]);return r(a.Select,{data:o,label:d(a.Group,{position:"apart",children:[r(a.Box,{children:"Data Source"}),c&&r(Hs,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:GC,rightSection:c?r(a.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:s,value:e.key,onChange:u})}),WC=e=>{const{queryModel:t}=e,n=de(),i=U(),o=i.findQueryUsage(t.id).length>0,l=Ve.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?r(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:r(a.Button,{color:"gray",size:"xs",leftIcon:r(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):r(a.Button,{color:"red",size:"xs",onClick:u,leftIcon:r(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},jC=T.observer(WC),YC=T.observer(({queryModel:e})=>{const[t,n]=m.useState(e.name);return m.useEffect(()=>{n(e.name)},[e.name]),r(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:d(a.Stack,{spacing:10,sx:{width:"100%"},children:[r(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),r(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:i=>{n(i.currentTarget.value)},rightSection:r(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:r(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),r(FC,{value:{type:e.type,key:e.key},onChange:({type:i,key:s})=>{e.setKey(s),e.setType(i)}}),r(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),r(a.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),e.typedAsHTTP&&r(a.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo}),r(a.Divider,{mt:20,mb:10,variant:"dashed"}),r(jC,{queryModel:e})]})})});function RC(){const[e,{open:t,close:n}]=we.useDisclosure(!1);return d(B,{children:[r(a.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:320,children:r(an,{value:Eo,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),r(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:r(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const QC=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{sx:{position:"relative",flexGrow:1},children:r(De,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},gn=m.forwardRef(({value:e,onChange:t,label:n,defaultValue:i},s)=>{const[o,l]=m.useState(e),u=()=>{t(o)},c=()=>{l(e)},p=()=>{l(i)};m.useEffect(()=>{l(e)},[e]);const f=o!==e;return d(a.Stack,{spacing:4,sx:{height:"100%"},children:[d(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[r(a.Group,{position:"left",children:r(RC,{})}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:p,size:"xs",variant:"default",leftIcon:r(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),r(a.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:r(L.IconRecycle,{size:16}),children:"Revert Changes"}),r(a.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:r(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),r(a.Text,{size:14,children:n}),r(QC,{value:o,onChange:l})]})});function UC({content:e}){return d(a.HoverCard,{width:"60vw",shadow:"md",children:[r(a.HoverCard.Target,{children:r(a.ActionIcon,{size:16,color:"blue",children:r(L.IconEye,{})})}),r(a.HoverCard.Dropdown,{children:r(st.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const KC=T.observer(()=>{const t=[...de().globalSQLSnippets.list];return t.length===0?null:d(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[r("thead",{children:d("tr",{children:[r("th",{children:"Key"}),r("th",{children:"Value"})]})}),r("tbody",{children:t.map(n=>{const{id:i,content:s}=n;return d("tr",{children:[r("td",{children:i}),r("td",{width:200,children:r(UC,{content:s})})]},i)})})]})}),XC=`
485
+ `,F0=()=>{const[e,t]=m.useState(!1);return d(B,{children:[r(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),r(a.Collapse,{in:e,children:r(st.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:G0})})]})},W0=T.observer(function({config:t}){return d(B,{children:[r(a.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),r(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),r(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),r(kr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),r(F0,{})]})}),j0=T.observer(function({filter:t}){const[n,i]=m.useState(t.plainDefaultValue);return m.useEffect(()=>{i(t.plainDefaultValue)},[t]),d(a.Box,{sx:{maxWidth:"480px"},children:[r(a.Text,{pb:"md",color:"gray",children:"Preview"}),r(Es,{filter:t,value:n,onChange:i}),r(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),r(st.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Y0={select:q0,"multi-select":B0,"tree-select":W0,"text-input":N0,checkbox:L0,"date-range":O0},R0=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],Q0=T.observer(function({filter:t}){const n=U(),i=m.useMemo(()=>Y0[t.type],[t.type]);return d(a.Group,{grow:!0,spacing:20,align:"top",children:[d(a.Box,{sx:{maxWidth:"600px"},children:[r(a.Text,{pb:"md",color:"gray",children:"Edit"}),d(a.Stack,{children:[d(a.Group,{noWrap:!0,children:[r(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&r(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:s=>t.setAutoSubmit(s.currentTarget.checked),mt:22})]}),r(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),r(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:s=>{t.setKey(s.currentTarget.value)}}),r(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:s=>{t.setLabel(s.currentTarget.value)}}),r(a.Select,{label:"Widget",data:R0,required:!0,value:t.type,onChange:t.setType}),r(i,{config:t.config})]})]}),r(j0,{filter:t})]})}),U0=T.observer(({id:e})=>{const t=Ve.useModals(),n=de(),i=U();if(e==="")return null;const s=i.filters.findByID(e);if(!s)return d(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return d(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[r(a.Group,{position:"right",pt:10,children:r(a.Button,{size:"xs",color:"red",leftIcon:r(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),r(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:r(Q0,{filter:s})})]})}),K0=T.observer(()=>{const e=U(),[t,n]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Bt.showNotification({title:"Failed",message:o.message,color:"red"})}},s=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return d(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[r(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:r(a.Text,{weight:500,children:"Mock Context"})}),d(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[d(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[r(a.Text,{children:"A valid json string is required"}),r(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!s,onClick:i,children:r(D.DeviceFloppy,{size:20})})]})]})}),X0=T.observer(()=>{const{panel:e}=Te();return r(tr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Z0=T.observer(()=>{const{panel:e}=Te(),{style:t}=e;return r(B,{children:r(a.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})})}),J0=T.observer(()=>{const{panel:e}=Te(),{title:t,setTitle:n}=e,[i,s]=we.useInputState(t),o=t!==i,l=m.useCallback(()=>{o&&n(i)},[o,i]);return m.useEffect(()=>{s(t)},[t]),r(a.TextInput,{value:i,onChange:s,label:d(a.Group,{children:[r(a.Text,{children:"Panel Title"}),r(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:r(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function H0(){return d(a.Stack,{sx:{height:"100%"},children:[r(a.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),r(Z0,{}),r(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),r(J0,{}),r(X0,{})]})}const eC=({queryID:e})=>{const t=U(),{state:n,error:i}=t.getDataStuffByID(e),s=m.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:i?r(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):s!=null&&s.stateMessage?r(a.Text,{color:"gray",align:"center",children:s.stateMessage}):null},tC={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Us({data:e}){const t=m.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const i=Be.createColumnHelper();return Object.keys(e[0]).map(s=>i.accessor(s,{cell:o=>o.getValue()}))},[e]),n=Be.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Be.getCoreRowModel()});return e.length===0?r(a.Box,{sx:{height:"5em"}}):r(Le,{children:d(a.Table,{sx:tC,children:[r("thead",{children:n.getHeaderGroups().map(i=>r("tr",{children:i.headers.map(s=>d("th",{style:{width:s.getSize()},children:[s.isPlaceholder?null:Be.flexRender(s.column.columnDef.header,s.getContext()),r(a.ActionIcon,{onMouseDown:s.getResizeHandler(),onTouchStart:s.getResizeHandler(),className:`resizer ${s.column.getIsResizing()?"isResizing":""}`,children:r(D.ArrowBarToRight,{})})]},s.id))},i.id))}),r("tbody",{children:n.getRowModel().rows.map(i=>r("tr",{children:i.getVisibleCells().map(s=>r("td",{children:r(Le,{children:Be.flexRender(s.column.columnDef.cell,s.getContext())})},s.id))},i.id))})]})})}const Ir=T.observer(function({id:t,moreActions:n=null}){const i=U(),{data:s,state:o}=i.getDataStuffByID(t),l=o==="loading",u=()=>{i.queries.refetchDataByQueryID(t)},c=()=>{i.queries.downloadDataByQueryID(t)},p=m.useMemo(()=>Array.isArray(s)?s.slice(0,10):[],[s]),f=!Array.isArray(s)||s.length===0;return d(a.Stack,{sx:{border:"1px solid #eee"},children:[d(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[d(a.Group,{position:"left",children:[r(a.Text,{weight:500,children:"Preview Data"}),s.length>10&&d(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",s.length]})]}),d(a.Group,{pr:15,children:[n,r(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:r(D.Refresh,{size:16})}),r(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:r(D.Download,{size:16})})]})]}),d(a.Box,{sx:{position:"relative",overflow:"auto"},children:[r(a.LoadingOverlay,{visible:l}),r(eC,{queryID:t}),r(Us,{data:p})]})]})}),nC=T.observer(function(){const t=de(),n=U(),{panel:i}=Te(),[s,o]=m.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return d(B,{children:[r(a.Drawer,{opened:s,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:"xl",zIndex:320,children:r(a.Checkbox.Group,{orientation:"vertical",value:[...i.queryIDs],onChange:i.setQueryIDs,children:n.queries.options.map(u=>r(a.Checkbox,{label:u.label,value:u.value},u.value))})}),d(a.Stack,{spacing:6,children:[r(a.Group,{position:"right",children:r(a.Button,{variant:"light",size:"sm",leftIcon:r(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),i.queryIDs.length===1&&r(Ir,{id:i.queryIDs[0],moreActions:r(a.Tooltip,{label:"Open this query",children:r(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(i.queryIDs[0]),children:r(L.IconArrowCurveRight,{size:16})})})}),i.queryIDs.length>1&&d(a.Tabs,{defaultValue:i.queryIDs[0],children:[r(a.Tabs.List,{children:i.queries.map(u=>r(a.Tabs.Tab,{value:u.id,children:u.name},u.id))}),i.queries.map(u=>r(a.Tabs.Panel,{value:u.id,children:r(Ir,{id:u.id,moreActions:r(a.Tooltip,{label:"Open this query",children:r(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:r(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),rC=T.observer(()=>{const{panel:e}=Te();return r(Le,{children:r(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:d(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[d(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[r(a.Group,{children:r(Ps,{})}),r(a.Group,{grow:!0,position:"center",children:r(a.Text,{lineClamp:1,weight:"bold",children:e.title})}),r(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),r(a.Group,{px:5,pb:5,sx:{flexGrow:1},children:r(Ns,{panel:e,height:"410px"})})]})})})}),Mr={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{}},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class iC{constructor(t){V(this,"panel");V(this,"selected");this.panel=t,ie.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Mr.name)).length;this.panel.addVariable(v.cloneDeep({...Mr,name:`${Mr.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const i=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[i]}}}function aC(){const{panel:e}=Te();return X.useCreation(()=>new iC(e),[e])}const Ks=a.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),sC=m.forwardRef(function({value:t,onChange:n,data:i,withStyle:s=!0},o){const l=(u,c)=>{const p=v.cloneDeep(t);v.set(p,u,c),n(p)};return d(a.Box,{px:"sm",py:"md",ref:o,children:[d(a.Group,{grow:!0,noWrap:!0,children:[r(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),r(j,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),r(Qt,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),r(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),r(Ne,{value:t.formatter,onChange:u=>l("formatter",u)}),s&&r(za,{value:t,onChange:n})]})}),oC=e=>{const{uiModel:t}=e;return r(a.Stack,{className:"var-list",children:t.variables.map(n=>r(a.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},lC=T.observer(oC),uC=({variable:e,data:t})=>r(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:r(a.Paper,{withBorder:!0,p:"md",children:Ea(e,t)})}),cC=T.observer(uC),dC=e=>{const t=X.useCreation(()=>yl(e.variable),[e.variable]),{classes:n}=Ks(),{data:i}=Te();return d(a.Group,{style:{height:"100%"},align:"start",children:[d(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[d(a.Group,{position:"right",children:[r(a.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:r(L.IconDeviceFloppy,{size:18})}),r(a.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:r(L.IconTrash,{size:18})})]}),r(sC,{value:y.getSnapshot(t.copy),onChange:t.update,data:i})]}),r(cC,{variable:y.getSnapshot(t.copy),data:i})]})},pC=T.observer(dC),hC=()=>{const e=aC(),{classes:t}=Ks();return d(a.Group,{className:t.root,noWrap:!0,align:"start",children:[r(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:d(a.Stack,{justify:"space-between",children:[r(a.Box,{className:"var-list-actions",children:r(a.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),r(lC,{uiModel:e})]})}),e.selected?r(B,{children:r(pC,{uiModel:e,variable:e.selected})}):r("span",{children:"Select or create a new variable on right side"})]})},fC=T.observer(hC);function gC(){const{vizManager:e}=m.useContext(je);return m.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return v.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const mC=T.observer(({value:e,submit:t})=>{const[n,i]=we.useInputState(e);m.useEffect(()=>{i(e)},[e]);const s=gC(),o=e!==n;return r(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:i,data:s,rightSection:r(a.ActionIcon,{disabled:!o,onClick:()=>t(n),children:r(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Xs=[];function yC(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function bC(){const{data:e,panel:{variables:t,viz:n,title:i,queryIDs:s,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:p,id:f}}=Te(),{vizManager:h}=m.useContext(je),g={title:i,description:o,viz:n,queryIDs:s,id:f},b={setDescription:l,addQueryID:c,removeQueryID:p,setTitle:u},_=Vs(g);try{return h.resolveComponent(g.viz.type),r(un,{configure:_,children:r(kx,{variables:t,setVizConf:n.setConf,panel:g,panelInfoEditor:b,vizManager:h,data:e})})}catch(C){return console.info(v.get(C,"message")),null}}const vC=T.observer(()=>{const{data:e,panel:{viz:t}}=Te(),{vizManager:n}=m.useContext(je),i=m.useCallback(p=>{if(p===t.type)return;const f=yC(n,p);t.setType(p),t.setConf(f||{})},[t.type]),s=p=>{try{t.setConf(JSON.parse(p))}catch(f){console.error(f)}},o=m.useMemo(()=>{var p;return(p=Xs.find(f=>f.value===t.type))==null?void 0:p.Panel},[t.type,Xs]),l=bC(),u=o?m.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return d(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[r(mC,{submit:i,value:t.type}),d(Le,{children:[r(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&r(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})]})}),xC=T.observer(({panel:e,sourceViewID:t})=>{const n=U(),[i,s]=m.useState(t);m.useEffect(()=>{s(t)},[t]);const[o,{open:l,close:u}]=we.useDisclosure(!1),c=()=>{e.moveToView(t,i),u()};return d(B,{children:[r(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:r(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),r(a.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,overflow:"inside",children:d(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[r(a.Radio.Group,{value:i,onChange:s,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:r(a.Stack,{spacing:"xs",children:n.views.options.map(p=>r(a.Radio,{value:p.value,label:p.label},p.value))})}),d(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[r(a.Button,{size:"xs",color:"red",leftIcon:r(L.IconX,{size:14}),onClick:u,children:"Cancel"}),r(a.Button,{size:"xs",color:"blue",leftIcon:r(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:i===t,children:"Confirm"})]})]})})]})}),CC={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},Zs=({children:e})=>d(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[r(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),r(rC,{})]});function wC(e){return!["richText","button"].includes(e)}const _C=T.observer(({panel:e})=>{const t=Ve.useModals(),n=de(),i=U(),[s,o]=m.useState("Data"),l=e.queries,c=wC(e.viz.type)&&e.dataLoading,p=c||e.queryErrors.length>0||e.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];m.useEffect(()=>{o(b=>p&&b==="Visualization"?"Data":b)},[e.id,p]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return d(En,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors},children:[d(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[d(a.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),d(a.Group,{position:"right",noWrap:!0,children:[r(xC,{panel:e,sourceViewID:f}),r(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:r(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),d(a.Tabs,{value:s,onTabChange:o,keepMounted:!1,styles:CC,children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),r(a.Tabs.Tab,{value:"Panel",children:"Panel"}),r(a.Tabs.Tab,{value:"Variables",disabled:p,children:r(a.Tooltip,{label:"Requires data",disabled:!p,withinPortal:!0,zIndex:310,children:r(a.Text,{children:"Variables"})})}),r(a.Tabs.Tab,{value:"Visualization",disabled:p,children:r(a.Tooltip,{label:"Requires data",disabled:!p,withinPortal:!0,zIndex:310,children:r(a.Text,{children:"Visualization"})})}),r(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),d(a.Tabs.Panel,{value:"Data",children:[r(a.LoadingOverlay,{visible:c,exitTransitionDuration:0}),r(nC,{})]}),r(a.Tabs.Panel,{value:"Panel",children:r(Zs,{children:r(H0,{})})}),r(a.Tabs.Panel,{value:"Variables",children:r(fC,{})}),r(a.Tabs.Panel,{value:"Visualization",children:r(Le,{children:r(Zs,{children:r(vC,{})})})}),r(a.Tabs.Panel,{value:"Interactions",children:r(Le,{children:r(ou,{})})})]})]})}),SC=T.observer(({viewID:e,panelID:t})=>{const n=U();if(!n.views.findByID(e))return d(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const s=n.panels.findByID(t);return s?r(_C,{panel:s}):d(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Js=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:i,spacing:s=16,pl:o=0})=>d(a.Stack,{spacing:s,mt:6,pl:o,children:[Array.from(new Array(i-1),(l,u)=>r(a.Skeleton,{width:e,height:n,radius:"xs"},u)),r(a.Skeleton,{width:t,height:n,radius:"xs"})]}),zt=({value:e})=>e===null||e===""?null:r(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:r(a.ActionIcon,{children:r(L.IconInfoCircle,{size:14})})}),TC=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?r(a.Tooltip,{label:n,disabled:!n,children:r(a.Badge,{children:t})}):null},DC=T.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?r(Js,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:d(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{width:50}}),r("col",{style:{minWidth:300}}),r("col",{style:{width:30}}),r("col",{style:{width:70}}),r("col",{style:{minWidth:300}}),r("col",{style:{minWidth:80,width:80}}),r("col",{style:{minWidth:120,width:120}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"#"}),r("th",{children:"Column Name"}),r("th",{}),r("th",{}),r("th",{children:"Type"}),r("th",{children:"Nullable"}),r("th",{children:"Default Value"})]})}),r("tbody",{children:t.data.map(n=>d("tr",{children:[r("td",{children:n.ordinal_position}),r("td",{children:n.column_name}),r("td",{children:r(zt,{value:n.column_comment})}),r("td",{children:r(TC,{column:n})}),r("td",{children:n.column_type}),r("td",{children:n.is_nullable}),r("td",{children:r(zt,{value:n.column_default})})]},n.column_name))})]})}),kC=T.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return d(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{width:100}}),r("col",{style:{minWidth:300}}),r("col",{style:{width:150}}),r("col",{style:{width:150}}),r("col",{style:{width:250}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"Index Length"}),r("th",{children:"Index Name"}),r("th",{children:"Index Algorithm"}),r("th",{children:"Unique"}),r("th",{children:"Column Name"})]})}),r("tbody",{children:n.map(i=>d("tr",{children:[r("td",{children:i.index_length}),r("td",{children:i.index_name}),r("td",{children:i.index_algorithm}),r("td",{children:i.is_unique?"YES":"NO"}),r("td",{children:i.column_name})]},i.index_name))})]})}),IC=T.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return d(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{minWidth:300}}),r("col",{style:{width:150}}),r("col",{style:{width:100}}),r("col",{style:{width:100}}),r("col",{style:{width:100}}),r("col",{style:{width:100}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"Index Name"}),r("th",{children:"Index Algorithm"}),r("th",{children:"Unique"}),r("th",{children:"Definition"}),r("th",{children:"Condition"}),r("th",{children:"Comment"})]})}),r("tbody",{children:n.map(i=>d("tr",{children:[r("td",{children:i.index_name}),r("td",{children:i.index_algorithm}),r("td",{children:i.is_unique?"YES":"NO"}),r("td",{children:r(zt,{value:i.index_definition})}),r("td",{children:r(zt,{value:i.condition})}),r("td",{children:r(zt,{value:i.comment})})]},i.index_name))})]})}),MC=T.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===he.MySQL?r(kC,{dataSource:e}):e.type===he.Postgresql?r(IC,{dataSource:e}):null}),$C=T.observer(({dataSource:e})=>d(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[r(Le,{children:r(DC,{dataSource:e})}),r(Le,{children:r(MC,{dataSource:e})})]}));function AC({table_type:e}){return e==="VIEW"?r(L.IconEye,{size:14}):e==="BASE TABLE"?r(L.IconTable,{size:14}):null}const zC=T.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?r(Js,{height:"24px",lastWidth:"50%",count:15}):r(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,i])=>r(a.NavLink,{label:n,icon:r(L.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:i.map(s=>r(a.NavLink,{label:s.table_name,icon:r(AC,{table_type:s.table_type}),onClick:()=>{e.setKeywords(n,s.table_name)},active:e.table_name===s.table_name},s.table_name))},n))})}),EC=({visible:e})=>r(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:r(a.LoadingOverlay,{visible:e})}),LC=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],PC={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},OC=T.observer(({dataSource:e})=>{const{tableData:t}=e;return d(a.Group,{pt:10,px:10,position:"apart",children:[d(a.Group,{position:"left",children:[t.maxPage>1&&r(a.Pagination,{size:"sm",page:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{item:{height:"30px"}}}),r(a.Select,{icon:r(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:PC,data:LC,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),r(a.Group,{position:"right",children:d(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),VC=T.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?r(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?r(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?r(EC,{visible:!0}):d(Le,{children:[r(OC,{dataSource:e}),d(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[r(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),r(Us,{data:t.data})]})]})}),BC={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},qC=T.observer(({dataSource:e})=>(m.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?r(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):d(a.Flex,{sx:{height:"100%"},children:[r(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:r(Le,{children:r(zC,{dataSource:e})})}),d(a.Tabs,{defaultValue:"structure",styles:BC,children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"structure",icon:r(L.IconColumns,{size:14}),children:"Structure"}),r(a.Tabs.Tab,{value:"data",icon:r(L.IconDatabase,{size:14}),children:"Data"})]}),r(a.Tabs.Panel,{value:"structure",children:r($C,{dataSource:e})}),r(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:r(VC,{dataSource:e})})]})]}))),NC={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Hs=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,i]=m.useState(!1);return e.type==="http"?null:d(B,{children:[r(a.Modal,{opened:n,onClose:()=>i(!1),title:d(a.Group,{position:"apart",sx:{flexGrow:1},children:[r(a.Text,{fw:500,children:"Explorer Data Source"}),d(a.Group,{spacing:7,children:[r(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),r(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:NC,children:r(a.Box,{sx:{height:"calc(100vh - 220px)"},children:r(qC,{dataSource:e})})}),r(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),GC=m.forwardRef(({label:e,type:t,...n},i)=>d(a.Group,{position:"apart",ref:i,...n,children:[r(a.Text,{children:e}),r(a.Text,{children:t})]})),FC=T.observer(({value:e,onChange:t})=>{const n=de(),{data:i=[],loading:s}=X.useRequest(_n,{refreshDeps:[]},[]),o=m.useMemo(()=>i.map(p=>({label:p.key,value:p.key,type:p.type})),[i]),l=m.useMemo(()=>o.reduce((p,f)=>(p[f.value]=f.type,p),{}),[o]),u=p=>{p!==null&&t({key:p,type:l[p]})},c=m.useMemo(()=>n.datasources.find(e),[n,e]);return r(a.Select,{data:o,label:d(a.Group,{position:"apart",children:[r(a.Box,{children:"Data Source"}),c&&r(Hs,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:GC,rightSection:c?r(a.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:s,value:e.key,onChange:u})}),WC=e=>{const{queryModel:t}=e,n=de(),i=U(),o=i.findQueryUsage(t.id).length>0,l=Ve.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?r(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:r(a.Button,{color:"gray",size:"xs",leftIcon:r(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):r(a.Button,{color:"red",size:"xs",onClick:u,leftIcon:r(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},jC=T.observer(WC),YC=T.observer(({queryModel:e})=>{const[t,n]=m.useState(e.name);return m.useEffect(()=>{n(e.name)},[e.name]),r(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:d(a.Stack,{spacing:10,sx:{width:"100%"},children:[r(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),r(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:i=>{n(i.currentTarget.value)},rightSection:r(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:r(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),r(FC,{value:{type:e.type,key:e.key},onChange:({type:i,key:s})=>{e.setKey(s),e.setType(i)}}),r(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),r(a.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),e.typedAsHTTP&&r(a.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo}),r(a.Divider,{mt:20,mb:10,variant:"dashed"}),r(jC,{queryModel:e})]})})});function RC(){const[e,{open:t,close:n}]=we.useDisclosure(!1);return d(B,{children:[r(a.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:320,children:r(rn,{value:Eo,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),r(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:r(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const QC=({value:e,onChange:t})=>{const n=i=>{i&&t(i)};return r(a.Box,{sx:{position:"relative",flexGrow:1},children:r(De,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},gn=m.forwardRef(({value:e,onChange:t,label:n,defaultValue:i},s)=>{const[o,l]=m.useState(e),u=()=>{t(o)},c=()=>{l(e)},p=()=>{l(i)};m.useEffect(()=>{l(e)},[e]);const f=o!==e;return d(a.Stack,{spacing:4,sx:{height:"100%"},children:[d(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[r(a.Group,{position:"left",children:r(RC,{})}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:p,size:"xs",variant:"default",leftIcon:r(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),r(a.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:r(L.IconRecycle,{size:16}),children:"Revert Changes"}),r(a.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:r(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),r(a.Text,{size:14,children:n}),r(QC,{value:o,onChange:l})]})});function UC({content:e}){return d(a.HoverCard,{width:"60vw",shadow:"md",children:[r(a.HoverCard.Target,{children:r(a.ActionIcon,{size:16,color:"blue",children:r(L.IconEye,{})})}),r(a.HoverCard.Dropdown,{children:r(st.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const KC=T.observer(()=>{const t=[...de().globalSQLSnippets.list];return t.length===0?null:d(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[r("thead",{children:d("tr",{children:[r("th",{children:"Key"}),r("th",{children:"Value"})]})}),r("tbody",{children:t.map(n=>{const{id:i,content:s}=n;return d("tr",{children:[r("td",{children:i}),r("td",{width:200,children:r(UC,{content:s})})]},i)})})]})}),XC=`
486
486
  -- You may reference query variables in SQL or VizConfig.
487
487
  SELECT *
488
488
  FROM commit
@@ -499,4 +499,4 @@ WHERE
499
499
  `),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
500
500
  `)},ZC=T.observer(({queryModel:e})=>e.typedAsHTTP?d(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),r(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),r($r,{})]}),r(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:r(gn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:to.pre})}),r(a.Tabs.Panel,{value:"post_process",p:"sm",children:r(gn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:to.post})})]}):null),JC=T.observer(({queryID:e,usage:t})=>{const n=de().editor,i=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}},s=o=>{n.setPath(["_VIEWS_",o])};return r(a.Stack,{py:"sm",px:"md",children:d(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[r("thead",{children:d("tr",{children:[r("th",{style:{width:100},children:"Type"}),r("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),r("th",{children:"In View(s)"})]})}),r("tbody",{children:t.map(o=>d("tr",{children:[r("td",{children:v.capitalize(o.type)}),r("td",{children:r(a.Anchor,{component:"button",type:"button",onClick:()=>i(o),children:o.label})}),r("td",{children:d(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>r(a.Anchor,{component:"button",type:"button",onClick:()=>s(l.id),children:r(a.Box,{children:l.label})})),o.views.length===0&&r(a.Box,{children:"--"})]})})]},o.id))})]})})}),Ar=({value:e,onChange:t,height:n="200px",defaultLanguage:i="sql",theme:s="vs-dark"})=>{const o=u=>{console.log("changing"),t==null||t(u??"")},l=!t;return r(De,{className:"minimal-monaco-editor",height:n,defaultLanguage:i,value:e,onChange:l?void 0:o,theme:s,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},HC=({value:e,height:t="200px",defaultLanguage:n="sql"})=>r(De,{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}}),ew=T.observer(({value:e})=>{const n=U().payloadForSQL,i=m.useMemo(()=>wn(e,n),[e,n]);return r(HC,{height:"100%",value:i})}),no={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
501
501
  `),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
502
- `)},tw=T.observer(({queryModel:e})=>{const[t,n]=m.useState(e.sql);m.useEffect(()=>{n(o=>o!==e.sql?e.sql:o)},[e.sql]);const i=t!==e.sql,s=()=>{e.setSQL(t)};return e.typedAsSQL?d(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Edit",children:d(a.Group,{spacing:14,position:"apart",children:["Edit SQL",r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!i,onClick:s,children:r(D.DeviceFloppy,{size:20})})]})}),r(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),r(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),r(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),r($r,{}),e.datasource&&r(Hs,{dataSource:e.datasource})]}),r(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:r(Ar,{height:"100%",value:t,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),r(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:r(ew,{value:e.sql})}),r(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:r(gn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:no.pre})}),r(a.Tabs.Panel,{value:"post_process",p:"sm",children:r(gn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:no.post})})]}):null}),mn={height:"calc(100% - 44px)",padding:0},nw=T.observer(({queryModel:e})=>{const t=U(),n=m.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[i,s]=m.useState(n);m.useEffect(()=>{s(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return r(a.Stack,{sx:{flexGrow:1},my:0,p:0,children:d(a.Tabs,{value:i,onTabChange:s,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[d(a.Tabs.List,{grow:!0,children:[r(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&r(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&r(a.Tabs.Tab,{value:"HTTP",children:"Request"}),r(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:r(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:r(a.Text,{children:"Data"})})}),r(a.Tabs.Tab,{value:"Usage",disabled:l,children:r(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:r(a.Text,{children:"Usage"})})})]}),r(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:r(YC,{queryModel:e})}),e.typedAsSQL&&r(a.Tabs.Panel,{value:"SQL",sx:mn,children:r(a.Stack,{sx:{height:"100%"},children:r(tw,{queryModel:e})})}),e.typedAsHTTP&&r(a.Tabs.Panel,{value:"HTTP",sx:mn,children:r(a.Stack,{sx:{height:"100%"},children:r(ZC,{queryModel:e})})}),r(a.Tabs.Panel,{value:"Data",sx:{...mn,overflow:"hidden"},children:r(Ir,{id:e.id})}),r(a.Tabs.Panel,{value:"Usage",sx:{...mn,overflow:"hidden"},children:r(JC,{queryID:e.id,usage:o})})]})})}),rw=T.observer(({id:e})=>{const n=U().queries.findByID(e);return e===""?null:n?r(a.Stack,{sx:{height:"100%"},spacing:"sm",children:r(nw,{queryModel:n})}):r(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),iw=T.observer(({value:e})=>{const n=U().payloadForSQL,i=m.useMemo(()=>wn(e,n),[e,n]);return r(Ar,{height:"100%",value:i})}),aw=T.observer(({item:e,remove:t,onKeyChanged:n})=>{const[i,s]=m.useState("SQL"),[o,l]=m.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,p=e.isADuplicatedKey(o),[f,h]=m.useState(e.value),g=()=>{e.setValue(f)};m.useEffect(()=>{l(e.key),h(e.value)},[e]);const b=f!==e.value,_=Ve.useModals(),C=()=>{_.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return d(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[d(a.Group,{sx:{alignItems:"end"},spacing:40,children:[r(a.TextInput,{label:p?"This key is occupied by another snippet":"Key",value:o,onChange:S=>{l(S.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:r(a.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||p,children:r(D.DeviceFloppy,{size:16})}),error:p}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),d(a.Tabs,{value:i,onTabChange:s,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[d(a.Tabs.List,{sx:{position:"relative"},children:[r(a.Tabs.Tab,{value:"SQL",children:"SQL"}),r(a.Tabs.Tab,{value:"Preview",children:"Preview"}),r($r,{}),r(a.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!b,sx:{position:"absolute",top:0,right:10},children:r(D.DeviceFloppy,{size:18})})]}),r(a.Tabs.Panel,{value:"SQL",pt:"sm",children:r(Ar,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),r(a.Tabs.Panel,{value:"Preview",pt:"sm",children:r(iw,{value:f})})]})]})}),sw=T.observer(({id:e})=>{const t=de(),n=U(),i=m.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!i)return d(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const s=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return r(aw,{item:i,remove:()=>{n.sqlSnippets.removeByKey(e),s()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),ow=T.observer(({view:e})=>!e||e.type!==J.Division?null:d(a.Stack,{children:[r(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),r(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),lw=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],uw=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],cw=T.observer(({view:e})=>{if(!e||e.type!==J.Tabs)return null;const t=e.config;return d(a.Stack,{children:[r(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),r(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:lw}),r(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:uw}),r(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),dw=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},pw=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e??br),u=g=>{l({...o,enabled:g})},c=()=>{s();const{enabled:g,func_content:b}=o,_={enabled:g,func_content:b};l(_),t(_)},p=()=>{s(),l(e)},f=g=>{l(b=>({...b,func_content:g}))},h=()=>{f(br.func_content)};return d(B,{children:[r(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:r(D.Settings,{size:14})}),r(a.Modal,{size:800,title:"Customize modal title",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),r(dw,{value:o.func_content,onChange:f,disabled:!o.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:h,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},hw=T.observer(({view:e})=>{if(!e||e.type!==J.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return d(a.Stack,{children:[r(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),d(a.Flex,{gap:10,children:[r(a.TextInput,{label:"Modal Title",value:n,onChange:v.noop,disabled:!0,sx:{flexGrow:1}}),r(pw,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),d(a.Group,{grow:!0,children:[r(a.TextInput,{label:"Width",value:t.width,onChange:i=>t.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),r(a.TextInput,{label:"Height",value:t.height,onChange:i=>t.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),fw=T.observer(({view:e})=>d(B,{children:[r(ow,{view:e}),r(hw,{view:e}),r(cw,{view:e})]})),gw=[{label:"Division",value:J.Division},{label:"Modal",value:J.Modal},{label:"Tabs",value:J.Tabs}],mw=T.observer(({view:e})=>e?d(a.Stack,{sx:{position:"relative"},children:[r(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),r(a.Select,{label:"Type",withinPortal:!0,value:e.type,onChange:e.setType,data:gw}),r(fw,{view:e})]}):null),yw=T.observer(({id:e})=>{const t=Ve.useModals(),n=de(),i=U();if(e==="")return null;const s=i.views.findByID(e);if(!s)return d(a.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:()=>{i.views.removeByID(e),o()},zIndex:320})};return d(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[r(a.Group,{position:"right",pt:10,children:r(a.Button,{size:"xs",color:"red",leftIcon:r(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),r(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:r(mw,{view:s})})]})});function bw(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function vw(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function xw(e){return e.length===2&&e[0]==="_FILTERS_"}function Cw(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function ww(e){return e.length===2&&e[0]==="_QUERIES_"}function _w(e){return e.length===2&&e[0]==="_VIEWS_"}function Sw(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const Tw=T.observer(()=>r(a.Stack,{sx:{height:"100%"},p:"sm",children:r(eo,{})})),Dw=T.observer(()=>{const e=de().editor,t=e.path;return bw(t)?r(Tw,{}):vw(t)?r(K0,{}):xw(t)?r(a.Box,{p:"xs",pl:20,children:r(U0,{id:t[1]})}):Cw(t)?r(sw,{id:t[1]}):ww(t)?r(rw,{id:t[1]}):_w(t)?r(a.Box,{p:"xs",pl:20,children:r(yw,{id:t[1]})}):Sw(t)?r(SC,{viewID:t[1],panelID:t[3]}):r(a.Box,{children:e.path})}),kw=T.observer(()=>r(Dw,{})),Iw=T.observer(()=>{const e=de(),t=()=>{const n=new Date().getTime().toString(),i={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:yr.TextInput,config:Zi(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(i),e.editor.setPath(["_FILTERS_",n])};return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),Mw=T.observer(({parentID:e})=>{const t=U();if(!e)return null;const n=t.views.findByID(e);return n?r(a.Button,{variant:"subtle",leftIcon:r(L.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"}):null}),$w=T.observer(()=>{const e=de(),t=()=>{const n=new Date().getTime().toString(),i={id:n,name:n,type:he.Postgresql,key:"",sql:""};e.content.queries.append(i),e.editor.setPath(["_QUERIES_",n])};return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),Aw=T.observer(()=>{const e=de(),t=()=>{const n=new Date().getTime().toString(),i={key:n,value:""};e.content.sqlSnippets.append(i),e.editor.setPath(["_SQL_SNIPPETS_",n])};return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),zw=T.observer(()=>{const e=U();return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),Ew=T.observer(({action_type:e,parentID:t})=>(U(),e==="_Add_A_Filter_"?r(Iw,{}):e==="_Add_A_SQL_SNIPPET_"?r(Aw,{}):e==="_Add_A_QUERY_"?r($w,{}):e==="_Add_A_VIEW_"?r(zw,{}):e==="_Add_A_PANEL_"?r(Mw,{parentID:t}):null)),ro=T.observer(({option:e})=>{var p;const t=de().editor,n=t.isOptionActive,i=n(t.path,e),s=t.isOptionOpened,o=t.navigate,l=s(e),[u,c]=m.useState(l);return m.useEffect(()=>{c(l)},[l]),r(a.NavLink,{active:i,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?r(e.Icon,{size:18}):null,children:(p=e.children)==null?void 0:p.map(f=>f._type==="ACTION"?r(Ew,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):r(ro,{option:f},f.value))},e.label)}),Lw=T.observer(()=>{const e=de();return r(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>r(ro,{option:t},t.value))})}),Pw=T.observer(()=>{const e=de();return d(a.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[r(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:r(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),r(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:r(Lw,{})}),r(a.Navbar.Section,{children:r(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:r(a.Button,{size:"xs",color:"red",leftIcon:r(L.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),Ow={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"}},Vw=T.observer(()=>{const e=de().editor;return r(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:r(a.AppShell,{padding:0,navbar:r(Pw,{}),styles:Ow,children:r(kw,{})})})}),Bw=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function qw(e){m.useEffect(()=>{if(De.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=Bw(e);De.loader.config({paths:{vs:n}}),De.loader.init().then(i=>console.log("monaco instance:",i))},[])}Wa();const Nw={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},Gw=({context:e,dashboard:t,content:n,update:i,className:s="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},p)=>{qw(o.monacoPath),qi(o);const{data:f=[]}=X.useRequest(_n),{data:h=[]}=X.useRequest(Ni),[g,b]=m.useState(!1),_=m.useMemo(()=>xr(t,n,f,h,e),[t,n]);m.useImperativeHandle(p,()=>_,[_]),Wi(_.content,!0),m.useEffect(()=>{_.context.replace(e)},[e]),m.useEffect(()=>{_.datasources.replace(f)},[f]),m.useEffect(()=>{_.globalSQLSnippets.replace(h)},[h]),m.useEffect(()=>ie.reaction(()=>ie.toJS(_.json),$=>{l==null||l($)}),[_]);const C=async()=>{await i(_.json,_.content.json)},S=X.useCreation(pr,[]),I=_r(S);return r(Ve.ModalsProvider,{children:r(Tn,{value:_,children:r(Sn,{value:_.content,children:r(He.Provider,{value:{layoutFrozen:g,freezeLayout:b,inEditMode:!0},children:r(je.Provider,{value:S,children:d(un,{configure:I,children:[r(a.AppShell,{padding:0,header:r(s0,{saveDashboardChanges:C,headerSlot:u,headerMenuItems:c}),navbar:r(E0,{}),styles:Nw,children:r(a.Box,{className:`${s} dashboard-root`,sx:{position:"relative"},children:_.content.views.visibleViews.map($=>r(Gs,{view:$},$.id))})}),r(Vw,{})]})})})})})})},Fw=T.observer(m.forwardRef(Gw)),B1="";Wa();const Ww=T.observer(({context:e,dashboard:t,content:n,className:i="dashboard",config:s,fullScreenPanelID:o,setFullScreenPanelID:l})=>{qi(s);const{data:u=[]}=X.useRequest(_n),{data:c=[]}=X.useRequest(Ni),p=m.useMemo(()=>xr(t,n,u,c,e),[t,n]);Wi(p.content,!1),m.useEffect(()=>{p.context.replace(e)},[e]),m.useEffect(()=>{p.datasources.replace(u)},[u]),m.useEffect(()=>{p.globalSQLSnippets.replace(c)},[c]);const f=X.useCreation(pr,[]),h=_r(f);return r(Ve.ModalsProvider,{children:r(Tn,{value:p,children:r(Sn,{value:p.content,children:r(Ln.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:r(He.Provider,{value:{layoutFrozen:!0,freezeLayout:v.noop,inEditMode:!1},children:r(a.Box,{className:`${i} dashboard-root`,children:r(je.Provider,{value:f,children:r(un,{configure:h,children:p.content.views.visibleViews.map(g=>r(pn,{view:g},g.id))})})})})})})})})});var zr={},jw={get exports(){return zr},set exports(e){zr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=o.format;s.en.ordinal=function(u){var c=["th","st","nd","rd"],p=u%100;return"["+u+(c[(p-20)%10]||c[p]||c[0])+"]"},o.format=function(u){var c=this,p=this.$locale();if(!this.isValid())return l.bind(this)(u);var f=this.$utils(),h=(u||"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(g){switch(g){case"Q":return Math.ceil((c.$M+1)/3);case"Do":return p.ordinal(c.$D);case"gggg":return c.weekYear();case"GGGG":return c.isoWeekYear();case"wo":return p.ordinal(c.week(),"W");case"w":case"ww":return f.s(c.week(),g==="w"?1:2,"0");case"W":case"WW":return f.s(c.isoWeek(),g==="W"?1:2,"0");case"k":case"kk":return f.s(String(c.$H===0?24:c.$H),g==="k"?1:2,"0");case"X":return Math.floor(c.$d.getTime()/1e3);case"x":return c.$d.getTime();case"z":return"["+c.offsetName()+"]";case"zzz":return"["+c.offsetName("long")+"]";default:return g}});return l.bind(this)(h)}}})})(jw);const Yw=zr;var Er={},Rw={get exports(){return Er},set exports(e){Er=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=function(c){var p=c.date,f=c.utc;return Array.isArray(p)?f?p.length?new Date(Date.UTC.apply(null,p)):new Date:p.length===1?s(String(p[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(p))):p},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(Rw);const Qw=Er;var Lr={},Uw={get exports(){return Lr},set exports(e){Lr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype;s.$g=function(g,b,_){return this.$utils().u(g)?this[b]:this.$set(_,g)},s.set=function(g,b){return this.$set(g,b)};var o=s.startOf;s.startOf=function(g,b){return this.$d=o.bind(this)(g,b).toDate(),this.init(),this};var l=s.add;s.add=function(g,b){return this.$d=l.bind(this)(g,b).toDate(),this.init(),this};var u=s.locale;s.locale=function(g,b){return g?(this.$L=u.bind(this)(g,b).$L,this):this.$L};var c=s.daysInMonth;s.daysInMonth=function(){return c.bind(this.clone())()};var p=s.isSame;s.isSame=function(g,b){return p.bind(this.clone())(g,b)};var f=s.isBefore;s.isBefore=function(g,b){return f.bind(this.clone())(g,b)};var h=s.isAfter;s.isAfter=function(g,b){return h.bind(this.clone())(g,b)}}})})(Uw);const Kw=Lr;var Pr={},Xw={get exports(){return Pr},set exports(e){Pr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype,o=s.format;s.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(p,f){var h,g=String(u.$y+543),b=p==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,b.concat(["0"]))});return o.bind(this)(c)}}})})(Xw);const Zw=Pr;var Or={},Jw={get exports(){return Or},set exports(e){Or=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){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"};i.prototype.calendar=function(u,c){var p=c||this.$locale().calendar||l,f=s(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",b=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,_=p[b]||l[b];return typeof _=="function"?_.call(this,s()):this.format(_)}}})})(Jw);const Hw=Or;var Vr={},e_={get exports(){return Vr},set exports(e){Vr=e}};(function(e,t){(function(n,i){e.exports=i()})(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"},i=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(C){return(C=+C)+(C>68?1900:2e3)},p=function(C){return function(S){this[C]=+S}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(S){if(!S||S==="Z")return 0;var I=S.match(/([+-]|\d\d)/g),$=60*I[1]+(+I[2]||0);return $===0?0:I[0]==="+"?-$:$}(C)}],h=function(C){var S=u[C];return S&&(S.indexOf?S:S.s.concat(S.f))},g=function(C,S){var I,$=u.meridiem;if($){for(var q=1;q<=24;q+=1)if(C.indexOf($(q,0,S))>-1){I=q>12;break}}else I=C===(S?"pm":"PM");return I},b={A:[l,function(C){this.afternoon=g(C,!1)}],a:[l,function(C){this.afternoon=g(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[s,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,p("seconds")],ss:[o,p("seconds")],m:[o,p("minutes")],mm:[o,p("minutes")],H:[o,p("hours")],h:[o,p("hours")],HH:[o,p("hours")],hh:[o,p("hours")],D:[o,p("day")],DD:[s,p("day")],Do:[l,function(C){var S=u.ordinal,I=C.match(/\d+/);if(this.day=I[0],S)for(var $=1;$<=31;$+=1)S($).replace(/\[|\]/g,"")===C&&(this.day=$)}],M:[o,p("month")],MM:[s,p("month")],MMM:[l,function(C){var S=h("months"),I=(h("monthsShort")||S.map(function($){return $.slice(0,3)})).indexOf(C)+1;if(I<1)throw new Error;this.month=I%12||I}],MMMM:[l,function(C){var S=h("months").indexOf(C)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,p("year")],YY:[s,function(C){this.year=c(C)}],YYYY:[/\d{4}/,p("year")],Z:f,ZZ:f};function _(C){var S,I;S=C,I=u&&u.formats;for(var $=(C=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,R,ne){var se=ne&&ne.toUpperCase();return R||I[ne]||n[ne]||I[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(le,fe,Ce){return fe||Ce.slice(1)})})).match(i),q=$.length,N=0;N<q;N+=1){var P=$[N],z=b[P],A=z&&z[0],F=z&&z[1];$[N]=F?{regex:A,parser:F}:P.replace(/^\[|\]$/g,"")}return function(K){for(var R={},ne=0,se=0;ne<q;ne+=1){var le=$[ne];if(typeof le=="string")se+=le.length;else{var fe=le.regex,Ce=le.parser,pe=K.slice(se),ye=fe.exec(pe)[0];Ce.call(R,ye),K=K.replace(ye,"")}}return function(ge){var Ie=ge.afternoon;if(Ie!==void 0){var Pe=ge.hours;Ie?Pe<12&&(ge.hours+=12):Pe===12&&(ge.hours=0),delete ge.afternoon}}(R),R}}return function(C,S,I){I.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(c=C.parseTwoDigitYear);var $=S.prototype,q=$.parse;$.parse=function(N){var P=N.date,z=N.utc,A=N.args;this.$u=z;var F=A[1];if(typeof F=="string"){var K=A[2]===!0,R=A[3]===!0,ne=K||R,se=A[2];R&&(se=A[2]),u=this.$locale(),!K&&se&&(u=I.Ls[se]),this.$d=function(pe,ye,ge){try{if(["x","X"].indexOf(ye)>-1)return new Date((ye==="X"?1e3:1)*pe);var Ie=_(ye)(pe),Pe=Ie.year,lt=Ie.month,yn=Ie.day,bn=Ie.hours,pi=Ie.minutes,hi=Ie.seconds,Lt=Ie.milliseconds,bt=Ie.zone,rt=new Date,ut=yn||(Pe||lt?1:rt.getDate()),it=Pe||rt.getFullYear(),vt=0;Pe&&!lt||(vt=lt>0?lt-1:rt.getMonth());var xt=bn||0,Pt=pi||0,Ot=hi||0,at=Lt||0;return bt?new Date(Date.UTC(it,vt,ut,xt,Pt,Ot,at+60*bt.offset*1e3)):ge?new Date(Date.UTC(it,vt,ut,xt,Pt,Ot,at)):new Date(it,vt,ut,xt,Pt,Ot,at)}catch{return new Date("")}}(P,F,z),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),ne&&P!=this.format(F)&&(this.$d=new Date("")),u={}}else if(F instanceof Array)for(var le=F.length,fe=1;fe<=le;fe+=1){A[1]=F[fe-1];var Ce=I.apply(this,A);if(Ce.isValid()){this.$d=Ce.$d,this.$L=Ce.$L,this.init();break}fe===le&&(this.$d=new Date(""))}else q.call(this,N)}}})})(e_);const t_=Vr;var Br={},n_={get exports(){return Br},set exports(e){Br=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.dayOfYear=function(o){var l=Math.round((s(this).startOf("day")-s(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(n_);const r_=Br;var qr={},i_={get exports(){return qr},set exports(e){qr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n,i,s=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,p=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:p,months:f,days:u,hours:l,minutes:o,seconds:s,milliseconds:1,weeks:6048e5},b=function(P){return P instanceof N},_=function(P,z,A){return new N(P,A,z.$l)},C=function(P){return i.p(P)+"s"},S=function(P){return P<0},I=function(P){return S(P)?Math.ceil(P):Math.floor(P)},$=function(P){return Math.abs(P)},q=function(P,z){return P?S(P)?{negative:!0,format:""+$(P)+z}:{negative:!1,format:""+P+z}:{negative:!1,format:""}},N=function(){function P(A,F,K){var R=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),F)return _(A*g[C(F)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(le){R.$d[C(le)]=A[le]}),this.calMilliseconds(),this;if(typeof A=="string"){var ne=A.match(h);if(ne){var se=ne.slice(2).map(function(le){return le!=null?Number(le):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var z=P.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(F,K){return F+(A.$d[K]||0)*g[K]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=I(A/p),A%=p,this.$d.months=I(A/f),A%=f,this.$d.days=I(A/u),A%=u,this.$d.hours=I(A/l),A%=l,this.$d.minutes=I(A/o),A%=o,this.$d.seconds=I(A/s),A%=s,this.$d.milliseconds=A},z.toISOString=function(){var A=q(this.$d.years,"Y"),F=q(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var R=q(K,"D"),ne=q(this.$d.hours,"H"),se=q(this.$d.minutes,"M"),le=this.$d.seconds||0;this.$d.milliseconds&&(le+=this.$d.milliseconds/1e3);var fe=q(le,"S"),Ce=A.negative||F.negative||R.negative||ne.negative||se.negative||fe.negative,pe=ne.format||se.format||fe.format?"T":"",ye=(Ce?"-":"")+"P"+A.format+F.format+R.format+pe+ne.format+se.format+fe.format;return ye==="P"||ye==="-P"?"P0D":ye},z.toJSON=function(){return this.toISOString()},z.format=function(A){var F=A||"YYYY-MM-DDTHH:mm:ss",K={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return F.replace(c,function(R,ne){return ne||String(K[R])})},z.as=function(A){return this.$ms/g[C(A)]},z.get=function(A){var F=this.$ms,K=C(A);return K==="milliseconds"?F%=1e3:F=K==="weeks"?I(F/g[K]):this.$d[K],F===0?0:F},z.add=function(A,F,K){var R;return R=F?A*g[C(F)]:b(A)?A.$ms:_(A,this).$ms,_(this.$ms+R*(K?-1:1),this)},z.subtract=function(A,F){return this.add(A,F,!0)},z.locale=function(A){var F=this.clone();return F.$l=A,F},z.clone=function(){return _(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")},P}();return function(P,z,A){n=A,i=A().$utils(),A.duration=function(R,ne){var se=A.locale();return _(R,{$l:se},ne)},A.isDuration=b;var F=z.prototype.add,K=z.prototype.subtract;z.prototype.add=function(R,ne){return b(R)&&(R=R.asMilliseconds()),F.bind(this)(R,ne)},z.prototype.subtract=function(R,ne){return b(R)&&(R=R.asMilliseconds()),K.bind(this)(R,ne)}}})})(i_);const a_=qr;var Nr={},s_={get exports(){return Nr},set exports(e){Nr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isBetween=function(o,l,u,c){var p=s(o),f=s(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(p,u):!this.isBefore(p,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(p,u):!this.isAfter(p,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(s_);const o_=Nr;var Gr={},l_={get exports(){return Gr},set exports(e){Gr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(l_);const u_=Gr;var Fr={},c_={get exports(){return Fr},set exports(e){Fr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){s.isMoment=function(o){return s.isDayjs(o)}}})})(c_);const d_=Fr;var Wr={},p_={get exports(){return Wr},set exports(e){Wr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="day";return function(i,s,o){var l=function(p){return p.add(4-p.isoWeekday(),n)},u=s.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(p){if(!this.$utils().u(p))return this.add(7*(p-this.isoWeek()),n);var f,h,g,b,_=l(this),C=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),b=4-g.isoWeekday(),g.isoWeekday()>4&&(b+=7),g.add(b,n));return _.diff(C,"week")+1},u.isoWeekday=function(p){return this.$utils().u(p)?this.day()||7:this.day(this.day()%7?p:p-7)};var c=u.startOf;u.startOf=function(p,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(p)==="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)(p,f)}}})})(p_);const h_=Wr;var jr={},f_={get exports(){return jr},set exports(e){jr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isoWeeksInYear=function(){var s=this.isLeapYear(),o=this.endOf("y").day();return o===4||s&&o===5?53:52}}})})(f_);const g_=jr;var Yr={},m_={get exports(){return Yr},set exports(e){Yr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isSameOrAfter=function(s,o){return this.isSame(s,o)||this.isAfter(s,o)}}})})(m_);const y_=Yr;var Rr={},b_={get exports(){return Rr},set exports(e){Rr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isSameOrBefore=function(s,o){return this.isSame(s,o)||this.isBefore(s,o)}}})})(b_);const v_=Rr;var Qr={},x_={get exports(){return Qr},set exports(e){Qr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isToday=function(){var o="YYYY-MM-DD",l=s();return this.format(o)===l.format(o)}}})})(x_);const C_=Qr;var Ur={},w_={get exports(){return Ur},set exports(e){Ur=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=s().add(1,"day");return this.format(o)===l.format(o)}}})})(w_);const __=Ur;var Kr={},S_={get exports(){return Kr},set exports(e){Kr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=s().subtract(1,"day");return this.format(o)===l.format(o)}}})})(S_);const T_=Kr;var Xr={},D_={get exports(){return Xr},set exports(e){Xr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,b,_,C){var S=h.name?h:h.$locale(),I=l(S[g]),$=l(S[b]),q=I||$.map(function(P){return P.slice(0,_)});if(!C)return q;var N=S.weekStart;return q.map(function(P,z){return q[(z+(N||0))%7]})},c=function(){return s.Ls[s.locale()]},p=function(h,g){return h.formats[g]||function(b){return b.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(_,C,S){return C||S.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 p(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},s.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(g){return p(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},s.months=function(){return u(c(),"months")},s.monthsShort=function(){return u(c(),"monthsShort","months",3)},s.weekdays=function(h){return u(c(),"weekdays",null,null,h)},s.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},s.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(D_);const k_=Xr;var Zr={},I_={get exports(){return Zr},set exports(e){Zr=e}};(function(e,t){(function(n,i){e.exports=i()})(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(i,s,o){var l=s.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var p=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(b,_,C){var S=C&&C.toUpperCase();return _||g[C]||n[C]||g[S].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,$,q){return $||q.slice(1)})})}(c,p===void 0?{}:p);return u.call(this,f)}}})})(I_);const M_=Zr;var Jr={},$_={get exports(){return Jr},set exports(e){Jr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){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 p=1;p<u.length;p+=1)u[p].isValid()&&!u[p][l](c)||(c=u[p]);return c};s.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},s.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})($_);const A_=Jr;var Hr={},z_={get exports(){return Hr},set exports(e){Hr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=function(h){var g,b=h.date,_=h.utc,C={};if(!((g=b)instanceof Date)&&!(g instanceof Array)&&g instanceof Object){if(!Object.keys(b).length)return new Date;var S=_?s.utc():s();Object.keys(b).forEach(function(F){var K,R;C[K=F,R=o.$utils().p(K),R==="date"?"day":R]=b[F]});var I=C.day||(C.year||C.month>=0?1:S.date()),$=C.year||S.year(),q=C.month>=0?C.month:C.year||C.day?0:S.month(),N=C.hour||0,P=C.minute||0,z=C.second||0,A=C.millisecond||0;return _?new Date(Date.UTC($,q,I,N,P,z,A)):new Date($,q,I,N,P,z,A)}return b},u=o.parse;o.parse=function(h){h.date=l.bind(this)(h),u.bind(this)(h)};var c=o.set,p=o.add,f=function(h,g,b,_){if(_===void 0&&(_=1),g instanceof Object){var C=Object.keys(g),S=this;return C.forEach(function(I){S=h.bind(S)(g[I]*_,I)}),S}return h.bind(this)(g*_,b)};o.set=function(h,g){return g=g===void 0?h:g,f.bind(this)(function(b,_){return c.bind(this)(_,b)},g,h)},o.add=function(h,g){return f.bind(this)(p,h,g)},o.subtract=function(h,g){return f.bind(this)(p,h,g,-1)}}})})(z_);const E_=Hr;var ei={},L_={get exports(){return ei},set exports(e){ei=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){s[o]=s[o.replace(/s$/,"")]})}})})(L_);const P_=ei;var ti={},O_={get exports(){return ti},set exports(e){ti=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype.parse;i.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 s.bind(this)(u)};var o=i.prototype.format;i.prototype.format=function(){for(var u=arguments.length,c=new Array(u),p=0;p<u;p++)c[p]=arguments[p];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=i.prototype.fromToBase;l&&(i.prototype.fromToBase=function(u,c,p,f){var h=this.$locale()||p.$locale();return l.call(this,u,c,p,f,h&&h.postformat)})}})})(O_);const V_=ti;var ni={},B_={get exports(){return ni},set exports(e){ni=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="month",i="quarter";return function(s,o){var l=o.prototype;l.quarter=function(p){return this.$utils().u(p)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(p-1))};var u=l.add;l.add=function(p,f){return p=Number(p),this.$utils().p(f)===i?this.add(3*p,n):u.bind(this)(p,f)};var c=l.startOf;l.startOf=function(p,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(p)===i){var b=this.quarter()-1;return g?this.month(3*b).startOf(n).startOf("day"):this.month(3*b+2).endOf(n).endOf("day")}return c.bind(this)(p,f)}}})})(B_);const q_=ni;var ri={},N_={get exports(){return ri},set exports(e){ri=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){n=n||{};var o=i.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(p,f,h,g){return o.fromToBase(p,f,h,g)}s.en.relativeTime=l,o.fromToBase=function(p,f,h,g,b){for(var _,C,S,I=h.$locale().relativeTime||l,$=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"}],q=$.length,N=0;N<q;N+=1){var P=$[N];P.d&&(_=g?s(p).diff(h,P.d,!0):h.diff(p,P.d,!0));var z=(n.rounding||Math.round)(Math.abs(_));if(S=_>0,z<=P.r||!P.r){z<=1&&N>0&&(P=$[N-1]);var A=I[P.l];b&&(z=b(""+z)),C=typeof A=="string"?A.replace("%d",z):A(z,f,P.l,S);break}}if(f)return C;var F=S?I.future:I.past;return typeof F=="function"?F(C):F.replace("%s",C)},o.to=function(p,f){return u(p,f,this,!0)},o.from=function(p,f){return u(p,f,this)};var c=function(p){return p.$u?s.utc():s()};o.toNow=function(p){return this.to(c(this),p)},o.fromNow=function(p){return this.from(c(this),p)}}})})(N_);const G_=ri;var ii={},F_={get exports(){return ii},set exports(e){ii=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},i={};return function(s,o,l){var u,c=function(g,b,_){_===void 0&&(_={});var C=new Date(g),S=function(I,$){$===void 0&&($={});var q=$.timeZoneName||"short",N=I+"|"+q,P=i[N];return P||(P=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:I,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:q}),i[N]=P),P}(b,_);return S.formatToParts(C)},p=function(g,b){for(var _=c(g,b),C=[],S=0;S<_.length;S+=1){var I=_[S],$=I.type,q=I.value,N=n[$];N>=0&&(C[N]=parseInt(q,10))}var P=C[3],z=P===24?0:P,A=C[0]+"-"+C[1]+"-"+C[2]+" "+z+":"+C[4]+":"+C[5]+":000",F=+g;return(l.utc(A).valueOf()-(F-=F%1e3))/6e4},f=o.prototype;f.tz=function(g,b){g===void 0&&(g=u);var _=this.utcOffset(),C=this.toDate(),S=C.toLocaleString("en-US",{timeZone:g}),I=Math.round((C-new Date(S))/1e3/60),$=l(S).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-I,!0);if(b){var q=$.utcOffset();$=$.add(_-q,"minute")}return $.$x.$timezone=g,$},f.offsetName=function(g){var b=this.$x.$timezone||l.tz.guess(),_=c(this.valueOf(),b,{timeZoneName:g}).find(function(C){return C.type.toLowerCase()==="timezonename"});return _&&_.value};var h=f.startOf;f.startOf=function(g,b){if(!this.$x||!this.$x.$timezone)return h.call(this,g,b);var _=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(_,g,b).tz(this.$x.$timezone,!0)},l.tz=function(g,b,_){var C=_&&b,S=_||b||u,I=p(+l(),S);if(typeof g!="string")return l(g).tz(S);var $=function(z,A,F){var K=z-60*A*1e3,R=p(K,F);if(A===R)return[K,A];var ne=p(K-=60*(R-A)*1e3,F);return R===ne?[K,R]:[z-60*Math.min(R,ne)*1e3,Math.max(R,ne)]}(l.utc(g,C).valueOf(),I,S),q=$[0],N=$[1],P=l(q).utcOffset(N);return P.$x.$timezone=S,P},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(F_);const W_=ii;var ai={},j_={get exports(){return ai},set exports(e){ai=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(j_);const Y_=ai;var si={},R_={get exports(){return si},set exports(e){si=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.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}}}})})(R_);const Q_=si;var oi={},U_={get exports(){return oi},set exports(e){oi=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){s.updateLocale=function(o,l){var u=s.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(U_);const K_=oi;var li={},X_={get exports(){return li},set exports(e){li=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="minute",i=/[+-]\d\d(?::?\d\d)?/g,s=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(C){var S={date:C,utc:!0,args:arguments};return new l(S)},c.utc=function(C){var S=u(this.toDate(),{locale:this.$L,utc:!0});return C?S.add(this.utcOffset(),n):S},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var p=c.parse;c.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),p.call(this,C)};var f=c.init;c.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(C,S){var I=this.$utils().u;if(I(C))return this.$u?0:I(this.$offset)?h.call(this):this.$offset;if(typeof C=="string"&&(C=function(P){P===void 0&&(P="");var z=P.match(i);if(!z)return null;var A=(""+z[0]).match(s)||["-",0,0],F=A[0],K=60*+A[1]+ +A[2];return K===0?0:F==="+"?K:-K}(C),C===null))return this;var $=Math.abs(C)<=16?60*C:C,q=this;if(S)return q.$offset=$,q.$u=C===0,q;if(C!==0){var N=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(q=this.local().add($+N,n)).$offset=$,q.$x.$localOffset=N}else q=this.utc();return q};var g=c.format;c.format=function(C){var S=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,S)},c.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var b=c.toDate;c.toDate=function(C){return C==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():b.call(this)};var _=c.diff;c.diff=function(C,S,I){if(C&&this.$u===C.$u)return _.call(this,C,S,I);var $=this.local(),q=u(C).local();return _.call($,q,S,I)}}})})(X_);const Z_=li;var ui={},J_={get exports(){return ui},set exports(e){ui=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.weekday=function(s){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(s)?u:this.subtract(u,"day").add(s,"day")}}})})(J_);const H_=ui;var ci={},e1={get exports(){return ci},set exports(e){ci=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="week",i="year";return function(s,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 p=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(i).add(1,i).date(p),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(i).date(p).startOf(n).subtract(1,"millisecond"),b=this.diff(g,n,!0);return b<0?l(this).startOf("week").week():Math.ceil(b)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(e1);const t1=ci;var di={},n1={get exports(){return di},set exports(e){di=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.weekYear=function(){var s=this.month(),o=this.week(),l=this.year();return o===1&&s===11?l+1:s===0&&o>=52?l-1:l}}})})(n1);const r1=di;Y.extend(Yw),Y.extend(Qw),Y.extend(Kw),Y.extend(Zw),Y.extend(Hw),Y.extend(t_),Y.extend(r_),Y.extend(a_),Y.extend(o_),Y.extend(u_),Y.extend(d_),Y.extend(y_),Y.extend(v_),Y.extend(C_),Y.extend(__),Y.extend(T_),Y.extend(h_),Y.extend(g_),Y.extend(k_),Y.extend(M_),Y.extend(A_),Y.extend(E_),Y.extend(P_),Y.extend(V_),Y.extend(q_),Y.extend(G_),Y.extend(W_),Y.extend(Y_),Y.extend(Q_),Y.extend(K_),Y.extend(Z_),Y.extend(t1),Y.extend(r1),Y.extend(H_),Y.tz.setDefault("UTC");const i1=()=>Promise.resolve().then(()=>$l).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));k.ContentModel=zt,k.ContentModelContextProvider=Sn,k.ContextModel=ua,k.DashboardEditor=Fw,k.DashboardFilterType=yr,k.DashboardMode=xs,k.DashboardModel=Ms,k.DashboardViewEditor=Gs,k.DashboardViewRender=pn,k.EViewComponentType=J,k.FilterModel=kn,k.FiltersModel=Hi,k.FullScreenPanelContext=Ln,k.LayoutStateContext=He,k.ModelContextProvider=Tn,k.Panel=dn,k.PanelContextProvider=En,k.PanelModel=ys,k.PanelsModel=vs,k.QueriesModel=sa,k.QueryModel=aa,k.ReadOnlyDashboard=Ww,k.SQLSnippetModel=oa,k.SQLSnippetsModel=la,k.ViewComponentTypeBackground=Cs,k.ViewComponentTypeColor=Kv,k.ViewComponentTypeName=Uv,k.ViewModel=Ts,k.ViewsModel=Ds,k.applyPartialDashboard=rx,k.createContentModel=Is,k.createDashboardModel=xr,k.createDashboardViewsModel=vr,k.getInitialFiltersPayload=ea,k.getNewPanel=bs,k.getVersion=i1,k.initialDashboardContent=Xv,k.useContentModelContext=U,k.useFullScreenPanelContext=ka,k.useModelContext=de,k.usePanelContext=Te,k.useTopLevelServices=_r,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
502
+ `)},tw=T.observer(({queryModel:e})=>{const[t,n]=m.useState(e.sql);m.useEffect(()=>{n(o=>o!==e.sql?e.sql:o)},[e.sql]);const i=t!==e.sql,s=()=>{e.setSQL(t)};return e.typedAsSQL?d(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[d(a.Tabs.List,{children:[r(a.Tabs.Tab,{value:"Edit",children:d(a.Group,{spacing:14,position:"apart",children:["Edit SQL",r(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!i,onClick:s,children:r(D.DeviceFloppy,{size:20})})]})}),r(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),r(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),r(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),r($r,{}),e.datasource&&r(Hs,{dataSource:e.datasource})]}),r(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:r(Ar,{height:"100%",value:t,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),r(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:r(ew,{value:e.sql})}),r(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:r(gn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:no.pre})}),r(a.Tabs.Panel,{value:"post_process",p:"sm",children:r(gn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:no.post})})]}):null}),mn={height:"calc(100% - 44px)",padding:0},nw=T.observer(({queryModel:e})=>{const t=U(),n=m.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[i,s]=m.useState(n);m.useEffect(()=>{s(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return r(a.Stack,{sx:{flexGrow:1},my:0,p:0,children:d(a.Tabs,{value:i,onTabChange:s,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[d(a.Tabs.List,{grow:!0,children:[r(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&r(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&r(a.Tabs.Tab,{value:"HTTP",children:"Request"}),r(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:r(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:r(a.Text,{children:"Data"})})}),r(a.Tabs.Tab,{value:"Usage",disabled:l,children:r(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:r(a.Text,{children:"Usage"})})})]}),r(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:r(YC,{queryModel:e})}),e.typedAsSQL&&r(a.Tabs.Panel,{value:"SQL",sx:mn,children:r(a.Stack,{sx:{height:"100%"},children:r(tw,{queryModel:e})})}),e.typedAsHTTP&&r(a.Tabs.Panel,{value:"HTTP",sx:mn,children:r(a.Stack,{sx:{height:"100%"},children:r(ZC,{queryModel:e})})}),r(a.Tabs.Panel,{value:"Data",sx:{...mn,overflow:"hidden"},children:r(Ir,{id:e.id})}),r(a.Tabs.Panel,{value:"Usage",sx:{...mn,overflow:"hidden"},children:r(JC,{queryID:e.id,usage:o})})]})})}),rw=T.observer(({id:e})=>{const n=U().queries.findByID(e);return e===""?null:n?r(a.Stack,{sx:{height:"100%"},spacing:"sm",children:r(nw,{queryModel:n})}):r(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),iw=T.observer(({value:e})=>{const n=U().payloadForSQL,i=m.useMemo(()=>wn(e,n),[e,n]);return r(Ar,{height:"100%",value:i})}),aw=T.observer(({item:e,remove:t,onKeyChanged:n})=>{const[i,s]=m.useState("SQL"),[o,l]=m.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,p=e.isADuplicatedKey(o),[f,h]=m.useState(e.value),g=()=>{e.setValue(f)};m.useEffect(()=>{l(e.key),h(e.value)},[e]);const b=f!==e.value,_=Ve.useModals(),C=()=>{_.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return d(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[d(a.Group,{sx:{alignItems:"end"},spacing:40,children:[r(a.TextInput,{label:p?"This key is occupied by another snippet":"Key",value:o,onChange:S=>{l(S.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:r(a.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||p,children:r(D.DeviceFloppy,{size:16})}),error:p}),r(a.Button,{leftIcon:r(D.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),d(a.Tabs,{value:i,onTabChange:s,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[d(a.Tabs.List,{sx:{position:"relative"},children:[r(a.Tabs.Tab,{value:"SQL",children:"SQL"}),r(a.Tabs.Tab,{value:"Preview",children:"Preview"}),r($r,{}),r(a.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!b,sx:{position:"absolute",top:0,right:10},children:r(D.DeviceFloppy,{size:18})})]}),r(a.Tabs.Panel,{value:"SQL",pt:"sm",children:r(Ar,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),r(a.Tabs.Panel,{value:"Preview",pt:"sm",children:r(iw,{value:f})})]})]})}),sw=T.observer(({id:e})=>{const t=de(),n=U(),i=m.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!i)return d(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const s=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return r(aw,{item:i,remove:()=>{n.sqlSnippets.removeByKey(e),s()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),ow=T.observer(({view:e})=>!e||e.type!==J.Division?null:d(a.Stack,{children:[r(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),r(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),lw=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],uw=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],cw=T.observer(({view:e})=>{if(!e||e.type!==J.Tabs)return null;const t=e.config;return d(a.Stack,{children:[r(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),r(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:lw}),r(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:uw}),r(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),dw=({disabled:e,value:t,onChange:n})=>{const i=s=>{s&&n(s)};return d(a.Box,{sx:{position:"relative"},children:[e&&r(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},pw=({value:e,onChange:t})=>{const[n,{setTrue:i,setFalse:s}]=X.useBoolean(),[o,l]=m.useState(e??br),u=g=>{l({...o,enabled:g})},c=()=>{s();const{enabled:g,func_content:b}=o,_={enabled:g,func_content:b};l(_),t(_)},p=()=>{s(),l(e)},f=g=>{l(b=>({...b,func_content:g}))},h=()=>{f(br.func_content)};return d(B,{children:[r(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:r(D.Settings,{size:14})}),r(a.Modal,{size:800,title:"Customize modal title",opened:n,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(a.Stack,{children:[r(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),r(dw,{value:o.func_content,onChange:f,disabled:!o.enabled}),d(a.Group,{position:"apart",children:[r(a.Button,{onClick:h,color:"red",leftIcon:r(D.Recycle,{size:20}),children:"Rest"}),d(a.Group,{position:"right",children:[r(a.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},hw=T.observer(({view:e})=>{if(!e||e.type!==J.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return d(a.Stack,{children:[r(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),d(a.Flex,{gap:10,children:[r(a.TextInput,{label:"Modal Title",value:n,onChange:v.noop,disabled:!0,sx:{flexGrow:1}}),r(pw,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),d(a.Group,{grow:!0,children:[r(a.TextInput,{label:"Width",value:t.width,onChange:i=>t.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),r(a.TextInput,{label:"Height",value:t.height,onChange:i=>t.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),fw=T.observer(({view:e})=>d(B,{children:[r(ow,{view:e}),r(hw,{view:e}),r(cw,{view:e})]})),gw=[{label:"Division",value:J.Division},{label:"Modal",value:J.Modal},{label:"Tabs",value:J.Tabs}],mw=T.observer(({view:e})=>e?d(a.Stack,{sx:{position:"relative"},children:[r(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),r(a.Select,{label:"Type",withinPortal:!0,value:e.type,onChange:e.setType,data:gw}),r(fw,{view:e})]}):null),yw=T.observer(({id:e})=>{const t=Ve.useModals(),n=de(),i=U();if(e==="")return null;const s=i.views.findByID(e);if(!s)return d(a.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:()=>{i.views.removeByID(e),o()},zIndex:320})};return d(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[r(a.Group,{position:"right",pt:10,children:r(a.Button,{size:"xs",color:"red",leftIcon:r(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),r(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:r(mw,{view:s})})]})});function bw(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function vw(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function xw(e){return e.length===2&&e[0]==="_FILTERS_"}function Cw(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function ww(e){return e.length===2&&e[0]==="_QUERIES_"}function _w(e){return e.length===2&&e[0]==="_VIEWS_"}function Sw(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const Tw=T.observer(()=>r(a.Stack,{sx:{height:"100%"},p:"sm",children:r(eo,{})})),Dw=T.observer(()=>{const e=de().editor,t=e.path;return bw(t)?r(Tw,{}):vw(t)?r(K0,{}):xw(t)?r(a.Box,{p:"xs",pl:20,children:r(U0,{id:t[1]})}):Cw(t)?r(sw,{id:t[1]}):ww(t)?r(rw,{id:t[1]}):_w(t)?r(a.Box,{p:"xs",pl:20,children:r(yw,{id:t[1]})}):Sw(t)?r(SC,{viewID:t[1],panelID:t[3]}):r(a.Box,{children:e.path})}),kw=T.observer(()=>r(Dw,{})),Iw=T.observer(()=>{const e=de(),t=()=>{const n=new Date().getTime().toString(),i={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:yr.TextInput,config:Zi(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(i),e.editor.setPath(["_FILTERS_",n])};return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),Mw=T.observer(({parentID:e})=>{const t=U();if(!e)return null;const n=t.views.findByID(e);return n?r(a.Button,{variant:"subtle",leftIcon:r(L.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"}):null}),$w=T.observer(()=>{const e=de(),t=()=>{const n=new Date().getTime().toString(),i={id:n,name:n,type:he.Postgresql,key:"",sql:""};e.content.queries.append(i),e.editor.setPath(["_QUERIES_",n])};return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),Aw=T.observer(()=>{const e=de(),t=()=>{const n=new Date().getTime().toString(),i={key:n,value:""};e.content.sqlSnippets.append(i),e.editor.setPath(["_SQL_SNIPPETS_",n])};return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),zw=T.observer(()=>{const e=U();return r(a.Button,{variant:"subtle",leftIcon:r(L.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"})}),Ew=T.observer(({action_type:e,parentID:t})=>(U(),e==="_Add_A_Filter_"?r(Iw,{}):e==="_Add_A_SQL_SNIPPET_"?r(Aw,{}):e==="_Add_A_QUERY_"?r($w,{}):e==="_Add_A_VIEW_"?r(zw,{}):e==="_Add_A_PANEL_"?r(Mw,{parentID:t}):null)),ro=T.observer(({option:e})=>{var p;const t=de().editor,n=t.isOptionActive,i=n(t.path,e),s=t.isOptionOpened,o=t.navigate,l=s(e),[u,c]=m.useState(l);return m.useEffect(()=>{c(l)},[l]),r(a.NavLink,{active:i,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?r(e.Icon,{size:18}):null,children:(p=e.children)==null?void 0:p.map(f=>f._type==="ACTION"?r(Ew,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):r(ro,{option:f},f.value))},e.label)}),Lw=T.observer(()=>{const e=de();return r(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>r(ro,{option:t},t.value))})}),Pw=T.observer(()=>{const e=de();return d(a.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[r(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:r(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),r(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:r(Lw,{})}),r(a.Navbar.Section,{children:r(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:r(a.Button,{size:"xs",color:"red",leftIcon:r(L.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),Ow={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"}},Vw=T.observer(()=>{const e=de().editor;return r(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:r(a.AppShell,{padding:0,navbar:r(Pw,{}),styles:Ow,children:r(kw,{})})})}),Bw=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function qw(e){m.useEffect(()=>{if(De.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=Bw(e);De.loader.config({paths:{vs:n}}),De.loader.init().then(i=>console.log("monaco instance:",i))},[])}Wa();const Nw={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},Gw=({context:e,dashboard:t,content:n,update:i,className:s="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},p)=>{qw(o.monacoPath),qi(o);const{data:f=[]}=X.useRequest(_n),{data:h=[]}=X.useRequest(Ni),[g,b]=m.useState(!1),_=m.useMemo(()=>xr(t,n,f,h,e),[t,n]);m.useImperativeHandle(p,()=>_,[_]),Wi(_.content,!0),m.useEffect(()=>{_.context.replace(e)},[e]),m.useEffect(()=>{_.datasources.replace(f)},[f]),m.useEffect(()=>{_.globalSQLSnippets.replace(h)},[h]),m.useEffect(()=>ie.reaction(()=>ie.toJS(_.json),$=>{l==null||l($)}),[_]);const C=async()=>{await i(_.json,_.content.json)},S=X.useCreation(pr,[]),I=_r(S);return r(Ve.ModalsProvider,{children:r(Tn,{value:_,children:r(Sn,{value:_.content,children:r(He.Provider,{value:{layoutFrozen:g,freezeLayout:b,inEditMode:!0},children:r(je.Provider,{value:S,children:d(un,{configure:I,children:[r(a.AppShell,{padding:0,header:r(s0,{saveDashboardChanges:C,headerSlot:u,headerMenuItems:c}),navbar:r(E0,{}),styles:Nw,children:r(a.Box,{className:`${s} dashboard-root`,sx:{position:"relative"},children:_.content.views.visibleViews.map($=>r(Gs,{view:$},$.id))})}),r(Vw,{})]})})})})})})},Fw=T.observer(m.forwardRef(Gw)),B1="";Wa();const Ww=T.observer(({context:e,dashboard:t,content:n,className:i="dashboard",config:s,fullScreenPanelID:o,setFullScreenPanelID:l})=>{qi(s);const{data:u=[]}=X.useRequest(_n),{data:c=[]}=X.useRequest(Ni),p=m.useMemo(()=>xr(t,n,u,c,e),[t,n]);Wi(p.content,!1),m.useEffect(()=>{p.context.replace(e)},[e]),m.useEffect(()=>{p.datasources.replace(u)},[u]),m.useEffect(()=>{p.globalSQLSnippets.replace(c)},[c]);const f=X.useCreation(pr,[]),h=_r(f);return r(Ve.ModalsProvider,{children:r(Tn,{value:p,children:r(Sn,{value:p.content,children:r(Ln.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:r(He.Provider,{value:{layoutFrozen:!0,freezeLayout:v.noop,inEditMode:!1},children:r(a.Box,{className:`${i} dashboard-root`,children:r(je.Provider,{value:f,children:r(un,{configure:h,children:p.content.views.visibleViews.map(g=>r(pn,{view:g},g.id))})})})})})})})})});var zr={},jw={get exports(){return zr},set exports(e){zr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=o.format;s.en.ordinal=function(u){var c=["th","st","nd","rd"],p=u%100;return"["+u+(c[(p-20)%10]||c[p]||c[0])+"]"},o.format=function(u){var c=this,p=this.$locale();if(!this.isValid())return l.bind(this)(u);var f=this.$utils(),h=(u||"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(g){switch(g){case"Q":return Math.ceil((c.$M+1)/3);case"Do":return p.ordinal(c.$D);case"gggg":return c.weekYear();case"GGGG":return c.isoWeekYear();case"wo":return p.ordinal(c.week(),"W");case"w":case"ww":return f.s(c.week(),g==="w"?1:2,"0");case"W":case"WW":return f.s(c.isoWeek(),g==="W"?1:2,"0");case"k":case"kk":return f.s(String(c.$H===0?24:c.$H),g==="k"?1:2,"0");case"X":return Math.floor(c.$d.getTime()/1e3);case"x":return c.$d.getTime();case"z":return"["+c.offsetName()+"]";case"zzz":return"["+c.offsetName("long")+"]";default:return g}});return l.bind(this)(h)}}})})(jw);const Yw=zr;var Er={},Rw={get exports(){return Er},set exports(e){Er=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=function(c){var p=c.date,f=c.utc;return Array.isArray(p)?f?p.length?new Date(Date.UTC.apply(null,p)):new Date:p.length===1?s(String(p[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(p))):p},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(Rw);const Qw=Er;var Lr={},Uw={get exports(){return Lr},set exports(e){Lr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype;s.$g=function(g,b,_){return this.$utils().u(g)?this[b]:this.$set(_,g)},s.set=function(g,b){return this.$set(g,b)};var o=s.startOf;s.startOf=function(g,b){return this.$d=o.bind(this)(g,b).toDate(),this.init(),this};var l=s.add;s.add=function(g,b){return this.$d=l.bind(this)(g,b).toDate(),this.init(),this};var u=s.locale;s.locale=function(g,b){return g?(this.$L=u.bind(this)(g,b).$L,this):this.$L};var c=s.daysInMonth;s.daysInMonth=function(){return c.bind(this.clone())()};var p=s.isSame;s.isSame=function(g,b){return p.bind(this.clone())(g,b)};var f=s.isBefore;s.isBefore=function(g,b){return f.bind(this.clone())(g,b)};var h=s.isAfter;s.isAfter=function(g,b){return h.bind(this.clone())(g,b)}}})})(Uw);const Kw=Lr;var Pr={},Xw={get exports(){return Pr},set exports(e){Pr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype,o=s.format;s.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(p,f){var h,g=String(u.$y+543),b=p==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,b.concat(["0"]))});return o.bind(this)(c)}}})})(Xw);const Zw=Pr;var Or={},Jw={get exports(){return Or},set exports(e){Or=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){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"};i.prototype.calendar=function(u,c){var p=c||this.$locale().calendar||l,f=s(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",b=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,_=p[b]||l[b];return typeof _=="function"?_.call(this,s()):this.format(_)}}})})(Jw);const Hw=Or;var Vr={},e_={get exports(){return Vr},set exports(e){Vr=e}};(function(e,t){(function(n,i){e.exports=i()})(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"},i=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(C){return(C=+C)+(C>68?1900:2e3)},p=function(C){return function(S){this[C]=+S}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(S){if(!S||S==="Z")return 0;var I=S.match(/([+-]|\d\d)/g),$=60*I[1]+(+I[2]||0);return $===0?0:I[0]==="+"?-$:$}(C)}],h=function(C){var S=u[C];return S&&(S.indexOf?S:S.s.concat(S.f))},g=function(C,S){var I,$=u.meridiem;if($){for(var q=1;q<=24;q+=1)if(C.indexOf($(q,0,S))>-1){I=q>12;break}}else I=C===(S?"pm":"PM");return I},b={A:[l,function(C){this.afternoon=g(C,!1)}],a:[l,function(C){this.afternoon=g(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[s,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,p("seconds")],ss:[o,p("seconds")],m:[o,p("minutes")],mm:[o,p("minutes")],H:[o,p("hours")],h:[o,p("hours")],HH:[o,p("hours")],hh:[o,p("hours")],D:[o,p("day")],DD:[s,p("day")],Do:[l,function(C){var S=u.ordinal,I=C.match(/\d+/);if(this.day=I[0],S)for(var $=1;$<=31;$+=1)S($).replace(/\[|\]/g,"")===C&&(this.day=$)}],M:[o,p("month")],MM:[s,p("month")],MMM:[l,function(C){var S=h("months"),I=(h("monthsShort")||S.map(function($){return $.slice(0,3)})).indexOf(C)+1;if(I<1)throw new Error;this.month=I%12||I}],MMMM:[l,function(C){var S=h("months").indexOf(C)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,p("year")],YY:[s,function(C){this.year=c(C)}],YYYY:[/\d{4}/,p("year")],Z:f,ZZ:f};function _(C){var S,I;S=C,I=u&&u.formats;for(var $=(C=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,R,ne){var se=ne&&ne.toUpperCase();return R||I[ne]||n[ne]||I[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(le,fe,Ce){return fe||Ce.slice(1)})})).match(i),q=$.length,N=0;N<q;N+=1){var P=$[N],z=b[P],A=z&&z[0],F=z&&z[1];$[N]=F?{regex:A,parser:F}:P.replace(/^\[|\]$/g,"")}return function(K){for(var R={},ne=0,se=0;ne<q;ne+=1){var le=$[ne];if(typeof le=="string")se+=le.length;else{var fe=le.regex,Ce=le.parser,pe=K.slice(se),ye=fe.exec(pe)[0];Ce.call(R,ye),K=K.replace(ye,"")}}return function(ge){var Ie=ge.afternoon;if(Ie!==void 0){var Pe=ge.hours;Ie?Pe<12&&(ge.hours+=12):Pe===12&&(ge.hours=0),delete ge.afternoon}}(R),R}}return function(C,S,I){I.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(c=C.parseTwoDigitYear);var $=S.prototype,q=$.parse;$.parse=function(N){var P=N.date,z=N.utc,A=N.args;this.$u=z;var F=A[1];if(typeof F=="string"){var K=A[2]===!0,R=A[3]===!0,ne=K||R,se=A[2];R&&(se=A[2]),u=this.$locale(),!K&&se&&(u=I.Ls[se]),this.$d=function(pe,ye,ge){try{if(["x","X"].indexOf(ye)>-1)return new Date((ye==="X"?1e3:1)*pe);var Ie=_(ye)(pe),Pe=Ie.year,lt=Ie.month,yn=Ie.day,bn=Ie.hours,pi=Ie.minutes,hi=Ie.seconds,Et=Ie.milliseconds,bt=Ie.zone,rt=new Date,ut=yn||(Pe||lt?1:rt.getDate()),it=Pe||rt.getFullYear(),vt=0;Pe&&!lt||(vt=lt>0?lt-1:rt.getMonth());var xt=bn||0,Lt=pi||0,Pt=hi||0,at=Et||0;return bt?new Date(Date.UTC(it,vt,ut,xt,Lt,Pt,at+60*bt.offset*1e3)):ge?new Date(Date.UTC(it,vt,ut,xt,Lt,Pt,at)):new Date(it,vt,ut,xt,Lt,Pt,at)}catch{return new Date("")}}(P,F,z),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),ne&&P!=this.format(F)&&(this.$d=new Date("")),u={}}else if(F instanceof Array)for(var le=F.length,fe=1;fe<=le;fe+=1){A[1]=F[fe-1];var Ce=I.apply(this,A);if(Ce.isValid()){this.$d=Ce.$d,this.$L=Ce.$L,this.init();break}fe===le&&(this.$d=new Date(""))}else q.call(this,N)}}})})(e_);const t_=Vr;var Br={},n_={get exports(){return Br},set exports(e){Br=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.dayOfYear=function(o){var l=Math.round((s(this).startOf("day")-s(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(n_);const r_=Br;var qr={},i_={get exports(){return qr},set exports(e){qr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n,i,s=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,p=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:p,months:f,days:u,hours:l,minutes:o,seconds:s,milliseconds:1,weeks:6048e5},b=function(P){return P instanceof N},_=function(P,z,A){return new N(P,A,z.$l)},C=function(P){return i.p(P)+"s"},S=function(P){return P<0},I=function(P){return S(P)?Math.ceil(P):Math.floor(P)},$=function(P){return Math.abs(P)},q=function(P,z){return P?S(P)?{negative:!0,format:""+$(P)+z}:{negative:!1,format:""+P+z}:{negative:!1,format:""}},N=function(){function P(A,F,K){var R=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),F)return _(A*g[C(F)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(le){R.$d[C(le)]=A[le]}),this.calMilliseconds(),this;if(typeof A=="string"){var ne=A.match(h);if(ne){var se=ne.slice(2).map(function(le){return le!=null?Number(le):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var z=P.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(F,K){return F+(A.$d[K]||0)*g[K]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=I(A/p),A%=p,this.$d.months=I(A/f),A%=f,this.$d.days=I(A/u),A%=u,this.$d.hours=I(A/l),A%=l,this.$d.minutes=I(A/o),A%=o,this.$d.seconds=I(A/s),A%=s,this.$d.milliseconds=A},z.toISOString=function(){var A=q(this.$d.years,"Y"),F=q(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var R=q(K,"D"),ne=q(this.$d.hours,"H"),se=q(this.$d.minutes,"M"),le=this.$d.seconds||0;this.$d.milliseconds&&(le+=this.$d.milliseconds/1e3);var fe=q(le,"S"),Ce=A.negative||F.negative||R.negative||ne.negative||se.negative||fe.negative,pe=ne.format||se.format||fe.format?"T":"",ye=(Ce?"-":"")+"P"+A.format+F.format+R.format+pe+ne.format+se.format+fe.format;return ye==="P"||ye==="-P"?"P0D":ye},z.toJSON=function(){return this.toISOString()},z.format=function(A){var F=A||"YYYY-MM-DDTHH:mm:ss",K={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return F.replace(c,function(R,ne){return ne||String(K[R])})},z.as=function(A){return this.$ms/g[C(A)]},z.get=function(A){var F=this.$ms,K=C(A);return K==="milliseconds"?F%=1e3:F=K==="weeks"?I(F/g[K]):this.$d[K],F===0?0:F},z.add=function(A,F,K){var R;return R=F?A*g[C(F)]:b(A)?A.$ms:_(A,this).$ms,_(this.$ms+R*(K?-1:1),this)},z.subtract=function(A,F){return this.add(A,F,!0)},z.locale=function(A){var F=this.clone();return F.$l=A,F},z.clone=function(){return _(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")},P}();return function(P,z,A){n=A,i=A().$utils(),A.duration=function(R,ne){var se=A.locale();return _(R,{$l:se},ne)},A.isDuration=b;var F=z.prototype.add,K=z.prototype.subtract;z.prototype.add=function(R,ne){return b(R)&&(R=R.asMilliseconds()),F.bind(this)(R,ne)},z.prototype.subtract=function(R,ne){return b(R)&&(R=R.asMilliseconds()),K.bind(this)(R,ne)}}})})(i_);const a_=qr;var Nr={},s_={get exports(){return Nr},set exports(e){Nr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isBetween=function(o,l,u,c){var p=s(o),f=s(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(p,u):!this.isBefore(p,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(p,u):!this.isAfter(p,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(s_);const o_=Nr;var Gr={},l_={get exports(){return Gr},set exports(e){Gr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(l_);const u_=Gr;var Fr={},c_={get exports(){return Fr},set exports(e){Fr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){s.isMoment=function(o){return s.isDayjs(o)}}})})(c_);const d_=Fr;var Wr={},p_={get exports(){return Wr},set exports(e){Wr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="day";return function(i,s,o){var l=function(p){return p.add(4-p.isoWeekday(),n)},u=s.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(p){if(!this.$utils().u(p))return this.add(7*(p-this.isoWeek()),n);var f,h,g,b,_=l(this),C=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),b=4-g.isoWeekday(),g.isoWeekday()>4&&(b+=7),g.add(b,n));return _.diff(C,"week")+1},u.isoWeekday=function(p){return this.$utils().u(p)?this.day()||7:this.day(this.day()%7?p:p-7)};var c=u.startOf;u.startOf=function(p,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(p)==="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)(p,f)}}})})(p_);const h_=Wr;var jr={},f_={get exports(){return jr},set exports(e){jr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isoWeeksInYear=function(){var s=this.isLeapYear(),o=this.endOf("y").day();return o===4||s&&o===5?53:52}}})})(f_);const g_=jr;var Yr={},m_={get exports(){return Yr},set exports(e){Yr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isSameOrAfter=function(s,o){return this.isSame(s,o)||this.isAfter(s,o)}}})})(m_);const y_=Yr;var Rr={},b_={get exports(){return Rr},set exports(e){Rr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.isSameOrBefore=function(s,o){return this.isSame(s,o)||this.isBefore(s,o)}}})})(b_);const v_=Rr;var Qr={},x_={get exports(){return Qr},set exports(e){Qr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isToday=function(){var o="YYYY-MM-DD",l=s();return this.format(o)===l.format(o)}}})})(x_);const C_=Qr;var Ur={},w_={get exports(){return Ur},set exports(e){Ur=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=s().add(1,"day");return this.format(o)===l.format(o)}}})})(w_);const __=Ur;var Kr={},S_={get exports(){return Kr},set exports(e){Kr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){i.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=s().subtract(1,"day");return this.format(o)===l.format(o)}}})})(S_);const T_=Kr;var Xr={},D_={get exports(){return Xr},set exports(e){Xr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,b,_,C){var S=h.name?h:h.$locale(),I=l(S[g]),$=l(S[b]),q=I||$.map(function(P){return P.slice(0,_)});if(!C)return q;var N=S.weekStart;return q.map(function(P,z){return q[(z+(N||0))%7]})},c=function(){return s.Ls[s.locale()]},p=function(h,g){return h.formats[g]||function(b){return b.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(_,C,S){return C||S.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 p(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},s.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(g){return p(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},s.months=function(){return u(c(),"months")},s.monthsShort=function(){return u(c(),"monthsShort","months",3)},s.weekdays=function(h){return u(c(),"weekdays",null,null,h)},s.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},s.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(D_);const k_=Xr;var Zr={},I_={get exports(){return Zr},set exports(e){Zr=e}};(function(e,t){(function(n,i){e.exports=i()})(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(i,s,o){var l=s.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var p=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(b,_,C){var S=C&&C.toUpperCase();return _||g[C]||n[C]||g[S].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,$,q){return $||q.slice(1)})})}(c,p===void 0?{}:p);return u.call(this,f)}}})})(I_);const M_=Zr;var Jr={},$_={get exports(){return Jr},set exports(e){Jr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){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 p=1;p<u.length;p+=1)u[p].isValid()&&!u[p][l](c)||(c=u[p]);return c};s.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},s.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})($_);const A_=Jr;var Hr={},z_={get exports(){return Hr},set exports(e){Hr=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){var o=i.prototype,l=function(h){var g,b=h.date,_=h.utc,C={};if(!((g=b)instanceof Date)&&!(g instanceof Array)&&g instanceof Object){if(!Object.keys(b).length)return new Date;var S=_?s.utc():s();Object.keys(b).forEach(function(F){var K,R;C[K=F,R=o.$utils().p(K),R==="date"?"day":R]=b[F]});var I=C.day||(C.year||C.month>=0?1:S.date()),$=C.year||S.year(),q=C.month>=0?C.month:C.year||C.day?0:S.month(),N=C.hour||0,P=C.minute||0,z=C.second||0,A=C.millisecond||0;return _?new Date(Date.UTC($,q,I,N,P,z,A)):new Date($,q,I,N,P,z,A)}return b},u=o.parse;o.parse=function(h){h.date=l.bind(this)(h),u.bind(this)(h)};var c=o.set,p=o.add,f=function(h,g,b,_){if(_===void 0&&(_=1),g instanceof Object){var C=Object.keys(g),S=this;return C.forEach(function(I){S=h.bind(S)(g[I]*_,I)}),S}return h.bind(this)(g*_,b)};o.set=function(h,g){return g=g===void 0?h:g,f.bind(this)(function(b,_){return c.bind(this)(_,b)},g,h)},o.add=function(h,g){return f.bind(this)(p,h,g)},o.subtract=function(h,g){return f.bind(this)(p,h,g,-1)}}})})(z_);const E_=Hr;var ei={},L_={get exports(){return ei},set exports(e){ei=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){s[o]=s[o.replace(/s$/,"")]})}})})(L_);const P_=ei;var ti={},O_={get exports(){return ti},set exports(e){ti=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){var s=i.prototype.parse;i.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 s.bind(this)(u)};var o=i.prototype.format;i.prototype.format=function(){for(var u=arguments.length,c=new Array(u),p=0;p<u;p++)c[p]=arguments[p];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=i.prototype.fromToBase;l&&(i.prototype.fromToBase=function(u,c,p,f){var h=this.$locale()||p.$locale();return l.call(this,u,c,p,f,h&&h.postformat)})}})})(O_);const V_=ti;var ni={},B_={get exports(){return ni},set exports(e){ni=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="month",i="quarter";return function(s,o){var l=o.prototype;l.quarter=function(p){return this.$utils().u(p)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(p-1))};var u=l.add;l.add=function(p,f){return p=Number(p),this.$utils().p(f)===i?this.add(3*p,n):u.bind(this)(p,f)};var c=l.startOf;l.startOf=function(p,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(p)===i){var b=this.quarter()-1;return g?this.month(3*b).startOf(n).startOf("day"):this.month(3*b+2).endOf(n).endOf("day")}return c.bind(this)(p,f)}}})})(B_);const q_=ni;var ri={},N_={get exports(){return ri},set exports(e){ri=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){n=n||{};var o=i.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(p,f,h,g){return o.fromToBase(p,f,h,g)}s.en.relativeTime=l,o.fromToBase=function(p,f,h,g,b){for(var _,C,S,I=h.$locale().relativeTime||l,$=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"}],q=$.length,N=0;N<q;N+=1){var P=$[N];P.d&&(_=g?s(p).diff(h,P.d,!0):h.diff(p,P.d,!0));var z=(n.rounding||Math.round)(Math.abs(_));if(S=_>0,z<=P.r||!P.r){z<=1&&N>0&&(P=$[N-1]);var A=I[P.l];b&&(z=b(""+z)),C=typeof A=="string"?A.replace("%d",z):A(z,f,P.l,S);break}}if(f)return C;var F=S?I.future:I.past;return typeof F=="function"?F(C):F.replace("%s",C)},o.to=function(p,f){return u(p,f,this,!0)},o.from=function(p,f){return u(p,f,this)};var c=function(p){return p.$u?s.utc():s()};o.toNow=function(p){return this.to(c(this),p)},o.fromNow=function(p){return this.from(c(this),p)}}})})(N_);const G_=ri;var ii={},F_={get exports(){return ii},set exports(e){ii=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},i={};return function(s,o,l){var u,c=function(g,b,_){_===void 0&&(_={});var C=new Date(g),S=function(I,$){$===void 0&&($={});var q=$.timeZoneName||"short",N=I+"|"+q,P=i[N];return P||(P=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:I,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:q}),i[N]=P),P}(b,_);return S.formatToParts(C)},p=function(g,b){for(var _=c(g,b),C=[],S=0;S<_.length;S+=1){var I=_[S],$=I.type,q=I.value,N=n[$];N>=0&&(C[N]=parseInt(q,10))}var P=C[3],z=P===24?0:P,A=C[0]+"-"+C[1]+"-"+C[2]+" "+z+":"+C[4]+":"+C[5]+":000",F=+g;return(l.utc(A).valueOf()-(F-=F%1e3))/6e4},f=o.prototype;f.tz=function(g,b){g===void 0&&(g=u);var _=this.utcOffset(),C=this.toDate(),S=C.toLocaleString("en-US",{timeZone:g}),I=Math.round((C-new Date(S))/1e3/60),$=l(S).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-I,!0);if(b){var q=$.utcOffset();$=$.add(_-q,"minute")}return $.$x.$timezone=g,$},f.offsetName=function(g){var b=this.$x.$timezone||l.tz.guess(),_=c(this.valueOf(),b,{timeZoneName:g}).find(function(C){return C.type.toLowerCase()==="timezonename"});return _&&_.value};var h=f.startOf;f.startOf=function(g,b){if(!this.$x||!this.$x.$timezone)return h.call(this,g,b);var _=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(_,g,b).tz(this.$x.$timezone,!0)},l.tz=function(g,b,_){var C=_&&b,S=_||b||u,I=p(+l(),S);if(typeof g!="string")return l(g).tz(S);var $=function(z,A,F){var K=z-60*A*1e3,R=p(K,F);if(A===R)return[K,A];var ne=p(K-=60*(R-A)*1e3,F);return R===ne?[K,R]:[z-60*Math.min(R,ne)*1e3,Math.max(R,ne)]}(l.utc(g,C).valueOf(),I,S),q=$[0],N=$[1],P=l(q).utcOffset(N);return P.$x.$timezone=S,P},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(F_);const W_=ii;var ai={},j_={get exports(){return ai},set exports(e){ai=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(j_);const Y_=ai;var si={},R_={get exports(){return si},set exports(e){si=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.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}}}})})(R_);const Q_=si;var oi={},U_={get exports(){return oi},set exports(e){oi=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i,s){s.updateLocale=function(o,l){var u=s.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(U_);const K_=oi;var li={},X_={get exports(){return li},set exports(e){li=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="minute",i=/[+-]\d\d(?::?\d\d)?/g,s=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(C){var S={date:C,utc:!0,args:arguments};return new l(S)},c.utc=function(C){var S=u(this.toDate(),{locale:this.$L,utc:!0});return C?S.add(this.utcOffset(),n):S},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var p=c.parse;c.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),p.call(this,C)};var f=c.init;c.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(C,S){var I=this.$utils().u;if(I(C))return this.$u?0:I(this.$offset)?h.call(this):this.$offset;if(typeof C=="string"&&(C=function(P){P===void 0&&(P="");var z=P.match(i);if(!z)return null;var A=(""+z[0]).match(s)||["-",0,0],F=A[0],K=60*+A[1]+ +A[2];return K===0?0:F==="+"?K:-K}(C),C===null))return this;var $=Math.abs(C)<=16?60*C:C,q=this;if(S)return q.$offset=$,q.$u=C===0,q;if(C!==0){var N=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(q=this.local().add($+N,n)).$offset=$,q.$x.$localOffset=N}else q=this.utc();return q};var g=c.format;c.format=function(C){var S=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,S)},c.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var b=c.toDate;c.toDate=function(C){return C==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():b.call(this)};var _=c.diff;c.diff=function(C,S,I){if(C&&this.$u===C.$u)return _.call(this,C,S,I);var $=this.local(),q=u(C).local();return _.call($,q,S,I)}}})})(X_);const Z_=li;var ui={},J_={get exports(){return ui},set exports(e){ui=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.weekday=function(s){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(s)?u:this.subtract(u,"day").add(s,"day")}}})})(J_);const H_=ui;var ci={},e1={get exports(){return ci},set exports(e){ci=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){var n="week",i="year";return function(s,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 p=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(i).add(1,i).date(p),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(i).date(p).startOf(n).subtract(1,"millisecond"),b=this.diff(g,n,!0);return b<0?l(this).startOf("week").week():Math.ceil(b)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(e1);const t1=ci;var di={},n1={get exports(){return di},set exports(e){di=e}};(function(e,t){(function(n,i){e.exports=i()})(te,function(){return function(n,i){i.prototype.weekYear=function(){var s=this.month(),o=this.week(),l=this.year();return o===1&&s===11?l+1:s===0&&o>=52?l-1:l}}})})(n1);const r1=di;Y.extend(Yw),Y.extend(Qw),Y.extend(Kw),Y.extend(Zw),Y.extend(Hw),Y.extend(t_),Y.extend(r_),Y.extend(a_),Y.extend(o_),Y.extend(u_),Y.extend(d_),Y.extend(y_),Y.extend(v_),Y.extend(C_),Y.extend(__),Y.extend(T_),Y.extend(h_),Y.extend(g_),Y.extend(k_),Y.extend(M_),Y.extend(A_),Y.extend(E_),Y.extend(P_),Y.extend(V_),Y.extend(q_),Y.extend(G_),Y.extend(W_),Y.extend(Y_),Y.extend(Q_),Y.extend(K_),Y.extend(Z_),Y.extend(t1),Y.extend(r1),Y.extend(H_),Y.tz.setDefault("UTC");const i1=()=>Promise.resolve().then(()=>$l).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));k.ContentModel=ln,k.ContentModelContextProvider=Sn,k.ContextModel=ua,k.DashboardEditor=Fw,k.DashboardFilterType=yr,k.DashboardMode=xs,k.DashboardModel=Ms,k.DashboardViewEditor=Gs,k.DashboardViewRender=pn,k.EViewComponentType=J,k.FilterModel=kn,k.FiltersModel=Hi,k.FullScreenPanelContext=Ln,k.LayoutStateContext=He,k.ModelContextProvider=Tn,k.Panel=dn,k.PanelContextProvider=En,k.PanelModel=ys,k.PanelsModel=vs,k.QueriesModel=sa,k.QueryModel=aa,k.ReadOnlyDashboard=Ww,k.SQLSnippetModel=oa,k.SQLSnippetsModel=la,k.ViewComponentTypeBackground=Cs,k.ViewComponentTypeColor=Kv,k.ViewComponentTypeName=Uv,k.ViewModel=Ts,k.ViewsModel=Ds,k.applyPartialDashboard=rx,k.createContentModel=Is,k.createDashboardModel=xr,k.createDashboardViewsModel=vr,k.getInitialFiltersPayload=ea,k.getNewPanel=bs,k.getVersion=i1,k.initialDashboardContent=Xv,k.useContentModelContext=U,k.useFullScreenPanelContext=ka,k.useModelContext=de,k.usePanelContext=Te,k.useTopLevelServices=_r,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});