@devtable/dashboard 10.9.3 → 10.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(M,y){typeof exports=="object"&&typeof module<"u"?y(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-react"),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("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),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-react","@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","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],y):(M=typeof globalThis<"u"?globalThis:M||self,y(M.dashboard={},M.react,M["@mantine/core"],M["@mantine/modals"],M.ahooks,M.mobx,M["mobx-react-lite"],M.CryptoJS,M.dayjs,M._,M.numbro,M["d3-array"],M.mathjs,M["@faker-js/faker"],M.axios,M["mobx-state-tree"],M["performant-array-to-tree"],M.jszip,M["file-saver"],M["@tabler/icons-react"],M["@mantine/hooks"],M["@tanstack/react-table"],M["react-virtual"],M.eventemitter2,M["chroma-js"],M["echarts-gl"],M["echarts/core"],M["echarts/components"],M["echarts/renderers"],M["echarts-for-react/lib/core"],M["react-hook-form"],M["tabler-icons-react"],M["echarts/charts"],M["@mantine/notifications"],M.popmotion,M["@monaco-editor/react"],M["d3-regression"],M["@mantine/prism"],M["@mantine/tiptap"],M["@tiptap/extension-color"],M["@tiptap/extension-highlight"],M["@tiptap/extension-placeholder"],M["@tiptap/extension-subscript"],M["@tiptap/extension-superscript"],M["@tiptap/extension-text-align"],M["@tiptap/extension-text-style"],M["@tiptap/extension-table"],M["@tiptap/extension-table-cell"],M["@tiptap/extension-table-header"],M["@tiptap/extension-table-row"],M["@tiptap/extension-underline"],M["@tiptap/react"],M["@tiptap/starter-kit"],M["prosemirror-keymap"],M["prosemirror-commands"],M["prosemirror-schema-list"],M["@mantine/dates"],M["rc-select"],M["rc-tree-select"],M["react-grid-layout"],M["react-router-dom"],M.reactflow))})(this,function(M,y,s,Ue,X,ie,k,_a,R,x,ee,Yt,Xl,Jl,pt,b,Zl,Hl,cr,L,Me,Xe,eu,ka,st,nD,tu,G,Ve,Ne,v,D,pe,hn,_t,Ie,nu,kt,J,Ta,Da,Ma,Ia,Ea,Aa,za,$a,La,Oa,Pa,Ba,Va,Na,rD,Te,dr,ru,qa,Fa,fn,iu,Ee){"use strict";var eD=Object.defineProperty;var tD=(M,y,s)=>y in M?eD(M,y,{enumerable:!0,configurable:!0,writable:!0,value:s}):M[y]=s;var N=(M,y,s)=>(tD(M,typeof y!="symbol"?y+"":y,s),s);function gn(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const au=gn(Yt),mn=gn(Xl),le=gn(tu),ht=gn(nu);var ne=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Qt={},su={get exports(){return Qt},set exports(t){Qt=t}},Kt={};/**
1
+ (function(M,y){typeof exports=="object"&&typeof module<"u"?y(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-react"),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("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),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-react","@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","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],y):(M=typeof globalThis<"u"?globalThis:M||self,y(M.dashboard={},M.react,M["@mantine/core"],M["@mantine/modals"],M.ahooks,M.mobx,M["mobx-react-lite"],M.CryptoJS,M.dayjs,M._,M.numbro,M["d3-array"],M.mathjs,M["@faker-js/faker"],M.axios,M["mobx-state-tree"],M["performant-array-to-tree"],M.jszip,M["file-saver"],M["@tabler/icons-react"],M["@mantine/hooks"],M["@tanstack/react-table"],M["react-virtual"],M.eventemitter2,M["chroma-js"],M["echarts-gl"],M["echarts/core"],M["echarts/components"],M["echarts/renderers"],M["echarts-for-react/lib/core"],M["react-hook-form"],M["tabler-icons-react"],M["echarts/charts"],M["@mantine/notifications"],M.popmotion,M["@monaco-editor/react"],M["d3-regression"],M["@mantine/prism"],M["@mantine/tiptap"],M["@tiptap/extension-color"],M["@tiptap/extension-highlight"],M["@tiptap/extension-placeholder"],M["@tiptap/extension-subscript"],M["@tiptap/extension-superscript"],M["@tiptap/extension-text-align"],M["@tiptap/extension-text-style"],M["@tiptap/extension-table"],M["@tiptap/extension-table-cell"],M["@tiptap/extension-table-header"],M["@tiptap/extension-table-row"],M["@tiptap/extension-underline"],M["@tiptap/react"],M["@tiptap/starter-kit"],M["prosemirror-keymap"],M["prosemirror-commands"],M["prosemirror-schema-list"],M["@mantine/dates"],M["rc-select"],M["rc-tree-select"],M["react-grid-layout"],M["react-router-dom"],M.reactflow))})(this,function(M,y,s,Ue,X,ie,k,_a,R,x,ee,Yt,Xl,Jl,pt,b,Zl,Hl,cr,L,Me,Xe,eu,ka,st,rD,tu,G,Ve,Ne,v,D,pe,hn,_t,Ie,nu,kt,J,Ta,Da,Ma,Ia,Ea,Aa,za,$a,La,Oa,Pa,Ba,Va,Na,iD,Te,dr,ru,qa,Fa,fn,iu,Ee){"use strict";var tD=Object.defineProperty;var nD=(M,y,s)=>y in M?tD(M,y,{enumerable:!0,configurable:!0,writable:!0,value:s}):M[y]=s;var N=(M,y,s)=>(nD(M,typeof y!="symbol"?y+"":y,s),s);function gn(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const au=gn(Yt),mn=gn(Xl),le=gn(tu),ht=gn(nu);var ne=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Qt={},su={get exports(){return Qt},set exports(t){Qt=t}},Kt={};/**
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 Wa;function lu(){return Wa||(Wa=1,process.env.NODE_ENV!=="production"&&function(){var t=y,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=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"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),w=Symbol.iterator,C="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var z=w&&S[w]||S[C];return typeof z=="function"?z:null}var T=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function I(S){{for(var z=arguments.length,P=new Array(z>1?z-1:0),Q=1;Q<z;Q++)P[Q-1]=arguments[Q];O("error",S,P)}}function O(S,z,P){{var Q=T.ReactDebugCurrentFrame,se=Q.getStackAddendum();se!==""&&(z+="%s",P=P.concat([se]));var de=P.map(function(re){return String(re)});de.unshift("Warning: "+z),Function.prototype.apply.call(console[S],console,de)}}var B=!1,$=!1,A=!1,E=!1,F=!1,U;U=Symbol.for("react.module.reference");function Y(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||F||S===a||S===d||S===f||E||S===m||B||$||A||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===h||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===U||S.getModuleId!==void 0))}function Z(S,z,P){var Q=S.displayName;if(Q)return Q;var se=z.displayName||z.name||"";return se!==""?P+"("+se+")":P}function oe(S){return S.displayName||"Context"}function ue(S){if(S==null)return null;if(typeof S.tag=="number"&&I("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case a:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if(typeof S=="object")switch(S.$$typeof){case u:var z=S;return oe(z)+".Consumer";case l:var P=S;return oe(P._context)+".Provider";case c:return Z(S,S.render,"ForwardRef");case h:var Q=S.displayName||null;return Q!==null?Q:ue(S.type)||"Memo";case g:{var se=S,de=se._payload,re=se._init;try{return ue(re(de))}catch{return null}}}return null}var ye=Object.assign,De=0,ge,xe,ve,Oe,Qe,At,or;function lr(){}lr.__reactDisabledLog=!0;function ya(){{if(De===0){ge=console.log,xe=console.info,ve=console.warn,Oe=console.error,Qe=console.group,At=console.groupCollapsed,or=console.groupEnd;var S={configurable:!0,enumerable:!0,value:lr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}De++}}function ba(){{if(De--,De===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:ye({},S,{value:ge}),info:ye({},S,{value:xe}),warn:ye({},S,{value:ve}),error:ye({},S,{value:Oe}),group:ye({},S,{value:Qe}),groupCollapsed:ye({},S,{value:At}),groupEnd:ye({},S,{value:or})})}De<0&&I("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ln=T.ReactCurrentDispatcher,Ft;function wt(S,z,P){{if(Ft===void 0)try{throw Error()}catch(se){var Q=se.stack.trim().match(/\n( *(at )?)/);Ft=Q&&Q[1]||""}return`
17
+ */var Wa;function lu(){return Wa||(Wa=1,process.env.NODE_ENV!=="production"&&function(){var t=y,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=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"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),w=Symbol.iterator,C="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var z=w&&S[w]||S[C];return typeof z=="function"?z:null}var T=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function I(S){{for(var z=arguments.length,P=new Array(z>1?z-1:0),Q=1;Q<z;Q++)P[Q-1]=arguments[Q];O("error",S,P)}}function O(S,z,P){{var Q=T.ReactDebugCurrentFrame,se=Q.getStackAddendum();se!==""&&(z+="%s",P=P.concat([se]));var de=P.map(function(re){return String(re)});de.unshift("Warning: "+z),Function.prototype.apply.call(console[S],console,de)}}var B=!1,$=!1,A=!1,E=!1,F=!1,U;U=Symbol.for("react.module.reference");function Y(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||F||S===a||S===d||S===f||E||S===m||B||$||A||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===h||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===U||S.getModuleId!==void 0))}function Z(S,z,P){var Q=S.displayName;if(Q)return Q;var se=z.displayName||z.name||"";return se!==""?P+"("+se+")":P}function oe(S){return S.displayName||"Context"}function ue(S){if(S==null)return null;if(typeof S.tag=="number"&&I("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case a:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if(typeof S=="object")switch(S.$$typeof){case u:var z=S;return oe(z)+".Consumer";case l:var P=S;return oe(P._context)+".Provider";case c:return Z(S,S.render,"ForwardRef");case h:var Q=S.displayName||null;return Q!==null?Q:ue(S.type)||"Memo";case g:{var se=S,de=se._payload,re=se._init;try{return ue(re(de))}catch{return null}}}return null}var be=Object.assign,De=0,ge,xe,me,Oe,Qe,At,or;function lr(){}lr.__reactDisabledLog=!0;function ya(){{if(De===0){ge=console.log,xe=console.info,me=console.warn,Oe=console.error,Qe=console.group,At=console.groupCollapsed,or=console.groupEnd;var S={configurable:!0,enumerable:!0,value:lr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}De++}}function ba(){{if(De--,De===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:be({},S,{value:ge}),info:be({},S,{value:xe}),warn:be({},S,{value:me}),error:be({},S,{value:Oe}),group:be({},S,{value:Qe}),groupCollapsed:be({},S,{value:At}),groupEnd:be({},S,{value:or})})}De<0&&I("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ln=T.ReactCurrentDispatcher,Ft;function wt(S,z,P){{if(Ft===void 0)try{throw Error()}catch(se){var Q=se.stack.trim().match(/\n( *(at )?)/);Ft=Q&&Q[1]||""}return`
18
18
  `+Ft+S}}var zt=!1,Ct;{var Gt=typeof WeakMap=="function"?WeakMap:Map;Ct=new Gt}function Wt(S,z){if(!S||zt)return"";{var P=Ct.get(S);if(P!==void 0)return P}var Q;zt=!0;var se=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var de;de=ln.current,ln.current=null,ya();try{if(z){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(dt){Q=dt}Reflect.construct(S,[],re)}else{try{re.call()}catch(dt){Q=dt}S.call(re.prototype)}}else{try{throw Error()}catch(dt){Q=dt}S()}}catch(dt){if(dt&&Q&&typeof dt.stack=="string"){for(var te=dt.stack.split(`
19
19
  `),Be=Q.stack.split(`
20
20
  `),we=te.length-1,Se=Be.length-1;we>=1&&Se>=0&&te[we]!==Be[Se];)Se--;for(;we>=1&&Se>=0;we--,Se--)if(te[we]!==Be[Se]){if(we!==1||Se!==1)do if(we--,Se--,Se<0||te[we]!==Be[Se]){var Ke=`
21
- `+te[we].replace(" at new "," at ");return S.displayName&&Ke.includes("<anonymous>")&&(Ke=Ke.replace("<anonymous>",S.displayName)),typeof S=="function"&&Ct.set(S,Ke),Ke}while(we>=1&&Se>=0);break}}}finally{zt=!1,ln.current=de,ba(),Error.prepareStackTrace=se}var Rt=S?S.displayName||S.name:"",Ul=Rt?wt(Rt):"";return typeof S=="function"&&Ct.set(S,Ul),Ul}function un(S,z,P){return Wt(S,!1)}function cn(S){var z=S.prototype;return!!(z&&z.isReactComponent)}function St(S,z,P){if(S==null)return"";if(typeof S=="function")return Wt(S,cn(S));if(typeof S=="string")return wt(S);switch(S){case d:return wt("Suspense");case f:return wt("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return un(S.render);case h:return St(S.type,z,P);case g:{var Q=S,se=Q._payload,de=Q._init;try{return St(de(se),z,P)}catch{}}}return""}var dn=Object.prototype.hasOwnProperty,Bl={},Vl=T.ReactDebugCurrentFrame;function ur(S){if(S){var z=S._owner,P=St(S.type,S._source,z?z.type:null);Vl.setExtraStackFrame(P)}else Vl.setExtraStackFrame(null)}function LT(S,z,P,Q,se){{var de=Function.call.bind(dn);for(var re in S)if(de(S,re)){var te=void 0;try{if(typeof S[re]!="function"){var Be=Error((Q||"React class")+": "+P+" type `"+re+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[re]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Be.name="Invariant Violation",Be}te=S[re](z,re,Q,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(we){te=we}te&&!(te instanceof Error)&&(ur(se),I("%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",P,re,typeof te),ur(null)),te instanceof Error&&!(te.message in Bl)&&(Bl[te.message]=!0,ur(se),I("Failed %s type: %s",P,te.message),ur(null))}}}var OT=Array.isArray;function va(S){return OT(S)}function PT(S){{var z=typeof Symbol=="function"&&Symbol.toStringTag,P=z&&S[Symbol.toStringTag]||S.constructor.name||"Object";return P}}function BT(S){try{return Nl(S),!1}catch{return!0}}function Nl(S){return""+S}function ql(S){if(BT(S))return I("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",PT(S)),Nl(S)}var pn=T.ReactCurrentOwner,VT={key:!0,ref:!0,__self:!0,__source:!0},Fl,Gl,xa;xa={};function NT(S){if(dn.call(S,"ref")){var z=Object.getOwnPropertyDescriptor(S,"ref").get;if(z&&z.isReactWarning)return!1}return S.ref!==void 0}function qT(S){if(dn.call(S,"key")){var z=Object.getOwnPropertyDescriptor(S,"key").get;if(z&&z.isReactWarning)return!1}return S.key!==void 0}function FT(S,z){if(typeof S.ref=="string"&&pn.current&&z&&pn.current.stateNode!==z){var P=ue(pn.current.type);xa[P]||(I('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',ue(pn.current.type),S.ref),xa[P]=!0)}}function GT(S,z){{var P=function(){Fl||(Fl=!0,I("%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)",z))};P.isReactWarning=!0,Object.defineProperty(S,"key",{get:P,configurable:!0})}}function WT(S,z){{var P=function(){Gl||(Gl=!0,I("%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)",z))};P.isReactWarning=!0,Object.defineProperty(S,"ref",{get:P,configurable:!0})}}var jT=function(S,z,P,Q,se,de,re){var te={$$typeof:e,type:S,key:z,ref:P,props:re,_owner:de};return te._store={},Object.defineProperty(te._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(te,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Q}),Object.defineProperty(te,"_source",{configurable:!1,enumerable:!1,writable:!1,value:se}),Object.freeze&&(Object.freeze(te.props),Object.freeze(te)),te};function RT(S,z,P,Q,se){{var de,re={},te=null,Be=null;P!==void 0&&(ql(P),te=""+P),qT(z)&&(ql(z.key),te=""+z.key),NT(z)&&(Be=z.ref,FT(z,se));for(de in z)dn.call(z,de)&&!VT.hasOwnProperty(de)&&(re[de]=z[de]);if(S&&S.defaultProps){var we=S.defaultProps;for(de in we)re[de]===void 0&&(re[de]=we[de])}if(te||Be){var Se=typeof S=="function"?S.displayName||S.name||"Unknown":S;te&&GT(re,Se),Be&&WT(re,Se)}return jT(S,te,Be,se,Q,pn.current,re)}}var wa=T.ReactCurrentOwner,Wl=T.ReactDebugCurrentFrame;function jt(S){if(S){var z=S._owner,P=St(S.type,S._source,z?z.type:null);Wl.setExtraStackFrame(P)}else Wl.setExtraStackFrame(null)}var Ca;Ca=!1;function Sa(S){return typeof S=="object"&&S!==null&&S.$$typeof===e}function jl(){{if(wa.current){var S=ue(wa.current.type);if(S)return`
21
+ `+te[we].replace(" at new "," at ");return S.displayName&&Ke.includes("<anonymous>")&&(Ke=Ke.replace("<anonymous>",S.displayName)),typeof S=="function"&&Ct.set(S,Ke),Ke}while(we>=1&&Se>=0);break}}}finally{zt=!1,ln.current=de,ba(),Error.prepareStackTrace=se}var Rt=S?S.displayName||S.name:"",Ul=Rt?wt(Rt):"";return typeof S=="function"&&Ct.set(S,Ul),Ul}function un(S,z,P){return Wt(S,!1)}function cn(S){var z=S.prototype;return!!(z&&z.isReactComponent)}function St(S,z,P){if(S==null)return"";if(typeof S=="function")return Wt(S,cn(S));if(typeof S=="string")return wt(S);switch(S){case d:return wt("Suspense");case f:return wt("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return un(S.render);case h:return St(S.type,z,P);case g:{var Q=S,se=Q._payload,de=Q._init;try{return St(de(se),z,P)}catch{}}}return""}var dn=Object.prototype.hasOwnProperty,Bl={},Vl=T.ReactDebugCurrentFrame;function ur(S){if(S){var z=S._owner,P=St(S.type,S._source,z?z.type:null);Vl.setExtraStackFrame(P)}else Vl.setExtraStackFrame(null)}function OT(S,z,P,Q,se){{var de=Function.call.bind(dn);for(var re in S)if(de(S,re)){var te=void 0;try{if(typeof S[re]!="function"){var Be=Error((Q||"React class")+": "+P+" type `"+re+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[re]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Be.name="Invariant Violation",Be}te=S[re](z,re,Q,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(we){te=we}te&&!(te instanceof Error)&&(ur(se),I("%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",P,re,typeof te),ur(null)),te instanceof Error&&!(te.message in Bl)&&(Bl[te.message]=!0,ur(se),I("Failed %s type: %s",P,te.message),ur(null))}}}var PT=Array.isArray;function va(S){return PT(S)}function BT(S){{var z=typeof Symbol=="function"&&Symbol.toStringTag,P=z&&S[Symbol.toStringTag]||S.constructor.name||"Object";return P}}function VT(S){try{return Nl(S),!1}catch{return!0}}function Nl(S){return""+S}function ql(S){if(VT(S))return I("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",BT(S)),Nl(S)}var pn=T.ReactCurrentOwner,NT={key:!0,ref:!0,__self:!0,__source:!0},Fl,Gl,xa;xa={};function qT(S){if(dn.call(S,"ref")){var z=Object.getOwnPropertyDescriptor(S,"ref").get;if(z&&z.isReactWarning)return!1}return S.ref!==void 0}function FT(S){if(dn.call(S,"key")){var z=Object.getOwnPropertyDescriptor(S,"key").get;if(z&&z.isReactWarning)return!1}return S.key!==void 0}function GT(S,z){if(typeof S.ref=="string"&&pn.current&&z&&pn.current.stateNode!==z){var P=ue(pn.current.type);xa[P]||(I('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',ue(pn.current.type),S.ref),xa[P]=!0)}}function WT(S,z){{var P=function(){Fl||(Fl=!0,I("%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)",z))};P.isReactWarning=!0,Object.defineProperty(S,"key",{get:P,configurable:!0})}}function jT(S,z){{var P=function(){Gl||(Gl=!0,I("%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)",z))};P.isReactWarning=!0,Object.defineProperty(S,"ref",{get:P,configurable:!0})}}var RT=function(S,z,P,Q,se,de,re){var te={$$typeof:e,type:S,key:z,ref:P,props:re,_owner:de};return te._store={},Object.defineProperty(te._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(te,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Q}),Object.defineProperty(te,"_source",{configurable:!1,enumerable:!1,writable:!1,value:se}),Object.freeze&&(Object.freeze(te.props),Object.freeze(te)),te};function YT(S,z,P,Q,se){{var de,re={},te=null,Be=null;P!==void 0&&(ql(P),te=""+P),FT(z)&&(ql(z.key),te=""+z.key),qT(z)&&(Be=z.ref,GT(z,se));for(de in z)dn.call(z,de)&&!NT.hasOwnProperty(de)&&(re[de]=z[de]);if(S&&S.defaultProps){var we=S.defaultProps;for(de in we)re[de]===void 0&&(re[de]=we[de])}if(te||Be){var Se=typeof S=="function"?S.displayName||S.name||"Unknown":S;te&&WT(re,Se),Be&&jT(re,Se)}return RT(S,te,Be,se,Q,pn.current,re)}}var wa=T.ReactCurrentOwner,Wl=T.ReactDebugCurrentFrame;function jt(S){if(S){var z=S._owner,P=St(S.type,S._source,z?z.type:null);Wl.setExtraStackFrame(P)}else Wl.setExtraStackFrame(null)}var Ca;Ca=!1;function Sa(S){return typeof S=="object"&&S!==null&&S.$$typeof===e}function jl(){{if(wa.current){var S=ue(wa.current.type);if(S)return`
22
22
 
23
- Check the render method of \``+S+"`."}return""}}function YT(S){{if(S!==void 0){var z=S.fileName.replace(/^.*[\\\/]/,""),P=S.lineNumber;return`
23
+ Check the render method of \``+S+"`."}return""}}function QT(S){{if(S!==void 0){var z=S.fileName.replace(/^.*[\\\/]/,""),P=S.lineNumber;return`
24
24
 
25
- Check your code at `+z+":"+P+"."}return""}}var Rl={};function QT(S){{var z=jl();if(!z){var P=typeof S=="string"?S:S.displayName||S.name;P&&(z=`
25
+ Check your code at `+z+":"+P+"."}return""}}var Rl={};function KT(S){{var z=jl();if(!z){var P=typeof S=="string"?S:S.displayName||S.name;P&&(z=`
26
26
 
27
- Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var P=QT(z);if(Rl[P])return;Rl[P]=!0;var Q="";S&&S._owner&&S._owner!==wa.current&&(Q=" It was passed a child from "+ue(S._owner.type)+"."),jt(S),I('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',P,Q),jt(null)}}function Ql(S,z){{if(typeof S!="object")return;if(va(S))for(var P=0;P<S.length;P++){var Q=S[P];Sa(Q)&&Yl(Q,z)}else if(Sa(S))S._store&&(S._store.validated=!0);else if(S){var se=_(S);if(typeof se=="function"&&se!==S.entries)for(var de=se.call(S),re;!(re=de.next()).done;)Sa(re.value)&&Yl(re.value,z)}}}function KT(S){{var z=S.type;if(z==null||typeof z=="string")return;var P;if(typeof z=="function")P=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===c||z.$$typeof===h))P=z.propTypes;else return;if(P){var Q=ue(z);LT(P,S.props,"prop",Q,S)}else if(z.PropTypes!==void 0&&!Ca){Ca=!0;var se=ue(z);I("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",se||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&I("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function UT(S){{for(var z=Object.keys(S.props),P=0;P<z.length;P++){var Q=z[P];if(Q!=="children"&&Q!=="key"){jt(S),I("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),jt(null);break}}S.ref!==null&&(jt(S),I("Invalid attribute `ref` supplied to `React.Fragment`."),jt(null))}}function Kl(S,z,P,Q,se,de){{var re=Y(S);if(!re){var te="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(te+=" 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 Be=YT(se);Be?te+=Be:te+=jl();var we;S===null?we="null":va(S)?we="array":S!==void 0&&S.$$typeof===e?(we="<"+(ue(S.type)||"Unknown")+" />",te=" Did you accidentally export a JSX literal instead of a component?"):we=typeof S,I("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",we,te)}var Se=RT(S,z,P,se,de);if(Se==null)return Se;if(re){var Ke=z.children;if(Ke!==void 0)if(Q)if(va(Ke)){for(var Rt=0;Rt<Ke.length;Rt++)Ql(Ke[Rt],S);Object.freeze&&Object.freeze(Ke)}else I("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 Ql(Ke,S)}return S===r?UT(Se):KT(Se),Se}}function XT(S,z,P){return Kl(S,z,P,!0)}function JT(S,z,P){return Kl(S,z,P,!1)}var ZT=JT,HT=XT;Ut.Fragment=r,Ut.jsx=ZT,Ut.jsxs=HT}()),Ut}(function(t){process.env.NODE_ENV==="production"?t.exports=ou():t.exports=lu()})(su);const V=Qt.Fragment,i=Qt.jsx,p=Qt.jsxs,$t={CryptoJS:_a,d3Array:au,dayjs:R,lodash:x,numbro:ee,mathjs:mn,faker:Jl.faker},uu=[{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"}],cu=t=>`
27
+ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var P=KT(z);if(Rl[P])return;Rl[P]=!0;var Q="";S&&S._owner&&S._owner!==wa.current&&(Q=" It was passed a child from "+ue(S._owner.type)+"."),jt(S),I('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',P,Q),jt(null)}}function Ql(S,z){{if(typeof S!="object")return;if(va(S))for(var P=0;P<S.length;P++){var Q=S[P];Sa(Q)&&Yl(Q,z)}else if(Sa(S))S._store&&(S._store.validated=!0);else if(S){var se=_(S);if(typeof se=="function"&&se!==S.entries)for(var de=se.call(S),re;!(re=de.next()).done;)Sa(re.value)&&Yl(re.value,z)}}}function UT(S){{var z=S.type;if(z==null||typeof z=="string")return;var P;if(typeof z=="function")P=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===c||z.$$typeof===h))P=z.propTypes;else return;if(P){var Q=ue(z);OT(P,S.props,"prop",Q,S)}else if(z.PropTypes!==void 0&&!Ca){Ca=!0;var se=ue(z);I("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",se||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&I("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function XT(S){{for(var z=Object.keys(S.props),P=0;P<z.length;P++){var Q=z[P];if(Q!=="children"&&Q!=="key"){jt(S),I("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),jt(null);break}}S.ref!==null&&(jt(S),I("Invalid attribute `ref` supplied to `React.Fragment`."),jt(null))}}function Kl(S,z,P,Q,se,de){{var re=Y(S);if(!re){var te="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(te+=" 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 Be=QT(se);Be?te+=Be:te+=jl();var we;S===null?we="null":va(S)?we="array":S!==void 0&&S.$$typeof===e?(we="<"+(ue(S.type)||"Unknown")+" />",te=" Did you accidentally export a JSX literal instead of a component?"):we=typeof S,I("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",we,te)}var Se=YT(S,z,P,se,de);if(Se==null)return Se;if(re){var Ke=z.children;if(Ke!==void 0)if(Q)if(va(Ke)){for(var Rt=0;Rt<Ke.length;Rt++)Ql(Ke[Rt],S);Object.freeze&&Object.freeze(Ke)}else I("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 Ql(Ke,S)}return S===r?XT(Se):UT(Se),Se}}function JT(S,z,P){return Kl(S,z,P,!0)}function ZT(S,z,P){return Kl(S,z,P,!1)}var HT=ZT,eD=JT;Ut.Fragment=r,Ut.jsx=HT,Ut.jsxs=eD}()),Ut}(function(t){process.env.NODE_ENV==="production"?t.exports=ou():t.exports=lu()})(su);const V=Qt.Fragment,i=Qt.jsx,p=Qt.jsxs,$t={CryptoJS:_a,d3Array:au,dayjs:R,lodash:x,numbro:ee,mathjs:mn,faker:Jl.faker},uu=[{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"}],cu=t=>`
28
28
  <tr>
29
29
  <td><code>${t.name}</code></td>
30
30
  <td>
@@ -51,12 +51,12 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
51
51
  ${uu.map(cu).join("")}
52
52
  </tbody>
53
53
  </table>
54
- `;function pr(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(a){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function hr(t,e){try{return pr(t,e)}catch(n){return console.error(n),n.message}}function pu({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},$t)}catch(n){return console.error(n),t}}function hu(t,e){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,$t)}catch(n){return console.error(n),e}}function fu(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const a=e[r];if(a!="authentication"&&t[a])n.push(e[r]+"="+(typeof t[a]=="object"?JSON.stringify(t[a]):t[a]));else{const o=Object.keys(t[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&t[a][u]&&n.push(o[l]+"="+(typeof t[a][u]=="object"?JSON.stringify(t[a][u]):t[a][u]))}}}return n.sort().join("&")}function gu(t,e){let n=fu(t);return n+="&key="+e,_a.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(t){if(!this.app_id||!this.app_secret)return;const e=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:e,sign:gu({app_id:this.app_id,nonce_str:e,...t},this.app_secret)}},getRequest(t,e){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:l,signal:e};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),pt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(t){return async(e,n={})=>{var r;return e.env||(e.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",t)("/query",e,n)}}};function ja(t){qe.baseURL!==t.apiBaseURL&&(qe.baseURL=t.apiBaseURL),t.app_id&&(qe.app_id=t.app_id),t.app_secret&&(qe.app_secret=t.app_secret),t.makeQueryENV&&(qe.makeQueryENV=t.makeQueryENV)}async function mu({query:t,payload:e},n){if(!t.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=t,c=pr(o,e),d=pu({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=hu(u,f),f}async function yu({type:t,key:e,configString:n},r){return await qe.query(r)({type:t,key:e,query:n},{})}async function fr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(t){return console.error(t),[]}}async function Ra(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(t){return console.error(t),[]}}const Ya=y.createContext(null),gr=Ya.Provider;function K(){const t=y.useContext(Ya);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const bu={layoutFrozen:!1,freezeLayout:x.noop,inEditMode:!1},ft=y.createContext(bu),Qa=y.createContext(null),mr=Qa.Provider;function he(){const t=y.useContext(Qa);if(!t)throw new Error("Please use ModelContextProvider");return t}function Ka(t,e){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(a),e&&t.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{t.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(t.filters.values,l),c=n(u);console.log(`${l}: ${c}`),t.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}const Ua=b.types.model("FilterConfigModel_Checkbox",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),vu=()=>Ua.create({_name:"checkbox",description:"",default_value:!1});var me=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(me||{}),Ae=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ae||{});b.types.model({type:b.types.enumeration("DataSourceType",[me.Postgresql,me.MySQL,me.HTTP]),key:b.types.string,sql:b.types.string});function Xa(t,e){return t.map(n=>{try{return n?R.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const xu=b.types.model("FilterConfigModel_DateRange",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=t;return{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Xa(l,o),allowSingleDateInRange:u}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return R(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return R(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=b.getParent(t);b.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),Ja=b.types.snapshotProcessor(xu,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:R.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:Xa(e,n.inputFormat)}}}),wu=()=>Ja.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Cu=b.types.model({label:b.types.string,value:b.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),yr=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(Cu),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0)}).views(t=>({get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return n==="idle"?e:[]}})).actions(t=>({addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),yn=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return ie.toJS(e)}),Za=b.types.compose("FilterConfigModel_MultiSelect",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),yr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return yn({_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=b.getRoot(t).content.filters,n=b.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>ie.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Su=()=>Za.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function _u(t){return Zl.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function ku(t){return t.map(e=>{const{label:n,description:r,...a}=e,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:e.label},e.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Ha=b.types.compose("FilterConfigModel_TreeSelect",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),yr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return{_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id),n=ku(e);return _u(n)},get errorMessage(){const{error:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},applyDefaultSelection(){const e=b.getParent(t,1).key;b.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){b.addDisposer(t,ie.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Tu=()=>Ha.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),es=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,required:b.types.boolean,width:b.types.optional(b.types.string,"")}),yr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=t;return yn({_name:e,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(e){return!!e}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e}})),Du=()=>es.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ts=b.types.model("FilterConfigModel_TextInput",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),ns=()=>ts.create({_name:"text-input",required:!1,default_value:""}),br=b.types.model("FilterModel",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[Ae.Select,Ae.MultiSelect,Ae.TreeSelect,Ae.TextInput,Ae.Checkbox,Ae.DateRange]),config:b.types.union(es,Za,Ha,ts,Ua,Ja)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==Ae.TreeSelect},get auto_submit_supported(){return[Ae.Select,Ae.Checkbox,Ae.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=t;return{id:e,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:ie.toJS(o)}},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return x.get(t.config,"required",!1)?x.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case Ae.Select:t.config=Du();break;case Ae.MultiSelect:t.config=Su();break;case Ae.TreeSelect:t.config=Tu();break;case Ae.TextInput:t.config=ns();break;case Ae.Checkbox:t.config=vu();break;case Ae.DateRange:t.config=wu();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));function rs(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:R.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function Mu(t){return t.reduce((e,n)=>(e[n.key]=rs(n.config.default_value,n.config),e),{})}function Iu(t,e,n){b.addDisposer(t,b.addMiddleware(t,(r,a)=>{a(r,()=>{b.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const is=b.types.model("FiltersModel",{current:b.types.optional(b.types.array(br),[]),values:b.types.optional(b.types.frozen(),{}),previewValues:b.types.optional(b.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},get inOrder(){return x.sortBy(t.current,"order")},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDs.includes(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){Iu(t.current,br,(n,r)=>{if(n==="setType"){const a=rs(r.config.default_value,r.config);t.setValueByKey(r.key,a),t.updatePreviewValues({...t.previewValues,[r.key]:a})}})}return{afterCreate(){e()}}});function as(t){return{current:t,values:Mu(t)}}const ss="\uFEFF";function Eu(t,e){const n=new Blob([ss+e],{type:"text/csv"});cr.saveAs(n,`${t}.csv`)}function Au(t,e){const n=new Blob([e],{type:"application/json"});cr.saveAs(n,`${t}.json`)}function os(t){const e=new Hl;t.forEach(({id:n,data:r})=>{e.file(`${n}.csv`,us(r))}),e.generateAsync({type:"blob"}).then(n=>{cr.saveAs(n,"dashboard_data.zip")})}function ls(t){return typeof t=="string"&&t.includes(",")?`"${t}"`:t}function us(t){if(!Array.isArray(t)||t.length===0)return"";const e=[],n=Object.keys(t[0]).map(ls);return e.push(n.join(",")),t.forEach(r=>{const a=Object.values(r).map(ls).join(",");e.push(a)}),ss+e.join(`
55
- `)}const zu=b.types.model("QueryModel",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[me.Postgresql,me.MySQL,me.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===me.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=t;return yn({id:e,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})},get conditionOptions(){if(!b.isAlive(t))return[];const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,r=Object.keys({...e}).map(l=>`context.${l}`),a=Object.keys(n).map(l=>`filters.${l}`);return[...r,...a].map(l=>({label:l.split(".")[1],value:l,group:x.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!b.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=b.getRoot(t).content.payloadForSQL;return e.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(t=>({get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=b.getRoot(t).content.payloadForSQL,r=[...e].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=b.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=t.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:e},a)).filter(a=>!!a);return{context:n,filters:r}}})).actions(t=>({setName(e){t.name=e},setKey(e){t.key=e},setType(e){t.type=e},setSQL(e){t.sql=e},setRunBy(e){t.run_by.length=0,t.run_by.push(...e)},setReactTo(e){t.react_to.length=0,t.react_to.push(...e)},setPreProcess(e){t.pre_process=e},setPostProcess(e){t.post_process=e}}));function $u(t,e){return new Function(`return ${t}`)()(e,$t)}function Lu(t,e,n){return $u(t,{context:e,filters:n})}function Ou(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,$t)}catch(n){return console.error(n),e}}function Pu(t,e){return new Function(`return ${t.config.processing.post}`)()(e,$t)}function Bu(t,e){return t?new Function(`return ${t}`)()(e,$t):e}const cs=b.types.compose("QueryModel",zu,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.array(b.types.frozen()),[]),error:b.types.frozen()})).views(t=>({get formattedSQL(){const e=b.getRoot(t).content.payloadForSQL;return hr(t.sql,e)},get typedAsSQL(){return[me.Postgresql,me.MySQL].includes(t.type)},get typedAsHTTP(){return[me.HTTP].includes(t.type)},get datasource(){const{key:e,type:n}=t;return b.getRoot(t).datasources.find({type:n,key:e})},get httpConfigString(){const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,{name:r,pre_process:a}=t.json,o=Lu(a,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:b.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=b.getRoot(t).content.payloadForSQL;t.data=yield*b.toGenerator(mu({payload:n,title:t.name,query:t.json},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:b.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:a}=t.json;let o=JSON.parse(t.httpConfigString);o=Ou(t.datasource,o);const l=yield*b.toGenerator(yu({type:n,key:r,configString:JSON.stringify(o)},t.controller.signal));let u=Pu(t.datasource,l);u=Bu(a,u),t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}})})).actions(t=>({fetchData:()=>t.typedAsHTTP?t.runHTTP():t.runSQL(),beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>{var e,n;return t.typedAsHTTP?`${t.id}--${t.key}--${t.reQueryKey}--${(e=t.datasource)==null?void 0:e.id}`:`${t.id}--${t.key}--${t.formattedSQL}--${t.pre_process}--${t.post_process}--${(n=t.datasource)==null?void 0:n.id}`},t.fetchData,{fireImmediately:!0,delay:0}))}})),ds=b.types.model("QueriesModel",{current:b.types.optional(b.types.array(cs),[])}).views(t=>({get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())}})).views(t=>({get json(){return t.current.filter(e=>e.id).map(e=>e.json)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));os(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o.toJSON()}));os(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=us(a);Eu(r,o)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData()},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(b.detach(n),t.current.remove(n))}})),ps=b.types.model("SQLSnippetModel",{key:b.types.string,value:b.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}},isADuplicatedKey(e){return!e||e===t.key?!1:!!b.getParent(t,2).findByKey(e)}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}})),hs=b.types.model("SQLSnippetsModel",{current:b.types.optional(b.types.array(ps),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(e,n=>n.label.toLowerCase())},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),fs=b.types.model("ContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Vu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;if(n===me.MySQL)return`
54
+ `;function pr(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(a){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function hr(t,e){try{return pr(t,e)}catch(n){return console.error(n),n.message}}function pu({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},$t)}catch(n){return console.error(n),t}}function hu(t,e){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,$t)}catch(n){return console.error(n),e}}function fu(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const a=e[r];if(a!="authentication"&&t[a])n.push(e[r]+"="+(typeof t[a]=="object"?JSON.stringify(t[a]):t[a]));else{const o=Object.keys(t[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&t[a][u]&&n.push(o[l]+"="+(typeof t[a][u]=="object"?JSON.stringify(t[a][u]):t[a][u]))}}}return n.sort().join("&")}function gu(t,e){let n=fu(t);return n+="&key="+e,_a.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(t){if(!this.app_id||!this.app_secret)return;const e=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:e,sign:gu({app_id:this.app_id,nonce_str:e,...t},this.app_secret)}},getRequest(t,e){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:l,signal:e};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),pt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(t){return async(e,n={})=>{var r;return e.env||(e.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",t)("/query",e,n)}}};function ja(t){qe.baseURL!==t.apiBaseURL&&(qe.baseURL=t.apiBaseURL),t.app_id&&(qe.app_id=t.app_id),t.app_secret&&(qe.app_secret=t.app_secret),t.makeQueryENV&&(qe.makeQueryENV=t.makeQueryENV)}async function mu({query:t,payload:e},n){if(!t.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=t,c=pr(o,e),d=pu({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=hu(u,f),f}async function yu({type:t,key:e,configString:n},r){return await qe.query(r)({type:t,key:e,query:n},{})}async function fr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(t){return console.error(t),[]}}async function Ra(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(t){return console.error(t),[]}}const Ya=y.createContext(null),gr=Ya.Provider;function K(){const t=y.useContext(Ya);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const bu={layoutFrozen:!1,freezeLayout:x.noop,inEditMode:!1},ft=y.createContext(bu),Qa=y.createContext(null),mr=Qa.Provider;function he(){const t=y.useContext(Qa);if(!t)throw new Error("Please use ModelContextProvider");return t}function Ka(t,e){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(a),e&&t.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{t.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(t.filters.values,l),c=n(u);console.log(`${l}: ${c}`),t.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}const Ua=b.types.model("FilterConfigModel_Checkbox",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),vu=()=>Ua.create({_name:"checkbox",description:"",default_value:!1});var ye=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(ye||{}),Ae=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ae||{});b.types.model({type:b.types.enumeration("DataSourceType",[ye.Postgresql,ye.MySQL,ye.HTTP]),key:b.types.string,sql:b.types.string});function Xa(t,e){return t.map(n=>{try{return n?R.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const xu=b.types.model("FilterConfigModel_DateRange",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=t;return{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Xa(l,o),allowSingleDateInRange:u}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return R(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return R(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=b.getParent(t);b.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),Ja=b.types.snapshotProcessor(xu,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:R.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:Xa(e,n.inputFormat)}}}),wu=()=>Ja.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Cu=b.types.model({label:b.types.string,value:b.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),yr=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(Cu),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0)}).views(t=>({get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return n==="idle"?e:[]}})).actions(t=>({addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),yn=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return ie.toJS(e)}),Za=b.types.compose("FilterConfigModel_MultiSelect",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),yr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return yn({_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=b.getRoot(t).content.filters,n=b.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>ie.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Su=()=>Za.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function _u(t){return Zl.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function ku(t){return t.map(e=>{const{label:n,description:r,...a}=e,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:e.label},e.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Ha=b.types.compose("FilterConfigModel_TreeSelect",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),yr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return{_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id),n=ku(e);return _u(n)},get errorMessage(){const{error:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},applyDefaultSelection(){const e=b.getParent(t,1).key;b.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){b.addDisposer(t,ie.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Tu=()=>Ha.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),es=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,required:b.types.boolean,width:b.types.optional(b.types.string,"")}),yr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=t;return yn({_name:e,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(e){return!!e}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e}})),Du=()=>es.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ts=b.types.model("FilterConfigModel_TextInput",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),ns=()=>ts.create({_name:"text-input",required:!1,default_value:""}),br=b.types.model("FilterModel",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[Ae.Select,Ae.MultiSelect,Ae.TreeSelect,Ae.TextInput,Ae.Checkbox,Ae.DateRange]),config:b.types.union(es,Za,Ha,ts,Ua,Ja)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==Ae.TreeSelect},get auto_submit_supported(){return[Ae.Select,Ae.Checkbox,Ae.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=t;return{id:e,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:ie.toJS(o)}},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return x.get(t.config,"required",!1)?x.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case Ae.Select:t.config=Du();break;case Ae.MultiSelect:t.config=Su();break;case Ae.TreeSelect:t.config=Tu();break;case Ae.TextInput:t.config=ns();break;case Ae.Checkbox:t.config=vu();break;case Ae.DateRange:t.config=wu();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));function rs(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:R.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function Mu(t){return t.reduce((e,n)=>(e[n.key]=rs(n.config.default_value,n.config),e),{})}function Iu(t,e,n){b.addDisposer(t,b.addMiddleware(t,(r,a)=>{a(r,()=>{b.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const is=b.types.model("FiltersModel",{current:b.types.optional(b.types.array(br),[]),values:b.types.optional(b.types.frozen(),{}),previewValues:b.types.optional(b.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},get inOrder(){return x.sortBy(t.current,"order")},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDs.includes(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){Iu(t.current,br,(n,r)=>{if(n==="setType"){const a=rs(r.config.default_value,r.config);t.setValueByKey(r.key,a),t.updatePreviewValues({...t.previewValues,[r.key]:a})}})}return{afterCreate(){e()}}});function as(t){return{current:t,values:Mu(t)}}const ss="\uFEFF";function Eu(t,e){const n=new Blob([ss+e],{type:"text/csv"});cr.saveAs(n,`${t}.csv`)}function Au(t,e){const n=new Blob([e],{type:"application/json"});cr.saveAs(n,`${t}.json`)}function os(t){const e=new Hl;t.forEach(({id:n,data:r})=>{e.file(`${n}.csv`,us(r))}),e.generateAsync({type:"blob"}).then(n=>{cr.saveAs(n,"dashboard_data.zip")})}function ls(t){return typeof t=="string"&&t.includes(",")?`"${t}"`:t}function us(t){if(!Array.isArray(t)||t.length===0)return"";const e=[],n=Object.keys(t[0]).map(ls);return e.push(n.join(",")),t.forEach(r=>{const a=Object.values(r).map(ls).join(",");e.push(a)}),ss+e.join(`
55
+ `)}const zu=b.types.model("QueryModel",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[ye.Postgresql,ye.MySQL,ye.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===ye.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=t;return yn({id:e,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})},get conditionOptions(){if(!b.isAlive(t))return[];const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,r=Object.keys({...e}).map(l=>`context.${l}`),a=Object.keys(n).map(l=>`filters.${l}`);return[...r,...a].map(l=>({label:l.split(".")[1],value:l,group:x.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!b.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=b.getRoot(t).content.payloadForSQL;return e.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(t=>({get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=b.getRoot(t).content.payloadForSQL,r=[...e].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=b.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=t.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:e},a)).filter(a=>!!a);return{context:n,filters:r}}})).actions(t=>({setName(e){t.name=e},setKey(e){t.key=e},setType(e){t.type=e},setSQL(e){t.sql=e},setRunBy(e){t.run_by.length=0,t.run_by.push(...e)},setReactTo(e){t.react_to.length=0,t.react_to.push(...e)},setPreProcess(e){t.pre_process=e},setPostProcess(e){t.post_process=e}}));function $u(t,e){return new Function(`return ${t}`)()(e,$t)}function Lu(t,e,n){return $u(t,{context:e,filters:n})}function Ou(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,$t)}catch(n){return console.error(n),e}}function Pu(t,e){return new Function(`return ${t.config.processing.post}`)()(e,$t)}function Bu(t,e){return t?new Function(`return ${t}`)()(e,$t):e}const cs=b.types.compose("QueryModel",zu,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.array(b.types.frozen()),[]),error:b.types.frozen()})).views(t=>({get formattedSQL(){const e=b.getRoot(t).content.payloadForSQL;return hr(t.sql,e)},get typedAsSQL(){return[ye.Postgresql,ye.MySQL].includes(t.type)},get typedAsHTTP(){return[ye.HTTP].includes(t.type)},get datasource(){const{key:e,type:n}=t;return b.getRoot(t).datasources.find({type:n,key:e})},get httpConfigString(){const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,{name:r,pre_process:a}=t.json,o=Lu(a,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:b.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=b.getRoot(t).content.payloadForSQL;t.data=yield*b.toGenerator(mu({payload:n,title:t.name,query:t.json},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:b.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:a}=t.json;let o=JSON.parse(t.httpConfigString);o=Ou(t.datasource,o);const l=yield*b.toGenerator(yu({type:n,key:r,configString:JSON.stringify(o)},t.controller.signal));let u=Pu(t.datasource,l);u=Bu(a,u),t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}})})).actions(t=>({fetchData:()=>t.typedAsHTTP?t.runHTTP():t.runSQL(),beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>{var e,n;return t.typedAsHTTP?`${t.id}--${t.key}--${t.reQueryKey}--${(e=t.datasource)==null?void 0:e.id}`:`${t.id}--${t.key}--${t.formattedSQL}--${t.pre_process}--${t.post_process}--${(n=t.datasource)==null?void 0:n.id}`},t.fetchData,{fireImmediately:!0,delay:0}))}})),ds=b.types.model("QueriesModel",{current:b.types.optional(b.types.array(cs),[])}).views(t=>({get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())}})).views(t=>({get json(){return t.current.filter(e=>e.id).map(e=>e.json)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));os(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o.toJSON()}));os(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=us(a);Eu(r,o)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData()},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(b.detach(n),t.current.remove(n))}})),ps=b.types.model("SQLSnippetModel",{key:b.types.string,value:b.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}},isADuplicatedKey(e){return!e||e===t.key?!1:!!b.getParent(t,2).findByKey(e)}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}})),hs=b.types.model("SQLSnippetsModel",{current:b.types.optional(b.types.array(ps),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(e,n=>n.label.toLowerCase())},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),fs=b.types.model("ContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Vu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;if(n===ye.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 = '${r}' AND table_schema = '${a}'
59
- `;if(n===me.Postgresql){const o=`'${a}.${r}'::regclass`;return`
59
+ `;if(n===ye.Postgresql){const o=`'${a}.${r}'::regclass`;return`
60
60
  SELECT
61
61
  ordinal_position,
62
62
  UPPER(pc.contype) AS column_key,
@@ -73,7 +73,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
73
73
  LEFT JOIN pg_constraint pc ON pc.conrelid = ${o} AND ordinal_position = any(pc.conkey)
74
74
  WHERE
75
75
  table_name = '${r}' AND table_schema = '${a}';
76
- `}return""}})),Nu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;return n===me.MySQL?`
76
+ `}return""}})),Nu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;return n===ye.MySQL?`
77
77
  SELECT
78
78
  sub_part AS index_length,
79
79
  index_name AS index_name,
@@ -86,7 +86,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
86
86
  table_name = '${r}' AND table_schema = '${a}'
87
87
  ORDER BY
88
88
  seq_in_index ASC;
89
- `:n===me.Postgresql?`
89
+ `:n===ye.Postgresql?`
90
90
  SELECT
91
91
  ix.relname AS index_name,
92
92
  upper(am.amname) AS index_algorithm,
@@ -108,15 +108,15 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
108
108
  JOIN pg_am AS am ON ix.relam = am.oid
109
109
  WHERE
110
110
  t.relname = '${r}' AND n.nspname = '${a}';
111
- `:""}})),qu=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0},get sql(){const e=b.getParent(t,1).type;return e===me.MySQL||e===me.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),Fu=b.types.model({page:b.types.optional(b.types.number,1),limit:b.types.optional(b.types.number,20),data:b.types.optional(b.types.frozen(),[]),total:b.types.optional(b.types.number,0),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get keywords(){return b.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=b.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get sql(){const e=b.getParent(t,1),{table_name:n,table_schema:r}=e;return`
111
+ `:""}})),qu=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0},get sql(){const e=b.getParent(t,1).type;return e===ye.MySQL||e===ye.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),Fu=b.types.model({page:b.types.optional(b.types.number,1),limit:b.types.optional(b.types.number,20),data:b.types.optional(b.types.frozen(),[]),total:b.types.optional(b.types.number,0),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get keywords(){return b.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=b.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get sql(){const e=b.getParent(t,1),{table_name:n,table_schema:r}=e;return`
112
112
  SELECT *
113
113
  FROM ${r}.${n}
114
114
  LIMIT ${t.limit} OFFSET ${(t.page-1)*t.limit}
115
115
  `},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
116
116
  SELECT count(*) AS total
117
117
  FROM ${n}.${e}
118
- `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(t,ie.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),Gu=b.types.model("DataSourceModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[me.HTTP,me.MySQL,me.Postgresql]),key:b.types.string,config:b.types.frozen(),tables:b.types.optional(qu,{}),columns:b.types.optional(Vu,{}),tableData:b.types.optional(Fu,{}),indexes:b.types.optional(Nu,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=b.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*b.toGenerator(qe.query(t.controllers.tables.signal)({type:t.type,key:t.key,query:t.tables.sql},{}));t.tables.data=x.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!pt.isCancel(r)){t.tables.data={};const a=x.get(r,"message","unkown error");t.tables.error=x.get(r,"response.data.detail.message",a),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:b.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*b.toGenerator(qe.query(t.controllers.columns.signal)({type:t.type,key:t.key,query:t.columns.sql},{})),t.columns.state="idle",t.columns.error=null}catch(r){if(pt.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const a=x.get(r,"message","unkown error");t.columns.error=x.get(r,"response.data.detail.message",a),t.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*b.toGenerator(qe.query(t.controllers.indexes.signal)({type:t.type,key:t.key,query:t.indexes.sql},{})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(pt.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const a=x.get(r,"message","unkown error");t.indexes.error=x.get(r,"response.data.detail.message",a),t.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(pt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.columns.sql,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.indexes.sql,t.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(t,ie.reaction(()=>t.tableData.sql,t.loadTableData,{fireImmediately:!1,delay:0}))}})),Wu=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(Gu),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function bn(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function ju(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const Ru=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=b.getRoot(t),{filters:n,views:r,sqlSnippets:a,queries:o}=e;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,bn("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...a.options,bn("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,bn("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...r.editorOptions,bn("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=ju(e);n&&t.setPath(n)}})),Yu=b.types.model("MockContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Qu=b.types.model("VariableModel",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}))}).views(t=>({get json(){const{name:e,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=t;return x.cloneDeep({name:e,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}}));class Ku{constructor(e){N(this,"origin");N(this,"copy");this.origin=e,this.copy=b.clone(e),ie.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(e){b.applySnapshot(this.copy,e)}}const Uu=t=>new Ku(t);class Xu{constructor(){N(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const a=this.migrations.filter(u=>u.version>e.from&&u.version<=e.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class be extends Xu{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,a)=>({version:e,...n(r,a)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await e.setItem(null,o)}async needMigration({configData:e}){const n=await e.getItem(null);return x.get(n,"version",0)<this.VERSION}}var Je=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Je||{});const gs=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
119
- `),vr={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class Lt{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:x.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,e),u=x.get(o,e);l!==u&&n(l,u)},r)}}class xr{constructor(e,n,r){N(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Lt(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new Lt(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new Lt(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(x.values(e).map(n=>this.constructInstance(new Lt(this.attachmentStorage,n.id))))}}class ms{constructor(e){N(this,"rootRef");this.rootRef=ie.observable({current:e})}async deleteItem(e){ie.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?ie.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))ie.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ie.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return ie.reaction(()=>this.getValueFromRoot(e),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){N(this,"channels",new Map);N(this,"globalChannel",new ka)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new ka;return this.channels.set(e,r),r}}class Zu{constructor(e){N(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new Ju,instanceData:new ms(e.viz.conf)};return this.instances.set(e.id,r),r}}function ys(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new ms({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Hu=t=>{const{panel:e,vizManager:n,data:r,variables:a}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),u={...ys(l,r,n,a),viewport:{width:e.layout.w,height:e.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(t,["panel","vizManager","data"])})},ec=t=>{const{vizManager:e,panel:n,panelInfoEditor:r,data:a,variables:o}=t,l=e.resolveComponent(n.viz.type),u=e.getOrCreateInstance(n),c={...ys(u,a,e,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(t,["panel","vizManager","data","panelInfoEditor"])})},bs=(t,e)=>{const n=st.bezier(t),r=st.bezier(e);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},vn=t=>{const e=st.bezier(t);return function(n){return e(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:bs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:bs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:vn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:vn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:vn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:vn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(e){N(this,"symbol");this.symbol=Symbol(e)}}function ot(t){return new oc(t)}class wr{constructor(){N(this,"parent");N(this,"factoryRegistry",new Map);N(this,"instanceRegistry",new Map)}createScoped(){const e=new wr;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const vs="10.9.3",lc=Object.freeze(Object.defineProperty({__proto__:null,version:vs},Symbol.toStringTag,{value:"Module"}));class uc{constructor(e){N(this,"staticColors",new Map);N(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class cc{constructor(){N(this,"plugins",new Map);N(this,"vizComponents",new Map);N(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.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=(t,e)=>{const[n,{setFalse:r}]=X.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(t.getItem(e).then(u=>{o(u),r()}),t.watchItem(e,u=>{o(u)})));const l=y.useCallback(async u=>{await t.setItem(e,u),o(u)},[t,e]);return{loading:n,value:a,set:l}},Cr={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 q(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function lt(t,e){var a;const{queryID:n,columnKey:r}=q(e);return n?r?((a=t[n])==null?void 0:a.map(o=>o[r]))??[]:t[n]:[]}function xn(t,e){const{queryID:n}=q(e);return n?t[n]:[]}function dc(t){return Object.values(t)[0]}function wn(t,e){const{queryID:n,columnKey:r}=q(e);return t[r]}le.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function pc({context:t}){const{value:e}=W(t.instanceData,"config"),n=t.data,{width:r,height:a}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},e,Cr),h=y.useMemo(()=>xn(n,o),[n,o]),{x:g,y:m,z:w}=y.useMemo(()=>({x:q(o),y:q(l),z:q(u)}),[o,l,u]),{min:C,max:_}=y.useMemo(()=>{const I=x.minBy(h,B=>B[w.columnKey]),O=x.maxBy(h,B=>B[w.columnKey]);return{min:x.get(I,w.columnKey),max:x.get(O,w.columnKey)}},[h,w]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[w.columnKey]])}]};return e?i(Ne,{echarts:le,option:T,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const xs=y.createContext({panel:null,data:{},loading:!1,errors:[]}),Sr=xs.Provider;function ze(){const t=y.useContext(xs);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const hc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},_r=y.createContext(hc);function ws(){const t=y.useContext(_r);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const j=k.observer(y.forwardRef(({label:t,required:e,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=ze(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:t,data:d,value:n,onChange:r,required:e,sx:o,...l})}));function fc({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=x.defaults({},e,Cr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[e]),e?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(D.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function gc(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=t;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class mc extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:gc(a,r)}})}}const yc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new mc,name:"bar-3d",viewRender:pc,configRender:fc,createConfig(){return{version:2,config:x.cloneDeep(Cr)}}};class Fe extends y.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const $e={mantissa:0,output:"number",trimMantissa:!1,average:!1};function bc({value:t,onChange:e},n){const r=u=>{e({...t,output:u})},a=u=>{const c=u===0?!1:t.trimMantissa;e({...t,mantissa:u,trimMantissa:c})},o=u=>{e({...t,trimMantissa:u.currentTarget.checked})},l=u=>{e({...t,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:t.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(D.ArrowRight,{size:9})," ",ee(123456789).format(t)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(D.ArrowRight,{size:9})," ",ee(1234).format(t)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(D.ArrowRight,{size:9})," ",ee(.1234).format(t)]})]})})]})]})}const Re=y.forwardRef(bc),nt={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
118
+ `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(t,ie.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),Gu=b.types.model("DataSourceModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[ye.HTTP,ye.MySQL,ye.Postgresql]),key:b.types.string,config:b.types.frozen(),tables:b.types.optional(qu,{}),columns:b.types.optional(Vu,{}),tableData:b.types.optional(Fu,{}),indexes:b.types.optional(Nu,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=b.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*b.toGenerator(qe.query(t.controllers.tables.signal)({type:t.type,key:t.key,query:t.tables.sql},{}));t.tables.data=x.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!pt.isCancel(r)){t.tables.data={};const a=x.get(r,"message","unkown error");t.tables.error=x.get(r,"response.data.detail.message",a),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:b.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*b.toGenerator(qe.query(t.controllers.columns.signal)({type:t.type,key:t.key,query:t.columns.sql},{})),t.columns.state="idle",t.columns.error=null}catch(r){if(pt.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const a=x.get(r,"message","unkown error");t.columns.error=x.get(r,"response.data.detail.message",a),t.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*b.toGenerator(qe.query(t.controllers.indexes.signal)({type:t.type,key:t.key,query:t.indexes.sql},{})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(pt.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const a=x.get(r,"message","unkown error");t.indexes.error=x.get(r,"response.data.detail.message",a),t.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(pt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.columns.sql,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.indexes.sql,t.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(t,ie.reaction(()=>t.tableData.sql,t.loadTableData,{fireImmediately:!1,delay:0}))}})),Wu=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(Gu),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function bn(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function ju(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const Ru=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=b.getRoot(t),{filters:n,views:r,sqlSnippets:a,queries:o}=e;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,bn("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...a.options,bn("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,bn("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...r.editorOptions,bn("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=ju(e);n&&t.setPath(n)}})),Yu=b.types.model("MockContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Qu=b.types.model("VariableModel",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}))}).views(t=>({get json(){const{name:e,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=t;return x.cloneDeep({name:e,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}}));class Ku{constructor(e){N(this,"origin");N(this,"copy");this.origin=e,this.copy=b.clone(e),ie.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(e){b.applySnapshot(this.copy,e)}}const Uu=t=>new Ku(t);class Xu{constructor(){N(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const a=this.migrations.filter(u=>u.version>e.from&&u.version<=e.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ve extends Xu{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,a)=>({version:e,...n(r,a)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await e.setItem(null,o)}async needMigration({configData:e}){const n=await e.getItem(null);return x.get(n,"version",0)<this.VERSION}}var Je=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Je||{});const gs=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
119
+ `),vr={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class Lt{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:x.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,e),u=x.get(o,e);l!==u&&n(l,u)},r)}}class xr{constructor(e,n,r){N(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Lt(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new Lt(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new Lt(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(x.values(e).map(n=>this.constructInstance(new Lt(this.attachmentStorage,n.id))))}}class ms{constructor(e){N(this,"rootRef");this.rootRef=ie.observable({current:e})}async deleteItem(e){ie.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?ie.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))ie.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ie.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return ie.reaction(()=>this.getValueFromRoot(e),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){N(this,"channels",new Map);N(this,"globalChannel",new ka)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new ka;return this.channels.set(e,r),r}}class Zu{constructor(e){N(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new Ju,instanceData:new ms(e.viz.conf)};return this.instances.set(e.id,r),r}}function ys(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new ms({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Hu=t=>{const{panel:e,vizManager:n,data:r,variables:a}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),u={...ys(l,r,n,a),viewport:{width:e.layout.w,height:e.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(t,["panel","vizManager","data"])})},ec=t=>{const{vizManager:e,panel:n,panelInfoEditor:r,data:a,variables:o}=t,l=e.resolveComponent(n.viz.type),u=e.getOrCreateInstance(n),c={...ys(u,a,e,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(t,["panel","vizManager","data","panelInfoEditor"])})},bs=(t,e)=>{const n=st.bezier(t),r=st.bezier(e);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},vn=t=>{const e=st.bezier(t);return function(n){return e(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:bs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:bs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:vn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:vn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:vn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:vn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(e){N(this,"symbol");this.symbol=Symbol(e)}}function ot(t){return new oc(t)}class wr{constructor(){N(this,"parent");N(this,"factoryRegistry",new Map);N(this,"instanceRegistry",new Map)}createScoped(){const e=new wr;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const vs="10.9.5",lc=Object.freeze(Object.defineProperty({__proto__:null,version:vs},Symbol.toStringTag,{value:"Module"}));class uc{constructor(e){N(this,"staticColors",new Map);N(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class cc{constructor(){N(this,"plugins",new Map);N(this,"vizComponents",new Map);N(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.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=(t,e)=>{const[n,{setFalse:r}]=X.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(t.getItem(e).then(u=>{o(u),r()}),t.watchItem(e,u=>{o(u)})));const l=y.useCallback(async u=>{await t.setItem(e,u),o(u)},[t,e]);return{loading:n,value:a,set:l}},Cr={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 q(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function lt(t,e){var a;const{queryID:n,columnKey:r}=q(e);return n?r?((a=t[n])==null?void 0:a.map(o=>o[r]))??[]:t[n]:[]}function xn(t,e){const{queryID:n}=q(e);return n?t[n]:[]}function dc(t){return Object.values(t)[0]}function wn(t,e){const{queryID:n,columnKey:r}=q(e);return t[r]}le.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function pc({context:t}){const{value:e}=W(t.instanceData,"config"),n=t.data,{width:r,height:a}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},e,Cr),h=y.useMemo(()=>xn(n,o),[n,o]),{x:g,y:m,z:w}=y.useMemo(()=>({x:q(o),y:q(l),z:q(u)}),[o,l,u]),{min:C,max:_}=y.useMemo(()=>{const I=x.minBy(h,B=>B[w.columnKey]),O=x.maxBy(h,B=>B[w.columnKey]);return{min:x.get(I,w.columnKey),max:x.get(O,w.columnKey)}},[h,w]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[w.columnKey]])}]};return e?i(Ne,{echarts:le,option:T,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const xs=y.createContext({panel:null,data:{},loading:!1,errors:[]}),Sr=xs.Provider;function ze(){const t=y.useContext(xs);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const hc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},_r=y.createContext(hc);function ws(){const t=y.useContext(_r);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const j=k.observer(y.forwardRef(({label:t,required:e,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=ze(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:t,data:d,value:n,onChange:r,required:e,sx:o,...l})}));function fc({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=x.defaults({},e,Cr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[e]),e?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(D.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function gc(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=t;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class mc extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:gc(a,r)}})}}const yc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new mc,name:"bar-3d",viewRender:pc,configRender:fc,createConfig(){return{version:2,config:x.cloneDeep(Cr)}}};class Fe extends y.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const $e={mantissa:0,output:"number",trimMantissa:!1,average:!1};function bc({value:t,onChange:e},n){const r=u=>{e({...t,output:u})},a=u=>{const c=u===0?!1:t.trimMantissa;e({...t,mantissa:u,trimMantissa:c})},o=u=>{e({...t,trimMantissa:u.currentTarget.checked})},l=u=>{e({...t,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:t.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(D.ArrowRight,{size:9})," ",ee(123456789).format(t)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(D.ArrowRight,{size:9})," ",ee(1234).format(t)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(D.ArrowRight,{size:9})," ",ee(.1234).format(t)]})]})})]})]})}const Re=y.forwardRef(bc),nt={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
120
120
  `)},Cs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:xc,configRender:vc,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 vc(t){return i(V,{})}function xc(t){return i(s.Text,{children:"Click chart's series"})}const wc=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Cn=y.forwardRef(({sectionTitle:t,value:e,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(e);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[t&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:e.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:wc,value:e.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:e.ellipsis,disabled:!0})]})]})}),gt=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,on_axis:o})},a=o=>{e({...t,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Axis",value:t.on_axis,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.in_tooltip,onChange:a})]})}),Ze={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function mt({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],r=t==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
121
121
  max-width: ${e}px;
122
122
  word-break: ${n};
@@ -163,7 +163,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
163
163
  </tbody>
164
164
  </table>
165
165
  `}const Uc=t=>e=>{const{componentSubType:n,value:r}=e;return n==="scatter"?Kc(t,r):Yc(t,r)};function Xc({config:t}){return{trigger:"item",confine:!0,formatter:Uc(t)}}const Xt=y.forwardRef(function({value:e,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:e,onChange:n,...r})}),Jc=[{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 Zc({label:t,value:e,onChange:n,pt:r="sm"},a){y.useEffect(()=>{typeof e=="string"&&(console.log(e),n({type:e,config:{}}))},[e,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:t,data:Jc,value:e.type,onChange:o}),e.type==="quantile"&&i(s.NumberInput,{label:"p",value:e.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Sn=y.forwardRef(Zc);function Hc({label:t,value:e,onChange:n},r){const[a,o]=y.useState(Array.isArray(e)?[...e]:[]),l=y.useCallback(()=>{o(g=>[...g,""])},[o]),u=y.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=y.useMemo(()=>!x.isEqual(a,e),[a,e]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=y.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return p(V,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:t}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:w=>{o(C=>(C.splice(m,1,w),[...C]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(D.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(D.PlaylistAdd,{size:20})})]})]})}const ed=y.forwardRef(Hc);function td({value:t,onChange:e},n){const{colorManager:r}=y.useContext(at),a=y.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=y.useMemo(()=>a.some(l=>l.value===t),[t,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":t,onChange:l=>e(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":t,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:t,onChange:e,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?t:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Pe=y.forwardRef(td),_n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function nd({label:t,value:e,onChange:n},r){var l;const[a,o]=y.useState(((l=_n.find(u=>u.label===e))==null?void 0:l.value)??_n[0].value);return y.useEffect(()=>{const u=_n.find(c=>c.value===a);u&&n(u.label)},[a]),p(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:t}),i(s.Slider,{label:null,marks:_n,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const ks=y.forwardRef(nd);function rd({label:t,value:e,onChange:n,type:r},a){const[o,l]=y.useState(Array.isArray(e)?[...e]:[]),u=y.useCallback(()=>{l(h=>[...h,""])},[l]),c=y.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=y.useMemo(()=>!x.isEqual(o.map(String),e.map(String)),[o,e]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(V,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:t}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:m=>{const w=m.currentTarget.value;l(C=>(C.splice(g,1,w),[...C]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(D.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(D.PlaylistAdd,{size:20})})]})]})}const id=y.forwardRef(rd),Ts=y.forwardRef(function({value:e,onChange:n},r){const a=e.color.type,o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return p(V,{children:[i(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),i(s.Stack,{children:i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:e.size,onChange:l=>o("size",l.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(ks,{label:"Font Weight",value:e.weight,onChange:l=>o("weight",l)})}),i(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),p(s.Stack,{children:[i(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:e.color.type,onChange:l=>o("color.type",l)}),a==="static"&&i(Pe,{value:e.color.staticColor,onChange:l=>o("color.staticColor",l)}),a==="continuous"&&p(V,{children:[i(id,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:l=>o("color.valueRange",l)}),i(ed,{label:"Color Range",value:e.color.colorRange,onChange:l=>o("color.colorRange",l)})]})]})]})});y.forwardRef(function({value:e,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return p(s.Box,{px:"sm",py:"md",ref:a,children:[i(s.Text,{weight:"bold",pb:0,children:e.name}),i(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:l=>o("name",l.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:l=>o("data_field",l)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Re,{value:e.formatter,onChange:l=>o("formatter",l)}),r&&i(Ts,{value:e,onChange:n})]})});const Pt={type:"none",config:{}};function ad(t){const e=Array.from(t).sort((r,a)=>r-a),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function sd(t){const e=Number(t);return isFinite(e)?e:0}function od(t,e){switch(e.type){case"sum":return x.sum(t);case"mean":return x.mean(t);case"median":return ad(t);case"max":return x.max(t)??0;case"min":return x.min(t)??0;case"quantile":return Yt.quantile(t,e.config.p)??0;case"CV":const n=mn.std(...t),r=mn.mean(...t);return r?n/r:"N/A";case"std":return mn.std(...t);default:return t}}function Dr(t,e){const n=t.map(sd);return od(n,e)}function kn(t,e,n){try{return Dr(lt(t,e),n)}catch(r){return console.error(r),null}}class ld{constructor({valueRange:e,colorRange:n}){N(this,"mapper");this.mapper=_t.interpolate(e,n)}getColor(e){return this.mapper(e)}}function ud(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function yt({data_field:t,aggregation:e},n){return kn(n,t,e)}function et({formatter:t},e){if(!["string","number"].includes(typeof e))return ud(e);try{return ee(e).format(t)}catch(n){return console.error(n),e}}function cd(t,e){if(t.type==="static")return t.staticColor;if(t.type==="continuous")try{if(typeof e!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${e}`);return new ld(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function Ds(t,e){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=t,u=kn(e,r,a),c=et(t,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:cd(n,u),weight:l,children:c})}function dd(t,e){const n={};return t.forEach(r=>{const a=r.name;n[a]=Ds(r,e)}),n}function pd(t){return t.split(" ").map((e,n)=>p(y.Fragment,{children:[e," "]},n))}function hd(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
166
- `,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[pd(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Mr(t){return hd(t)}function Jt(t,e,n){const r=dd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Mr(o);const c=r[u[1]];if(!c)return Mr(o);const d=u[2]??"";return p(y.Fragment,{children:[c,Mr(d)]},`${o}-${l}`)})}function fd(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=kn(e,o,l);n[a]=et(r,u)}),n}function Tn(t,e,n){const r=fd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function gd(t,e,n){const r=e.reduce((a,o)=>{const l=yt(o,n);return a[o.name]=et(o,l),a},{});return t.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Tn(a.template,e,n)},position:"insideEndTop"}}}))}function md({config:t,data:e,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=t,l=Gc(t,e),u=ut(r.axisLabel.overflow.on_axis),c=jc(t);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:Wc({config:t}),tooltip:Xc({config:t}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Ot(r.axisLabel.formatter)}}],yAxis:[{name:a.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return ee(d).format(a.label_formatter)}}}],series:[...c,...gd(o,n,e)]}}function bt(t,e){return y.useMemo(()=>{const{queryID:n,columnKey:r}=q(e);return x.keyBy(t[n],r)},[t,e])}le.use([G.DataZoomComponent,pe.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function yd({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),{variables:r}=t,a=t.data,{width:o,height:l}=t.viewport,u=x.defaults({},n,kr),c=tt({vizManager:t.vizManager,instance:e}),d=He(c.triggerManager,Cs.id),f=bt(a,u.x_axis.data_key),h=y.useCallback(w=>{const C=x.get(f,w.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...w,rowData:C})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>md({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Ne,{echarts:le,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})}function bd({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},children:i(D.Trash,{size:16})})]},e)}function vd({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(bd,{control:t,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const xd=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Dn=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(nt.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(xd,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),wd=({control:t,watch:e})=>(e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})),Cd=({control:t,watch:e})=>(e(["y_axis"]),p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})]})),Sd=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),_d=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Sd,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function kd({control:t,watch:e}){return i(s.Stack,{children:i(_d,{control:t,watch:e})})}function Td({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},e,kr),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,e),[f,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(wd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Cd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(kd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Pe,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(vd,{variables:r,control:o,watch:u})})]})]})})}function Dd(t){return x.omit(t,"variables")}function Md(t){const{label_formatter:e=$e,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function Id(t){const e={rotate:0,formatter:{...nt}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function Ed(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function Ad(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function zd(t){const e={tooltip:{metrics:[]}};return x.defaultsDeep(e,t)}function $d(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Ld extends be{constructor(){super(...arguments);N(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Dd(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Md(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Id(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Ed(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Ad(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:zd(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:$d(a,r)}})}}const Od={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Ld,name:"boxplot",viewRender:yd,configRender:Td,createConfig(){return{version:8,config:x.cloneDeep(kr)}},triggers:[Cs]},Ms={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Bd,configRender:Pd,payload:[]};function Pd(t){return i(V,{})}function Bd(t){return i(s.Text,{children:"Click this button"})}const Ir={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Vd={left:"flex-start",center:"center",right:"flex-end"},Nd={top:"flex-start",center:"center",bottom:"flex-end"},qd=k.observer(({context:t,instance:e})=>{const n=tt({vizManager:t.vizManager,instance:e}),r=He(n.triggerManager,Ms.id),a=K(),{value:o}=W(t.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Ir),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=t.viewport,m=a.payloadForSQL,w=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Vd[c],alignItems:Nd[d]},children:i(s.Button,{...f,onClick:w,children:x.template(u)(m)})})}),Fd=({value:t,onChange:e,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>e(l),[e]),o=l=>t===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Gd=s.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),Wd=({label:t,value:e,onChange:n})=>i(s.Select,{data:Gd,label:t,value:e,onChange:n}),jd=[{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}],Rd=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Yd=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Qd({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Ir),[e]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:jd,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Fd,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Wd,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Rd,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:Yd,...g})})]})]})]})}class Kd extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const Ud={displayName:"Button",displayGroup:"Others",migrator:new Kd,name:"button",viewRender:qd,configRender:Qd,createConfig(){return{version:2,config:x.cloneDeep(Ir)}},triggers:[Ms]},Er={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Jd,configRender:Xd,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 Xd(t){return i(V,{})}function Jd(t){return i(s.Text,{children:"Click chart's series"})}const Bt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Ar={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:$e}],reference_lines:[],reference_areas:[],dataZoom:Bt};function zr(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Zd(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function Hd(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function ep(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function tp(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:ep(r),...Hd(r)})),e}function Mn(t,e){switch(t.config.method){case"linear":return[...ht.regressionLinear()(e)];case"exponential":return[...ht.regressionExp()(e)];case"logarithmic":return[...ht.regressionLog()(e)];case"polynomial":return[...ht.regressionPoly().order(t.config.order)(e)];default:return[]}}function np(t,e,n,r){const{transform:a,plot:o}=t,l={...o,name:e,data:Mn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function rp({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=np(o,l,u,c);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===e){const h=lt(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=q(o.y_axis_data_key),d=x.groupBy(xn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((w,C)=>[C,Number(w[c])]);a(o,f,f,g)})}),r}function ip(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function ap(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function sp({type:t,...e},n,r,a){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:u}=q(r),c=x.keyBy(xn(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:_t.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function $r(t,e,n){const r=lt(t,e),a=lt(t,n);return x.zip(r,a)}function op(t,e,n,r){const a=$r(e,n,r);return x.unionBy(a,t,0)}function lp({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?op(t,e,n,r):lt(e,r)}function up({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return lp({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=$r(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const h=u[d].map(m=>m[1]),g=Dr(h,n);return[d,g]})}function cp({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=$r({[a]:c},n,r)}),l}function dp({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},w,C,_,T){const I=e.type!=="category",O={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:sp(h,C,t,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return O.data=up({dataTemplate:w,data:C,aggregation_on_value:u,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:I}),O;const B=cp({group_by_key:l,data:C,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(B).map(([$,A])=>{const E=x.cloneDeep(O);return E.name=$,E.color=void 0,E.data=A,E})}function pp(t,e,n,r,a,o){const l=e.map(c=>[c,0]);return t.series.map(c=>dp(t,c,l,n,o,r)).flat().concat(ap(t.reference_lines,a,o,n)).concat(ip(t.reference_areas,o))}function hp(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Ot(e.x_axis.axisLabel.formatter)(r,a)}function fp(t,e,n){const r=e.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
166
+ `,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[pd(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Mr(t){return hd(t)}function Jt(t,e,n){const r=dd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Mr(o);const c=r[u[1]];if(!c)return Mr(o);const d=u[2]??"";return p(y.Fragment,{children:[c,Mr(d)]},`${o}-${l}`)})}function fd(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=kn(e,o,l);n[a]=et(r,u)}),n}function Tn(t,e,n){const r=fd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function gd(t,e,n){const r=e.reduce((a,o)=>{const l=yt(o,n);return a[o.name]=et(o,l),a},{});return t.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Tn(a.template,e,n)},position:"insideEndTop"}}}))}function md({config:t,data:e,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=t,l=Gc(t,e),u=ut(r.axisLabel.overflow.on_axis),c=jc(t);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:Wc({config:t}),tooltip:Xc({config:t}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Ot(r.axisLabel.formatter)}}],yAxis:[{name:a.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return ee(d).format(a.label_formatter)}}}],series:[...c,...gd(o,n,e)]}}function bt(t,e){return y.useMemo(()=>{const{queryID:n,columnKey:r}=q(e);return x.keyBy(t[n],r)},[t,e])}le.use([G.DataZoomComponent,pe.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function yd({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),{variables:r}=t,a=t.data,{width:o,height:l}=t.viewport,u=x.defaults({},n,kr),c=tt({vizManager:t.vizManager,instance:e}),d=He(c.triggerManager,Cs.id),f=bt(a,u.x_axis.data_key),h=y.useCallback(w=>{const C=x.get(f,w.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...w,rowData:C})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>md({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Ne,{echarts:le,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})}function bd({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},children:i(D.Trash,{size:16})})]},e)}function vd({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(bd,{control:t,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const xd=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Dn=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(nt.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(xd,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),wd=({control:t,watch:e})=>(e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})),Cd=({control:t,watch:e})=>(e(["y_axis"]),p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})]})),Sd=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),_d=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Sd,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function kd({control:t,watch:e}){return i(s.Stack,{children:i(_d,{control:t,watch:e})})}function Td({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},e,kr),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,e),[f,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(wd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Cd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(kd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Pe,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(vd,{variables:r,control:o,watch:u})})]})]})})}function Dd(t){return x.omit(t,"variables")}function Md(t){const{label_formatter:e=$e,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function Id(t){const e={rotate:0,formatter:{...nt}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function Ed(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function Ad(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function zd(t){const e={tooltip:{metrics:[]}};return x.defaultsDeep(e,t)}function $d(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Ld extends ve{constructor(){super(...arguments);N(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Dd(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Md(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Id(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Ed(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Ad(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:zd(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:$d(a,r)}})}}const Od={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Ld,name:"boxplot",viewRender:yd,configRender:Td,createConfig(){return{version:8,config:x.cloneDeep(kr)}},triggers:[Cs]},Ms={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Bd,configRender:Pd,payload:[]};function Pd(t){return i(V,{})}function Bd(t){return i(s.Text,{children:"Click this button"})}const Ir={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Vd={left:"flex-start",center:"center",right:"flex-end"},Nd={top:"flex-start",center:"center",bottom:"flex-end"},qd=k.observer(({context:t,instance:e})=>{const n=tt({vizManager:t.vizManager,instance:e}),r=He(n.triggerManager,Ms.id),a=K(),{value:o}=W(t.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Ir),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=t.viewport,m=a.payloadForSQL,w=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Vd[c],alignItems:Nd[d]},children:i(s.Button,{...f,onClick:w,children:x.template(u)(m)})})}),Fd=({value:t,onChange:e,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>e(l),[e]),o=l=>t===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Gd=s.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),Wd=({label:t,value:e,onChange:n})=>i(s.Select,{data:Gd,label:t,value:e,onChange:n}),jd=[{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}],Rd=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Yd=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Qd({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Ir),[e]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:jd,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Fd,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Wd,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Rd,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:Yd,...g})})]})]})]})}class Kd extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const Ud={displayName:"Button",displayGroup:"Others",migrator:new Kd,name:"button",viewRender:qd,configRender:Qd,createConfig(){return{version:2,config:x.cloneDeep(Ir)}},triggers:[Ms]},Er={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Jd,configRender:Xd,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 Xd(t){return i(V,{})}function Jd(t){return i(s.Text,{children:"Click chart's series"})}const Bt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Ar={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:$e}],reference_lines:[],reference_areas:[],dataZoom:Bt};function zr(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Zd(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function Hd(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function ep(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function tp(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:ep(r),...Hd(r)})),e}function Mn(t,e){switch(t.config.method){case"linear":return[...ht.regressionLinear()(e)];case"exponential":return[...ht.regressionExp()(e)];case"logarithmic":return[...ht.regressionLog()(e)];case"polynomial":return[...ht.regressionPoly().order(t.config.order)(e)];default:return[]}}function np(t,e,n,r){const{transform:a,plot:o}=t,l={...o,name:e,data:Mn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function rp({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=np(o,l,u,c);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===e){const h=lt(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=q(o.y_axis_data_key),d=x.groupBy(xn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((w,C)=>[C,Number(w[c])]);a(o,f,f,g)})}),r}function ip(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function ap(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function sp({type:t,...e},n,r,a){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:u}=q(r),c=x.keyBy(xn(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:_t.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function $r(t,e,n){const r=lt(t,e),a=lt(t,n);return x.zip(r,a)}function op(t,e,n,r){const a=$r(e,n,r);return x.unionBy(a,t,0)}function lp({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?op(t,e,n,r):lt(e,r)}function up({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return lp({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=$r(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const h=u[d].map(m=>m[1]),g=Dr(h,n);return[d,g]})}function cp({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=$r({[a]:c},n,r)}),l}function dp({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},w,C,_,T){const I=e.type!=="category",O={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:sp(h,C,t,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return O.data=up({dataTemplate:w,data:C,aggregation_on_value:u,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:I}),O;const B=cp({group_by_key:l,data:C,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(B).map(([$,A])=>{const E=x.cloneDeep(O);return E.name=$,E.color=void 0,E.data=A,E})}function pp(t,e,n,r,a,o){const l=e.map(c=>[c,0]);return t.series.map(c=>dp(t,c,l,n,o,r)).flat().concat(ap(t.reference_lines,a,o,n)).concat(ip(t.reference_areas,o))}function hp(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Ot(e.x_axis.axisLabel.formatter)(r,a)}function fp(t,e,n){const r=e.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
167
167
  <tr>
168
168
  <td>${f}</td>
169
169
  <th style="text-align: right; padding: 0 1em;">${d}</th>
@@ -179,7 +179,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
179
179
  </tbody>
180
180
  </table>
181
181
  `}}}function gp(t){return t.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return ee(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Is(t,e){const n={};return e.map(r=>{const a=yt(r,t);n[r.name]=et(r,a)}),n}function mp(t,e){const{overflow:n,...r}=t.x_axis.axisLabel,a=ut(n.on_axis);return[{data:e,name:t.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:t.x_axis.type,axisLabel:{...r,...a,formatter:Ot(r.formatter)}}]}function yp(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,show:o,...l},u)=>{let c=l.position;return c||(c=u>0?"right":"left"),{...l,show:o,min:r||void 0,max:a||void 0,position:c,axisLabel:{show:o,formatter:e[u]??e.default},axisLine:{show:o},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:o?15:0,splitLine:{show:!1}}})}const bp={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function vp(t,e,n){const r=Is(e,n),a=gp(t),o=x.uniq(lt(e,t.x_axis_data_key)),l=pp(t,o,e,a,n,r),u=rp(t,e),c={xAxis:mp(t,o),yAxis:yp(t,a),series:[...l,...u],tooltip:fp(t,l,a),grid:Zd(t),legend:tp(l),dataZoom:zr(t.dataZoom)};return x.defaultsDeep({},c,bp)}function Es(t){const e=t.getModel(),n=e.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=e.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});t.setOption({...t.getOption(),series:n})}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function As(t){return t.trim().length>0}function xp({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.x_axis_data_key),u=He(a.triggerManager,Er.id),c=y.useCallback(m=>{const w=x.get(l,m.name,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...m,rowData:w})})},[l,u,a]),d=y.useMemo(()=>vp(t,e,o),[t,e]),f=y.useRef(),h=y.useMemo(()=>({click:c}),[c]),g=m=>{f.current=m,Es(m)};return y.useEffect(()=>{f.current&&Es(f.current)},[d]),!n||!r?null:i(Ne,{echarts:le,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function wp({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Ar),[r]),l=t.data,{width:u,height:c}=t.viewport,{ref:d,height:f}=Me.useElementSize(),{ref:h,height:g}=Me.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Jt(C.top,a,l),bottom:Jt(C.bottom,a,l)}},[o,l]),w=Math.max(0,c-f-g);return p(s.Box,{children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:As(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((C,_)=>i(y.Fragment,{children:C},_))}),i(xp,{variables:a,width:u,height:w,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:As(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((C,_)=>i(y.Fragment,{children:C},_))})]})}const Lr=y.forwardRef(({value:t,onChange:e},n)=>{const r=a=>o=>{e({...t,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:t.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:t.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:t.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!t.y_axis_slider,checked:t.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Cp=[{label:"Rectangle",value:"rectangle"}],Sp=[{label:"Horizontal",value:"horizontal"}];function _p({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.color`,control:t,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.type`,control:t,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Cp,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:Sp,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.y_keys.upper`,control:t,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.y_keys.lower`,control:t,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]},e)}function kp({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[p(s.Tabs.List,{children:[u.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(_p,{control:t,index:h,remove:o,variableOptions:d})},h))]})}const Tp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Dp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Mp({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Dp,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:Tp,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function Ip({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(Mp,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},m))]})}const Ep=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Ap=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function zp({control:t,regressionItem:e,index:n,remove:r,yAxisOptions:a}){const o=e.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:t,render:({field:l})=>i(s.Select,{label:"Method",data:Ep,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:t,render:({field:l})=>i(s.Select,{label:"Line Type",data:Ap,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function $p({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=e("y_axes"),c=y.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(zp,{regressionItem:f,control:t,index:h,remove:a,yAxisOptions:c},h)},h))]})}const Or={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
- `)}},Lp=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Op({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Lp,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Pp=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Bp=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Or.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Pp,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Vp=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Bp,{value:t,onChange:e}),Np=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},qp=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],zs=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Or[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:qp,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Np,{value:e,onChange:n}),i(Vp,{value:e,onChange:n})]})}),Fp=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Gp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Wp({control:t,index:e,seriesItem:n}){const r=n.showSymbol;return p(V,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${e}.lineStyle.type`,control:t,render:({field:a})=>i(s.Select,{label:"Line Type",data:Gp,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.lineStyle.width`,control:t,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${e}.step`,control:t,render:({field:a})=>i(s.Select,{label:"Step",data:Fp,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.smooth`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${e}.display_name_on_line`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.showSymbol`,control:t,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:a})=>i(zs,{label:"Symbol Size",...a})})]})]})}function jp({control:t,index:e}){return i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>i(zs,{label:"Size",...n})})}const Rp=[{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 Yp({control:t,index:e,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${e}.type`,control:t,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>i(Sn,{label:"Aggregation on Value",value:l.value??Pt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Wp,{index:e,control:t,seriesItem:r}),o==="bar"&&i(Op,{index:e,control:t,seriesItem:r}),o==="scatter"&&i(jp,{index:e,control:t}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>i(s.Select,{label:"Label Position",data:Rp,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Qp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:Me.randomId(),showSymbol:!1,symbolSize:Or.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:""};r(f)},c=e("y_axes"),d=y.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Yp,{control:t,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function Kp({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Up=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(L.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),Xp=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Jp({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:t,render:({field:n})=>i(s.Select,{label:i(Up,{}),required:!0,data:Xp,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}const Zp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Hp=[{label:"left",value:"left"},{label:"right",value:"right"}];function eh({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Zp,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Hp,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function th({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:$e,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(eh,{control:t,index:d,remove:a})},d))]})}function nh({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,Ar),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Jp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(th,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(Qp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i($p,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(Kp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ip,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(kp,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(Lr,{...g})})})]})]})})}function rh(t){const e=x.cloneDeep(x.omit(t,"variables"));return e.stats=x.omit(e.stats,"variables"),e}function ih(t){const{rotate:e,formatter:n=nt}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function ah(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function sh(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function oh(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...t,reference_lines:e}}function lh(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function uh(t){const e=t.series.map(n=>{const{aggregation_on_group:r=Pt}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function ch(t){const e=t.series.map(n=>{const{aggregation_on_value:r=Pt}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function dh(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function ph(t){const{series:e,...n}=t;return{...n,series:e.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function hh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function fh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function gh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function mh(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function yh(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Pt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function bh(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function vh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=t;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class xh extends be{constructor(){super(...arguments);N(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:rh(a)}}),this.version(3,n=>({...n,version:3,config:ih(n.config)})),this.version(4,n=>({...n,version:4,config:ah(n.config)})),this.version(5,n=>({...n,version:5,config:sh(n.config)})),this.version(6,n=>({...n,version:6,config:oh(n.config)})),this.version(7,n=>({...n,version:7,config:lh(n.config)})),this.version(8,n=>({...n,version:8,config:uh(n.config)})),this.version(9,n=>({...n,version:9,config:ch(n.config)})),this.version(10,n=>({...n,version:10,config:dh(n.config)})),this.version(11,n=>({...n,version:11,config:ph(n.config)})),this.version(12,n=>({...n,version:12,config:hh(n.config)})),this.version(13,n=>({...n,version:13,config:fh(n.config)})),this.version(14,n=>({...n,version:14,config:gh(n.config)})),this.version(15,n=>({...n,version:15,config:mh(n.config)})),this.version(16,n=>({...n,version:16,config:yh(n.config)})),this.version(17,n=>({...n,version:17,config:bh(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:vh(n.config,r)}))}}const wh={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new xh,name:"cartesian",viewRender:wp,configRender:nh,createConfig(){return{version:18,config:x.cloneDeep(Ar)}},triggers:[Er]};function Ch(t){if(t.enable_value)return t.value}function Sh(t){if(t.enable_value)return t.value}function _h(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&x.get(r,n)&&n===t.funnelAlign&&x.set(r,n,e),r}function kh(t,e){return t.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=q(r),g=q(a),m=e[h.queryID].map(C=>({name:C[h.columnKey],value:C[g.columnKey]})),w=ut(o.overflow.on_axis);return{type:"funnel",..._h(n),min:Ch(l),max:Sh(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...w},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function Th({conf:t,params:e,max:n}){const{name:r,value:a}=e.data,o=ee(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Dh(t,e){var o;const n=q(t.series[0].level_name_data_key),r=q(t.series[0].level_value_data_key),a=(o=x.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Th({conf:t,params:l,max:a}).map(f=>`
182
+ `)}},Lp=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Op({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Lp,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Pp=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Bp=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Or.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Pp,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Vp=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Bp,{value:t,onChange:e}),Np=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},qp=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],zs=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Or[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:qp,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Np,{value:e,onChange:n}),i(Vp,{value:e,onChange:n})]})}),Fp=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Gp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Wp({control:t,index:e,seriesItem:n}){const r=n.showSymbol;return p(V,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${e}.lineStyle.type`,control:t,render:({field:a})=>i(s.Select,{label:"Line Type",data:Gp,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.lineStyle.width`,control:t,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${e}.step`,control:t,render:({field:a})=>i(s.Select,{label:"Step",data:Fp,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.smooth`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${e}.display_name_on_line`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.showSymbol`,control:t,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:a})=>i(zs,{label:"Symbol Size",...a})})]})]})}function jp({control:t,index:e}){return i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>i(zs,{label:"Size",...n})})}const Rp=[{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 Yp({control:t,index:e,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${e}.type`,control:t,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>i(Sn,{label:"Aggregation on Value",value:l.value??Pt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Wp,{index:e,control:t,seriesItem:r}),o==="bar"&&i(Op,{index:e,control:t,seriesItem:r}),o==="scatter"&&i(jp,{index:e,control:t}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>i(s.Select,{label:"Label Position",data:Rp,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Qp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:Me.randomId(),showSymbol:!1,symbolSize:Or.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:""};r(f)},c=e("y_axes"),d=y.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Yp,{control:t,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function Kp({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Up=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(L.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),Xp=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Jp({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:t,render:({field:n})=>i(s.Select,{label:i(Up,{}),required:!0,data:Xp,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}const Zp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Hp=[{label:"left",value:"left"},{label:"right",value:"right"}];function eh({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Zp,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Hp,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function th({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:$e,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(eh,{control:t,index:d,remove:a})},d))]})}function nh({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,Ar),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Jp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(th,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(Qp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i($p,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(Kp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ip,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(kp,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(Lr,{...g})})})]})]})})}function rh(t){const e=x.cloneDeep(x.omit(t,"variables"));return e.stats=x.omit(e.stats,"variables"),e}function ih(t){const{rotate:e,formatter:n=nt}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function ah(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function sh(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function oh(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...t,reference_lines:e}}function lh(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function uh(t){const e=t.series.map(n=>{const{aggregation_on_group:r=Pt}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function ch(t){const e=t.series.map(n=>{const{aggregation_on_value:r=Pt}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function dh(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function ph(t){const{series:e,...n}=t;return{...n,series:e.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function hh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function fh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function gh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function mh(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function yh(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Pt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function bh(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function vh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=t;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class xh extends ve{constructor(){super(...arguments);N(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:rh(a)}}),this.version(3,n=>({...n,version:3,config:ih(n.config)})),this.version(4,n=>({...n,version:4,config:ah(n.config)})),this.version(5,n=>({...n,version:5,config:sh(n.config)})),this.version(6,n=>({...n,version:6,config:oh(n.config)})),this.version(7,n=>({...n,version:7,config:lh(n.config)})),this.version(8,n=>({...n,version:8,config:uh(n.config)})),this.version(9,n=>({...n,version:9,config:ch(n.config)})),this.version(10,n=>({...n,version:10,config:dh(n.config)})),this.version(11,n=>({...n,version:11,config:ph(n.config)})),this.version(12,n=>({...n,version:12,config:hh(n.config)})),this.version(13,n=>({...n,version:13,config:fh(n.config)})),this.version(14,n=>({...n,version:14,config:gh(n.config)})),this.version(15,n=>({...n,version:15,config:mh(n.config)})),this.version(16,n=>({...n,version:16,config:yh(n.config)})),this.version(17,n=>({...n,version:17,config:bh(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:vh(n.config,r)}))}}const wh={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new xh,name:"cartesian",viewRender:wp,configRender:nh,createConfig(){return{version:18,config:x.cloneDeep(Ar)}},triggers:[Er]};function Ch(t){if(t.enable_value)return t.value}function Sh(t){if(t.enable_value)return t.value}function _h(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&x.get(r,n)&&n===t.funnelAlign&&x.set(r,n,e),r}function kh(t,e){return t.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=q(r),g=q(a),m=e[h.queryID].map(C=>({name:C[h.columnKey],value:C[g.columnKey]})),w=ut(o.overflow.on_axis);return{type:"funnel",..._h(n),min:Ch(l),max:Sh(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...w},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function Th({conf:t,params:e,max:n}){const{name:r,value:a}=e.data,o=ee(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Dh(t,e){var o;const n=q(t.series[0].level_name_data_key),r=q(t.series[0].level_value_data_key),a=(o=x.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Th({conf:t,params:l,max:a}).map(f=>`
183
183
  <tr>
184
184
  <th style="text-align: right;">
185
185
  <div style="${f.style.label}">${f.label}</div>
@@ -195,7 +195,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
195
195
  <table style="width: auto">
196
196
  <tbody>${c.join("")}</tbody>
197
197
  </table>
198
- `}}function Mh(t,e){return{trigger:"item",confine:!0,formatter:Dh(t,e)}}function Ih(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Mh(t,e),series:kh(t,e)}}function Eh(t){return t||(t=Date.now().toString()),{id:t,name:t,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Pr={series:[Eh("Funnel")]};le.use([pe.FunnelChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Ah({conf:t,data:e,width:n,height:r}){const a=y.useMemo(()=>Ih(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function zh({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,Pr),[e]),r=t.data,{width:a,height:o}=t.viewport;return i(s.Box,{children:i(Ah,{width:a,height:o,data:r,conf:n})})}const $h=[{label:"Top",value:"top"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Bottom",value:"bottom"},{label:"Outside",value:"outside"},{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"}],Br=y.forwardRef(({label:t,value:e,onChange:n,options:r=$h},a)=>i(s.Select,{ref:a,label:t,data:r,value:e,onChange:n})),Lh=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Oh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ph=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Bh={horizontal:[{label:"Top",value:"top"},{label:"Inside Center",value:"inside"},{label:"Bottom",value:"bottom"}],vertical:[{label:"Left",value:"left"},{label:"Inside Left",value:"insideLeft"},{label:"Inside Center",value:"inside"},{label:"Inside Right",value:"insideRight"},{label:"Right",value:"right"}]},Vh=({item:t,control:e,index:n,remove:r})=>{const a=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Series Name",...u})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.level_name_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Value Field",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.min.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Min Value"}),i(s.Tooltip,{label:"Check to enable specific min value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.min.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.min.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.max.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Max Value"}),i(s.Tooltip,{label:"Check to enable specific max value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.max.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.max.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.orient`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Ph,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:e,render:({field:u})=>i(s.Select,{label:"Sort",data:Lh,...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:Oh,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:e,render:({field:u})=>i(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.axisLabel.position`,control:e,render:({field:u})=>i(Br,{label:"Position",options:Bh[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:e,render:({field:u})=>i(gt,{...u})})})]})},Nh=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),u=x.get(l,"0.id"),[c,d]=y.useState(u??null);return y.useEffect(()=>{u&&d(f=>f!==null?f:u)},[u]),p(s.Tabs,{value:c,onTabChange:f=>d(f),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:f.id,children:f.name},f.id)),i(s.Tabs.Tab,{value:"add",disabled:!0,children:i(s.Tooltip,{label:"TODO",children:i(s.Center,{children:i(L.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:f.id,children:i(Vh,{item:f,control:t,index:h,remove:a})},f.id))]})};function qh({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Pr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Funnel Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(Nh,{control:a,watch:l})]})})}function Fh(t){return{series:t.series.map(e=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function Gh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=t;return{...o,series:a.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wh extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Fh(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Gh(a,r)}})}}const jh={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Wh,name:"funnel",viewRender:zh,configRender:qh,createConfig:()=>({version:3,config:Pr})};function $s({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Rh(t){const e=$s(t.x_axis.axisLabel.formatter),n=$s(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function Yh(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return ee(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Qh(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function Kh(t,e){const{x_axis:n,y_axis:r,heat_block:a}=t,o=q(n.data_key),l=q(r.data_key),u=q(a.data_key),c=e[o.queryID].map(d=>[x.get(d,o.columnKey),x.get(d,l.columnKey),x.get(d,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:2},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const Uh=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Xh({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(u,l),style:{label:"",value:mt(t.x_axis.axisLabel.overflow.in_tooltip)}},h={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(c,l),style:{label:"",value:mt(t.y_axis.axisLabel.overflow.in_tooltip)}},g={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,h,g],w=r[`${u}---${c}`];return w&&t.tooltip.metrics.forEach(C=>{const _=q(C.data_key);m.push({label:C.name,value:Uh(x.get(w,_.columnKey,"")),style:{label:"",value:""}})}),m}function Jh(t,e,n,r){const{x_axis:a,y_axis:o,heat_block:l}=t,u=q(a.data_key),c=q(o.data_key);q(l.data_key);const d=x.keyBy(e[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=Xh({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(w=>`
198
+ `}}function Mh(t,e){return{trigger:"item",confine:!0,formatter:Dh(t,e)}}function Ih(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Mh(t,e),series:kh(t,e)}}function Eh(t){return t||(t=Date.now().toString()),{id:t,name:t,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Pr={series:[Eh("Funnel")]};le.use([pe.FunnelChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Ah({conf:t,data:e,width:n,height:r}){const a=y.useMemo(()=>Ih(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function zh({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,Pr),[e]),r=t.data,{width:a,height:o}=t.viewport;return i(s.Box,{children:i(Ah,{width:a,height:o,data:r,conf:n})})}const $h=[{label:"Top",value:"top"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Bottom",value:"bottom"},{label:"Outside",value:"outside"},{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"}],Br=y.forwardRef(({label:t,value:e,onChange:n,options:r=$h},a)=>i(s.Select,{ref:a,label:t,data:r,value:e,onChange:n})),Lh=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Oh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ph=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Bh={horizontal:[{label:"Top",value:"top"},{label:"Inside Center",value:"inside"},{label:"Bottom",value:"bottom"}],vertical:[{label:"Left",value:"left"},{label:"Inside Left",value:"insideLeft"},{label:"Inside Center",value:"inside"},{label:"Inside Right",value:"insideRight"},{label:"Right",value:"right"}]},Vh=({item:t,control:e,index:n,remove:r})=>{const a=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Series Name",...u})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.level_name_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Value Field",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.min.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Min Value"}),i(s.Tooltip,{label:"Check to enable specific min value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.min.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.min.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.max.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Max Value"}),i(s.Tooltip,{label:"Check to enable specific max value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.max.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.max.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.orient`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Ph,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:e,render:({field:u})=>i(s.Select,{label:"Sort",data:Lh,...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:Oh,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:e,render:({field:u})=>i(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.axisLabel.position`,control:e,render:({field:u})=>i(Br,{label:"Position",options:Bh[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:e,render:({field:u})=>i(gt,{...u})})})]})},Nh=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),u=x.get(l,"0.id"),[c,d]=y.useState(u??null);return y.useEffect(()=>{u&&d(f=>f!==null?f:u)},[u]),p(s.Tabs,{value:c,onTabChange:f=>d(f),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:f.id,children:f.name},f.id)),i(s.Tabs.Tab,{value:"add",disabled:!0,children:i(s.Tooltip,{label:"TODO",children:i(s.Center,{children:i(L.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:f.id,children:i(Vh,{item:f,control:t,index:h,remove:a})},f.id))]})};function qh({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Pr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Funnel Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(Nh,{control:a,watch:l})]})})}function Fh(t){return{series:t.series.map(e=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function Gh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=t;return{...o,series:a.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wh extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Fh(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Gh(a,r)}})}}const jh={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Wh,name:"funnel",viewRender:zh,configRender:qh,createConfig:()=>({version:3,config:Pr})};function $s({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Rh(t){const e=$s(t.x_axis.axisLabel.formatter),n=$s(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function Yh(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return ee(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Qh(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function Kh(t,e){const{x_axis:n,y_axis:r,heat_block:a}=t,o=q(n.data_key),l=q(r.data_key),u=q(a.data_key),c=e[o.queryID].map(d=>[x.get(d,o.columnKey),x.get(d,l.columnKey),x.get(d,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:2},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const Uh=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Xh({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(u,l),style:{label:"",value:mt(t.x_axis.axisLabel.overflow.in_tooltip)}},h={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(c,l),style:{label:"",value:mt(t.y_axis.axisLabel.overflow.in_tooltip)}},g={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,h,g],w=r[`${u}---${c}`];return w&&t.tooltip.metrics.forEach(C=>{const _=q(C.data_key);m.push({label:C.name,value:Uh(x.get(w,_.columnKey,"")),style:{label:"",value:""}})}),m}function Jh(t,e,n,r){const{x_axis:a,y_axis:o,heat_block:l}=t,u=q(a.data_key),c=q(o.data_key);q(l.data_key);const d=x.keyBy(e[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=Xh({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(w=>`
199
199
  <tr>
200
200
  <th style="text-align: right;">
201
201
  <div style="${w.style.label}">${w.label}</div>
@@ -218,7 +218,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
218
218
  </table>
219
219
  `}}}const Zh=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ls={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
220
220
  `)}},Hh=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,value:g}=o,m={type:h,value:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,value:h}))},f=()=>{d(Ls.dynamic.value)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Zh,{value:o.value,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},ef=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Hh,{value:t,onChange:e}),tf=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,value:r})};return i(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:t.value,onChange:n})},nf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],In=y.forwardRef(({label:t="Value",value:e,onChange:n},r)=>{const a=o=>{n({...Ls[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:nf,value:e.type,onChange:a,sx:{flexGrow:1}}),i(tf,{value:e,onChange:n}),i(ef,{value:e,onChange:n})]})});function En(t,e,n){if(!t.type)return n;if(t.type==="static"){const{value:a}=t;return a}const{value:r}=t;try{return console.log("returning here"),new Function(`return ${r}`)()({variables:e},{lodash:x,interpolate:_t.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function rf(t,e){const n=En(t.heat_block.min,e),r=En(t.heat_block.max,e);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function af(t,e,n){const r=q(t.x_axis.data_key),a=x.uniq(e[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=t.x_axis.axisLabel,u=ut(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:t.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 sf(t,e,n){const r=q(t.x_axis.data_key),a=q(t.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=t.y_axis,c=x.uniq(e[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=t.y_axis.axisLabel,h=ut(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:1}}const of={tooltip:{confine:!0}};function lf(t,e,n){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=yt(c,e);return u[c.name]=et(c,d),u},{}),a=Rh(t),o=Yh(t),l={xAxis:af(t,e,a.x_axis),yAxis:sf(t,e,a.y_axis),series:Kh(t,e),tooltip:Jh(t,e,a,o),grid:Qh(t),visualMap:rf(t,r)};return x.defaultsDeep({},l,of)}function uf(t){return i(V,{})}function cf(t){return i(s.Text,{children:"Click heat block"})}const Os={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:cf,configRender:uf,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"}]},Vr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ze,formatter:{...nt}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ze,formatter:{...nt}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};le.use([G.DataZoomComponent,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function df({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const h=q(t.x_axis.data_key),g=q(t.y_axis.data_key);return x.keyBy(e[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),u=He(a.triggerManager,Os.id),c=y.useCallback(h=>{const[g,m]=h.value,w=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...h,rowData:w})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>lf(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function pf({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Vr),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(df,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function hf({control:t,watch:e}){e(["heat_block"]);const n=e("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:r})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:r})=>i(In,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:r})=>i(In,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:r})=>i(Re,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:t,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:t,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(L.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const ff=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),gf=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(ff,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function mf({control:t,watch:e}){return i(gf,{control:t,watch:e})}const yf=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},bf={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
221
- `)},Ps=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(bf.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(yf,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function vf({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ps,{...n})})]})]})}const xf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function wf({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:xf,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ps,{...n})})]})]})}function Cf({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Vr),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:l(n),style:{flexGrow:1},children:p(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(vf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(wf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(hf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(mf,{control:o,watch:u})})]})]})})}function Sf(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=t;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function _f(t){return x.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}function kf(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tf extends be{constructor(){super(...arguments);N(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Sf(n.config,r)})),this.version(3,n=>({...n,version:3,config:_f(n.config)})),this.version(4,n=>({...n,version:4,config:kf(n.config)}))}}const Df={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Tf,name:"heatmap",viewRender:pf,configRender:Cf,createConfig:()=>({version:4,config:Vr}),triggers:[Os]},Bs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:If,configRender:Mf,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 Mf(t){return i(V,{})}function If(t){return i(s.Text,{children:"Click chart's series"})}const Vs={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Nr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:$e},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Bt,markLine:Vs};function An(t){return ee(t).format({output:"percent",mantissa:0})}function Ef(t){const e=t.value[1];try{return An(e)}catch(n){return console.error(n),e}}function Af(t){function e(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!t.bar.label_formatter)return r;try{return ee(r).format(t.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:e,line:Ef,lineValue:An}}function zf(t,e,n){const{label_template:r}=t.markLine;if(!r)return"";const a={...t,percentage:e,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function $f(t,e){if(e.length===0)return{};const n=e.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=e[n],a={x:An((n+1)/e.length),y:An(r[1])},o={left:n+1,right:e.length-n-1},l=r[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:t.markLine.color},label:{formatter:zf(t,a,o)}}]}:{}}function Lf(t,e,n){const{x_axis:r,data_key:a}=t;if(!r.data_key||!a)return[];const o=q(r.data_key),l=q(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=e[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),d=u.reduce((h,g,m)=>{const w=m===0?0:h[m-1][1];return h.push([g[0],w+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=$f(t,d);return[{name:t.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:t.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:t.line.name,type:"line",itemStyle:{color:t.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const Of=(t,e)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const a=r.map((u,c)=>{const d=u.seriesName,[f,h]=u.value;if(!d)return h;const g=c===0?e.bar:e.lineValue;return`
221
+ `)},Ps=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(bf.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(yf,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function vf({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ps,{...n})})]})]})}const xf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function wf({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:xf,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ps,{...n})})]})]})}function Cf({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Vr),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:l(n),style:{flexGrow:1},children:p(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(vf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(wf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(hf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(mf,{control:o,watch:u})})]})]})})}function Sf(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=t;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function _f(t){return x.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}function kf(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tf extends ve{constructor(){super(...arguments);N(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Sf(n.config,r)})),this.version(3,n=>({...n,version:3,config:_f(n.config)})),this.version(4,n=>({...n,version:4,config:kf(n.config)}))}}const Df={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Tf,name:"heatmap",viewRender:pf,configRender:Cf,createConfig:()=>({version:4,config:Vr}),triggers:[Os]},Bs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:If,configRender:Mf,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 Mf(t){return i(V,{})}function If(t){return i(s.Text,{children:"Click chart's series"})}const Vs={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Nr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:$e},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Bt,markLine:Vs};function An(t){return ee(t).format({output:"percent",mantissa:0})}function Ef(t){const e=t.value[1];try{return An(e)}catch(n){return console.error(n),e}}function Af(t){function e(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!t.bar.label_formatter)return r;try{return ee(r).format(t.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:e,line:Ef,lineValue:An}}function zf(t,e,n){const{label_template:r}=t.markLine;if(!r)return"";const a={...t,percentage:e,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function $f(t,e){if(e.length===0)return{};const n=e.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=e[n],a={x:An((n+1)/e.length),y:An(r[1])},o={left:n+1,right:e.length-n-1},l=r[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:t.markLine.color},label:{formatter:zf(t,a,o)}}]}:{}}function Lf(t,e,n){const{x_axis:r,data_key:a}=t;if(!r.data_key||!a)return[];const o=q(r.data_key),l=q(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=e[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),d=u.reduce((h,g,m)=>{const w=m===0?0:h[m-1][1];return h.push([g[0],w+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=$f(t,d);return[{name:t.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:t.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:t.line.name,type:"line",itemStyle:{color:t.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const Of=(t,e)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const a=r.map((u,c)=>{const d=u.seriesName,[f,h]=u.value;if(!d)return h;const g=c===0?e.bar:e.lineValue;return`
222
222
  <tr>
223
223
  <th style="text-align: right; padding: 0 1em;">${d}</th>
224
224
  <td style="text-align: left; padding: 0 1em;">${g(h)}</td>
@@ -255,8 +255,8 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
255
255
  name: string;
256
256
  };
257
257
  }
258
- `,Yf=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Rf})})]})};function Qf({control:t,watch:e}){return e(["markLine"]),p(s.Stack,{children:[p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"markLine.color",control:t,render:({field:n})=>i(Pe,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(Yf,{})]})]})}function Kf({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Uf({control:t,watch:e}){return e(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function Xf({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Nr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Bar",children:"Bar"}),i(s.Tabs.Tab,{value:"Line",children:"Line"}),i(s.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Kf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Uf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(Gf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(jf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(Qf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:h})=>i(Lr,{...h})})})]})]})}function Jf(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Zf(t){const{markLine:e=Vs,...n}=t;return{...n,markLine:e}}function Hf(t){const e=x.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...nt}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function eg(t){const{label_formatter:e=$e}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function tg(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function ng(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(e,t)}function rg(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function ig(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class ag extends be{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Jf(n.config)})),this.version(3,n=>({...n,version:3,config:Zf(n.config)})),this.version(4,n=>({...n,version:4,config:Hf(n.config)})),this.version(5,n=>({...n,version:5,config:eg(n.config)})),this.version(6,n=>({...n,version:6,config:tg(n.config)})),this.version(7,n=>({...n,version:7,config:ng(n.config)})),this.version(8,n=>({...n,version:8,config:rg(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:ig(n.config,r)}))}}const sg={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new ag,name:"paretoChart",viewRender:qf,configRender:Xf,createConfig(){return{version:9,config:x.cloneDeep(Nr)}},triggers:[Bs]},qr={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 og(){le.registerTheme("merico-light",{color:Object.values(qr.graphics.multiple),visualMap:{color:Object.values(qr.graphics.depth).reverse()}})}function Ns(){og()}function*lg(t){const e=qr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function ug(t,e,n){const{label_field:r,value_field:a,color_field:o}=t;if(!r||!a)return{};const l=q(r),u=q(a),c=q(o),d=e[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:c.columnKey?h[c.columnKey]:void 0})),f=lg("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
259
- {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,m=h.labelLinePoints;return x.set(m,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function cg(t,e,n){return{tooltip:{show:!0,confine:!0},series:ug(t,e,n)}}const qs={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:pg,configRender:dg,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:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function dg(t){return i(V,{})}function pg(t){return i(s.Text,{children:"Click chart's series"})}const Fr={label_field:"",value_field:"",color_field:""};le.use([pe.PieChart,Ve.CanvasRenderer]);function hg({conf:t,data:e,width:n,height:r,interactionManager:a}){const o=bt(e,t.label_field),l=He(a.triggerManager,qs.id),u=y.useCallback(f=>{const h=x.get(o,f.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...f,rowData:h})})},[o,l,a]),c=y.useMemo(()=>cg(t,e,n),[t,e,n]),d=y.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:i(Ne,{echarts:le,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function fg({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),a=y.useMemo(()=>x.defaults({},r,Fr),[r]),o=t.data,{width:l,height:u}=t.viewport;return!l||!u?null:i(hg,{conf:a,width:l,height:u,data:o,interactionManager:n})}function gg({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Fr),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["label_field","value_field","color_field"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Pie Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[i(v.Controller,{control:o,name:"label_field",render:({field:g})=>i(j,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(j,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(j,{label:"Color Key",clearable:!0,...g})})]})]})})}function mg(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function yg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=t;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class bg extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:mg(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:yg(n.config,r)}))}}const vg={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new bg,name:"pie",viewRender:fg,configRender:gg,createConfig(){return{version:3,config:x.cloneDeep(Fr)}},triggers:[qs]};function xg(t){return i(V,{})}function wg(t){return i(s.Text,{children:"Click heat block"})}const Fs={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:wg,configRender:xg,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"}]},zn={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Gs(t){return t?e=>{try{return ee(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function Cg(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Gs(t.dimensions[e].formatter)(n)}}function Sg(t){return({name:e,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=t.dimensions[l],c=Gs(u.formatter);return`
258
+ `,Yf=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Rf})})]})};function Qf({control:t,watch:e}){return e(["markLine"]),p(s.Stack,{children:[p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"markLine.color",control:t,render:({field:n})=>i(Pe,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(Yf,{})]})]})}function Kf({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Uf({control:t,watch:e}){return e(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function Xf({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Nr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Bar",children:"Bar"}),i(s.Tabs.Tab,{value:"Line",children:"Line"}),i(s.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Kf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Uf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(Gf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(jf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(Qf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:h})=>i(Lr,{...h})})})]})]})}function Jf(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Zf(t){const{markLine:e=Vs,...n}=t;return{...n,markLine:e}}function Hf(t){const e=x.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...nt}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function eg(t){const{label_formatter:e=$e}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function tg(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function ng(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(e,t)}function rg(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function ig(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class ag extends ve{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Jf(n.config)})),this.version(3,n=>({...n,version:3,config:Zf(n.config)})),this.version(4,n=>({...n,version:4,config:Hf(n.config)})),this.version(5,n=>({...n,version:5,config:eg(n.config)})),this.version(6,n=>({...n,version:6,config:tg(n.config)})),this.version(7,n=>({...n,version:7,config:ng(n.config)})),this.version(8,n=>({...n,version:8,config:rg(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:ig(n.config,r)}))}}const sg={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new ag,name:"paretoChart",viewRender:qf,configRender:Xf,createConfig(){return{version:9,config:x.cloneDeep(Nr)}},triggers:[Bs]},qr={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 og(){le.registerTheme("merico-light",{color:Object.values(qr.graphics.multiple),visualMap:{color:Object.values(qr.graphics.depth).reverse()}})}function Ns(){og()}function*lg(t){const e=qr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function ug(t,e,n){const{label_field:r,value_field:a,color_field:o}=t;if(!r||!a)return{};const l=q(r),u=q(a),c=q(o),d=e[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:c.columnKey?h[c.columnKey]:void 0})),f=lg("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
259
+ {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,m=h.labelLinePoints;return x.set(m,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function cg(t,e,n){return{tooltip:{show:!0,confine:!0},series:ug(t,e,n)}}const qs={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:pg,configRender:dg,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:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function dg(t){return i(V,{})}function pg(t){return i(s.Text,{children:"Click chart's series"})}const Fr={label_field:"",value_field:"",color_field:""};le.use([pe.PieChart,Ve.CanvasRenderer]);function hg({conf:t,data:e,width:n,height:r,interactionManager:a}){const o=bt(e,t.label_field),l=He(a.triggerManager,qs.id),u=y.useCallback(f=>{const h=x.get(o,f.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...f,rowData:h})})},[o,l,a]),c=y.useMemo(()=>cg(t,e,n),[t,e,n]),d=y.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:i(Ne,{echarts:le,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function fg({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),a=y.useMemo(()=>x.defaults({},r,Fr),[r]),o=t.data,{width:l,height:u}=t.viewport;return!l||!u?null:i(hg,{conf:a,width:l,height:u,data:o,interactionManager:n})}function gg({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Fr),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["label_field","value_field","color_field"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Pie Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[i(v.Controller,{control:o,name:"label_field",render:({field:g})=>i(j,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(j,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(j,{label:"Color Key",clearable:!0,...g})})]})]})})}function mg(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function yg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=t;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class bg extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:mg(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:yg(n.config,r)}))}}const vg={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new bg,name:"pie",viewRender:fg,configRender:gg,createConfig(){return{version:3,config:x.cloneDeep(Fr)}},triggers:[qs]};function xg(t){return i(V,{})}function wg(t){return i(s.Text,{children:"Click heat block"})}const Fs={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:wg,configRender:xg,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"}]},zn={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Gs(t){return t?e=>{try{return ee(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function Cg(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Gs(t.dimensions[e].formatter)(n)}}function Sg(t){return({name:e,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=t.dimensions[l],c=Gs(u.formatter);return`
260
260
  <tr>
261
261
  <td style="padding-left: 18px;">${u.name}</td>
262
262
  <td style="text-align: right; "><strong>${c(o)}</strong></td>
@@ -284,7 +284,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
284
284
  ${a.join("")}
285
285
  </tbody>
286
286
  </table>
287
- `}}const _g={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},kg=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Tg(t,e){const{series_name_key:n,dimensions:r}=t;if(!n||r.length===0)return{};const a=r.map(({name:c,max:d})=>({name:c,max:d})),o=q(n),l=e[o.queryID].map(c=>({value:r.map(({data_key:d})=>{const f=q(d);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:a,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Sg(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Cg(t)},color:kg};return x.merge({},_g,u)}le.use([pe.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Dg({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.series_name_key),u=He(a.triggerManager,Fs.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Tg(x.defaultsDeep({},t,zn),e),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Mg({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,zn),[r]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(s.Box,{children:i(Dg,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Ig({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`dimensions.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.max`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${e}.formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(D.Trash,{size:16})})]},e)}function Eg({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"dimensions"}),o=e("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:100,formatter:$e})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(Ig,{control:t,index:m,remove:h})},m))]})]})}function Ag({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,zn),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(s.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),i(v.Controller,{name:"series_name_key",control:a,render:({field:h})=>i(j,{label:"Series Name Field",required:!0,sx:{flex:1},...h})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show background",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show value label",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})})]}),i(Eg,{control:a,watch:l})]})})}function zg(t){const{dimensions:e=[],...n}=t;function r({name:a="",data_key:o="",max:l=10,formatter:u=$e}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:e.map(r)}}function $g(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(r=>({...r,id:r.id??r.name}))}}function Lg(t){const e={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(e,t)}function Og(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=t;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Pg extends be{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:zg(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:$g(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Lg(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:Og(a,r)}})}}const Bg={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Pg,name:"radar",viewRender:Mg,configRender:Ag,createConfig:()=>({version:5,config:zn}),triggers:[Fs]};function Vg(t,e){const{plot:n,transform:r}=t.regression;return e.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Mn(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Ws(t,e){const n=q(t.x_axis.data_key),r=q(t.regression.y_axis_data_key);return x.uniqBy(e.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function Ng(t,e){const{plot:n,transform:r}=t.regression,a=Ws(t,e);return[{type:"scatter",name:t.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Mn(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function qg(t,e){const{plot:n,transform:r,group_by_key:a}=t.regression,o=q(a),l=x.groupBy(e,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=Ws(t,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[Mn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Fg(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?qg(t,e):Ng(t,e)}function Gg(t){return Array.isArray(t)||(t=[t]),t.map(e=>({marker:e.marker,label:e.seriesName,x:e.value[0],y:e.value[1]}))}function Wg(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=Gg(e);return n.length===0?"":`
287
+ `}}const _g={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},kg=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Tg(t,e){const{series_name_key:n,dimensions:r}=t;if(!n||r.length===0)return{};const a=r.map(({name:c,max:d})=>({name:c,max:d})),o=q(n),l=e[o.queryID].map(c=>({value:r.map(({data_key:d})=>{const f=q(d);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:a,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Sg(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Cg(t)},color:kg};return x.merge({},_g,u)}le.use([pe.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Dg({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.series_name_key),u=He(a.triggerManager,Fs.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Tg(x.defaultsDeep({},t,zn),e),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Mg({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,zn),[r]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(s.Box,{children:i(Dg,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Ig({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`dimensions.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.max`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${e}.formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(D.Trash,{size:16})})]},e)}function Eg({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"dimensions"}),o=e("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:100,formatter:$e})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(Ig,{control:t,index:m,remove:h})},m))]})]})}function Ag({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,zn),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(s.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),i(v.Controller,{name:"series_name_key",control:a,render:({field:h})=>i(j,{label:"Series Name Field",required:!0,sx:{flex:1},...h})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show background",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show value label",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})})]}),i(Eg,{control:a,watch:l})]})})}function zg(t){const{dimensions:e=[],...n}=t;function r({name:a="",data_key:o="",max:l=10,formatter:u=$e}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:e.map(r)}}function $g(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(r=>({...r,id:r.id??r.name}))}}function Lg(t){const e={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(e,t)}function Og(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=t;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Pg extends ve{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:zg(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:$g(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Lg(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:Og(a,r)}})}}const Bg={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Pg,name:"radar",viewRender:Mg,configRender:Ag,createConfig:()=>({version:5,config:zn}),triggers:[Fs]};function Vg(t,e){const{plot:n,transform:r}=t.regression;return e.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Mn(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Ws(t,e){const n=q(t.x_axis.data_key),r=q(t.regression.y_axis_data_key);return x.uniqBy(e.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function Ng(t,e){const{plot:n,transform:r}=t.regression,a=Ws(t,e);return[{type:"scatter",name:t.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Mn(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function qg(t,e){const{plot:n,transform:r,group_by_key:a}=t.regression,o=q(a),l=x.groupBy(e,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=Ws(t,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[Mn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Fg(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?qg(t,e):Ng(t,e)}function Gg(t){return Array.isArray(t)||(t=[t]),t.map(e=>({marker:e.marker,label:e.seriesName,x:e.value[0],y:e.value[1]}))}function Wg(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=Gg(e);return n.length===0?"":`
288
288
  <table style="width: auto">
289
289
  <thead>
290
290
  <tr>
@@ -304,7 +304,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
304
304
  </tbody>
305
305
  </table>
306
306
  `}}}function js({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function jg(t){const{overflow:e,format:n,formatter:r,...a}=t.x_axis.axisLabel,o=ut(e.on_axis);return{type:"value",name:t.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...a,...o,formatter:(l,u)=>{let c=l;try{c=ee(l).format(n)}catch{}return js(r)(c,u)}}}}const Rg={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Yg(t,e){const n=Fg(t,e),r=Vg(t,n),a={xAxis:jg(t),yAxis:{name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...r],tooltip:Wg(t),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 x.defaultsDeep({},a,Rg)}function $n(t,e,n){return 1-(1-t)*(e-1)/(e-n-1)}function Qg(t,e,n,r){const{x_axis:a,y_axis:o}=r,l=ht.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:t,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"red",children:ee(c).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"red",children:ee(u).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name})]}),rSquared:d,adjustedRSquared:$n(d,e.length,1)}}function Kg(t,e,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ht.regressionExp()(n);return{name:t,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.exp("}),i(s.Text,{weight:"bold",color:"gray",children:u}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name}),i(s.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:$n(c,e.length,1)}}function Ug(t,e,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ht.regressionLog()(n);return{name:t,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.log("}),i(s.Text,{children:a.name}),i(s.Text,{children:")"}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:$n(c,e.length,1)}}function Xg(t,e,n,r){const{x_axis:a,y_axis:o,regression:l}=r,u=ht.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:t,expression:"",rSquared:c,adjustedRSquared:$n(c,e.length,1)}}function Rs(t,e,n){const{regression:r,x_axis:a}=n,o=q(a.data_key),l=q(r.y_axis_data_key),u=e.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?Qg(t,e,u,n):r.transform.config.method==="exponential"?Kg(t,e,u,n):r.transform.config.method==="logarithmic"?Ug(t,e,u,n):r.transform.config.method==="polynomial"?Xg(t,e,u,n):{name:t,expression:"",rSquared:0,adjustedRSquared:0}}function Jg(t,e){if(!e)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!e.regression.group_by_key)return[Rs("",t,e)];const n=q(e.regression.group_by_key),r=x.groupBy(t,n.columnKey);return Object.entries(r).map(([a,o])=>Rs(a,o,e))}const Zg={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ys({desc:t}){const{expression:e,rSquared:n,adjustedRSquared:r}=t;return e?i(s.Table,{fontSize:14,sx:Zg,children:p("tbody",{children:[i("tr",{children:i("td",{colSpan:2,children:i(s.Text,{align:"center",children:e})})}),p("tr",{children:[i("td",{children:"R-Sq"}),i("td",{style:{textAlign:"right"},children:ee(n).format({output:"percent",mantissa:1})})]}),p("tr",{children:[i("td",{children:"R-Sq(Adjusted)"}),i("td",{style:{textAlign:"right"},children:ee(r).format({output:"percent",mantissa:1})})]})]})}):i(s.Text,{children:"Unavailable for this regression method"})}function Hg({conf:t,queryData:e}){var r;const n=y.useMemo(()=>Jg(e,t),[t,e]);return t.regression.group_by_key?(console.log(n),p(s.Tabs,{defaultValue:(r=n[0])==null?void 0:r.name,color:"gray",children:[i(s.Tabs.List,{grow:!0,children:n.map(a=>i(s.Tabs.Tab,{value:a.name,children:a.name},a.name))}),n.map(a=>i(s.Tabs.Panel,{value:a.name,children:i(Ys,{desc:a})},a.name))]})):i(Ys,{desc:n[0]})}function em({conf:t,queryData:e}){return p(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"Regression Info"})}),i(s.HoverCard.Dropdown,{children:i(Fe,{children:i(Hg,{conf:t,queryData:e})})})]})}function tm(t){return i(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:0,height:"22px",zIndex:1},children:i(em,{...t})})}const Ln={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
307
- `)},Gr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:{...Ln}}},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"}};le.use([G.DataZoomComponent,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function nm({context:t}){const{value:e}=W(t.instanceData,"config"),{width:n,height:r}=t.viewport,a=y.useMemo(()=>{var m;const c=t.data,d=e==null?void 0:e.x_axis.data_key,f=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const h=q(d),g=q(f);return c[h.queryID].map(w=>typeof w[g.columnKey]=="number"?w:{...w,[g.columnKey]:Number(w[g.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=y.useMemo(()=>Yg(x.defaultsDeep({},e,Gr),a),[e,a]),l=y.useRef(null),u=c=>{l.current=c};return!n||!r||!e?null:p(s.Box,{sx:{position:"relative"},children:[i(tm,{conf:e,queryData:a}),i(Ne,{echarts:le,onChartReady:u,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})]})}const rm=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function im({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:t,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:t,render:({field:a})=>i(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:t,render:({field:a})=>i(s.Select,{label:"回归方法",data:rm,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:t,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:t,render:({field:a})=>i(Pe,{...a})})]})]})}const am=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Qs=y.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=X.useBoolean(),[u,c]=y.useState(t);y.useEffect(()=>{c(t)},[t]);const d=w=>{c({...u,enabled:w})},f=()=>{l();const{enabled:w,func_content:C}=u,_={enabled:w,func_content:C};c(_),e(_)},h=()=>{l(),c(t)},g=w=>{c(C=>({...C,func_content:w}))},m=()=>{g(Ln.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),i(s.Modal,{size:800,title:"Customize label content",opened:a,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:w=>d(w.currentTarget.checked)}),i(am,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function sm({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:t,render:({field:n})=>i(Re,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Qs,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function om({control:t,watch:e}){return e(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>i(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function lm({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Gr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X轴",children:"X轴"}),i(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),i(s.Tabs.Tab,{value:"回归",children:"回归"})]}),i(s.Tabs.Panel,{value:"X轴",children:i(sm,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(om,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(im,{control:a,watch:l})})]})]})})}function um(t){const e={x_axis:{axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:Ln}},regression:{group_by_key:""}};return x.defaultsDeep(e,t)}function cm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class dm extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:um(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:cm(a,r)}})}}const pm={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new dm,name:"regressionChart",viewRender:nm,configRender:lm,createConfig(){return{version:3,config:x.cloneDeep(Gr)}}},On={content:""},Wr={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"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function Ks(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(r),o=e.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=Ks(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Us(t,e,n,r){for(let a=t.childCount,o=e.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=t.child(--a),u=e.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=Us(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>e&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,e-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,a){let o="",l=!0;return this.nodesBetween(e,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(e,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)a.push(e.content[o]);return new ae(a,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],a=0;if(n>e)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>e&&((l<e||c>n)&&(u.isText?u=u.cut(Math.max(0,e-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,e-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(e,n){return e==n?ae.empty:e==0&&n==this.content.length?this:new ae(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[e]=n,new ae(a,o)}addToStart(e){return new ae([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new ae(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];e(a,r,n),r+=a.nodeSize}}findDiffStart(e,n=0){return Ks(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Us(this,e,n,r)}findIndex(e,n=-1){if(e==0)return Pn(0,e);if(e==this.size)return Pn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=e)return l==e||n>0?Pn(r+1,l):Pn(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return ae.empty;let n,r=0;for(let a=0;a<e.length;a++){let o=e[a];r+=o.nodeSize,a&&o.isText&&e[a-1].sameMarkup(o)?(n||(n=e.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||e,r)}static from(e){if(!e)return ae.empty;if(e instanceof ae)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new ae([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const jr={index:0,offset:0};function Pn(t,e){return jr.index=t,jr.offset=e,jr}function Rr(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Rr(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Rr(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class We{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let a=0;a<e.length;a++){let o=e[a];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,a));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Rr(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return We.none;if(e instanceof We)return[e];let n=e.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}We.none=[];class hm extends Error{}class ce{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Js(this.content,e+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(e,n){return new ce(Xs(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ae.fromJSON(e,n.content),r,a)}static maxOpen(e,n=!0){let r=0,a=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(e,r,a)}}ce.empty=new ce(ae.empty,0,0);function Xs(t,e,n){let{index:r,offset:a}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:u}=t.findIndex(n);if(a==e||o.isText){if(u!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(Xs(o.content,e-a-1,n-a-1)))}function Js(t,e,n,r){let{index:a,offset:o}=t.findIndex(e),l=t.maybeChild(a);if(o==e||l.isText)return r&&!r.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let u=Js(l.content,e-o-1,n);return u&&t.replaceChild(a,l.copy(u))}class Bn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=e.nodes[r.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let r=new to(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new to(this,n,!0);return r.addAll(e,n.from,n.to),ce.maxOpen(r.finish())}matchTag(e,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(mm(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(e)!=0||l.context&&!r.matchesContext(l.context)||u.length>e.length&&(u.charCodeAt(e.length)!=61||u.slice(e.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(e){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in e.marks){let o=e.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=no(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in e.nodes){let o=e.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=no(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Bn(e,Bn.schemaRules(e)))}}const Zs={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},fm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Hs={ol:!0,ul:!0},Vn=1,Nn=2,Zt=4;function eo(t,e,n){return e!=null?(e?Vn:0)|(e==="full"?Nn:0):t&&t.whitespace=="pre"?Vn|Nn:n&~Zt}class qn{constructor(e,n,r,a,o,l,u){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=We.none,this.stashMarks=[],this.match=l||(u&Zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(e.type))?(this.match=r,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Vn)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ae.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):bm(a.type,e))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Zs.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class to{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=eo(null,n.preserveWhitespace,0)|(r?Zt:0);a?o=new qn(a.type,a.attrs,We.none,We.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new qn(null,null,We.none,We.none,!0,null,l):o=new qn(e.schema.topNodeType,null,We.none,We.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(ym(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(e);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(e){let n=e.nodeValue,r=this.top;if(r.options&Nn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&Vn)r.options&Nn?n=n.replace(/\r\n?/g,`
307
+ `)},Gr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:{...Ln}}},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"}};le.use([G.DataZoomComponent,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function nm({context:t}){const{value:e}=W(t.instanceData,"config"),{width:n,height:r}=t.viewport,a=y.useMemo(()=>{var m;const c=t.data,d=e==null?void 0:e.x_axis.data_key,f=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const h=q(d),g=q(f);return c[h.queryID].map(w=>typeof w[g.columnKey]=="number"?w:{...w,[g.columnKey]:Number(w[g.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=y.useMemo(()=>Yg(x.defaultsDeep({},e,Gr),a),[e,a]),l=y.useRef(null),u=c=>{l.current=c};return!n||!r||!e?null:p(s.Box,{sx:{position:"relative"},children:[i(tm,{conf:e,queryData:a}),i(Ne,{echarts:le,onChartReady:u,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})]})}const rm=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function im({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:t,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:t,render:({field:a})=>i(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:t,render:({field:a})=>i(s.Select,{label:"回归方法",data:rm,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:t,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:t,render:({field:a})=>i(Pe,{...a})})]})]})}const am=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Qs=y.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=X.useBoolean(),[u,c]=y.useState(t);y.useEffect(()=>{c(t)},[t]);const d=w=>{c({...u,enabled:w})},f=()=>{l();const{enabled:w,func_content:C}=u,_={enabled:w,func_content:C};c(_),e(_)},h=()=>{l(),c(t)},g=w=>{c(C=>({...C,func_content:w}))},m=()=>{g(Ln.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),i(s.Modal,{size:800,title:"Customize label content",opened:a,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:w=>d(w.currentTarget.checked)}),i(am,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function sm({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:t,render:({field:n})=>i(Re,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Qs,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function om({control:t,watch:e}){return e(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>i(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function lm({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Gr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X轴",children:"X轴"}),i(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),i(s.Tabs.Tab,{value:"回归",children:"回归"})]}),i(s.Tabs.Panel,{value:"X轴",children:i(sm,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(om,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(im,{control:a,watch:l})})]})]})})}function um(t){const e={x_axis:{axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:Ln}},regression:{group_by_key:""}};return x.defaultsDeep(e,t)}function cm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class dm extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:um(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:cm(a,r)}})}}const pm={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new dm,name:"regressionChart",viewRender:nm,configRender:lm,createConfig(){return{version:3,config:x.cloneDeep(Gr)}}},On={content:""},Wr={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"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function Ks(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(r),o=e.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=Ks(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Us(t,e,n,r){for(let a=t.childCount,o=e.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=t.child(--a),u=e.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=Us(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>e&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,e-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,a){let o="",l=!0;return this.nodesBetween(e,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(e,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)a.push(e.content[o]);return new ae(a,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],a=0;if(n>e)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>e&&((l<e||c>n)&&(u.isText?u=u.cut(Math.max(0,e-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,e-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(e,n){return e==n?ae.empty:e==0&&n==this.content.length?this:new ae(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[e]=n,new ae(a,o)}addToStart(e){return new ae([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new ae(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];e(a,r,n),r+=a.nodeSize}}findDiffStart(e,n=0){return Ks(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Us(this,e,n,r)}findIndex(e,n=-1){if(e==0)return Pn(0,e);if(e==this.size)return Pn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=e)return l==e||n>0?Pn(r+1,l):Pn(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return ae.empty;let n,r=0;for(let a=0;a<e.length;a++){let o=e[a];r+=o.nodeSize,a&&o.isText&&e[a-1].sameMarkup(o)?(n||(n=e.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||e,r)}static from(e){if(!e)return ae.empty;if(e instanceof ae)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new ae([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const jr={index:0,offset:0};function Pn(t,e){return jr.index=t,jr.offset=e,jr}function Rr(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Rr(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Rr(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class We{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let a=0;a<e.length;a++){let o=e[a];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,a));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Rr(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return We.none;if(e instanceof We)return[e];let n=e.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}We.none=[];class hm extends Error{}class ce{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Js(this.content,e+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(e,n){return new ce(Xs(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ae.fromJSON(e,n.content),r,a)}static maxOpen(e,n=!0){let r=0,a=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(e,r,a)}}ce.empty=new ce(ae.empty,0,0);function Xs(t,e,n){let{index:r,offset:a}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:u}=t.findIndex(n);if(a==e||o.isText){if(u!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(Xs(o.content,e-a-1,n-a-1)))}function Js(t,e,n,r){let{index:a,offset:o}=t.findIndex(e),l=t.maybeChild(a);if(o==e||l.isText)return r&&!r.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let u=Js(l.content,e-o-1,n);return u&&t.replaceChild(a,l.copy(u))}class Bn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=e.nodes[r.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let r=new to(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new to(this,n,!0);return r.addAll(e,n.from,n.to),ce.maxOpen(r.finish())}matchTag(e,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(mm(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(e)!=0||l.context&&!r.matchesContext(l.context)||u.length>e.length&&(u.charCodeAt(e.length)!=61||u.slice(e.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(e){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in e.marks){let o=e.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=no(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in e.nodes){let o=e.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=no(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Bn(e,Bn.schemaRules(e)))}}const Zs={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},fm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Hs={ol:!0,ul:!0},Vn=1,Nn=2,Zt=4;function eo(t,e,n){return e!=null?(e?Vn:0)|(e==="full"?Nn:0):t&&t.whitespace=="pre"?Vn|Nn:n&~Zt}class qn{constructor(e,n,r,a,o,l,u){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=We.none,this.stashMarks=[],this.match=l||(u&Zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(e.type))?(this.match=r,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Vn)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ae.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):bm(a.type,e))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Zs.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class to{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=eo(null,n.preserveWhitespace,0)|(r?Zt:0);a?o=new qn(a.type,a.attrs,We.none,We.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new qn(null,null,We.none,We.none,!0,null,l):o=new qn(e.schema.topNodeType,null,We.none,We.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(ym(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(e);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(e){let n=e.nodeValue,r=this.top;if(r.options&Nn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&Vn)r.options&Nn?n=n.replace(/\r\n?/g,`
308
308
  `):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=e.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(e)}else this.findInside(e)}addElement(e,n){let r=e.nodeName.toLowerCase(),a;Hs.hasOwnProperty(r)&&this.parser.normalizeLists&&gm(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,n));if(o?o.ignore:fm.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,u=this.top,c=this.needsBlock;if(Zs.hasOwnProperty(r))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),l=!0,u.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e);return}this.addAll(e),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(e,o,o.consuming===!1?a:void 0)}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
309
309
  `))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=We.none,r=We.none;for(let a=0;a<e.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(e[a],e[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(e,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=e;typeof n.contentElement=="string"?c=e.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(e):n.contentElement&&(c=n.contentElement),this.findAround(e,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(e,n,r){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o);this.findAtPoint(e,a)}findPlace(e){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let r=n.activeMarks;for(let a=0;a<e.marks.length;a++)(!n.type||n.type.allowsMarkType(e.marks[a].type))&&(r=e.marks[a].addToSet(r));return n.content.push(e.mark(r)),!0}return!1}enter(e,n,r){let a=this.findPlace(e.create(n));return a&&this.enterInner(e,n,!0,r),a}enterInner(e,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=eo(e,a,o.options);o.options&Zt&&o.content.length==0&&(l|=Zt),this.nodes.push(new qn(e,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)e+=r[a].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&e.nodeType==1&&e.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=vm(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(e)>-1)a.pendingMarks=e.removeFromSet(a.pendingMarks);else{a.activeMarks=e.removeFromSet(a.activeMarks);let l=a.popFromStashMark(e);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function gm(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Hs.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function mm(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ym(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function no(t){let e={};for(let n in t)e[n]=t[n];return e}function bm(t,e){let n=e.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(t))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==e||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function vm(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const ro=65535,io=Math.pow(2,16);function xm(t,e){return t+e*io}function ao(t){return t&ro}function wm(t){return(t-(t&ro))/io}const so=1,oo=2,Fn=4,lo=8;class uo{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&lo)>0}get deletedBefore(){return(this.delInfo&(so|Fn))>0}get deletedAfter(){return(this.delInfo&(oo|Fn))>0}get deletedAcross(){return(this.delInfo&Fn)>0}}class Ye{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Ye.empty)return Ye.empty}recover(e){let n=0,r=ao(e);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+wm(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>e)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(e<=h){let g=d?e==c?-1:e==h?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let w=e==(n<0?c:h)?null:xm(u/3,e-c),C=e==c?oo:e==h?so:Fn;return(n<0?e!=c:e!=h)&&(C|=lo),new uo(m,C,w)}a+=f-d}return r?e+a:new uo(e+a,0,null)}touches(e,n){let r=0,a=ao(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>e)break;let d=this.ranges[u+o],f=c+d;if(e<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];e(u,u+d,c,c+f),o+=f-d}}invert(){return new Ye(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ye.empty:new Ye(e<0?[0,-e,0]:[0,0,e])}}Ye.empty=new Ye([]);const Yr=Object.create(null);class Ge{getMap(){return Ye.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Yr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Yr)throw new RangeError("Duplicate use of step JSON ID "+e);return Yr[e]=n,n.prototype.jsonID=e,n}}class _e{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new _e(e,null)}static fail(e){return new _e(null,e)}static fromReplace(e,n,r,a){try{return _e.ok(e.replace(n,r,a))}catch(o){if(o instanceof hm)return _e.fail(o.message);throw o}}}function Qr(t,e,n){let r=[];for(let a=0;a<t.childCount;a++){let o=t.child(a);o.content.size&&(o=o.copy(Qr(o.content,e,o))),o.isInline&&(o=e(o,n,a)),r.push(o)}return ae.fromArray(r)}class Tt extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Qr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,o)}invert(){return new Dt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Tt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Tt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Tt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Tt(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("addMark",Tt);class Dt extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new ce(Qr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),e),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,r)}invert(){return new Tt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Dt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Dt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Dt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Dt(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("removeMark",Dt);class Mt extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Mt(this.pos,n.marks[a]);return new Mt(this.pos,this.mark)}}return new Ht(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Mt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Mt(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("addNodeMark",Mt);class Ht extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Mt(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ht(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ht(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("removeNodeMark",Ht);class rt extends Ge{constructor(e,n,r,a=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=a}apply(e){return this.structure&&Kr(e,this.from,this.to)?_e.fail("Structure replace would overwrite content"):_e.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ye([this.from,this.to-this.from,this.slice.size])}invert(e){return new rt(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new rt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(e){if(!(e instanceof rt)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?ce.empty:new ce(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new rt(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?ce.empty:new ce(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new rt(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new rt(n.from,n.to,ce.fromJSON(e,n.slice),!!n.structure)}}Ge.jsonID("replace",rt);class It extends Ge{constructor(e,n,r,a,o,l,u=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(e){if(this.structure&&(Kr(e,this.from,this.gapFrom)||Kr(e,this.gapTo,this.to)))return _e.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return _e.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?_e.fromReplace(e,this.from,this.to,r):_e.fail("Content does not fit in gap")}getMap(){return new Ye([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new It(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),a=e.map(this.gapFrom,-1),o=e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new It(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new It(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ge.jsonID("replaceAround",It);function Kr(t,e,n){let r=t.resolve(e),a=n-e,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function Cm(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Sm(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let a=t.$from.node(r),o=t.$from.index(r),l=t.$to.indexAfter(r);if(r<t.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!Cm(a,o,l))break}return null}function Gn(t,e,n=1,r){let a=t.resolve(e),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),w=r&&r[f+1];w&&(m=m.replaceChild(0,w.type.create(w.attrs)));let C=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!C.type.validContent(m))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function co(t,e){let n=t.resolve(e),r=n.index();return _m(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function _m(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class en extends Ge{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return _e.fromReplace(e,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Ye.empty}invert(e){return new en(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new en(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new en(n.pos,n.attr,n.value)}}Ge.jsonID("attr",en);let tn=class extends Error{};tn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},tn.prototype=Object.create(Error.prototype),tn.prototype.constructor=tn,tn.prototype.name="TransformError";const Ur=Object.create(null);class fe{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new km(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=e.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=e.mapping.slice(o);e.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&fo(e,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=e.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?e.deleteRange(d,f):(e.replaceRangeWith(d,f,n),fo(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let a=e.parent.inlineContent?new ke(e):Vt(e.node(0),e.parent,e.pos,e.index(),n,r);if(a)return a;for(let o=e.depth-1;o>=0;o--){let l=n<0?Vt(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Vt(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ct(e.node(0))}static atStart(e){return Vt(e,e,0,0,1)||new ct(e)}static atEnd(e){return Vt(e,e,e.content.size,e.childCount,-1)||new ct(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Ur[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Ur)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ur[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ke.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class km{constructor(e,n){this.$from=e,this.$to=n}}let po=!1;function ho(t){!po&&!t.parent.inlineContent&&(po=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ke extends fe{constructor(e,n=e){ho(e),ho(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=e.resolve(n.map(this.anchor));return new ke(a.parent.inlineContent?a:r,r)}replace(e,n=ce.empty){if(super.replace(e,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof ke&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Wn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ke(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let a=e.resolve(n);return new this(a,r==n?a:e.resolve(r))}static between(e,n,r){let a=e.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=fe.findFrom(n,r,!0)||fe.findFrom(n,-r,!0);if(o)n=o.$head;else return fe.near(n,r)}return e.parent.inlineContent||(a==0?e=n:(e=(fe.findFrom(e,-r,!0)||fe.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=a<0&&(e=n))),new ke(e,n)}}fe.jsonID("text",ke);class Wn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Wn(e.map(this.anchor),e.map(this.head))}resolve(e){return ke.between(e.resolve(this.anchor),e.resolve(this.head))}}class je extends fe{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=e.resolve(a);return r?fe.near(o):new je(o)}content(){return new ce(ae.from(this.node),0,0)}eq(e){return e instanceof je&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Xr(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new je(e.resolve(n.anchor))}static create(e,n){return new je(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}je.prototype.visible=!1,fe.jsonID("node",je);class Xr{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new Wn(r,r):new Xr(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&je.isSelectable(r)?new je(n):fe.near(n)}}class ct extends fe{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=ce.empty){if(n==ce.empty){e.delete(0,e.doc.content.size);let r=fe.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new ct(e)}map(e){return new ct(e)}eq(e){return e instanceof ct}getBookmark(){return Tm}}fe.jsonID("all",ct);const Tm={map(){return this},resolve(t){return new ct(t)}};function Vt(t,e,n,r,a,o=!1){if(e.inlineContent)return ke.create(t,n);for(let l=r-(a>0?0:1);a>0?l<e.childCount:l>=0;l+=a){let u=e.child(l);if(u.isAtom){if(!o&&je.isSelectable(u))return je.create(t,n-(a<0?u.nodeSize:0))}else{let c=Vt(t,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function fo(t,e,n){let r=t.steps.length-1;if(r<e)return;let a=t.steps[r];if(!(a instanceof rt||a instanceof It))return;let o=t.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),t.setSelection(fe.near(t.doc.resolve(l),n))}function go(t,e){return!e||!t?t:t.bind(e)}class jn{constructor(e,n,r){this.name=e,this.init=go(n.init,r),this.apply=go(n.apply,r)}}new jn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new jn("selection",{init(t,e){return t.selection||fe.atStart(e.doc)},apply(t){return t.selection}}),new jn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new jn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function mo(t,e,n){for(let r in t){let a=t[r];a instanceof Function?a=a.bind(e):r=="handleDOMEvents"&&(a=mo(a,e,{})),n[r]=a}return n}class nn{constructor(e){this.spec=e,this.props={},e.props&&mo(e.props,this,this.props),this.key=e.key?e.key.key:yo("plugin")}getState(e){return e[this.key]}}const Jr=Object.create(null);function yo(t){return t in Jr?t+"$"+ ++Jr[t]:(Jr[t]=0,t+"$")}class rn{constructor(e="key"){this.key=yo(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function bo(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class Dm{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!e,d=e||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...C)=>{const _=this.buildProps(d,n),T=m(...C)(_);return u.push(T),h}])),run:f};return h}createCan(e){const{rawCommands:n,state:r}=this,a=!1,o=e||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&e.setStoredMarks(o.storedMarks);const u={tr:e,editor:a,view:l,state:bo({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function vt(t,e,n){return t.config[e]===void 0&&t.parent?vt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?vt(t.parent,e,n):null}):t.config[e]}function Mm(t){const e=t.filter(a=>a.type==="extension"),n=t.filter(a=>a.type==="node"),r=t.filter(a=>a.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function Le(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function Im(t){return typeof t=="function"}function Nt(t,e=void 0,...n){return Im(t)?e?t.bind(e)(...n):t(...n):t}function Em(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function Am(t){return Object.prototype.toString.call(t).slice(8,-1)}function Zr(t){return Am(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function vo(t,e){const n={...t};return Zr(t)&&Zr(e)&&Object.keys(e).forEach(r=>{Zr(e[r])?r in t?n[r]=vo(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class it{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Nt(vt(this,"addOptions",{name:this.name}))),this.storage=Nt(vt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new it(e)}configure(e={}){const n=this.extend();return n.options=vo(this.options,e),n.storage=Nt(vt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new it(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Nt(vt(n,"addOptions",{name:n.name})),n.storage=Nt(vt(n,"addStorage",{name:n.name,options:n.options})),n}}function zm(t,e,n){const{from:r,to:a}=e,{blockSeparator:o=`
310
310
 
@@ -314,7 +314,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
314
314
  ${Object.entries(e).map(([r,a])=>`const ${r} = '${a}';`).join(`
315
315
  `)}
316
316
  return ${t};
317
- `)(n)}catch(r){return console.error(r),console.log(t),t}}function Gy(t,e,n,r){const a=Ny(e,r),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const f=u[2]??"";return`${c}${f}`}const d=qy(u[1]);return`${Fy(d,a,n)}${u[2]}`}).join("")}const Wy=k.observer(({context:t})=>{const e=K(),{value:n}=W(t.instanceData,"config"),{variables:r,data:a}=t,o=y.useMemo(()=>{const l=x.defaults({},n,On);return l.content?Gy(l.content,r,e.payloadForViz,a):""},[n,r,e.payloadForViz]);return o?i(Kn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function jy(){const{editor:t}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(L.IconBorderAll,{stroke:1.5,size:16})})}const ai=y.forwardRef(({value:t,onChange:e,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=y.useState(t),c=Va.useEditor({extensions:[Na,Ba,J.Link,Ea,Ia,Da,$a.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Pa,Oa,La,Aa.configure({types:["heading","paragraph"]}),Ma.configure({placeholder:"This is placeholder"}),za,Ta.Color,Mo],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});y.useEffect(()=>{u(t),c==null||c.commands.setContent(t)},[t]);const d=()=>{e(l),a==null||a()},f=t!==l,h=y.useMemo(()=>x.defaultsDeep({},{content:Wr},n),[n]);return c?p(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[p(s.Group,{align:"center",children:[i(s.Text,{size:14,fw:500,children:r}),i(s.ActionIcon,{color:"blue",disabled:!f,onClick:d,children:i(L.IconDeviceFloppy,{size:18})})]}),p(J.RichTextEditor,{editor:c,styles:h,children:[p(J.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[i(J.RichTextEditor.ControlsGroup,{children:i(J.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Bold,{}),i(J.RichTextEditor.Italic,{}),i(J.RichTextEditor.Underline,{}),i(J.RichTextEditor.Strikethrough,{}),i(J.RichTextEditor.ClearFormatting,{}),i(J.RichTextEditor.Highlight,{}),i(J.RichTextEditor.Code,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.H1,{}),i(J.RichTextEditor.H2,{}),i(J.RichTextEditor.H3,{}),i(J.RichTextEditor.H4,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Blockquote,{}),i(J.RichTextEditor.Hr,{}),i(J.RichTextEditor.BulletList,{}),i(J.RichTextEditor.OrderedList,{}),i(J.RichTextEditor.Subscript,{}),i(J.RichTextEditor.Superscript,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Link,{}),i(J.RichTextEditor.Unlink,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.AlignLeft,{}),i(J.RichTextEditor.AlignCenter,{}),i(J.RichTextEditor.AlignJustify,{}),i(J.RichTextEditor.AlignRight,{})]}),i(J.RichTextEditor.ControlsGroup,{children:i(jy,{})}),i(Vy,{editor:c})]}),i(J.RichTextEditor.Content,{})]})]}):null});function Ry({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,On),[e]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),y.useEffect(()=>{u(r)},[r]);const c=y.useRef(null),d=()=>{var f;return(f=c.current)==null?void 0:f.click()};return i("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:p(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[i(s.Text,{children:"Content"}),i(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(ai,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Yy extends be{constructor(){super(...arguments);N(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,On)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Qy={displayName:"Rich Text",displayGroup:"Others",migrator:new Yy,name:"richText",viewRender:Wy,configRender:Ry,createConfig(){return{version:1,config:x.cloneDeep(On)}}},an={static:{type:"static",color:st.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
317
+ `)(n)}catch(r){return console.error(r),console.log(t),t}}function Gy(t,e,n,r){const a=Ny(e,r),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const f=u[2]??"";return`${c}${f}`}const d=qy(u[1]);return`${Fy(d,a,n)}${u[2]}`}).join("")}const Wy=k.observer(({context:t})=>{const e=K(),{value:n}=W(t.instanceData,"config"),{variables:r,data:a}=t,o=y.useMemo(()=>{const l=x.defaults({},n,On);return l.content?Gy(l.content,r,e.payloadForViz,a):""},[n,r,e.payloadForViz]);return o?i(Kn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function jy(){const{editor:t}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(L.IconBorderAll,{stroke:1.5,size:16})})}const ai=y.forwardRef(({value:t,onChange:e,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=y.useState(t),c=Va.useEditor({extensions:[Na,Ba,J.Link,Ea,Ia,Da,$a.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Pa,Oa,La,Aa.configure({types:["heading","paragraph"]}),Ma.configure({placeholder:"This is placeholder"}),za,Ta.Color,Mo],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});y.useEffect(()=>{u(t),c==null||c.commands.setContent(t)},[t]);const d=()=>{e(l),a==null||a()},f=t!==l,h=y.useMemo(()=>x.defaultsDeep({},{content:Wr},n),[n]);return c?p(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[p(s.Group,{align:"center",children:[i(s.Text,{size:14,fw:500,children:r}),i(s.ActionIcon,{color:"blue",disabled:!f,onClick:d,children:i(L.IconDeviceFloppy,{size:18})})]}),p(J.RichTextEditor,{editor:c,styles:h,children:[p(J.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[i(J.RichTextEditor.ControlsGroup,{children:i(J.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Bold,{}),i(J.RichTextEditor.Italic,{}),i(J.RichTextEditor.Underline,{}),i(J.RichTextEditor.Strikethrough,{}),i(J.RichTextEditor.ClearFormatting,{}),i(J.RichTextEditor.Highlight,{}),i(J.RichTextEditor.Code,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.H1,{}),i(J.RichTextEditor.H2,{}),i(J.RichTextEditor.H3,{}),i(J.RichTextEditor.H4,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Blockquote,{}),i(J.RichTextEditor.Hr,{}),i(J.RichTextEditor.BulletList,{}),i(J.RichTextEditor.OrderedList,{}),i(J.RichTextEditor.Subscript,{}),i(J.RichTextEditor.Superscript,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Link,{}),i(J.RichTextEditor.Unlink,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.AlignLeft,{}),i(J.RichTextEditor.AlignCenter,{}),i(J.RichTextEditor.AlignJustify,{}),i(J.RichTextEditor.AlignRight,{})]}),i(J.RichTextEditor.ControlsGroup,{children:i(jy,{})}),i(Vy,{editor:c})]}),i(J.RichTextEditor.Content,{})]})]}):null});function Ry({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,On),[e]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),y.useEffect(()=>{u(r)},[r]);const c=y.useRef(null),d=()=>{var f;return(f=c.current)==null?void 0:f.click()};return i("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:p(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[i(s.Text,{children:"Content"}),i(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(ai,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Yy extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,On)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Qy={displayName:"Rich Text",displayGroup:"Others",migrator:new Yy,name:"richText",viewRender:Wy,configRender:Ry,createConfig(){return{version:1,config:x.cloneDeep(On)}}},an={static:{type:"static",color:st.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
318
318
  `)}},Io={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Uy,configRender:Ky,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 Ky(t){return i(V,{})}function Uy(t){return i(s.Text,{children:"Click scatter"})}const Eo={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
319
319
  `)},Ao={label:Ze.on_axis,tooltip:Ze.in_tooltip},si={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:an.static,label_position:"right",label_overflow:Ao},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Eo}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:$e,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Bt};function Xy(t,e){if(!t.x_axis.data_key)return[];const n=q(t.x_axis.data_key);return[{source:e[n.queryID]}]}function Jy(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis.name&&(r+=15),{top:n,bottom:r}}function Zy(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Un(t,e){if(t)return e[t]??void 0}function Hy({reference_areas:t,variableValueMap:e}){const n=t.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Un(r.leftBottomPoint.x_data_key,e),yAxis:Un(r.leftBottomPoint.y_data_key,e)},{xAxis:Un(r.rightTopPoint.x_data_key,e),yAxis:Un(r.rightTopPoint.y_data_key,e)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function eb({type:t,...e},n){if(!t)return 10;if(t==="static"){const{size:a}=e;return a}const{func_content:r}=e;return(a,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:_t.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function tb({type:t,...e},n){if(!t)return an.static.color;if(t==="static"){const{color:a}=e;return a}const{func_content:r}=e;return({value:a})=>{try{return new Function(`return ${r}`)()({rowData:a,variables:n},{lodash:x,interpolate:_t.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function nb(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function rb({x_axis:t,scatter:e},n){const r=q(t.data_key),a=q(e.y_data_key),o=q(e.name_data_key);return{label:{show:!!e.label_position,position:e.label_position,...ut(e.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:tb(e.color,n)},symbolSize:eb(e.symbolSize,n),encode:{x:r.columnKey,y:a.columnKey}}}function ib(t,e,n,r){return[rb(t,r)].concat(nb(t.reference_lines,n,r,e)).concat(Hy({reference_areas:t.reference_areas,variableValueMap:r}))}function zo({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function $o(t,e,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?zo(r.axisLabel.formatter)(t,e):t}function ab(t,e){const{x_axis:n,tooltip:r}=e;if(r.trigger==="item"){const u=wn(t[0].data,n.data_key);return $o(u,0,e)}const a=t.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!a)return"";const{axisValue:o,axisIndex:l}=a;return $o(o,l,e)}const sb=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function ob(t,e){const{scatter:n,tooltip:r}=t;return{confine:!0,trigger:r.trigger,formatter:function(a){const o=e[0]??e.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=ab(l,t),c=mt(t.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
320
320
  <th style="text-align: right; padding-right: 1em">
@@ -338,7 +338,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
338
338
  <tbody>${f.join("")}</tbody>
339
339
  </table>
340
340
  `}}}function lb(t,e){const n=e.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=t.x_axis;return[{data:e,name:t.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:zo(r.formatter)}}]}function ub(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:e[l]??e.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const cb={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 db(t,e,n){const r=n.reduce((c,d)=>{const f=yt(d,e);return c[d.name]=et(d,f),c},{}),a=t.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let m=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?m=g.value[1]:m=g.value),!d)return m;try{return ee(m).format(d)}catch(w){return console.error(w),m}},c),{default:({value:c})=>c}),o=x.uniq(lt(e,t.x_axis.data_key)),l=ib(t,e,n,r),u={xAxis:lb(t,o),yAxis:ub(t,a),series:l,dataset:Xy(t,e),tooltip:ob(t,a),grid:Jy(t),legend:Zy(),dataZoom:zr(t.dataZoom)};return x.defaultsDeep({},u,cb)}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Lo(t){return t.trim().length>0}function pb({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.x_axis.data_key),u=He(a.triggerManager,Io.id),c=y.useCallback(h=>{const g=h.data;u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>db(t,e,o),[t,e]);return i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function hb({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,si),[r]),l=t.data,{width:u,height:c}=t.viewport,{ref:d,height:f}=Me.useElementSize(),{ref:h,height:g}=Me.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Jt(C.top,a,l),bottom:Jt(C.bottom,a,l)}},[o,l]),w=Math.max(0,c-f-g);return!u||!c?null:p(s.Box,{children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Lo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),i(pb,{variables:a,width:u,height:w,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Lo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const fb=y.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),e(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:t.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(Br,{label:"Text Position",value:t.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:t.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:t.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i(Pe,{value:t.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i(Pe,{value:t.label.color,onChange:u=>l("label.color",u)})]})]})});function gb(){const t=new Date().getTime().toString();return{id:t,content:{text:t},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 mb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g=gb();a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:t,render:({field:w})=>p(s.Stack,{children:[i(fb,{variableOptions:d,yAxisOptions:h,...w}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const yb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],bb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function vb({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:bb,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:yb,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function xb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:st.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(vb,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},m))]})}const wb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Cb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(an.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(wb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Sb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Cb,{value:t,onChange:e}),_b=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},kb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Tb=y.forwardRef(({label:t="Color",value:e,onChange:n},r)=>{const a=o=>{n({...an[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:kb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(_b,{value:e,onChange:n}),i(Sb,{value:e,onChange:n})]})}),Db=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,label:o})},a=o=>{e({...t,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:a})]})}),Mb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Oo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
341
- `)}},Ib=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Oo.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Mb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Eb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Ib,{value:t,onChange:e}),Ab=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},zb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],$b=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Oo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:zb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Ab,{value:e,onChange:n}),i(Eb,{value:e,onChange:n})]})}),Lb=[{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 Ob({control:t,watch:e}){return e(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:t,render:({field:n})=>i(j,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:t,render:({field:n})=>i(j,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:t,render:({field:n})=>i($b,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:t,render:({field:n})=>i(Tb,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:t,render:({field:n})=>i(s.Select,{label:"Label Position",data:Lb,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>i(Db,{...n})})]})}function Pb({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Bb=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Vb=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Bb,{control:t,index:g,remove:a},h.id)},h.id))]})]})},Nb=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function qb({control:t,watch:e}){return e("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>i(s.Select,{label:"Trigger",data:Nb,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Vb,{control:t,watch:e})]})}const Fb=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Gb=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(Eo.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Fb,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Wb({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gb,{...n})})]})]})}const jb=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Rb=[{label:"left",value:"left"},{label:"right",value:"right"}];function Yb({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:jb,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Rb,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Qb({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:$e,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Yb,{control:t,index:d,remove:a})},d))]})}function Kb(t){return t||{templates:{top:"",bottom:""}}}function Ub({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Kb(e),...n}}function Xb({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,si),[e]),o=y.useMemo(()=>Ub(a),[a]);y.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});y.useEffect(()=>{f(o)},[o]);const h=d(),g=y.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Wb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Qb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Ob,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(qb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Pb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(xb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(mb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(Lr,{...m})})})]})]})})}function Jb(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Zb(t){const e={scatter:{label_overflow:Ao}};return x.defaultsDeep(e,t)}function Hb(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...an.static,color:e}}}:t}function ev(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...t,reference_lines:e}}function tv(t){const e={tooltip:{trigger:"item"}};return x.defaultsDeep({},t,e)}function nv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class rv extends be{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:Jb(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Zb(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Hb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:ev(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:tv(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:nv(a,r)}})}}const iv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new rv,name:"scatterChart",viewRender:hb,configRender:Xb,createConfig(){return{version:9,config:x.cloneDeep(si)}},triggers:[Io]},oi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function av(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=t;return{align:e,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function sv(t){return x.omit(t,["variables"])}function ov(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function lv(t){const e=x.cloneDeep(t),n=x.get(e,"color.valueRange");return n!==void 0&&x.set(e,"color.valueRange",n.map(r=>Number(r))),e}class uv extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:av(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(lv(l))}),{...n,version:2,config:sv(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:ov(r)}})}}const cv={left:"flex-start",center:"center",right:"flex-end"},dv={top:"flex-start",center:"center",bottom:"flex-end"},pv=k.observer(({context:t})=>{const e=K(),{value:n=oi}=W(t.instanceData,"config"),{variables:r}=t,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=t.viewport,d=y.useMemo(()=>{try{return x.template(a)(e.payloadForSQL)}catch{return a}},[e.payloadForSQL,a]),f=y.useMemo(()=>Jt(d,r,t.data),[d,r,t.data,t]);return i(s.Center,{sx:{width:u,height:c,justifyContent:cv[o],alignItems:dv[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(y.Fragment,{children:h},g))})})}),hv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fv=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function gv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,oi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(Xt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:hv,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:fv,...h})})]})]})})}const mv={createConfig(){return{version:3,config:oi}},displayName:"Stats",displayGroup:"Others",migrator:new uv,name:"stats",viewRender:pv,configRender:gv},li={label_key:"",value_key:"",group_key:"",levels:[]};function yv(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function bv(t){const e=yv(t).map(a=>({...a,children:[]})),n=x.keyBy(e,a=>a.id),r=[];return e.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function vv(t,e){const{label_key:n,value_key:r,group_key:a}=t;if(!n||!r)return[];const o=q(n),l=q(r),u=q(a),c=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?bv(c):c}const xv=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const a=e[e.length-2].value;if(r/a<t)return" "}catch{return n}};function wv(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:xv(r)}}})}function Cv(){return({treePathInfo:t,name:e,value:n,color:r,marker:a,...o})=>{const l=t.slice(0,t.length-1),u=[`<tr>
341
+ `)}},Ib=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Oo.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Mb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Eb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Ib,{value:t,onChange:e}),Ab=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},zb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],$b=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Oo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:zb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Ab,{value:e,onChange:n}),i(Eb,{value:e,onChange:n})]})}),Lb=[{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 Ob({control:t,watch:e}){return e(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:t,render:({field:n})=>i(j,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:t,render:({field:n})=>i(j,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:t,render:({field:n})=>i($b,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:t,render:({field:n})=>i(Tb,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:t,render:({field:n})=>i(s.Select,{label:"Label Position",data:Lb,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>i(Db,{...n})})]})}function Pb({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Bb=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Vb=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Bb,{control:t,index:g,remove:a},h.id)},h.id))]})]})},Nb=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function qb({control:t,watch:e}){return e("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>i(s.Select,{label:"Trigger",data:Nb,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Vb,{control:t,watch:e})]})}const Fb=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Gb=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(Eo.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Fb,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Wb({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gb,{...n})})]})]})}const jb=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Rb=[{label:"left",value:"left"},{label:"right",value:"right"}];function Yb({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:jb,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Rb,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Qb({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:$e,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Yb,{control:t,index:d,remove:a})},d))]})}function Kb(t){return t||{templates:{top:"",bottom:""}}}function Ub({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Kb(e),...n}}function Xb({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,si),[e]),o=y.useMemo(()=>Ub(a),[a]);y.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});y.useEffect(()=>{f(o)},[o]);const h=d(),g=y.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Wb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Qb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Ob,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(qb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Pb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(xb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(mb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(Lr,{...m})})})]})]})})}function Jb(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Zb(t){const e={scatter:{label_overflow:Ao}};return x.defaultsDeep(e,t)}function Hb(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...an.static,color:e}}}:t}function ev(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...t,reference_lines:e}}function tv(t){const e={tooltip:{trigger:"item"}};return x.defaultsDeep({},t,e)}function nv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class rv extends ve{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:Jb(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Zb(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Hb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:ev(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:tv(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:nv(a,r)}})}}const iv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new rv,name:"scatterChart",viewRender:hb,configRender:Xb,createConfig(){return{version:9,config:x.cloneDeep(si)}},triggers:[Io]},oi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function av(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=t;return{align:e,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function sv(t){return x.omit(t,["variables"])}function ov(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function lv(t){const e=x.cloneDeep(t),n=x.get(e,"color.valueRange");return n!==void 0&&x.set(e,"color.valueRange",n.map(r=>Number(r))),e}class uv extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:av(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(lv(l))}),{...n,version:2,config:sv(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:ov(r)}})}}const cv={left:"flex-start",center:"center",right:"flex-end"},dv={top:"flex-start",center:"center",bottom:"flex-end"},pv=k.observer(({context:t})=>{const e=K(),{value:n=oi}=W(t.instanceData,"config"),{variables:r}=t,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=t.viewport,d=y.useMemo(()=>{try{return x.template(a)(e.payloadForSQL)}catch{return a}},[e.payloadForSQL,a]),f=y.useMemo(()=>Jt(d,r,t.data),[d,r,t.data,t]);return i(s.Center,{sx:{width:u,height:c,justifyContent:cv[o],alignItems:dv[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(y.Fragment,{children:h},g))})})}),hv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fv=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function gv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,oi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(Xt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:hv,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:fv,...h})})]})]})})}const mv={createConfig(){return{version:3,config:oi}},displayName:"Stats",displayGroup:"Others",migrator:new uv,name:"stats",viewRender:pv,configRender:gv},li={label_key:"",value_key:"",group_key:"",levels:[]};function yv(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function bv(t){const e=yv(t).map(a=>({...a,children:[]})),n=x.keyBy(e,a=>a.id),r=[];return e.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function vv(t,e){const{label_key:n,value_key:r,group_key:a}=t;if(!n||!r)return[];const o=q(n),l=q(r),u=q(a),c=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?bv(c):c}const xv=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const a=e[e.length-2].value;if(r/a<t)return" "}catch{return n}};function wv(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:xv(r)}}})}function Cv(){return({treePathInfo:t,name:e,value:n,color:r,marker:a,...o})=>{const l=t.slice(0,t.length-1),u=[`<tr>
342
342
  <th style="text-align: right; padding: 0 1em;">Value</th>
343
343
  <td style="text-align: left; padding: 0 1em;">${n}</td>
344
344
  </tr>
@@ -356,8 +356,8 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
356
356
  <table style="width: auto">
357
357
  <tbody>${u.join("")}</tbody>
358
358
  </table>
359
- `}}function Sv(){return{show:!0,trigger:"item",confine:!0,formatter:Cv()}}const _v={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function kv(t,e,n){n.reduce((o,l)=>{const u=yt(l,e);return o[l.name]=et(l,u),o},{});const a={series:{data:vv(t,e),levels:wv(t)},tooltip:Sv()};return x.defaultsDeep({},a,_v)}le.use([pe.SunburstChart,Ve.CanvasRenderer]);function Tv({context:t}){const{variables:e}=t,{value:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},n,li),[n]),a=t.data,{width:o,height:l}=t.viewport,u=y.useMemo(()=>kv(r,a,e),[r,a,e]);return!o||!l?null:i(Ne,{echarts:le,option:u,style:{width:o,height:l},notMerge:!0,theme:"merico-light"})}function Dv({control:t,watch:e}){return e(["label_key","value_key","group_key"]),p(s.Stack,{children:[i(v.Controller,{name:"label_key",control:t,render:({field:n})=>i(j,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:t,render:({field:n})=>i(j,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:t,render:({field:n})=>i(j,{label:"Group Key",clearable:!0,...n})})]})}const Mv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Iv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ev=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.r0`,control:t,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${e}.r`,control:t,render:({field:r})=>i(s.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),i(v.Controller,{name:`levels.${e}.label.show_label_tolerance`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.rotate`,control:t,render:({field:r})=>i(s.Select,{label:"Rotate",data:Mv,...r})}),i(v.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:r})=>i(s.Select,{label:"Align",data:Iv,...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:r})=>i(Br,{label:"Position",...r})}),i(v.Controller,{name:`levels.${e}.label.padding`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Level"})]}),Av=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"levels"}),o=e("levels"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=e("levels.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Ev,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function zv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);u(["label_key","value_key","group_key","levels"]);const[g,m]=y.useState("Data");return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Sunburst Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{value:g,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Levels",children:"Levels"})]}),i(s.Tabs.Panel,{value:"Data",children:i(Dv,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(Av,{control:o,watch:u})})]})]})})}function $v(t){const{label_field:e,value_field:n,...r}=t;return{...r,label_key:e,value_key:n}}function Lv(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function Ov(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Pv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=t;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Bv extends be{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:$v(n.config)})),this.version(3,n=>({...n,version:3,config:Lv(n.config)})),this.version(4,n=>({...n,version:4,config:Ov(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Pv(n.config,r)}))}}const Vv={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Bv,name:"sunburst",viewRender:Tv,configRender:zv,createConfig(){return{version:5,config:x.cloneDeep(li)}}},Po=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
360
- `),ui={func_content:Po,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Nv=k.observer(({context:t})=>{const e=K(),{value:n=ui}=W(t.instanceData,"config"),{variables:r}=t,a=t.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=y.useMemo(()=>r.reduce((h,g)=>{const m=yt(g,a);return h[g.name]=et(g,m),h},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,a,d,e.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),qv=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative"},children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Fv=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(Po)};return y.useEffect(()=>{u(t)},[t]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(qv,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Gv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Wv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ui),[e]),a=y.useMemo(()=>{const{func_content:g,horizontal_align:m,font_size:w,font_weight:C}=r;return{func_content:g,horizontal_align:m,font_size:w,font_weight:C}},[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Fv,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Gv,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(ks,{label:"Font Weight",...g})})})]})]})})}class jv extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Rv={displayName:"Text",displayGroup:"Others",migrator:new jv,name:"text",viewRender:Nv,configRender:Wv,createConfig(){return{version:1,config:x.cloneDeep(ui)}}},Yv=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Bo(t,e){const n=x.get(t,e,"");if(n)throw new Error(n)}async function Qv(t,e,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,pt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Kv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=t;if(!r||!a||!o)return;const l=dc(e);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Qv(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Bo(c,"response.data.detail"),Bo(c,"response.data.error"),console.error(c),c}},ci={expertSystemURL:"",path:"",goal:"",question:""},di={height:"100%",overflowY:"auto",...Wr},Vo=({message:t})=>i(s.Box,{sx:di,children:i("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Uv=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return i(Vo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(Yv,{}),i(Vo,{message:r})]})})};function Xv({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},e,ci),[e]),{width:r,height:a}=t.viewport,o=t.data,{data:l,error:u,loading:c}=X.useRequest(Kv({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:di,"data-enable-scrollbar":!0,children:i(Uv,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:di,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function Jv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ci),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(D.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Zv extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Hv={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Zv,name:"mericoGQM",viewRender:Xv,configRender:Jv,createConfig(){return{version:1,config:x.cloneDeep(ci)}}};function ex(t,e,n){if(!t)return n[0];try{return[e,R(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function tx(t,e,n){const r=ex(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function nx(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return ee(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function rx(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function ix(t,e,n,r){const{calendar:a,heat_block:o}=t,l=q(a.data_key),u=q(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const ax=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function sx({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(f=>{const h=q(f.data_key);c.push({label:f.name,value:ax(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function ox(t,e,n){const r=q(t.calendar.data_key),a=x.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=sx({conf:t,valueFormatters:n,dataDict:a,params:o}).map(f=>`
359
+ `}}function Sv(){return{show:!0,trigger:"item",confine:!0,formatter:Cv()}}const _v={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function kv(t,e,n){n.reduce((o,l)=>{const u=yt(l,e);return o[l.name]=et(l,u),o},{});const a={series:{data:vv(t,e),levels:wv(t)},tooltip:Sv()};return x.defaultsDeep({},a,_v)}le.use([pe.SunburstChart,Ve.CanvasRenderer]);function Tv({context:t}){const{variables:e}=t,{value:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},n,li),[n]),a=t.data,{width:o,height:l}=t.viewport,u=y.useMemo(()=>kv(r,a,e),[r,a,e]);return!o||!l?null:i(Ne,{echarts:le,option:u,style:{width:o,height:l},notMerge:!0,theme:"merico-light"})}function Dv({control:t,watch:e}){return e(["label_key","value_key","group_key"]),p(s.Stack,{children:[i(v.Controller,{name:"label_key",control:t,render:({field:n})=>i(j,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:t,render:({field:n})=>i(j,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:t,render:({field:n})=>i(j,{label:"Group Key",clearable:!0,...n})})]})}const Mv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Iv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ev=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.r0`,control:t,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${e}.r`,control:t,render:({field:r})=>i(s.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),i(v.Controller,{name:`levels.${e}.label.show_label_tolerance`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.rotate`,control:t,render:({field:r})=>i(s.Select,{label:"Rotate",data:Mv,...r})}),i(v.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:r})=>i(s.Select,{label:"Align",data:Iv,...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:r})=>i(Br,{label:"Position",...r})}),i(v.Controller,{name:`levels.${e}.label.padding`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Level"})]}),Av=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"levels"}),o=e("levels"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=e("levels.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Ev,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function zv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);u(["label_key","value_key","group_key","levels"]);const[g,m]=y.useState("Data");return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Sunburst Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{value:g,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Levels",children:"Levels"})]}),i(s.Tabs.Panel,{value:"Data",children:i(Dv,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(Av,{control:o,watch:u})})]})]})})}function $v(t){const{label_field:e,value_field:n,...r}=t;return{...r,label_key:e,value_key:n}}function Lv(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function Ov(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Pv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=t;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Bv extends ve{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:$v(n.config)})),this.version(3,n=>({...n,version:3,config:Lv(n.config)})),this.version(4,n=>({...n,version:4,config:Ov(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Pv(n.config,r)}))}}const Vv={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Bv,name:"sunburst",viewRender:Tv,configRender:zv,createConfig(){return{version:5,config:x.cloneDeep(li)}}},Po=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
360
+ `),ui={func_content:Po,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Nv=k.observer(({context:t})=>{const e=K(),{value:n=ui}=W(t.instanceData,"config"),{variables:r}=t,a=t.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=y.useMemo(()=>r.reduce((h,g)=>{const m=yt(g,a);return h[g.name]=et(g,m),h},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,a,d,e.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),qv=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative"},children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Fv=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(Po)};return y.useEffect(()=>{u(t)},[t]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(qv,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Gv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Wv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ui),[e]),a=y.useMemo(()=>{const{func_content:g,horizontal_align:m,font_size:w,font_weight:C}=r;return{func_content:g,horizontal_align:m,font_size:w,font_weight:C}},[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Fv,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Gv,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(ks,{label:"Font Weight",...g})})})]})]})})}class jv extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Rv={displayName:"Text",displayGroup:"Others",migrator:new jv,name:"text",viewRender:Nv,configRender:Wv,createConfig(){return{version:1,config:x.cloneDeep(ui)}}},Yv=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Bo(t,e){const n=x.get(t,e,"");if(n)throw new Error(n)}async function Qv(t,e,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,pt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Kv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=t;if(!r||!a||!o)return;const l=dc(e);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Qv(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Bo(c,"response.data.detail"),Bo(c,"response.data.error"),console.error(c),c}},ci={expertSystemURL:"",path:"",goal:"",question:""},di={height:"100%",overflowY:"auto",...Wr},Vo=({message:t})=>i(s.Box,{sx:di,children:i("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Uv=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return i(Vo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(Yv,{}),i(Vo,{message:r})]})})};function Xv({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},e,ci),[e]),{width:r,height:a}=t.viewport,o=t.data,{data:l,error:u,loading:c}=X.useRequest(Kv({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:di,"data-enable-scrollbar":!0,children:i(Uv,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:di,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function Jv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ci),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(D.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Zv extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Hv={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Zv,name:"mericoGQM",viewRender:Xv,configRender:Jv,createConfig(){return{version:1,config:x.cloneDeep(ci)}}};function ex(t,e,n){if(!t)return n[0];try{return[e,R(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function tx(t,e,n){const r=ex(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function nx(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return ee(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function rx(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function ix(t,e,n,r){const{calendar:a,heat_block:o}=t,l=q(a.data_key),u=q(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const ax=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function sx({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(f=>{const h=q(f.data_key);c.push({label:f.name,value:ax(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function ox(t,e,n){const r=q(t.calendar.data_key),a=x.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=sx({conf:t,valueFormatters:n,dataDict:a,params:o}).map(f=>`
361
361
  <tr>
362
362
  <th style="text-align: right;">
363
363
  <div style="${f.style.label}">${f.label}</div>
@@ -383,7 +383,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
383
383
  </thead>
384
384
  <tbody>${u.join("")}</tbody>
385
385
  </table>
386
- `}}}function lx(t,e,n){const r=En(t.heat_block.min,n),a=En(t.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const ux={tooltip:{confine:!0},grid:{containLabel:!0}},cx=t=>R(t).get("year");function dx(t,e){const n=q(t.calendar.data_key),r=e[n.queryID],a=x.groupBy(r,d=>cx(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>R(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:R(c).diff(u,"day"),dataByYear:a,years:o}}function px(t,e,n){const r=n.reduce((h,g)=>{const m=yt(g,e);return h[g.name]=et(g,m),h},{}),a=nx(t),{dateSpan:o,minDate:l,dataByYear:u,years:c}=dx(t,e),d=o<=366,f={calendar:tx(d,l,c),series:ix(t,d,u,e),tooltip:ox(t,e,a),visualMap:lx(t,d,r),legend:rx(d,c)};return x.defaultsDeep({},f,ux)}function hx(t){return i(V,{})}function fx(t){return i(s.Text,{children:"Click heat block"})}const No={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:fx,configRender:hx,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"}]},pi={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e},tooltip:{metrics:[]}};le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function gx({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function mx({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.calendar.data_key),u=He(a.triggerManager,No.id),c=y.useCallback(h=>{const[g,m]=h.value,w=x.get(l,g,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...h,rowData:w})})},[l,u,a]),d=y.useMemo(()=>({click:c,legendselectchanged:gx}),[c]),f=y.useMemo(()=>px(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function yx({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,pi),[r]),l=t.data,{width:u,height:c}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:i(s.Box,{children:i(mx,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function bx({control:t,watch:e}){return e(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:n})=>i(In,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:n})=>i(In,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})}const vx=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),xx=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(vx,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function wx({control:t,watch:e}){return i(xx,{control:t,watch:e})}const Cx=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Sx({control:t,watch:e}){return e(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:t,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:Cx,sx:{flex:1},...n})})]})}function _x({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,pi),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(Sx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(bx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(wx,{control:o,watch:u})})]})]})})}function kx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=t;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Tx(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Dx extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:kx(n.config,r)})),this.version(3,n=>({...n,version:3,config:Tx(n.config)}))}}const Mx={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Dx,name:"calendarHeatmap",viewRender:yx,configRender:_x,createConfig:()=>({version:3,config:pi}),triggers:[No]},hi={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:$e,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...nt},overflow:Ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Ix(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:$e,show:!0}}function Ex(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,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:Pt,xAxisIndex:"0"}}function Ax(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zx(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),t.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function $x(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Lx(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:$x(r)})),e}function Ox(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function Xn(t,e,n){const r=lt(t,e),a=lt(t,n);return x.zip(a,r)}function Px(t,e,n,r){const a=Xn(e,n,r);return x.unionBy(a,t,0)}function Bx({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?Px(t,e,n,r):Xn(e,n,r)}function Vx({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Bx({dataTemplate:t,data:e,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=Xn(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const h=u[d].map(m=>m[1]),g=Dr(h,n);return[d,g]})}function Nx({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Xn({[a]:c},r,n)}),l}function qx({y_axis:t},{data_key:e,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},m,w,C,_,T){const I={label:{show:!!r,position:r,formatter:T[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===t.data_key)return I.data=Vx({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:w}),I;const O=Nx({group_by_key:o,data:C,name_data_key:t.data_key,value_data_key:e});return Object.entries(O).map(([B,$])=>{const A=x.cloneDeep(I);return A.name=B,A.color=void 0,A.data=$,A})}function Fx(t,e,n,r,a,o,l){const u=e.map(d=>[d,0]);return t.series.map(d=>qx(t,d,u,n,r,l,a)).flat().concat(Ox(t.reference_lines,o,l,r))}function Gx(t,e){const n=t.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Ot(e.y_axis.axisLabel.formatter)(o,l)}function Wx(t,e,n){const r=e.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
386
+ `}}}function lx(t,e,n){const r=En(t.heat_block.min,n),a=En(t.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const ux={tooltip:{confine:!0},grid:{containLabel:!0}},cx=t=>R(t).get("year");function dx(t,e){const n=q(t.calendar.data_key),r=e[n.queryID],a=x.groupBy(r,d=>cx(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>R(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:R(c).diff(u,"day"),dataByYear:a,years:o}}function px(t,e,n){const r=n.reduce((h,g)=>{const m=yt(g,e);return h[g.name]=et(g,m),h},{}),a=nx(t),{dateSpan:o,minDate:l,dataByYear:u,years:c}=dx(t,e),d=o<=366,f={calendar:tx(d,l,c),series:ix(t,d,u,e),tooltip:ox(t,e,a),visualMap:lx(t,d,r),legend:rx(d,c)};return x.defaultsDeep({},f,ux)}function hx(t){return i(V,{})}function fx(t){return i(s.Text,{children:"Click heat block"})}const No={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:fx,configRender:hx,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"}]},pi={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e},tooltip:{metrics:[]}};le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function gx({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function mx({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.calendar.data_key),u=He(a.triggerManager,No.id),c=y.useCallback(h=>{const[g,m]=h.value,w=x.get(l,g,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...h,rowData:w})})},[l,u,a]),d=y.useMemo(()=>({click:c,legendselectchanged:gx}),[c]),f=y.useMemo(()=>px(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function yx({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,pi),[r]),l=t.data,{width:u,height:c}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:i(s.Box,{children:i(mx,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function bx({control:t,watch:e}){return e(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:n})=>i(In,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:n})=>i(In,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})}const vx=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),xx=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(vx,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function wx({control:t,watch:e}){return i(xx,{control:t,watch:e})}const Cx=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Sx({control:t,watch:e}){return e(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:t,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:Cx,sx:{flex:1},...n})})]})}function _x({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,pi),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(Sx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(bx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(wx,{control:o,watch:u})})]})]})})}function kx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=t;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Tx(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Dx extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:kx(n.config,r)})),this.version(3,n=>({...n,version:3,config:Tx(n.config)}))}}const Mx={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Dx,name:"calendarHeatmap",viewRender:yx,configRender:_x,createConfig:()=>({version:3,config:pi}),triggers:[No]},hi={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:$e,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...nt},overflow:Ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Ix(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:$e,show:!0}}function Ex(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,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:Pt,xAxisIndex:"0"}}function Ax(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zx(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),t.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function $x(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Lx(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:$x(r)})),e}function Ox(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function Xn(t,e,n){const r=lt(t,e),a=lt(t,n);return x.zip(a,r)}function Px(t,e,n,r){const a=Xn(e,n,r);return x.unionBy(a,t,0)}function Bx({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?Px(t,e,n,r):Xn(e,n,r)}function Vx({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Bx({dataTemplate:t,data:e,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=Xn(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const h=u[d].map(m=>m[1]),g=Dr(h,n);return[d,g]})}function Nx({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Xn({[a]:c},r,n)}),l}function qx({y_axis:t},{data_key:e,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},m,w,C,_,T){const I={label:{show:!!r,position:r,formatter:T[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===t.data_key)return I.data=Vx({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:w}),I;const O=Nx({group_by_key:o,data:C,name_data_key:t.data_key,value_data_key:e});return Object.entries(O).map(([B,$])=>{const A=x.cloneDeep(I);return A.name=B,A.color=void 0,A.data=$,A})}function Fx(t,e,n,r,a,o,l){const u=e.map(d=>[d,0]);return t.series.map(d=>qx(t,d,u,n,r,l,a)).flat().concat(Ox(t.reference_lines,o,l,r))}function Gx(t,e){const n=t.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Ot(e.y_axis.axisLabel.formatter)(o,l)}function Wx(t,e,n){const r=e.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
387
387
  <tr>
388
388
  <td>${f}</td>
389
389
  <th style="text-align: right; padding: 0 1em;">${d}</th>
@@ -398,7 +398,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
398
398
  ${l.join("")}
399
399
  </tbody>
400
400
  </table>
401
- `}}}function jx(t){return t.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return ee(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Rx(t,e){const n={};return e.map(r=>{const a=yt(r,t);n[r.name]=et(r,a)}),n}function Yx(t,e){return t.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:e[o]??e.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Qx(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=t.y_axis.axisLabel,o=ut(r.on_axis);return[{data:e,name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Ot(a.formatter)},z:5}]}function Kx(t,e,n){if(!t.y_axis.data_key)return{};const r=Rx(e,n),a=jx(t),o=q(t.y_axis.data_key),l=x.uniq(e[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=Fx(t,l,u,e,a,n,r);return{xAxis:Yx(t,a),yAxis:Qx(t,l),series:c,tooltip:Wx(t,c,a),grid:zx(t),legend:Lx(c)}}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ux({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.y_axis.data_key),u=He(a.triggerManager,Er.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Kx(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Xx({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,hi),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(Ux,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}const Jx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Zx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Hx({control:t,index:e,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Zx,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.xAxisIndex`,control:t,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:Jx,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function e0({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((m,w)=>({...m,...l[w]})),c=()=>{const m=Ax();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=e("x_axes"),h=y.useMemo(()=>f.map(({name:m},w)=>({label:m,value:w.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((m,w)=>i(s.Tabs.Tab,{value:m.id,children:m.name},w)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((m,w)=>i(s.Tabs.Panel,{value:m.id,children:i(Hx,{control:t,index:w,remove:o,watch:e,variableOptions:d,xAxisOptions:h})},w))]})}function t0(t){const[e,n]=y.useState(t);return y.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const n0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function r0({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:n0,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const i0=[{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 a0({control:t,index:e,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.xAxisIndex`,control:t,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.data_key`,control:t,render:({field:o})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>i(Sn,{label:"Aggregation on Value",value:o.value??Pt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(r0,{index:e,control:t,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>i(s.Select,{label:"Label Position",data:i0,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:o})=>i(Pe,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${e}.invisible`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function s0({control:t,watch:e}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,w)=>({...m,...o[w]})),u=()=>{const m=Ex();r(m)},c=e("x_axes"),d=y.useMemo(()=>c.map(({name:m},w)=>({label:m,value:w.toString()})),[c]),{tab:f,setTab:h}=t0((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(m=>i(s.Tabs.Tab,{value:m.id,children:m.name},m.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((m,w)=>i(s.Tabs.Panel,{value:m.id,children:i(a0,{control:t,index:w,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const o0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function l0({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:o0,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this X Axis"})]})}function u0({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=Ix();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(l0,{control:t,index:f,remove:a})},d.id))]})}function c0({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function d0({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,hi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(u0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(c0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(s0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(e0,{variables:r,control:o,watch:u})})]})]})})}function p0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class h0 extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:p0(a,r)}})}}const f0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new h0,name:"horizontalBarChart",viewRender:Xx,configRender:d0,createConfig:()=>({version:2,config:hi})},fi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ln}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function g0(){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 qo=({value:t})=>{try{return ee(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function m0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:qo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
401
+ `}}}function jx(t){return t.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return ee(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Rx(t,e){const n={};return e.map(r=>{const a=yt(r,t);n[r.name]=et(r,a)}),n}function Yx(t,e){return t.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:e[o]??e.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Qx(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=t.y_axis.axisLabel,o=ut(r.on_axis);return[{data:e,name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Ot(a.formatter)},z:5}]}function Kx(t,e,n){if(!t.y_axis.data_key)return{};const r=Rx(e,n),a=jx(t),o=q(t.y_axis.data_key),l=x.uniq(e[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=Fx(t,l,u,e,a,n,r);return{xAxis:Yx(t,a),yAxis:Qx(t,l),series:c,tooltip:Wx(t,c,a),grid:zx(t),legend:Lx(c)}}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ux({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.y_axis.data_key),u=He(a.triggerManager,Er.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Kx(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Xx({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,hi),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(Ux,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}const Jx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Zx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Hx({control:t,index:e,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Zx,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.xAxisIndex`,control:t,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:Jx,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function e0({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((m,w)=>({...m,...l[w]})),c=()=>{const m=Ax();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=e("x_axes"),h=y.useMemo(()=>f.map(({name:m},w)=>({label:m,value:w.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((m,w)=>i(s.Tabs.Tab,{value:m.id,children:m.name},w)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((m,w)=>i(s.Tabs.Panel,{value:m.id,children:i(Hx,{control:t,index:w,remove:o,watch:e,variableOptions:d,xAxisOptions:h})},w))]})}function t0(t){const[e,n]=y.useState(t);return y.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const n0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function r0({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:n0,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const i0=[{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 a0({control:t,index:e,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.xAxisIndex`,control:t,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.data_key`,control:t,render:({field:o})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>i(Sn,{label:"Aggregation on Value",value:o.value??Pt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(r0,{index:e,control:t,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>i(s.Select,{label:"Label Position",data:i0,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:o})=>i(Pe,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${e}.invisible`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function s0({control:t,watch:e}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,w)=>({...m,...o[w]})),u=()=>{const m=Ex();r(m)},c=e("x_axes"),d=y.useMemo(()=>c.map(({name:m},w)=>({label:m,value:w.toString()})),[c]),{tab:f,setTab:h}=t0((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(m=>i(s.Tabs.Tab,{value:m.id,children:m.name},m.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((m,w)=>i(s.Tabs.Panel,{value:m.id,children:i(a0,{control:t,index:w,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const o0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function l0({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:o0,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this X Axis"})]})}function u0({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=Ix();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(l0,{control:t,index:f,remove:a})},d.id))]})}function c0({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function d0({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,hi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(u0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(c0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(s0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(e0,{variables:r,control:o,watch:u})})]})]})})}function p0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class h0 extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:p0(a,r)}})}}const f0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new h0,name:"horizontalBarChart",viewRender:Xx,configRender:d0,createConfig:()=>({version:2,config:hi})},fi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ln}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function g0(){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 qo=({value:t})=>{try{return ee(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function m0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:qo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
402
402
  <table style="width: auto">
403
403
  <thead>
404
404
  <tr colspan="2">
@@ -477,15 +477,15 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
477
477
  </tr>
478
478
  </tbody>
479
479
  </table>
480
- `}},show_in_legend:!0}))}function w0(t,e,n,r){const a=q(e.data_key),o=e.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function C0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[m0(t,n,r),b0(t,n,r,l),...x0(t,n,r,l),w0(t,e,n,r)]}function S0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:js(n.formatter)},axisLine:{show:!1}}]}function _0(t){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:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function gi(t){return t==1||t==2?1:gi(t-2)+gi(t-1)}const k0=Array.from(new Array(20),(t,e)=>gi(e+1));function Go(t){return t<=1?t:k0.findIndex(e=>t<=e)-1}function T0(t,e){const{x_axis:n,deviation:r}=t,a=q(n.data_key),o=q(r.data_keys.estimated_value),l=q(r.data_keys.actual_value);return e[a.queryID].map(u=>{const c=Go(u[o.columnKey]),d=Go(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function D0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function M0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:D0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const I0={tooltip:{trigger:"axis"}};function E0(t,e){const{deviation:n,metrics:r}=t,a=r.find(l=>l.data_key===e);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function A0(t,e,n){const r=T0(t,n),a=q(t.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=E0(t,e),c=C0(t,u,o,l),d={xAxis:S0(t,o),yAxis:_0(u),series:c,grid:g0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:M0(c)};return x.defaultsDeep({},d,I0)}const z0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},$0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:a}=t,o=y.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:e,onChange:l=>n(l.currentTarget.value),styles:z0})]})},L0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function O0(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:L0,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function P0(t){return p(s.Group,{position:"apart",children:[i(O0,{}),i($0,{...t})]})}le.use([pe.BarChart,pe.LineChart,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.VisualMapComponent]);function B0({conf:t,data:e,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>A0(t,a,e),[t,e,a]);return i(Ne,{echarts:le,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function V0({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,fi),[e]),r=t.data,{width:a,height:o}=t.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=y.useState(d);if(y.useEffect(()=>{h(w=>w||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(a,300),m=Math.max(o,370);return p(s.Box,{sx:{overflow:"hidden",height:m,width:g},children:[i(P0,{conf:n,metricKey:f,setMetricKey:h}),i(B0,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function N0({control:t,watch:e}){return e(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:t,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:n})=>i(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>i(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const q0=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),F0=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(q0,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function G0({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Qs,{...n})})]})]})}function W0({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,fi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(G0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(N0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(F0,{control:a,watch:l})})]})]})})}function j0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class R0 extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:j0(a,r)}})}}const Y0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new R0,name:"mericoEstimationChart",viewRender:V0,configRender:W0,createConfig:()=>({version:2,config:fi})},mi={styles:{justify:"space-around",align:"start"},metrics:[]};function Q0(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:$e}}function K0({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},n,mi),[n]),o=t.data,l=y.useMemo(()=>Is(o,r),[r,o]),{width:u,height:c}=t.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.value}),i(s.Text,{size:"24px",color:"#000000",sx:{lineHeight:1},children:ee(l[d.data_keys.value]).format(d.formatter)})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.basis}),i(s.Text,{size:"12px",color:"#000000",sx:{lineHeight:1},children:ee(l[d.data_keys.basis]).format(d.formatter)})]})]},d.id))})}function U0({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.names.value`,control:t,render:({field:a})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${e}.data_keys.value`,control:t,render:({field:a})=>i(s.Select,{label:"Metric Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.names.basis`,control:t,render:({field:a})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${e}.data_keys.basis`,control:t,render:({field:a})=>i(s.Select,{label:"Basis Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${e}.formatter`,control:t,render:({field:a})=>i(Re,{...a})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(D.Trash,{size:16})})]},e)}function X0({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"metrics"}),l=e("metrics"),u=r.map((w,C)=>({...w,...l[C]})),c=()=>{a(Q0())},d=y.useMemo(()=>n.map(w=>({label:w.name,value:w.name})),[n]),f=x.get(u,"0.id",null),[h,g]=y.useState(f);y.useEffect(()=>{g(w=>w||f)},[f]);const m=w=>{o(w);const C=x.get(u,"0.id",null);g(C)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((w,C)=>i(s.Tabs.Tab,{value:w.id,children:w.names.value?w.names.value:C+1},C)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),u.map((w,C)=>i(s.Tabs.Panel,{value:w.id,children:i(U0,{control:t,index:C,remove:m,variableOptions:d})},C))]})]})}const J0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],Z0=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function H0({control:t,watch:e}){return e("styles"),p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:t,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:J0,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Z0,sx:{flex:1},...n})})]})]})}function ew({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,mi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),i(H0,{control:o,watch:u}),i(X0,{control:o,watch:u,variables:r})]})})}class tw extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config}))}}const nw={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new tw,name:"merico-stats",viewRender:K0,configRender:ew,createConfig:()=>({version:1,config:mi})},rw=[{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(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),iw=[tc,nc,ac,ic,rc,sc],Wo=()=>({id:"dashboard",version:vs,manifest:{viz:[wi,mv,Rv,Qy,Vv,vg,f0,yc,Od,jh,Df,Mx,sg,wh,iv,Bg,pm,Hv,Y0,nw,Ud],color:[...rw,...iw]}}),sn=new cc,Ce={pluginManager:ot("pluginManager"),vizManager:ot("vizManager"),colorManager:ot("colorManager"),instanceScope:{panelModel:ot("panelModel"),vizInstance:ot("vizInstance"),interactionManager:ot("interactionManager"),migrator:ot("migrator"),operationManager:ot("operationManager"),triggerManager:ot("triggerManager")}},yi=()=>{try{sn.install(Wo())}catch{}const t=new Zu(sn),e=new uc(sn);return{pluginManager:sn,vizManager:t,colorManager:e}},at=y.createContext(yi());try{sn.install(Wo())}catch{}function aw(t,e){const{value:n,set:r}=W(t.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,e)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,e))},[n]),{config:a,setConfig:o,commit:l}}function sw(t){const{config:e,setConfig:n,commit:r}=aw(t,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...e,openInNewTab:u}),await r()}const l=u=>n({...e,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function ow(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class lw extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const uw={displayName:"Open Link",id:"builtin:op:open-link",configRender:sw,run:ow,migrator:new lw,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function cw(t){const{value:e,set:n}=W(t.operationData,"config"),r=a=>void n({template:a});return[(e==null?void 0:e.template)||"",r]}function dw(t){const[e,n]=cw(t.operation);return i(s.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function pw(t,e){const n=await e.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const hw={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:dw,run:pw},fw=k.observer(t=>{const e=K(),{value:n,set:r}=W(t.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:e.views.options})});async function gw(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const mw={displayName:"Open View",id:"builtin:op:open_view",configRender:fw,run:gw},yw={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},bw=({value:t="",onChange:e})=>{const[n,r]=y.useState(t);y.useEffect(()=>{r(t)},[t]);const a=()=>{e(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===t,children:i(L.IconDeviceFloppy,{})})})},vw={dictionary:{}},xw=k.observer(t=>{const e=K(),{value:n=vw,set:r}=W(t.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...e.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:yw,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...e.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(bw,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function ww(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const Cw={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:xw,run:ww},Sw={filter_keys:[]},_w=k.observer(t=>{const e=K(),{value:n=Sw,set:r}=W(t.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=y.useMemo(()=>e.filters.current.map(u=>({label:u.label,value:u.key})),[e.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function kw(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const Jn=[hw,uw,mw,Cw,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:_w,run:kw}];class Tw{constructor(e,n=Jn){N(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Lt(a,"data")}};this.attachments=new xr(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(e,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(e);return!a||a.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}class bi{constructor(e,n,r){N(this,"operationManager");N(this,"triggerManager");N(this,"attachments");this.operationManager=new Tw(e,r),this.triggerManager=new qc(e,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new xr(e,"__INTERACTIONS",a)}async addInteraction(e,n){const r=e.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(e){const n=await this.attachments.getInstance(e);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===e);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const tt=({vizManager:t,instance:e})=>X.useCreation(()=>new bi(e,t.resolveComponent(e.type),Jn),[e,t]),jo={left:"flex-start",center:"center",right:"flex-end"},Dw=({header:t,cx:e})=>{const n=x.get(t.column.columnDef.meta,"align","left");return p(s.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:jo[n]},children:[t.isPlaceholder?null:Xe.flexRender(t.column.columnDef.header,t.getContext()),i(Mw,{direction:t.column.getIsSorted()})]})},Mw=({direction:t})=>{switch(t){case"asc":return i(L.IconArrowUp,{size:16});case"desc":return i(L.IconArrowDown,{size:"1em"});default:return null}},vi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:zw,configRender:Ew,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"}]},Iw={column:""};function Ro(t,e){const{value:n}=W(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const a=xn(e,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function Ew(t){const{columnsFromConfig:e,columnsFromData:n}=Ro(t.instance,t.sampleData),r=e.length>0?e:n,{value:a,set:o}=W(t.trigger.triggerData,"config"),{column:l}=x.defaults({},a,Iw),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Aw(t,e){return t?x.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function zw(t){const{columnsFromConfig:e}=Ro(t.instance),{value:n}=W(t.trigger.triggerData,"config");return i(s.Text,{children:Aw(n,e)})}const $w=s.createStyles(t=>({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:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Lw={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}};function Yo(t,e,n){return Math.min(Math.max(t,e),n)}class Ow{constructor(e){this.steps=e;const n=[],r=new Set;for(const a of e)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(e,n){const r=(n.to-e.to)/(n.from-e.from),a=e.to-r*e.from;return o=>r*o+a}getStepFunctionForValue(e){let n=x.findLastIndex(this.steps,r=>r.from<=e);return n=Yo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return Yo(this.getStepFunctionForValue(e)(e),0,100)}}class Pw{constructor(e,n,r,a,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.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 r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===vi.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(x.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new Ow(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Bw=s.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:jo[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function Vw(t){return t?st(t).oklch()[0]>.7?"black":"white":"inherit"}function Nw(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:Vw(e)}}function qt(t){const e=t.tableCellContext.isClickable(),n=Bw({clickable:e,align:t.align});return i("div",{className:n.classes.content,style:{...Nw(t)},children:i(s.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:i("span",{title:t.children,children:t.children})})})}function qw(t){return i(qt,{...t,children:t.value})}function Fw(t){const e=ee(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(qt,{...t,children:e})}function Gw(t){const e=ee(t.value).format({thousandSeparated:!0});return i(qt,{...t,children:e})}function Ww(t){const e=ee(t.value).format({output:"percent",mantissa:3});return i(qt,{...t,children:e})}function jw(t){const e=t.value,n=t.func_content;if(!n)return i(qt,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return i(qt,{...t,children:r})}function Rw(t){switch(t.type){case Je.string:return i(qw,{...t});case Je.eloc:return i(Fw,{...t});case Je.number:return i(Gw,{...t});case Je.percentage:return i(Ww,{...t});case Je.custom:return i(jw,{...t})}}const Yw=t=>{const e=tt(t),n=He(e.triggerManager,vi.id),{colorManager:r}=y.useContext(at);return y.useCallback(a=>new Pw(t.getColIndex,a,n,e,r),[n,e,t.getColIndex])};function Qw({context:t,instance:e}){var ye,De;const n=t.data,{height:r,width:a}=t.viewport,{value:o=vr}=W(t.instanceData,"config"),{id_field:l,use_raw_columns:u,columns:c,...d}=o,{classes:f,cx:h}=$w(),g=y.useMemo(()=>{if(!l)return[];const ge=q(l);return n[ge.queryID]},[n,l]),m=y.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(ge=>({id:ge,label:ge,value_field:ge,value_type:Je.string,align:"left"})):c,[u,c,g]),w=Yw({getColIndex:y.useCallback(ge=>m.indexOf(ge.column.columnDef.meta),[m]),vizManager:t.vizManager,instance:e}),C=y.useMemo(()=>{const ge=Xe.createColumnHelper();return m.map(ve=>{const Oe=q(ve.value_field);return ge.accessor(Oe.columnKey,{cell:Qe=>i(Rw,{tableCellContext:w(Qe.cell),value:Qe.getValue(),type:ve.value_type,...ve}),header:ve.label,enableSorting:!0,meta:ve,size:ve.width,minSize:ve.width})})},[m,w]),[_,T]=y.useState([]),I=Xe.useReactTable({data:g,state:{sorting:_},onSortingChange:T,columns:C,getCoreRowModel:Xe.getCoreRowModel(),getSortedRowModel:Xe.getSortedRowModel()}),{rows:O}=I.getRowModel(),B=y.useRef(null),$=eu.useVirtual({parentRef:B,size:O.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:A,totalSize:E}=$,F=A.length>0&&((ye=A==null?void 0:A[0])==null?void 0:ye.start)||0,U=A.length>0?E-(((De=A==null?void 0:A[A.length-1])==null?void 0:De.end)||0):0,Y=O.length,Z=Y>0,oe=Z?r-22:r,ue=Z?22:0;return!Array.isArray(g)||g.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:B,style:{height:r,width:a},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[Y>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",Y]})}),p(s.Table,{sx:{...Lw,maxHeight:oe},...d,striped:o.striped,children:[i("thead",{className:f.thead,style:{top:ue},children:I.getHeaderGroups().map(ge=>i("tr",{children:ge.headers.map(xe=>i("th",{style:{width:xe.getSize()},children:i(Dw,{header:xe,cx:h})},xe.id))},ge.id))}),p("tbody",{children:[F>0&&i("tr",{children:i("td",{style:{height:`${F}px`}})}),A.map(ge=>{const xe=O[ge.index];return i("tr",{children:xe.getVisibleCells().map(ve=>i("td",{children:Xe.flexRender(ve.column.columnDef.cell,ve.getContext())},ve.id))},xe.id)}),U>0&&i("tr",{children:i("td",{style:{height:`${U}px`}})})]})]})]})}const Qo=s.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)"}}}})),Kw=[{from:0,to:0},{from:100,to:100}];class Uw{constructor(){N(this,"steps",new Map);N(this,"interpolation");N(this,"onChange");ie.makeAutoObservable(this,{steps:ie.observable},{deep:!1}),ie.reaction(()=>ie.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(Kw):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function Xw(t){const{onChange:e,color:n,index:r,value:a}=t,{classes:o}=Qo(),[l,u]=y.useState(a),[c,{setTrue:d,setFalse:f}]=X.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,w=`map ${a} to color ${r}`,C=()=>{u(a),f()},_=()=>{f(),e==null||e(l)},T=ee(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:w,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:T}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":st(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:w,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:T})]})}const Jw=k.observer(({model:t})=>{const{classes:e}=Qo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return i("div",{className:e.palette,children:n.map(([r,a],o)=>i(Xw,{index:o,color:r,value:t.getStepFromValue(a),onChange:l=>t.changeStep(l,a)},r))})}),Zw=k.observer(function(e){const n=X.useCreation(()=>new Uw,[]);return y.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:i(Jw,{model:n})}),Hw=t=>{const{value:e,onChange:n,colorManager:r}=t,a=r.getColorInterpolations(),[o,l]=y.useState(e),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=X.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(ie.toJS(o))};function w(_){l(T=>({...T,steps:_}))}const C=()=>{f(),l(e)};return p(V,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),i(Zw,{steps:o.steps,interpolation:u,onChange:w}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:C,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},eC=["static","interpolation","none"].map(t=>({label:x.capitalize(t),value:t})),tC=[{from:0,to:0},{from:100,to:100}];function Ko(t){return t?x.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function nC(t,e){var n;return Ko(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function rC(t,e){return x.isObject(e)?e:{steps:tC,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const iC=y.forwardRef((t,e)=>{const{colorManager:n}=y.useContext(at),[r,a]=y.useState(Ko(t.value)),[o,l]=y.useState(nC(n,t.value)),u=X.useLatest(o),[c,d]=y.useState(rC(n,t.value)),f=X.useLatest(c),h=w=>{var C,_,T;a(w||"none"),w==="static"?(C=t.onChange)==null||C.call(t,u.current):w==="none"||!w?(_=t.onChange)==null||_.call(t,"none"):(T=t.onChange)==null||T.call(t,f.current)},g=w=>{var C;l(w),(C=t.onChange)==null||C.call(t,w)},m=w=>{var C;d(w),(C=t.onChange)==null||C.call(t,w)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:eC}),r==="static"&&i(Pe,{value:o,onChange:g}),r==="interpolation"&&i(Hw,{colorManager:n,value:c,onChange:m})]})}),aC={[Je.eloc]:"ELOC"},sC=Object.values(Je).map(t=>({label:x.get(aC,t,x.capitalize(t)),value:t})),oC=y.forwardRef(({label:t,value:e,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:t,data:sC,value:e,onChange:n,sx:r})),lC=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(gs)};return y.useEffect(()=>{u(t)},[t]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),uC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],xi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),cC=({control:t,index:e,watch:n,remove:r,column:a})=>{const o=n(`columns.${e}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.label`,control:t,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${e}.value_field`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.value_type`,control:t,render:({field:l})=>i(oC,{label:"Value Type",sx:{flex:1},...l})}),o===Je.custom&&i(v.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>i(lC,{value:l.value??gs,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(xi,{}),disabled:!0}),i(v.Controller,{name:`columns.${e}.width`,control:t,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(xi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(xi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${e}.align`,control:t,render:({field:l})=>i(s.Select,{label:"Alignment",data:uC,...l})})}),i(v.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>i(iC,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(e),children:"Delete this column"})]})},dC=({control:t,watch:e})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:t,name:"columns"}),l=()=>{const c=Me.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:Je.string})};e("columns");const u=e("use_raw_columns");return p(V,{children:[i(v.Controller,{name:"use_raw_columns",control:t,render:({field:c})=>i(s.Switch,{mt:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),!u&&p(s.Stack,{children:[i(s.Text,{my:0,children:"Custom Columns"}),p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(cC,{control:t,watch:e,index:d,column:c,remove:a},d)},c.id))]})]})]})};function pC({control:t,watch:e}){return e(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:t,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:t,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:t,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function hC({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??Me.randomId(),...r}))}}function fC({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,vr),[e]),a=y.useMemo(()=>hC(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Columns",children:"Columns"})]}),i(s.Tabs.Panel,{value:"Data",children:i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(j,{label:"ID Field",required:!0,...g})})}),i(s.Tabs.Panel,{value:"Style",children:i(pC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Columns",children:i(dC,{control:o,watch:u})})]})]})}function gC(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function mC(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=t;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class yC extends be{constructor(){super(...arguments);N(this,"VERSION",4)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??Me.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:gC(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:mC(n.config,r)}))}}const wi={createConfig(){return{version:4,config:x.cloneDeep(vr)}},displayName:"Table",displayGroup:"Others",migrator:new yC,name:"table",viewRender:Qw,configRender:fC,triggers:[vi]},bC=b.types.model("PanelLayoutModel",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{x:e,y:n,w:r,h:a,moved:o}=t;return{h:a,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:a,h:o,moved:l}=e;t.x=n,t.y=r,t.w=a,t.h=o,t.moved=!!l,t.static=!!e.static}})),vC=b.types.model("PanelStyleBorderModel",{enabled:b.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),xC=b.types.model("PanelStyleModel",{border:vC}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),wC=b.types.model("PanelVizModel",{type:b.types.string,conf:b.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),Uo=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:bC,queryIDs:b.types.array(b.types.string),viz:wC,style:xC,variables:b.types.optional(b.types.array(Qu),[])}).views(t=>({get contentModel(){return b.getParentOfType(t,Zn)}})).views(t=>({get queryIDSet(){return new Set(t.queryIDs)},get queries(){return t.contentModel.queries.findByIDSet(this.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data.toJSON(),e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){return this.queries.map(e=>e.stateMessage).filter(e=>!!e)},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:e,title:n,description:r,queryIDs:a}=t;return{id:e,viz:t.viz.json,style:t.style.json,title:n,layout:t.layout.json,queryIDs:[...a],variables:t.variables.map(o=>o.json),description:r}},get dataFieldOptions(){return t.queryIDs.length===0?[]:this.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${e.id}.${a}`,group:e.name}))}).flat()}})).actions(t=>({setID(e){t.id=e},setTitle(e){t.title=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=b.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=b.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)},removeSelf(){b.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){b.getRoot(t).content.views.findByID(e).removePanelID(t.id),b.getRoot(t).content.views.findByID(n).appendPanelID(t.id),b.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])},refreshData(){t.queries.forEach(e=>e.fetchData())},downloadData(){b.getRoot(t).content.queries.downloadDataByQueryIDs(t.queryIDs)}}));function Xo(t){return{id:t,layout:{x:0,y:1/0,w:18,h:300},title:t,description:"<p></p>",queryIDs:[],viz:{type:wi.name,conf:wi.createConfig()},style:{border:{enabled:!0}}}}const Jo=b.types.model("PanelsModel",{list:b.types.optional(b.types.array(Uo),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(a=>{const o=t.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),a}})).actions(t=>({replace(e){t.list=b.castToSnapshot(e)},append(e){t.list.push(e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},duplicateByID(e){const n=t.list.find(a=>a.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}}));var Zo=(t=>(t.Use="use",t.Edit="edit",t))(Zo||{}),H=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(H||{});const CC={div:"Division",tabs:"Tabs",modal:"Modal"},Ho={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},SC={div:"#ff4000",modal:"#000",tabs:"#ffad18"},_C={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var Ci=(t=>(t.Select="select",t.TreeSelect="tree-select",t.MultiSelect="multi-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ci||{});const el=b.types.model("ViewModel_Division",{_name:b.types.literal(H.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})).actions(t=>({})),kC=()=>el.create({_name:H.Division}),Si={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
481
- `)},TC=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=b.getParent(t,2),a=b.getRoot(t);if(!e)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),tl=b.types.model("ViewModel_Modal",{_name:b.types.literal(H.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(TC,Si)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:a}=t;return{_name:e,width:n,height:r,custom_modal_title:a.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),DC=()=>tl.create({_name:H.Modal,width:"90vw",height:"90vh"}),MC=b.types.model("ViewModel_Tabs_Tab",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{id:e,name:n,view_id:r,color:a}=t;return{id:e,name:n,color:a,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),nl=b.types.model("ViewModel_Tabs",{_name:b.types.literal(H.Modal),tabs:b.types.optional(b.types.array(MC),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:a,grow:o}=t;return{grow:o,tabs:a.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=b.cast(e)},addTab(){const e=Me.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),IC=()=>nl.create({_name:H.Modal,tabs:[]}),rl=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[H.Division,H.Modal,H.Tabs]),config:b.types.union(el,tl,nl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:a}=t;return{id:e,name:n,type:r,config:a.json,panelIDs:t.panelIDs}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case H.Division:t.config=kC();break;case H.Modal:t.config=DC();break;case H.Tabs:t.config=IC();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})).actions(t=>({})),il=b.types.model("ViewsModel",{current:b.types.optional(b.types.array(rl),[]),visibleViewIDs:b.types.array(b.types.string),idOfVIE:b.types.string}).views(t=>({get json(){return t.current.map(e=>yn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=b.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({replace(e){t.current.replace(e)},addANewView(e,n,r,a){t.current.push({id:e,name:n,type:r,config:a,panelIDs:[]})},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n!==-1&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)}})).actions(t=>({addARandomNewView(){const e=new Date().getTime().toString();t.addANewView(e,H.Division,H.Division,{_name:H.Division}),t.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(t.removeByID(t.idOfVIE),t.setIDOfVIE(t.current[0].id))},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function _i(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}function al(t,e,n,r){return t.reduce((a,o)=>(a[o[e]]=pr(o[n],r),a),{})}const EC=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:is,queries:ds,sqlSnippets:hs,views:il,panels:Jo,mock_context:Yu,origin:b.types.maybe(b.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get filtersChanged(){const e="filters.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=b.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get payloadForSQL(){const e=b.getParent(t).context.current,n=b.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:al(t.sqlSnippets.current,"key","value",r),global_sql_snippets:al(n.list,"id","content",r)}},get payloadForViz(){const e=b.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);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(t=>({findQueryUsage(e){const n=t.panels.idMap,r=t.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(e))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=t.views.idMap,o=t.filters.current.filter(l=>x.get(l,"config.options_query_id")===e).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(t=>({duplicatePanelByID(e,n){var a;const r=t.panels.duplicateByID(e);r&&((a=t.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=new Date().getTime().toString();t.panels.append(Xo(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)}})).actions(t=>({reset(){b.applySnapshot(t.filters.current,t.origin.filters.current),b.applySnapshot(t.queries.current,t.origin.queries.current),b.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),b.applySnapshot(t.views.current,t.origin.views.current),b.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){b.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:a}=e;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;t.id=n,t.name=r,t.version=o,b.applySnapshot(t.filters.current,l),b.applySnapshot(t.views.current,_i(u).current),b.applySnapshot(t.panels.list,c),b.applySnapshot(t.queries.current,d),b.applySnapshot(t.sqlSnippets.current,f),t.mock_context.current=h}})),Zn=b.types.snapshotProcessor(EC,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=b.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function AC(t,e){e.filters&&b.applySnapshot(t.filters.current,e.filters)}function sl({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Zn.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,version:l,filters:as(u),queries:{current:f},sqlSnippets:{current:h},mock_context:{current:g},views:_i(c),panels:{list:d}})}const zC=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),$C=b.types.model("GlobalSQLSnippetsModel",{list:b.types.optional(b.types.array(zC),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),ol=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Zn,content_id:b.types.string,datasources:Wu,globalSQLSnippets:$C,context:fs,editor:Ru}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:a,group:o,content_id:l}=e;t.id=r,t.name=a,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function ki({id:t,name:e,group:n,content_id:r},a,o,l,u){return ol.create({id:t,name:e,group:n,content_id:r,content:sl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:u},editor:{}})}const Ti=y.createContext(null);function Hn(t){const e=y.useContext(Ti),n=X.useCreation(()=>t.configure(e||new wr),[t.configure]),r=X.usePrevious(n);return r&&r!==n&&r.dispose(),i(Ti.Provider,{value:n,children:t.children})}function ll(){return y.useContext(Ti)}const LC={viewPanelInFullScreen:x.noop,inFullScreen:!1},Di=y.createContext(LC),OC=({description:t,isDescriptionEmpty:e})=>e?null:i(s.Tooltip,{color:"white",label:i(Kn,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(L.IconInfoCircle,{size:16,color:"gray"})})}),PC=k.observer(({label:t,config:{default_value:e,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:t}),i(OC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),ul=k.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=e,l=Array.isArray(n)?n.map(f=>f?R(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&R(h).format(a)))},c=e.getMinDate(l[0]),d=e.getMaxDate(l[0]);return i(ru.DatePickerInput,{type:"range",label:t,value:l,onChange:u,icon:i(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),BC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),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:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.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}}}})),cl=({errorMessage:t})=>t?i(s.Text,{color:"red",size:12,children:t}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),VC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f})=>{const{classes:h,cx:g}=BC({radius:a},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[m,w]=y.useState(!1),C=B=>{w(B)},_=m&&(u==null?void 0:u.length)>0,[T,I]=y.useState(""),O=y.useMemo(()=>{if(!T)return d;const B=T.toLowerCase(),$=A=>{var E;return((E=A.description)==null?void 0:E.toLowerCase().includes(B))||A.label.toLowerCase().includes(B)};return d.filter($)},[T,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(qa,{disabled:t,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:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(cl,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:B=>`${B.length} selected`,searchValue:T,onSearch:I,filterOption:!1,children:O.map(B=>i(qa.Option,{children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:B.label}),B.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:B.description})]})})},B.value))})]})},NC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading",d=e.min_width?e.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(VC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),qC=y.forwardRef(({label:t,description:e,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:t}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),FC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading";return y.useEffect(()=>{var h;const{default_selection_count:d}=e;if(!d)return;const f=((h=e.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),r(f,!0)},[e.default_selection_count,e.options]),i(s.Select,{label:t,data:e.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:qC})});function GC({label:t,config:e,value:n,onChange:r}){return i(s.TextInput,{label:t,value:n||"",onChange:a=>r(a.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const WC=({rotate:t,onClick:e})=>i("svg",{onClick:e,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(${t})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),jC=({expanded:t,isLeaf:e,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),e?i("span",{style:{width:"14px",display:"inline-block"}}):i(WC,{rotate:t?"0":"-90",onClick:r,...a})),RC=({onClick:t})=>p("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),YC=({onClick:t,...e})=>i(RC,{onClick:t,...e}),QC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),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:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.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"}}}})),KC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f})=>{const{classes:h,cx:g}=QC({radius:a},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[m,w]=y.useState(!1),C=T=>{w(T)},_=m&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Fa,{disabled:t,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:()=>i(s.CloseButton,{}),switcherIcon:jC,treeIcon:YC,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(cl,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Fa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:T=>`${T.length} selected`})]})},UC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=e,u=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return i(KC,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:t})}),XC=k.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:a})=>{switch(t){case"select":return i(FC,{...r,...a,config:e});case"multi-select":return i(NC,{...r,...a,config:e});case"tree-select":return i(UC,{...r,...a,config:e});case"text-input":return i(GC,{...r,...a,config:e});case"date-range":return i(ul,{...r,...a,config:e});case"checkbox":return i(PC,{...r,...a,config:e});default:return null}}),dl=k.observer(y.forwardRef(({filter:t,...e},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(XC,{filter:t,formFieldProps:e})})}))),pl=k.observer(function({view:e}){const n=K(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),y.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const u=n.filters.visibleInView(e.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(w,C)=>{m(w),(g.should_auto_submit||C)&&n.filters.setValueByKey(g.key,w)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(dl,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),gD="";function JC(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const hl=k.observer(()=>{const{freezeLayout:t}=y.useContext(ft),[e,n]=y.useState(!1),{panel:r}=ze();return y.useEffect(()=>{t(e)},[e]),JC(r.description)?null:p(V,{children:[i(s.Modal,{opened:e,onClose:()=>n(!1),title:r.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Kn,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(a=>!a),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(D.InfoCircle,{size:20})})})]})}),ZC=k.observer(({view:t})=>{const e=he(),n=K(),r=Ue.useModals(),{panel:a}=ze(),{id:o}=a,{inEditMode:l}=y.useContext(ft),{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(Di),d=()=>{n.duplicatePanelByID(o,t.id)},f=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",o])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,t.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(o)},[o,u]),m=!c&&t.type!==H.Modal;return i(V,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),m&&i(s.Menu.Item,{onClick:g,icon:i(D.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(V,{children:[i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(D.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(D.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(D.Trash,{size:14}),children:"Delete"})]})]})]})})})}),HC=k.observer(({panel:t})=>p(s.Stack,{children:[t.queryErrors.map((e,n)=>i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),t.queryStateMessages.map((e,n)=>i(s.Text,{color:"gray",align:"center",children:e},`${n}-${e}`))]}));var fl=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(fl||{}),er=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(er||{});class e1{constructor(e){N(this,"vizInstance");N(this,"operationManager");N(this,"triggerManager");N(this,"vizManager");N(this,"runningMigration");N(this,"panelModel");N(this,"status","notStarted");this.panelModel=e.getRequired(Ce.instanceScope.panelModel),this.vizInstance=e.getRequired(Ce.instanceScope.vizInstance),this.operationManager=e.getRequired(Ce.instanceScope.operationManager),this.triggerManager=e.getRequired(Ce.instanceScope.triggerManager),this.vizManager=e.getRequired(Ce.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.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(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function gl(t){const{panel:e}=ze();return y.useCallback(n=>{const r=n.getRequired(Ce.vizManager),a=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(Ce.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(Ce.instanceScope.interactionManager,o=>{const l=o.getRequired(Ce.instanceScope.vizInstance);return new bi(l,a,Jn)}).provideFactory(Ce.instanceScope.operationManager,o=>o.getRequired(Ce.instanceScope.interactionManager).operationManager).provideFactory(Ce.instanceScope.triggerManager,o=>o.getRequired(Ce.instanceScope.interactionManager).triggerManager).provideValue(Ce.instanceScope.panelModel,e).provideFactory(Ce.instanceScope.migrator,o=>new e1(o))},[t.viz.type,t.viz.conf])}function ml(t){const[e,n]=y.useState(!1),r=ll().getRequired(Ce.instanceScope.migrator);return X.useAsyncEffect(async()=>{const a=r.status===er.notStarted;n(r.status===er.done),r.status===er.notStarted&&r.runMigration().then(o=>{o===fl.migrated&&a&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function yl(t,e){const n=ll().getRequired(Ce.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function t1({setVizConf:t,...e}){const{panel:n}=e,r=yl(t,n),a=ml(()=>{hn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return X.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(ec,{...e}):i(s.Text,{children:"Checking update..."})}function n1(t){const{panel:e,setVizConf:n}=t;yl(n,e);const{inEditMode:r}=y.useContext(ft);return ml(()=>{r&&hn.showNotification({title:`${e.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Hu,{...t}):i(s.Text,{children:"Checking update"})}const mD="";function r1(t,e){const{vizManager:n}=y.useContext(at),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=ze(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:e},f=gl(d);try{return n.resolveComponent(r.type),i(Hn,{configure:f,children:i(n1,{setVizConf:r.setConf,panel:d,data:t,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const i1=k.observer(function({data:e}){const{ref:n,width:r,height:a}=Me.useElementSize(),o=r1(e,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:l&&i(Fe,{children:o})})}),bl=k.observer(({panel:t,height:e})=>p(s.Flex,{direction:"column",sx:{height:e,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&i(HC,{panel:t}),t.canRenderViz&&i(i1,{data:t.data})]})),yD="",a1=k.observer(function(){const{panel:e}=ze(),{title:n}=e;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function s1(t){return!["richText","button"].includes(t)}const o1={border:"1px solid #e9ecef"},l1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function u1(t,e){return t.style.border.enabled?o1:e?l1:{border:"1px dashed transparent"}}const tr=k.observer(function({panel:e,view:n}){const{inEditMode:r}=y.useContext(ft),a=e.title?"calc(100% - 25px - 5px)":"100%",o=u1(e,r),u=s1(e.viz.type)||r;return i(Sr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors},children:p(s.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(hl,{})}),u&&i(ZC,{view:n}),i(a1,{}),i(bl,{panel:e,height:a})]})})}),bD="",c1=y.forwardRef(({h:t},e)=>i(s.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(D.ArrowsMove,{size:16})})),d1=y.forwardRef(({handleAxis:t,...e},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...e,children:i(D.ChevronDownRight,{size:16})})),p1=fn.WidthProvider(fn),h1=k.observer(({view:t,className:e="layout"})=>{const n=K(),{panels:r,layouts:a}=n.panels.panelsByIDs(t.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(p1,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(d1,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(c1,{h:u.layout.h}),i(tr,{view:t,panel:u})]},u.id))})}),f1=fn.WidthProvider(fn),g1=k.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:a}=K().panels.panelsByIDs(e.panelIDs);return i(f1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(tr,{view:e,panel:o})},o.id))})}),m1=k.observer(({children:t})=>i(s.Box,{pt:10,pb:100,children:t}));function vl(t){return t.replace(/(vw|vh)/,"%")}const y1=k.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:a}=y.useMemo(()=>({width:vl(n.width),height:vl(n.height)}),[n.width,n.height]);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:o=>{o.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",width:r,height:a},content:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionProps:{duration:0},children:t})})}),b1=({variant:t,orientation:e})=>{const n={tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},v1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},x1=k.observer(({children:t,view:e})=>{const n=Ue.useModals(),r=K(),a=y.useMemo(()=>r.views.options.filter(c=>c.type===H.Division),[e.id,r.views.options]),o=e.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 p(s.Box,{className:"preview-view-tabs",children:[p(s.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:b1(o),children:[p(s.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>i(s.Tabs.Tab,{value:c.id,sx:v1(c),children:c.name??c.id},c.id)),i(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:i(D.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,d)=>{const f=r.views.findByID(c.view_id);return p(s.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),i(s.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:a}),i(s.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:u,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&i(nr,{view:f})]},c.id)})]}),t]})}),w1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(y1,{view:t,children:e});case H.Tabs:return i(x1,{view:t,children:e});case H.Division:default:return i(m1,{children:e})}}),xl=k.observer(function({view:e}){return i(Di.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(w1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(pl,{view:e})}),i(h1,{view:e})]})})})})}),C1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},S1=k.observer(function({view:e,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:C1,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(tr,{view:e,panel:n})})})});function _1(t,e,n){const{panels:r}=K(),a=t.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(e)?e:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const k1=k.observer(({children:t})=>i(s.Box,{children:t})),T1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config,a=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{content:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionProps:{duration:0},children:t})}),D1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},M1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config;return p(s.Box,{className:"render-view-tabs",children:[p(s.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:r.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:r.grow,children:r.tabs.map(a=>i(s.Tabs.Tab,{value:a.id,sx:D1(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabs.map(a=>{const o=n.views.findByID(a.view_id);return o?i(s.Tabs.Panel,{value:a.id,children:i(nr,{view:o})},a.id):null})]}),t]})}),I1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(T1,{view:t,children:e});case H.Tabs:return i(M1,{view:t,children:e});case H.Division:default:return i(k1,{children:e})}}),nr=k.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ws(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=_1(e,n,r);return i(Di.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&i(S1,{view:e,panel:u,exitFullScreen:o}),i(I1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(pl,{view:e})}),!l&&i(g1,{view:e})]})})]})})});function Mi(t){return y.useCallback(e=>e.provideValue(Ce.pluginManager,t.pluginManager).provideValue(Ce.vizManager,t.vizManager).provideValue(Ce.colorManager,t.colorManager),[])}const E1=k.observer(({headerMenuItems:t=null})=>{const e=he(),n=K(),r=()=>{const a=JSON.stringify(n.json,null,2),o=`${e.name}__${n.name}`;Au(o,a)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(L.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(L.IconCode,{size:14}),onClick:r,children:"Download Schema"}),t]})]})}),A1=k.observer(({saveDashboardChanges:t})=>{const e=Ue.useModals(),n=K(),r=()=>{e.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(L.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(L.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(L.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),z1=k.observer(({saveDashboardChanges:t,headerSlot:e=null,headerMenuItems:n})=>{const r=iu.useNavigate(),a=he(),o=()=>{r(`/dashboard/${a.id}`)},l=Ue.useModals(),u=()=>{l.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=a.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:c?"red":"green",leftIcon:i(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:a.name})]})}),i(A1,{saveDashboardChanges:t})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[e,i(E1,{headerMenuItems:n})]})]})})}),$1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},L1=k.observer(()=>{const t=K();return i(s.Box,{sx:$1,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!t.views.VIE,onClick:()=>t.addANewPanel(t.views.idOfVIE),leftIcon:i(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"}),i(s.Box,{}),i(s.Box,{})]})})}),O1=k.observer(t=>p(V,{children:[i(z1,{...t}),i(L1,{})]})),vD="",xD="";function P1(t,e,n){const r=[];return t.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=e[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:w}=m;switch(g){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:w.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(w.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:w.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function B1(t,e){const n=t.filters.keyLabelMap;return{edges:P1(t.panels.list,e,n),edgeNodes:[]}}function wl(t,e,n){return t*e+t*n}function V1(t,e,n){return t*e+(t-1)*n}const rr=25,Ii=40,Cl=25,Ei=350,N1=150,q1=150,Sl=150,_l=300,ir=40,kl=25,F1=300;function G1(t,e){const n=x.keyBy(e,a=>a.id),r=[];return t.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=wl(u,ir,kl)+Ii,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:rr,y:c},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,style:{width:_l,height:ir}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:rr,y:c},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,style:{width:_l,height:ir}})})}),r}const W1={[H.Division]:"Div",[H.Modal]:"Modal",[H.Tabs]:"Tabs"},j1=Ho;function R1(t){return t.current.map((n,r)=>{const a=V1(n.panelIDs.length,ir,kl)+Ii+Cl;let o=[];return n.type===H.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:`${W1[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,className:"light",style:{backgroundColor:j1[n.type],width:Ei,height:a}}})}function Y1(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==H.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function Q1(t){const e=R1(t.views);Y1(e);const n=G1(t.views,t.panels.list);return[...e,...n]}function K1({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==H.Tabs||(r.sourcePosition=Ee.Position.Bottom,r.style.width=Ei+rr*2,r.style.height=Cl+r._tab_view_ids.reduce((a,o)=>{const l=t[o];l.position.y=a,l.position.x=rr;const u=l.style.height;return a+u+20},Ii))})}function U1({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=t[r.source],o=t[r.target];if(!a||!o||!a.parentNode)return;const l=t[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),e.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function X1({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=t[a.source],l=t[a.target];if(o&&l&&o.parentNode){const u=t[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+F1,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Ee.Position.Left,l.targetPosition=Ee.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+Sl}})}function J1({nodeMap:t,nodes:e,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=wl(u,Ei,q1),l.position.y=0-N1-Sl})}function Z1({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return J1(r),U1(r),K1(r),X1(r),{nodes:e,edges:n}}function H1(t){const e=Q1(t),n=x.keyBy(e,c=>c.id),{edges:r,edgeNodes:a}=B1(t,n),o=[...e,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return Z1(u)}const wD="",Ai={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleOff,{size:14})})};function eS(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Ai[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ai[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ai[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),e}const tS=y.memo(({data:t,isConnectable:e,sourcePosition:n=Ee.Position.Right,targetPosition:r=Ee.Position.Left,...a})=>{const o=y.useMemo(()=>eS(t.interactions),[t.interactions]);return p(V,{children:[i(Ee.Handle,{type:"target",position:r,isConnectable:e}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(D.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:t.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Ee.Handle,{type:"source",position:n,isConnectable:e})]})}),CD="",nS={interaction:tS},rS=k.observer(()=>{const t=K(),{edges:e,nodes:n}=H1(t);return p(Ee,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:nS,children:[i(Ee.MiniMap,{}),i(Ee.Controls,{}),i(Ee.Background,{})]})}),iS=k.observer(({opened:t,close:e})=>{const{freezeLayout:n}=y.useContext(ft);return y.useEffect(()=>{n(t)},[t]),i(s.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(rS,{})})}),aS={"> 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 sS({onClick:t,name:e,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:i(s.Text,{size:"sm",children:e})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(L.IconAdjustments,{size:16})})})]})}const oS=k.observer(()=>{const t=he(),e=K(),n=y.useCallback(a=>()=>e.views.setIDOfVIE(a),[e]),r=a=>{t.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[e.views.options.map(a=>i(sS,{active:e.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),lS=k.observer(()=>{const t=he(),e=K(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...aS,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(L.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(L.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(L.IconLink,{size:18})})})]}),i(iS,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(oS,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(L.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),uS=k.observer(function({config:e}){return p(V,{children:[i(s.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(ai,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),cS=[{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"}],dS=k.observer(function({config:e}){return p(V,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:cS,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),i(ul,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),zi=k.observer(({value:t,onChange:e})=>{const n=K(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),pS=`
480
+ `}},show_in_legend:!0}))}function w0(t,e,n,r){const a=q(e.data_key),o=e.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function C0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[m0(t,n,r),b0(t,n,r,l),...x0(t,n,r,l),w0(t,e,n,r)]}function S0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:js(n.formatter)},axisLine:{show:!1}}]}function _0(t){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:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function gi(t){return t==1||t==2?1:gi(t-2)+gi(t-1)}const k0=Array.from(new Array(20),(t,e)=>gi(e+1));function Go(t){return t<=1?t:k0.findIndex(e=>t<=e)-1}function T0(t,e){const{x_axis:n,deviation:r}=t,a=q(n.data_key),o=q(r.data_keys.estimated_value),l=q(r.data_keys.actual_value);return e[a.queryID].map(u=>{const c=Go(u[o.columnKey]),d=Go(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function D0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function M0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:D0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const I0={tooltip:{trigger:"axis"}};function E0(t,e){const{deviation:n,metrics:r}=t,a=r.find(l=>l.data_key===e);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function A0(t,e,n){const r=T0(t,n),a=q(t.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=E0(t,e),c=C0(t,u,o,l),d={xAxis:S0(t,o),yAxis:_0(u),series:c,grid:g0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:M0(c)};return x.defaultsDeep({},d,I0)}const z0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},$0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:a}=t,o=y.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:e,onChange:l=>n(l.currentTarget.value),styles:z0})]})},L0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function O0(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:L0,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function P0(t){return p(s.Group,{position:"apart",children:[i(O0,{}),i($0,{...t})]})}le.use([pe.BarChart,pe.LineChart,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.VisualMapComponent]);function B0({conf:t,data:e,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>A0(t,a,e),[t,e,a]);return i(Ne,{echarts:le,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function V0({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,fi),[e]),r=t.data,{width:a,height:o}=t.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=y.useState(d);if(y.useEffect(()=>{h(w=>w||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(a,300),m=Math.max(o,370);return p(s.Box,{sx:{overflow:"hidden",height:m,width:g},children:[i(P0,{conf:n,metricKey:f,setMetricKey:h}),i(B0,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function N0({control:t,watch:e}){return e(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:t,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:n})=>i(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>i(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const q0=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),F0=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(q0,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function G0({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Qs,{...n})})]})]})}function W0({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,fi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(G0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(N0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(F0,{control:a,watch:l})})]})]})})}function j0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class R0 extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:j0(a,r)}})}}const Y0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new R0,name:"mericoEstimationChart",viewRender:V0,configRender:W0,createConfig:()=>({version:2,config:fi})},mi={styles:{justify:"space-around",align:"start"},metrics:[]};function Q0(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:$e}}function K0({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},n,mi),[n]),o=t.data,l=y.useMemo(()=>Is(o,r),[r,o]),{width:u,height:c}=t.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.value}),i(s.Text,{size:"24px",color:"#000000",sx:{lineHeight:1},children:ee(l[d.data_keys.value]).format(d.formatter)})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.basis}),i(s.Text,{size:"12px",color:"#000000",sx:{lineHeight:1},children:ee(l[d.data_keys.basis]).format(d.formatter)})]})]},d.id))})}function U0({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.names.value`,control:t,render:({field:a})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${e}.data_keys.value`,control:t,render:({field:a})=>i(s.Select,{label:"Metric Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.names.basis`,control:t,render:({field:a})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${e}.data_keys.basis`,control:t,render:({field:a})=>i(s.Select,{label:"Basis Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${e}.formatter`,control:t,render:({field:a})=>i(Re,{...a})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(D.Trash,{size:16})})]},e)}function X0({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"metrics"}),l=e("metrics"),u=r.map((w,C)=>({...w,...l[C]})),c=()=>{a(Q0())},d=y.useMemo(()=>n.map(w=>({label:w.name,value:w.name})),[n]),f=x.get(u,"0.id",null),[h,g]=y.useState(f);y.useEffect(()=>{g(w=>w||f)},[f]);const m=w=>{o(w);const C=x.get(u,"0.id",null);g(C)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((w,C)=>i(s.Tabs.Tab,{value:w.id,children:w.names.value?w.names.value:C+1},C)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),u.map((w,C)=>i(s.Tabs.Panel,{value:w.id,children:i(U0,{control:t,index:C,remove:m,variableOptions:d})},C))]})]})}const J0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],Z0=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function H0({control:t,watch:e}){return e("styles"),p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:t,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:J0,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Z0,sx:{flex:1},...n})})]})]})}function ew({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,mi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),i(H0,{control:o,watch:u}),i(X0,{control:o,watch:u,variables:r})]})})}class tw extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config}))}}const nw={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new tw,name:"merico-stats",viewRender:K0,configRender:ew,createConfig:()=>({version:1,config:mi})},rw=[{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(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),iw=[tc,nc,ac,ic,rc,sc],Wo=()=>({id:"dashboard",version:vs,manifest:{viz:[wi,mv,Rv,Qy,Vv,vg,f0,yc,Od,jh,Df,Mx,sg,wh,iv,Bg,pm,Hv,Y0,nw,Ud],color:[...rw,...iw]}}),sn=new cc,Ce={pluginManager:ot("pluginManager"),vizManager:ot("vizManager"),colorManager:ot("colorManager"),instanceScope:{panelModel:ot("panelModel"),vizInstance:ot("vizInstance"),interactionManager:ot("interactionManager"),migrator:ot("migrator"),operationManager:ot("operationManager"),triggerManager:ot("triggerManager")}},yi=()=>{try{sn.install(Wo())}catch{}const t=new Zu(sn),e=new uc(sn);return{pluginManager:sn,vizManager:t,colorManager:e}},at=y.createContext(yi());try{sn.install(Wo())}catch{}function aw(t,e){const{value:n,set:r}=W(t.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,e)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,e))},[n]),{config:a,setConfig:o,commit:l}}function sw(t){const{config:e,setConfig:n,commit:r}=aw(t,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...e,openInNewTab:u}),await r()}const l=u=>n({...e,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function ow(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class lw extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const uw={displayName:"Open Link",id:"builtin:op:open-link",configRender:sw,run:ow,migrator:new lw,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function cw(t){const{value:e,set:n}=W(t.operationData,"config"),r=a=>void n({template:a});return[(e==null?void 0:e.template)||"",r]}function dw(t){const[e,n]=cw(t.operation);return i(s.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function pw(t,e){const n=await e.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const hw={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:dw,run:pw},fw=k.observer(t=>{const e=K(),{value:n,set:r}=W(t.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:e.views.options})});async function gw(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const mw={displayName:"Open View",id:"builtin:op:open_view",configRender:fw,run:gw},yw={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},bw=({value:t="",onChange:e})=>{const[n,r]=y.useState(t);y.useEffect(()=>{r(t)},[t]);const a=()=>{e(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===t,children:i(L.IconDeviceFloppy,{})})})},vw={dictionary:{}},xw=k.observer(t=>{const e=K(),{value:n=vw,set:r}=W(t.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...e.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:yw,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...e.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(bw,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function ww(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const Cw={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:xw,run:ww},Sw={filter_keys:[]},_w=k.observer(t=>{const e=K(),{value:n=Sw,set:r}=W(t.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=y.useMemo(()=>e.filters.current.map(u=>({label:u.label,value:u.key})),[e.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function kw(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const Jn=[hw,uw,mw,Cw,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:_w,run:kw}];class Tw{constructor(e,n=Jn){N(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Lt(a,"data")}};this.attachments=new xr(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(e,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(e);return!a||a.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}class bi{constructor(e,n,r){N(this,"operationManager");N(this,"triggerManager");N(this,"attachments");this.operationManager=new Tw(e,r),this.triggerManager=new qc(e,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new xr(e,"__INTERACTIONS",a)}async addInteraction(e,n){const r=e.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(e){const n=await this.attachments.getInstance(e);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===e);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const tt=({vizManager:t,instance:e})=>X.useCreation(()=>new bi(e,t.resolveComponent(e.type),Jn),[e,t]),jo={left:"flex-start",center:"center",right:"flex-end"},Dw=({header:t,cx:e})=>{const n=x.get(t.column.columnDef.meta,"align","left");return p(s.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:jo[n]},children:[t.isPlaceholder?null:Xe.flexRender(t.column.columnDef.header,t.getContext()),i(Mw,{direction:t.column.getIsSorted()})]})},Mw=({direction:t})=>{switch(t){case"asc":return i(L.IconArrowUp,{size:16});case"desc":return i(L.IconArrowDown,{size:"1em"});default:return null}},vi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:zw,configRender:Ew,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"}]},Iw={column:""};function Ro(t,e){const{value:n}=W(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const a=xn(e,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function Ew(t){const{columnsFromConfig:e,columnsFromData:n}=Ro(t.instance,t.sampleData),r=e.length>0?e:n,{value:a,set:o}=W(t.trigger.triggerData,"config"),{column:l}=x.defaults({},a,Iw),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Aw(t,e){return t?x.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function zw(t){const{columnsFromConfig:e}=Ro(t.instance),{value:n}=W(t.trigger.triggerData,"config");return i(s.Text,{children:Aw(n,e)})}const $w=s.createStyles(t=>({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:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Lw={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}};function Yo(t,e,n){return Math.min(Math.max(t,e),n)}class Ow{constructor(e){this.steps=e;const n=[],r=new Set;for(const a of e)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(e,n){const r=(n.to-e.to)/(n.from-e.from),a=e.to-r*e.from;return o=>r*o+a}getStepFunctionForValue(e){let n=x.findLastIndex(this.steps,r=>r.from<=e);return n=Yo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return Yo(this.getStepFunctionForValue(e)(e),0,100)}}class Pw{constructor(e,n,r,a,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.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 r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===vi.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(x.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new Ow(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Bw=s.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:jo[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function Vw(t){return t?st(t).oklch()[0]>.7?"black":"white":"inherit"}function Nw(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:Vw(e)}}function qt(t){const e=t.tableCellContext.isClickable(),n=Bw({clickable:e,align:t.align});return i("div",{className:n.classes.content,style:{...Nw(t)},children:i(s.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:i("span",{title:t.children,children:t.children})})})}function qw(t){return i(qt,{...t,children:t.value})}function Fw(t){const e=ee(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(qt,{...t,children:e})}function Gw(t){const e=ee(t.value).format({thousandSeparated:!0});return i(qt,{...t,children:e})}function Ww(t){const e=ee(t.value).format({output:"percent",mantissa:3});return i(qt,{...t,children:e})}function jw(t){const e=t.value,n=t.func_content;if(!n)return i(qt,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return i(qt,{...t,children:r})}function Rw(t){switch(t.type){case Je.string:return i(qw,{...t});case Je.eloc:return i(Fw,{...t});case Je.number:return i(Gw,{...t});case Je.percentage:return i(Ww,{...t});case Je.custom:return i(jw,{...t})}}const Yw=t=>{const e=tt(t),n=He(e.triggerManager,vi.id),{colorManager:r}=y.useContext(at);return y.useCallback(a=>new Pw(t.getColIndex,a,n,e,r),[n,e,t.getColIndex])};function Qw({context:t,instance:e}){var be,De;const n=t.data,{height:r,width:a}=t.viewport,{value:o=vr}=W(t.instanceData,"config"),{id_field:l,use_raw_columns:u,columns:c,...d}=o,{classes:f,cx:h}=$w(),g=y.useMemo(()=>{if(!l)return[];const ge=q(l);return n[ge.queryID]},[n,l]),m=y.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(ge=>({id:ge,label:ge,value_field:ge,value_type:Je.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,g]),w=Yw({getColIndex:y.useCallback(ge=>m.indexOf(ge.column.columnDef.meta),[m]),vizManager:t.vizManager,instance:e}),C=y.useMemo(()=>{const ge=Xe.createColumnHelper();return m.map(me=>{const Oe=q(me.value_field);return ge.accessor(Oe.columnKey,{cell:Qe=>i(Rw,{tableCellContext:w(Qe.cell),value:Qe.getValue(),type:me.value_type,...me}),header:me.label,enableSorting:!0,meta:me,size:typeof me.width=="number"?me.width:void 0,minSize:typeof me.width=="number"?me.width:void 0})})},[m,w]),[_,T]=y.useState([]),I=Xe.useReactTable({data:g,state:{sorting:_},onSortingChange:T,columns:C,getCoreRowModel:Xe.getCoreRowModel(),getSortedRowModel:Xe.getSortedRowModel()}),{rows:O}=I.getRowModel(),B=y.useRef(null),$=eu.useVirtual({parentRef:B,size:O.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:A,totalSize:E}=$,F=A.length>0&&((be=A==null?void 0:A[0])==null?void 0:be.start)||0,U=A.length>0?E-(((De=A==null?void 0:A[A.length-1])==null?void 0:De.end)||0):0,Y=O.length,Z=Y>0,oe=Z?r-22:r,ue=Z?22:0;return l?!Array.isArray(g)||g.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:B,style:{height:r,width:a},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[Y>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",Y]})}),p(s.Table,{sx:{...Lw,maxHeight:oe},...d,striped:o.striped,children:[i("thead",{className:f.thead,style:{top:ue},children:I.getHeaderGroups().map(ge=>i("tr",{children:ge.headers.map(xe=>i("th",{style:{width:xe.getSize()},children:i(Dw,{header:xe,cx:h})},xe.id))},ge.id))}),p("tbody",{children:[F>0&&i("tr",{children:i("td",{style:{height:`${F}px`}})}),A.map(ge=>{const xe=O[ge.index];return i("tr",{children:xe.getVisibleCells().map(me=>i("td",{children:Xe.flexRender(me.column.columnDef.cell,me.getContext())},me.id))},xe.id)}),U>0&&i("tr",{children:i("td",{style:{height:`${U}px`}})})]})]})]}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"})}const Qo=s.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)"}}}})),Kw=[{from:0,to:0},{from:100,to:100}];class Uw{constructor(){N(this,"steps",new Map);N(this,"interpolation");N(this,"onChange");ie.makeAutoObservable(this,{steps:ie.observable},{deep:!1}),ie.reaction(()=>ie.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(Kw):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function Xw(t){const{onChange:e,color:n,index:r,value:a}=t,{classes:o}=Qo(),[l,u]=y.useState(a),[c,{setTrue:d,setFalse:f}]=X.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,w=`map ${a} to color ${r}`,C=()=>{u(a),f()},_=()=>{f(),e==null||e(l)},T=ee(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:w,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:T}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":st(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:w,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:T})]})}const Jw=k.observer(({model:t})=>{const{classes:e}=Qo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return i("div",{className:e.palette,children:n.map(([r,a],o)=>i(Xw,{index:o,color:r,value:t.getStepFromValue(a),onChange:l=>t.changeStep(l,a)},r))})}),Zw=k.observer(function(e){const n=X.useCreation(()=>new Uw,[]);return y.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:i(Jw,{model:n})}),Hw=t=>{const{value:e,onChange:n,colorManager:r}=t,a=r.getColorInterpolations(),[o,l]=y.useState(e),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=X.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(ie.toJS(o))};function w(_){l(T=>({...T,steps:_}))}const C=()=>{f(),l(e)};return p(V,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),i(Zw,{steps:o.steps,interpolation:u,onChange:w}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:C,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},eC=["static","interpolation","none"].map(t=>({label:x.capitalize(t),value:t})),tC=[{from:0,to:0},{from:100,to:100}];function Ko(t){return t?x.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function nC(t,e){var n;return Ko(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function rC(t,e){return x.isObject(e)?e:{steps:tC,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const iC=y.forwardRef((t,e)=>{const{colorManager:n}=y.useContext(at),[r,a]=y.useState(Ko(t.value)),[o,l]=y.useState(nC(n,t.value)),u=X.useLatest(o),[c,d]=y.useState(rC(n,t.value)),f=X.useLatest(c),h=w=>{var C,_,T;a(w||"none"),w==="static"?(C=t.onChange)==null||C.call(t,u.current):w==="none"||!w?(_=t.onChange)==null||_.call(t,"none"):(T=t.onChange)==null||T.call(t,f.current)},g=w=>{var C;l(w),(C=t.onChange)==null||C.call(t,w)},m=w=>{var C;d(w),(C=t.onChange)==null||C.call(t,w)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:eC}),r==="static"&&i(Pe,{value:o,onChange:g}),r==="interpolation"&&i(Hw,{colorManager:n,value:c,onChange:m})]})}),aC={[Je.eloc]:"ELOC"},sC=Object.values(Je).map(t=>({label:x.get(aC,t,x.capitalize(t)),value:t})),oC=y.forwardRef(({label:t,value:e,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:t,data:sC,value:e,onChange:n,sx:r})),lC=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(gs)};return y.useEffect(()=>{u(t)},[t]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),uC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],xi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),cC=({control:t,index:e,watch:n,remove:r,column:a})=>{const o=n(`columns.${e}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.label`,control:t,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${e}.value_field`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.value_type`,control:t,render:({field:l})=>i(oC,{label:"Value Type",sx:{flex:1},...l})}),o===Je.custom&&i(v.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>i(lC,{value:l.value??gs,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(xi,{}),disabled:!0}),i(v.Controller,{name:`columns.${e}.width`,control:t,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(xi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(xi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${e}.align`,control:t,render:({field:l})=>i(s.Select,{label:"Alignment",data:uC,...l})})}),i(v.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>i(iC,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(e),children:"Delete this column"})]})},dC=({control:t,watch:e})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:t,name:"columns"}),l=()=>{const c=Me.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:Je.string,width:""})};e("columns");const u=e("use_raw_columns");return p(V,{children:[i(v.Controller,{name:"use_raw_columns",control:t,render:({field:c})=>i(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&i(s.Stack,{children:p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(cC,{control:t,watch:e,index:d,column:c,remove:a},d)},c.id))]})})]})};function pC({control:t,watch:e}){return e(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:t,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:t,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:t,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function hC({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??Me.randomId(),...r}))}}function fC({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,vr),[e]),a=y.useMemo(()=>hC(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Columns",children:"Columns"}),i(s.Tabs.Tab,{value:"Style",children:"Style"})]}),p(s.Tabs.Panel,{value:"Columns",children:[i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(j,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(dC,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(pC,{control:o,watch:u})})]})]})}function gC(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function mC(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=t;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function yC(t){const{columns:e,...n}=t;return{...n,columns:e.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class bC extends ve{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??Me.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:gC(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:mC(n.config,r)})),this.version(5,n=>({...n,version:5,config:yC(n.config)}))}}const wi={createConfig(){return{version:5,config:x.cloneDeep(vr)}},displayName:"Table",displayGroup:"Others",migrator:new bC,name:"table",viewRender:Qw,configRender:fC,triggers:[vi]},vC=b.types.model("PanelLayoutModel",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{x:e,y:n,w:r,h:a,moved:o}=t;return{h:a,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:a,h:o,moved:l}=e;t.x=n,t.y=r,t.w=a,t.h=o,t.moved=!!l,t.static=!!e.static}})),xC=b.types.model("PanelStyleBorderModel",{enabled:b.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),wC=b.types.model("PanelStyleModel",{border:xC}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),CC=b.types.model("PanelVizModel",{type:b.types.string,conf:b.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),Uo=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:vC,queryIDs:b.types.array(b.types.string),viz:CC,style:wC,variables:b.types.optional(b.types.array(Qu),[])}).views(t=>({get contentModel(){return b.getParentOfType(t,Zn)}})).views(t=>({get queryIDSet(){return new Set(t.queryIDs)},get queries(){return t.contentModel.queries.findByIDSet(this.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data.toJSON(),e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){return this.queries.map(e=>e.stateMessage).filter(e=>!!e)},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:e,title:n,description:r,queryIDs:a}=t;return{id:e,viz:t.viz.json,style:t.style.json,title:n,layout:t.layout.json,queryIDs:[...a],variables:t.variables.map(o=>o.json),description:r}},get dataFieldOptions(){return t.queryIDs.length===0?[]:this.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${e.id}.${a}`,group:e.name}))}).flat()}})).actions(t=>({setID(e){t.id=e},setTitle(e){t.title=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=b.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=b.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)},removeSelf(){b.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){b.getRoot(t).content.views.findByID(e).removePanelID(t.id),b.getRoot(t).content.views.findByID(n).appendPanelID(t.id),b.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])},refreshData(){t.queries.forEach(e=>e.fetchData())},downloadData(){b.getRoot(t).content.queries.downloadDataByQueryIDs(t.queryIDs)}}));function Xo(t){return{id:t,layout:{x:0,y:1/0,w:18,h:300},title:t,description:"<p></p>",queryIDs:[],viz:{type:wi.name,conf:wi.createConfig()},style:{border:{enabled:!0}}}}const Jo=b.types.model("PanelsModel",{list:b.types.optional(b.types.array(Uo),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(a=>{const o=t.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),a}})).actions(t=>({replace(e){t.list=b.castToSnapshot(e)},append(e){t.list.push(e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},duplicateByID(e){const n=t.list.find(a=>a.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}}));var Zo=(t=>(t.Use="use",t.Edit="edit",t))(Zo||{}),H=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(H||{});const SC={div:"Division",tabs:"Tabs",modal:"Modal"},Ho={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},_C={div:"#ff4000",modal:"#000",tabs:"#ffad18"},kC={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var Ci=(t=>(t.Select="select",t.TreeSelect="tree-select",t.MultiSelect="multi-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ci||{});const el=b.types.model("ViewModel_Division",{_name:b.types.literal(H.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})).actions(t=>({})),TC=()=>el.create({_name:H.Division}),Si={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
481
+ `)},DC=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=b.getParent(t,2),a=b.getRoot(t);if(!e)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),tl=b.types.model("ViewModel_Modal",{_name:b.types.literal(H.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(DC,Si)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:a}=t;return{_name:e,width:n,height:r,custom_modal_title:a.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),MC=()=>tl.create({_name:H.Modal,width:"90vw",height:"90vh"}),IC=b.types.model("ViewModel_Tabs_Tab",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{id:e,name:n,view_id:r,color:a}=t;return{id:e,name:n,color:a,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),nl=b.types.model("ViewModel_Tabs",{_name:b.types.literal(H.Modal),tabs:b.types.optional(b.types.array(IC),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:a,grow:o}=t;return{grow:o,tabs:a.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=b.cast(e)},addTab(){const e=Me.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),EC=()=>nl.create({_name:H.Modal,tabs:[]}),rl=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[H.Division,H.Modal,H.Tabs]),config:b.types.union(el,tl,nl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:a}=t;return{id:e,name:n,type:r,config:a.json,panelIDs:t.panelIDs}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case H.Division:t.config=TC();break;case H.Modal:t.config=MC();break;case H.Tabs:t.config=EC();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})).actions(t=>({})),il=b.types.model("ViewsModel",{current:b.types.optional(b.types.array(rl),[]),visibleViewIDs:b.types.array(b.types.string),idOfVIE:b.types.string}).views(t=>({get json(){return t.current.map(e=>yn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=b.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({replace(e){t.current.replace(e)},addANewView(e,n,r,a){t.current.push({id:e,name:n,type:r,config:a,panelIDs:[]})},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n!==-1&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)}})).actions(t=>({addARandomNewView(){const e=new Date().getTime().toString();t.addANewView(e,H.Division,H.Division,{_name:H.Division}),t.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(t.removeByID(t.idOfVIE),t.setIDOfVIE(t.current[0].id))},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function _i(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}function al(t,e,n,r){return t.reduce((a,o)=>(a[o[e]]=pr(o[n],r),a),{})}const AC=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:is,queries:ds,sqlSnippets:hs,views:il,panels:Jo,mock_context:Yu,origin:b.types.maybe(b.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get filtersChanged(){const e="filters.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=b.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get payloadForSQL(){const e=b.getParent(t).context.current,n=b.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:al(t.sqlSnippets.current,"key","value",r),global_sql_snippets:al(n.list,"id","content",r)}},get payloadForViz(){const e=b.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);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(t=>({findQueryUsage(e){const n=t.panels.idMap,r=t.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(e))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=t.views.idMap,o=t.filters.current.filter(l=>x.get(l,"config.options_query_id")===e).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(t=>({duplicatePanelByID(e,n){var a;const r=t.panels.duplicateByID(e);r&&((a=t.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=new Date().getTime().toString();t.panels.append(Xo(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)}})).actions(t=>({reset(){b.applySnapshot(t.filters.current,t.origin.filters.current),b.applySnapshot(t.queries.current,t.origin.queries.current),b.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),b.applySnapshot(t.views.current,t.origin.views.current),b.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){b.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:a}=e;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;t.id=n,t.name=r,t.version=o,b.applySnapshot(t.filters.current,l),b.applySnapshot(t.views.current,_i(u).current),b.applySnapshot(t.panels.list,c),b.applySnapshot(t.queries.current,d),b.applySnapshot(t.sqlSnippets.current,f),t.mock_context.current=h}})),Zn=b.types.snapshotProcessor(AC,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=b.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function zC(t,e){e.filters&&b.applySnapshot(t.filters.current,e.filters)}function sl({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Zn.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,version:l,filters:as(u),queries:{current:f},sqlSnippets:{current:h},mock_context:{current:g},views:_i(c),panels:{list:d}})}const $C=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),LC=b.types.model("GlobalSQLSnippetsModel",{list:b.types.optional(b.types.array($C),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),ol=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Zn,content_id:b.types.string,datasources:Wu,globalSQLSnippets:LC,context:fs,editor:Ru}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:a,group:o,content_id:l}=e;t.id=r,t.name=a,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function ki({id:t,name:e,group:n,content_id:r},a,o,l,u){return ol.create({id:t,name:e,group:n,content_id:r,content:sl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:u},editor:{}})}const Ti=y.createContext(null);function Hn(t){const e=y.useContext(Ti),n=X.useCreation(()=>t.configure(e||new wr),[t.configure]),r=X.usePrevious(n);return r&&r!==n&&r.dispose(),i(Ti.Provider,{value:n,children:t.children})}function ll(){return y.useContext(Ti)}const OC={viewPanelInFullScreen:x.noop,inFullScreen:!1},Di=y.createContext(OC),PC=({description:t,isDescriptionEmpty:e})=>e?null:i(s.Tooltip,{color:"white",label:i(Kn,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(L.IconInfoCircle,{size:16,color:"gray"})})}),BC=k.observer(({label:t,config:{default_value:e,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:t}),i(PC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),ul=k.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=e,l=Array.isArray(n)?n.map(f=>f?R(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&R(h).format(a)))},c=e.getMinDate(l[0]),d=e.getMaxDate(l[0]);return i(ru.DatePickerInput,{type:"range",label:t,value:l,onChange:u,icon:i(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),VC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),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:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.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}}}})),cl=({errorMessage:t})=>t?i(s.Text,{color:"red",size:12,children:t}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),NC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f})=>{const{classes:h,cx:g}=VC({radius:a},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[m,w]=y.useState(!1),C=B=>{w(B)},_=m&&(u==null?void 0:u.length)>0,[T,I]=y.useState(""),O=y.useMemo(()=>{if(!T)return d;const B=T.toLowerCase(),$=A=>{var E;return((E=A.description)==null?void 0:E.toLowerCase().includes(B))||A.label.toLowerCase().includes(B)};return d.filter($)},[T,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(qa,{disabled:t,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:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(cl,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:B=>`${B.length} selected`,searchValue:T,onSearch:I,filterOption:!1,children:O.map(B=>i(qa.Option,{children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:B.label}),B.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:B.description})]})})},B.value))})]})},qC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading",d=e.min_width?e.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(NC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),FC=y.forwardRef(({label:t,description:e,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:t}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),GC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading";return y.useEffect(()=>{var h;const{default_selection_count:d}=e;if(!d)return;const f=((h=e.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),r(f,!0)},[e.default_selection_count,e.options]),i(s.Select,{label:t,data:e.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:FC})});function WC({label:t,config:e,value:n,onChange:r}){return i(s.TextInput,{label:t,value:n||"",onChange:a=>r(a.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const jC=({rotate:t,onClick:e})=>i("svg",{onClick:e,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(${t})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),RC=({expanded:t,isLeaf:e,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),e?i("span",{style:{width:"14px",display:"inline-block"}}):i(jC,{rotate:t?"0":"-90",onClick:r,...a})),YC=({onClick:t})=>p("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),QC=({onClick:t,...e})=>i(YC,{onClick:t,...e}),KC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),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:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.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"}}}})),UC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f})=>{const{classes:h,cx:g}=KC({radius:a},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[m,w]=y.useState(!1),C=T=>{w(T)},_=m&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Fa,{disabled:t,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:()=>i(s.CloseButton,{}),switcherIcon:RC,treeIcon:QC,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(cl,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Fa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:T=>`${T.length} selected`})]})},XC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=e,u=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return i(UC,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:t})}),JC=k.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:a})=>{switch(t){case"select":return i(GC,{...r,...a,config:e});case"multi-select":return i(qC,{...r,...a,config:e});case"tree-select":return i(XC,{...r,...a,config:e});case"text-input":return i(WC,{...r,...a,config:e});case"date-range":return i(ul,{...r,...a,config:e});case"checkbox":return i(BC,{...r,...a,config:e});default:return null}}),dl=k.observer(y.forwardRef(({filter:t,...e},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(JC,{filter:t,formFieldProps:e})})}))),pl=k.observer(function({view:e}){const n=K(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),y.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const u=n.filters.visibleInView(e.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(w,C)=>{m(w),(g.should_auto_submit||C)&&n.filters.setValueByKey(g.key,w)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(dl,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),mD="";function ZC(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const hl=k.observer(()=>{const{freezeLayout:t}=y.useContext(ft),[e,n]=y.useState(!1),{panel:r}=ze();return y.useEffect(()=>{t(e)},[e]),ZC(r.description)?null:p(V,{children:[i(s.Modal,{opened:e,onClose:()=>n(!1),title:r.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Kn,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(a=>!a),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(D.InfoCircle,{size:20})})})]})}),HC=k.observer(({view:t})=>{const e=he(),n=K(),r=Ue.useModals(),{panel:a}=ze(),{id:o}=a,{inEditMode:l}=y.useContext(ft),{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(Di),d=()=>{n.duplicatePanelByID(o,t.id)},f=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",o])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,t.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(o)},[o,u]),m=!c&&t.type!==H.Modal;return i(V,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),m&&i(s.Menu.Item,{onClick:g,icon:i(D.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(V,{children:[i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(D.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(D.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(D.Trash,{size:14}),children:"Delete"})]})]})]})})})}),e1=k.observer(({panel:t})=>p(s.Stack,{children:[t.queryErrors.map((e,n)=>i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),t.queryStateMessages.map((e,n)=>i(s.Text,{color:"gray",align:"center",children:e},`${n}-${e}`))]}));var fl=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(fl||{}),er=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(er||{});class t1{constructor(e){N(this,"vizInstance");N(this,"operationManager");N(this,"triggerManager");N(this,"vizManager");N(this,"runningMigration");N(this,"panelModel");N(this,"status","notStarted");this.panelModel=e.getRequired(Ce.instanceScope.panelModel),this.vizInstance=e.getRequired(Ce.instanceScope.vizInstance),this.operationManager=e.getRequired(Ce.instanceScope.operationManager),this.triggerManager=e.getRequired(Ce.instanceScope.triggerManager),this.vizManager=e.getRequired(Ce.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.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(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function gl(t){const{panel:e}=ze();return y.useCallback(n=>{const r=n.getRequired(Ce.vizManager),a=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(Ce.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(Ce.instanceScope.interactionManager,o=>{const l=o.getRequired(Ce.instanceScope.vizInstance);return new bi(l,a,Jn)}).provideFactory(Ce.instanceScope.operationManager,o=>o.getRequired(Ce.instanceScope.interactionManager).operationManager).provideFactory(Ce.instanceScope.triggerManager,o=>o.getRequired(Ce.instanceScope.interactionManager).triggerManager).provideValue(Ce.instanceScope.panelModel,e).provideFactory(Ce.instanceScope.migrator,o=>new t1(o))},[t.viz.type,t.viz.conf])}function ml(t){const[e,n]=y.useState(!1),r=ll().getRequired(Ce.instanceScope.migrator);return X.useAsyncEffect(async()=>{const a=r.status===er.notStarted;n(r.status===er.done),r.status===er.notStarted&&r.runMigration().then(o=>{o===fl.migrated&&a&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function yl(t,e){const n=ll().getRequired(Ce.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function n1({setVizConf:t,...e}){const{panel:n}=e,r=yl(t,n),a=ml(()=>{hn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return X.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(ec,{...e}):i(s.Text,{children:"Checking update..."})}function r1(t){const{panel:e,setVizConf:n}=t;yl(n,e);const{inEditMode:r}=y.useContext(ft);return ml(()=>{r&&hn.showNotification({title:`${e.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Hu,{...t}):i(s.Text,{children:"Checking update"})}const yD="";function i1(t,e){const{vizManager:n}=y.useContext(at),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=ze(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:e},f=gl(d);try{return n.resolveComponent(r.type),i(Hn,{configure:f,children:i(r1,{setVizConf:r.setConf,panel:d,data:t,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const a1=k.observer(function({data:e}){const{ref:n,width:r,height:a}=Me.useElementSize(),o=i1(e,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:l&&i(Fe,{children:o})})}),bl=k.observer(({panel:t,height:e})=>p(s.Flex,{direction:"column",sx:{height:e,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&i(e1,{panel:t}),t.canRenderViz&&i(a1,{data:t.data})]})),bD="",s1=k.observer(function(){const{panel:e}=ze(),{title:n}=e;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function o1(t){return!["richText","button"].includes(t)}const l1={border:"1px solid #e9ecef"},u1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function c1(t,e){return t.style.border.enabled?l1:e?u1:{border:"1px dashed transparent"}}const tr=k.observer(function({panel:e,view:n}){const{inEditMode:r}=y.useContext(ft),a=e.title?"calc(100% - 25px - 5px)":"100%",o=c1(e,r),u=o1(e.viz.type)||r;return i(Sr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors},children:p(s.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(hl,{})}),u&&i(HC,{view:n}),i(s1,{}),i(bl,{panel:e,height:a})]})})}),vD="",d1=y.forwardRef(({h:t},e)=>i(s.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(D.ArrowsMove,{size:16})})),p1=y.forwardRef(({handleAxis:t,...e},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...e,children:i(D.ChevronDownRight,{size:16})})),h1=fn.WidthProvider(fn),f1=k.observer(({view:t,className:e="layout"})=>{const n=K(),{panels:r,layouts:a}=n.panels.panelsByIDs(t.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(h1,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(p1,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(d1,{h:u.layout.h}),i(tr,{view:t,panel:u})]},u.id))})}),g1=fn.WidthProvider(fn),m1=k.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:a}=K().panels.panelsByIDs(e.panelIDs);return i(g1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(tr,{view:e,panel:o})},o.id))})}),y1=k.observer(({children:t})=>i(s.Box,{pt:10,pb:100,children:t}));function vl(t){return t.replace(/(vw|vh)/,"%")}const b1=k.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:a}=y.useMemo(()=>({width:vl(n.width),height:vl(n.height)}),[n.width,n.height]);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:o=>{o.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",width:r,height:a},content:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionProps:{duration:0},children:t})})}),v1=({variant:t,orientation:e})=>{const n={tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},x1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},w1=k.observer(({children:t,view:e})=>{const n=Ue.useModals(),r=K(),a=y.useMemo(()=>r.views.options.filter(c=>c.type===H.Division),[e.id,r.views.options]),o=e.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 p(s.Box,{className:"preview-view-tabs",children:[p(s.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:v1(o),children:[p(s.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>i(s.Tabs.Tab,{value:c.id,sx:x1(c),children:c.name??c.id},c.id)),i(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:i(D.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,d)=>{const f=r.views.findByID(c.view_id);return p(s.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),i(s.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:a}),i(s.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:u,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&i(nr,{view:f})]},c.id)})]}),t]})}),C1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(b1,{view:t,children:e});case H.Tabs:return i(w1,{view:t,children:e});case H.Division:default:return i(y1,{children:e})}}),xl=k.observer(function({view:e}){return i(Di.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(C1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(pl,{view:e})}),i(f1,{view:e})]})})})})}),S1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},_1=k.observer(function({view:e,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:S1,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(tr,{view:e,panel:n})})})});function k1(t,e,n){const{panels:r}=K(),a=t.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(e)?e:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const T1=k.observer(({children:t})=>i(s.Box,{children:t})),D1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config,a=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{content:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionProps:{duration:0},children:t})}),M1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},I1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config;return p(s.Box,{className:"render-view-tabs",children:[p(s.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:r.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:r.grow,children:r.tabs.map(a=>i(s.Tabs.Tab,{value:a.id,sx:M1(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabs.map(a=>{const o=n.views.findByID(a.view_id);return o?i(s.Tabs.Panel,{value:a.id,children:i(nr,{view:o})},a.id):null})]}),t]})}),E1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(D1,{view:t,children:e});case H.Tabs:return i(I1,{view:t,children:e});case H.Division:default:return i(T1,{children:e})}}),nr=k.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ws(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=k1(e,n,r);return i(Di.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&i(_1,{view:e,panel:u,exitFullScreen:o}),i(E1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(pl,{view:e})}),!l&&i(m1,{view:e})]})})]})})});function Mi(t){return y.useCallback(e=>e.provideValue(Ce.pluginManager,t.pluginManager).provideValue(Ce.vizManager,t.vizManager).provideValue(Ce.colorManager,t.colorManager),[])}const A1=k.observer(({headerMenuItems:t=null})=>{const e=he(),n=K(),r=()=>{const a=JSON.stringify(n.json,null,2),o=`${e.name}__${n.name}`;Au(o,a)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(L.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(L.IconCode,{size:14}),onClick:r,children:"Download Schema"}),t]})]})}),z1=k.observer(({saveDashboardChanges:t})=>{const e=Ue.useModals(),n=K(),r=()=>{e.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(L.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(L.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(L.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),$1=k.observer(({saveDashboardChanges:t,headerSlot:e=null,headerMenuItems:n})=>{const r=iu.useNavigate(),a=he(),o=()=>{r(`/dashboard/${a.id}`)},l=Ue.useModals(),u=()=>{l.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=a.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:c?"red":"green",leftIcon:i(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:a.name})]})}),i(z1,{saveDashboardChanges:t})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[e,i(A1,{headerMenuItems:n})]})]})})}),L1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},O1=k.observer(()=>{const t=K();return i(s.Box,{sx:L1,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!t.views.VIE,onClick:()=>t.addANewPanel(t.views.idOfVIE),leftIcon:i(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"}),i(s.Box,{}),i(s.Box,{})]})})}),P1=k.observer(t=>p(V,{children:[i($1,{...t}),i(O1,{})]})),xD="",wD="";function B1(t,e,n){const r=[];return t.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=e[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:w}=m;switch(g){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:w.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(w.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:w.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function V1(t,e){const n=t.filters.keyLabelMap;return{edges:B1(t.panels.list,e,n),edgeNodes:[]}}function wl(t,e,n){return t*e+t*n}function N1(t,e,n){return t*e+(t-1)*n}const rr=25,Ii=40,Cl=25,Ei=350,q1=150,F1=150,Sl=150,_l=300,ir=40,kl=25,G1=300;function W1(t,e){const n=x.keyBy(e,a=>a.id),r=[];return t.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=wl(u,ir,kl)+Ii,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:rr,y:c},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,style:{width:_l,height:ir}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:rr,y:c},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,style:{width:_l,height:ir}})})}),r}const j1={[H.Division]:"Div",[H.Modal]:"Modal",[H.Tabs]:"Tabs"},R1=Ho;function Y1(t){return t.current.map((n,r)=>{const a=N1(n.panelIDs.length,ir,kl)+Ii+Cl;let o=[];return n.type===H.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:`${j1[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,className:"light",style:{backgroundColor:R1[n.type],width:Ei,height:a}}})}function Q1(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==H.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function K1(t){const e=Y1(t.views);Q1(e);const n=W1(t.views,t.panels.list);return[...e,...n]}function U1({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==H.Tabs||(r.sourcePosition=Ee.Position.Bottom,r.style.width=Ei+rr*2,r.style.height=Cl+r._tab_view_ids.reduce((a,o)=>{const l=t[o];l.position.y=a,l.position.x=rr;const u=l.style.height;return a+u+20},Ii))})}function X1({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=t[r.source],o=t[r.target];if(!a||!o||!a.parentNode)return;const l=t[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),e.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function J1({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=t[a.source],l=t[a.target];if(o&&l&&o.parentNode){const u=t[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+G1,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Ee.Position.Left,l.targetPosition=Ee.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+Sl}})}function Z1({nodeMap:t,nodes:e,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=wl(u,Ei,F1),l.position.y=0-q1-Sl})}function H1({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return Z1(r),X1(r),U1(r),J1(r),{nodes:e,edges:n}}function eS(t){const e=K1(t),n=x.keyBy(e,c=>c.id),{edges:r,edgeNodes:a}=V1(t,n),o=[...e,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return H1(u)}const CD="",Ai={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleOff,{size:14})})};function tS(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Ai[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ai[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ai[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),e}const nS=y.memo(({data:t,isConnectable:e,sourcePosition:n=Ee.Position.Right,targetPosition:r=Ee.Position.Left,...a})=>{const o=y.useMemo(()=>tS(t.interactions),[t.interactions]);return p(V,{children:[i(Ee.Handle,{type:"target",position:r,isConnectable:e}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(D.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:t.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Ee.Handle,{type:"source",position:n,isConnectable:e})]})}),SD="",rS={interaction:nS},iS=k.observer(()=>{const t=K(),{edges:e,nodes:n}=eS(t);return p(Ee,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:rS,children:[i(Ee.MiniMap,{}),i(Ee.Controls,{}),i(Ee.Background,{})]})}),aS=k.observer(({opened:t,close:e})=>{const{freezeLayout:n}=y.useContext(ft);return y.useEffect(()=>{n(t)},[t]),i(s.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(iS,{})})}),sS={"> 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 oS({onClick:t,name:e,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:i(s.Text,{size:"sm",children:e})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(L.IconAdjustments,{size:16})})})]})}const lS=k.observer(()=>{const t=he(),e=K(),n=y.useCallback(a=>()=>e.views.setIDOfVIE(a),[e]),r=a=>{t.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[e.views.options.map(a=>i(oS,{active:e.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),uS=k.observer(()=>{const t=he(),e=K(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...sS,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(L.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(L.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(L.IconLink,{size:18})})})]}),i(aS,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(lS,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(L.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),cS=k.observer(function({config:e}){return p(V,{children:[i(s.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(ai,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),dS=[{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"}],pS=k.observer(function({config:e}){return p(V,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:dS,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),i(ul,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),zi=k.observer(({value:t,onChange:e})=>{const n=K(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),hS=`
482
482
  // row
483
483
  {
484
484
  label: string;
485
485
  value: string;
486
486
  description?: string; // optional
487
487
  }
488
- `,Tl=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:pS})})]})},hS=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[...r];return p(V,{children:[i(s.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.MultiSelect,{label:"Default Selection",data:a,value:[...e.default_value],onChange:e.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(zi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(Tl,{})]})}),fS=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[{label:"No default selection",value:""},...r];return p(V,{children:[i(s.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:e.width,onChange:o=>e.setWidth(o.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.Select,{label:"Default Selection",data:a,value:e.default_value,onChange:e.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(zi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(Tl,{})]})}),gS=k.observer(function({config:e}){return p(V,{children:[i(s.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),mS=`
488
+ `,Tl=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:hS})})]})},fS=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[...r];return p(V,{children:[i(s.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.MultiSelect,{label:"Default Selection",data:a,value:[...e.default_value],onChange:e.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(zi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(Tl,{})]})}),gS=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[{label:"No default selection",value:""},...r];return p(V,{children:[i(s.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:e.width,onChange:o=>e.setWidth(o.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.Select,{label:"Default Selection",data:a,value:e.default_value,onChange:e.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(zi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(Tl,{})]})}),mS=k.observer(function({config:e}){return p(V,{children:[i(s.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),yS=`
489
489
  // row
490
490
  {
491
491
  label: string;
@@ -493,7 +493,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
493
493
  parent_value: string;
494
494
  description?: string;
495
495
  }
496
- `,yS=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:mS})})]})},bS=k.observer(function({config:e}){return p(V,{children:[i(s.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(zi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(yS,{})]})}),vS=k.observer(function({filter:e}){const[n,r]=y.useState(e.plainDefaultValue);return y.useEffect(()=>{r(e.plainDefaultValue)},[e]),p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Preview"}),i(dl,{filter:e,value:n,onChange:r}),i(s.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),i(kt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),xS={select:fS,"multi-select":hS,"tree-select":bS,"text-input":gS,checkbox:uS,"date-range":dS},wS=[{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"}],CS=k.observer(function({filter:e}){const n=K(),r=y.useMemo(()=>xS[e.type],[e.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:a=>e.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:a=>{e.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:a=>{e.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:wS,required:!0,value:e.type,onChange:e.setType}),i(r,{config:e.config})]})]}),i(vS,{filter:e})]})}),SS=k.observer(({id:t})=>{const e=Ue.useModals(),n=he(),r=K();if(t==="")return null;const a=r.filters.findByID(t);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(CS,{filter:a})})]})}),_S=k.observer(()=>{const t=K(),[e,n]=y.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){hn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:e,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(D.DeviceFloppy,{size:20})})]})]})}),kS=k.observer(()=>{const{panel:t}=ze();return i(ai,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),TS=k.observer(()=>{const{panel:t}=ze(),{style:e}=t;return i(V,{children:i(s.Switch,{label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})})}),DS=k.observer(()=>{const{panel:t}=ze(),{title:e,setTitle:n}=t,[r,a]=Me.useInputState(e),o=e!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(e)},[e]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function MS(){return p(s.Stack,{sx:{height:"100%"},children:[i(s.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),i(TS,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(DS,{}),i(kS,{})]})}const IS=({queryID:t})=>{const e=K(),{state:n,error:r}=e.getDataStuffByID(t),a=y.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},ES={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 Dl({data:t}){const e=y.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Xe.createColumnHelper();return Object.keys(t[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[t]),n=Xe.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Xe.getCoreRowModel()});return t.length===0?i(s.Box,{sx:{height:"5em"}}):i(Fe,{children:p(s.Table,{sx:ES,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:Xe.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(D.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Fe,{children:Xe.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const $i=k.observer(function({id:e,moreActions:n=null}){const r=K(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(e)},c=()=>{r.queries.downloadDataByQueryID(e)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(D.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(D.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(IS,{queryID:e}),i(Dl,{data:d})]})]})}),AS=k.observer(function(){const e=he(),n=K(),{panel:r}=ze(),[a,o]=y.useState(!1),l=u=>{e.editor.setPath(["_QUERIES_",u])};return p(V,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i($i,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(L.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i($i,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),zS=k.observer(()=>{const{panel:t}=ze();return i(Fe,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(hl,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:t.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1},children:i(bl,{panel:t,height:"410px"})})]})})})}),Li={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 $S{constructor(e){N(this,"panel");N(this,"selected");this.panel=e,ie.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(Li.name)).length;this.panel.addVariable(x.cloneDeep({...Li,name:`${Li.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function LS(){const{panel:t}=ze();return X.useCreation(()=>new $S(t),[t])}const Ml=s.createStyles(t=>({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}})),OS=y.forwardRef(function({value:e,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:u=>l("name",u.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:u=>l("data_field",u)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:u=>l("aggregation",u)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Re,{value:e.formatter,onChange:u=>l("formatter",u)}),a&&i(Ts,{value:e,onChange:n})]})}),PS=t=>{const{uiModel:e}=t;return i(s.Stack,{className:"var-list",children:e.variables.map(n=>i(s.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},BS=k.observer(PS),VS=({variable:t,data:e})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:Ds(t,e)})}),NS=k.observer(VS),qS=t=>{const e=X.useCreation(()=>Uu(t.variable),[t.variable]),{classes:n}=Ml(),{data:r}=ze();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:i(L.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:i(L.IconTrash,{size:18})})]}),i(OS,{value:b.getSnapshot(e.copy),onChange:e.update,data:r})]}),i(NS,{variable:b.getSnapshot(e.copy),data:r})]})},FS=k.observer(qS),GS=()=>{const t=LS(),{classes:e}=Ml();return p(s.Group,{className:e.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),i(BS,{uiModel:t})]})}),t.selected?i(V,{children:i(FS,{uiModel:t,variable:t.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},WS=k.observer(GS);function jS(){const{vizManager:t}=y.useContext(at);return y.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const RS=k.observer(({value:t,submit:e})=>{const[n,r]=Me.useInputState(t);y.useEffect(()=>{r(t)},[t]);const a=jS(),o=t!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>e(n),children:i(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Il=[];function YS(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function QS(){const{data:t,panel:{variables:e,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=ze(),{vizManager:h}=y.useContext(at),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},w=gl(g);try{return h.resolveComponent(g.viz.type),i(Hn,{configure:w,children:i(t1,{variables:e,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:t})})}catch(C){return console.info(x.get(C,"message")),null}}const KS=k.observer(()=>{const{data:t,panel:{viz:e}}=ze(),{vizManager:n}=y.useContext(at),r=y.useCallback(d=>{if(d===e.type)return;const f=YS(n,d);e.setType(d),e.setConf(f||{})},[e.type]),a=d=>{try{e.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=Il.find(f=>f.value===e.type))==null?void 0:d.Panel},[e.type,Il]),l=QS(),u=o?y.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(RS,{submit:r,value:e.type}),p(Fe,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:a})]})]})}),US=k.observer(({panel:t,sourceViewID:e})=>{const n=K(),[r,a]=y.useState(e);y.useEffect(()=>{a(e)},[e]);const[o,{open:l,close:u}]=Me.useDisclosure(!1),c=()=>{t.moveToView(e,r),u()};return p(V,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===e,children:"Confirm"})]})]})})]})}),XS={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},El=({children:t})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),i(zS,{})]});function JS(t){return!["richText","button"].includes(t)}const ZS=k.observer(({panel:t})=>{const e=Ue.useModals(),n=he(),r=K(),[a,o]=y.useState("Data"),l=t.queries,c=JS(t.viz.type)&&t.dataLoading,d=c||t.queryErrors.length>0||t.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Sr,{value:{panel:t,data:t.data,loading:c,errors:t.queryErrors},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[t.title?t.title:t.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(US,{panel:t,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:XS,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(AS,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(El,{children:i(MS,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(WS,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Fe,{children:i(El,{children:i(KS,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Fe,{children:i(Nc,{})})})]})]})}),HS=k.observer(({viewID:t,panelID:e})=>{const n=K();if(!n.views.findByID(t))return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const a=n.panels.findByID(e);return a?i(ZS,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),Al=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:t,height:n,radius:"xs"},u)),i(s.Skeleton,{width:e,height:n,radius:"xs"})]}),on=({value:t})=>t===null||t===""?null:i(s.Tooltip,{label:t,disabled:!t,multiline:!0,children:i(s.ActionIcon,{children:i(L.IconInfoCircle,{size:14})})}),e_=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:e})}):null},t_=k.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?i(Al,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:e.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(on,{value:n.column_comment})}),i("td",{children:i(e_,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(on,{value:n.column_default})})]},n.column_name))})]})}),n_=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),r_=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(on,{value:r.index_definition})}),i("td",{children:i(on,{value:r.condition})}),i("td",{children:i(on,{value:r.comment})})]},r.index_name))})]})}),i_=k.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===me.MySQL?i(n_,{dataSource:t}):t.type===me.Postgresql?i(r_,{dataSource:t}):null}),a_=k.observer(({dataSource:t})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Fe,{children:i(t_,{dataSource:t})}),i(Fe,{children:i(i_,{dataSource:t})})]}));function s_({table_type:t}){return t==="VIEW"?i(L.IconEye,{size:14}):t==="BASE TABLE"?i(L.IconTable,{size:14}):null}const o_=k.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?i(Al,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(L.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(s_,{table_type:a.table_type}),onClick:()=>{t.setKeywords(n,a.table_name)},active:t.table_name===a.table_name},a.table_name))},n))})}),l_=({visible:t})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:t})}),u_=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],c_={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},d_=k.observer(({dataSource:t})=>{const{tableData:e}=t;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[e.maxPage>1&&i(s.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:c_,data:u_,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),p_=k.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?i(l_,{visible:!0}):p(Fe,{children:[i(d_,{dataSource:t}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:e.loading,overlayBlur:2}),i(Dl,{data:e.data})]})]})}),h_={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},f_=k.observer(({dataSource:t})=>(y.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Fe,{children:i(o_,{dataSource:t})})}),p(s.Tabs,{defaultValue:"structure",styles:h_,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(L.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(L.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(a_,{dataSource:t})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(p_,{dataSource:t})})]})]}))),g_={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},zl=k.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=y.useState(!1);return t.type==="http"?null:p(V,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:g_,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(f_,{dataSource:t})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),m_=y.forwardRef(({label:t,type:e,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:t}),i(s.Text,{children:e})]})),y_=k.observer(({value:t,onChange:e})=>{const n=he(),{data:r=[],loading:a}=X.useRequest(fr,{refreshDeps:[]},[]),o=y.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=y.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&e({key:d,type:l[d]})},c=y.useMemo(()=>n.datasources.find(t),[n,t]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(zl,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:m_,rightSection:c?i(s.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:a,value:t.key,onChange:u})}),b_=t=>{const{queryModel:e}=t,n=he(),r=K(),o=r.findQueryUsage(e.id).length>0,l=Ue.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(e.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.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:i(s.Button,{color:"gray",size:"xs",leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},v_=k.observer(b_),x_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.name);return y.useEffect(()=>{n(t.name)},[t.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:i(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),i(y_,{value:{type:t.type,key:t.key},onChange:({type:r,key:a})=>{t.setKey(a),t.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy}),t.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(v_,{queryModel:t})]})})});function w_(){const[t,{open:e,close:n}]=Me.useDisclosure(!1);return p(V,{children:[i(s.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:320,children:i(Kn,{value:du,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:i(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const C_=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Ie,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},ar=y.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(t),u=()=>{e(o)},c=()=>{l(t)},d=()=>{l(r)};y.useEffect(()=>{l(t)},[t]);const f=o!==t;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(w_,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(C_,{value:o,onChange:l})]})});function S_({content:t}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(L.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(kt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const __=k.observer(()=>{const e=[...he().globalSQLSnippets.list];return e.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:e.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(S_,{content:a})})]},r)})})]})}),k_=`
496
+ `,bS=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:yS})})]})},vS=k.observer(function({config:e}){return p(V,{children:[i(s.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(zi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(bS,{})]})}),xS=k.observer(function({filter:e}){const[n,r]=y.useState(e.plainDefaultValue);return y.useEffect(()=>{r(e.plainDefaultValue)},[e]),p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Preview"}),i(dl,{filter:e,value:n,onChange:r}),i(s.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),i(kt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),wS={select:gS,"multi-select":fS,"tree-select":vS,"text-input":mS,checkbox:cS,"date-range":pS},CS=[{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"}],SS=k.observer(function({filter:e}){const n=K(),r=y.useMemo(()=>wS[e.type],[e.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:a=>e.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:a=>{e.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:a=>{e.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:CS,required:!0,value:e.type,onChange:e.setType}),i(r,{config:e.config})]})]}),i(xS,{filter:e})]})}),_S=k.observer(({id:t})=>{const e=Ue.useModals(),n=he(),r=K();if(t==="")return null;const a=r.filters.findByID(t);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(SS,{filter:a})})]})}),kS=k.observer(()=>{const t=K(),[e,n]=y.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){hn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:e,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(D.DeviceFloppy,{size:20})})]})]})}),TS=k.observer(()=>{const{panel:t}=ze();return i(ai,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),DS=k.observer(()=>{const{panel:t}=ze(),{style:e}=t;return i(V,{children:i(s.Switch,{label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})})}),MS=k.observer(()=>{const{panel:t}=ze(),{title:e,setTitle:n}=t,[r,a]=Me.useInputState(e),o=e!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(e)},[e]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function IS(){return p(s.Stack,{sx:{height:"100%"},children:[i(s.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),i(DS,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(MS,{}),i(TS,{})]})}const ES=({queryID:t})=>{const e=K(),{state:n,error:r}=e.getDataStuffByID(t),a=y.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},AS={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".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 Dl({data:t}){const e=y.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Xe.createColumnHelper();return Object.keys(t[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[t]),n=Xe.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Xe.getCoreRowModel()});return t.length===0?i(s.Box,{sx:{height:"5em"}}):i(Fe,{children:p(s.Table,{sx:AS,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:Xe.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(D.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Fe,{children:Xe.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const $i=k.observer(function({id:e,moreActions:n=null}){const r=K(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(e)},c=()=>{r.queries.downloadDataByQueryID(e)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(D.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(D.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(ES,{queryID:e}),i(Dl,{data:d})]})]})}),zS=k.observer(function(){const e=he(),n=K(),{panel:r}=ze(),[a,o]=y.useState(!1),l=u=>{e.editor.setPath(["_QUERIES_",u])};return p(V,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i($i,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(L.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i($i,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),$S=k.observer(()=>{const{panel:t}=ze();return i(Fe,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(hl,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:t.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1},children:i(bl,{panel:t,height:"410px"})})]})})})}),Li={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 LS{constructor(e){N(this,"panel");N(this,"selected");this.panel=e,ie.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(Li.name)).length;this.panel.addVariable(x.cloneDeep({...Li,name:`${Li.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function OS(){const{panel:t}=ze();return X.useCreation(()=>new LS(t),[t])}const Ml=s.createStyles(t=>({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}})),PS=y.forwardRef(function({value:e,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:u=>l("name",u.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:u=>l("data_field",u)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:u=>l("aggregation",u)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Re,{value:e.formatter,onChange:u=>l("formatter",u)}),a&&i(Ts,{value:e,onChange:n})]})}),BS=t=>{const{uiModel:e}=t;return i(s.Stack,{className:"var-list",children:e.variables.map(n=>i(s.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},VS=k.observer(BS),NS=({variable:t,data:e})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:Ds(t,e)})}),qS=k.observer(NS),FS=t=>{const e=X.useCreation(()=>Uu(t.variable),[t.variable]),{classes:n}=Ml(),{data:r}=ze();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:i(L.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:i(L.IconTrash,{size:18})})]}),i(PS,{value:b.getSnapshot(e.copy),onChange:e.update,data:r})]}),i(qS,{variable:b.getSnapshot(e.copy),data:r})]})},GS=k.observer(FS),WS=()=>{const t=OS(),{classes:e}=Ml();return p(s.Group,{className:e.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),i(VS,{uiModel:t})]})}),t.selected?i(V,{children:i(GS,{uiModel:t,variable:t.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},jS=k.observer(WS);function RS(){const{vizManager:t}=y.useContext(at);return y.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const YS=k.observer(({value:t,submit:e})=>{const[n,r]=Me.useInputState(t);y.useEffect(()=>{r(t)},[t]);const a=RS(),o=t!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>e(n),children:i(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Il=[];function QS(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function KS(){const{data:t,panel:{variables:e,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=ze(),{vizManager:h}=y.useContext(at),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},w=gl(g);try{return h.resolveComponent(g.viz.type),i(Hn,{configure:w,children:i(n1,{variables:e,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:t})})}catch(C){return console.info(x.get(C,"message")),null}}const US=k.observer(()=>{const{data:t,panel:{viz:e}}=ze(),{vizManager:n}=y.useContext(at),r=y.useCallback(d=>{if(d===e.type)return;const f=QS(n,d);e.setType(d),e.setConf(f||{})},[e.type]),a=d=>{try{e.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=Il.find(f=>f.value===e.type))==null?void 0:d.Panel},[e.type,Il]),l=KS(),u=o?y.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(YS,{submit:r,value:e.type}),p(Fe,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:a})]})]})}),XS=k.observer(({panel:t,sourceViewID:e})=>{const n=K(),[r,a]=y.useState(e);y.useEffect(()=>{a(e)},[e]);const[o,{open:l,close:u}]=Me.useDisclosure(!1),c=()=>{t.moveToView(e,r),u()};return p(V,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===e,children:"Confirm"})]})]})})]})}),JS={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},El=({children:t})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),i($S,{})]});function ZS(t){return!["richText","button"].includes(t)}const HS=k.observer(({panel:t})=>{const e=Ue.useModals(),n=he(),r=K(),[a,o]=y.useState("Data"),l=t.queries,c=ZS(t.viz.type)&&t.dataLoading,d=c||t.queryErrors.length>0||t.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Sr,{value:{panel:t,data:t.data,loading:c,errors:t.queryErrors},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[t.title?t.title:t.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(XS,{panel:t,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:JS,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(zS,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(El,{children:i(IS,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(jS,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Fe,{children:i(El,{children:i(US,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Fe,{children:i(Nc,{})})})]})]})}),e_=k.observer(({viewID:t,panelID:e})=>{const n=K();if(!n.views.findByID(t))return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const a=n.panels.findByID(e);return a?i(HS,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),Al=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:t,height:n,radius:"xs"},u)),i(s.Skeleton,{width:e,height:n,radius:"xs"})]}),on=({value:t})=>t===null||t===""?null:i(s.Tooltip,{label:t,disabled:!t,multiline:!0,children:i(s.ActionIcon,{children:i(L.IconInfoCircle,{size:14})})}),t_=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:e})}):null},n_=k.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?i(Al,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:e.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(on,{value:n.column_comment})}),i("td",{children:i(t_,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(on,{value:n.column_default})})]},n.column_name))})]})}),r_=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),i_=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(on,{value:r.index_definition})}),i("td",{children:i(on,{value:r.condition})}),i("td",{children:i(on,{value:r.comment})})]},r.index_name))})]})}),a_=k.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===ye.MySQL?i(r_,{dataSource:t}):t.type===ye.Postgresql?i(i_,{dataSource:t}):null}),s_=k.observer(({dataSource:t})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Fe,{children:i(n_,{dataSource:t})}),i(Fe,{children:i(a_,{dataSource:t})})]}));function o_({table_type:t}){return t==="VIEW"?i(L.IconEye,{size:14}):t==="BASE TABLE"?i(L.IconTable,{size:14}):null}const l_=k.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?i(Al,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(L.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(o_,{table_type:a.table_type}),onClick:()=>{t.setKeywords(n,a.table_name)},active:t.table_name===a.table_name},a.table_name))},n))})}),u_=({visible:t})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:t})}),c_=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],d_={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},p_=k.observer(({dataSource:t})=>{const{tableData:e}=t;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[e.maxPage>1&&i(s.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:d_,data:c_,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),h_=k.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?i(u_,{visible:!0}):p(Fe,{children:[i(p_,{dataSource:t}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:e.loading,overlayBlur:2}),i(Dl,{data:e.data})]})]})}),f_={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},g_=k.observer(({dataSource:t})=>(y.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Fe,{children:i(l_,{dataSource:t})})}),p(s.Tabs,{defaultValue:"structure",styles:f_,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(L.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(L.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(s_,{dataSource:t})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(h_,{dataSource:t})})]})]}))),m_={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},zl=k.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=y.useState(!1);return t.type==="http"?null:p(V,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:m_,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(g_,{dataSource:t})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),y_=y.forwardRef(({label:t,type:e,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:t}),i(s.Text,{children:e})]})),b_=k.observer(({value:t,onChange:e})=>{const n=he(),{data:r=[],loading:a}=X.useRequest(fr,{refreshDeps:[]},[]),o=y.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=y.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&e({key:d,type:l[d]})},c=y.useMemo(()=>n.datasources.find(t),[n,t]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(zl,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:y_,rightSection:c?i(s.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:a,value:t.key,onChange:u})}),v_=t=>{const{queryModel:e}=t,n=he(),r=K(),o=r.findQueryUsage(e.id).length>0,l=Ue.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(e.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.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:i(s.Button,{color:"gray",size:"xs",leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},x_=k.observer(v_),w_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.name);return y.useEffect(()=>{n(t.name)},[t.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:i(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),i(b_,{value:{type:t.type,key:t.key},onChange:({type:r,key:a})=>{t.setKey(a),t.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy}),t.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(x_,{queryModel:t})]})})});function C_(){const[t,{open:e,close:n}]=Me.useDisclosure(!1);return p(V,{children:[i(s.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:320,children:i(Kn,{value:du,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:i(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const S_=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Ie,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},ar=y.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(t),u=()=>{e(o)},c=()=>{l(t)},d=()=>{l(r)};y.useEffect(()=>{l(t)},[t]);const f=o!==t;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(C_,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(S_,{value:o,onChange:l})]})});function __({content:t}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(L.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(kt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const k_=k.observer(()=>{const e=[...he().globalSQLSnippets.list];return e.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:e.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(__,{content:a})})]},r)})})]})}),T_=`
497
497
  -- You may reference query variables in SQL or VizConfig.
498
498
  SELECT *
499
499
  FROM commit
@@ -506,8 +506,8 @@ WHERE
506
506
  AND \${sql_snippets.author_email_condition}
507
507
  -- Global SQL snippets (shared between dashboards)
508
508
  AND \${global_sql_snippets.account_condition}
509
- `,$l=k.observer(function({showSQLSnippets:e=!0,sx:n={}}){const r=he(),a=K(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return e&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return i(s.Stack,{sx:{overflow:"hidden",...n},children:p(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"guide",icon:i(L.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(L.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(L.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(kt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:k_})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(kt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),i(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:p(s.Stack,{spacing:10,children:[i(s.Alert,{icon:i(L.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(__,{})]})})]})})}),Oi=k.observer(()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:i($l,{})}),i(s.Button,{variant:"subtle",onClick:()=>e(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Ll={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
509
+ `,$l=k.observer(function({showSQLSnippets:e=!0,sx:n={}}){const r=he(),a=K(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return e&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return i(s.Stack,{sx:{overflow:"hidden",...n},children:p(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"guide",icon:i(L.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(L.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(L.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(kt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:T_})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(kt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),i(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:p(s.Stack,{spacing:10,children:[i(s.Alert,{icon:i(L.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(k_,{})]})})]})})}),Oi=k.observer(()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:i($l,{})}),i(s.Button,{variant:"subtle",onClick:()=>e(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Ll={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
510
510
  `),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
511
- `)},T_=k.observer(({queryModel:t})=>t.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Oi,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ar,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ll.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ar,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ll.post})})]}):null),D_=k.observer(({queryID:t,usage:e})=>{const n=he().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:e.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Pi=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{console.log("changing"),e==null||e(u??"")},l=!e;return i(Ie,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},M_=({value:t,height:e="200px",defaultLanguage:n="sql"})=>i(Ie,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),I_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>hr(t,n),[t,n]);return i(M_,{height:"100%",value:r})}),Ol={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
511
+ `)},D_=k.observer(({queryModel:t})=>t.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Oi,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ar,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ll.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ar,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ll.post})})]}):null),M_=k.observer(({queryID:t,usage:e})=>{const n=he().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:e.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Pi=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{console.log("changing"),e==null||e(u??"")},l=!e;return i(Ie,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},I_=({value:t,height:e="200px",defaultLanguage:n="sql"})=>i(Ie,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),E_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>hr(t,n),[t,n]);return i(I_,{height:"100%",value:r})}),Ol={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
512
512
  `),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
513
- `)},E_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.sql);y.useEffect(()=>{n(o=>o!==t.sql?t.sql:o)},[t.sql]);const r=e!==t.sql,a=()=>{t.setSQL(e)};return t.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:p(s.Group,{spacing:14,position:"apart",children:["Edit SQL",i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!r,onClick:a,children:i(D.DeviceFloppy,{size:20})})]})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Oi,{}),t.datasource&&i(zl,{dataSource:t.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(Pi,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(I_,{value:t.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ar,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ol.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ar,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ol.post})})]}):null}),sr={height:"calc(100% - 44px)",padding:0},A_=k.observer(({queryModel:t})=>{const e=K(),n=y.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=e.findQueryUsage(t.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),t.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:t.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(x_,{queryModel:t})}),t.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:sr,children:i(s.Stack,{sx:{height:"100%"},children:i(E_,{queryModel:t})})}),t.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:sr,children:i(s.Stack,{sx:{height:"100%"},children:i(T_,{queryModel:t})})}),i(s.Tabs.Panel,{value:"Data",sx:{...sr,overflow:"hidden"},children:i($i,{id:t.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...sr,overflow:"hidden"},children:i(D_,{queryID:t.id,usage:o})})]})})}),z_=k.observer(({id:t})=>{const n=K().queries.findByID(t);return t===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(A_,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),$_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>hr(t,n),[t,n]);return i(Pi,{height:"100%",value:r})}),L_=k.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(t.key),u=()=>{t.setKey(o),n(o)},c=o!==t.key,d=t.isADuplicatedKey(o),[f,h]=y.useState(t.value),g=()=>{t.setValue(f)};y.useEffect(()=>{l(t.key),h(t.value)},[t]);const m=f!==t.value,w=Ue.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(D.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Oi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(D.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Pi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i($_,{value:f})})]})]})}),O_=k.observer(({id:t})=>{const e=he(),n=K(),r=y.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const a=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])};return i(L_,{item:r,remove:()=>{n.sqlSnippets.removeByKey(t),a()},onKeyChanged:u=>{e.editor.setPath(["_SQL_SNIPPETS_",u])}})}),P_=k.observer(({view:t})=>!t||t.type!==H.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),B_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],V_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],N_=k.observer(({view:t})=>{if(!t||t.type!==H.Tabs)return null;const e=t.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:e.variant,onChange:e.setVariant,data:B_}),i(s.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:V_}),i(s.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),q_=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},F_=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t??Si),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,w={enabled:g,func_content:m};l(w),e(w)},d=()=>{a(),l(t)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(Si.func_content)};return p(V,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(D.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(q_,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},G_=k.observer(({view:t})=>{if(!t||t.type!==H.Modal)return null;const e=t.config,n=e.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(F_,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),W_=k.observer(({view:t})=>p(V,{children:[i(P_,{view:t}),i(G_,{view:t}),i(N_,{view:t})]})),j_=[{label:"Division",value:H.Division},{label:"Modal",value:H.Modal},{label:"Tabs",value:H.Tabs}],R_=k.observer(({view:t})=>t?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:j_}),i(W_,{view:t})]}):null),Y_=k.observer(({id:t})=>{const e=Ue.useModals(),n=he(),r=K();if(t==="")return null;const a=r.views.findByID(t);if(!a)return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(R_,{view:a})})]})});function Q_(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function K_(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function U_(t){return t.length===2&&t[0]==="_FILTERS_"}function X_(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function J_(t){return t.length===2&&t[0]==="_QUERIES_"}function Z_(t){return t.length===2&&t[0]==="_VIEWS_"}function H_(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const ek=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i($l,{})})),tk=k.observer(()=>{const t=he().editor,e=t.path;return Q_(e)?i(ek,{}):K_(e)?i(_S,{}):U_(e)?i(s.Box,{p:"xs",pl:20,children:i(SS,{id:e[1]})}):X_(e)?i(O_,{id:e[1]}):J_(e)?i(z_,{id:e[1]}):Z_(e)?i(s.Box,{p:"xs",pl:20,children:i(Y_,{id:e[1]})}):H_(e)?i(HS,{viewID:e[1],panelID:e[3]}):i(s.Box,{children:t.path})}),nk=k.observer(()=>i(tk,{})),rk=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:Ci.TextInput,config:ns(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),ik=k.observer(({parentID:t})=>{const e=K();if(!t)return null;const n=e.views.findByID(t);return n?i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),ak=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:me.Postgresql,key:"",sql:""};t.content.queries.append(r),t.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),sk=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),ok=k.observer(()=>{const t=K();return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),lk=k.observer(({action_type:t,parentID:e})=>(K(),t==="_Add_A_Filter_"?i(rk,{}):t==="_Add_A_SQL_SNIPPET_"?i(sk,{}):t==="_Add_A_QUERY_"?i(ak,{}):t==="_Add_A_VIEW_"?i(ok,{}):t==="_Add_A_PANEL_"?i(ik,{parentID:e}):null)),Pl=k.observer(({option:t})=>{var d;const e=he().editor,n=e.isOptionActive,r=n(e.path,t),a=e.isOptionOpened,o=e.navigate,l=a(t),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:t.label,onClick:()=>o(t),icon:t.Icon?i(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(lk,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(Pl,{option:f},f.value))},t.label)}),uk=k.observer(()=>{const t=he();return i(s.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>i(Pl,{option:e},e.value))})}),ck=k.observer(()=>{const t=he();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(uk,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),dk={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"}},pk=k.observer(()=>{const t=he().editor;return i(s.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(ck,{}),styles:dk,children:i(nk,{})})})}),hk=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function fk(t){y.useEffect(()=>{if(Ie.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=hk(t);Ie.loader.config({paths:{vs:n}}),Ie.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ns();const gk={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},mk=({context:t,dashboard:e,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},d)=>{fk(o.monacoPath),ja(o);const{data:f=[]}=X.useRequest(fr),{data:h=[]}=X.useRequest(Ra),[g,m]=y.useState(!1),w=y.useMemo(()=>ki(e,n,f,h,t),[e,n]);y.useImperativeHandle(d,()=>w,[w]),Ka(w.content,!0),y.useEffect(()=>{w.context.replace(t)},[t]),y.useEffect(()=>{w.datasources.replace(f)},[f]),y.useEffect(()=>{w.globalSQLSnippets.replace(h)},[h]),y.useEffect(()=>ie.reaction(()=>ie.toJS(w.json),I=>{l==null||l(I)}),[w]);const C=async()=>{await r(w.json,w.content.json)},_=X.useCreation(yi,[]),T=Mi(_);return i(Ue.ModalsProvider,{children:i(mr,{value:w,children:i(gr,{value:w.content,children:i(ft.Provider,{value:{layoutFrozen:g,freezeLayout:m,inEditMode:!0},children:i(at.Provider,{value:_,children:p(Hn,{configure:T,children:[i(s.AppShell,{padding:0,header:i(O1,{saveDashboardChanges:C,headerSlot:u,headerMenuItems:c}),navbar:i(lS,{}),styles:gk,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:w.content.views.visibleViews.map(I=>i(xl,{view:I},I.id))})}),i(pk,{})]})})})})})})},yk=k.observer(y.forwardRef(mk)),SD="";Ns();const bk=k.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{ja(a);const{data:u=[]}=X.useRequest(fr),{data:c=[]}=X.useRequest(Ra),d=y.useMemo(()=>ki(e,n,u,c,t),[e,n]);Ka(d.content,!1),y.useEffect(()=>{d.context.replace(t)},[t]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=X.useCreation(yi,[]),h=Mi(f);return i(Ue.ModalsProvider,{children:i(mr,{value:d,children:i(gr,{value:d.content,children:i(_r.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(ft.Provider,{value:{layoutFrozen:!0,freezeLayout:x.noop,inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(at.Provider,{value:f,children:i(Hn,{configure:h,children:d.content.views.visibleViews.map(g=>i(nr,{view:g},g.id))})})})})})})})})});var Bi={},vk={get exports(){return Bi},set exports(t){Bi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(vk);const xk=Bi;var Vi={},wk={get exports(){return Vi},set exports(t){Vi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(wk);const Ck=Vi;var Ni={},Sk={get exports(){return Ni},set exports(t){Ni=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,w){return this.$utils().u(g)?this[m]:this.$set(w,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(Sk);const _k=Ni;var qi={},kk={get exports(){return qi},set exports(t){qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(kk);const Tk=qi;var Fi={},Dk={get exports(){return Fi},set exports(t){Fi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,w=d[m]||l[m];return typeof w=="function"?w.call(this,a()):this.format(w)}}})})(Dk);const Mk=Fi;var Gi={},Ik={get exports(){return Gi},set exports(t){Gi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(C){return(C=+C)+(C>68?1900:2e3)},d=function(C){return function(_){this[C]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var T=_.match(/([+-]|\d\d)/g),I=60*T[1]+(+T[2]||0);return I===0?0:T[0]==="+"?-I:I}(C)}],h=function(C){var _=u[C];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(C,_){var T,I=u.meridiem;if(I){for(var O=1;O<=24;O+=1)if(C.indexOf(I(O,0,_))>-1){T=O>12;break}}else T=C===(_?"pm":"PM");return T},m={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:[a,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(C){var _=u.ordinal,T=C.match(/\d+/);if(this.day=T[0],_)for(var I=1;I<=31;I+=1)_(I).replace(/\[|\]/g,"")===C&&(this.day=I)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(C){var _=h("months"),T=(h("monthsShort")||_.map(function(I){return I.slice(0,3)})).indexOf(C)+1;if(T<1)throw new Error;this.month=T%12||T}],MMMM:[l,function(C){var _=h("months").indexOf(C)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(C){this.year=c(C)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function w(C){var _,T;_=C,T=u&&u.formats;for(var I=(C=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Y,Z){var oe=Z&&Z.toUpperCase();return Y||T[Z]||n[Z]||T[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(ue,ye,De){return ye||De.slice(1)})})).match(r),O=I.length,B=0;B<O;B+=1){var $=I[B],A=m[$],E=A&&A[0],F=A&&A[1];I[B]=F?{regex:E,parser:F}:$.replace(/^\[|\]$/g,"")}return function(U){for(var Y={},Z=0,oe=0;Z<O;Z+=1){var ue=I[Z];if(typeof ue=="string")oe+=ue.length;else{var ye=ue.regex,De=ue.parser,ge=U.slice(oe),xe=ye.exec(ge)[0];De.call(Y,xe),U=U.replace(xe,"")}}return function(ve){var Oe=ve.afternoon;if(Oe!==void 0){var Qe=ve.hours;Oe?Qe<12&&(ve.hours+=12):Qe===12&&(ve.hours=0),delete ve.afternoon}}(Y),Y}}return function(C,_,T){T.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(c=C.parseTwoDigitYear);var I=_.prototype,O=I.parse;I.parse=function(B){var $=B.date,A=B.utc,E=B.args;this.$u=A;var F=E[1];if(typeof F=="string"){var U=E[2]===!0,Y=E[3]===!0,Z=U||Y,oe=E[2];Y&&(oe=E[2]),u=this.$locale(),!U&&oe&&(u=T.Ls[oe]),this.$d=function(ge,xe,ve){try{if(["x","X"].indexOf(xe)>-1)return new Date((xe==="X"?1e3:1)*ge);var Oe=w(xe)(ge),Qe=Oe.year,At=Oe.month,or=Oe.day,lr=Oe.hours,ya=Oe.minutes,ba=Oe.seconds,ln=Oe.milliseconds,Ft=Oe.zone,wt=new Date,zt=or||(Qe||At?1:wt.getDate()),Ct=Qe||wt.getFullYear(),Gt=0;Qe&&!At||(Gt=At>0?At-1:wt.getMonth());var Wt=lr||0,un=ya||0,cn=ba||0,St=ln||0;return Ft?new Date(Date.UTC(Ct,Gt,zt,Wt,un,cn,St+60*Ft.offset*1e3)):ve?new Date(Date.UTC(Ct,Gt,zt,Wt,un,cn,St)):new Date(Ct,Gt,zt,Wt,un,cn,St)}catch{return new Date("")}}($,F,A),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),Z&&$!=this.format(F)&&(this.$d=new Date("")),u={}}else if(F instanceof Array)for(var ue=F.length,ye=1;ye<=ue;ye+=1){E[1]=F[ye-1];var De=T.apply(this,E);if(De.isValid()){this.$d=De.$d,this.$L=De.$L,this.init();break}ye===ue&&(this.$d=new Date(""))}else O.call(this,B)}}})})(Ik);const Ek=Gi;var Wi={},Ak={get exports(){return Wi},set exports(t){Wi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(Ak);const zk=Wi;var ji={},$k={get exports(){return ji},set exports(t){ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof B},w=function($,A,E){return new B($,E,A.$l)},C=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},I=function($){return Math.abs($)},O=function($,A){return $?_($)?{negative:!0,format:""+I($)+A}:{negative:!1,format:""+$+A}:{negative:!1,format:""}},B=function(){function $(E,F,U){var Y=this;if(this.$d={},this.$l=U,E===void 0&&(this.$ms=0,this.parseFromMilliseconds()),F)return w(E*g[C(F)],this);if(typeof E=="number")return this.$ms=E,this.parseFromMilliseconds(),this;if(typeof E=="object")return Object.keys(E).forEach(function(ue){Y.$d[C(ue)]=E[ue]}),this.calMilliseconds(),this;if(typeof E=="string"){var Z=E.match(h);if(Z){var oe=Z.slice(2).map(function(ue){return ue!=null?Number(ue):0});return this.$d.years=oe[0],this.$d.months=oe[1],this.$d.weeks=oe[2],this.$d.days=oe[3],this.$d.hours=oe[4],this.$d.minutes=oe[5],this.$d.seconds=oe[6],this.calMilliseconds(),this}}return this}var A=$.prototype;return A.calMilliseconds=function(){var E=this;this.$ms=Object.keys(this.$d).reduce(function(F,U){return F+(E.$d[U]||0)*g[U]},0)},A.parseFromMilliseconds=function(){var E=this.$ms;this.$d.years=T(E/d),E%=d,this.$d.months=T(E/f),E%=f,this.$d.days=T(E/u),E%=u,this.$d.hours=T(E/l),E%=l,this.$d.minutes=T(E/o),E%=o,this.$d.seconds=T(E/a),E%=a,this.$d.milliseconds=E},A.toISOString=function(){var E=O(this.$d.years,"Y"),F=O(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Y=O(U,"D"),Z=O(this.$d.hours,"H"),oe=O(this.$d.minutes,"M"),ue=this.$d.seconds||0;this.$d.milliseconds&&(ue+=this.$d.milliseconds/1e3);var ye=O(ue,"S"),De=E.negative||F.negative||Y.negative||Z.negative||oe.negative||ye.negative,ge=Z.format||oe.format||ye.format?"T":"",xe=(De?"-":"")+"P"+E.format+F.format+Y.format+ge+Z.format+oe.format+ye.format;return xe==="P"||xe==="-P"?"P0D":xe},A.toJSON=function(){return this.toISOString()},A.format=function(E){var F=E||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return F.replace(c,function(Y,Z){return Z||String(U[Y])})},A.as=function(E){return this.$ms/g[C(E)]},A.get=function(E){var F=this.$ms,U=C(E);return U==="milliseconds"?F%=1e3:F=U==="weeks"?T(F/g[U]):this.$d[U],F===0?0:F},A.add=function(E,F,U){var Y;return Y=F?E*g[C(F)]:m(E)?E.$ms:w(E,this).$ms,w(this.$ms+Y*(U?-1:1),this)},A.subtract=function(E,F){return this.add(E,F,!0)},A.locale=function(E){var F=this.clone();return F.$l=E,F},A.clone=function(){return w(this.$ms,this)},A.humanize=function(E){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!E)},A.milliseconds=function(){return this.get("milliseconds")},A.asMilliseconds=function(){return this.as("milliseconds")},A.seconds=function(){return this.get("seconds")},A.asSeconds=function(){return this.as("seconds")},A.minutes=function(){return this.get("minutes")},A.asMinutes=function(){return this.as("minutes")},A.hours=function(){return this.get("hours")},A.asHours=function(){return this.as("hours")},A.days=function(){return this.get("days")},A.asDays=function(){return this.as("days")},A.weeks=function(){return this.get("weeks")},A.asWeeks=function(){return this.as("weeks")},A.months=function(){return this.get("months")},A.asMonths=function(){return this.as("months")},A.years=function(){return this.get("years")},A.asYears=function(){return this.as("years")},$}();return function($,A,E){n=E,r=E().$utils(),E.duration=function(Y,Z){var oe=E.locale();return w(Y,{$l:oe},Z)},E.isDuration=m;var F=A.prototype.add,U=A.prototype.subtract;A.prototype.add=function(Y,Z){return m(Y)&&(Y=Y.asMilliseconds()),F.bind(this)(Y,Z)},A.prototype.subtract=function(Y,Z){return m(Y)&&(Y=Y.asMilliseconds()),U.bind(this)(Y,Z)}}})})($k);const Lk=ji;var Ri={},Ok={get exports(){return Ri},set exports(t){Ri=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(Ok);const Pk=Ri;var Yi={},Bk={get exports(){return Yi},set exports(t){Yi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(Bk);const Vk=Yi;var Qi={},Nk={get exports(){return Qi},set exports(t){Qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(Nk);const qk=Qi;var Ki={},Fk={get exports(){return Ki},set exports(t){Ki=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,w=l(this),C=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return w.diff(C,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(Fk);const Gk=Ki;var Ui={},Wk={get exports(){return Ui},set exports(t){Ui=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(Wk);const jk=Ui;var Xi={},Rk={get exports(){return Xi},set exports(t){Xi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(Rk);const Yk=Xi;var Ji={},Qk={get exports(){return Ji},set exports(t){Ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(Qk);const Kk=Ji;var Zi={},Uk={get exports(){return Zi},set exports(t){Zi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(Uk);const Xk=Zi;var Hi={},Jk={get exports(){return Hi},set exports(t){Hi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(Jk);const Zk=Hi;var ea={},Hk={get exports(){return ea},set exports(t){ea=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(Hk);const eT=ea;var ta={},tT={get exports(){return ta},set exports(t){ta=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,w,C){var _=h.name?h:h.$locale(),T=l(_[g]),I=l(_[m]),O=T||I.map(function($){return $.slice(0,w)});if(!C)return O;var B=_.weekStart;return O.map(function($,A){return O[(A+(B||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,_){return C||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(tT);const nT=ta;var na={},rT={get exports(){return na},set exports(t){na=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var _=C&&C.toUpperCase();return w||g[C]||n[C]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(T,I,O){return I||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(rT);const iT=na;var ra={},aT={get exports(){return ra},set exports(t){ra=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(aT);const sT=ra;var ia={},oT={get exports(){return ia},set exports(t){ia=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,w=g.date,C=g.utc,_={};if(!((m=w)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var T=C?a.utc():a();Object.keys(w).forEach(function(U){var Y,Z;_[Y=U,Z=o.$utils().p(Y),Z==="date"?"day":Z]=w[U]});var I=_.day||(_.year||_.month>=0?1:T.date()),O=_.year||T.year(),B=_.month>=0?_.month:_.year||_.day?0:T.month(),$=_.hour||0,A=_.minute||0,E=_.second||0,F=_.millisecond||0;return C?new Date(Date.UTC(O,B,I,$,A,E,F)):new Date(O,B,I,$,A,E,F)}return w},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,w,C){C===void 0&&(C=1);var _=Object.keys(m),T=this;return _.forEach(function(I){T=g.bind(T)(m[I]*C,I)}),T};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(w,C){return c.bind(this)(C,w)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(oT);const lT=ia;var aa={},uT={get exports(){return aa},set exports(t){aa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(uT);const cT=aa;var sa={},dT={get exports(){return sa},set exports(t){sa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(dT);const pT=sa;var oa={},hT={get exports(){return oa},set exports(t){oa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(hT);const fT=oa;var la={},gT={get exports(){return la},set exports(t){la=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var w,C,_,T=h.$locale().relativeTime||l,I=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],O=I.length,B=0;B<O;B+=1){var $=I[B];$.d&&(w=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var A=(n.rounding||Math.round)(Math.abs(w));if(_=w>0,A<=$.r||!$.r){A<=1&&B>0&&($=I[B-1]);var E=T[$.l];m&&(A=m(""+A)),C=typeof E=="string"?E.replace("%d",A):E(A,f,$.l,_);break}}if(f)return C;var F=_?T.future:T.past;return typeof F=="function"?F(C):F.replace("%s",C)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(gT);const mT=la;var ua={},yT={get exports(){return ua},set exports(t){ua=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,w){w===void 0&&(w={});var C=new Date(g),_=function(T,I){I===void 0&&(I={});var O=I.timeZoneName||"short",B=T+"|"+O,$=r[B];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[B]=$),$}(m,w);return _.formatToParts(C)},d=function(g,m){for(var w=c(g,m),C=[],_=0;_<w.length;_+=1){var T=w[_],I=T.type,O=T.value,B=n[I];B>=0&&(C[B]=parseInt(O,10))}var $=C[3],A=$===24?0:$,E=C[0]+"-"+C[1]+"-"+C[2]+" "+A+":"+C[4]+":"+C[5]+":000",F=+g;return(l.utc(E).valueOf()-(F-=F%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var w=this.utcOffset(),C=this.toDate(),_=C.toLocaleString("en-US",{timeZone:g}),T=Math.round((C-new Date(_))/1e3/60),I=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-T,!0);if(m){var O=I.utcOffset();I=I.add(w-O,"minute")}return I.$x.$timezone=g,I},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),w=c(this.valueOf(),m,{timeZoneName:g}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var w=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(w,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,w){var C=w&&m,_=w||m||u,T=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var I=function(A,E,F){var U=A-60*E*1e3,Y=d(U,F);if(E===Y)return[U,E];var Z=d(U-=60*(Y-E)*1e3,F);return Y===Z?[U,Y]:[A-60*Math.min(Y,Z)*1e3,Math.max(Y,Z)]}(l.utc(g,C).valueOf(),T,_),O=I[0],B=I[1],$=l(O).utcOffset(B);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(yT);const bT=ua;var ca={},vT={get exports(){return ca},set exports(t){ca=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(vT);const xT=ca;var da={},wT={get exports(){return da},set exports(t){da=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(wT);const CT=da;var pa={},ST={get exports(){return pa},set exports(t){pa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(ST);const _T=pa;var ha={},kT={get exports(){return ha},set exports(t){ha=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(C){var _={date:C,utc:!0,args:arguments};return new l(_)},c.utc=function(C){var _=u(this.toDate(),{locale:this.$L,utc:!0});return C?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),d.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,_){var T=this.$utils().u;if(T(C))return this.$u?0:T(this.$offset)?h.call(this):this.$offset;if(typeof C=="string"&&(C=function($){$===void 0&&($="");var A=$.match(r);if(!A)return null;var E=(""+A[0]).match(a)||["-",0,0],F=E[0],U=60*+E[1]+ +E[2];return U===0?0:F==="+"?U:-U}(C),C===null))return this;var I=Math.abs(C)<=16?60*C:C,O=this;if(_)return O.$offset=I,O.$u=C===0,O;if(C!==0){var B=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(I+B,n)).$offset=I,O.$x.$localOffset=B}else O=this.utc();return O};var g=c.format;c.format=function(C){var _=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},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 m=c.toDate;c.toDate=function(C){return C==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=c.diff;c.diff=function(C,_,T){if(C&&this.$u===C.$u)return w.call(this,C,_,T);var I=this.local(),O=u(C).local();return w.call(I,O,_,T)}}})})(kT);const TT=ha;var fa={},DT={get exports(){return fa},set exports(t){fa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(DT);const MT=fa;var ga={},IT={get exports(){return ga},set exports(t){ga=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(IT);const ET=ga;var ma={},AT={get exports(){return ma},set exports(t){ma=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(AT);const zT=ma;R.extend(xk),R.extend(Ck),R.extend(_k),R.extend(Tk),R.extend(Mk),R.extend(Ek),R.extend(zk),R.extend(Lk),R.extend(Pk),R.extend(Vk),R.extend(qk),R.extend(Yk),R.extend(Kk),R.extend(Xk),R.extend(Zk),R.extend(eT),R.extend(Gk),R.extend(jk),R.extend(nT),R.extend(iT),R.extend(sT),R.extend(lT),R.extend(cT),R.extend(pT),R.extend(fT),R.extend(mT),R.extend(bT),R.extend(xT),R.extend(CT),R.extend(_T),R.extend(TT),R.extend(ET),R.extend(zT),R.extend(MT),R.tz.setDefault("UTC");const $T=()=>Promise.resolve().then(()=>lc).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));M.ContentModel=Zn,M.ContentModelContextProvider=gr,M.ContextModel=fs,M.DashboardEditor=yk,M.DashboardFilterType=Ci,M.DashboardMode=Zo,M.DashboardModel=ol,M.DashboardViewEditor=xl,M.DashboardViewRender=nr,M.EViewComponentType=H,M.FilterModel=br,M.FiltersModel=is,M.FullScreenPanelContext=_r,M.LayoutStateContext=ft,M.ModelContextProvider=mr,M.Panel=tr,M.PanelContextProvider=Sr,M.PanelModel=Uo,M.PanelsModel=Jo,M.QueriesModel=ds,M.QueryModel=cs,M.ReadOnlyDashboard=bk,M.SQLSnippetModel=ps,M.SQLSnippetsModel=hs,M.ViewComponentTypeBackground=Ho,M.ViewComponentTypeColor=SC,M.ViewComponentTypeName=CC,M.ViewModel=rl,M.ViewsModel=il,M.applyPartialDashboard=AC,M.createContentModel=sl,M.createDashboardModel=ki,M.createDashboardViewsModel=_i,M.getInitialFiltersPayload=as,M.getNewPanel=Xo,M.getVersion=$T,M.initialDashboardContent=_C,M.useContentModelContext=K,M.useFullScreenPanelContext=ws,M.useModelContext=he,M.usePanelContext=ze,M.useTopLevelServices=Mi,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
513
+ `)},A_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.sql);y.useEffect(()=>{n(o=>o!==t.sql?t.sql:o)},[t.sql]);const r=e!==t.sql,a=()=>{t.setSQL(e)};return t.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:p(s.Group,{spacing:14,position:"apart",children:["Edit SQL",i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!r,onClick:a,children:i(D.DeviceFloppy,{size:20})})]})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Oi,{}),t.datasource&&i(zl,{dataSource:t.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(Pi,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(E_,{value:t.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ar,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ol.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ar,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ol.post})})]}):null}),sr={height:"calc(100% - 44px)",padding:0},z_=k.observer(({queryModel:t})=>{const e=K(),n=y.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=e.findQueryUsage(t.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),t.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:t.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(w_,{queryModel:t})}),t.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:sr,children:i(s.Stack,{sx:{height:"100%"},children:i(A_,{queryModel:t})})}),t.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:sr,children:i(s.Stack,{sx:{height:"100%"},children:i(D_,{queryModel:t})})}),i(s.Tabs.Panel,{value:"Data",sx:{...sr,overflow:"hidden"},children:i($i,{id:t.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...sr,overflow:"hidden"},children:i(M_,{queryID:t.id,usage:o})})]})})}),$_=k.observer(({id:t})=>{const n=K().queries.findByID(t);return t===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(z_,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),L_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>hr(t,n),[t,n]);return i(Pi,{height:"100%",value:r})}),O_=k.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(t.key),u=()=>{t.setKey(o),n(o)},c=o!==t.key,d=t.isADuplicatedKey(o),[f,h]=y.useState(t.value),g=()=>{t.setValue(f)};y.useEffect(()=>{l(t.key),h(t.value)},[t]);const m=f!==t.value,w=Ue.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(D.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Oi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(D.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Pi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(L_,{value:f})})]})]})}),P_=k.observer(({id:t})=>{const e=he(),n=K(),r=y.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const a=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])};return i(O_,{item:r,remove:()=>{n.sqlSnippets.removeByKey(t),a()},onKeyChanged:u=>{e.editor.setPath(["_SQL_SNIPPETS_",u])}})}),B_=k.observer(({view:t})=>!t||t.type!==H.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),V_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],N_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],q_=k.observer(({view:t})=>{if(!t||t.type!==H.Tabs)return null;const e=t.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:e.variant,onChange:e.setVariant,data:V_}),i(s.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:N_}),i(s.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),F_=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},G_=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t??Si),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,w={enabled:g,func_content:m};l(w),e(w)},d=()=>{a(),l(t)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(Si.func_content)};return p(V,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(D.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(F_,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},W_=k.observer(({view:t})=>{if(!t||t.type!==H.Modal)return null;const e=t.config,n=e.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(G_,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),j_=k.observer(({view:t})=>p(V,{children:[i(B_,{view:t}),i(W_,{view:t}),i(q_,{view:t})]})),R_=[{label:"Division",value:H.Division},{label:"Modal",value:H.Modal},{label:"Tabs",value:H.Tabs}],Y_=k.observer(({view:t})=>t?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:R_}),i(j_,{view:t})]}):null),Q_=k.observer(({id:t})=>{const e=Ue.useModals(),n=he(),r=K();if(t==="")return null;const a=r.views.findByID(t);if(!a)return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(Y_,{view:a})})]})});function K_(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function U_(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function X_(t){return t.length===2&&t[0]==="_FILTERS_"}function J_(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function Z_(t){return t.length===2&&t[0]==="_QUERIES_"}function H_(t){return t.length===2&&t[0]==="_VIEWS_"}function ek(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const tk=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i($l,{})})),nk=k.observer(()=>{const t=he().editor,e=t.path;return K_(e)?i(tk,{}):U_(e)?i(kS,{}):X_(e)?i(s.Box,{p:"xs",pl:20,children:i(_S,{id:e[1]})}):J_(e)?i(P_,{id:e[1]}):Z_(e)?i($_,{id:e[1]}):H_(e)?i(s.Box,{p:"xs",pl:20,children:i(Q_,{id:e[1]})}):ek(e)?i(e_,{viewID:e[1],panelID:e[3]}):i(s.Box,{children:t.path})}),rk=k.observer(()=>i(nk,{})),ik=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:Ci.TextInput,config:ns(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),ak=k.observer(({parentID:t})=>{const e=K();if(!t)return null;const n=e.views.findByID(t);return n?i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),sk=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:ye.Postgresql,key:"",sql:""};t.content.queries.append(r),t.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),ok=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),lk=k.observer(()=>{const t=K();return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),uk=k.observer(({action_type:t,parentID:e})=>(K(),t==="_Add_A_Filter_"?i(ik,{}):t==="_Add_A_SQL_SNIPPET_"?i(ok,{}):t==="_Add_A_QUERY_"?i(sk,{}):t==="_Add_A_VIEW_"?i(lk,{}):t==="_Add_A_PANEL_"?i(ak,{parentID:e}):null)),Pl=k.observer(({option:t})=>{var d;const e=he().editor,n=e.isOptionActive,r=n(e.path,t),a=e.isOptionOpened,o=e.navigate,l=a(t),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:t.label,onClick:()=>o(t),icon:t.Icon?i(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(uk,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(Pl,{option:f},f.value))},t.label)}),ck=k.observer(()=>{const t=he();return i(s.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>i(Pl,{option:e},e.value))})}),dk=k.observer(()=>{const t=he();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(ck,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),pk={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"}},hk=k.observer(()=>{const t=he().editor;return i(s.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(dk,{}),styles:pk,children:i(rk,{})})})}),fk=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function gk(t){y.useEffect(()=>{if(Ie.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=fk(t);Ie.loader.config({paths:{vs:n}}),Ie.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ns();const mk={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},yk=({context:t,dashboard:e,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},d)=>{gk(o.monacoPath),ja(o);const{data:f=[]}=X.useRequest(fr),{data:h=[]}=X.useRequest(Ra),[g,m]=y.useState(!1),w=y.useMemo(()=>ki(e,n,f,h,t),[e,n]);y.useImperativeHandle(d,()=>w,[w]),Ka(w.content,!0),y.useEffect(()=>{w.context.replace(t)},[t]),y.useEffect(()=>{w.datasources.replace(f)},[f]),y.useEffect(()=>{w.globalSQLSnippets.replace(h)},[h]),y.useEffect(()=>ie.reaction(()=>ie.toJS(w.json),I=>{l==null||l(I)}),[w]);const C=async()=>{await r(w.json,w.content.json)},_=X.useCreation(yi,[]),T=Mi(_);return i(Ue.ModalsProvider,{children:i(mr,{value:w,children:i(gr,{value:w.content,children:i(ft.Provider,{value:{layoutFrozen:g,freezeLayout:m,inEditMode:!0},children:i(at.Provider,{value:_,children:p(Hn,{configure:T,children:[i(s.AppShell,{padding:0,header:i(P1,{saveDashboardChanges:C,headerSlot:u,headerMenuItems:c}),navbar:i(uS,{}),styles:mk,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:w.content.views.visibleViews.map(I=>i(xl,{view:I},I.id))})}),i(hk,{})]})})})})})})},bk=k.observer(y.forwardRef(yk)),_D="";Ns();const vk=k.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{ja(a);const{data:u=[]}=X.useRequest(fr),{data:c=[]}=X.useRequest(Ra),d=y.useMemo(()=>ki(e,n,u,c,t),[e,n]);Ka(d.content,!1),y.useEffect(()=>{d.context.replace(t)},[t]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=X.useCreation(yi,[]),h=Mi(f);return i(Ue.ModalsProvider,{children:i(mr,{value:d,children:i(gr,{value:d.content,children:i(_r.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(ft.Provider,{value:{layoutFrozen:!0,freezeLayout:x.noop,inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(at.Provider,{value:f,children:i(Hn,{configure:h,children:d.content.views.visibleViews.map(g=>i(nr,{view:g},g.id))})})})})})})})})});var Bi={},xk={get exports(){return Bi},set exports(t){Bi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(xk);const wk=Bi;var Vi={},Ck={get exports(){return Vi},set exports(t){Vi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(Ck);const Sk=Vi;var Ni={},_k={get exports(){return Ni},set exports(t){Ni=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,w){return this.$utils().u(g)?this[m]:this.$set(w,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(_k);const kk=Ni;var qi={},Tk={get exports(){return qi},set exports(t){qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(Tk);const Dk=qi;var Fi={},Mk={get exports(){return Fi},set exports(t){Fi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,w=d[m]||l[m];return typeof w=="function"?w.call(this,a()):this.format(w)}}})})(Mk);const Ik=Fi;var Gi={},Ek={get exports(){return Gi},set exports(t){Gi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(C){return(C=+C)+(C>68?1900:2e3)},d=function(C){return function(_){this[C]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var T=_.match(/([+-]|\d\d)/g),I=60*T[1]+(+T[2]||0);return I===0?0:T[0]==="+"?-I:I}(C)}],h=function(C){var _=u[C];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(C,_){var T,I=u.meridiem;if(I){for(var O=1;O<=24;O+=1)if(C.indexOf(I(O,0,_))>-1){T=O>12;break}}else T=C===(_?"pm":"PM");return T},m={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:[a,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(C){var _=u.ordinal,T=C.match(/\d+/);if(this.day=T[0],_)for(var I=1;I<=31;I+=1)_(I).replace(/\[|\]/g,"")===C&&(this.day=I)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(C){var _=h("months"),T=(h("monthsShort")||_.map(function(I){return I.slice(0,3)})).indexOf(C)+1;if(T<1)throw new Error;this.month=T%12||T}],MMMM:[l,function(C){var _=h("months").indexOf(C)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(C){this.year=c(C)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function w(C){var _,T;_=C,T=u&&u.formats;for(var I=(C=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Y,Z){var oe=Z&&Z.toUpperCase();return Y||T[Z]||n[Z]||T[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(ue,be,De){return be||De.slice(1)})})).match(r),O=I.length,B=0;B<O;B+=1){var $=I[B],A=m[$],E=A&&A[0],F=A&&A[1];I[B]=F?{regex:E,parser:F}:$.replace(/^\[|\]$/g,"")}return function(U){for(var Y={},Z=0,oe=0;Z<O;Z+=1){var ue=I[Z];if(typeof ue=="string")oe+=ue.length;else{var be=ue.regex,De=ue.parser,ge=U.slice(oe),xe=be.exec(ge)[0];De.call(Y,xe),U=U.replace(xe,"")}}return function(me){var Oe=me.afternoon;if(Oe!==void 0){var Qe=me.hours;Oe?Qe<12&&(me.hours+=12):Qe===12&&(me.hours=0),delete me.afternoon}}(Y),Y}}return function(C,_,T){T.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(c=C.parseTwoDigitYear);var I=_.prototype,O=I.parse;I.parse=function(B){var $=B.date,A=B.utc,E=B.args;this.$u=A;var F=E[1];if(typeof F=="string"){var U=E[2]===!0,Y=E[3]===!0,Z=U||Y,oe=E[2];Y&&(oe=E[2]),u=this.$locale(),!U&&oe&&(u=T.Ls[oe]),this.$d=function(ge,xe,me){try{if(["x","X"].indexOf(xe)>-1)return new Date((xe==="X"?1e3:1)*ge);var Oe=w(xe)(ge),Qe=Oe.year,At=Oe.month,or=Oe.day,lr=Oe.hours,ya=Oe.minutes,ba=Oe.seconds,ln=Oe.milliseconds,Ft=Oe.zone,wt=new Date,zt=or||(Qe||At?1:wt.getDate()),Ct=Qe||wt.getFullYear(),Gt=0;Qe&&!At||(Gt=At>0?At-1:wt.getMonth());var Wt=lr||0,un=ya||0,cn=ba||0,St=ln||0;return Ft?new Date(Date.UTC(Ct,Gt,zt,Wt,un,cn,St+60*Ft.offset*1e3)):me?new Date(Date.UTC(Ct,Gt,zt,Wt,un,cn,St)):new Date(Ct,Gt,zt,Wt,un,cn,St)}catch{return new Date("")}}($,F,A),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),Z&&$!=this.format(F)&&(this.$d=new Date("")),u={}}else if(F instanceof Array)for(var ue=F.length,be=1;be<=ue;be+=1){E[1]=F[be-1];var De=T.apply(this,E);if(De.isValid()){this.$d=De.$d,this.$L=De.$L,this.init();break}be===ue&&(this.$d=new Date(""))}else O.call(this,B)}}})})(Ek);const Ak=Gi;var Wi={},zk={get exports(){return Wi},set exports(t){Wi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(zk);const $k=Wi;var ji={},Lk={get exports(){return ji},set exports(t){ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof B},w=function($,A,E){return new B($,E,A.$l)},C=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},I=function($){return Math.abs($)},O=function($,A){return $?_($)?{negative:!0,format:""+I($)+A}:{negative:!1,format:""+$+A}:{negative:!1,format:""}},B=function(){function $(E,F,U){var Y=this;if(this.$d={},this.$l=U,E===void 0&&(this.$ms=0,this.parseFromMilliseconds()),F)return w(E*g[C(F)],this);if(typeof E=="number")return this.$ms=E,this.parseFromMilliseconds(),this;if(typeof E=="object")return Object.keys(E).forEach(function(ue){Y.$d[C(ue)]=E[ue]}),this.calMilliseconds(),this;if(typeof E=="string"){var Z=E.match(h);if(Z){var oe=Z.slice(2).map(function(ue){return ue!=null?Number(ue):0});return this.$d.years=oe[0],this.$d.months=oe[1],this.$d.weeks=oe[2],this.$d.days=oe[3],this.$d.hours=oe[4],this.$d.minutes=oe[5],this.$d.seconds=oe[6],this.calMilliseconds(),this}}return this}var A=$.prototype;return A.calMilliseconds=function(){var E=this;this.$ms=Object.keys(this.$d).reduce(function(F,U){return F+(E.$d[U]||0)*g[U]},0)},A.parseFromMilliseconds=function(){var E=this.$ms;this.$d.years=T(E/d),E%=d,this.$d.months=T(E/f),E%=f,this.$d.days=T(E/u),E%=u,this.$d.hours=T(E/l),E%=l,this.$d.minutes=T(E/o),E%=o,this.$d.seconds=T(E/a),E%=a,this.$d.milliseconds=E},A.toISOString=function(){var E=O(this.$d.years,"Y"),F=O(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Y=O(U,"D"),Z=O(this.$d.hours,"H"),oe=O(this.$d.minutes,"M"),ue=this.$d.seconds||0;this.$d.milliseconds&&(ue+=this.$d.milliseconds/1e3);var be=O(ue,"S"),De=E.negative||F.negative||Y.negative||Z.negative||oe.negative||be.negative,ge=Z.format||oe.format||be.format?"T":"",xe=(De?"-":"")+"P"+E.format+F.format+Y.format+ge+Z.format+oe.format+be.format;return xe==="P"||xe==="-P"?"P0D":xe},A.toJSON=function(){return this.toISOString()},A.format=function(E){var F=E||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return F.replace(c,function(Y,Z){return Z||String(U[Y])})},A.as=function(E){return this.$ms/g[C(E)]},A.get=function(E){var F=this.$ms,U=C(E);return U==="milliseconds"?F%=1e3:F=U==="weeks"?T(F/g[U]):this.$d[U],F===0?0:F},A.add=function(E,F,U){var Y;return Y=F?E*g[C(F)]:m(E)?E.$ms:w(E,this).$ms,w(this.$ms+Y*(U?-1:1),this)},A.subtract=function(E,F){return this.add(E,F,!0)},A.locale=function(E){var F=this.clone();return F.$l=E,F},A.clone=function(){return w(this.$ms,this)},A.humanize=function(E){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!E)},A.milliseconds=function(){return this.get("milliseconds")},A.asMilliseconds=function(){return this.as("milliseconds")},A.seconds=function(){return this.get("seconds")},A.asSeconds=function(){return this.as("seconds")},A.minutes=function(){return this.get("minutes")},A.asMinutes=function(){return this.as("minutes")},A.hours=function(){return this.get("hours")},A.asHours=function(){return this.as("hours")},A.days=function(){return this.get("days")},A.asDays=function(){return this.as("days")},A.weeks=function(){return this.get("weeks")},A.asWeeks=function(){return this.as("weeks")},A.months=function(){return this.get("months")},A.asMonths=function(){return this.as("months")},A.years=function(){return this.get("years")},A.asYears=function(){return this.as("years")},$}();return function($,A,E){n=E,r=E().$utils(),E.duration=function(Y,Z){var oe=E.locale();return w(Y,{$l:oe},Z)},E.isDuration=m;var F=A.prototype.add,U=A.prototype.subtract;A.prototype.add=function(Y,Z){return m(Y)&&(Y=Y.asMilliseconds()),F.bind(this)(Y,Z)},A.prototype.subtract=function(Y,Z){return m(Y)&&(Y=Y.asMilliseconds()),U.bind(this)(Y,Z)}}})})(Lk);const Ok=ji;var Ri={},Pk={get exports(){return Ri},set exports(t){Ri=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(Pk);const Bk=Ri;var Yi={},Vk={get exports(){return Yi},set exports(t){Yi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(Vk);const Nk=Yi;var Qi={},qk={get exports(){return Qi},set exports(t){Qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(qk);const Fk=Qi;var Ki={},Gk={get exports(){return Ki},set exports(t){Ki=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,w=l(this),C=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return w.diff(C,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(Gk);const Wk=Ki;var Ui={},jk={get exports(){return Ui},set exports(t){Ui=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(jk);const Rk=Ui;var Xi={},Yk={get exports(){return Xi},set exports(t){Xi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(Yk);const Qk=Xi;var Ji={},Kk={get exports(){return Ji},set exports(t){Ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(Kk);const Uk=Ji;var Zi={},Xk={get exports(){return Zi},set exports(t){Zi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(Xk);const Jk=Zi;var Hi={},Zk={get exports(){return Hi},set exports(t){Hi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(Zk);const Hk=Hi;var ea={},eT={get exports(){return ea},set exports(t){ea=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(eT);const tT=ea;var ta={},nT={get exports(){return ta},set exports(t){ta=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,w,C){var _=h.name?h:h.$locale(),T=l(_[g]),I=l(_[m]),O=T||I.map(function($){return $.slice(0,w)});if(!C)return O;var B=_.weekStart;return O.map(function($,A){return O[(A+(B||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,_){return C||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(nT);const rT=ta;var na={},iT={get exports(){return na},set exports(t){na=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var _=C&&C.toUpperCase();return w||g[C]||n[C]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(T,I,O){return I||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(iT);const aT=na;var ra={},sT={get exports(){return ra},set exports(t){ra=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(sT);const oT=ra;var ia={},lT={get exports(){return ia},set exports(t){ia=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,w=g.date,C=g.utc,_={};if(!((m=w)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var T=C?a.utc():a();Object.keys(w).forEach(function(U){var Y,Z;_[Y=U,Z=o.$utils().p(Y),Z==="date"?"day":Z]=w[U]});var I=_.day||(_.year||_.month>=0?1:T.date()),O=_.year||T.year(),B=_.month>=0?_.month:_.year||_.day?0:T.month(),$=_.hour||0,A=_.minute||0,E=_.second||0,F=_.millisecond||0;return C?new Date(Date.UTC(O,B,I,$,A,E,F)):new Date(O,B,I,$,A,E,F)}return w},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,w,C){C===void 0&&(C=1);var _=Object.keys(m),T=this;return _.forEach(function(I){T=g.bind(T)(m[I]*C,I)}),T};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(w,C){return c.bind(this)(C,w)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(lT);const uT=ia;var aa={},cT={get exports(){return aa},set exports(t){aa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(cT);const dT=aa;var sa={},pT={get exports(){return sa},set exports(t){sa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(pT);const hT=sa;var oa={},fT={get exports(){return oa},set exports(t){oa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(fT);const gT=oa;var la={},mT={get exports(){return la},set exports(t){la=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var w,C,_,T=h.$locale().relativeTime||l,I=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],O=I.length,B=0;B<O;B+=1){var $=I[B];$.d&&(w=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var A=(n.rounding||Math.round)(Math.abs(w));if(_=w>0,A<=$.r||!$.r){A<=1&&B>0&&($=I[B-1]);var E=T[$.l];m&&(A=m(""+A)),C=typeof E=="string"?E.replace("%d",A):E(A,f,$.l,_);break}}if(f)return C;var F=_?T.future:T.past;return typeof F=="function"?F(C):F.replace("%s",C)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(mT);const yT=la;var ua={},bT={get exports(){return ua},set exports(t){ua=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,w){w===void 0&&(w={});var C=new Date(g),_=function(T,I){I===void 0&&(I={});var O=I.timeZoneName||"short",B=T+"|"+O,$=r[B];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[B]=$),$}(m,w);return _.formatToParts(C)},d=function(g,m){for(var w=c(g,m),C=[],_=0;_<w.length;_+=1){var T=w[_],I=T.type,O=T.value,B=n[I];B>=0&&(C[B]=parseInt(O,10))}var $=C[3],A=$===24?0:$,E=C[0]+"-"+C[1]+"-"+C[2]+" "+A+":"+C[4]+":"+C[5]+":000",F=+g;return(l.utc(E).valueOf()-(F-=F%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var w=this.utcOffset(),C=this.toDate(),_=C.toLocaleString("en-US",{timeZone:g}),T=Math.round((C-new Date(_))/1e3/60),I=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-T,!0);if(m){var O=I.utcOffset();I=I.add(w-O,"minute")}return I.$x.$timezone=g,I},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),w=c(this.valueOf(),m,{timeZoneName:g}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var w=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(w,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,w){var C=w&&m,_=w||m||u,T=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var I=function(A,E,F){var U=A-60*E*1e3,Y=d(U,F);if(E===Y)return[U,E];var Z=d(U-=60*(Y-E)*1e3,F);return Y===Z?[U,Y]:[A-60*Math.min(Y,Z)*1e3,Math.max(Y,Z)]}(l.utc(g,C).valueOf(),T,_),O=I[0],B=I[1],$=l(O).utcOffset(B);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(bT);const vT=ua;var ca={},xT={get exports(){return ca},set exports(t){ca=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(xT);const wT=ca;var da={},CT={get exports(){return da},set exports(t){da=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(CT);const ST=da;var pa={},_T={get exports(){return pa},set exports(t){pa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(_T);const kT=pa;var ha={},TT={get exports(){return ha},set exports(t){ha=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(C){var _={date:C,utc:!0,args:arguments};return new l(_)},c.utc=function(C){var _=u(this.toDate(),{locale:this.$L,utc:!0});return C?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),d.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,_){var T=this.$utils().u;if(T(C))return this.$u?0:T(this.$offset)?h.call(this):this.$offset;if(typeof C=="string"&&(C=function($){$===void 0&&($="");var A=$.match(r);if(!A)return null;var E=(""+A[0]).match(a)||["-",0,0],F=E[0],U=60*+E[1]+ +E[2];return U===0?0:F==="+"?U:-U}(C),C===null))return this;var I=Math.abs(C)<=16?60*C:C,O=this;if(_)return O.$offset=I,O.$u=C===0,O;if(C!==0){var B=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(I+B,n)).$offset=I,O.$x.$localOffset=B}else O=this.utc();return O};var g=c.format;c.format=function(C){var _=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},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 m=c.toDate;c.toDate=function(C){return C==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=c.diff;c.diff=function(C,_,T){if(C&&this.$u===C.$u)return w.call(this,C,_,T);var I=this.local(),O=u(C).local();return w.call(I,O,_,T)}}})})(TT);const DT=ha;var fa={},MT={get exports(){return fa},set exports(t){fa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(MT);const IT=fa;var ga={},ET={get exports(){return ga},set exports(t){ga=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(ET);const AT=ga;var ma={},zT={get exports(){return ma},set exports(t){ma=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(zT);const $T=ma;R.extend(wk),R.extend(Sk),R.extend(kk),R.extend(Dk),R.extend(Ik),R.extend(Ak),R.extend($k),R.extend(Ok),R.extend(Bk),R.extend(Nk),R.extend(Fk),R.extend(Qk),R.extend(Uk),R.extend(Jk),R.extend(Hk),R.extend(tT),R.extend(Wk),R.extend(Rk),R.extend(rT),R.extend(aT),R.extend(oT),R.extend(uT),R.extend(dT),R.extend(hT),R.extend(gT),R.extend(yT),R.extend(vT),R.extend(wT),R.extend(ST),R.extend(kT),R.extend(DT),R.extend(AT),R.extend($T),R.extend(IT),R.tz.setDefault("UTC");const LT=()=>Promise.resolve().then(()=>lc).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));M.ContentModel=Zn,M.ContentModelContextProvider=gr,M.ContextModel=fs,M.DashboardEditor=bk,M.DashboardFilterType=Ci,M.DashboardMode=Zo,M.DashboardModel=ol,M.DashboardViewEditor=xl,M.DashboardViewRender=nr,M.EViewComponentType=H,M.FilterModel=br,M.FiltersModel=is,M.FullScreenPanelContext=_r,M.LayoutStateContext=ft,M.ModelContextProvider=mr,M.Panel=tr,M.PanelContextProvider=Sr,M.PanelModel=Uo,M.PanelsModel=Jo,M.QueriesModel=ds,M.QueryModel=cs,M.ReadOnlyDashboard=vk,M.SQLSnippetModel=ps,M.SQLSnippetsModel=hs,M.ViewComponentTypeBackground=Ho,M.ViewComponentTypeColor=_C,M.ViewComponentTypeName=SC,M.ViewModel=rl,M.ViewsModel=il,M.applyPartialDashboard=zC,M.createContentModel=sl,M.createDashboardModel=ki,M.createDashboardViewsModel=_i,M.getInitialFiltersPayload=as,M.getNewPanel=Xo,M.getVersion=LT,M.initialDashboardContent=kC,M.useContentModelContext=K,M.useFullScreenPanelContext=ws,M.useModelContext=he,M.usePanelContext=ze,M.useTopLevelServices=Mi,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});