@devtable/dashboard 10.42.0 → 10.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard.es.js +479 -469
- package/dist/dashboard.umd.js +42 -42
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(T,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),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("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),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","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@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","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","react-router-dom","reactflow"],m):(T=typeof globalThis<"u"?globalThis:T||self,m(T.dashboard={},T.react,T["@mantine/core"],T["@mantine/modals"],T.ahooks,T.mobx,T["mobx-react-lite"],T.CryptoJS,T.dayjs,T._,T.numbro,T["d3-array"],T.mathjs,T["@faker-js/faker"],T.axios,T.eventemitter2,T["chroma-js"],T["echarts-for-react/lib/core"],T["echarts-gl"],T["echarts/components"],T["echarts/core"],T["echarts/renderers"],T["react-hook-form"],T["tabler-icons-react"],T["echarts/charts"],T["@tabler/icons-react"],T["@mantine/hooks"],T["@mantine/notifications"],T["@mantine/tiptap"],T["@tiptap/extension-color"],T["@tiptap/extension-highlight"],T["@tiptap/extension-placeholder"],T["@tiptap/extension-subscript"],T["@tiptap/extension-superscript"],T["@tiptap/extension-text-align"],T["@tiptap/extension-text-style"],T["@tiptap/extension-table"],T["@tiptap/extension-table-cell"],T["@tiptap/extension-table-header"],T["@tiptap/extension-table-row"],T["@tiptap/extension-underline"],T["@tiptap/react"],T["@tiptap/starter-kit"],T["prosemirror-keymap"],T["prosemirror-commands"],T["prosemirror-schema-list"],T["@monaco-editor/react"],T.popmotion,T["d3-regression"],T["@mantine/prism"],T["@tanstack/react-table"],T["react-virtual"],T["@mantine/dates"],T["rc-select"],T["rc-tree-select"],T["react-grid-layout"],T["mobx-state-tree"],T["performant-array-to-tree"],T["@json2csv/whatwg"],T["file-saver"],T.jszip,T["dom-to-image-more"],T["react-router-dom"],T.reactflow))})(this,function(T,m,s,Fe,Q,te,k,
|
|
1
|
+
(function(T,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),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("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),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","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@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","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","react-router-dom","reactflow"],m):(T=typeof globalThis<"u"?globalThis:T||self,m(T.dashboard={},T.react,T["@mantine/core"],T["@mantine/modals"],T.ahooks,T.mobx,T["mobx-react-lite"],T.CryptoJS,T.dayjs,T._,T.numbro,T["d3-array"],T.mathjs,T["@faker-js/faker"],T.axios,T.eventemitter2,T["chroma-js"],T["echarts-for-react/lib/core"],T["echarts-gl"],T["echarts/components"],T["echarts/core"],T["echarts/renderers"],T["react-hook-form"],T["tabler-icons-react"],T["echarts/charts"],T["@tabler/icons-react"],T["@mantine/hooks"],T["@mantine/notifications"],T["@mantine/tiptap"],T["@tiptap/extension-color"],T["@tiptap/extension-highlight"],T["@tiptap/extension-placeholder"],T["@tiptap/extension-subscript"],T["@tiptap/extension-superscript"],T["@tiptap/extension-text-align"],T["@tiptap/extension-text-style"],T["@tiptap/extension-table"],T["@tiptap/extension-table-cell"],T["@tiptap/extension-table-header"],T["@tiptap/extension-table-row"],T["@tiptap/extension-underline"],T["@tiptap/react"],T["@tiptap/starter-kit"],T["prosemirror-keymap"],T["prosemirror-commands"],T["prosemirror-schema-list"],T["@monaco-editor/react"],T.popmotion,T["d3-regression"],T["@mantine/prism"],T["@tanstack/react-table"],T["react-virtual"],T["@mantine/dates"],T["rc-select"],T["rc-tree-select"],T["react-grid-layout"],T["mobx-state-tree"],T["performant-array-to-tree"],T["@json2csv/whatwg"],T["file-saver"],T.jszip,T["dom-to-image-more"],T["react-router-dom"],T.reactflow))})(this,function(T,m,s,Fe,Q,te,k,Ba,U,x,Z,tn,qu,Fu,pt,Va,ht,Ae,CM,F,Gu,ze,v,I,he,E,_e,Tn,J,Na,qa,Fa,Ga,Wa,ja,Ra,Ya,Qa,Ua,Ka,Xa,Ja,Za,SM,ke,br,Te,It,Wu,Mt,et,ju,Ru,Ha,es,Dn,b,Yu,Qu,vr,Uu,ts,Ku,Ie){"use strict";var xM=Object.defineProperty;var wM=(T,m,s)=>m in T?xM(T,m,{enumerable:!0,configurable:!0,writable:!0,value:s}):T[m]=s;var q=(T,m,s)=>(wM(T,typeof m!="symbol"?m+"":m,s),s);function nn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Xu=nn(Ba),Ju=nn(tn),In=nn(qu),ie=nn(Gu),wt=nn(Wu);var re=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},rn={},Zu={get exports(){return rn},set exports(e){rn=e}},an={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ns;function Hu(){if(ns)return an;ns=1;var e=m,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(u,c,d){var f,h={},g=null,y=null;d!==void 0&&(g=""+d),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(y=c.ref);for(f in c)r.call(c,f)&&!o.hasOwnProperty(f)&&(h[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)h[f]===void 0&&(h[f]=c[f]);return{$$typeof:t,type:u,key:g,ref:y,props:h,_owner:a.current}}return an.Fragment=n,an.jsx=l,an.jsxs=l,an}var sn={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -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
|
|
18
|
-
`+Xt+S}}var Vt=!1,Tt;{var Jt=typeof WeakMap=="function"?WeakMap:Map;Tt=new Jt}function Zt(S,z){if(!S||Vt)return"";{var V=Tt.get(S);if(V!==void 0)return V}var X;Vt=!0;var oe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var pe;pe=wn.current,wn.current=null,
|
|
17
|
+
*/var rs;function ec(){return rs||(rs=1,process.env.NODE_ENV!=="production"&&function(){var e=m,t=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"),y=Symbol.for("react.offscreen"),C=Symbol.iterator,w="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var z=C&&S[C]||S[w];return typeof z=="function"?z:null}var D=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function M(S){{for(var z=arguments.length,V=new Array(z>1?z-1:0),X=1;X<z;X++)V[X-1]=arguments[X];O("error",S,V)}}function O(S,z,V){{var X=D.ReactDebugCurrentFrame,oe=X.getStackAddendum();oe!==""&&(z+="%s",V=V.concat([oe]));var pe=V.map(function(ne){return String(ne)});pe.unshift("Warning: "+z),Function.prototype.apply.call(console[S],console,pe)}}var G=!1,$=!1,L=!1,A=!1,N=!1,K;K=Symbol.for("react.module.reference");function Y(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||N||S===a||S===d||S===f||A||S===y||G||$||L||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===h||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===K||S.getModuleId!==void 0))}function H(S,z,V){var X=S.displayName;if(X)return X;var oe=z.displayName||z.name||"";return oe!==""?V+"("+oe+")":V}function se(S){return S.displayName||"Context"}function de(S){if(S==null)return null;if(typeof S.tag=="number"&&M("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 se(z)+".Consumer";case l:var V=S;return se(V._context)+".Provider";case c:return H(S,S.render,"ForwardRef");case h:var X=S.displayName||null;return X!==null?X:de(S.type)||"Memo";case g:{var oe=S,pe=oe._payload,ne=oe._init;try{return de(ne(pe))}catch{return null}}}return null}var xe=Object.assign,Le=0,bt,Ye,dt,qe,vt,Bt,gr;function mr(){}mr.__reactDisabledLog=!0;function Aa(){{if(Le===0){bt=console.log,Ye=console.info,dt=console.warn,qe=console.error,vt=console.group,Bt=console.groupCollapsed,gr=console.groupEnd;var S={configurable:!0,enumerable:!0,value:mr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}Le++}}function za(){{if(Le--,Le===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:xe({},S,{value:bt}),info:xe({},S,{value:Ye}),warn:xe({},S,{value:dt}),error:xe({},S,{value:qe}),group:xe({},S,{value:vt}),groupCollapsed:xe({},S,{value:Bt}),groupEnd:xe({},S,{value:gr})})}Le<0&&M("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var wn=D.ReactCurrentDispatcher,Xt;function kt(S,z,V){{if(Xt===void 0)try{throw Error()}catch(oe){var X=oe.stack.trim().match(/\n( *(at )?)/);Xt=X&&X[1]||""}return`
|
|
18
|
+
`+Xt+S}}var Vt=!1,Tt;{var Jt=typeof WeakMap=="function"?WeakMap:Map;Tt=new Jt}function Zt(S,z){if(!S||Vt)return"";{var V=Tt.get(S);if(V!==void 0)return V}var X;Vt=!0;var oe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var pe;pe=wn.current,wn.current=null,Aa();try{if(z){var ne=function(){throw Error()};if(Object.defineProperty(ne.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ne,[])}catch(xt){X=xt}Reflect.construct(S,[],ne)}else{try{ne.call()}catch(xt){X=xt}S.call(ne.prototype)}}else{try{throw Error()}catch(xt){X=xt}S()}}catch(xt){if(xt&&X&&typeof xt.stack=="string"){for(var ee=xt.stack.split(`
|
|
19
19
|
`),Pe=X.stack.split(`
|
|
20
20
|
`),me=ee.length-1,we=Pe.length-1;me>=1&&we>=0&&ee[me]!==Pe[we];)we--;for(;me>=1&&we>=0;me--,we--)if(ee[me]!==Pe[we]){if(me!==1||we!==1)do if(me--,we--,we<0||ee[me]!==Pe[we]){var He=`
|
|
21
|
-
`+ee[me].replace(" at new "," at ");return S.displayName&&He.includes("<anonymous>")&&(He=He.replace("<anonymous>",S.displayName)),typeof S=="function"&&Tt.set(S,He),He}while(me>=1&&we>=0);break}}}finally{Vt=!1,wn.current=pe,
|
|
21
|
+
`+ee[me].replace(" at new "," at ");return S.displayName&&He.includes("<anonymous>")&&(He=He.replace("<anonymous>",S.displayName)),typeof S=="function"&&Tt.set(S,He),He}while(me>=1&&we>=0);break}}}finally{Vt=!1,wn.current=pe,za(),Error.prepareStackTrace=oe}var en=S?S.displayName||S.name:"",Nu=en?kt(en):"";return typeof S=="function"&&Tt.set(S,Nu),Nu}function Cn(S,z,V){return Zt(S,!1)}function Sn(S){var z=S.prototype;return!!(z&&z.isReactComponent)}function Dt(S,z,V){if(S==null)return"";if(typeof S=="function")return Zt(S,Sn(S));if(typeof S=="string")return kt(S);switch(S){case d:return kt("Suspense");case f:return kt("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return Cn(S.render);case h:return Dt(S.type,z,V);case g:{var X=S,oe=X._payload,pe=X._init;try{return Dt(pe(oe),z,V)}catch{}}}return""}var _n=Object.prototype.hasOwnProperty,Du={},Iu=D.ReactDebugCurrentFrame;function yr(S){if(S){var z=S._owner,V=Dt(S.type,S._source,z?z.type:null);Iu.setExtraStackFrame(V)}else Iu.setExtraStackFrame(null)}function eM(S,z,V,X,oe){{var pe=Function.call.bind(_n);for(var ne in S)if(pe(S,ne)){var ee=void 0;try{if(typeof S[ne]!="function"){var Pe=Error((X||"React class")+": "+V+" type `"+ne+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[ne]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Pe.name="Invariant Violation",Pe}ee=S[ne](z,ne,X,V,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(me){ee=me}ee&&!(ee instanceof Error)&&(yr(oe),M("%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).",X||"React class",V,ne,typeof ee),yr(null)),ee instanceof Error&&!(ee.message in Du)&&(Du[ee.message]=!0,yr(oe),M("Failed %s type: %s",V,ee.message),yr(null))}}}var tM=Array.isArray;function Ea(S){return tM(S)}function nM(S){{var z=typeof Symbol=="function"&&Symbol.toStringTag,V=z&&S[Symbol.toStringTag]||S.constructor.name||"Object";return V}}function rM(S){try{return Mu(S),!1}catch{return!0}}function Mu(S){return""+S}function Au(S){if(rM(S))return M("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",nM(S)),Mu(S)}var kn=D.ReactCurrentOwner,iM={key:!0,ref:!0,__self:!0,__source:!0},zu,Eu,$a;$a={};function aM(S){if(_n.call(S,"ref")){var z=Object.getOwnPropertyDescriptor(S,"ref").get;if(z&&z.isReactWarning)return!1}return S.ref!==void 0}function sM(S){if(_n.call(S,"key")){var z=Object.getOwnPropertyDescriptor(S,"key").get;if(z&&z.isReactWarning)return!1}return S.key!==void 0}function oM(S,z){if(typeof S.ref=="string"&&kn.current&&z&&kn.current.stateNode!==z){var V=de(kn.current.type);$a[V]||(M('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',de(kn.current.type),S.ref),$a[V]=!0)}}function lM(S,z){{var V=function(){zu||(zu=!0,M("%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))};V.isReactWarning=!0,Object.defineProperty(S,"key",{get:V,configurable:!0})}}function uM(S,z){{var V=function(){Eu||(Eu=!0,M("%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))};V.isReactWarning=!0,Object.defineProperty(S,"ref",{get:V,configurable:!0})}}var cM=function(S,z,V,X,oe,pe,ne){var ee={$$typeof:t,type:S,key:z,ref:V,props:ne,_owner:pe};return ee._store={},Object.defineProperty(ee._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ee,"_self",{configurable:!1,enumerable:!1,writable:!1,value:X}),Object.defineProperty(ee,"_source",{configurable:!1,enumerable:!1,writable:!1,value:oe}),Object.freeze&&(Object.freeze(ee.props),Object.freeze(ee)),ee};function dM(S,z,V,X,oe){{var pe,ne={},ee=null,Pe=null;V!==void 0&&(Au(V),ee=""+V),sM(z)&&(Au(z.key),ee=""+z.key),aM(z)&&(Pe=z.ref,oM(z,oe));for(pe in z)_n.call(z,pe)&&!iM.hasOwnProperty(pe)&&(ne[pe]=z[pe]);if(S&&S.defaultProps){var me=S.defaultProps;for(pe in me)ne[pe]===void 0&&(ne[pe]=me[pe])}if(ee||Pe){var we=typeof S=="function"?S.displayName||S.name||"Unknown":S;ee&&lM(ne,we),Pe&&uM(ne,we)}return cM(S,ee,Pe,oe,X,kn.current,ne)}}var La=D.ReactCurrentOwner,$u=D.ReactDebugCurrentFrame;function Ht(S){if(S){var z=S._owner,V=Dt(S.type,S._source,z?z.type:null);$u.setExtraStackFrame(V)}else $u.setExtraStackFrame(null)}var Pa;Pa=!1;function Oa(S){return typeof S=="object"&&S!==null&&S.$$typeof===t}function Lu(){{if(La.current){var S=de(La.current.type);if(S)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+S+"`."}return""}}function pM(S){{if(S!==void 0){var z=S.fileName.replace(/^.*[\\\/]/,""),V=S.lineNumber;return`
|
|
24
24
|
|
|
25
25
|
Check your code at `+z+":"+V+"."}return""}}var Pu={};function hM(S){{var z=Lu();if(!z){var V=typeof S=="string"?S:S.displayName||S.name;V&&(z=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var V=hM(z);if(Pu[V])return;Pu[V]=!0;var X="";S&&S._owner&&S._owner
|
|
27
|
+
Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var V=hM(z);if(Pu[V])return;Pu[V]=!0;var X="";S&&S._owner&&S._owner!==La.current&&(X=" It was passed a child from "+de(S._owner.type)+"."),Ht(S),M('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',V,X),Ht(null)}}function Bu(S,z){{if(typeof S!="object")return;if(Ea(S))for(var V=0;V<S.length;V++){var X=S[V];Oa(X)&&Ou(X,z)}else if(Oa(S))S._store&&(S._store.validated=!0);else if(S){var oe=_(S);if(typeof oe=="function"&&oe!==S.entries)for(var pe=oe.call(S),ne;!(ne=pe.next()).done;)Oa(ne.value)&&Ou(ne.value,z)}}}function fM(S){{var z=S.type;if(z==null||typeof z=="string")return;var V;if(typeof z=="function")V=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===c||z.$$typeof===h))V=z.propTypes;else return;if(V){var X=de(z);eM(V,S.props,"prop",X,S)}else if(z.PropTypes!==void 0&&!Pa){Pa=!0;var oe=de(z);M("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",oe||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&M("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function gM(S){{for(var z=Object.keys(S.props),V=0;V<z.length;V++){var X=z[V];if(X!=="children"&&X!=="key"){Ht(S),M("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",X),Ht(null);break}}S.ref!==null&&(Ht(S),M("Invalid attribute `ref` supplied to `React.Fragment`."),Ht(null))}}function Vu(S,z,V,X,oe,pe){{var ne=Y(S);if(!ne){var ee="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(ee+=" 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 Pe=pM(oe);Pe?ee+=Pe:ee+=Lu();var me;S===null?me="null":Ea(S)?me="array":S!==void 0&&S.$$typeof===t?(me="<"+(de(S.type)||"Unknown")+" />",ee=" Did you accidentally export a JSX literal instead of a component?"):me=typeof S,M("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",me,ee)}var we=dM(S,z,V,oe,pe);if(we==null)return we;if(ne){var He=z.children;if(He!==void 0)if(X)if(Ea(He)){for(var en=0;en<He.length;en++)Bu(He[en],S);Object.freeze&&Object.freeze(He)}else M("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 Bu(He,S)}return S===r?gM(we):fM(we),we}}function mM(S,z,V){return Vu(S,z,V,!0)}function yM(S,z,V){return Vu(S,z,V,!1)}var bM=yM,vM=mM;sn.Fragment=r,sn.jsx=bM,sn.jsxs=vM}()),sn}(function(e){process.env.NODE_ENV==="production"?e.exports=Hu():e.exports=ec()})(Zu);const B=rn.Fragment,i=rn.jsx,p=rn.jsxs,At={CryptoJS:Ba,d3Array:Ju,dayjs:U,lodash:x,numbro:Z,mathjs:In,faker:Fu.faker},tc=[{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"}],nc=e=>`
|
|
28
28
|
<tr>
|
|
29
29
|
<td><code>${e.name}</code></td>
|
|
30
30
|
<td>
|
|
@@ -51,21 +51,21 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
51
51
|
${tc.map(nc).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function xr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function wr(e,t){try{return xr(e,t)}catch(n){return console.error(n),n.message}}function ic({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},At)}catch(n){return console.error(n),e}}function ac(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,At,n)}catch(r){return console.error(r),t}}function sc(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function oc(e,t){let n=sc(e);return n+="&key="+t,Xu.MD5(n).toString().toUpperCase()}class rs{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:oc({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,a,o,l)=>{const u=this.buildHeader(o),c=this.buildAxiosConfig(t,r,a,o,u,n);return pt(c).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,n,r,a,o,l){const u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),u}buildHeader(t){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...t.headers}}}class lc{constructor(t){this.implementation=t}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class is extends rs{constructor(){super(...arguments);q(this,"makeQueryENV",null)}query(n){return async(r,a={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",r,a)}}httpDataSourceQuery(n){return async(r,a={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",n)("/query",r,a,!0)}}structure(n){return async(r,a={})=>this.post(n)("/query/structure",r,a)}}class as{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Nt=new is;function Cr(e){Nt.baseURL!==e.apiBaseURL&&(Nt.baseURL=e.apiBaseURL),e.app_id&&(Nt.app_id=e.app_id),e.app_secret&&(Nt.app_secret=e.app_secret),e.makeQueryENV&&(Nt.makeQueryENV=e.makeQueryENV)}const ss=new as(Nt),at=ss;function os(){return{filters:{},context:{}}}function ls(e){const t=os();if(!e)return os();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}async function uc({query:e,name:t,payload:n,additionals:r},a){if(!e.sql)return[];const{type:o,key:l,sql:u,pre_process:c,post_process:d}=e,f=xr(u,n),h=ic({sql:f,pre_process:c});let g=await at.query(a)({type:o,key:l,query:h,...r},{params:{name:t}});return g=ac(d,g,ls(n)),g}async function cc({type:e,key:t,configString:n,name:r,additionals:a},o){try{return await at.httpDataSourceQuery(o)({type:e,key:t,query:n,...a},{params:{name:r}})}catch(l){if(pt.isCancel(l))throw l;return console.error(l),l}}async function Sr(){try{return(await at.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function us(){try{return(await at.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class cs{constructor(t){q(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))te.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return te.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class dc{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Ba)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Ba;return this.channels.set(t,r),r}}class pc{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new dc,instanceData:new cs(t.viz.conf)};return this.instances.set(t.id,r),r}}function ds(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new cs({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const hc=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...ds(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},fc=e=>{const{vizManager:t,panel:n,data:r,variables:a}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),u={...ds(l,r,t,a)},c=o.configRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ps=(e,t)=>{const n=ht.bezier(e),r=ht.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Mn=e=>{const t=ht.bezier(e);return function(n){return t(n/100).hex()}},gc={type:"interpolation",displayName:"Red / Green",getColor:ps(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},mc={type:"interpolation",displayName:"Yellow / Blue",getColor:ps(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},yc={type:"interpolation",displayName:"Red",getColor:Mn(["#fff7f1","darkred"]),name:"red",category:"sequential"},bc={type:"interpolation",displayName:"Green",getColor:Mn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},vc={type:"interpolation",displayName:"Blue",getColor:Mn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},xc={type:"interpolation",displayName:"Orange",getColor:Mn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class wc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function ft(e){return new wc(e)}class _r{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new _r;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const hs="10.42.0",Cc=Object.freeze(Object.defineProperty({__proto__:null,version:hs},Symbol.toStringTag,{value:"Module"}));class Sc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class _c{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class kc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ge extends kc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const R=(e,t)=>{const[n,{setFalse:r}]=Q.useBoolean(!0),[a,o]=m.useState();m.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=m.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},Oe={top:16,right:16,bottom:16,left:16},tt=e=>Math.max(0,e-Oe.left-Oe.right),nt=e=>Math.max(0,e-Oe.top-Oe.bottom),on=(e,t)=>({width:tt(e),height:nt(t)}),Be=({width:e,height:t,children:n})=>i(s.Box,{pt:Oe.top,pr:Oe.right,pb:Oe.bottom,pl:Oe.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function P(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Tc(e){return e.includes(".")?P(e):{queryID:"",columnKey:e}}function gt(e,t){var a;const{queryID:n,columnKey:r}=P(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function ln(e,t){const{queryID:n}=P(t);return n?e[n]:[]}function Dc(e){return Object.values(e)[0]}function An(e,t){const{queryID:n,columnKey:r}=P(t);return e[r]}const kr={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"}};ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function Ic({context:e}){const{value:t}=R(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,kr),h=m.useMemo(()=>ln(n,o),[n,o]),{x:g,y,z:C}=m.useMemo(()=>({x:P(o),y:P(l),z:P(u)}),[o,l,u]),{min:w,max:_}=m.useMemo(()=>{const M=x.minBy(h,G=>G[C.columnKey]),O=x.maxBy(h,G=>G[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(O,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(M=>[M[g.columnKey],M[y.columnKey],M[C.columnKey]])}]};return t?i(Be,{width:r,height:a,children:i(Ae,{echarts:ie,option:D,style:on(r,a),notMerge:!0,theme:"merico-light"})}):null}const fs=m.createContext(null),Tr=fs.Provider;function Dr(){const e=m.useContext(fs);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ue=()=>Dr(),Ir=()=>Dr(),gs=m.createContext({searchButtonProps:{}}),Mr=gs.Provider;function ms(){return m.useContext(gs)}const ys=m.createContext(null),Ar=ys.Provider;function bs(){const e=m.useContext(ys);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>bs(),ye=()=>bs(),Mc={inEditMode:!1},zn=m.createContext(Mc),vs=m.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),zr=vs.Provider;function xs(){const e=m.useContext(vs);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Ct=()=>xs(),Qe=()=>xs(),Ac={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Er=m.createContext(Ac);function ws(){const e=m.useContext(Er);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(m.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=Qe(),d=m.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function zc({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=x.defaults({},t,kr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return m.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(I.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function Ec(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class $c extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:Ec(a,r)}})}}const Lc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new $c,name:"bar-3d",viewRender:Ic,configRender:zc,createConfig(){return{version:2,config:x.cloneDeep(kr)}}};class Ee extends m.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const De={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Pc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Ee,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(I.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(I.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(I.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const Ge=m.forwardRef(Pc),Ue={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
54
|
+
`;function xr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function wr(e,t){try{return xr(e,t)}catch(n){return console.error(n),n.message}}function ic({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},At)}catch(n){return console.error(n),e}}function ac(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,At,n)}catch(r){return console.error(r),t}}function sc(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function oc(e,t){let n=sc(e);return n+="&key="+t,Xu.MD5(n).toString().toUpperCase()}class is{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:oc({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,a,o,l)=>{const u=this.buildHeader(o),c=this.buildAxiosConfig(t,r,a,o,u,n);return pt(c).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,n,r,a,o,l){const u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),u}buildHeader(t){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...t.headers}}}class lc{constructor(t){this.implementation=t}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class as extends is{constructor(){super(...arguments);q(this,"makeQueryENV",null)}query(n){return async(r,a={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",r,a)}}httpDataSourceQuery(n){return async(r,a={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",n)("/query",r,a,!0)}}structure(n){return async(r,a={})=>this.post(n)("/query/structure",r,a)}}class ss{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Nt=new as;function Cr(e){Nt.baseURL!==e.apiBaseURL&&(Nt.baseURL=e.apiBaseURL),e.app_id&&(Nt.app_id=e.app_id),e.app_secret&&(Nt.app_secret=e.app_secret),e.makeQueryENV&&(Nt.makeQueryENV=e.makeQueryENV)}const os=new ss(Nt),at=os;function ls(){return{filters:{},context:{}}}function Sr(e){const t=ls();if(!e)return ls();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}async function uc({query:e,name:t,payload:n,additionals:r},a){if(!e.sql)return[];const{type:o,key:l,sql:u,pre_process:c,post_process:d}=e,f=xr(u,n),h=ic({sql:f,pre_process:c});let g=await at.query(a)({type:o,key:l,query:h,...r},{params:{name:t}});return g=ac(d,g,Sr(n)),g}async function cc({type:e,key:t,configString:n,name:r,additionals:a},o){try{return await at.httpDataSourceQuery(o)({type:e,key:t,query:n,...a},{params:{name:r}})}catch(l){if(pt.isCancel(l))throw l;return console.error(l),l}}async function _r(){try{return(await at.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function us(){try{return(await at.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class cs{constructor(t){q(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))te.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return te.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class dc{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Va)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Va;return this.channels.set(t,r),r}}class pc{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new dc,instanceData:new cs(t.viz.conf)};return this.instances.set(t.id,r),r}}function ds(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new cs({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const hc=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...ds(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},fc=e=>{const{vizManager:t,panel:n,data:r,variables:a}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),u={...ds(l,r,t,a)},c=o.configRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ps=(e,t)=>{const n=ht.bezier(e),r=ht.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Mn=e=>{const t=ht.bezier(e);return function(n){return t(n/100).hex()}},gc={type:"interpolation",displayName:"Red / Green",getColor:ps(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},mc={type:"interpolation",displayName:"Yellow / Blue",getColor:ps(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},yc={type:"interpolation",displayName:"Red",getColor:Mn(["#fff7f1","darkred"]),name:"red",category:"sequential"},bc={type:"interpolation",displayName:"Green",getColor:Mn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},vc={type:"interpolation",displayName:"Blue",getColor:Mn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},xc={type:"interpolation",displayName:"Orange",getColor:Mn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class wc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function ft(e){return new wc(e)}class kr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new kr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const hs="10.42.1",Cc=Object.freeze(Object.defineProperty({__proto__:null,version:hs},Symbol.toStringTag,{value:"Module"}));class Sc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class _c{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class kc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ge extends kc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const R=(e,t)=>{const[n,{setFalse:r}]=Q.useBoolean(!0),[a,o]=m.useState();m.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=m.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},Oe={top:16,right:16,bottom:16,left:16},tt=e=>Math.max(0,e-Oe.left-Oe.right),nt=e=>Math.max(0,e-Oe.top-Oe.bottom),on=(e,t)=>({width:tt(e),height:nt(t)}),Be=({width:e,height:t,children:n})=>i(s.Box,{pt:Oe.top,pr:Oe.right,pb:Oe.bottom,pl:Oe.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function P(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Tc(e){return e.includes(".")?P(e):{queryID:"",columnKey:e}}function gt(e,t){var a;const{queryID:n,columnKey:r}=P(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function ln(e,t){const{queryID:n}=P(t);return n?e[n]:[]}function Dc(e){return Object.values(e)[0]}function An(e,t){const{queryID:n,columnKey:r}=P(t);return e[r]}const Tr={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"}};ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function Ic({context:e}){const{value:t}=R(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,Tr),h=m.useMemo(()=>ln(n,o),[n,o]),{x:g,y,z:C}=m.useMemo(()=>({x:P(o),y:P(l),z:P(u)}),[o,l,u]),{min:w,max:_}=m.useMemo(()=>{const M=x.minBy(h,G=>G[C.columnKey]),O=x.maxBy(h,G=>G[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(O,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(M=>[M[g.columnKey],M[y.columnKey],M[C.columnKey]])}]};return t?i(Be,{width:r,height:a,children:i(Ae,{echarts:ie,option:D,style:on(r,a),notMerge:!0,theme:"merico-light"})}):null}const fs=m.createContext(null),Dr=fs.Provider;function Ir(){const e=m.useContext(fs);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ue=()=>Ir(),Mr=()=>Ir(),gs=m.createContext({searchButtonProps:{}}),Ar=gs.Provider;function ms(){return m.useContext(gs)}const ys=m.createContext(null),zr=ys.Provider;function bs(){const e=m.useContext(ys);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>bs(),ye=()=>bs(),Mc={inEditMode:!1},zn=m.createContext(Mc),vs=m.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Er=vs.Provider;function xs(){const e=m.useContext(vs);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Ct=()=>xs(),Qe=()=>xs(),Ac={fullScreenPanelID:"",setFullScreenPanelID:x.noop},$r=m.createContext(Ac);function ws(){const e=m.useContext($r);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(m.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=Qe(),d=m.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function zc({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=x.defaults({},t,Tr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return m.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(I.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function Ec(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class $c extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:Ec(a,r)}})}}const Lc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new $c,name:"bar-3d",viewRender:Ic,configRender:zc,createConfig(){return{version:2,config:x.cloneDeep(Tr)}}};class Ee extends m.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const De={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Pc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Ee,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(I.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(I.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(I.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const Ge=m.forwardRef(Pc),Ue={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
55
|
`)},Cs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Bc,configRender:Oc,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 Oc(e){return i(B,{})}function Bc(e){return i(s.Text,{children:"Click chart's series"})}const Vc=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],En=m.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(t);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[e&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:Vc,value:t.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),st=m.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},a=o=>{t({...e,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(En,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),i(En,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:a})]})}),We={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function ot({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
|
|
56
56
|
max-width: ${t}px;
|
|
57
57
|
word-break: ${n};
|
|
58
58
|
white-space: ${r};
|
|
59
59
|
overflow: hidden;
|
|
60
60
|
text-overflow: ${a};
|
|
61
|
-
`}function rt(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const $r={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:De},tooltip:{metrics:[]},color:"#228be6",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"}};function zt(e,t){return m.useMemo(()=>{const{queryID:n,columnKey:r}=P(t);return x.keyBy(e[n],r)},[e,t])}const Ke=(e,t)=>{const[n,r]=m.useState([]);return m.useEffect(()=>e.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===t))),[]),n};class qt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:x.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,t),u=x.get(o,t);l!==u&&n(l,u)},r)}}class Lr{constructor(t,n,r){q(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new qt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new qt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new qt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(x.values(t).map(n=>this.constructInstance(new qt(this.attachmentStorage,n.id))))}}function Nc(e,t){const{value:n,set:r}=R(e.operation.operationData,"config"),[a,o]=m.useState(x.defaults({},n,t)),l=async()=>{await r(a)};return m.useEffect(()=>{o(x.defaults({},n,t))},[n]),{config:a,setConfig:o,commit:l}}function qc(e){const{config:t,setConfig:n,commit:r}=Nc(e,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Fc(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class Gc extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Wc={displayName:"Open Link",id:"builtin:op:open-link",configRender:qc,run:Fc,migrator:new Gc,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function jc(e){const{value:t,set:n}=R(e.operationData,"config"),r=a=>void n({template:a});return[(t==null?void 0:t.template)||"",r]}function Rc(e){const[t,n]=jc(e.operation);return i(s.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Yc(e,t){const n=await t.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const Qc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Rc,run:Yc},Uc=k.observer(e=>{const t=le(),{value:n,set:r}=R(e.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:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Kc(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const Xc={displayName:"Open View",id:"builtin:op:open_view",configRender:Uc,run:Kc},Jc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Zc=({value:e="",onChange:t})=>{const[n,r]=m.useState(e);m.useEffect(()=>{r(e)},[e]);const a=()=>{t(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===e,children:i(E.IconDeviceFloppy,{})})})},Hc={dictionary:{}},ed=k.observer(e=>{const t=le(),{value:n=Hc,set:r}=R(e.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...t.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:Jc,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...t.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(Zc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function td(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const nd={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:ed,run:td},rd={filter_keys:[]},id=k.observer(e=>{const t=le(),{value:n=rd,set:r}=R(e.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=m.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.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 ad(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const $n=[Qc,Wc,Xc,nd,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:id,run:ad}];class sd{constructor(t,n=$n){q(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 qt(a,"data")}};this.attachments=new Lr(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' 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(t){return this.operations.find(n=>n.id===t)}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(t,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(t);return!a||a.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Ss="__TRIGGERS";class od{constructor(t,n){q(this,"attachments");this.instance=t,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new qt(a,"data")}};this.attachments=new Lr(t,Ss,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Ss,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:te.toJS(x.get(a,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class Pr{constructor(t,n,r){q(this,"operationManager");q(this,"triggerManager");q(this,"attachments");this.operationManager=new sd(t,r),this.triggerManager=new od(t,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 Lr(t,"__INTERACTIONS",a)}async addInteraction(t,n){const r=t.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(t){const n=await this.attachments.getInstance(t);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(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===t);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 Xe=({vizManager:e,instance:t})=>Q.useCreation(()=>new Pr(t,e.resolveComponent(t.type),$n),[t,e]),_s=e=>{const{title:t="Variables",variables:n}=e,r=_e.useClipboard(),a=o=>{r.copy(o),Tn.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class ld{constructor(t,n){q(this,"operationId");q(this,"operation");q(this,"operationSchema");q(this,"variables",[]);this.operationManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function ud(e){return!!e.operationId}const cd=k.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:t,children:n})}),dd=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return m.createElement(e.operationSchema.configRender,t)}),pd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),hd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=e,c=Q.useCreation(()=>new ld(a,l),[a,l]);return Q.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),ud(c)?p(B,{children:[i(cd,{model:c,onClick:n}),i(s.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(pd,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(dd,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(_s,{title:"Variables",variables:c.variables})})]})]})})]}):null});class fd{constructor(t,n){q(this,"triggerId");q(this,"trigger");q(this,"triggerSchema");q(this,"sampleData");this.triggerManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return gd(this)}}function gd(e){return!!e.triggerId&&!!e.triggerSchema}function md(e,t){return Q.useCreation(()=>new fd(e,t),[e,t])}const yd=k.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return i(s.Button,{variant:"outline",onClick:t,children:m.createElement(n,r)})}),bd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),vd=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return m.createElement(e.triggerSchema.configRender,t)}),xd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=e.model;return p(B,{children:[i(s.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(bd,{model:a}),i(vd,{model:a}),i(_s,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(yd,{onClick:n,model:a})]})});function wd(e,t){const[n,r]=m.useState([]);return Q.useAsyncEffect(async()=>{const a=await e.getInteractionList();r(a)},[t,e]),n}const Cd=k.observer(({item:e,manager:t,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=md(t.triggerManager,n);if(Q.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(xd,{model:c}),i(hd,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:i(I.Trash,{size:16})})]})}return null}),Sd=e=>{const[t,n]=m.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=e,u=wd(r,t),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(_e.randomId(),r.triggerManager.getTriggerSchemaList()[0]),y=await r.operationManager.createOrGetOperation(_e.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,y),n(C=>C+1)};async function d(g){await r.removeInteraction(g.id),n(y=>y+1)}const{data:f=0,loading:h}=Q.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(I.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(Cd,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},_d=()=>{const{panel:e,data:t}=Ct(),n=e.viz,{vizManager:r}=m.useContext(ct),a=e.json,o=Q.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=Q.useCreation(()=>new Pr(o,r.resolveComponent(n.type),$n),[o,n.type]);return m.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},kd=()=>{const e=_d();return i(Sd,{...e})};function Ft({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Td(e,t){return Object.entries(e).map(([r,a])=>{const o=a.map(_=>_[t]).sort((_,D)=>_-D),l=tn.quantile(o,.25)??0,u=tn.quantile(o,.5)??0,c=tn.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),y=Math.min(x.last(o)??0,h),C=a.filter(_=>{const D=_[t];return D<g||D>y}).map(_=>[r,_[t],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:y,outliers:C}})}function Dd(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const a=P(n.data_key),o=P(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(t[a.queryID],a.columnKey),u=Td(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function Id({config:e}){return{...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const Or=["max","q3","median","q1","min"];function Md(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:Or,x:"name",itemName:["name"],tooltip:Or}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function Ad(e){const{outliers:t,min:n,max:r}=e,a=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>r).length,l=(u,c)=>`
|
|
61
|
+
`}function rt(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const Lr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:De},tooltip:{metrics:[]},color:"#228be6",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"}};function zt(e,t){return m.useMemo(()=>{const{queryID:n,columnKey:r}=P(t);return x.keyBy(e[n],r)},[e,t])}const Ke=(e,t)=>{const[n,r]=m.useState([]);return m.useEffect(()=>e.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===t))),[]),n};class qt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:x.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,t),u=x.get(o,t);l!==u&&n(l,u)},r)}}class Pr{constructor(t,n,r){q(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new qt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new qt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new qt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(x.values(t).map(n=>this.constructInstance(new qt(this.attachmentStorage,n.id))))}}function Nc(e,t){const{value:n,set:r}=R(e.operation.operationData,"config"),[a,o]=m.useState(x.defaults({},n,t)),l=async()=>{await r(a)};return m.useEffect(()=>{o(x.defaults({},n,t))},[n]),{config:a,setConfig:o,commit:l}}function qc(e){const{config:t,setConfig:n,commit:r}=Nc(e,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Fc(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class Gc extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Wc={displayName:"Open Link",id:"builtin:op:open-link",configRender:qc,run:Fc,migrator:new Gc,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function jc(e){const{value:t,set:n}=R(e.operationData,"config"),r=a=>void n({template:a});return[(t==null?void 0:t.template)||"",r]}function Rc(e){const[t,n]=jc(e.operation);return i(s.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Yc(e,t){const n=await t.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const Qc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Rc,run:Yc},Uc=k.observer(e=>{const t=le(),{value:n,set:r}=R(e.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:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Kc(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const Xc={displayName:"Open View",id:"builtin:op:open_view",configRender:Uc,run:Kc},Jc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Zc=({value:e="",onChange:t})=>{const[n,r]=m.useState(e);m.useEffect(()=>{r(e)},[e]);const a=()=>{t(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===e,children:i(E.IconDeviceFloppy,{})})})},Hc={dictionary:{}},ed=k.observer(e=>{const t=le(),{value:n=Hc,set:r}=R(e.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...t.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:Jc,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...t.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(Zc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function td(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const nd={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:ed,run:td},rd={filter_keys:[]},id=k.observer(e=>{const t=le(),{value:n=rd,set:r}=R(e.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=m.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.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 ad(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const $n=[Qc,Wc,Xc,nd,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:id,run:ad}];class sd{constructor(t,n=$n){q(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 qt(a,"data")}};this.attachments=new Pr(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' 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(t){return this.operations.find(n=>n.id===t)}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(t,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(t);return!a||a.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Ss="__TRIGGERS";class od{constructor(t,n){q(this,"attachments");this.instance=t,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new qt(a,"data")}};this.attachments=new Pr(t,Ss,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Ss,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:te.toJS(x.get(a,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class Or{constructor(t,n,r){q(this,"operationManager");q(this,"triggerManager");q(this,"attachments");this.operationManager=new sd(t,r),this.triggerManager=new od(t,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 Pr(t,"__INTERACTIONS",a)}async addInteraction(t,n){const r=t.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(t){const n=await this.attachments.getInstance(t);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(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===t);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 Xe=({vizManager:e,instance:t})=>Q.useCreation(()=>new Or(t,e.resolveComponent(t.type),$n),[t,e]),_s=e=>{const{title:t="Variables",variables:n}=e,r=_e.useClipboard(),a=o=>{r.copy(o),Tn.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class ld{constructor(t,n){q(this,"operationId");q(this,"operation");q(this,"operationSchema");q(this,"variables",[]);this.operationManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function ud(e){return!!e.operationId}const cd=k.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:t,children:n})}),dd=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return m.createElement(e.operationSchema.configRender,t)}),pd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),hd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=e,c=Q.useCreation(()=>new ld(a,l),[a,l]);return Q.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),ud(c)?p(B,{children:[i(cd,{model:c,onClick:n}),i(s.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(pd,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(dd,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(_s,{title:"Variables",variables:c.variables})})]})]})})]}):null});class fd{constructor(t,n){q(this,"triggerId");q(this,"trigger");q(this,"triggerSchema");q(this,"sampleData");this.triggerManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return gd(this)}}function gd(e){return!!e.triggerId&&!!e.triggerSchema}function md(e,t){return Q.useCreation(()=>new fd(e,t),[e,t])}const yd=k.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return i(s.Button,{variant:"outline",onClick:t,children:m.createElement(n,r)})}),bd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),vd=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return m.createElement(e.triggerSchema.configRender,t)}),xd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=e.model;return p(B,{children:[i(s.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(bd,{model:a}),i(vd,{model:a}),i(_s,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(yd,{onClick:n,model:a})]})});function wd(e,t){const[n,r]=m.useState([]);return Q.useAsyncEffect(async()=>{const a=await e.getInteractionList();r(a)},[t,e]),n}const Cd=k.observer(({item:e,manager:t,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=md(t.triggerManager,n);if(Q.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(xd,{model:c}),i(hd,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:i(I.Trash,{size:16})})]})}return null}),Sd=e=>{const[t,n]=m.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=e,u=wd(r,t),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(_e.randomId(),r.triggerManager.getTriggerSchemaList()[0]),y=await r.operationManager.createOrGetOperation(_e.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,y),n(C=>C+1)};async function d(g){await r.removeInteraction(g.id),n(y=>y+1)}const{data:f=0,loading:h}=Q.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(I.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(Cd,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},_d=()=>{const{panel:e,data:t}=Ct(),n=e.viz,{vizManager:r}=m.useContext(ct),a=e.json,o=Q.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=Q.useCreation(()=>new Or(o,r.resolveComponent(n.type),$n),[o,n.type]);return m.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},kd=()=>{const e=_d();return i(Sd,{...e})};function Ft({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Td(e,t){return Object.entries(e).map(([r,a])=>{const o=a.map(_=>_[t]).sort((_,D)=>_-D),l=tn.quantile(o,.25)??0,u=tn.quantile(o,.5)??0,c=tn.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),y=Math.min(x.last(o)??0,h),C=a.filter(_=>{const D=_[t];return D<g||D>y}).map(_=>[r,_[t],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:y,outliers:C}})}function Dd(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const a=P(n.data_key),o=P(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(t[a.queryID],a.columnKey),u=Td(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function Id({config:e}){return{...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const Br=["max","q3","median","q1","min"];function Md(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:Br,x:"name",itemName:["name"],tooltip:Br}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function Ad(e){const{outliers:t,min:n,max:r}=e,a=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>r).length,l=(u,c)=>`
|
|
62
62
|
<tr>
|
|
63
63
|
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
64
64
|
<td style="text-align: left; padding: 0 1em;">
|
|
65
65
|
${c}
|
|
66
66
|
</td>
|
|
67
67
|
</tr>
|
|
68
|
-
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const zd=(e,t)=>{const n=
|
|
68
|
+
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const zd=(e,t)=>{const n=Br.map(l=>`
|
|
69
69
|
<tr>
|
|
70
70
|
<th style="text-align: right; padding: 0 1em;">${x.capitalize(l)}</th>
|
|
71
71
|
<td style="text-align: left; padding: 0 1em;">
|
|
@@ -97,13 +97,13 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
97
97
|
${r.join("")}
|
|
98
98
|
</tbody>
|
|
99
99
|
</table>
|
|
100
|
-
`}const Ld=e=>t=>{const{componentSubType:n,value:r}=t;return n==="scatter"?$d(e,r):zd(e,r)};function Pd({config:e}){return{trigger:"item",confine:!0,formatter:Ld(e)}}const un=m.forwardRef(function({value:t,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:t,onChange:n,...r})}),Br={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(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.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 Ts(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=e.child(--a),u=t.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=Ts(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let r=0;r<t.length;r++)this.size+=t[r].nodeSize}nodesBetween(t,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>t&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,t-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,a){let o="",l=!0;return this.nodesBetween(t,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(t,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(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.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<t.content.length;o++)a.push(t.content[o]);return new ae(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>t&&((l<t||c>n)&&(u.isText?u=u.cut(Math.max(0,t-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,t-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(t,n){return t==n?ae.empty:t==0&&n==this.content.length?this:new ae(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new ae(a,o)}addToStart(t){return new ae([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new ae(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.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(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];t(a,r,n),r+=a.nodeSize}}findDiffStart(t,n=0){return ks(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Ts(this,t,n,r)}findIndex(t,n=-1){if(t==0)return Ln(0,t);if(t==this.size)return Ln(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=t)return l==t||n>0?Ln(r+1,l):Ln(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return ae.empty;let n,r=0;for(let a=0;a<t.length;a++){let o=t[a];r+=o.nodeSize,a&&o.isText&&t[a-1].sameMarkup(o)?(n||(n=t.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||t,r)}static from(t){if(!t)return ae.empty;if(t instanceof ae)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new ae([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const Vr={index:0,offset:0};function Ln(e,t){return Vr.index=e,Vr.offset=t,Vr}function Nr(e,t){if(e===t)return!0;if(!(e&&typeof e=="object")||!(t&&typeof t=="object"))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!Nr(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!Nr(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class je{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let a=0;a<t.length;a++){let o=t[a];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,a));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=t.slice()),r||n.push(this),n}removeFromSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return t.slice(0,n).concat(t.slice(n+1));return t}isInSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return!0;return!1}eq(t){return this==t||this.type==t.type&&Nr(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let n in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=t.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(t,n){if(t==n)return!0;if(t.length!=n.length)return!1;for(let r=0;r<t.length;r++)if(!t[r].eq(n[r]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return je.none;if(t instanceof je)return[t];let n=t.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}je.none=[];class Od extends Error{}class ce{constructor(t,n,r){this.content=t,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Is(this.content,t+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ce(Ds(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,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(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let o=t.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=t.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(t,r,a)}}ce.empty=new ce(ae.empty,0,0);function Ds(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(a==t||o.isText){if(u!=n&&!e.child(l).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy(Ds(o.content,t-a-1,n-a-1)))}function Is(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),l=e.maybeChild(a);if(o==t||l.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=Is(l.content,t-o-1,n);return u&&e.replaceChild(a,l.copy(u))}class Pn{constructor(t,n){this.schema=t,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=t.nodes[r.node];return a.contentMatch.matchType(a)})}parse(t,n={}){let r=new Es(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new Es(this,n,!0);return r.addAll(t,n.from,n.to),ce.maxOpen(r.finish())}matchTag(t,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Nd(t,o.tag)&&(o.namespace===void 0||t.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(t,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(t)!=0||l.context&&!r.matchesContext(l.context)||u.length>t.length&&(u.charCodeAt(t.length)!=61||u.slice(t.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(t){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 t.marks){let o=t.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=$s(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in t.nodes){let o=t.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=$s(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Pn(t,Pn.schemaRules(t)))}}const Ms={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},Bd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},As={ol:!0,ul:!0},On=1,Bn=2,cn=4;function zs(e,t,n){return t!=null?(t?On:0)|(t==="full"?Bn:0):e&&e.whitespace=="pre"?On|Bn:n&~cn}class Vn{constructor(t,n,r,a,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=je.none,this.stashMarks=[],this.match=l||(u&cn?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(t.type))?(this.match=r,a):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&On)){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!t&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(t){for(let n=this.stashMarks.length-1;n>=0;n--)if(t.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(t){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):Fd(a.type,t))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!Ms.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class Es{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=zs(null,n.preserveWhitespace,0)|(r?cn:0);a?o=new Vn(a.type,a.attrs,je.none,je.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Vn(null,null,je.none,je.none,!0,null,l):o=new Vn(t.schema.topNodeType,null,je.none,je.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t){if(t.nodeType==3)this.addTextNode(t);else if(t.nodeType==1){let n=t.getAttribute("style");if(!n)this.addElement(t);else{let r=this.readStyles(qd(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(t);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(t){let n=t.nodeValue,r=this.top;if(r.options&Bn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&On)r.options&Bn?n=n.replace(/\r\n?/g,`
|
|
100
|
+
`}const Ld=e=>t=>{const{componentSubType:n,value:r}=t;return n==="scatter"?$d(e,r):zd(e,r)};function Pd({config:e}){return{trigger:"item",confine:!0,formatter:Ld(e)}}const un=m.forwardRef(function({value:t,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:t,onChange:n,...r})}),Vr={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(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.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 Ts(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=e.child(--a),u=t.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=Ts(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let r=0;r<t.length;r++)this.size+=t[r].nodeSize}nodesBetween(t,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>t&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,t-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,a){let o="",l=!0;return this.nodesBetween(t,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(t,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(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.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<t.content.length;o++)a.push(t.content[o]);return new ae(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>t&&((l<t||c>n)&&(u.isText?u=u.cut(Math.max(0,t-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,t-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(t,n){return t==n?ae.empty:t==0&&n==this.content.length?this:new ae(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new ae(a,o)}addToStart(t){return new ae([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new ae(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.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(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];t(a,r,n),r+=a.nodeSize}}findDiffStart(t,n=0){return ks(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Ts(this,t,n,r)}findIndex(t,n=-1){if(t==0)return Ln(0,t);if(t==this.size)return Ln(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=t)return l==t||n>0?Ln(r+1,l):Ln(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return ae.empty;let n,r=0;for(let a=0;a<t.length;a++){let o=t[a];r+=o.nodeSize,a&&o.isText&&t[a-1].sameMarkup(o)?(n||(n=t.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||t,r)}static from(t){if(!t)return ae.empty;if(t instanceof ae)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new ae([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const Nr={index:0,offset:0};function Ln(e,t){return Nr.index=e,Nr.offset=t,Nr}function qr(e,t){if(e===t)return!0;if(!(e&&typeof e=="object")||!(t&&typeof t=="object"))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!qr(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!qr(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class je{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let a=0;a<t.length;a++){let o=t[a];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,a));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=t.slice()),r||n.push(this),n}removeFromSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return t.slice(0,n).concat(t.slice(n+1));return t}isInSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return!0;return!1}eq(t){return this==t||this.type==t.type&&qr(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let n in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=t.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(t,n){if(t==n)return!0;if(t.length!=n.length)return!1;for(let r=0;r<t.length;r++)if(!t[r].eq(n[r]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return je.none;if(t instanceof je)return[t];let n=t.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}je.none=[];class Od extends Error{}class ce{constructor(t,n,r){this.content=t,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Is(this.content,t+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ce(Ds(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,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(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let o=t.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=t.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(t,r,a)}}ce.empty=new ce(ae.empty,0,0);function Ds(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(a==t||o.isText){if(u!=n&&!e.child(l).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy(Ds(o.content,t-a-1,n-a-1)))}function Is(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),l=e.maybeChild(a);if(o==t||l.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=Is(l.content,t-o-1,n);return u&&e.replaceChild(a,l.copy(u))}class Pn{constructor(t,n){this.schema=t,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=t.nodes[r.node];return a.contentMatch.matchType(a)})}parse(t,n={}){let r=new Es(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new Es(this,n,!0);return r.addAll(t,n.from,n.to),ce.maxOpen(r.finish())}matchTag(t,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Nd(t,o.tag)&&(o.namespace===void 0||t.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(t,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(t)!=0||l.context&&!r.matchesContext(l.context)||u.length>t.length&&(u.charCodeAt(t.length)!=61||u.slice(t.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(t){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 t.marks){let o=t.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=$s(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in t.nodes){let o=t.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=$s(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Pn(t,Pn.schemaRules(t)))}}const Ms={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},Bd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},As={ol:!0,ul:!0},On=1,Bn=2,cn=4;function zs(e,t,n){return t!=null?(t?On:0)|(t==="full"?Bn:0):e&&e.whitespace=="pre"?On|Bn:n&~cn}class Vn{constructor(t,n,r,a,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=je.none,this.stashMarks=[],this.match=l||(u&cn?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(t.type))?(this.match=r,a):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&On)){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!t&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(t){for(let n=this.stashMarks.length-1;n>=0;n--)if(t.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(t){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):Fd(a.type,t))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!Ms.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class Es{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=zs(null,n.preserveWhitespace,0)|(r?cn:0);a?o=new Vn(a.type,a.attrs,je.none,je.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Vn(null,null,je.none,je.none,!0,null,l):o=new Vn(t.schema.topNodeType,null,je.none,je.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t){if(t.nodeType==3)this.addTextNode(t);else if(t.nodeType==1){let n=t.getAttribute("style");if(!n)this.addElement(t);else{let r=this.readStyles(qd(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(t);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(t){let n=t.nodeValue,r=this.top;if(r.options&Bn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&On)r.options&Bn?n=n.replace(/\r\n?/g,`
|
|
101
101
|
`):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=t.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(t)}else this.findInside(t)}addElement(t,n){let r=t.nodeName.toLowerCase(),a;As.hasOwnProperty(r)&&this.parser.normalizeLists&&Vd(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(a=this.parser.matchTag(t,this,n));if(o?o.ignore:Bd.hasOwnProperty(r))this.findInside(t),this.ignoreFallback(t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let l,u=this.top,c=this.needsBlock;if(Ms.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(!t.firstChild){this.leafFallback(t);return}this.addAll(t),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(t,o,o.consuming===!1?a:void 0)}leafFallback(t){t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode(`
|
|
102
|
-
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=je.none,r=je.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[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(t,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(t):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(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);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(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=zs(t,a,o.options);o.options&cn&&o.content.length==0&&(l|=cn),this.nodes.push(new Vn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!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(t));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(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.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 t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.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(t){let n=Gd(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function Vd(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&As.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Nd(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function qd(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function $s(e){let t={};for(let n in e)t[n]=e[n];return t}function Fd(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))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==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Gd(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const Ls=65535,Ps=Math.pow(2,16);function Wd(e,t){return e+t*Ps}function Os(e){return e&Ls}function jd(e){return(e-(e&Ls))/Ps}const Bs=1,Vs=2,Nn=4,Ns=8;class qs{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ns)>0}get deletedBefore(){return(this.delInfo&(Bs|Nn))>0}get deletedAfter(){return(this.delInfo&(Vs|Nn))>0}get deletedAcross(){return(this.delInfo&Nn)>0}}class Je{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Je.empty)return Je.empty}recover(t){let n=0,r=Os(t);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+jd(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,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>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,y=c+a+(g<0?0:f);if(r)return y;let C=t==(n<0?c:h)?null:Wd(u/3,t-c),w=t==c?Vs:t==h?Bs:Nn;return(n<0?t!=c:t!=h)&&(w|=Ns),new qs(y,w,C)}a+=f-d}return r?t+a:new qs(t+a,0,null)}touches(t,n){let r=0,a=Os(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>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){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];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Je.empty:new Je(t<0?[0,-t,0]:[0,0,t])}}Je.empty=new Je([]);const qr=Object.create(null);class Ve{getMap(){return Je.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=qr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in qr)throw new RangeError("Duplicate use of step JSON ID "+t);return qr[t]=n,n.prototype.jsonID=t,n}}class Ce{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new Ce(t,null)}static fail(t){return new Ce(null,t)}static fromReplace(t,n,r,a){try{return Ce.ok(t.replace(n,r,a))}catch(o){if(o instanceof Od)return Ce.fail(o.message);throw o}}}function Fr(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(Fr(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ae.fromArray(r)}class Et extends Ve{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Fr(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 Ce.fromReplace(t,this.from,this.to,o)}invert(){return new $t(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Et(n.pos,r.pos,this.mark)}merge(t){return t instanceof Et&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Et(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Et(n.from,n.to,t.markFromJSON(n.mark))}}Ve.jsonID("addMark",Et);class $t extends Ve{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce(Fr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return Ce.fromReplace(t,this.from,this.to,r)}invert(){return new Et(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new $t(n.pos,r.pos,this.mark)}merge(t){return t instanceof $t&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new $t(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new $t(n.from,n.to,t.markFromJSON(n.mark))}}Ve.jsonID("removeMark",$t);class Lt extends Ve{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.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 Lt(this.pos,n.marks[a]);return new Lt(this.pos,this.mark)}}return new dn(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Lt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Lt(n.pos,t.markFromJSON(n.mark))}}Ve.jsonID("addNodeMark",Lt);class dn extends Ve{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Lt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new dn(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new dn(n.pos,t.markFromJSON(n.mark))}}Ve.jsonID("removeNodeMark",dn);class lt extends Ve{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Gr(t,this.from,this.to)?Ce.fail("Structure replace would overwrite content"):Ce.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Je([this.from,this.to-this.from,this.slice.size])}invert(t){return new lt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new lt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof lt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new lt(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new lt(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new lt(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}Ve.jsonID("replace",lt);class Pt extends Ve{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Gr(t,this.from,this.gapFrom)||Gr(t,this.gapTo,this.to)))return Ce.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Ce.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Ce.fromReplace(t,this.from,this.to,r):Ce.fail("Content does not fit in gap")}getMap(){return new Je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Pt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Pt(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,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 Pt(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ve.jsonID("replaceAround",Pt);function Gr(e,t,n){let r=e.resolve(t),a=n-t,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 Rd(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Yd(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!Rd(a,o,l))break}return null}function qn(e,t,n=1,r){let a=e.resolve(t),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 y=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(y=y.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(y))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 Fs(e,t){let n=e.resolve(t),r=n.index();return Qd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Qd(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class pn extends Ve{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.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 Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Je.empty}invert(t){return new pn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new pn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new pn(n.pos,n.attr,n.value)}}Ve.jsonID("attr",pn);let hn=class extends Error{};hn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},hn.prototype=Object.create(Error.prototype),hn.prototype.constructor=hn,hn.prototype.name="TransformError";const Wr=Object.create(null);class fe{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Ud(t.min(n),t.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 t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,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=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&js(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),js(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new Se(t):Gt(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Gt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Gt(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new mt(t.node(0))}static atStart(t){return Gt(t,t,0,0,1)||new mt(t)}static atEnd(t){return Gt(t,t,t.content.size,t.childCount,-1)||new mt(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Wr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Wr)throw new RangeError("Duplicate use of selection JSON ID "+t);return Wr[t]=n,n.prototype.jsonID=t,n}getBookmark(){return Se.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class Ud{constructor(t,n){this.$from=t,this.$to=n}}let Gs=!1;function Ws(e){!Gs&&!e.parent.inlineContent&&(Gs=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class Se extends fe{constructor(t,n=t){Ws(t),Ws(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=t.resolve(n.map(this.anchor));return new Se(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof Se&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Fn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new Se(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.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 t.parent.inlineContent||(a==0?t=n:(t=(fe.findFrom(t,-r,!0)||fe.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new Se(t,n)}}fe.jsonID("text",Se);class Fn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Fn(t.map(this.anchor),t.map(this.head))}resolve(t){return Se.between(t.resolve(this.anchor),t.resolve(this.head))}}class Re extends fe{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?fe.near(o):new Re(o)}content(){return new ce(ae.from(this.node),0,0)}eq(t){return t instanceof Re&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new jr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Re(t.resolve(n.anchor))}static create(t,n){return new Re(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Re.prototype.visible=!1,fe.jsonID("node",Re);class jr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Fn(r,r):new jr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Re.isSelectable(r)?new Re(n):fe.near(n)}}class mt extends fe{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=fe.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new mt(t)}map(t){return new mt(t)}eq(t){return t instanceof mt}getBookmark(){return Kd}}fe.jsonID("all",mt);const Kd={map(){return this},resolve(e){return new mt(e)}};function Gt(e,t,n,r,a,o=!1){if(t.inlineContent)return Se.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Re.isSelectable(u))return Re.create(e,n-(a<0?u.nodeSize:0))}else{let c=Gt(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function js(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof lt||a instanceof Pt))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}function Rs(e,t){return!t||!e?e:e.bind(t)}class Gn{constructor(t,n,r){this.name=t,this.init=Rs(n.init,r),this.apply=Rs(n.apply,r)}}new Gn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Gn("selection",{init(e,t){return e.selection||fe.atStart(t.doc)},apply(e){return e.selection}}),new Gn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Gn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Ys(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Ys(a,t,{})),n[r]=a}return n}class fn{constructor(t){this.spec=t,this.props={},t.props&&Ys(t.props,this,this.props),this.key=t.key?t.key.key:Qs("plugin")}getState(t){return t[this.key]}}const Rr=Object.create(null);function Qs(e){return e in Rr?e+"$"+ ++Rr[e]:(Rr[e]=0,e+"$")}class gn{constructor(t="key"){this.key=Qs(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function Us(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),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 Xd{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).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(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||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,y])=>[g,(...w)=>{const _=this.buildProps(d,n),D=y(...w)(_);return u.push(D),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||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(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:Us({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function St(e,t,n){return e.config[t]===void 0&&e.parent?St(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?St(e.parent,t,n):null}):e.config[t]}function Jd(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Me(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function Zd(e){return typeof e=="function"}function Wt(e,t=void 0,...n){return Zd(e)?t?e.bind(t)(...n):e(...n):e}function Hd(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function ep(e){return Object.prototype.toString.call(e).slice(8,-1)}function Yr(e){return ep(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Ks(e,t){const n={...e};return Yr(e)&&Yr(t)&&Object.keys(t).forEach(r=>{Yr(t[r])?r in e?n[r]=Ks(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class ut{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.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=Wt(St(this,"addOptions",{name:this.name}))),this.storage=Wt(St(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new ut(t)}configure(t={}){const n=this.extend();return n.options=Ks(this.options,t),n.storage=Wt(St(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new ut(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Wt(St(n,"addOptions",{name:n.name})),n.storage=Wt(St(n,"addStorage",{name:n.name,options:n.options})),n}}function tp(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
|
|
102
|
+
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=je.none,r=je.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[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(t,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(t):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(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);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(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=zs(t,a,o.options);o.options&cn&&o.content.length==0&&(l|=cn),this.nodes.push(new Vn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!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(t));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(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.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 t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.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(t){let n=Gd(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function Vd(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&As.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Nd(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function qd(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function $s(e){let t={};for(let n in e)t[n]=e[n];return t}function Fd(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))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==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Gd(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const Ls=65535,Ps=Math.pow(2,16);function Wd(e,t){return e+t*Ps}function Os(e){return e&Ls}function jd(e){return(e-(e&Ls))/Ps}const Bs=1,Vs=2,Nn=4,Ns=8;class qs{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ns)>0}get deletedBefore(){return(this.delInfo&(Bs|Nn))>0}get deletedAfter(){return(this.delInfo&(Vs|Nn))>0}get deletedAcross(){return(this.delInfo&Nn)>0}}class Je{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Je.empty)return Je.empty}recover(t){let n=0,r=Os(t);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+jd(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,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>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,y=c+a+(g<0?0:f);if(r)return y;let C=t==(n<0?c:h)?null:Wd(u/3,t-c),w=t==c?Vs:t==h?Bs:Nn;return(n<0?t!=c:t!=h)&&(w|=Ns),new qs(y,w,C)}a+=f-d}return r?t+a:new qs(t+a,0,null)}touches(t,n){let r=0,a=Os(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>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){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];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Je.empty:new Je(t<0?[0,-t,0]:[0,0,t])}}Je.empty=new Je([]);const Fr=Object.create(null);class Ve{getMap(){return Je.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Fr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Fr)throw new RangeError("Duplicate use of step JSON ID "+t);return Fr[t]=n,n.prototype.jsonID=t,n}}class Ce{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new Ce(t,null)}static fail(t){return new Ce(null,t)}static fromReplace(t,n,r,a){try{return Ce.ok(t.replace(n,r,a))}catch(o){if(o instanceof Od)return Ce.fail(o.message);throw o}}}function Gr(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(Gr(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ae.fromArray(r)}class Et extends Ve{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Gr(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 Ce.fromReplace(t,this.from,this.to,o)}invert(){return new $t(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Et(n.pos,r.pos,this.mark)}merge(t){return t instanceof Et&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Et(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Et(n.from,n.to,t.markFromJSON(n.mark))}}Ve.jsonID("addMark",Et);class $t extends Ve{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce(Gr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return Ce.fromReplace(t,this.from,this.to,r)}invert(){return new Et(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new $t(n.pos,r.pos,this.mark)}merge(t){return t instanceof $t&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new $t(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new $t(n.from,n.to,t.markFromJSON(n.mark))}}Ve.jsonID("removeMark",$t);class Lt extends Ve{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.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 Lt(this.pos,n.marks[a]);return new Lt(this.pos,this.mark)}}return new dn(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Lt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Lt(n.pos,t.markFromJSON(n.mark))}}Ve.jsonID("addNodeMark",Lt);class dn extends Ve{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Lt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new dn(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new dn(n.pos,t.markFromJSON(n.mark))}}Ve.jsonID("removeNodeMark",dn);class lt extends Ve{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Wr(t,this.from,this.to)?Ce.fail("Structure replace would overwrite content"):Ce.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Je([this.from,this.to-this.from,this.slice.size])}invert(t){return new lt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new lt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof lt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new lt(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new lt(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new lt(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}Ve.jsonID("replace",lt);class Pt extends Ve{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Wr(t,this.from,this.gapFrom)||Wr(t,this.gapTo,this.to)))return Ce.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Ce.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Ce.fromReplace(t,this.from,this.to,r):Ce.fail("Content does not fit in gap")}getMap(){return new Je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Pt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Pt(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,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 Pt(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ve.jsonID("replaceAround",Pt);function Wr(e,t,n){let r=e.resolve(t),a=n-t,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 Rd(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Yd(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!Rd(a,o,l))break}return null}function qn(e,t,n=1,r){let a=e.resolve(t),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 y=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(y=y.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(y))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 Fs(e,t){let n=e.resolve(t),r=n.index();return Qd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Qd(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class pn extends Ve{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.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 Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Je.empty}invert(t){return new pn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new pn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new pn(n.pos,n.attr,n.value)}}Ve.jsonID("attr",pn);let hn=class extends Error{};hn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},hn.prototype=Object.create(Error.prototype),hn.prototype.constructor=hn,hn.prototype.name="TransformError";const jr=Object.create(null);class fe{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Ud(t.min(n),t.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 t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,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=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&js(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),js(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new Se(t):Gt(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Gt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Gt(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new mt(t.node(0))}static atStart(t){return Gt(t,t,0,0,1)||new mt(t)}static atEnd(t){return Gt(t,t,t.content.size,t.childCount,-1)||new mt(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=jr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in jr)throw new RangeError("Duplicate use of selection JSON ID "+t);return jr[t]=n,n.prototype.jsonID=t,n}getBookmark(){return Se.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class Ud{constructor(t,n){this.$from=t,this.$to=n}}let Gs=!1;function Ws(e){!Gs&&!e.parent.inlineContent&&(Gs=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class Se extends fe{constructor(t,n=t){Ws(t),Ws(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=t.resolve(n.map(this.anchor));return new Se(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof Se&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Fn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new Se(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.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 t.parent.inlineContent||(a==0?t=n:(t=(fe.findFrom(t,-r,!0)||fe.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new Se(t,n)}}fe.jsonID("text",Se);class Fn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Fn(t.map(this.anchor),t.map(this.head))}resolve(t){return Se.between(t.resolve(this.anchor),t.resolve(this.head))}}class Re extends fe{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?fe.near(o):new Re(o)}content(){return new ce(ae.from(this.node),0,0)}eq(t){return t instanceof Re&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Rr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Re(t.resolve(n.anchor))}static create(t,n){return new Re(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Re.prototype.visible=!1,fe.jsonID("node",Re);class Rr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Fn(r,r):new Rr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Re.isSelectable(r)?new Re(n):fe.near(n)}}class mt extends fe{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=fe.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new mt(t)}map(t){return new mt(t)}eq(t){return t instanceof mt}getBookmark(){return Kd}}fe.jsonID("all",mt);const Kd={map(){return this},resolve(e){return new mt(e)}};function Gt(e,t,n,r,a,o=!1){if(t.inlineContent)return Se.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Re.isSelectable(u))return Re.create(e,n-(a<0?u.nodeSize:0))}else{let c=Gt(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function js(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof lt||a instanceof Pt))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}function Rs(e,t){return!t||!e?e:e.bind(t)}class Gn{constructor(t,n,r){this.name=t,this.init=Rs(n.init,r),this.apply=Rs(n.apply,r)}}new Gn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Gn("selection",{init(e,t){return e.selection||fe.atStart(t.doc)},apply(e){return e.selection}}),new Gn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Gn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Ys(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Ys(a,t,{})),n[r]=a}return n}class fn{constructor(t){this.spec=t,this.props={},t.props&&Ys(t.props,this,this.props),this.key=t.key?t.key.key:Qs("plugin")}getState(t){return t[this.key]}}const Yr=Object.create(null);function Qs(e){return e in Yr?e+"$"+ ++Yr[e]:(Yr[e]=0,e+"$")}class gn{constructor(t="key"){this.key=Qs(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function Us(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),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 Xd{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).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(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||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,y])=>[g,(...w)=>{const _=this.buildProps(d,n),D=y(...w)(_);return u.push(D),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||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(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:Us({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function St(e,t,n){return e.config[t]===void 0&&e.parent?St(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?St(e.parent,t,n):null}):e.config[t]}function Jd(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Me(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function Zd(e){return typeof e=="function"}function Wt(e,t=void 0,...n){return Zd(e)?t?e.bind(t)(...n):e(...n):e}function Hd(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function ep(e){return Object.prototype.toString.call(e).slice(8,-1)}function Qr(e){return ep(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Ks(e,t){const n={...e};return Qr(e)&&Qr(t)&&Object.keys(t).forEach(r=>{Qr(t[r])?r in e?n[r]=Ks(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class ut{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.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=Wt(St(this,"addOptions",{name:this.name}))),this.storage=Wt(St(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new ut(t)}configure(t={}){const n=this.extend();return n.options=Ks(this.options,t),n.storage=Wt(St(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new ut(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Wt(St(n,"addOptions",{name:n.name})),n.storage=Wt(St(n,"addStorage",{name:n.name,options:n.options})),n}}function tp(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
|
|
103
103
|
|
|
104
|
-
`,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var y;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(y=d==null?void 0:d.text)===null||y===void 0?void 0:y.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function np(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}ut.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new fn({key:new gn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=np(n);return tp(r,{from:l,to:u},{textSerializers:c})}}})]}});const rp=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),ip=(e=!1)=>({commands:t})=>t.setContent("",e),ap=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),y=h.blockRange(g);if(!y)return;const C=Yd(y);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(y.start,w)}(C||C===0)&&t.lift(y,C)})}),!0},sp=e=>t=>e(t),op=()=>({state:e,dispatch:t})=>ke.createParagraphNear(e,t),lp=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},up=e=>({tr:t,state:n,dispatch:r})=>{const a=Me(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},cp=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},dp=()=>({state:e,dispatch:t})=>ke.deleteSelection(e,t),pp=()=>({commands:e})=>e.keyboardShortcut("Enter"),hp=()=>({state:e,dispatch:t})=>ke.exitCode(e,t);function Wn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:Hd(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function Qr(e,t,n={}){return e.find(r=>r.type===t&&Wn(r.attrs,n))}function fp(e,t,n={}){return!!Qr(e,t,n)}function Xs(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=Qr([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Qr([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&fp([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function _t(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const gp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=_t(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=Xs(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=Se.create(l,h.from,h.to);n.setSelection(g)}}return!0},mp=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function Js(e){return e instanceof Se}function Ot(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function yp(e,t=null){if(!t)return null;const n=fe.atStart(e),r=fe.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?Se.create(e,Ot(0,a,o),Ot(e.content.size,a,o)):Se.create(e,Ot(t,a,o),Ot(t,a,o))}function Ur(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const bp=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Ur()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!Js(n.state.selection))return l(),!0;const u=yp(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},vp=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),xp=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Zs(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function jn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ae.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),jn("",t,n)}if(typeof e=="string"){const r=Pn.fromSchema(t);return n.slice?r.parseSlice(Zs(e),n.parseOptions).content:r.parse(Zs(e),n.parseOptions)}return jn("",t,n)}function wp(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof lt||a instanceof Pt))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}const Cp=e=>e.toString().startsWith("<"),Sp=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=jn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((Cp(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&wp(r,r.steps.length-1,-1)}return!0},_p=()=>({state:e,dispatch:t})=>ke.joinUp(e,t),kp=()=>({state:e,dispatch:t})=>ke.joinDown(e,t),Tp=()=>({state:e,dispatch:t})=>ke.joinBackward(e,t),Dp=()=>({state:e,dispatch:t})=>ke.joinForward(e,t);function Hs(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ip(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Ur()||Hs()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Mp=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=Ip(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Kr(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Me(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const y=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:y,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Wn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const Ap=(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return Kr(n,a,t)?ke.lift(n,r):!1},zp=()=>({state:e,dispatch:t})=>ke.liftEmptyBlock(e,t),Ep=e=>({state:t,dispatch:n})=>{const r=Me(e,t.schema);return br.liftListItem(r)(t,n)},$p=()=>({state:e,dispatch:t})=>ke.newlineInCode(e,t);function eo(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function to(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const Lp=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=eo(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Me(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,to(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(to(h.attrs,t)))})})}),!0):!1},Pp=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Op=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Bp=()=>({state:e,dispatch:t})=>ke.selectNodeBackward(e,t),Vp=()=>({state:e,dispatch:t})=>ke.selectNodeForward(e,t),Np=()=>({state:e,dispatch:t})=>ke.selectParentNode(e,t),qp=()=>({state:e,dispatch:t})=>ke.selectTextblockEnd(e,t),Fp=()=>({state:e,dispatch:t})=>ke.selectTextblockStart(e,t);function Gp(e,t,n={}){return jn(e,t,{slice:!1,parseOptions:n})}const Wp=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Gp(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function jp(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Rp(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Xr(e){return t=>Rp(t.$from,e)}function Yp(e,t){const n=_t(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Rn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function Qp(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?_t(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Wn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const y=h.pos,C=g.pos;e.doc.nodesBetween(y,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const D=Math.max(y,_),M=Math.min(C,_+w.nodeSize),O=M-D;l+=O,u.push(...w.marks.map(G=>({mark:G,from:D,to:M})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Wn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function no(e,t){const{nodeExtensions:n}=Jd(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Wt(St(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Up(e,t,n){var r;const{selection:a}=t;let o=null;if(Js(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const y=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=y&&C}return!d}),d})}const Kp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=_t(e,r.schema);if(a)if(l){const d=Yp(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,y)=>{const C=Math.max(y,f),w=Math.min(y+g.nodeSize,h);g.marks.find(D=>D.type===c)?g.marks.forEach(D=>{c===D.type&&n.addMark(C,w,c.create({...D.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Up(r,n,c)},Xp=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Jp=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Me(e,n.schema);return o.isTextblock?a().command(({commands:l})=>ke.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>ke.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Zp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=Ot(e,0,r.content.size),o=Re.create(r,a);t.setSelection(o)}return!0},Hp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=Se.atStart(r).from,u=Se.atEnd(r).to,c=Ot(a,l,u),d=Ot(o,l,u),f=Se.create(r,c,d);t.setSelection(f)}return!0},eh=e=>({state:t,dispatch:n})=>{const r=Me(e,t.schema);return br.sinkListItem(r)(t,n)};function ro(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const th=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=Rn(d,u.node().type.name,u.node().attrs);if(o instanceof Re&&o.node.isBlock)return!u.parentOffset||!qn(l,u.pos)?!1:(r&&(e&&ro(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof Se&&t.deleteSelection();const g=u.depth===0?void 0:jp(u.node(-1).contentMatchAt(u.indexAfter(-1)));let y=h&&g?[{type:g,attrs:f}]:void 0,C=qn(t.doc,t.mapping.map(u.pos),1,y);if(!y&&!C&&qn(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,y=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,y),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&ro(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},nh=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Me(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const D=u.index(-1)?1:u.index(-2)?2:3;for(let A=u.depth-D;A>=u.depth-3;A-=1)_=ae.from(u.node(A).copy(_));const M=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,O=Rn(h,u.node().type.name,u.node().attrs),G=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(ae.from(l.createAndFill(null,G)||void 0));const $=u.before(u.depth-(D-1));t.replace($,u.after(-M),new ce(_,4-D,0));let L=-1;t.doc.nodesBetween($,t.doc.content.size,(A,N)=>{if(L>-1)return!1;A.isTextblock&&A.content.size===0&&(L=N+1)}),L>-1&&t.setSelection(Se.near(t.doc.resolve(L))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,y=Rn(h,f.type.name,f.attrs),C=Rn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:y},{type:g,attrs:C}]:[{type:l,attrs:y}];if(!qn(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:D}=n,{splittableMarks:M}=a.extensionManager,O=D||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!O||!r)return!0;const G=O.filter($=>M.includes($.type.name));t.ensureMarks(G)}return!0},Jr=(e,t)=>{const n=Xr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Fs(e.doc,n.pos)&&e.join(n.pos),!0},Zr=(e,t)=>{const n=Xr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Fs(e.doc,r)&&e.join(r),!0};var rh=Object.freeze({__proto__:null,blur:rp,clearContent:ip,clearNodes:ap,command:sp,createParagraphNear:op,deleteCurrentNode:lp,deleteNode:up,deleteRange:cp,deleteSelection:dp,enter:pp,exitCode:hp,extendMarkRange:gp,first:mp,focus:bp,forEach:vp,insertContent:xp,insertContentAt:Sp,joinUp:_p,joinDown:kp,joinBackward:Tp,joinForward:Dp,keyboardShortcut:Mp,lift:Ap,liftEmptyBlock:zp,liftListItem:Ep,newlineInCode:$p,resetAttributes:Lp,scrollIntoView:Pp,selectAll:Op,selectNodeBackward:Bp,selectNodeForward:Vp,selectParentNode:Np,selectTextblockEnd:qp,selectTextblockStart:Fp,setContent:Wp,setMark:Kp,setMeta:Xp,setNode:Jp,setNodeSelection:Zp,setTextSelection:Hp,sinkListItem:eh,splitBlock:th,splitListItem:nh,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,y=Me(e,l.schema),C=Me(t,l.schema),{selection:w,storedMarks:_}=l,{$from:D,$to:M}=w,O=D.blockRange(M),G=_||w.$to.parentOffset&&w.$from.marks();if(!O)return!1;const $=Xr(L=>no(L.type.name,h))(w);if(O.depth>=1&&$&&O.depth-$.depth<=1){if($.node.type===y)return d.liftListItem(C);if(no($.node.type.name,h)&&y.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,y),!0)).command(()=>Jr(o,y)).command(()=>Zr(o,y)).run()}return!n||!G||!u?c().command(()=>f().wrapInList(y,r)?!0:d.clearNodes()).wrapInList(y,r).command(()=>Jr(o,y)).command(()=>Zr(o,y)).run():c().command(()=>{const L=f().wrapInList(y,r),A=G.filter(N=>g.includes(N.type.name));return o.ensureMarks(A),L?!0:d.clearNodes()}).wrapInList(y,r).command(()=>Jr(o,y)).command(()=>Zr(o,y)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=_t(e,r.schema);return Qp(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Me(e,r.schema),l=Me(t,r.schema);return Kr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Me(e,n.schema);return Kr(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=_t(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:y}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=Xs(d,c,C);w&&(g=w.from,y=w.to),n.removeMark(g,y,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=eo(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Me(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(y=>{if(l===y.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...y.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return ke.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return br.wrapInList(a,t)(n,r)}});ut.create({name:"commands",addCommands(){return{...rh}}}),ut.create({name:"editable",addProseMirrorPlugins(){return[new fn({key:new gn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ut.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new fn({key:new gn("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),ut.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:y}=h,C=fe.atStart(d).from===g;return!f||!C||!y.type.isTextblock||y.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Ur()||Hs()?o:a},addProseMirrorPlugins(){return[new fn({key:new gn("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=fe.atStart(t.doc).from,c=fe.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=Us({state:n,transaction:h}),{commands:y}=new Xd({editor:this.editor,state:g});if(y.clearNodes(),!!h.steps.length)return h}})]}}),ut.create({name:"tabindex",addProseMirrorPlugins(){return[new fn({key:new gn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const io=ut.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ih=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),ah=[{label:"auto",value:""}].concat(ih.map(e=>({label:e,value:e}))),sh={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},oh=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(E.IconTextSize,{stroke:1.5,size:16}),data:ah,styles:sh,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Yn=({value:e,styles:t={}})=>{const n=Xa.useEditor({extensions:[Ja,Ka,J.Link,Ga,Fa,Na,Ra.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ua,Qa,Ya,Wa.configure({types:["heading","paragraph"]}),qa.configure({placeholder:"This is placeholder"}),ja,Va.Color,io],content:e,editable:!1});m.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=m.useMemo(()=>x.defaultsDeep({},{content:Br},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function lh(){const[e,{open:t,close:n}]=_e.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:i(Yn,{value:rc,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i(E.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const uh=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Te,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},mn=m.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=m.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};m.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(lh,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(uh,{value:o,onChange:l})]})}),ch=m.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:d}]=_e.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:u,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:i(s.Box,{h:600,children:i(mn,{value:e,onChange:t,defaultValue:o,label:n})})}),i(s.Button,{onClick:c,...a,children:r})]})}),ao=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
-
`),jt={type:"none",config:{}};function dh(e){const t=Array.from(e).sort((r,a)=>r-a),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function ph(e){const t=Number(e);return isFinite(t)?t:0}function hh(e,t){switch(t.type){case"sum":return x.sum(e);case"mean":return x.mean(e);case"median":return dh(e);case"max":return x.max(e)??0;case"min":return x.min(e)??0;case"quantile":return tn.quantile(e,t.config.p)??0;case"CV":const n=In.std(...e),r=In.mean(...e);return r?n/r:"N/A";case"std":return In.std(...e);default:return e}}function
|
|
106
|
-
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[Dh(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function ei(e){return Ih(e)}function yn(e,t,n){const r=Th(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return ei(o);const c=r[u[1]];if(!c)return ei(o);const d=u[2]??"";return p(m.Fragment,{children:[c,ei(d)]},`${o}-${l}`)})}function Mh(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Qn(t,o,l);n[a]=Ze(r,u)}),n}function Xn(e,t,n){const r=Mh(t,n),a=/^\{(.+)\}(.*)$/;return e.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 Ah(e,t,n){const r=t.reduce((a,o)=>{const l=yt(o,n);return a[o.name]=Ze(o,l),a},{});return e.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 Xn(a.template,t,n)},position:"insideEndTop"}}}))}function zh(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function Eh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=Dd(e,t),u=rt(r.axisLabel.overflow.on_axis),c=Md(e);return{grid:zh(e),dataset:l,legend:Id({config:e}),tooltip:Pd({config:e}),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:Ft(r.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return Z(d).format(a.label_formatter)}}}],series:[...c,...Ah(o,n,t)]}}ie.use([F.DataZoomComponent,he.BoxplotChart,F.MarkLineComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function $h({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,$r),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,Cs.id),f=zt(a,u.x_axis.data_key),h=m.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=m.useMemo(()=>({click:h}),[h]),y=m.useMemo(()=>Eh({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Be,{width:o,height:l,children:i(Ae,{echarts:ie,option:y,style:on(o,l),onEvents:g,notMerge:!0,theme:"merico-light"})})}function Lh({control:e,index:t,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.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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(t),sx:{position:"absolute",top:15,right:5},children:i(I.Trash,{size:16})})]})}function Ph({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(Lh,{control:e,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 Oh=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Jn=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(Ue.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(Oh,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Bh=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{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:e,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:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})),Vh=({control:e,watch:t})=>(t(["y_axis"]),p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{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:e,render:({field:n})=>i(Ge,{...n})})]})]})),Nh=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),qh=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Nh,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Fh({control:e,watch:t}){return i(s.Stack,{children:i(qh,{control:e,watch:t})})}const Gh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Wh=({control:e,watch:t})=>{const n=t("legend"),r=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,mt:20,children:i(v.Controller,{name:"legend.show",control:e,render:({field:a})=>i(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(s.Group,{children:i(v.Controller,{name:"legend",control:e,render:({field:a})=>i(s.Select,{label:"Orientation",data:Gh,sx:{flex:1},value:a.value.orient,onChange:o=>{r(o,a.onChange)},disabled:!n.show})})})]})};function jh({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaults({},t,$r),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,t),[f,t]);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(I.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:"Legend",children:"Legend"}),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(Bh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Vh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Legend",children:i(Wh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Fh,{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($e,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ph,{variables:r,control:o,watch:u})})]})]})})}function Rh(e){return x.omit(e,"variables")}function Yh(e){const{label_formatter:t=De,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Qh(e){const t={rotate:0,formatter:{...Ue}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Uh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Kh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Xh(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Jh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;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}}function Zh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(t,e)}class Hh extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}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:Rh(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Yh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Qh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Uh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Kh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Xh(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Jh(a,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Zh(r)}})}}const ef={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Hh,name:"boxplot",viewRender:$h,configRender:jh,createConfig(){return{version:9,config:x.cloneDeep($r)}},triggers:[Cs]},uo={id:"builtin:button:click-button",displayName:"Click Button",nameRender:nf,configRender:tf,payload:[]};function tf(e){return i(B,{})}function nf(e){return i(s.Text,{children:"Click this button"})}const ti={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},rf={left:"flex-start",center:"center",right:"flex-end"},af={top:"flex-start",center:"center",bottom:"flex-end"},sf=k.observer(({context:e,instance:t})=>{const n=Xe({vizManager:e.vizManager,instance:t}),r=Ke(n.triggerManager,uo.id),a=ye(),{value:o}=R(e.instanceData,"config"),l=m.useMemo(()=>x.defaultsDeep({},o,ti),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,y=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:rf[c],alignItems:af[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(y)})})}),of=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=m.useCallback(l=>()=>t(l),[t]),o=l=>e===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)})})]})},lf=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),uf=({label:e,value:t,onChange:n})=>i(s.Select,{data:lf,label:e,value:t,onChange:n}),cf=[{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}],df=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],pf=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function hf({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,ti),[t]),a=r;m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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:cf,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(of,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(uf,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:y=>g.onChange(y.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:df,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:pf,...g})})]})]})]})}class ff extends ge{constructor(){super(...arguments);q(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 gf={displayName:"Button",displayGroup:"Others",migrator:new ff,name:"button",viewRender:sf,configRender:hf,createConfig(){return{version:2,config:x.cloneDeep(ti)}},triggers:[uo]},ni={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:yf,configRender:mf,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 mf(e){return i(B,{})}function yf(e){return i(s.Text,{children:"Click chart's series"})}const Rt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},ri={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:De}],reference_lines:[],reference_areas:[],dataZoom:Rt};function ii(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function bf(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function vf(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function xf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function wf(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:xf(r),...vf(r)})),t}function Zn(e,t){switch(e.config.method){case"linear":return[...wt.regressionLinear()(t)];case"exponential":return[...wt.regressionExp()(t)];case"logarithmic":return[...wt.regressionLog()(t)];case"polynomial":return[...wt.regressionPoly().order(e.config.order)(t)];default:return[]}}function Cf(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:Zn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Sf({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=Cf(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=gt(n,o.y_axis_data_key).map((g,y)=>[y,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=P(o.y_axis_data_key),d=x.groupBy(ln(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function _f(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function kf(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function Tf(e,t,n,r,a,o){return e.map(l=>{const u=n[l.variable_key],c=l.orientation==="horizontal",d=c?"yAxis":"xAxis",f=c?"insideEndTop":"end",h=kf(u,c,a,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:h,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[d]:u}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?Xn(l.template,t,r):""},position:f}}}})}function Df({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=P(r),c=x.keyBy(ln(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:It.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function ai(e,t,n){const r=gt(e,t),a=gt(e,n);return x.zip(r,a)}function If(e,t,n,r){const a=ai(t,n,r);return x.unionBy(a,e,0)}function Mf({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?If(e,t,n,r):gt(t,r)}function Af({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Mf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=ai(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(y=>y[1]),g=Hr(h,n);return[d,g]})}function zf({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=P(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ai({[a]:c},n,r)}),l}function Ef({x_axis_data_key:e,x_axis:t},{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,...y},C,w,_,D){const M=t.type!=="category",O={label:{show:!!a,position:a,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:Df(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...y};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return O.data=Af({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:M}),O;const G=zf({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(G).map(([$,L])=>{const A=x.cloneDeep(O);return A.name=$,A.color=void 0,A.data=L,A})}function $f(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>Ef(e,c,l,n,o,r)).flat().concat(Tf(e.reference_lines,a,o,n,t,e.x_axis.type)).concat(_f(e.reference_areas,o))}function Lf(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Ft(t.x_axis.axisLabel.formatter)(r,a)}function Pf(e,t,n){const r=t.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],y=n[g]??n.default;return`
|
|
104
|
+
`,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var y;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(y=d==null?void 0:d.text)===null||y===void 0?void 0:y.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function np(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}ut.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new fn({key:new gn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=np(n);return tp(r,{from:l,to:u},{textSerializers:c})}}})]}});const rp=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),ip=(e=!1)=>({commands:t})=>t.setContent("",e),ap=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),y=h.blockRange(g);if(!y)return;const C=Yd(y);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(y.start,w)}(C||C===0)&&t.lift(y,C)})}),!0},sp=e=>t=>e(t),op=()=>({state:e,dispatch:t})=>ke.createParagraphNear(e,t),lp=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},up=e=>({tr:t,state:n,dispatch:r})=>{const a=Me(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},cp=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},dp=()=>({state:e,dispatch:t})=>ke.deleteSelection(e,t),pp=()=>({commands:e})=>e.keyboardShortcut("Enter"),hp=()=>({state:e,dispatch:t})=>ke.exitCode(e,t);function Wn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:Hd(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function Ur(e,t,n={}){return e.find(r=>r.type===t&&Wn(r.attrs,n))}function fp(e,t,n={}){return!!Ur(e,t,n)}function Xs(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=Ur([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Ur([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&fp([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function _t(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const gp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=_t(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=Xs(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=Se.create(l,h.from,h.to);n.setSelection(g)}}return!0},mp=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function Js(e){return e instanceof Se}function Ot(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function yp(e,t=null){if(!t)return null;const n=fe.atStart(e),r=fe.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?Se.create(e,Ot(0,a,o),Ot(e.content.size,a,o)):Se.create(e,Ot(t,a,o),Ot(t,a,o))}function Kr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const bp=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Kr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!Js(n.state.selection))return l(),!0;const u=yp(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},vp=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),xp=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Zs(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function jn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ae.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),jn("",t,n)}if(typeof e=="string"){const r=Pn.fromSchema(t);return n.slice?r.parseSlice(Zs(e),n.parseOptions).content:r.parse(Zs(e),n.parseOptions)}return jn("",t,n)}function wp(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof lt||a instanceof Pt))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}const Cp=e=>e.toString().startsWith("<"),Sp=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=jn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((Cp(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&wp(r,r.steps.length-1,-1)}return!0},_p=()=>({state:e,dispatch:t})=>ke.joinUp(e,t),kp=()=>({state:e,dispatch:t})=>ke.joinDown(e,t),Tp=()=>({state:e,dispatch:t})=>ke.joinBackward(e,t),Dp=()=>({state:e,dispatch:t})=>ke.joinForward(e,t);function Hs(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ip(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Kr()||Hs()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Mp=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=Ip(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Xr(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Me(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const y=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:y,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Wn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const Ap=(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return Xr(n,a,t)?ke.lift(n,r):!1},zp=()=>({state:e,dispatch:t})=>ke.liftEmptyBlock(e,t),Ep=e=>({state:t,dispatch:n})=>{const r=Me(e,t.schema);return br.liftListItem(r)(t,n)},$p=()=>({state:e,dispatch:t})=>ke.newlineInCode(e,t);function eo(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function to(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const Lp=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=eo(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Me(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,to(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(to(h.attrs,t)))})})}),!0):!1},Pp=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Op=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Bp=()=>({state:e,dispatch:t})=>ke.selectNodeBackward(e,t),Vp=()=>({state:e,dispatch:t})=>ke.selectNodeForward(e,t),Np=()=>({state:e,dispatch:t})=>ke.selectParentNode(e,t),qp=()=>({state:e,dispatch:t})=>ke.selectTextblockEnd(e,t),Fp=()=>({state:e,dispatch:t})=>ke.selectTextblockStart(e,t);function Gp(e,t,n={}){return jn(e,t,{slice:!1,parseOptions:n})}const Wp=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Gp(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function jp(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Rp(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Jr(e){return t=>Rp(t.$from,e)}function Yp(e,t){const n=_t(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Rn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function Qp(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?_t(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Wn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const y=h.pos,C=g.pos;e.doc.nodesBetween(y,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const D=Math.max(y,_),M=Math.min(C,_+w.nodeSize),O=M-D;l+=O,u.push(...w.marks.map(G=>({mark:G,from:D,to:M})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Wn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function no(e,t){const{nodeExtensions:n}=Jd(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Wt(St(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Up(e,t,n){var r;const{selection:a}=t;let o=null;if(Js(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const y=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=y&&C}return!d}),d})}const Kp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=_t(e,r.schema);if(a)if(l){const d=Yp(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,y)=>{const C=Math.max(y,f),w=Math.min(y+g.nodeSize,h);g.marks.find(D=>D.type===c)?g.marks.forEach(D=>{c===D.type&&n.addMark(C,w,c.create({...D.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Up(r,n,c)},Xp=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Jp=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Me(e,n.schema);return o.isTextblock?a().command(({commands:l})=>ke.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>ke.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Zp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=Ot(e,0,r.content.size),o=Re.create(r,a);t.setSelection(o)}return!0},Hp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=Se.atStart(r).from,u=Se.atEnd(r).to,c=Ot(a,l,u),d=Ot(o,l,u),f=Se.create(r,c,d);t.setSelection(f)}return!0},eh=e=>({state:t,dispatch:n})=>{const r=Me(e,t.schema);return br.sinkListItem(r)(t,n)};function ro(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const th=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=Rn(d,u.node().type.name,u.node().attrs);if(o instanceof Re&&o.node.isBlock)return!u.parentOffset||!qn(l,u.pos)?!1:(r&&(e&&ro(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof Se&&t.deleteSelection();const g=u.depth===0?void 0:jp(u.node(-1).contentMatchAt(u.indexAfter(-1)));let y=h&&g?[{type:g,attrs:f}]:void 0,C=qn(t.doc,t.mapping.map(u.pos),1,y);if(!y&&!C&&qn(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,y=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,y),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&ro(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},nh=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Me(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const D=u.index(-1)?1:u.index(-2)?2:3;for(let A=u.depth-D;A>=u.depth-3;A-=1)_=ae.from(u.node(A).copy(_));const M=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,O=Rn(h,u.node().type.name,u.node().attrs),G=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(ae.from(l.createAndFill(null,G)||void 0));const $=u.before(u.depth-(D-1));t.replace($,u.after(-M),new ce(_,4-D,0));let L=-1;t.doc.nodesBetween($,t.doc.content.size,(A,N)=>{if(L>-1)return!1;A.isTextblock&&A.content.size===0&&(L=N+1)}),L>-1&&t.setSelection(Se.near(t.doc.resolve(L))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,y=Rn(h,f.type.name,f.attrs),C=Rn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:y},{type:g,attrs:C}]:[{type:l,attrs:y}];if(!qn(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:D}=n,{splittableMarks:M}=a.extensionManager,O=D||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!O||!r)return!0;const G=O.filter($=>M.includes($.type.name));t.ensureMarks(G)}return!0},Zr=(e,t)=>{const n=Jr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Fs(e.doc,n.pos)&&e.join(n.pos),!0},Hr=(e,t)=>{const n=Jr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Fs(e.doc,r)&&e.join(r),!0};var rh=Object.freeze({__proto__:null,blur:rp,clearContent:ip,clearNodes:ap,command:sp,createParagraphNear:op,deleteCurrentNode:lp,deleteNode:up,deleteRange:cp,deleteSelection:dp,enter:pp,exitCode:hp,extendMarkRange:gp,first:mp,focus:bp,forEach:vp,insertContent:xp,insertContentAt:Sp,joinUp:_p,joinDown:kp,joinBackward:Tp,joinForward:Dp,keyboardShortcut:Mp,lift:Ap,liftEmptyBlock:zp,liftListItem:Ep,newlineInCode:$p,resetAttributes:Lp,scrollIntoView:Pp,selectAll:Op,selectNodeBackward:Bp,selectNodeForward:Vp,selectParentNode:Np,selectTextblockEnd:qp,selectTextblockStart:Fp,setContent:Wp,setMark:Kp,setMeta:Xp,setNode:Jp,setNodeSelection:Zp,setTextSelection:Hp,sinkListItem:eh,splitBlock:th,splitListItem:nh,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,y=Me(e,l.schema),C=Me(t,l.schema),{selection:w,storedMarks:_}=l,{$from:D,$to:M}=w,O=D.blockRange(M),G=_||w.$to.parentOffset&&w.$from.marks();if(!O)return!1;const $=Jr(L=>no(L.type.name,h))(w);if(O.depth>=1&&$&&O.depth-$.depth<=1){if($.node.type===y)return d.liftListItem(C);if(no($.node.type.name,h)&&y.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,y),!0)).command(()=>Zr(o,y)).command(()=>Hr(o,y)).run()}return!n||!G||!u?c().command(()=>f().wrapInList(y,r)?!0:d.clearNodes()).wrapInList(y,r).command(()=>Zr(o,y)).command(()=>Hr(o,y)).run():c().command(()=>{const L=f().wrapInList(y,r),A=G.filter(N=>g.includes(N.type.name));return o.ensureMarks(A),L?!0:d.clearNodes()}).wrapInList(y,r).command(()=>Zr(o,y)).command(()=>Hr(o,y)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=_t(e,r.schema);return Qp(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Me(e,r.schema),l=Me(t,r.schema);return Xr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Me(e,n.schema);return Xr(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=_t(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:y}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=Xs(d,c,C);w&&(g=w.from,y=w.to),n.removeMark(g,y,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=eo(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Me(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(y=>{if(l===y.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...y.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return ke.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return br.wrapInList(a,t)(n,r)}});ut.create({name:"commands",addCommands(){return{...rh}}}),ut.create({name:"editable",addProseMirrorPlugins(){return[new fn({key:new gn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ut.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new fn({key:new gn("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),ut.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:y}=h,C=fe.atStart(d).from===g;return!f||!C||!y.type.isTextblock||y.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Kr()||Hs()?o:a},addProseMirrorPlugins(){return[new fn({key:new gn("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=fe.atStart(t.doc).from,c=fe.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=Us({state:n,transaction:h}),{commands:y}=new Xd({editor:this.editor,state:g});if(y.clearNodes(),!!h.steps.length)return h}})]}}),ut.create({name:"tabindex",addProseMirrorPlugins(){return[new fn({key:new gn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const io=ut.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ih=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),ah=[{label:"auto",value:""}].concat(ih.map(e=>({label:e,value:e}))),sh={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},oh=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(E.IconTextSize,{stroke:1.5,size:16}),data:ah,styles:sh,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Yn=({value:e,styles:t={}})=>{const n=Ja.useEditor({extensions:[Za,Xa,J.Link,Wa,Ga,qa,Ya.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ka,Ua,Qa,ja.configure({types:["heading","paragraph"]}),Fa.configure({placeholder:"This is placeholder"}),Ra,Na.Color,io],content:e,editable:!1});m.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=m.useMemo(()=>x.defaultsDeep({},{content:Vr},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function lh(){const[e,{open:t,close:n}]=_e.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:i(Yn,{value:rc,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i(E.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const uh=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Te,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},mn=m.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=m.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};m.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(lh,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(uh,{value:o,onChange:l})]})}),ch=m.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:d}]=_e.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:u,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:i(s.Box,{h:600,children:i(mn,{value:e,onChange:t,defaultValue:o,label:n})})}),i(s.Button,{onClick:c,...a,children:r})]})}),ao=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
+
`),jt={type:"none",config:{}};function dh(e){const t=Array.from(e).sort((r,a)=>r-a),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function ph(e){const t=Number(e);return isFinite(t)?t:0}function hh(e,t){switch(t.type){case"sum":return x.sum(e);case"mean":return x.mean(e);case"median":return dh(e);case"max":return x.max(e)??0;case"min":return x.min(e)??0;case"quantile":return tn.quantile(e,t.config.p)??0;case"CV":const n=In.std(...e),r=In.mean(...e);return r?n/r:"N/A";case"std":return In.std(...e);default:return e}}function ei(e,t){const n=e.map(ph);return hh(n,t)}function fh(e,t,n){try{const r=ln(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},At)}catch(r){return console.error(r),r.message}}function Qn(e,t,n){try{return n.type==="custom"?fh(e,t,n):ei(gt(e,t),n)}catch(r){return console.error(r),null}}const gh=[{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"},{label:"Custom",value:"custom"}];function mh({label:e,value:t,onChange:n,pt:r="sm"},a){m.useEffect(()=>{typeof t=="string"&&n({type:t,config:{}})},[t,n]);const o=c=>{n(c==="quantile"?{type:"quantile",config:{p:.99}}:c==="custom"?{type:"custom",config:{func:ao}}:{type:c,config:{}})},l=c=>{n({type:"quantile",config:{p:c}})},u=c=>{n({type:"custom",config:{func:c}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:e,data:gh,value:t.type,onChange:o}),t.type==="quantile"&&i(s.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1}),t.type==="custom"&&i(ch,{label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:u,defaultValue:ao,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:i(E.IconMathFunction,{size:16})}})]})}const Un=m.forwardRef(mh);function yh({label:e,value:t,onChange:n},r){const[a,o]=m.useState(Array.isArray(t)?[...t]:[]),l=m.useCallback(()=>{o(g=>[...g,""])},[o]),u=m.useCallback(g=>{o(y=>(y.splice(g,1),[...y]))},[o]),c=m.useMemo(()=>!x.isEqual(a,t),[a,t]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=m.useMemo(()=>Object.entries(f.colors).map(([g,y])=>y[6]),[f]);return p(B,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,y)=>i(s.ColorInput,{value:g,onChange:C=>{o(w=>(w.splice(y,1,C),[...w]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(y),color:"red",children:i(I.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(I.PlaylistAdd,{size:20})})]})]})}const bh=m.forwardRef(yh);function vh({value:e,onChange:t},n){const{colorManager:r}=m.useContext(ct),a=m.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=m.useMemo(()=>a.some(l=>l.value===e),[e,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":e,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:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const $e=m.forwardRef(vh),Kn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function xh({label:e,value:t,onChange:n},r){var l;const[a,o]=m.useState(((l=Kn.find(u=>u.label===t))==null?void 0:l.value)??Kn[0].value);return m.useEffect(()=>{const u=Kn.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:e}),i(s.Slider,{label:null,marks:Kn,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const so=m.forwardRef(xh);function wh({label:e,value:t,onChange:n,type:r},a){const[o,l]=m.useState(Array.isArray(t)?[...t]:[]),u=m.useCallback(()=>{l(h=>[...h,""])},[l]),c=m.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=m.useMemo(()=>!x.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(B,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:y=>{const C=y.currentTarget.value;l(w=>(w.splice(g,1,C),[...w]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(I.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(I.PlaylistAdd,{size:20})})]})]})}const Ch=m.forwardRef(wh),oo=m.forwardRef(function({value:t,onChange:n},r){const a=t.color.type,o=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)},l=u=>{if(u==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return p(B,{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:t.size,onChange:u=>o("size",u.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(so,{label:"Font Weight",value:t.weight,onChange:u=>o("weight",u)})}),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:t.color.type,onChange:l}),a==="static"&&i($e,{value:t.color.staticColor,onChange:u=>o("color.staticColor",u)}),a==="continuous"&&p(B,{children:[i(Ch,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:u=>o("color.valueRange",u)}),i(bh,{label:"Color Range",value:t.color.colorRange,onChange:u=>o("color.colorRange",u)})]})]})]})});m.forwardRef(function({value:t,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(t);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:t.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:t.name,onChange:l=>o("name",l.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:l=>o("data_field",l)})]}),i(Un,{label:"Aggregation",value:t.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),t.aggregation.type!=="custom"&&i(Ge,{value:t.formatter,onChange:l=>o("formatter",l)}),r&&i(oo,{value:t,onChange:n})]})});class Sh{constructor({valueRange:t,colorRange:n}){q(this,"mapper");this.mapper=It.interpolate(t,n)}getColor(t){return this.mapper(t)}}function _h(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function yt({data_field:e,aggregation:t},n){return Qn(n,e,t)}function Ze({formatter:e,aggregation:t},n){if(!["string","number"].includes(typeof n))return _h(n);if(t.type==="custom")return n;try{return Z(n).format(e)}catch(r){return console.error(r),n}}function kh(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new Sh(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function lo(e,t){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=e,u=Qn(t,r,a),c=Ze(e,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:kh(n,u),weight:l,children:c})}function Th(e,t){const n={};return e.forEach(r=>{const a=r.name;n[a]=lo(r,t)}),n}function Dh(e){return e.split(" ").map((t,n)=>p(m.Fragment,{children:[t," "]},n))}function Ih(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
|
|
106
|
+
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[Dh(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function ti(e){return Ih(e)}function yn(e,t,n){const r=Th(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return ti(o);const c=r[u[1]];if(!c)return ti(o);const d=u[2]??"";return p(m.Fragment,{children:[c,ti(d)]},`${o}-${l}`)})}function Mh(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Qn(t,o,l);n[a]=Ze(r,u)}),n}function Xn(e,t,n){const r=Mh(t,n),a=/^\{(.+)\}(.*)$/;return e.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 Ah(e,t,n){const r=t.reduce((a,o)=>{const l=yt(o,n);return a[o.name]=Ze(o,l),a},{});return e.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 Xn(a.template,t,n)},position:"insideEndTop"}}}))}function zh(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function Eh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=Dd(e,t),u=rt(r.axisLabel.overflow.on_axis),c=Md(e);return{grid:zh(e),dataset:l,legend:Id({config:e}),tooltip:Pd({config:e}),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:Ft(r.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return Z(d).format(a.label_formatter)}}}],series:[...c,...Ah(o,n,t)]}}ie.use([F.DataZoomComponent,he.BoxplotChart,F.MarkLineComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function $h({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,Lr),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,Cs.id),f=zt(a,u.x_axis.data_key),h=m.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=m.useMemo(()=>({click:h}),[h]),y=m.useMemo(()=>Eh({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Be,{width:o,height:l,children:i(Ae,{echarts:ie,option:y,style:on(o,l),onEvents:g,notMerge:!0,theme:"merico-light"})})}function Lh({control:e,index:t,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.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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(t),sx:{position:"absolute",top:15,right:5},children:i(I.Trash,{size:16})})]})}function Ph({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(Lh,{control:e,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 Oh=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Jn=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(Ue.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(Oh,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Bh=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{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:e,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:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})),Vh=({control:e,watch:t})=>(t(["y_axis"]),p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{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:e,render:({field:n})=>i(Ge,{...n})})]})]})),Nh=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),qh=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Nh,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Fh({control:e,watch:t}){return i(s.Stack,{children:i(qh,{control:e,watch:t})})}const Gh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Wh=({control:e,watch:t})=>{const n=t("legend"),r=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,mt:20,children:i(v.Controller,{name:"legend.show",control:e,render:({field:a})=>i(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(s.Group,{children:i(v.Controller,{name:"legend",control:e,render:({field:a})=>i(s.Select,{label:"Orientation",data:Gh,sx:{flex:1},value:a.value.orient,onChange:o=>{r(o,a.onChange)},disabled:!n.show})})})]})};function jh({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaults({},t,Lr),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,t),[f,t]);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(I.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:"Legend",children:"Legend"}),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(Bh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Vh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Legend",children:i(Wh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Fh,{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($e,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ph,{variables:r,control:o,watch:u})})]})]})})}function Rh(e){return x.omit(e,"variables")}function Yh(e){const{label_formatter:t=De,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Qh(e){const t={rotate:0,formatter:{...Ue}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Uh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Kh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Xh(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Jh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;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}}function Zh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(t,e)}class Hh extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}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:Rh(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Yh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Qh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Uh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Kh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Xh(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Jh(a,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Zh(r)}})}}const ef={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Hh,name:"boxplot",viewRender:$h,configRender:jh,createConfig(){return{version:9,config:x.cloneDeep(Lr)}},triggers:[Cs]},uo={id:"builtin:button:click-button",displayName:"Click Button",nameRender:nf,configRender:tf,payload:[]};function tf(e){return i(B,{})}function nf(e){return i(s.Text,{children:"Click this button"})}const ni={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},rf={left:"flex-start",center:"center",right:"flex-end"},af={top:"flex-start",center:"center",bottom:"flex-end"},sf=k.observer(({context:e,instance:t})=>{const n=Xe({vizManager:e.vizManager,instance:t}),r=Ke(n.triggerManager,uo.id),a=ye(),{value:o}=R(e.instanceData,"config"),l=m.useMemo(()=>x.defaultsDeep({},o,ni),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,y=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:rf[c],alignItems:af[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(y)})})}),of=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=m.useCallback(l=>()=>t(l),[t]),o=l=>e===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)})})]})},lf=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),uf=({label:e,value:t,onChange:n})=>i(s.Select,{data:lf,label:e,value:t,onChange:n}),cf=[{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}],df=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],pf=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function hf({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,ni),[t]),a=r;m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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:cf,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(of,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(uf,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:y=>g.onChange(y.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:df,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:pf,...g})})]})]})]})}class ff extends ge{constructor(){super(...arguments);q(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 gf={displayName:"Button",displayGroup:"Others",migrator:new ff,name:"button",viewRender:sf,configRender:hf,createConfig(){return{version:2,config:x.cloneDeep(ni)}},triggers:[uo]},ri={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:yf,configRender:mf,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 mf(e){return i(B,{})}function yf(e){return i(s.Text,{children:"Click chart's series"})}const Rt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},ii={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:De}],reference_lines:[],reference_areas:[],dataZoom:Rt};function ai(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function bf(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function vf(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function xf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function wf(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:xf(r),...vf(r)})),t}function Zn(e,t){switch(e.config.method){case"linear":return[...wt.regressionLinear()(t)];case"exponential":return[...wt.regressionExp()(t)];case"logarithmic":return[...wt.regressionLog()(t)];case"polynomial":return[...wt.regressionPoly().order(e.config.order)(t)];default:return[]}}function Cf(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:Zn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Sf({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=Cf(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=gt(n,o.y_axis_data_key).map((g,y)=>[y,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=P(o.y_axis_data_key),d=x.groupBy(ln(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function _f(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function kf(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function Tf(e,t,n,r,a,o){return e.map(l=>{const u=n[l.variable_key],c=l.orientation==="horizontal",d=c?"yAxis":"xAxis",f=c?"insideEndTop":"end",h=kf(u,c,a,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:h,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[d]:u}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?Xn(l.template,t,r):""},position:f}}}})}function Df({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=P(r),c=x.keyBy(ln(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:It.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function si(e,t,n){const r=gt(e,t),a=gt(e,n);return x.zip(r,a)}function If(e,t,n,r){const a=si(t,n,r);return x.unionBy(a,e,0)}function Mf({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?If(e,t,n,r):gt(t,r)}function Af({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Mf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=si(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(y=>y[1]),g=ei(h,n);return[d,g]})}function zf({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=P(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=si({[a]:c},n,r)}),l}function Ef({x_axis_data_key:e,x_axis:t},{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,...y},C,w,_,D){const M=t.type!=="category",O={label:{show:!!a,position:a,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:Df(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...y};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return O.data=Af({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:M}),O;const G=zf({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(G).map(([$,L])=>{const A=x.cloneDeep(O);return A.name=$,A.color=void 0,A.data=L,A})}function $f(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>Ef(e,c,l,n,o,r)).flat().concat(Tf(e.reference_lines,a,o,n,t,e.x_axis.type)).concat(_f(e.reference_areas,o))}function Lf(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Ft(t.x_axis.axisLabel.formatter)(r,a)}function Pf(e,t,n){const r=t.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],y=n[g]??n.default;return`
|
|
107
107
|
<tr>
|
|
108
108
|
<td>${f}</td>
|
|
109
109
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
@@ -118,8 +118,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
118
118
|
${l.join("")}
|
|
119
119
|
</tbody>
|
|
120
120
|
</table>
|
|
121
|
-
`}}}function Of(e){return e.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 Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function co(e,t){const n={};return t.map(r=>{const a=yt(r,e);n[r.name]=Ze(r,a)}),n}function Bf(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,a=rt(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...r,...a,formatter:Ft(r.formatter)}}]}function Vf(e){var t;try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(r=>Number(r[1])):[...e]}catch(n){return console.error(n),[...e]}}function Nf(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const a=Vf(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=a;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(a)}),Object.entries(n).forEach(([r,a])=>{const o=x.minBy(a)??0,l=x.maxBy(a)??0;o==0&&l==0&&(t[r]=1)}),t}function qf(e,t,n){const r=Nf(n);return e.y_axes.map(({nameAlignment:a,min:o,max:l,show:u,...c},d)=>{let f=c.position;return f||(f=d>0?"right":"left"),{...c,minInterval:r[d]??0,show:u,min:o||void 0,max:l||void 0,position:f,axisLabel:{show:u,formatter:t[d]??t.default},axisLine:{show:u},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:"end",nameGap:u?15:0,splitLine:{show:!1}}})}const Ff={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Gf(e,t,n){const r=co(t,n),a=Of(e),o=x.uniq(gt(t,e.x_axis_data_key)),l=$f(e,o,t,a,n,r),u=Sf(e,t),c={xAxis:Bf(e,o),yAxis:qf(e,a,l),series:[...l,...u],tooltip:Pf(e,l,a),grid:bf(e),legend:wf(l),dataZoom:ii(e.dataZoom)};return x.defaultsDeep({},c,Ff)}function po(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});e.setOption({...e.getOption(),series:n})}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function ho(e){return e.trim().length>0}function Wf({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis_data_key),u=Ke(a.triggerManager,ni.id),c=m.useCallback(y=>{const C=x.get(l,y.name,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...y,rowData:C})})},[l,u,a]),d=m.useMemo(()=>Gf(e,t,o),[e,t]),f=m.useRef(),h=m.useMemo(()=>({click:c}),[c]),g=y=>{f.current=y,po(y)};return m.useEffect(()=>{f.current&&po(f.current)},[d]),!n||!r?null:i(Ae,{echarts:ie,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function jf({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,ri),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=_e.useElementSize(),{ref:h,height:g}=_e.useElementSize(),y=m.useMemo(()=>{const{stats:{templates:_}}=o;return{top:yn(_.top,a,l),bottom:yn(_.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g),w=tt(u);return p(Be,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:ho(o.stats.templates.top)?"block":"none"},children:Object.values(y.top).map((_,D)=>i(m.Fragment,{children:_},D))}),i(Wf,{variables:a,width:w,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:ho(o.stats.templates.bottom)?"block":"none"},children:Object.values(y.bottom).map((_,D)=>i(m.Fragment,{children:_},D))})]})}const si=m.forwardRef(({value:e,onChange:t},n)=>{const r=a=>o=>{t({...e,[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:e.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:e.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:e.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:!e.y_axis_slider,checked:e.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Rf=[{label:"Rectangle",value:"rectangle"}],Yf=[{label:"Horizontal",value:"horizontal"}];function Qf({control:e,index:t,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.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.color`,control:e,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.${t}.type`,control:e,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Rf,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:Yf,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.${t}.y_keys.upper`,control:e,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Uf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("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=m.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},f.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Qf,{control:e,index:h,remove:o,variableOptions:d})},f.id))]})}const Kf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Xf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Jf({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.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.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Xf,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.${t}.yAxisIndex`,control:e,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.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Kf,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,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.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Zf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.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,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(Jf,{control:e,index:y,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},g.id))]})}const Hf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],eg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function tg({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:a}){const o=t.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:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>i(W,{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:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,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:e,render:({field:l})=>i(s.Select,{label:"Method",data:Hf,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:e,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:e,render:({field:l})=>i(s.Select,{label:"Line Type",data:eg,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,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:e,render:({field:l})=>i($e,{...l})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function ng({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=m.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),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},f.id)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(tg,{regressionItem:f,control:e,index:h,remove:a,yAxisOptions:c})},f.id))]})}const oi={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
122
|
-
`)}},rg=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function ig({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:rg,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const ag=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},sg=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(oi.dynamic.func_content)};return p(B,{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(ag,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},og=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(sg,{value:e,onChange:t}),lg=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},ug=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],fo=m.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...oi[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:ug,value:t.type,onChange:a,sx:{flexGrow:1}}),i(lg,{value:t,onChange:n}),i(og,{value:t,onChange:n})]})}),cg=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],dg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function pg({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return p(B,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:a})=>i(s.Select,{label:"Line Type",data:dg,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.lineStyle.width`,control:e,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.${t}.step`,control:e,render:({field:a})=>i(s.Select,{label:"Step",data:cg,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.${t}.smooth`,control:e,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.${t}.display_name_on_line`,control:e,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.${t}.showSymbol`,control:e,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.${t}.symbolSize`,control:e,render:({field:a})=>i(fo,{label:"Symbol Size",...a})})]})]})}function hg({control:e,index:t}){return i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>i(fo,{label:"Size",...n})})}const fg=[{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 gg({control:e,index:t,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.${t}.type`,control:e,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.${t}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.yAxisIndex`,control:e,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.${t}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>i(Un,{label:"Aggregation on Value",value:l.value??jt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(pg,{index:t,control:e,seriesItem:r}),o==="bar"&&i(ig,{index:t,control:e,seriesItem:r}),o==="scatter"&&i(hg,{index:t,control:e}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>i(s.Select,{label:"Label Position",data:fg,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function mg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:_e.randomId(),showSymbol:!1,symbolSize:oi.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=t("y_axes"),d=m.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(gg,{control:e,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function yg({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(un,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(un,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const bg=()=>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(E.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"]})})]})]}),vg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function xg({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:e,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:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:e,render:({field:n})=>i(s.Select,{label:i(bg,{}),required:!0,data:vg,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:e,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:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}const wg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Cg=[{label:"left",value:"left"},{label:"right",value:"right"}];function Sg({control:e,index:t,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.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Name Anchor",required:!0,data:wg,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.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Cg,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.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...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.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,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.${t}.show`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function _g({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:De,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},c.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Sg,{control:e,index:d,remove:a})},c.id))]})}function kg({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,ri),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(xg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(_g,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(mg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(ng,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(yg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Zf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Uf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(si,{...g})})})]})]})})}function Tg(e){const t=x.cloneDeep(x.omit(e,"variables"));return t.stats=x.omit(t.stats,"variables"),t}function Dg(e){const{rotate:t,formatter:n=Ue}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Ig(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function Mg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Ag(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ht.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...e,reference_lines:t}}function zg(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function Eg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=jt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function $g(e){const t=e.series.map(n=>{const{aggregation_on_value:r=jt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function Lg(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Pg(e){const{series:t,...n}=e;return{...n,series:t.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 Og(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function Bg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function Vg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function Ng(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function qg(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=jt}=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 Fg(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Gg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=e;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 Wg extends ge{constructor(){super(...arguments);q(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:Tg(a)}}),this.version(3,n=>({...n,version:3,config:Dg(n.config)})),this.version(4,n=>({...n,version:4,config:Ig(n.config)})),this.version(5,n=>({...n,version:5,config:Mg(n.config)})),this.version(6,n=>({...n,version:6,config:Ag(n.config)})),this.version(7,n=>({...n,version:7,config:zg(n.config)})),this.version(8,n=>({...n,version:8,config:Eg(n.config)})),this.version(9,n=>({...n,version:9,config:$g(n.config)})),this.version(10,n=>({...n,version:10,config:Lg(n.config)})),this.version(11,n=>({...n,version:11,config:Pg(n.config)})),this.version(12,n=>({...n,version:12,config:Og(n.config)})),this.version(13,n=>({...n,version:13,config:Bg(n.config)})),this.version(14,n=>({...n,version:14,config:Vg(n.config)})),this.version(15,n=>({...n,version:15,config:Ng(n.config)})),this.version(16,n=>({...n,version:16,config:qg(n.config)})),this.version(17,n=>({...n,version:17,config:Fg(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Gg(n.config,r)}))}}const jg={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Wg,name:"cartesian",viewRender:jf,configRender:kg,createConfig(){return{version:18,config:x.cloneDeep(ri)}},triggers:[ni]};function Rg(e){if(e.enable_value)return e.value}function Yg(e){if(e.enable_value)return e.value}function Qg(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&x.get(r,n)&&n===e.funnelAlign&&x.set(r,n,t),r}function Ug(e,t){return e.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=P(r),g=P(a),y=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=rt(o.overflow.on_axis);return{type:"funnel",...Qg(n),min:Rg(l),max:Yg(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":c,data:y}})}function Kg({conf:e,params:t,max:n}){const{name:r,value:a}=t.data,o=Z(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Xg(e,t){var o;const n=P(e.series[0].level_name_data_key),r=P(e.series[0].level_value_data_key),a=(o=x.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Kg({conf:e,params:l,max:a}).map(f=>`
|
|
121
|
+
`}}}function Of(e){return e.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 Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function co(e,t){const n={};return t.map(r=>{const a=yt(r,e);n[r.name]=Ze(r,a)}),n}function Bf(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,a=rt(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...r,...a,formatter:Ft(r.formatter)}}]}function Vf(e){var t;try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(r=>Number(r[1])):[...e]}catch(n){return console.error(n),[...e]}}function Nf(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const a=Vf(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=a;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(a)}),Object.entries(n).forEach(([r,a])=>{const o=x.minBy(a)??0,l=x.maxBy(a)??0;o==0&&l==0&&(t[r]=1)}),t}function qf(e,t,n){const r=Nf(n);return e.y_axes.map(({nameAlignment:a,min:o,max:l,show:u,...c},d)=>{let f=c.position;return f||(f=d>0?"right":"left"),{...c,minInterval:r[d]??0,show:u,min:o||void 0,max:l||void 0,position:f,axisLabel:{show:u,formatter:t[d]??t.default},axisLine:{show:u},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:"end",nameGap:u?15:0,splitLine:{show:!1}}})}const Ff={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Gf(e,t,n){const r=co(t,n),a=Of(e),o=x.uniq(gt(t,e.x_axis_data_key)),l=$f(e,o,t,a,n,r),u=Sf(e,t),c={xAxis:Bf(e,o),yAxis:qf(e,a,l),series:[...l,...u],tooltip:Pf(e,l,a),grid:bf(e),legend:wf(l),dataZoom:ai(e.dataZoom)};return x.defaultsDeep({},c,Ff)}function po(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});e.setOption({...e.getOption(),series:n})}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function ho(e){return e.trim().length>0}function Wf({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis_data_key),u=Ke(a.triggerManager,ri.id),c=m.useCallback(y=>{const C=x.get(l,y.name,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...y,rowData:C})})},[l,u,a]),d=m.useMemo(()=>Gf(e,t,o),[e,t]),f=m.useRef(),h=m.useMemo(()=>({click:c}),[c]),g=y=>{f.current=y,po(y)};return m.useEffect(()=>{f.current&&po(f.current)},[d]),!n||!r?null:i(Ae,{echarts:ie,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function jf({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,ii),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=_e.useElementSize(),{ref:h,height:g}=_e.useElementSize(),y=m.useMemo(()=>{const{stats:{templates:_}}=o;return{top:yn(_.top,a,l),bottom:yn(_.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g),w=tt(u);return p(Be,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:ho(o.stats.templates.top)?"block":"none"},children:Object.values(y.top).map((_,D)=>i(m.Fragment,{children:_},D))}),i(Wf,{variables:a,width:w,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:ho(o.stats.templates.bottom)?"block":"none"},children:Object.values(y.bottom).map((_,D)=>i(m.Fragment,{children:_},D))})]})}const oi=m.forwardRef(({value:e,onChange:t},n)=>{const r=a=>o=>{t({...e,[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:e.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:e.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:e.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:!e.y_axis_slider,checked:e.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Rf=[{label:"Rectangle",value:"rectangle"}],Yf=[{label:"Horizontal",value:"horizontal"}];function Qf({control:e,index:t,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.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.color`,control:e,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.${t}.type`,control:e,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Rf,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:Yf,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.${t}.y_keys.upper`,control:e,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Uf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("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=m.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},f.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Qf,{control:e,index:h,remove:o,variableOptions:d})},f.id))]})}const Kf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Xf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Jf({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.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.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Xf,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.${t}.yAxisIndex`,control:e,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.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Kf,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,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.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Zf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.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,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(Jf,{control:e,index:y,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},g.id))]})}const Hf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],eg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function tg({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:a}){const o=t.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:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>i(W,{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:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,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:e,render:({field:l})=>i(s.Select,{label:"Method",data:Hf,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:e,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:e,render:({field:l})=>i(s.Select,{label:"Line Type",data:eg,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,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:e,render:({field:l})=>i($e,{...l})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function ng({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=m.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),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},f.id)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(tg,{regressionItem:f,control:e,index:h,remove:a,yAxisOptions:c})},f.id))]})}const li={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
122
|
+
`)}},rg=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function ig({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:rg,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const ag=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},sg=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(li.dynamic.func_content)};return p(B,{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(ag,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},og=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(sg,{value:e,onChange:t}),lg=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},ug=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],fo=m.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...li[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:ug,value:t.type,onChange:a,sx:{flexGrow:1}}),i(lg,{value:t,onChange:n}),i(og,{value:t,onChange:n})]})}),cg=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],dg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function pg({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return p(B,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:a})=>i(s.Select,{label:"Line Type",data:dg,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.lineStyle.width`,control:e,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.${t}.step`,control:e,render:({field:a})=>i(s.Select,{label:"Step",data:cg,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.${t}.smooth`,control:e,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.${t}.display_name_on_line`,control:e,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.${t}.showSymbol`,control:e,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.${t}.symbolSize`,control:e,render:({field:a})=>i(fo,{label:"Symbol Size",...a})})]})]})}function hg({control:e,index:t}){return i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>i(fo,{label:"Size",...n})})}const fg=[{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 gg({control:e,index:t,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.${t}.type`,control:e,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.${t}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.yAxisIndex`,control:e,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.${t}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>i(Un,{label:"Aggregation on Value",value:l.value??jt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(pg,{index:t,control:e,seriesItem:r}),o==="bar"&&i(ig,{index:t,control:e,seriesItem:r}),o==="scatter"&&i(hg,{index:t,control:e}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>i(s.Select,{label:"Label Position",data:fg,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function mg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:_e.randomId(),showSymbol:!1,symbolSize:li.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=t("y_axes"),d=m.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(gg,{control:e,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function yg({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(un,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(un,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const bg=()=>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(E.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"]})})]})]}),vg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function xg({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:e,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:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:e,render:({field:n})=>i(s.Select,{label:i(bg,{}),required:!0,data:vg,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:e,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:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}const wg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Cg=[{label:"left",value:"left"},{label:"right",value:"right"}];function Sg({control:e,index:t,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.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Name Anchor",required:!0,data:wg,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.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Cg,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.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...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.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,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.${t}.show`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function _g({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:De,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},c.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Sg,{control:e,index:d,remove:a})},c.id))]})}function kg({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,ii),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(xg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(_g,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(mg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(ng,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(yg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Zf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Uf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(oi,{...g})})})]})]})})}function Tg(e){const t=x.cloneDeep(x.omit(e,"variables"));return t.stats=x.omit(t.stats,"variables"),t}function Dg(e){const{rotate:t,formatter:n=Ue}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Ig(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function Mg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Ag(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ht.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...e,reference_lines:t}}function zg(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function Eg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=jt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function $g(e){const t=e.series.map(n=>{const{aggregation_on_value:r=jt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function Lg(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Pg(e){const{series:t,...n}=e;return{...n,series:t.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 Og(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function Bg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function Vg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function Ng(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function qg(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=jt}=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 Fg(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Gg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=e;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 Wg extends ge{constructor(){super(...arguments);q(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:Tg(a)}}),this.version(3,n=>({...n,version:3,config:Dg(n.config)})),this.version(4,n=>({...n,version:4,config:Ig(n.config)})),this.version(5,n=>({...n,version:5,config:Mg(n.config)})),this.version(6,n=>({...n,version:6,config:Ag(n.config)})),this.version(7,n=>({...n,version:7,config:zg(n.config)})),this.version(8,n=>({...n,version:8,config:Eg(n.config)})),this.version(9,n=>({...n,version:9,config:$g(n.config)})),this.version(10,n=>({...n,version:10,config:Lg(n.config)})),this.version(11,n=>({...n,version:11,config:Pg(n.config)})),this.version(12,n=>({...n,version:12,config:Og(n.config)})),this.version(13,n=>({...n,version:13,config:Bg(n.config)})),this.version(14,n=>({...n,version:14,config:Vg(n.config)})),this.version(15,n=>({...n,version:15,config:Ng(n.config)})),this.version(16,n=>({...n,version:16,config:qg(n.config)})),this.version(17,n=>({...n,version:17,config:Fg(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Gg(n.config,r)}))}}const jg={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Wg,name:"cartesian",viewRender:jf,configRender:kg,createConfig(){return{version:18,config:x.cloneDeep(ii)}},triggers:[ri]};function Rg(e){if(e.enable_value)return e.value}function Yg(e){if(e.enable_value)return e.value}function Qg(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&x.get(r,n)&&n===e.funnelAlign&&x.set(r,n,t),r}function Ug(e,t){return e.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=P(r),g=P(a),y=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=rt(o.overflow.on_axis);return{type:"funnel",...Qg(n),min:Rg(l),max:Yg(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":c,data:y}})}function Kg({conf:e,params:t,max:n}){const{name:r,value:a}=t.data,o=Z(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Xg(e,t){var o;const n=P(e.series[0].level_name_data_key),r=P(e.series[0].level_value_data_key),a=(o=x.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Kg({conf:e,params:l,max:a}).map(f=>`
|
|
123
123
|
<tr>
|
|
124
124
|
<th style="text-align: right;">
|
|
125
125
|
<div style="${f.style.label}">${f.label}</div>
|
|
@@ -135,7 +135,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
135
135
|
<table style="width: auto">
|
|
136
136
|
<tbody>${c.join("")}</tbody>
|
|
137
137
|
</table>
|
|
138
|
-
`}}function Jg(e,t){return{trigger:"item",confine:!0,formatter:Xg(e,t)}}function Zg(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Jg(e,t),series:Ug(e,t)}}function Hg(e){return e||(e=Date.now().toString()),{id:e,name:e,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:We},sort:"descending",orient:"vertical",funnelAlign:"center"}}const
|
|
138
|
+
`}}function Jg(e,t){return{trigger:"item",confine:!0,formatter:Xg(e,t)}}function Zg(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Jg(e,t),series:Ug(e,t)}}function Hg(e){return e||(e=Date.now().toString()),{id:e,name:e,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:We},sort:"descending",orient:"vertical",funnelAlign:"center"}}const ui={series:[Hg("Funnel")]};ie.use([he.FunnelChart,F.DataZoomComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function em({conf:e,data:t,width:n,height:r}){const a=m.useMemo(()=>Zg(e,t),[e,t]);return i(Ae,{echarts:ie,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function tm({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaults({},t,ui),[t]),r=e.data,{width:a,height:o}=e.viewport;return!a||!o?null:i(Be,{width:a,height:o,children:i(em,{width:tt(a),height:nt(o),data:r,conf:n})})}const nm=[{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"}],ci=m.forwardRef(({label:e,value:t,onChange:n,options:r=nm},a)=>i(s.Select,{ref:a,label:e,data:r,value:t,onChange:n})),rm=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],im=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],am=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],sm={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"}]},om=({item:e,control:t,index:n,remove:r})=>{const a=e.min.enable_value,o=e.max.enable_value,{orient:l}=e;return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:t,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:t,render:({field:u})=>i(W,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:u})=>i(W,{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:t,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:t,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:t,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:t,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:t,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:t,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:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:am,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:t,render:({field:u})=>i(s.Select,{label:"Sort",data:rm,...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:t,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:im,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:t,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:t,render:({field:u})=>i(ci,{label:"Position",options:sm[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:t,render:({field:u})=>i(st,{...u})})})]})},lm=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=x.get(l,"0.id"),[c,d]=m.useState(u??null);return m.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(E.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:f.id,children:i(om,{item:f,control:e,index:h,remove:a})},f.id))]})};function um({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,ui),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=m.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(I.DeviceFloppy,{size:20})})]}),i(lm,{control:a,watch:l})]})})}function cm(e){return{series:e.series.map(t=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=t;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function dm(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=e;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 pm extends ge{constructor(){super(...arguments);q(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:cm(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:dm(a,r)}})}}const hm={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new pm,name:"funnel",viewRender:tm,configRender:um,createConfig:()=>({version:3,config:ui})};function go({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function fm(e){const t=go(e.x_axis.axisLabel.formatter),n=go(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function gm(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function mm(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function ym(e,t,n){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:t,label:r.label,labelLayout:{hideOverlap:!0}}}const bm=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function vm({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:ot(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:ot(e.y_axis.axisLabel.overflow.in_tooltip)}},g={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},y=[f,h,g],C=r[`${u}---${c}`];return C&&e.tooltip.metrics.forEach(w=>{const _=P(w.data_key);y.push({label:w.name,value:bm(x.get(C,_.columnKey,"")),style:{label:"",value:""}})}),y}function xm(e,t,n,r){const{x_axis:a,y_axis:o,heat_block:l}=e,u=P(a.data_key),c=P(o.data_key);P(l.data_key);const d=x.keyBy(t[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=vm({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(C=>`
|
|
139
139
|
<tr>
|
|
140
140
|
<th style="text-align: right;">
|
|
141
141
|
<div style="${C.style.label}">${C.label}</div>
|
|
@@ -157,8 +157,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
157
157
|
<tbody>${g.join("")}</tbody>
|
|
158
158
|
</table>
|
|
159
159
|
`}}}const wm=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},mo={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
|
|
160
|
-
`)}},Cm=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,value:g}=o,y={type:h,value:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,value:h}))},f=()=>{d(mo.dynamic.value)};return p(B,{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(wm,{value:o.value,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},Sm=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Cm,{value:e,onChange:t}),_m=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,value:r})};return i(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:n})},km=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Yt=m.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const a=o=>{n({...mo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:km,value:t.type,onChange:a,sx:{flexGrow:1}}),i(_m,{value:t,onChange:n}),i(Sm,{value:t,onChange:n})]})});function Qt(e,t,n){if(!e.type)return n;if(e.type==="static"){const{value:a}=e;return a}const{value:r}=e;try{return new Function(`return ${r}`)()({variables:t},{lodash:x,interpolate:It.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function Tm(e,t){const n=Qt(e.heat_block.min,t),r=Qt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Dm(e,t,n){const{overflow:r,rotate:a}=e.x_axis.axisLabel,o=rt(r.on_axis);return{id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:a,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function Im(e,t,n){const{nameAlignment:r,data_key:a,...o}=e.y_axis,{overflow:l,rotate:u}=e.y_axis.axisLabel,c=rt(l.on_axis);return{...o,type:"category",data:t,axisLabel:{rotate:u,...c,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:2}}const Mm={tooltip:{confine:!0}};function Am(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function zm(e,t,n,r,a){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const o=n.reduce((_,D)=>{const M=yt(D,t);return _[D.name]=Ze(D,M),_},{}),l=fm(e),u=gm(e),c=P(e.x_axis.data_key),d=P(e.y_axis.data_key),f=P(e.heat_block.data_key),h=x.uniq(t[c.queryID].map(_=>_[c.columnKey])),g=x.uniq(t[c.queryID].map(_=>_[d.columnKey])),y=t[c.queryID].map(_=>[x.get(_,c.columnKey),x.get(_,d.columnKey),x.get(_,f.columnKey)]),C=Am(h.length,g.length,r,a),w={xAxis:Dm(e,h,l.x_axis),yAxis:Im(e,g,l.y_axis),series:ym(e,y,C),tooltip:xm(e,t,l,u),grid:mm(e),visualMap:Tm(e,o)};return x.defaultsDeep({},w,Mm)}function Em(e){return i(B,{})}function $m(e){return i(s.Text,{children:"Click heat block"})}const yo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:$m,configRender:Em,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"}]},
|
|
161
|
-
`)},bo=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(Fm.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(qm,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Gm({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(bo,{...n})})]})]})}const Wm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function jm({control:e,watch:t}){return t(["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:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,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:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:Wm,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(bo,{...n})})]})]})}function Rm({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,
|
|
160
|
+
`)}},Cm=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,value:g}=o,y={type:h,value:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,value:h}))},f=()=>{d(mo.dynamic.value)};return p(B,{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(wm,{value:o.value,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},Sm=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Cm,{value:e,onChange:t}),_m=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,value:r})};return i(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:n})},km=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Yt=m.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const a=o=>{n({...mo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:km,value:t.type,onChange:a,sx:{flexGrow:1}}),i(_m,{value:t,onChange:n}),i(Sm,{value:t,onChange:n})]})});function Qt(e,t,n){if(!e.type)return n;if(e.type==="static"){const{value:a}=e;return a}const{value:r}=e;try{return new Function(`return ${r}`)()({variables:t},{lodash:x,interpolate:It.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function Tm(e,t){const n=Qt(e.heat_block.min,t),r=Qt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Dm(e,t,n){const{overflow:r,rotate:a}=e.x_axis.axisLabel,o=rt(r.on_axis);return{id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:a,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function Im(e,t,n){const{nameAlignment:r,data_key:a,...o}=e.y_axis,{overflow:l,rotate:u}=e.y_axis.axisLabel,c=rt(l.on_axis);return{...o,type:"category",data:t,axisLabel:{rotate:u,...c,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:2}}const Mm={tooltip:{confine:!0}};function Am(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function zm(e,t,n,r,a){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const o=n.reduce((_,D)=>{const M=yt(D,t);return _[D.name]=Ze(D,M),_},{}),l=fm(e),u=gm(e),c=P(e.x_axis.data_key),d=P(e.y_axis.data_key),f=P(e.heat_block.data_key),h=x.uniq(t[c.queryID].map(_=>_[c.columnKey])),g=x.uniq(t[c.queryID].map(_=>_[d.columnKey])),y=t[c.queryID].map(_=>[x.get(_,c.columnKey),x.get(_,d.columnKey),x.get(_,f.columnKey)]),C=Am(h.length,g.length,r,a),w={xAxis:Dm(e,h,l.x_axis),yAxis:Im(e,g,l.y_axis),series:ym(e,y,C),tooltip:xm(e,t,l,u),grid:mm(e),visualMap:Tm(e,o)};return x.defaultsDeep({},w,Mm)}function Em(e){return i(B,{})}function $m(e){return i(s.Text,{children:"Click heat block"})}const yo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:$m,configRender:Em,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"}]},di={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:We,formatter:{...Ue}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:We,formatter:{...Ue}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:De,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function Lm({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const h=P(e.x_axis.data_key),g=P(e.y_axis.data_key);return x.keyBy(t[h.queryID],y=>`${y[h.columnKey]}---${y[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,yo.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,`${g}---${y}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>zm(e,t,o,n,r),[e,t,n,r]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Pm({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,di),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(Lm,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function Om({control:e,watch:t}){t(["heat_block"]);const n=t("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:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,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:e,render:({field:r})=>i(Yt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Yt,{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:e,render:({field:r})=>i(Ge,{...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:e,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:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const Bm=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Vm=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Bm,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Nm({control:e,watch:t}){return i(Vm,{control:e,watch:t})}const qm=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Fm={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
161
|
+
`)},bo=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(Fm.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(qm,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Gm({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(bo,{...n})})]})]})}const Wm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function jm({control:e,watch:t}){return t(["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:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,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:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:Wm,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(bo,{...n})})]})]})}function Rm({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,di),[t]),a=m.useMemo(()=>x.cloneDeep(r),[r]);m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(Gm,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(jm,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(Om,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Nm,{control:o,watch:u})})]})]})})}function Ym(e,{panelModel:t}){try{const n=t.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}=e;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 Qm(e){return x.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function Um(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Km extends ge{constructor(){super(...arguments);q(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:Ym(n.config,r)})),this.version(3,n=>({...n,version:3,config:Qm(n.config)})),this.version(4,n=>({...n,version:4,config:Um(n.config)}))}}const Xm={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Km,name:"heatmap",viewRender:Pm,configRender:Rm,createConfig:()=>({version:4,config:di}),triggers:[yo]},vo={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Zm,configRender:Jm,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 Jm(e){return i(B,{})}function Zm(e){return i(s.Text,{children:"Click chart's series"})}const xo={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},pi={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:De},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Rt,markLine:xo};function Hn(e){return Z(e).format({output:"percent",mantissa:0})}function Hm(e){const t=e.value[1];try{return Hn(t)}catch(n){return console.error(n),t}}function ey(e){function t(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!e.bar.label_formatter)return r;try{return Z(r).format(e.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:t,line:Hm,lineValue:Hn}}function ty(e,t,n){const{label_template:r}=e.markLine;if(!r)return"";const a={...e,percentage:t,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function ny(e,t){if(t.length===0)return{};const n=t.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=t[n],a={x:Hn((n+1)/t.length),y:Hn(r[1])},o={left:n+1,right:t.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:e.markLine.color},label:{formatter:ty(e,a,o)}}]}:{}}function ry(e,t,n){const{x_axis:r,data_key:a}=e;if(!r.data_key||!a)return[];const o=P(r.data_key),l=P(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[o.queryID].map(h=>[h[o.columnKey],Number(h[l.columnKey])]).sort((h,g)=>g[1]-h[1]),c=u.reduce((h,g)=>h+g[1],0),d=u.reduce((h,g,y)=>{const C=y===0?0:h[y-1][1];return h.push([g[0],C+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=ny(e,d);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const iy=(e,t)=>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?t.bar:t.lineValue;return`
|
|
162
162
|
<tr>
|
|
163
163
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
164
164
|
<td style="text-align: left; padding: 0 1em;">${g(h)}</td>
|
|
@@ -172,7 +172,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
172
172
|
${a.join("")}
|
|
173
173
|
</tbody>
|
|
174
174
|
</table>
|
|
175
|
-
`};function ay(e,t){return{trigger:"axis",formatter:iy(e,t)}}function sy(e){const{name:t,axisLabel:n}=e.x_axis,r=rt(n.overflow.on_axis);return[{type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{fontWeight:"bold",align:"right"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...n,...r,formatter:Ft(n.formatter)}}]}function oy(e,t){return[{name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{fontWeight:"bold",align:e.bar.nameAlignment},position:"left",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}},{name:e.line.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:e.line.nameAlignment},position:"right",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.lineValue},splitLine:{show:!1}}]}function ly(e,t,n){const r=ey(e);return{dataZoom:
|
|
175
|
+
`};function ay(e,t){return{trigger:"axis",formatter:iy(e,t)}}function sy(e){const{name:t,axisLabel:n}=e.x_axis,r=rt(n.overflow.on_axis);return[{type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{fontWeight:"bold",align:"right"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...n,...r,formatter:Ft(n.formatter)}}]}function oy(e,t){return[{name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{fontWeight:"bold",align:e.bar.nameAlignment},position:"left",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}},{name:e.line.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:e.line.nameAlignment},position:"right",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.lineValue},splitLine:{show:!1}}]}function ly(e,t,n){const r=ey(e);return{dataZoom:ai(e.dataZoom),tooltip:ay(e,r),xAxis:sy(e),yAxis:oy(e,r),series:ry(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}ie.use([he.BarChart,he.LineChart,F.DataZoomComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function uy({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),r=e.data,{width:a,height:o}=e.viewport,l=x.defaults({},n,pi),u=ly(l,r),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,vo.id),f=zt(r,l.x_axis.data_key),h=m.useCallback(y=>{const C=x.get(f,y.name,{error:"rowData is not found"});d.forEach(w=>{c.runInteraction(w.id,{...y,rowData:C})})},[f,d,c]),g=m.useMemo(()=>({click:h}),[h]);return!l||!a||!o?null:i(Be,{width:a,height:o,children:i(Ae,{echarts:ie,option:u,style:on(a,o),onEvents:g,notMerge:!0,theme:"merico-light"})})}const cy=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function dy({control:e,watch:t}){return t(["bar"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"bar.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),i(v.Controller,{name:"bar.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:cy,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"bar.color",control:e,render:({field:n})=>i($e,{...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"bar.label_formatter",control:e,render:({field:n})=>i(Ge,{...n})})]})]})}const py=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function hy({control:e,watch:t}){return t(["line"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"line.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Line Name",sx:{flex:1},...n})}),i(v.Controller,{name:"line.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:py,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"line.color",control:e,render:({field:n})=>i($e,{...n})})]})]})}const fy=`
|
|
176
176
|
{
|
|
177
177
|
// 80-20 line stuff
|
|
178
178
|
percentage: {
|
|
@@ -195,8 +195,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
195
195
|
name: string;
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
`,gy=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:fy})})]})};function my({control:e,watch:t}){return t(["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:e,render:({field:n})=>i($e,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(gy,{})]})]})}function yy({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,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:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function by({control:e,watch:t}){return t(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function vy({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaults({},t,
|
|
199
|
-
{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,y=h.labelLinePoints;return x.set(y,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:y}},data:d,top:10,bottom:10,left:10,right:10}}function $y(e,t,n){return{tooltip:{show:!0,confine:!0},series:Ey(e,t,n)}}const Co={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:Py,configRender:Ly,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 Ly(e){return i(B,{})}function Py(e){return i(s.Text,{children:"Click chart's series"})}const
|
|
198
|
+
`,gy=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:fy})})]})};function my({control:e,watch:t}){return t(["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:e,render:({field:n})=>i($e,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(gy,{})]})]})}function yy({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,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:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function by({control:e,watch:t}){return t(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function vy({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaults({},t,pi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,t),[d,t]);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(I.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(yy,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(by,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(dy,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(hy,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(my,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:h})=>i(oi,{...h})})})]})]})}function xy(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function wy(e){const{markLine:t=xo,...n}=e;return{...n,markLine:t}}function Cy(e){const t=x.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Ue}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function Sy(e){const{label_formatter:t=De}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function _y(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function ky(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(t,e)}function Ty(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Dy(e,{panelModel:t}){try{const n=t.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}=e;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 Iy extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:xy(n.config)})),this.version(3,n=>({...n,version:3,config:wy(n.config)})),this.version(4,n=>({...n,version:4,config:Cy(n.config)})),this.version(5,n=>({...n,version:5,config:Sy(n.config)})),this.version(6,n=>({...n,version:6,config:_y(n.config)})),this.version(7,n=>({...n,version:7,config:ky(n.config)})),this.version(8,n=>({...n,version:8,config:Ty(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Dy(n.config,r)}))}}const My={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Iy,name:"paretoChart",viewRender:uy,configRender:vy,createConfig(){return{version:9,config:x.cloneDeep(pi)}},triggers:[vo]},hi={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 Ay(){ie.registerTheme("merico-light",{color:Object.values(hi.graphics.multiple),visualMap:{color:Object.values(hi.graphics.depth).reverse()}})}function wo(){Ay()}function*zy(e){const t=hi.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function Ey(e,t,n){const{label_field:r,value_field:a,color_field:o}=e;if(!r||!a)return{};const l=P(r),u=P(a),c=P(o),d=t[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:c.columnKey?h[c.columnKey]:void 0})),f=zy("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}}
|
|
199
|
+
{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,y=h.labelLinePoints;return x.set(y,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:y}},data:d,top:10,bottom:10,left:10,right:10}}function $y(e,t,n){return{tooltip:{show:!0,confine:!0},series:Ey(e,t,n)}}const Co={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:Py,configRender:Ly,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 Ly(e){return i(B,{})}function Py(e){return i(s.Text,{children:"Click chart's series"})}const fi={label_field:"",value_field:"",color_field:""};ie.use([he.PieChart,ze.CanvasRenderer]);function Oy({conf:e,data:t,width:n,height:r,interactionManager:a}){const o=zt(t,e.label_field),l=Ke(a.triggerManager,Co.id),u=m.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=m.useMemo(()=>$y(e,t,n),[e,t,n]),d=m.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:i(Ae,{echarts:ie,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function By({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),a=m.useMemo(()=>x.defaults({},r,fi),[r]),o=e.data,{width:l,height:u}=e.viewport;return!l||!u?null:i(Be,{width:l,height:u,children:i(Oy,{conf:a,width:tt(l),height:nt(u),data:o,interactionManager:n})})}function Vy({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,fi),[t]),a=m.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(W,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(W,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(W,{label:"Color Key",clearable:!0,...g})})]})]})})}function Ny(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function qy(e,{panelModel:t}){try{const n=t.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}=e;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Fy extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ny(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:qy(n.config,r)}))}}const Gy={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new Fy,name:"pie",viewRender:By,configRender:Vy,createConfig(){return{version:3,config:x.cloneDeep(fi)}},triggers:[Co]};function Wy(e){return i(B,{})}function jy(e){return i(s.Text,{children:"Click heat block"})}const So={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:jy,configRender:Wy,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"}]},er={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function _o(e){return e?t=>{try{return Z(t).format(e)}catch(n){return console.error(n),t}}:t=>t}function ko(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>_o(e.dimensions[t].formatter)(n)}}function To(e,t){return t.map(({data_key:n})=>{const r=P(n);return e[r.columnKey]})}function Ry(e,t,n){const r=P(t);return e[r.queryID].map(a=>({value:To(a,n),name:a[r.columnKey]}))}function Yy(e,t){const{series_name_key:n,dimensions:r}=t;return[{type:"radar",name:"main-radar",data:Ry(e,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:ko(t)}]}function Qy(e,t){const{additional_series:n,dimensions:r}=t;return n.map(o=>{const l=P(o.name_key),u=P(o.color_key);return{type:"radar",colorBy:"data",data:e[l.queryID].map(f=>{const h=f[l.columnKey],g=f[u.columnKey];return{name:h,value:To(f,r),itemStyle:{color:g}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:ko(t)}}).flat()}function Uy(e,t){return[...Yy(e,t),...Qy(e,t)]}function Ky(e){return({name:t,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=e.dimensions[l],c=_o(u.formatter);return`
|
|
200
200
|
<tr>
|
|
201
201
|
<td style="padding-left: 18px;">${u.name}</td>
|
|
202
202
|
<td style="text-align: right; "><strong>${c(o)}</strong></td>
|
|
@@ -244,15 +244,15 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
244
244
|
</tbody>
|
|
245
245
|
</table>
|
|
246
246
|
`}}}function Io({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function xb(e){const{overflow:t,format:n,formatter:r,...a}=e.x_axis.axisLabel,o=rt(t.on_axis);return{type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...a,...o,formatter:(l,u)=>{let c=l;try{c=Z(l).format(n)}catch{}return Io(r)(c,u)}}}}const wb={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Cb(e,t){const n=yb(e,t),r=fb(e,n),a={xAxis:xb(e),yAxis:{name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...r],tooltip:vb(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return x.defaultsDeep({},a,wb)}function tr(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function Sb(e,t,n,r){const{x_axis:a,y_axis:o}=r,l=wt.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:e,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:Z(c).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"red",children:Z(u).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name})]}),rSquared:d,adjustedRSquared:tr(d,t.length,1)}}function _b(e,t,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=wt.regressionExp()(n);return{name:e,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:tr(c,t.length,1)}}function kb(e,t,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=wt.regressionLog()(n);return{name:e,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:tr(c,t.length,1)}}function Tb(e,t,n,r){const{x_axis:a,y_axis:o,regression:l}=r,u=wt.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:e,expression:"",rSquared:c,adjustedRSquared:tr(c,t.length,1)}}function Mo(e,t,n){const{regression:r,x_axis:a}=n,o=P(a.data_key),l=P(r.y_axis_data_key),u=t.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?Sb(e,t,u,n):r.transform.config.method==="exponential"?_b(e,t,u,n):r.transform.config.method==="logarithmic"?kb(e,t,u,n):r.transform.config.method==="polynomial"?Tb(e,t,u,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function Db(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Mo("",e,t)];const n=P(t.regression.group_by_key),r=x.groupBy(e,n.columnKey);return Object.entries(r).map(([a,o])=>Mo(a,o,t))}const Ib={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ao({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?i(s.Table,{fontSize:14,sx:Ib,children:p("tbody",{children:[i("tr",{children:i("td",{colSpan:2,children:i(s.Text,{align:"center",children:t})})}),p("tr",{children:[i("td",{children:"R-Sq"}),i("td",{style:{textAlign:"right"},children:Z(n).format({output:"percent",mantissa:1})})]}),p("tr",{children:[i("td",{children:"R-Sq(Adjusted)"}),i("td",{style:{textAlign:"right"},children:Z(r).format({output:"percent",mantissa:1})})]})]})}):i(s.Text,{children:"Unavailable for this regression method"})}function Mb({conf:e,queryData:t}){var r;const n=m.useMemo(()=>Db(t,e),[e,t]);return e.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(Ao,{desc:a})},a.name))]})):i(Ao,{desc:n[0]})}function Ab({conf:e,queryData:t}){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(E.IconInfoCircle,{size:14}),children:"Regression Info"})}),i(s.HoverCard.Dropdown,{children:i(Ee,{children:i(Mb,{conf:e,queryData:t})})})]})}function zb(e){return i(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:Oe.left,right:Oe.right,height:"22px",zIndex:1},children:i(Ab,{...e})})}const nr={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
247
|
-
`)},
|
|
247
|
+
`)},gi={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:De,overflow:We,formatter:{...nr}}},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"}};ie.use([F.DataZoomComponent,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function Eb({context:e}){const{value:t}=R(e.instanceData,"config"),{width:n,height:r}=e.viewport,a=m.useMemo(()=>{var y;const c=e.data,d=t==null?void 0:t.x_axis.data_key,f=(y=t==null?void 0:t.regression)==null?void 0:y.y_axis_data_key;if(!d||!f)return[];const h=P(d),g=P(f);return c[h.queryID].map(C=>typeof C[g.columnKey]=="number"?C:{...C,[g.columnKey]:Number(C[g.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=m.useMemo(()=>Cb(x.defaultsDeep({},t,gi),a),[t,a]),l=m.useRef(null),u=c=>{l.current=c};return!n||!r||!t?null:p(Be,{width:n,height:r,children:[i(zb,{conf:t,queryData:a}),i(Ae,{echarts:ie,onChartReady:u,option:o,style:on(n,r),notMerge:!0,theme:"merico-light"})]})}const $b=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Lb({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),r=t("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:e,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:e,render:({field:a})=>i(W,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:e,render:({field:a})=>i(s.Select,{label:"回归方法",data:$b,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:e,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:e,render:({field:a})=>i($e,{...a})})]})]})}const Pb=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},zo=m.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=Q.useBoolean(),[u,c]=m.useState(e);m.useEffect(()=>{c(e)},[e]);const d=C=>{c({...u,enabled:C})},f=()=>{l();const{enabled:C,func_content:w}=u,_={enabled:C,func_content:w};c(_),t(_)},h=()=>{l(),c(e)},g=C=>{c(w=>({...w,func_content:C}))},y=()=>{g(nr.func_content)};return p(B,{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:C=>d(C.currentTarget.checked)}),i(Pb,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:y,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function Ob({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{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:e,render:({field:n})=>i(Ge,{...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:e,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:e,render:({field:n})=>i(zo,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function Bb({control:e,watch:t}){return t(["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:e,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>i(W,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Vb({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaults({},t,gi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,t),[d,t]);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(I.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(Ob,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(Bb,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(Lb,{control:a,watch:l})})]})]})})}function Nb(e){const t={x_axis:{axisLabel:{rotate:0,format:De,overflow:We,formatter:nr}},regression:{group_by_key:""}};return x.defaultsDeep(t,e)}function qb(e,{panelModel:t}){try{const n=t.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}=e;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 Fb extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Nb(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:qb(a,r)}})}}const Gb={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new Fb,name:"regressionChart",viewRender:Eb,configRender:Vb,createConfig(){return{version:3,config:x.cloneDeep(gi)}}},rr={content:""};function Wb(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Qn(t,o,l);n[a]=Ze(r,u)}),n}function jb(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function Rb(e,t,n){try{return new Function("payload",`
|
|
248
248
|
const filters = payload.filters;
|
|
249
249
|
const context = payload.context;
|
|
250
250
|
${Object.entries(t).map(([r,a])=>`const ${r} = '${a}';`).join(`
|
|
251
251
|
`)}
|
|
252
252
|
return ${e};
|
|
253
|
-
`)(n)}catch(r){return console.error(r),console.log(e),e}}function Yb(e,t,n,r){const a=Wb(t,r),o=/^(.+)\}\}(.*)$/;return e.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=jb(u[1]);return`${Rb(d,a,n)}${u[2]}`}).join("")}const Qb=k.observer(({context:e})=>{const t=ye(),{value:n}=R(e.instanceData,"config"),{variables:r,data:a}=e,o=m.useMemo(()=>{const l=x.defaults({},n,rr);return l.content?Yb(l.content,r,t.payloadForViz,a):""},[n,r,t.payloadForViz]);return o?i(Yn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function Ub(){const{editor:e}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(E.IconBorderAll,{stroke:1.5,size:16})})}const
|
|
253
|
+
`)(n)}catch(r){return console.error(r),console.log(e),e}}function Yb(e,t,n,r){const a=Wb(t,r),o=/^(.+)\}\}(.*)$/;return e.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=jb(u[1]);return`${Rb(d,a,n)}${u[2]}`}).join("")}const Qb=k.observer(({context:e})=>{const t=ye(),{value:n}=R(e.instanceData,"config"),{variables:r,data:a}=e,o=m.useMemo(()=>{const l=x.defaults({},n,rr);return l.content?Yb(l.content,r,t.payloadForViz,a):""},[n,r,t.payloadForViz]);return o?i(Yn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function Ub(){const{editor:e}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(E.IconBorderAll,{stroke:1.5,size:16})})}const mi=m.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=m.useState(e),c=Ja.useEditor({extensions:[Za,Xa,J.Link,Wa,Ga,qa,Ya.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ka,Ua,Qa,ja.configure({types:["heading","paragraph"]}),Fa.configure({placeholder:"This is placeholder"}),Ra,Na.Color,io],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});m.useEffect(()=>{u(e),c==null||c.commands.setContent(e)},[e]);const d=()=>{t(l),a==null||a()},f=e!==l,h=m.useMemo(()=>x.defaultsDeep({},{content:Vr},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(E.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"],popoverProps:{zIndex:320}})}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Bold,{}),i(J.RichTextEditor.Italic,{}),i(J.RichTextEditor.Underline,{}),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(Ub,{})}),i(oh,{editor:c})]}),i(J.RichTextEditor.Content,{})]})]}):null});function Kb({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaults({},t,rr),[t]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),m.useEffect(()=>{u(r)},[r]);const c=m.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(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(mi,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Xb extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,rr)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Jb={displayName:"Rich Text",displayGroup:"Others",migrator:new Xb,name:"richText",viewRender:Qb,configRender:Kb,createConfig(){return{version:1,config:x.cloneDeep(rr)}}},bn={static:{type:"static",color:ht.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
|
|
254
254
|
`)}},Eo={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Hb,configRender:Zb,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 Zb(e){return i(B,{})}function Hb(e){return i(s.Text,{children:"Click scatter"})}const $o={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
255
|
-
`)},Lo={label:We.on_axis,tooltip:We.in_tooltip},
|
|
255
|
+
`)},Lo={label:We.on_axis,tooltip:We.in_tooltip},yi={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:bn.static,label_position:"right",label_overflow:Lo},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...$o}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:De,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Rt};function ev(e,t){if(!e.x_axis.data_key)return[];const n=P(e.x_axis.data_key);return[{source:t[n.queryID]}]}function tv(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis.name&&(r+=15),{top:n,bottom:r}}function nv(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function ir(e,t){if(e)return t[e]??void 0}function rv({reference_areas:e,variableValueMap:t}){const n=e.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:ir(r.leftBottomPoint.x_data_key,t),yAxis:ir(r.leftBottomPoint.y_data_key,t)},{xAxis:ir(r.rightTopPoint.x_data_key,t),yAxis:ir(r.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function iv({type:e,...t},n){if(!e)return 10;if(e==="static"){const{size:a}=t;return a}const{func_content:r}=t;return(a,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:It.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function av({type:e,...t},n){if(!e)return bn.static.color;if(e==="static"){const{color:a}=t;return a}const{func_content:r}=t;return({value:a})=>{try{return new Function(`return ${r}`)()({rowData:a,variables:n},{lodash:x,interpolate:It.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function sv(e,t,n,r){return e.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?Xn(a.template,t,r):""},position:u}}}})}function ov({x_axis:e,scatter:t},n){const r=P(e.data_key),a=P(t.y_data_key),o=P(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...rt(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:av(t.color,n)},symbolSize:iv(t.symbolSize,n),encode:{x:r.columnKey,y:a.columnKey}}}function lv(e,t,n,r){return[ov(e,r)].concat(sv(e.reference_lines,n,r,t)).concat(rv({reference_areas:e.reference_areas,variableValueMap:r}))}function Po({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Oo(e,t,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Po(r.axisLabel.formatter)(e,t):e}function uv(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const u=An(e[0].data,n.data_key);return Oo(u,0,t)}const a=e.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!a)return"";const{axisValue:o,axisIndex:l}=a;return Oo(o,l,t)}const cv=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function dv(e,t){const{scatter:n,tooltip:r}=e;return{confine:!0,trigger:r.trigger,formatter:function(a){const o=t[0]??t.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=uv(l,e),c=ot(e.scatter.label_overflow.tooltip),d=l.map(({value:y})=>`
|
|
256
256
|
<th style="text-align: right; padding-right: 1em">
|
|
257
257
|
<div style="${c}">${An(y,n.name_data_key)}</div>
|
|
258
258
|
</th>
|
|
@@ -273,8 +273,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
273
273
|
<thead><tr>${d.join("")}</tr></thead>
|
|
274
274
|
<tbody>${f.join("")}</tbody>
|
|
275
275
|
</table>
|
|
276
|
-
`}}}function pv(e,t){const n=t.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:Po(r.formatter)}}]}function hv(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,minInterval:1,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const fv={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 gv(e,t,n){const r=n.reduce((c,d)=>{const f=yt(d,t);return c[d.name]=Ze(d,f),c},{}),a=e.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let y=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?y=g.value[1]:y=g.value),!d)return y;try{return Z(y).format(d)}catch(C){return console.error(C),y}},c),{default:({value:c})=>c}),o=x.uniq(gt(t,e.x_axis.data_key)),l=lv(e,t,n,r),u={xAxis:pv(e,o),yAxis:hv(e,a),series:l,dataset:ev(e,t),tooltip:dv(e,a),grid:tv(e),legend:nv(),dataZoom:ii(e.dataZoom)};return x.defaultsDeep({},u,fv)}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Bo(e){return e.trim().length>0}function mv({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis.data_key),u=Ke(a.triggerManager,Eo.id),c=m.useCallback(h=>{const g=h.data;u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>gv(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function yv({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,mi),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=_e.useElementSize(),{ref:h,height:g}=_e.useElementSize(),y=m.useMemo(()=>{const{stats:{templates:w}}=o;return{top:yn(w.top,a,l),bottom:yn(w.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g);return!u||!c?null:p(Be,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.top)?"block":"none"},children:Object.values(y.top).map(w=>w)}),i(mv,{variables:a,width:tt(u),height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.bottom)?"block":"none"},children:Object.values(y.bottom).map(w=>w)})]})}const bv=m.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),t(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:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(ui,{label:"Text Position",value:e.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:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:e.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:e.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:e.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:e.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:e.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($e,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i($e,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function vv(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function xv({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{const g=vv();a(g)},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.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,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(v.Controller,{name:`reference_areas.${y}`,control:e,render:({field:C})=>p(s.Stack,{children:[i(bv,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(E.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(y),children:"Delete this Reference Area"})]})})},g.id))]})}const wv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Cv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Sv({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.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.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Cv,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.${t}.yAxisIndex`,control:e,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.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:wv,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,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.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function _v({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:ht.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.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,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(Sv,{control:e,index:y,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},g.id))]})}const kv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Tv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(bn.dynamic.func_content)};return p(B,{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(kv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},Dv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Tv,{value:e,onChange:t}),Iv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},Mv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Av=m.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const a=o=>{n({...bn[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Mv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Iv,{value:t,onChange:n}),i(Dv,{value:t,onChange:n})]})}),zv=m.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},a=o=>{t({...e,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(En,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),i(En,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:a})]})}),Ev=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Vo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
277
|
-
`)}},$v=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Vo.dynamic.func_content)};return p(B,{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(Ev,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},Lv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i($v,{value:e,onChange:t}),Pv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Ov=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Bv=m.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...Vo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Ov,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Pv,{value:t,onChange:n}),i(Lv,{value:t,onChange:n})]})}),Vv=[{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 Nv({control:e,watch:t}){return t(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>i(W,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>i(W,{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:e,render:({field:n})=>i(Bv,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:e,render:({field:n})=>i(Av,{...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:e,render:({field:n})=>i(s.Select,{label:"Label Position",data:Vv,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>i(zv,{...n})})]})}function qv({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(un,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(un,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Fv=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Gv=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Fv,{control:e,index:g,remove:a},h.id)},h.id))]})]})},Wv=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function jv({control:e,watch:t}){return t("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>i(s.Select,{label:"Trigger",data:Wv,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Gv,{control:e,watch:t})]})}const Rv=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Yv=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h($o.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(Rv,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Qv({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,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:e,render:({field:n})=>i(Yv,{...n})})]})]})}const Uv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Kv=[{label:"left",value:"left"},{label:"right",value:"right"}];function Xv({control:e,index:t,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.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Uv,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.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Kv,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.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...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.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Jv({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:De,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},c.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Xv,{control:e,index:d,remove:a})},c.id))]})}function Zv(e){return e||{templates:{top:"",bottom:""}}}function Hv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:Zv(t),...n}}function ex({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,mi),[t]),o=m.useMemo(()=>Hv(a),[a]);m.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});m.useEffect(()=>{f(o)},[o]);const h=d(),g=m.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(I.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(Qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Jv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Nv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(jv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(_v,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(xv,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:y})=>i(si,{...y})})})]})]})})}function tx(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function nx(e){const t={scatter:{label_overflow:Lo}};return x.defaultsDeep(t,e)}function rx(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...bn.static,color:t}}}:e}function ix(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ht.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...e,reference_lines:t}}function ax(e){const t={tooltip:{trigger:"item"}};return x.defaultsDeep({},e,t)}function sx(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=e;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 ox extends ge{constructor(){super(...arguments);q(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:tx(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:nx(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:rx(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:ix(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:ax(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:sx(a,r)}})}}const lx={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new ox,name:"scatterChart",viewRender:yv,configRender:ex,createConfig(){return{version:9,config:x.cloneDeep(mi)}},triggers:[Eo]},yi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function ux(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function cx(e){return x.omit(e,["variables"])}function dx(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function px(e){const t=x.cloneDeep(e),n=x.get(t,"color.valueRange");return n!==void 0&&x.set(t,"color.valueRange",n.map(r=>Number(r))),t}class hx extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:ux(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(px(l))}),{...n,version:2,config:cx(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:dx(r)}})}}const fx={left:"flex-start",center:"center",right:"flex-end"},gx={top:"flex-start",center:"center",bottom:"flex-end"},mx=k.observer(({context:e})=>{const t=ye(),{value:n=yi}=R(e.instanceData,"config"),{variables:r}=e,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=m.useMemo(()=>{try{return x.template(a)(t.payloadForSQL)}catch{return a}},[t.payloadForSQL,a]),f=m.useMemo(()=>yn(d,r,e.data),[d,r,e.data,e]);return i(s.Center,{sx:{width:u,height:c,justifyContent:fx[o],alignItems:gx[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(m.Fragment,{children:h},g))})})}),yx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],bx=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function vx({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,yi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,t),[d,t]);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(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(un,{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:yx,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:bx,...h})})]})]})})}const xx={createConfig(){return{version:3,config:yi}},displayName:"Stats",displayGroup:"Others",migrator:new hx,name:"stats",viewRender:mx,configRender:vx},bi={label_key:"",value_key:"",group_key:"",levels:[]};function wx(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function Cx(e){const t=wx(e).map(a=>({...a,children:[]})),n=x.keyBy(t,a=>a.id),r=[];return t.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function Sx(e,t){const{label_key:n,value_key:r,group_key:a}=e;if(!n||!r)return[];const o=P(n),l=P(r),u=P(a),c=t[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?Cx(c):c}const _x=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const a=t[t.length-2].value;if(r/a<e)return" "}catch{return n}};function kx(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:_x(r)}}})}function Tx(){return({treePathInfo:e,name:t,value:n,color:r,marker:a,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
|
|
276
|
+
`}}}function pv(e,t){const n=t.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:Po(r.formatter)}}]}function hv(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,minInterval:1,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const fv={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 gv(e,t,n){const r=n.reduce((c,d)=>{const f=yt(d,t);return c[d.name]=Ze(d,f),c},{}),a=e.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let y=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?y=g.value[1]:y=g.value),!d)return y;try{return Z(y).format(d)}catch(C){return console.error(C),y}},c),{default:({value:c})=>c}),o=x.uniq(gt(t,e.x_axis.data_key)),l=lv(e,t,n,r),u={xAxis:pv(e,o),yAxis:hv(e,a),series:l,dataset:ev(e,t),tooltip:dv(e,a),grid:tv(e),legend:nv(),dataZoom:ai(e.dataZoom)};return x.defaultsDeep({},u,fv)}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Bo(e){return e.trim().length>0}function mv({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis.data_key),u=Ke(a.triggerManager,Eo.id),c=m.useCallback(h=>{const g=h.data;u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>gv(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function yv({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,yi),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=_e.useElementSize(),{ref:h,height:g}=_e.useElementSize(),y=m.useMemo(()=>{const{stats:{templates:w}}=o;return{top:yn(w.top,a,l),bottom:yn(w.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g);return!u||!c?null:p(Be,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.top)?"block":"none"},children:Object.values(y.top).map(w=>w)}),i(mv,{variables:a,width:tt(u),height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.bottom)?"block":"none"},children:Object.values(y.bottom).map(w=>w)})]})}const bv=m.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),t(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:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(ci,{label:"Text Position",value:e.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:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:e.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:e.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:e.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:e.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:e.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($e,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i($e,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function vv(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function xv({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{const g=vv();a(g)},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.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,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(v.Controller,{name:`reference_areas.${y}`,control:e,render:({field:C})=>p(s.Stack,{children:[i(bv,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(E.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(y),children:"Delete this Reference Area"})]})})},g.id))]})}const wv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Cv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Sv({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.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.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Cv,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.${t}.yAxisIndex`,control:e,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.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:wv,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,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.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function _v({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:ht.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.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,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(Sv,{control:e,index:y,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},g.id))]})}const kv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Tv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(bn.dynamic.func_content)};return p(B,{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(kv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},Dv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Tv,{value:e,onChange:t}),Iv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},Mv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Av=m.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const a=o=>{n({...bn[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Mv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Iv,{value:t,onChange:n}),i(Dv,{value:t,onChange:n})]})}),zv=m.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},a=o=>{t({...e,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(En,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),i(En,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:a})]})}),Ev=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Vo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
277
|
+
`)}},$v=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Vo.dynamic.func_content)};return p(B,{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(Ev,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.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"})]})]})]})})]})},Lv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i($v,{value:e,onChange:t}),Pv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Ov=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Bv=m.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...Vo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Ov,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Pv,{value:t,onChange:n}),i(Lv,{value:t,onChange:n})]})}),Vv=[{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 Nv({control:e,watch:t}){return t(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>i(W,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>i(W,{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:e,render:({field:n})=>i(Bv,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:e,render:({field:n})=>i(Av,{...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:e,render:({field:n})=>i(s.Select,{label:"Label Position",data:Vv,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>i(zv,{...n})})]})}function qv({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(un,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(un,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Fv=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Gv=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Fv,{control:e,index:g,remove:a},h.id)},h.id))]})]})},Wv=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function jv({control:e,watch:t}){return t("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>i(s.Select,{label:"Trigger",data:Wv,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Gv,{control:e,watch:t})]})}const Rv=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Yv=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h($o.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(Rv,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Qv({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,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:e,render:({field:n})=>i(Yv,{...n})})]})]})}const Uv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Kv=[{label:"left",value:"left"},{label:"right",value:"right"}];function Xv({control:e,index:t,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.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Uv,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.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Kv,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.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...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.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Jv({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:De,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},c.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Xv,{control:e,index:d,remove:a})},c.id))]})}function Zv(e){return e||{templates:{top:"",bottom:""}}}function Hv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:Zv(t),...n}}function ex({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,yi),[t]),o=m.useMemo(()=>Hv(a),[a]);m.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});m.useEffect(()=>{f(o)},[o]);const h=d(),g=m.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(I.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(Qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Jv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Nv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(jv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(_v,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(xv,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:y})=>i(oi,{...y})})})]})]})})}function tx(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function nx(e){const t={scatter:{label_overflow:Lo}};return x.defaultsDeep(t,e)}function rx(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...bn.static,color:t}}}:e}function ix(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ht.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...e,reference_lines:t}}function ax(e){const t={tooltip:{trigger:"item"}};return x.defaultsDeep({},e,t)}function sx(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=e;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 ox extends ge{constructor(){super(...arguments);q(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:tx(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:nx(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:rx(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:ix(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:ax(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:sx(a,r)}})}}const lx={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new ox,name:"scatterChart",viewRender:yv,configRender:ex,createConfig(){return{version:9,config:x.cloneDeep(yi)}},triggers:[Eo]},bi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function ux(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function cx(e){return x.omit(e,["variables"])}function dx(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function px(e){const t=x.cloneDeep(e),n=x.get(t,"color.valueRange");return n!==void 0&&x.set(t,"color.valueRange",n.map(r=>Number(r))),t}class hx extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:ux(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(px(l))}),{...n,version:2,config:cx(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:dx(r)}})}}const fx={left:"flex-start",center:"center",right:"flex-end"},gx={top:"flex-start",center:"center",bottom:"flex-end"},mx=k.observer(({context:e})=>{const t=ye(),{value:n=bi}=R(e.instanceData,"config"),{variables:r}=e,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=m.useMemo(()=>{try{return x.template(a)(t.payloadForSQL)}catch{return a}},[t.payloadForSQL,a]),f=m.useMemo(()=>yn(d,r,e.data),[d,r,e.data,e]);return i(s.Center,{sx:{width:u,height:c,justifyContent:fx[o],alignItems:gx[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(m.Fragment,{children:h},g))})})}),yx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],bx=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function vx({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,bi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,t),[d,t]);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(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(un,{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:yx,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:bx,...h})})]})]})})}const xx={createConfig(){return{version:3,config:bi}},displayName:"Stats",displayGroup:"Others",migrator:new hx,name:"stats",viewRender:mx,configRender:vx},vi={label_key:"",value_key:"",group_key:"",levels:[]};function wx(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function Cx(e){const t=wx(e).map(a=>({...a,children:[]})),n=x.keyBy(t,a=>a.id),r=[];return t.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function Sx(e,t){const{label_key:n,value_key:r,group_key:a}=e;if(!n||!r)return[];const o=P(n),l=P(r),u=P(a),c=t[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?Cx(c):c}const _x=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const a=t[t.length-2].value;if(r/a<e)return" "}catch{return n}};function kx(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:_x(r)}}})}function Tx(){return({treePathInfo:e,name:t,value:n,color:r,marker:a,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
|
|
278
278
|
<th style="text-align: right; padding: 0 1em;">Value</th>
|
|
279
279
|
<td style="text-align: left; padding: 0 1em;">${n}</td>
|
|
280
280
|
</tr>
|
|
@@ -292,9 +292,9 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
292
292
|
<table style="width: auto">
|
|
293
293
|
<tbody>${u.join("")}</tbody>
|
|
294
294
|
</table>
|
|
295
|
-
`}}function Dx(){return{show:!0,trigger:"item",confine:!0,formatter:Tx()}}const Ix={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Mx(e,t,n){n.reduce((o,l)=>{const u=yt(l,t);return o[l.name]=Ze(l,u),o},{});const a={series:{data:Sx(e,t),levels:kx(e)},tooltip:Dx()};return x.defaultsDeep({},a,Ix)}ie.use([he.SunburstChart,ze.CanvasRenderer]);function Ax({context:e}){const{variables:t}=e,{value:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaults({},n,
|
|
296
|
-
`),qo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},Fo={left:"flex-start",center:"center",right:"flex-end"},Wx=({header:e,cx:t})=>{const n=x.get(e.column.columnDef.meta,"align","left");return p(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:Fo[n]},children:[e.isPlaceholder?null:et.flexRender(e.column.columnDef.header,e.getContext()),i(jx,{direction:e.column.getIsSorted()})]})},jx=({direction:e})=>{switch(e){case"asc":return i(E.IconArrowUp,{size:16});case"desc":return i(E.IconArrowDown,{size:"1em"});default:return null}},Rx=s.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Yx={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Qx=s.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:Fo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function Ux(e){return e?ht(e).oklch()[0]>.7?"black":"white":"inherit"}function Kx(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:Ux(t)}}function Ut(e){const t=e.tableCellContext.isClickable(),n=Qx({clickable:t,align:e.align});return i("div",{className:n.classes.content,style:{...Kx(e)},children:i(s.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:i("span",{title:e.children,children:e.children})})})}function Xx(e){return i(Ut,{...e,children:e.value})}function Jx(e){const t=Z(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(Ut,{...e,children:t})}function Zx(e){const t=Z(e.value).format({thousandSeparated:!0});return i(Ut,{...e,children:t})}function Hx(e){const t=Z(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return i(Ut,{...e,children:t})}function e0(e){const t=e.value,n=e.func_content;if(!n)return i(Ut,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return i(Ut,{...e,children:r})}function t0(e){switch(e.type){case it.string:return i(Xx,{...e});case it.eloc:return i(Jx,{...e});case it.number:return i(Zx,{...e});case it.percentage:return i(Hx,{...e});case it.custom:return i(e0,{...e})}}function n0({tableContainerRef:e,rows:t}){var u,c;const n=ju.useVirtual({parentRef:e,size:t.length,estimateSize:m.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:a}=n,o=r.length>0&&((u=r==null?void 0:r[0])==null?void 0:u.start)||0,l=r.length>0?a-(((c=r==null?void 0:r[r.length-1])==null?void 0:c.end)||0):0;return Q.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),p("tbody",{children:[o>0&&i("tr",{children:i("td",{style:{height:`${o}px`}})}),r.map(d=>{const f=t[d.index];return i("tr",{children:f.getVisibleCells().map(h=>i("td",{children:et.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},f.id)}),l>0&&i("tr",{children:i("td",{style:{height:`${l}px`}})})]})}const vi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:s0,configRender:i0,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"}]},r0={column:""};function Go(e,t){const{value:n}=R(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const a=ln(t,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 i0(e){const{columnsFromConfig:t,columnsFromData:n}=Go(e.instance,e.sampleData),r=t.length>0?t:n,{value:a,set:o}=R(e.trigger.triggerData,"config"),{column:l}=x.defaults({},a,r0),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 a0(e,t){return e?x.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function s0(e){const{columnsFromConfig:t}=Go(e.instance),{value:n}=R(e.trigger.triggerData,"config");return i(s.Text,{children:a0(n,t)})}function Wo(e,t,n){return Math.min(Math.max(e,t),n)}class o0{constructor(t){this.steps=t;const n=[],r=new Set;for(const a of t)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(t,n){const r=(n.to-t.to)/(n.from-t.from),a=t.to-r*t.from;return o=>r*o+a}getStepFunctionForValue(t){let n=x.findLastIndex(this.steps,r=>r.from<=t);return n=Wo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return Wo(this.getStepFunctionForValue(t)(t),0,100)}}class l0{constructor(t,n,r,a,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of t)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 t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(x.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new o0(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const u0=e=>{const t=Xe(e),n=Ke(t.triggerManager,vi.id),{colorManager:r}=m.useContext(ct);return m.useCallback(a=>new l0(e.getColIndex,a,n,t,r),[n,t,e.getColIndex])};function c0({queryData:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=Rx(),g=m.useMemo(()=>u?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(N=>({id:N,label:N,value_field:N,value_type:it.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,e]),y=u0({getColIndex:m.useCallback(N=>g.indexOf(N.column.columnDef.meta),[g]),vizManager:a.vizManager,instance:o}),C=m.useMemo(()=>{const N=et.createColumnHelper();return g.map(Y=>{const H=Tc(Y.value_field);return N.accessor(H.columnKey,{cell:se=>i(t0,{tableCellContext:y(se.cell),value:se.getValue(),type:Y.value_type,...Y}),header:Y.label,enableSorting:!0,meta:Y,size:typeof Y.width=="number"?Y.width:void 0,minSize:typeof Y.width=="number"?Y.width:void 0})})},[g,y]),[w,_]=m.useState([]),D=et.useReactTable({data:e,state:{sorting:w},onSortingChange:_,columns:C,getCoreRowModel:et.getCoreRowModel(),getSortedRowModel:et.getSortedRowModel()}),{rows:M}=D.getRowModel(),O=m.useRef(null),G=M.length,$=G>0,L=$?n-22:n,A=$?22:0;return Q.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:a,instance:o,finalColumns:g,getCellContext:y,tableColumns:C,table:D,rows:M,tableContainerRef:O}),p("div",{ref:O,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[G>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: ",G]})}),p(s.Table,{sx:{...Yx,maxHeight:L},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:A},children:D.getHeaderGroups().map(N=>i("tr",{children:N.headers.map(K=>i("th",{style:{width:K.getSize()},children:i(Wx,{header:K,cx:h})},K.id))},N.id))}),i(n0,{tableContainerRef:O,rows:M})]})]})}function d0({data:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=r,d=m.useMemo(()=>{if(!l)return[];const f=P(l);return e[f.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):i(c0,{queryData:d,width:t,height:n,conf:r,context:a,instance:o})}function p0({context:e,instance:t}){const n=e.data,{height:r,width:a}=e.viewport,{value:o}=R(e.instanceData,"config");return o?o.id_field?i(d0,{data:n,width:a,height:r,conf:o,context:e,instance:t}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const jo=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)"}}}})),h0=[{from:0,to:0},{from:100,to:100}];class f0{constructor(){q(this,"steps",new Map);q(this,"interpolation");q(this,"onChange");te.makeAutoObservable(this,{steps:te.observable},{deep:!1}),te.reaction(()=>te.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(h0):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function g0(e){const{onChange:t,color:n,index:r,value:a}=e,{classes:o}=jo(),[l,u]=m.useState(a),[c,{setTrue:d,setFalse:f}]=Q.useBoolean(!1),h=r%2===1,g=h&&a!=null,y=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),t==null||t(l)},D=Z(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:C,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:D}),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":ht(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:w,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:C,style:{opacity:y?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const m0=k.observer(({model:e})=>{const{classes:t}=jo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return i("div",{className:t.palette,children:n.map(([r,a],o)=>i(g0,{index:o,color:r,value:e.getStepFromValue(a),onChange:l=>e.changeStep(l,a)},r))})}),y0=k.observer(function(t){const n=Q.useCreation(()=>new f0,[]);return m.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:i(m0,{model:n})}),b0=e=>{const{value:t,onChange:n,colorManager:r}=e,a=r.getColorInterpolations(),[o,l]=m.useState(t),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=Q.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(D=>({...D,interpolation:_}))}const y=()=>{f(),n==null||n(te.toJS(o))};function C(_){l(D=>({...D,steps:_}))}const w=()=>{f(),l(t)};return p(B,{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,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),i(y0,{steps:o.steps,interpolation:u,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:y,children:"OK"})]})]})})]})},v0=["static","interpolation","none"].map(e=>({label:x.capitalize(e),value:e})),x0=[{from:0,to:0},{from:100,to:100}];function Ro(e){return e?x.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function w0(e,t){var n;return Ro(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function C0(e,t){return x.isObject(t)?t:{steps:x0,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const S0=m.forwardRef((e,t)=>{const{colorManager:n}=m.useContext(ct),[r,a]=m.useState(Ro(e.value)),[o,l]=m.useState(w0(n,e.value)),u=Q.useLatest(o),[c,d]=m.useState(C0(n,e.value)),f=Q.useLatest(c),h=C=>{var w,_,D;a(C||"none"),C==="static"?(w=e.onChange)==null||w.call(e,u.current):C==="none"||!C?(_=e.onChange)==null||_.call(e,"none"):(D=e.onChange)==null||D.call(e,f.current)},g=C=>{var w;l(C),(w=e.onChange)==null||w.call(e,C)},y=C=>{var w;d(C),(w=e.onChange)==null||w.call(e,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:v0}),r==="static"&&i($e,{value:o,onChange:g}),r==="interpolation"&&i(b0,{colorManager:n,value:c,onChange:y})]})}),_0={[it.eloc]:"ELOC"},k0=Object.values(it).map(e=>({label:x.get(_0,e,x.capitalize(e)),value:e})),T0=m.forwardRef(({label:e,value:t,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:e,data:k0,value:t,onChange:n,sx:r})),D0=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(No)};return m.useEffect(()=>{u(e)},[e]),p(B,{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(Te,{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(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),I0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],xi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),M0=({control:e,index:t,watch:n,remove:r,column:a})=>{const o=n(`columns.${t}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>i(T0,{label:"Value Type",sx:{flex:1},...l})}),o===it.custom&&i(v.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>i(D0,{value:l.value??No,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.${t}.width`,control:e,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.${t}.align`,control:e,render:({field:l})=>i(s.Select,{label:"Alignment",data:I0,...l})})}),i(v.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>i(S0,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},A0=({control:e,watch:t})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:e,name:"columns"}),l=()=>{const c=_e.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:it.string,width:""})};t("columns");const u=t("use_raw_columns");return p(B,{children:[i(v.Controller,{name:"use_raw_columns",control:e,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(I.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(M0,{control:e,watch:t,index:d,column:c,remove:a})},c.id))]})})]})};function z0({control:e,watch:t}){return t(["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:e,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:e,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:e,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:e,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function E0({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??_e.randomId(),...r}))}}function $0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,qo),[t]),a=m.useMemo(()=>E0(r),[r]);m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(W,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(A0,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(z0,{control:o,watch:u})})]})]})}function L0(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function P0(e,{panelModel:t}){try{const n=t.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}=e;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 O0(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class B0 extends ge{constructor(){super(...arguments);q(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??_e.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:L0(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:P0(n.config,r)})),this.version(5,n=>({...n,version:5,config:O0(n.config)}))}}const wi={createConfig(){return{version:5,config:x.cloneDeep(qo)}},displayName:"Table",displayGroup:"Others",migrator:new B0,name:"table",viewRender:p0,configRender:$0,triggers:[vi]},Yo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
297
|
-
`),Ci={func_content:Yo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},V0=k.observer(({context:e})=>{const t=ye(),{value:n=Ci}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=m.useMemo(()=>r.reduce((h,g)=>{const y=yt(g,a);return h[g.name]=Ze(g,y),h},{}),[r,a]),f=m.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,a,d,t.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),N0=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative"},children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},q0=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(Yo)};return m.useEffect(()=>{u(e)},[e]),p(B,{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(N0,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),F0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function G0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Ci),[t]),a=m.useMemo(()=>{const{func_content:g,horizontal_align:y,font_size:C,font_weight:w}=r;return{func_content:g,horizontal_align:y,font_size:C,font_weight:w}},[r]);m.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});m.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=m.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(I.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(q0,{...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:F0,...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(so,{label:"Font Weight",...g})})})]})]})})}class W0 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const j0={displayName:"Text",displayGroup:"Others",migrator:new W0,name:"text",viewRender:V0,configRender:G0,createConfig(){return{version:1,config:x.cloneDeep(Ci)}}},R0=()=>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 Qo(e,t){const n=x.get(e,t,"");if(n)throw new Error(n)}async function Y0(e,t,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:e,method:"POST",url:t,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 Q0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=e;if(!r||!a||!o)return;const l=Dc(t);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Y0(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Qo(c,"response.data.detail"),Qo(c,"response.data.error"),console.error(c),c}},Si={expertSystemURL:"",path:"",goal:"",question:""},_i={height:"100%",overflowY:"auto",...Br},Uo=({message:e})=>i(s.Box,{sx:_i,children:i("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),U0=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return i(Uo,{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(R0,{}),i(Uo,{message:r})]})})};function K0({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaultsDeep({},t,Si),[t]),{width:r,height:a}=e.viewport,o=e.data,{data:l,error:u,loading:c}=Q.useRequest(Q0({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:_i,"data-enable-scrollbar":!0,children:i(U0,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:_i,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function X0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Si),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=m.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(I.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class J0 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Z0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new J0,name:"mericoGQM",viewRender:K0,configRender:X0,createConfig(){return{version:1,config:x.cloneDeep(Si)}}};function H0(e,t,n){if(!e)return n[0];try{return[t,U(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function ew(e,t,n){const r=H0(e,t,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 tw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function nw(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function rw(e,t,n,r){const{calendar:a,heat_block:o}=e,l=P(a.data_key),u=P(o.data_key);return t?{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 iw=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function aw({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(f=>{const h=P(f.data_key);c.push({label:f.name,value:iw(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function sw(e,t,n){const r=P(e.calendar.data_key),a=x.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=aw({conf:e,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
295
|
+
`}}function Dx(){return{show:!0,trigger:"item",confine:!0,formatter:Tx()}}const Ix={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Mx(e,t,n){n.reduce((o,l)=>{const u=yt(l,t);return o[l.name]=Ze(l,u),o},{});const a={series:{data:Sx(e,t),levels:kx(e)},tooltip:Dx()};return x.defaultsDeep({},a,Ix)}ie.use([he.SunburstChart,ze.CanvasRenderer]);function Ax({context:e}){const{variables:t}=e,{value:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaults({},n,vi),[n]),a=e.data,{width:o,height:l}=e.viewport,u=m.useMemo(()=>Mx(r,a,t),[r,a,t]);return!o||!l?null:i(Be,{width:o,height:l,children:i(Ae,{echarts:ie,option:u,style:on(o,l),notMerge:!0,theme:"merico-light"})})}function zx({control:e,watch:t}){return t(["label_key","value_key","group_key"]),p(s.Stack,{children:[i(v.Controller,{name:"label_key",control:e,render:({field:n})=>i(W,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:e,render:({field:n})=>i(W,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:e,render:({field:n})=>i(W,{label:"Group Key",clearable:!0,...n})})]})}const Ex=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],$x=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Lx=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.r0`,control:e,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${t}.r`,control:e,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.${t}.label.show_label_tolerance`,control:e,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.${t}.label.rotate`,control:e,render:({field:r})=>i(s.Select,{label:"Rotate",data:Ex,...r})}),i(v.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>i(s.Select,{label:"Align",data:$x,...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:r})=>i(ci,{label:"Position",...r})}),i(v.Controller,{name:`levels.${t}.label.padding`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),Px=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"levels"}),o=t("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=t("levels.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Lx,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Ox({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,vi),[t]),a=m.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,r),[f,r]);u(["label_key","value_key","group_key","levels"]);const[g,y]=m.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(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{value:g,onTabChange:y,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(zx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(Px,{control:o,watch:u})})]})]})})}function Bx(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function Vx(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function Nx(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function qx(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=e;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Fx extends ge{constructor(){super(...arguments);q(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Bx(n.config)})),this.version(3,n=>({...n,version:3,config:Vx(n.config)})),this.version(4,n=>({...n,version:4,config:Nx(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:qx(n.config,r)}))}}const Gx={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Fx,name:"sunburst",viewRender:Ax,configRender:Ox,createConfig(){return{version:5,config:x.cloneDeep(vi)}}};var it=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(it||{});const No=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
|
|
296
|
+
`),qo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},Fo={left:"flex-start",center:"center",right:"flex-end"},Wx=({header:e,cx:t})=>{const n=x.get(e.column.columnDef.meta,"align","left");return p(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:Fo[n]},children:[e.isPlaceholder?null:et.flexRender(e.column.columnDef.header,e.getContext()),i(jx,{direction:e.column.getIsSorted()})]})},jx=({direction:e})=>{switch(e){case"asc":return i(E.IconArrowUp,{size:16});case"desc":return i(E.IconArrowDown,{size:"1em"});default:return null}},Rx=s.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Yx={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Qx=s.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:Fo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function Ux(e){return e?ht(e).oklch()[0]>.7?"black":"white":"inherit"}function Kx(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:Ux(t)}}function Ut(e){const t=e.tableCellContext.isClickable(),n=Qx({clickable:t,align:e.align});return i("div",{className:n.classes.content,style:{...Kx(e)},children:i(s.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:i("span",{title:e.children,children:e.children})})})}function Xx(e){return i(Ut,{...e,children:e.value})}function Jx(e){const t=Z(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(Ut,{...e,children:t})}function Zx(e){const t=Z(e.value).format({thousandSeparated:!0});return i(Ut,{...e,children:t})}function Hx(e){const t=Z(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return i(Ut,{...e,children:t})}function e0(e){const t=e.value,n=e.func_content;if(!n)return i(Ut,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return i(Ut,{...e,children:r})}function t0(e){switch(e.type){case it.string:return i(Xx,{...e});case it.eloc:return i(Jx,{...e});case it.number:return i(Zx,{...e});case it.percentage:return i(Hx,{...e});case it.custom:return i(e0,{...e})}}function n0({tableContainerRef:e,rows:t}){var u,c;const n=ju.useVirtual({parentRef:e,size:t.length,estimateSize:m.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:a}=n,o=r.length>0&&((u=r==null?void 0:r[0])==null?void 0:u.start)||0,l=r.length>0?a-(((c=r==null?void 0:r[r.length-1])==null?void 0:c.end)||0):0;return Q.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),p("tbody",{children:[o>0&&i("tr",{children:i("td",{style:{height:`${o}px`}})}),r.map(d=>{const f=t[d.index];return i("tr",{children:f.getVisibleCells().map(h=>i("td",{children:et.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},f.id)}),l>0&&i("tr",{children:i("td",{style:{height:`${l}px`}})})]})}const xi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:s0,configRender:i0,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"}]},r0={column:""};function Go(e,t){const{value:n}=R(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const a=ln(t,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 i0(e){const{columnsFromConfig:t,columnsFromData:n}=Go(e.instance,e.sampleData),r=t.length>0?t:n,{value:a,set:o}=R(e.trigger.triggerData,"config"),{column:l}=x.defaults({},a,r0),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 a0(e,t){return e?x.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function s0(e){const{columnsFromConfig:t}=Go(e.instance),{value:n}=R(e.trigger.triggerData,"config");return i(s.Text,{children:a0(n,t)})}function Wo(e,t,n){return Math.min(Math.max(e,t),n)}class o0{constructor(t){this.steps=t;const n=[],r=new Set;for(const a of t)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(t,n){const r=(n.to-t.to)/(n.from-t.from),a=t.to-r*t.from;return o=>r*o+a}getStepFunctionForValue(t){let n=x.findLastIndex(this.steps,r=>r.from<=t);return n=Wo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return Wo(this.getStepFunctionForValue(t)(t),0,100)}}class l0{constructor(t,n,r,a,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of t)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===xi.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 t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(x.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new o0(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const u0=e=>{const t=Xe(e),n=Ke(t.triggerManager,xi.id),{colorManager:r}=m.useContext(ct);return m.useCallback(a=>new l0(e.getColIndex,a,n,t,r),[n,t,e.getColIndex])};function c0({queryData:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=Rx(),g=m.useMemo(()=>u?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(N=>({id:N,label:N,value_field:N,value_type:it.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,e]),y=u0({getColIndex:m.useCallback(N=>g.indexOf(N.column.columnDef.meta),[g]),vizManager:a.vizManager,instance:o}),C=m.useMemo(()=>{const N=et.createColumnHelper();return g.map(Y=>{const H=Tc(Y.value_field);return N.accessor(H.columnKey,{cell:se=>i(t0,{tableCellContext:y(se.cell),value:se.getValue(),type:Y.value_type,...Y}),header:Y.label,enableSorting:!0,meta:Y,size:typeof Y.width=="number"?Y.width:void 0,minSize:typeof Y.width=="number"?Y.width:void 0})})},[g,y]),[w,_]=m.useState([]),D=et.useReactTable({data:e,state:{sorting:w},onSortingChange:_,columns:C,getCoreRowModel:et.getCoreRowModel(),getSortedRowModel:et.getSortedRowModel()}),{rows:M}=D.getRowModel(),O=m.useRef(null),G=M.length,$=G>0,L=$?n-22:n,A=$?22:0;return Q.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:a,instance:o,finalColumns:g,getCellContext:y,tableColumns:C,table:D,rows:M,tableContainerRef:O}),p("div",{ref:O,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[G>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: ",G]})}),p(s.Table,{sx:{...Yx,maxHeight:L},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:A},children:D.getHeaderGroups().map(N=>i("tr",{children:N.headers.map(K=>i("th",{style:{width:K.getSize()},children:i(Wx,{header:K,cx:h})},K.id))},N.id))}),i(n0,{tableContainerRef:O,rows:M})]})]})}function d0({data:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=r,d=m.useMemo(()=>{if(!l)return[];const f=P(l);return e[f.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):i(c0,{queryData:d,width:t,height:n,conf:r,context:a,instance:o})}function p0({context:e,instance:t}){const n=e.data,{height:r,width:a}=e.viewport,{value:o}=R(e.instanceData,"config");return o?o.id_field?i(d0,{data:n,width:a,height:r,conf:o,context:e,instance:t}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const jo=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)"}}}})),h0=[{from:0,to:0},{from:100,to:100}];class f0{constructor(){q(this,"steps",new Map);q(this,"interpolation");q(this,"onChange");te.makeAutoObservable(this,{steps:te.observable},{deep:!1}),te.reaction(()=>te.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(h0):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function g0(e){const{onChange:t,color:n,index:r,value:a}=e,{classes:o}=jo(),[l,u]=m.useState(a),[c,{setTrue:d,setFalse:f}]=Q.useBoolean(!1),h=r%2===1,g=h&&a!=null,y=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),t==null||t(l)},D=Z(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:C,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:D}),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":ht(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:w,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:C,style:{opacity:y?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const m0=k.observer(({model:e})=>{const{classes:t}=jo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return i("div",{className:t.palette,children:n.map(([r,a],o)=>i(g0,{index:o,color:r,value:e.getStepFromValue(a),onChange:l=>e.changeStep(l,a)},r))})}),y0=k.observer(function(t){const n=Q.useCreation(()=>new f0,[]);return m.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:i(m0,{model:n})}),b0=e=>{const{value:t,onChange:n,colorManager:r}=e,a=r.getColorInterpolations(),[o,l]=m.useState(t),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=Q.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(D=>({...D,interpolation:_}))}const y=()=>{f(),n==null||n(te.toJS(o))};function C(_){l(D=>({...D,steps:_}))}const w=()=>{f(),l(t)};return p(B,{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,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),i(y0,{steps:o.steps,interpolation:u,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:y,children:"OK"})]})]})})]})},v0=["static","interpolation","none"].map(e=>({label:x.capitalize(e),value:e})),x0=[{from:0,to:0},{from:100,to:100}];function Ro(e){return e?x.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function w0(e,t){var n;return Ro(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function C0(e,t){return x.isObject(t)?t:{steps:x0,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const S0=m.forwardRef((e,t)=>{const{colorManager:n}=m.useContext(ct),[r,a]=m.useState(Ro(e.value)),[o,l]=m.useState(w0(n,e.value)),u=Q.useLatest(o),[c,d]=m.useState(C0(n,e.value)),f=Q.useLatest(c),h=C=>{var w,_,D;a(C||"none"),C==="static"?(w=e.onChange)==null||w.call(e,u.current):C==="none"||!C?(_=e.onChange)==null||_.call(e,"none"):(D=e.onChange)==null||D.call(e,f.current)},g=C=>{var w;l(C),(w=e.onChange)==null||w.call(e,C)},y=C=>{var w;d(C),(w=e.onChange)==null||w.call(e,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:v0}),r==="static"&&i($e,{value:o,onChange:g}),r==="interpolation"&&i(b0,{colorManager:n,value:c,onChange:y})]})}),_0={[it.eloc]:"ELOC"},k0=Object.values(it).map(e=>({label:x.get(_0,e,x.capitalize(e)),value:e})),T0=m.forwardRef(({label:e,value:t,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:e,data:k0,value:t,onChange:n,sx:r})),D0=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(No)};return m.useEffect(()=>{u(e)},[e]),p(B,{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(Te,{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(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),I0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],wi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),M0=({control:e,index:t,watch:n,remove:r,column:a})=>{const o=n(`columns.${t}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>i(T0,{label:"Value Type",sx:{flex:1},...l})}),o===it.custom&&i(v.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>i(D0,{value:l.value??No,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(wi,{}),disabled:!0}),i(v.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(wi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(wi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>i(s.Select,{label:"Alignment",data:I0,...l})})}),i(v.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>i(S0,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},A0=({control:e,watch:t})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:e,name:"columns"}),l=()=>{const c=_e.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:it.string,width:""})};t("columns");const u=t("use_raw_columns");return p(B,{children:[i(v.Controller,{name:"use_raw_columns",control:e,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(I.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(M0,{control:e,watch:t,index:d,column:c,remove:a})},c.id))]})})]})};function z0({control:e,watch:t}){return t(["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:e,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:e,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:e,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:e,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function E0({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??_e.randomId(),...r}))}}function $0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,qo),[t]),a=m.useMemo(()=>E0(r),[r]);m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(W,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(A0,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(z0,{control:o,watch:u})})]})]})}function L0(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function P0(e,{panelModel:t}){try{const n=t.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}=e;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 O0(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class B0 extends ge{constructor(){super(...arguments);q(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??_e.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:L0(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:P0(n.config,r)})),this.version(5,n=>({...n,version:5,config:O0(n.config)}))}}const Ci={createConfig(){return{version:5,config:x.cloneDeep(qo)}},displayName:"Table",displayGroup:"Others",migrator:new B0,name:"table",viewRender:p0,configRender:$0,triggers:[xi]},Yo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
297
|
+
`),Si={func_content:Yo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},V0=k.observer(({context:e})=>{const t=ye(),{value:n=Si}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=m.useMemo(()=>r.reduce((h,g)=>{const y=yt(g,a);return h[g.name]=Ze(g,y),h},{}),[r,a]),f=m.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,a,d,t.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),N0=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative"},children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},q0=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(Yo)};return m.useEffect(()=>{u(e)},[e]),p(B,{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(N0,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),F0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function G0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Si),[t]),a=m.useMemo(()=>{const{func_content:g,horizontal_align:y,font_size:C,font_weight:w}=r;return{func_content:g,horizontal_align:y,font_size:C,font_weight:w}},[r]);m.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});m.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=m.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(I.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(q0,{...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:F0,...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(so,{label:"Font Weight",...g})})})]})]})})}class W0 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const j0={displayName:"Text",displayGroup:"Others",migrator:new W0,name:"text",viewRender:V0,configRender:G0,createConfig(){return{version:1,config:x.cloneDeep(Si)}}},R0=()=>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 Qo(e,t){const n=x.get(e,t,"");if(n)throw new Error(n)}async function Y0(e,t,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:e,method:"POST",url:t,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 Q0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=e;if(!r||!a||!o)return;const l=Dc(t);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Y0(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Qo(c,"response.data.detail"),Qo(c,"response.data.error"),console.error(c),c}},_i={expertSystemURL:"",path:"",goal:"",question:""},ki={height:"100%",overflowY:"auto",...Vr},Uo=({message:e})=>i(s.Box,{sx:ki,children:i("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),U0=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return i(Uo,{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(R0,{}),i(Uo,{message:r})]})})};function K0({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaultsDeep({},t,_i),[t]),{width:r,height:a}=e.viewport,o=e.data,{data:l,error:u,loading:c}=Q.useRequest(Q0({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:ki,"data-enable-scrollbar":!0,children:i(U0,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:ki,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function X0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,_i),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=m.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(I.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class J0 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Z0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new J0,name:"mericoGQM",viewRender:K0,configRender:X0,createConfig(){return{version:1,config:x.cloneDeep(_i)}}};function H0(e,t,n){if(!e)return n[0];try{return[t,U(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function ew(e,t,n){const r=H0(e,t,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 tw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function nw(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function rw(e,t,n,r){const{calendar:a,heat_block:o}=e,l=P(a.data_key),u=P(o.data_key);return t?{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 iw=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function aw({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(f=>{const h=P(f.data_key);c.push({label:f.name,value:iw(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function sw(e,t,n){const r=P(e.calendar.data_key),a=x.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=aw({conf:e,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
298
298
|
<tr>
|
|
299
299
|
<th style="text-align: right;">
|
|
300
300
|
<div style="${f.style.label}">${f.label}</div>
|
|
@@ -320,7 +320,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
320
320
|
</thead>
|
|
321
321
|
<tbody>${u.join("")}</tbody>
|
|
322
322
|
</table>
|
|
323
|
-
`}}}function ow(e,t,n){const r=Qt(e.heat_block.min,n),a=Qt(e.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const lw={tooltip:{confine:!0},grid:{containLabel:!0}},uw=e=>U(e).get("year");function cw(e,t){const n=P(e.calendar.data_key),r=t[n.queryID],a=x.groupBy(r,d=>uw(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>U(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:U(c).diff(u,"day"),dataByYear:a,years:o}}function dw(e,t,n){const r=n.reduce((h,g)=>{const y=yt(g,t);return h[g.name]=Ze(g,y),h},{}),a=tw(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=cw(e,t),d=o<=366,f={calendar:ew(d,l,c),series:rw(e,d,u,t),tooltip:sw(e,t,a),visualMap:ow(e,d,r),legend:nw(d,c)};return x.defaultsDeep({},f,lw)}function pw(e){return i(B,{})}function hw(e){return i(s.Text,{children:"Click heat block"})}const Ko={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:hw,configRender:pw,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"}]},ki={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:De},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,F.CalendarComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function fw({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function gw({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.calendar.data_key),u=Ke(a.triggerManager,Ko.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c,legendselectchanged:fw}),[c]),f=m.useMemo(()=>dw(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function mw({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,ki),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:i(Be,{width:u,height:c,children:i(gw,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function yw({control:e,watch:t}){return t(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:e,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:e,render:({field:n})=>i(Yt,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:n})=>i(Yt,{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:e,render:({field:n})=>i(Ge,{...n})})]})}const bw=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),vw=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(bw,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function xw({control:e,watch:t}){return i(vw,{control:e,watch:t})}const ww=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Cw({control:e,watch:t}){return t(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:e,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:ww,sx:{flex:1},...n})})]})}function Sw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,ki),[t]),a=m.useMemo(()=>x.cloneDeep(r),[r]);m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(Cw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(yw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(xw,{control:o,watch:u})})]})]})})}function _w(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=e;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 kw(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tw extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:_w(n.config,r)})),this.version(3,n=>({...n,version:3,config:kw(n.config)}))}}const Dw={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Tw,name:"calendarHeatmap",viewRender:mw,configRender:Sw,createConfig:()=>({version:3,config:ki}),triggers:[Ko]},Ti={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:De,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ue},overflow:We},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Iw(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:De,show:!0}}function Mw(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:jt,xAxisIndex:"0"}}function Aw(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zw(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const r=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),e.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function Ew(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function $w(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Ew(r)})),t}function Lw(e,t,n,r){return e.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?Xn(a.template,t,r):""},position:u}}}})}function ar(e,t,n){const r=gt(e,t),a=gt(e,n);return x.zip(a,r)}function Pw(e,t,n,r){const a=ar(t,n,r);return x.unionBy(a,e,0)}function Ow({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?Pw(e,t,n,r):ar(t,n,r)}function Bw({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Ow({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=ar(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(y=>y[1]),g=Hr(h,n);return[d,g]})}function Vw({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=P(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ar({[a]:c},r,n)}),l}function Nw({y_axis:e},{data_key:t,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},y,C,w,_,D){const M={label:{show:!!r,position:r,formatter:D[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===e.data_key)return M.data=Bw({dataTemplate:y,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:C}),M;const O=Vw({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(O).map(([G,$])=>{const L=x.cloneDeep(M);return L.name=G,L.color=void 0,L.data=$,L})}function qw(e,t,n,r,a,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>Nw(e,d,u,n,r,l,a)).flat().concat(Lw(e.reference_lines,o,l,r))}function Fw(e,t){const n=e.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:Ft(t.y_axis.axisLabel.formatter)(o,l)}function Gw(e,t,n){const r=t.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],y=n[g]??n.default;return`
|
|
323
|
+
`}}}function ow(e,t,n){const r=Qt(e.heat_block.min,n),a=Qt(e.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const lw={tooltip:{confine:!0},grid:{containLabel:!0}},uw=e=>U(e).get("year");function cw(e,t){const n=P(e.calendar.data_key),r=t[n.queryID],a=x.groupBy(r,d=>uw(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>U(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:U(c).diff(u,"day"),dataByYear:a,years:o}}function dw(e,t,n){const r=n.reduce((h,g)=>{const y=yt(g,t);return h[g.name]=Ze(g,y),h},{}),a=tw(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=cw(e,t),d=o<=366,f={calendar:ew(d,l,c),series:rw(e,d,u,t),tooltip:sw(e,t,a),visualMap:ow(e,d,r),legend:nw(d,c)};return x.defaultsDeep({},f,lw)}function pw(e){return i(B,{})}function hw(e){return i(s.Text,{children:"Click heat block"})}const Ko={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:hw,configRender:pw,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"}]},Ti={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:De},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,F.CalendarComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function fw({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function gw({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.calendar.data_key),u=Ke(a.triggerManager,Ko.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c,legendselectchanged:fw}),[c]),f=m.useMemo(()=>dw(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function mw({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,Ti),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:i(Be,{width:u,height:c,children:i(gw,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function yw({control:e,watch:t}){return t(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:e,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:e,render:({field:n})=>i(Yt,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:n})=>i(Yt,{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:e,render:({field:n})=>i(Ge,{...n})})]})}const bw=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),vw=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(bw,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function xw({control:e,watch:t}){return i(vw,{control:e,watch:t})}const ww=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Cw({control:e,watch:t}){return t(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:e,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:ww,sx:{flex:1},...n})})]})}function Sw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Ti),[t]),a=m.useMemo(()=>x.cloneDeep(r),[r]);m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(Cw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(yw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(xw,{control:o,watch:u})})]})]})})}function _w(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=e;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 kw(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tw extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:_w(n.config,r)})),this.version(3,n=>({...n,version:3,config:kw(n.config)}))}}const Dw={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Tw,name:"calendarHeatmap",viewRender:mw,configRender:Sw,createConfig:()=>({version:3,config:Ti}),triggers:[Ko]},Di={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:De,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ue},overflow:We},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Iw(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:De,show:!0}}function Mw(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:jt,xAxisIndex:"0"}}function Aw(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zw(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const r=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),e.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function Ew(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function $w(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Ew(r)})),t}function Lw(e,t,n,r){return e.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?Xn(a.template,t,r):""},position:u}}}})}function ar(e,t,n){const r=gt(e,t),a=gt(e,n);return x.zip(a,r)}function Pw(e,t,n,r){const a=ar(t,n,r);return x.unionBy(a,e,0)}function Ow({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?Pw(e,t,n,r):ar(t,n,r)}function Bw({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Ow({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=ar(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(y=>y[1]),g=ei(h,n);return[d,g]})}function Vw({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=P(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ar({[a]:c},r,n)}),l}function Nw({y_axis:e},{data_key:t,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},y,C,w,_,D){const M={label:{show:!!r,position:r,formatter:D[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===e.data_key)return M.data=Bw({dataTemplate:y,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:C}),M;const O=Vw({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(O).map(([G,$])=>{const L=x.cloneDeep(M);return L.name=G,L.color=void 0,L.data=$,L})}function qw(e,t,n,r,a,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>Nw(e,d,u,n,r,l,a)).flat().concat(Lw(e.reference_lines,o,l,r))}function Fw(e,t){const n=e.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:Ft(t.y_axis.axisLabel.formatter)(o,l)}function Gw(e,t,n){const r=t.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],y=n[g]??n.default;return`
|
|
324
324
|
<tr>
|
|
325
325
|
<td>${f}</td>
|
|
326
326
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
@@ -335,7 +335,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
335
335
|
${l.join("")}
|
|
336
336
|
</tbody>
|
|
337
337
|
</table>
|
|
338
|
-
`}}}function Ww(e){return e.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 Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function jw(e,t){const n={};return t.map(r=>{const a=yt(r,e);n[r.name]=Ze(r,a)}),n}function Rw(e,t){return e.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:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Yw(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=e.y_axis.axisLabel,o=rt(r.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Ft(a.formatter)},z:5}]}function Qw(e,t,n){if(!e.y_axis.data_key)return{};const r=jw(t,n),a=Ww(e),o=P(e.y_axis.data_key),l=x.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=qw(e,l,u,t,a,n,r);return{xAxis:Rw(e,a),yAxis:Yw(e,l),series:c,tooltip:Gw(e,c,a),grid:zw(e),legend:$w(c)}}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Uw({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.y_axis.data_key),u=Ke(a.triggerManager,ni.id),c=m.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Qw(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Kw({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,Ti),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(Uw,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}const Xw=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Jw=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Zw({control:e,index:t,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${t}.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.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Jw,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.${t}.xAxisIndex`,control:e,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.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Xw,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,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.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Hw({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((y,C)=>({...y,...l[C]})),c=()=>{const y=Aw();a(y)},d=m.useMemo(()=>n.map(y=>({label:y.name,value:y.name})),[n]),f=t("x_axes"),h=m.useMemo(()=>f.map(({name:y},C)=>({label:y,value:C.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((y,C)=>i(s.Tabs.Tab,{value:y.id,children:y.name},y.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((y,C)=>i(s.Tabs.Panel,{value:y.id,children:i(Zw,{control:e,index:C,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},y.id))]})}function eC(e){const[t,n]=m.useState(e);return m.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const tC=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function nC({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:tC,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const rC=[{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 iC({control:e,index:t,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.${t}.name`,control:e,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.xAxisIndex`,control:e,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.${t}.data_key`,control:e,render:({field:o})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>i(Un,{label:"Aggregation on Value",value:o.value??jt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(nC,{index:t,control:e,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>i(s.Select,{label:"Label Position",data:rC,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>i($e,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,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.${t}.invisible`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function aC({control:e,watch:t}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((y,C)=>({...y,...o[C]})),u=()=>{const y=Mw();r(y)},c=t("x_axes"),d=m.useMemo(()=>c.map(({name:y},C)=>({label:y,value:C.toString()})),[c]),{tab:f,setTab:h}=eC((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(y=>i(s.Tabs.Tab,{value:y.id,children:y.name},y.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((y,C)=>i(s.Tabs.Panel,{value:y.id,children:i(iC,{control:e,index:C,remove:a,seriesItem:y,xAxisOptions:d},y.id)},y.id))]})}const sC=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function oC({control:e,index:t,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.${t}.name`,control:e,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.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:sC,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.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...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.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${t}.max`,control:e,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.${t}.show`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function lC({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=Iw();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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(oC,{control:e,index:f,remove:a})},d.id))]})}function uC({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,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:e,render:({field:n})=>i(Jn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function cC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,Ti),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=m.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(I.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(lC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(uC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(aC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Hw,{variables:r,control:o,watch:u})})]})]})})}function dC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=e;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 pC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:dC(a,r)}})}}const hC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new pC,name:"horizontalBarChart",viewRender:Kw,configRender:cC,createConfig:()=>({version:2,config:Ti})},Di={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...nr}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function fC(){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 Xo=({value:e})=>{try{return Z(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function gC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.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:Xo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
338
|
+
`}}}function Ww(e){return e.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 Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function jw(e,t){const n={};return t.map(r=>{const a=yt(r,e);n[r.name]=Ze(r,a)}),n}function Rw(e,t){return e.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:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Yw(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=e.y_axis.axisLabel,o=rt(r.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Ft(a.formatter)},z:5}]}function Qw(e,t,n){if(!e.y_axis.data_key)return{};const r=jw(t,n),a=Ww(e),o=P(e.y_axis.data_key),l=x.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=qw(e,l,u,t,a,n,r);return{xAxis:Rw(e,a),yAxis:Yw(e,l),series:c,tooltip:Gw(e,c,a),grid:zw(e),legend:$w(c)}}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Uw({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.y_axis.data_key),u=Ke(a.triggerManager,ri.id),c=m.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Qw(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Kw({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,Di),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(Uw,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}const Xw=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Jw=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Zw({control:e,index:t,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${t}.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.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,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.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Jw,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.${t}.xAxisIndex`,control:e,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.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Xw,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,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.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Hw({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((y,C)=>({...y,...l[C]})),c=()=>{const y=Aw();a(y)},d=m.useMemo(()=>n.map(y=>({label:y.name,value:y.name})),[n]),f=t("x_axes"),h=m.useMemo(()=>f.map(({name:y},C)=>({label:y,value:C.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((y,C)=>i(s.Tabs.Tab,{value:y.id,children:y.name},y.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((y,C)=>i(s.Tabs.Panel,{value:y.id,children:i(Zw,{control:e,index:C,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},y.id))]})}function eC(e){const[t,n]=m.useState(e);return m.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const tC=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function nC({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:tC,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const rC=[{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 iC({control:e,index:t,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.${t}.name`,control:e,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.xAxisIndex`,control:e,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.${t}.data_key`,control:e,render:({field:o})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>i(Un,{label:"Aggregation on Value",value:o.value??jt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(nC,{index:t,control:e,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>i(s.Select,{label:"Label Position",data:rC,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>i($e,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,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.${t}.invisible`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function aC({control:e,watch:t}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((y,C)=>({...y,...o[C]})),u=()=>{const y=Mw();r(y)},c=t("x_axes"),d=m.useMemo(()=>c.map(({name:y},C)=>({label:y,value:C.toString()})),[c]),{tab:f,setTab:h}=eC((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(y=>i(s.Tabs.Tab,{value:y.id,children:y.name},y.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((y,C)=>i(s.Tabs.Panel,{value:y.id,children:i(iC,{control:e,index:C,remove:a,seriesItem:y,xAxisOptions:d},y.id)},y.id))]})}const sC=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function oC({control:e,index:t,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.${t}.name`,control:e,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.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:sC,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.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...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.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${t}.max`,control:e,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.${t}.show`,control:e,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(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function lC({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=Iw();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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(oC,{control:e,index:f,remove:a})},d.id))]})}function uC({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,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:e,render:({field:n})=>i(Jn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function cC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,Di),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=m.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(I.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(lC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(uC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(aC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Hw,{variables:r,control:o,watch:u})})]})]})})}function dC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=e;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 pC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:dC(a,r)}})}}const hC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new pC,name:"horizontalBarChart",viewRender:Kw,configRender:cC,createConfig:()=>({version:2,config:Di})},Ii={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...nr}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function fC(){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 Xo=({value:e})=>{try{return Z(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function gC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.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:Xo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
339
339
|
<table style="width: auto">
|
|
340
340
|
<thead>
|
|
341
341
|
<tr colspan="2">
|
|
@@ -414,8 +414,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
414
414
|
</tr>
|
|
415
415
|
</tbody>
|
|
416
416
|
</table>
|
|
417
|
-
`}},show_in_legend:!0}))}function xC(e,t,n,r){const a=P(t.data_key),o=t.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 wC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[gC(e,n,r),yC(e,n,r,l),...vC(e,n,r,l),xC(e,t,n,r)]}function CC(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Io(n.formatter)},axisLine:{show:!1}}]}function SC(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function Ii(e){return e==1||e==2?1:Ii(e-2)+Ii(e-1)}const _C=Array.from(new Array(20),(e,t)=>Ii(t+1));function Zo(e){return e<=1?e:_C.findIndex(t=>e<=t)-1}function kC(e,t){const{x_axis:n,deviation:r}=e,a=P(n.data_key),o=P(r.data_keys.estimated_value),l=P(r.data_keys.actual_value);return t[a.queryID].map(u=>{const c=Zo(u[o.columnKey]),d=Zo(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function TC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function DC(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:TC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const IC={tooltip:{trigger:"axis"}};function MC(e,t){const{deviation:n,metrics:r}=e,a=r.find(l=>l.data_key===t);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function AC(e,t,n){const r=kC(e,n),a=P(e.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=MC(e,t),c=wC(e,u,o,l),d={xAxis:CC(e,o),yAxis:SC(u),series:c,grid:fC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:DC(c)};return x.defaultsDeep({},d,IC)}const zC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},EC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:a}=e,o=m.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:t,onChange:l=>n(l.currentTarget.value),styles:zC})]})},$C={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function LC(){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(E.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:$C,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 PC(e){return p(s.Group,{position:"apart",children:[i(LC,{}),i(EC,{...e})]})}ie.use([he.BarChart,he.LineChart,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.VisualMapComponent]);function OC({conf:e,data:t,width:n,height:r,metricKey:a}){const o=m.useMemo(()=>AC(e,a,t),[e,t,a]);return i(Ae,{echarts:ie,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function BC({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaults({},t,Di),[t]),r=e.data,{width:a,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=m.useState(d);if(m.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(tt(a),300),y=Math.max(nt(o),370);return p(s.Box,{pt:Oe.top,pr:Oe.right,pb:Oe.bottom,pl:Oe.left,sx:{overflow:"hidden",height:o,width:a},children:[i(PC,{conf:n,metricKey:f,setMetricKey:h}),i(OC,{width:g,height:y-30,data:r,conf:n,metricKey:f})]})}function VC({control:e,watch:t}){return t(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:e,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:e,render:({field:n})=>i(W,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>i(W,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const NC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),qC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(NC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function FC({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,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:e,render:({field:n})=>i(zo,{...n})})]})]})}function GC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Di),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=m.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(I.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(FC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(VC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(qC,{control:a,watch:l})})]})]})})}function WC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=e;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 jC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:WC(a,r)}})}}const RC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new jC,name:"mericoEstimationChart",viewRender:BC,configRender:GC,createConfig:()=>({version:2,config:Di})},Mi={styles:{justify:"space-around",align:"start"},metrics:[]};function YC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:De,postfix:{type:"text",value:""}}}const Ho=({postfix:e})=>e?p(B,{children:[i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,QC=k.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:a,postfix:o}=e,l=ye(),u=m.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const c=l.filters.getSelectOption(o.value);return c?c.label:null}return null},[o,l]);return p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.value}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.value]).format(a)}),i(Ho,{postfix:u})]})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.basis}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.basis]).format(a)}),i(Ho,{postfix:u})]})]})]})}),UC=k.observer(({context:e,instance:t})=>{const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaults({},n,Mi),[n]),o=e.data,l=m.useMemo(()=>co(o,r),[r,o]),{width:u,height:c}=e.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=>i(QC,{metric:d,variableValueMap:l},d.id))})}),KC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],XC=k.observer(m.forwardRef(({value:e,onChange:t},n)=>{const a=le().filters.selects,o=u=>{t({type:u,value:e.value})},l=u=>{t({type:e.type,value:u})};return p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{label:"Postfix Type",data:KC,value:e.type,onChange:o}),e.type==="text"&&i(s.TextInput,{label:"Postfix Content",value:e.value,onChange:u=>{l(u.currentTarget.value)}}),e.type==="filter-option-label"&&i(s.Select,{label:"Filter",value:e.value,onChange:l,data:a})]})}));function JC({control:e,index:t,remove:n,watch:r,variableOptions:a}){return r(`metrics.${t}.postfix`),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.${t}.names.value`,control:e,render:({field:o})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>i(s.Select,{label:"Metric Data",required:!0,data:a,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>i(s.Select,{label:"Basis Data",required:!0,data:a,sx:{flex:1},...o})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>i(Ge,{...o})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>i(XC,{...o})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(I.Trash,{size:16})})]})}const ZC=({control:e,watch:t,variables:n})=>{const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((C,w)=>({...C,...l[w]})),c=()=>{a(YC())},d=m.useMemo(()=>n.map(C=>({label:C.name,value:C.name})),[n]),f=x.get(u,"0.id",null),[h,g]=m.useState(f);m.useEffect(()=>{g(C=>C||f)},[f]);const y=C=>{o(C);const w=x.get(u,"0.id",null);g(w)};return p(B,{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((C,w)=>i(s.Tabs.Tab,{value:C.id,children:C.names.value?C.names.value:w+1},C.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),u.map((C,w)=>i(s.Tabs.Panel,{value:C.id,children:i(JC,{control:e,index:w,remove:y,variableOptions:d,watch:t})},C.id))]})]})},HC=[{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"}],e1=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function t1({control:e,watch:t}){return t("styles"),p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:e,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:HC,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:e1,sx:{flex:1},...n})})]})]})}function n1({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,Mi),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.DeviceFloppy,{size:20})})]}),i(t1,{control:o,watch:u}),i(ZC,{control:o,watch:u,variables:r})]})})}function r1(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class i1 extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:r1(n.config)}))}}const a1={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new i1,name:"merico-stats",viewRender:UC,configRender:n1,createConfig:()=>({version:2,config:Mi})};function s1({control:e,watch:t}){t(["heat_block"]);const n=t("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:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,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:e,render:({field:r})=>i(Yt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Yt,{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:e,render:({field:r})=>i(Ge,{...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:e,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:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const o1=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),l1=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(o1,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function u1({control:e,watch:t}){return i(l1,{control:e,watch:t})}const c1=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},d1={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
418
|
-
`)},el=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(d1.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(c1,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function p1({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(el,{...n})})]})]})}const h1=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function f1({control:e,watch:t}){return t(["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:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,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:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:h1,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(el,{...n})})]})]})}const
|
|
417
|
+
`}},show_in_legend:!0}))}function xC(e,t,n,r){const a=P(t.data_key),o=t.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 wC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[gC(e,n,r),yC(e,n,r,l),...vC(e,n,r,l),xC(e,t,n,r)]}function CC(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Io(n.formatter)},axisLine:{show:!1}}]}function SC(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function Mi(e){return e==1||e==2?1:Mi(e-2)+Mi(e-1)}const _C=Array.from(new Array(20),(e,t)=>Mi(t+1));function Zo(e){return e<=1?e:_C.findIndex(t=>e<=t)-1}function kC(e,t){const{x_axis:n,deviation:r}=e,a=P(n.data_key),o=P(r.data_keys.estimated_value),l=P(r.data_keys.actual_value);return t[a.queryID].map(u=>{const c=Zo(u[o.columnKey]),d=Zo(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function TC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function DC(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:TC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const IC={tooltip:{trigger:"axis"}};function MC(e,t){const{deviation:n,metrics:r}=e,a=r.find(l=>l.data_key===t);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function AC(e,t,n){const r=kC(e,n),a=P(e.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=MC(e,t),c=wC(e,u,o,l),d={xAxis:CC(e,o),yAxis:SC(u),series:c,grid:fC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:DC(c)};return x.defaultsDeep({},d,IC)}const zC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},EC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:a}=e,o=m.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:t,onChange:l=>n(l.currentTarget.value),styles:zC})]})},$C={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function LC(){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(E.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:$C,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 PC(e){return p(s.Group,{position:"apart",children:[i(LC,{}),i(EC,{...e})]})}ie.use([he.BarChart,he.LineChart,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.VisualMapComponent]);function OC({conf:e,data:t,width:n,height:r,metricKey:a}){const o=m.useMemo(()=>AC(e,a,t),[e,t,a]);return i(Ae,{echarts:ie,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function BC({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaults({},t,Ii),[t]),r=e.data,{width:a,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=m.useState(d);if(m.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(tt(a),300),y=Math.max(nt(o),370);return p(s.Box,{pt:Oe.top,pr:Oe.right,pb:Oe.bottom,pl:Oe.left,sx:{overflow:"hidden",height:o,width:a},children:[i(PC,{conf:n,metricKey:f,setMetricKey:h}),i(OC,{width:g,height:y-30,data:r,conf:n,metricKey:f})]})}function VC({control:e,watch:t}){return t(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:e,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:e,render:({field:n})=>i(W,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>i(W,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const NC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),qC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(NC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function FC({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,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:e,render:({field:n})=>i(zo,{...n})})]})]})}function GC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Ii),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=m.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(I.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(FC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(VC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(qC,{control:a,watch:l})})]})]})})}function WC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=e;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 jC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:WC(a,r)}})}}const RC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new jC,name:"mericoEstimationChart",viewRender:BC,configRender:GC,createConfig:()=>({version:2,config:Ii})},Ai={styles:{justify:"space-around",align:"start"},metrics:[]};function YC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:De,postfix:{type:"text",value:""}}}const Ho=({postfix:e})=>e?p(B,{children:[i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,QC=k.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:a,postfix:o}=e,l=ye(),u=m.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const c=l.filters.getSelectOption(o.value);return c?c.label:null}return null},[o,l]);return p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.value}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.value]).format(a)}),i(Ho,{postfix:u})]})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.basis}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.basis]).format(a)}),i(Ho,{postfix:u})]})]})]})}),UC=k.observer(({context:e,instance:t})=>{const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaults({},n,Ai),[n]),o=e.data,l=m.useMemo(()=>co(o,r),[r,o]),{width:u,height:c}=e.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=>i(QC,{metric:d,variableValueMap:l},d.id))})}),KC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],XC=k.observer(m.forwardRef(({value:e,onChange:t},n)=>{const a=le().filters.selects,o=u=>{t({type:u,value:e.value})},l=u=>{t({type:e.type,value:u})};return p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{label:"Postfix Type",data:KC,value:e.type,onChange:o}),e.type==="text"&&i(s.TextInput,{label:"Postfix Content",value:e.value,onChange:u=>{l(u.currentTarget.value)}}),e.type==="filter-option-label"&&i(s.Select,{label:"Filter",value:e.value,onChange:l,data:a})]})}));function JC({control:e,index:t,remove:n,watch:r,variableOptions:a}){return r(`metrics.${t}.postfix`),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.${t}.names.value`,control:e,render:({field:o})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>i(s.Select,{label:"Metric Data",required:!0,data:a,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>i(s.Select,{label:"Basis Data",required:!0,data:a,sx:{flex:1},...o})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>i(Ge,{...o})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>i(XC,{...o})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(I.Trash,{size:16})})]})}const ZC=({control:e,watch:t,variables:n})=>{const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((C,w)=>({...C,...l[w]})),c=()=>{a(YC())},d=m.useMemo(()=>n.map(C=>({label:C.name,value:C.name})),[n]),f=x.get(u,"0.id",null),[h,g]=m.useState(f);m.useEffect(()=>{g(C=>C||f)},[f]);const y=C=>{o(C);const w=x.get(u,"0.id",null);g(w)};return p(B,{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((C,w)=>i(s.Tabs.Tab,{value:C.id,children:C.names.value?C.names.value:w+1},C.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),u.map((C,w)=>i(s.Tabs.Panel,{value:C.id,children:i(JC,{control:e,index:w,remove:y,variableOptions:d,watch:t})},C.id))]})]})},HC=[{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"}],e1=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function t1({control:e,watch:t}){return t("styles"),p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:e,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:HC,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:e1,sx:{flex:1},...n})})]})]})}function n1({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,Ai),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.DeviceFloppy,{size:20})})]}),i(t1,{control:o,watch:u}),i(ZC,{control:o,watch:u,variables:r})]})})}function r1(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class i1 extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:r1(n.config)}))}}const a1={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new i1,name:"merico-stats",viewRender:UC,configRender:n1,createConfig:()=>({version:2,config:Ai})};function s1({control:e,watch:t}){t(["heat_block"]);const n=t("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:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,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:e,render:({field:r})=>i(Yt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Yt,{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:e,render:({field:r})=>i(Ge,{...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:e,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:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const o1=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),l1=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(o1,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function u1({control:e,watch:t}){return i(l1,{control:e,watch:t})}const c1=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},d1={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
418
|
+
`)},el=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(d1.func_content)};return p(B,{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:y=>c(y.currentTarget.checked)}),i(c1,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function p1({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(el,{...n})})]})]})}const h1=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function f1({control:e,watch:t}){return t(["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:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,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:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:h1,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:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,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:e,render:({field:n})=>i(el,{...n})})]})]})}const zi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:We,formatter:{...Ue}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:We,formatter:{...Ue}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:De,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function g1({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,zi),[t]),a=m.useMemo(()=>x.cloneDeep(r),[r]);m.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});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.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(I.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(p1,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(f1,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(s1,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(u1,{control:o,watch:u})})]})]})})}function m1(e){return i(B,{})}function y1(e){return i(s.Text,{children:"Click heat block"})}const tl={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:y1,configRender:m1,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"}]};function nl({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function b1(e){const t=nl(e.x_axis.axisLabel.formatter),n=nl(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function v1(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function x1(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function w1(e,t){const{x_axis:n,y_axis:r,heat_block:a}=e,o=P(n.data_key),l=P(r.data_key),u=P(a.data_key),c=t[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:{borderWidth:0},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const C1=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function S1({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:ot(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:ot(e.y_axis.axisLabel.overflow.in_tooltip)}},g={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},y=[f,h,g],C=r[`${u}---${c}`];return C&&e.tooltip.metrics.forEach(w=>{const _=P(w.data_key);y.push({label:w.name,value:C1(x.get(C,_.columnKey,"")),style:{label:"",value:""}})}),y}function _1(e,t,n,r){const{x_axis:a,y_axis:o,heat_block:l}=e,u=P(a.data_key),c=P(o.data_key);P(l.data_key);const d=x.keyBy(t[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=S1({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(C=>`
|
|
419
419
|
<tr>
|
|
420
420
|
<th style="text-align: right;">
|
|
421
421
|
<div style="${C.style.label}">${C.label}</div>
|
|
@@ -436,18 +436,18 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
436
436
|
</thead>
|
|
437
437
|
<tbody>${g.join("")}</tbody>
|
|
438
438
|
</table>
|
|
439
|
-
`}}}function k1(e,t){const n=Qt(e.heat_block.min,t),r=Qt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function T1(e,t,n){const r=P(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=rt(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function D1(e,t,n){const r=P(e.x_axis.data_key),a=P(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=rt(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const I1={tooltip:{confine:!0}};function M1(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=yt(c,t);return u[c.name]=Ze(c,d),u},{}),a=b1(e),o=v1(e),l={xAxis:T1(e,t,a.x_axis),yAxis:D1(e,t,a.y_axis),series:w1(e,t),tooltip:_1(e,t,a,o),grid:x1(e),visualMap:k1(e,r)};return x.defaultsDeep({},l,I1)}ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function A1({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const h=P(e.x_axis.data_key),g=P(e.y_axis.data_key);return x.keyBy(t[h.queryID],y=>`${y[h.columnKey]}---${y[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,tl.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,`${g}---${y}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>M1(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function z1({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,Ai),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(A1,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}class E1 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const $1={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new E1,name:"merico-heatmap",viewRender:z1,configRender:g1,createConfig:()=>({version:1,config:Ai}),triggers:[tl]},L1=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),P1=[gc,mc,vc,bc,yc,xc],rl=()=>({id:"dashboard",version:hs,manifest:{viz:[wi,xx,j0,Jb,Gx,Gy,hC,Lc,ef,hm,Xm,Dw,My,jg,lx,hb,Gb,Z0,RC,$1,a1,gf],color:[...L1,...P1]}}),vn=new _c,be={pluginManager:ft("pluginManager"),vizManager:ft("vizManager"),colorManager:ft("colorManager"),instanceScope:{panelModel:ft("panelModel"),vizInstance:ft("vizInstance"),interactionManager:ft("interactionManager"),migrator:ft("migrator"),operationManager:ft("operationManager"),triggerManager:ft("triggerManager")}},zi=()=>{try{vn.install(rl())}catch{}const e=new pc(vn),t=new Sc(vn);return{pluginManager:vn,vizManager:e,colorManager:t}},ct=m.createContext(zi());try{vn.install(rl())}catch{}const Ei=m.createContext(null);function sr(e){const t=m.useContext(Ei),n=Q.useCreation(()=>e.configure(t||new _r),[e.configure]),r=Q.usePrevious(n);return r&&r!==n&&r.dispose(),i(Ei.Provider,{value:n,children:e.children})}function il(){return m.useContext(Ei)}const O1=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Yn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(E.IconInfoCircle,{size:16,color:"gray"})})}),B1=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(O1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),al=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?U(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&U(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(Ru.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(I.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),V1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),sl=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),N1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f,required:h})=>{const{classes:g,cx:y}=V1({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[C,w]=m.useState(!1),_=$=>{w($)},D=C&&(u==null?void 0:u.length)>0,[M,O]=m.useState(""),G=m.useMemo(()=>{if(!M)return d;const $=M.toLowerCase(),L=A=>{var N;return((N=A.description)==null?void 0:N.toLowerCase().includes($))||A.label.toLowerCase().includes($)};return d.filter(L)},[M,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:g.label,children:[l,h&&i("span",{className:g.required,"aria-hidden":"true",children:"*"})]}),D&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Za,{disabled:e,allowClear:!0,className:y(g.root,"check-select"),dropdownClassName:y(g.dropdown,""),onDropdownVisibleChange:_,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(sl,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:$=>`${$.length} selected`,searchValue:M,onSearch:O,filterOption:!1,children:G.map($=>p(Za.Option,{title:$.label,children:[i(s.Text,{size:"sm","data-role":"label",children:$.label}),$.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:$.description})]},$.value))})]})},q1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(N1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u,required:t.required})}),F1=m.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),G1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:F1})});function W1({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const j1=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),R1=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i(j1,{rotate:e?"0":"-90",onClick:r,...a})),Y1=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),Q1=({onClick:e,...t})=>i(Y1,{onClick:e,...t}),U1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),K1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f,required:h,treeCheckStrictly:g})=>{const{classes:y,cx:C}=U1({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,_]=m.useState(!1),D=O=>{_(O)},M=w&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:y.label,children:[l,h&&i("span",{className:y.required,"aria-hidden":"true",children:"*"})]}),M&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ha,{disabled:e,allowClear:!0,treeCheckStrictly:g,className:C(y.root,"check-select"),dropdownClassName:C(y.dropdown,""),onDropdownVisibleChange:D,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:R1,treeIcon:Q1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(sl,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Ha.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:O=>`${O.length} selected`})]})},X1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(K1,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),J1=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(G1,{...r,...a,config:t});case"multi-select":return i(q1,{...r,...a,config:t});case"tree-select":return i(X1,{...r,...a,config:t});case"text-input":return i(W1,{...r,...a,config:t});case"date-range":return i(al,{...r,...a,config:t});case"checkbox":return i(B1,{...r,...a,config:t});default:return null}}),Z1=k.observer(m.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Ee,{children:i(J1,{filter:e,formFieldProps:t})})}))),H1=({disabled:e})=>{const{searchButtonProps:t}=ms(),{children:n="Search",type:r,...a}=t;return i(s.Button,{color:"blue",size:"sm",type:"submit",...a,disabled:e||a.disabled,children:n})};function eS(e){const t=le();m.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const ol=k.observer(function({view:t}){const n=ye(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});m.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),eS(l);const u=n.filters.visibleInView(t.id),c=m.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=m.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=m.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,y)=>(C,w)=>{y(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:y})=>i(Z1,{filter:g,value:y.value,onChange:h(g,y.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(H1,{disabled:f})})]})})}),tS={viewPanelInFullScreen:x.noop,inFullScreen:!1},or=m.createContext(tS),ll=b.types.model("MockContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function ul(e){return{current:e}}const nS=b.types.model("PanelLayoutMeta",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),rS=b.types.model("PanelStyleBorderMeta",{enabled:b.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),iS=b.types.model("PanelStyleMeta",{border:rS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),aS=b.types.model("VariableMeta",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}),b.types.model({type:b.types.literal("custom"),config:b.types.model({func:b.types.string})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),sS=b.types.model("PanelVizMeta",{type:b.types.string,conf:b.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),oS=b.types.model("PanelTitleMeta",{show:b.types.optional(b.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),lS=b.types.model({id:b.types.string,name:b.types.optional(b.types.string,""),title:oS,description:b.types.string,layout:nS,queryIDs:b.types.array(b.types.string),viz:sS,style:iS,variables:b.types.optional(b.types.array(aS),[])}).views(e=>({get json(){const{id:t,name:n,title:r,description:a,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:n,style:e.style.json,title:r,layout:e.layout.json,queryIDs:[...o],variables:e.variables.map(l=>l.json),description:a}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=b.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=b.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),lr=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return te.toJS(t)});var Ne=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Ne||{});const uS=b.types.model("QueryMeta",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[Ne.Postgresql,Ne.MySQL,Ne.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Ne.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return lr({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),cS=b.types.model("SQLSnippetMeta",{key:b.types.string,value:b.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var ve=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ve||{});const cl=b.types.model("FilterCheckboxConfigMeta",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),dS=()=>cl.create({_name:"checkbox",description:"",default_value:!1});function dl(e,t){return e.map(n=>{try{return n?U.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const pS=b.types.model("FilterDateRangeConfigMeta",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:dl(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=b.getParent(e);b.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),pl=b.types.snapshotProcessor(pS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:U.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:dl(t,n.inputFormat)}}}),hS=()=>pl.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),fS=b.types.model({label:b.types.string,value:b.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),$i=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(fS),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0),required:b.types.optional(b.types.boolean,!1)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),hl=b.types.compose("FilterMultiSelectConfigMeta",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),$i).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return lr({_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),gS=()=>hl.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),fl=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,width:b.types.optional(b.types.string,"")}),$i).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return lr({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t},getSelectOption(t){return e.options.find(n=>n.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),mS=()=>fl.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),gl=b.types.model("FilterTextInputConfigMeta",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),ml=()=>gl.create({_name:"text-input",required:!1,default_value:""});function yS(e){return Yu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function bS(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=m.createElement("div",{},[m.createElement(s.Text,{key:0,title:t.label},t.label),m.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const yl=b.types.compose("FilterTreeSelectConfigMeta",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[]),treeCheckStrictly:b.types.optional(b.types.boolean,!1)}),$i).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=e;return{_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get treeData(){const{data:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id),n=bS(t);return yS(n)},get errorMessage(){const{error:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=b.getParent(e,1).key;b.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){b.addDisposer(e,te.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),vS=()=>yl.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),bl=b.types.model("FilterMeta",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[ve.Select,ve.MultiSelect,ve.TreeSelect,ve.TextInput,ve.Checkbox,ve.DateRange]),config:b.types.union(fl,hl,yl,gl,cl,pl)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==ve.TreeSelect},get auto_submit_supported(){return[ve.Select,ve.Checkbox,ve.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:te.toJS(o)}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case ve.Select:e.config=mS();break;case ve.MultiSelect:e.config=gS();break;case ve.TreeSelect:e.config=vS();break;case ve.TextInput:e.config=ml();break;case ve.Checkbox:e.config=dS();break;case ve.DateRange:e.config=hS();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var j=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(j||{});const vl=b.types.model("ViewDivisionConfig",{_name:b.types.literal(j.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),xS=()=>vl.create({_name:j.Division}),wS=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=b.getParent(e,2),a=b.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),Li={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
440
|
-
`)},xl=b.types.model("ViewModalConfig",{_name:b.types.literal(j.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(wS,Li)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),CS=()=>xl.create({_name:j.Modal,width:"90vw",height:"90vh"}),SS=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),wl=b.types.model("ViewTabsConfig",{_name:b.types.literal(j.Modal),tabs:b.types.optional(b.types.array(SS),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=_e.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),_S=()=>wl.create({_name:j.Modal,tabs:[]}),kS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[j.Division,j.Modal,j.Tabs]),config:b.types.union(vl,xl,wl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case j.Division:e.config=xS();break;case j.Modal:e.config=CS();break;case j.Tabs:e.config=_S();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),Cl=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[Ne.HTTP,Ne.MySQL,Ne.Postgresql]),key:b.types.string,config:b.types.frozen()}),TS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(Cl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),DS=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}),Sl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(DS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Pi=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function _l(e){return Pi.create({current:e})}const IS=b.types.compose("ViewRenderModel",kS,b.types.model({tab:b.types.optional(b.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==j.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==j.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return b.getParent(e,3)},get panels(){if(e.type!==j.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===j.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){b.addDisposer(e,te.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),kl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(IS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>lr(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function MS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const Tl=lS.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function AS(e){return{id:e,name:e,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:wi.name,conf:wi.createConfig()},style:{border:{enabled:!0}}}}const Dl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(Tl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function Il(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:U.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function zS(e){return e.reduce((t,n)=>(t[n.key]=Il(n.config.default_value,n.config),t),{})}const Ml=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(bl),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function Al(e){return{current:e,values:zS(e)}}const ES=new Qu.AsyncParser({withBOM:!0});async function zl(e){return!Array.isArray(e)||e.length===0?"":await ES.parse(e).promise()}async function $S(e,t){const n=await zl(t),r=new Blob([n],{type:"text/csv"});vr.saveAs(r,`${e}.csv`)}function El(e){const t=new Uu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,zl(r))}),t.generateAsync({type:"blob"}).then(n=>{vr.saveAs(n,"dashboard_data.zip")})}function $l(e,t){const n=new Blob([t],{type:"application/json"});vr.saveAs(n,`${e}.json`)}function LS(e,t){return new Function(`return ${e}`)()(t,At)}function PS(e,t,n){return LS(e,{context:t,filters:n})}function OS(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,At)}catch(n){return console.error(n),t}}function BS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,At)}function VS(e,t,n){return e?new Function(`return ${e}`)()(t,At,n):t}const NS=uS.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}},get queries(){return b.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)}})),qS=b.types.compose("QueryRenderModel",NS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.frozen([]),[]),error:b.types.frozen()})).views(e=>({get rootModel(){return b.getRoot(e)},get contentModel(){return this.rootModel.content},get payload(){return this.contentModel.payloadForSQL},get formattedSQL(){return wr(e.sql,this.payload)},get typedAsSQL(){return[Ne.Postgresql,Ne.MySQL].includes(e.type)},get typedAsHTTP(){return[Ne.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return this.rootModel.datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:a}=e.json,o=PS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo(e.id)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=e.payload;e.data=yield*b.toGenerator(uc({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!pt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=OS(e.datasource,o);const l=yield*b.toGenerator(cc({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),u=BS(e.datasource,l),c=VS(a,u,e.contentModel.dashboardState);e.data=c,e.state="idle",e.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ll=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(qS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get contentModel(){return b.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(u=>{r.push(...u.queryIDs)})});const a=x.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const u=x.get(l,"config.options_query_id");if(!u)return;a.some(d=>l.visibleInViewsIDSet.has(d))&&r.push(u)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));El(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));El(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n;$S(r,a)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData(!0)}}));function FS(e){return{current:e}}const GS=cS.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),Pl=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(GS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function WS(e){return{current:e}}function ur(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=xr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class jS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),te.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const RS=e=>new jS(e),YS=k.observer(({view:e})=>{const t=ue(),n=le(),r=Fe.useModals(),{panel:a,downloadPanelScreenshot:o}=Qe(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=m.useContext(or),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=m.useCallback(()=>{u(l)},[l,u]),y=!c&&e.type!==j.Modal;return i(B,{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%"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),y&&i(s.Menu.Item,{onClick:g,icon:i(I.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(I.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(I.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(I.Trash,{size:14}),children:"Delete"})]})]})})})});function QS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Oi=k.observer(()=>{const[e,t]=m.useState(!1),{panel:n}=Ct();return QS(n.description)?null:p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.name,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Yn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(I.InfoCircle,{size:20})})})]})}),PM="",US=k.observer(function(){const{panel:t}=Ct(),{name:n,title:r}=t;return r.show?i(s.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function KS(e){const t=m.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;es.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var Ol=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Ol||{}),cr=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(cr||{});class XS{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(be.instanceScope.panelModel),this.vizInstance=t.getRequired(be.instanceScope.vizInstance),this.operationManager=t.getRequired(be.instanceScope.operationManager),this.triggerManager=t.getRequired(be.instanceScope.triggerManager),this.vizManager=t.getRequired(be.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Bl(e){const{panel:t}=Ct();return m.useCallback(n=>{const r=n.getRequired(be.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(be.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const l=o.getRequired(be.instanceScope.vizInstance);return new Pr(l,a,$n)}).provideFactory(be.instanceScope.operationManager,o=>o.getRequired(be.instanceScope.interactionManager).operationManager).provideFactory(be.instanceScope.triggerManager,o=>o.getRequired(be.instanceScope.interactionManager).triggerManager).provideValue(be.instanceScope.panelModel,t).provideFactory(be.instanceScope.migrator,o=>new XS(o))},[e.viz.type,e.viz.conf])}function Vl(e){const[t,n]=m.useState(!1),r=il().getRequired(be.instanceScope.migrator);return Q.useAsyncEffect(async()=>{const a=r.status===cr.notStarted;n(r.status===cr.done),r.status===cr.notStarted&&r.runMigration().then(o=>{o===Ol.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Nl(e,t){const n=il().getRequired(be.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function JS({setVizConf:e,...t}){const{panel:n}=t,r=Nl(e,n),a=Vl(()=>{Tn.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Q.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(fc,{...t}):i(s.Text,{children:"Checking update..."})}function ZS(e){const{panel:t,setVizConf:n}=e;Nl(n,t);const{inEditMode:r}=m.useContext(zn);return Vl(()=>{r&&Tn.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(hc,{...e}):i(s.Text,{children:"Checking update"})}const OM="";function HS(e,t){const{vizManager:n}=m.useContext(ct),{panel:{viz:r,title:a,id:o,name:l,description:u,queryIDs:c,variables:d}}=Ct(),f={id:o,name:l,title:a,description:u,queryIDs:c,viz:r,layout:t},h=Bl(f);try{return n.resolveComponent(r.type),i(sr,{configure:h,children:i(ZS,{setVizConf:r.setConf,panel:f,data:e,variables:d,vizManager:n})})}catch(g){return console.info(x.get(g,"message")),null}}const ql=k.observer(function({data:t}){const{ref:n,width:r,height:a}=_e.useElementSize(),o=HS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:i(s.Box,{sx:{width:r,height:a,overflow:"hidden"},children:l&&i(Ee,{children:o})})})}),Fl=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Bi=k.observer(({panel:e})=>p(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(Fl,{panel:e}),e.canRenderViz&&i(ql,{data:e.data})]})),e_={border:"1px solid #e9ecef"},Gl=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=KS(e);return e.title.show,i(zr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...e_,...t},children:[i(s.Box,{className:"panel-description-popover-wrapper",children:i(Oi,{})}),n,i(US,{}),i(Bi,{panel:e})]})})}),t_={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function n_(e){return e.style.border.enabled?{}:t_}const Wl=k.observer(function({panel:t,view:n}){const r=n_(t);return i(Gl,{panel:t,panelStyle:r,dropdownContent:i(YS,{view:n})})});function r_(e){return!["richText","button"].includes(e)}const i_=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=Ct(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=m.useContext(or),l=m.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==j.Modal;return r_(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target"})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(I.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function a_(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Vi=k.observer(({panel:e,view:t})=>{const n=a_(e);return i(Gl,{panel:e,panelStyle:n,dropdownContent:i(i_,{view:t})})}),s_={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},jl=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(I.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:s_,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Vi,{view:t,panel:n})})})});function Rl(e,t,n){const{panels:r}=ye(),a=e.id==="Main",[o,l]=m.useState(()=>a&&r.findByID(t)?t:null),u=m.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=m.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const BM="",o_=m.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(I.ArrowsMove,{size:16})})),l_=m.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(I.ChevronDownRight,{size:16})})),u_=Dn.WidthProvider(Dn),c_=k.observer(({view:e,className:t="layout"})=>{const n=ye(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=m.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(u_,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(l_,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(o_,{h:u.layout.h}),i(Wl,{view:e,panel:u})]},u.id))})}),d_=Dn.WidthProvider(Dn),p_=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=ye().panels.panelsByIDs(t.panelIDs);return i(d_,{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(Vi,{view:t,panel:o})},o.id))})});function Ni(e){const t=m.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;es.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const h_=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=Ir(),o=ye(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;$l(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i(E.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Yl=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=Ni(t);return p(B,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(h_,{downloadScreenShot:a})]})}),Ql=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i(E.IconCamera,{size:14})})),f_=k.observer(({children:e,view:t})=>{const n=ye(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=Ni(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Ql,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),g_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},m_=k.observer(({view:e})=>{const t=ye(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:e.tab,onTabChange:e.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:g_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(dr,{view:a})},r.id):null})]})}),y_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(f_,{view:e,children:t});case j.Tabs:return i(m_,{view:e});case j.Division:default:return i(Yl,{view:e,children:t})}}),b_=k.observer(({children:e,view:t})=>i(Yl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function Ul(e){return e.replace(/(vw|vh)/,"%")}const v_=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=m.useMemo(()=>({width:Ul(n.width),height:Ul(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Ni(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Ql,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),x_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},w_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},C_=k.observer(({view:e})=>{const t=Fe.useModals(),n=le(),r=m.useMemo(()=>n.views.options.filter(u=>u.type===j.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:e.tab,onTabChange:e.setTab,styles:x_(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:w_(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(I.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(E.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(dr,{view:d})]},u.id)})]})}),S_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(v_,{view:e,children:t});case j.Tabs:return i(C_,{view:e});case j.Division:default:return i(b_,{view:e,children:t})}}),Kl=k.observer(function({view:t}){return i(or.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(S_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:t})}),i(c_,{view:t})]})})})})}),dr=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ws(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Rl(t,n,r);return i(or.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===j.Modal?"0 !important":"100%"},children:[l&&i(jl,{view:t,panel:u,exitFullScreen:o}),i(y_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:t})}),!l&&i(p_,{view:t})]})})]})})});var Xl=(e=>(e.Use="use",e.Edit="edit",e))(Xl||{});const __={[j.Division]:"Division",[j.Tabs]:"Tabs",[j.Modal]:"Modal"},Jl={[j.Division]:"rgba(255, 0, 0, 0.2)",[j.Modal]:"rgba(0, 0, 0, 0.2)",[j.Tabs]:"rgba(255, 200, 100, 0.4)"},k_={[j.Division]:"#ff4000",[j.Modal]:"#000",[j.Tabs]:"#ffad18"},T_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:j.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function D_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Zl=b.types.compose("FiltersModel",Ml,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===ve.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){D_(e.current,bl,(n,r)=>{if(n==="setType"){const a=Il(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Hl=Ll.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.id)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.id)),e.current=b.cast(r)}})),eu=Pl.views(e=>({get sortedList(){return x.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},removeByKeys(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.key)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.key)),e.current=b.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),I_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),M_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),A_=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(e=>({get keywords(){return b.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=b.getParent(e,1);return`${n}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
|
|
439
|
+
`}}}function k1(e,t){const n=Qt(e.heat_block.min,t),r=Qt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function T1(e,t,n){const r=P(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=rt(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function D1(e,t,n){const r=P(e.x_axis.data_key),a=P(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=rt(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const I1={tooltip:{confine:!0}};function M1(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=yt(c,t);return u[c.name]=Ze(c,d),u},{}),a=b1(e),o=v1(e),l={xAxis:T1(e,t,a.x_axis),yAxis:D1(e,t,a.y_axis),series:w1(e,t),tooltip:_1(e,t,a,o),grid:x1(e),visualMap:k1(e,r)};return x.defaultsDeep({},l,I1)}ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function A1({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const h=P(e.x_axis.data_key),g=P(e.y_axis.data_key);return x.keyBy(t[h.queryID],y=>`${y[h.columnKey]}---${y[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,tl.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,`${g}---${y}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>M1(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function z1({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,zi),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(A1,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}class E1 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const $1={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new E1,name:"merico-heatmap",viewRender:z1,configRender:g1,createConfig:()=>({version:1,config:zi}),triggers:[tl]},L1=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),P1=[gc,mc,vc,bc,yc,xc],rl=()=>({id:"dashboard",version:hs,manifest:{viz:[Ci,xx,j0,Jb,Gx,Gy,hC,Lc,ef,hm,Xm,Dw,My,jg,lx,hb,Gb,Z0,RC,$1,a1,gf],color:[...L1,...P1]}}),vn=new _c,be={pluginManager:ft("pluginManager"),vizManager:ft("vizManager"),colorManager:ft("colorManager"),instanceScope:{panelModel:ft("panelModel"),vizInstance:ft("vizInstance"),interactionManager:ft("interactionManager"),migrator:ft("migrator"),operationManager:ft("operationManager"),triggerManager:ft("triggerManager")}},Ei=()=>{try{vn.install(rl())}catch{}const e=new pc(vn),t=new Sc(vn);return{pluginManager:vn,vizManager:e,colorManager:t}},ct=m.createContext(Ei());try{vn.install(rl())}catch{}const $i=m.createContext(null);function sr(e){const t=m.useContext($i),n=Q.useCreation(()=>e.configure(t||new kr),[e.configure]),r=Q.usePrevious(n);return r&&r!==n&&r.dispose(),i($i.Provider,{value:n,children:e.children})}function il(){return m.useContext($i)}const O1=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Yn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(E.IconInfoCircle,{size:16,color:"gray"})})}),B1=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(O1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),al=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?U(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&U(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(Ru.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(I.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),V1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),sl=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),N1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f,required:h})=>{const{classes:g,cx:y}=V1({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[C,w]=m.useState(!1),_=$=>{w($)},D=C&&(u==null?void 0:u.length)>0,[M,O]=m.useState(""),G=m.useMemo(()=>{if(!M)return d;const $=M.toLowerCase(),L=A=>{var N;return((N=A.description)==null?void 0:N.toLowerCase().includes($))||A.label.toLowerCase().includes($)};return d.filter(L)},[M,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:g.label,children:[l,h&&i("span",{className:g.required,"aria-hidden":"true",children:"*"})]}),D&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ha,{disabled:e,allowClear:!0,className:y(g.root,"check-select"),dropdownClassName:y(g.dropdown,""),onDropdownVisibleChange:_,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(sl,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:$=>`${$.length} selected`,searchValue:M,onSearch:O,filterOption:!1,children:G.map($=>p(Ha.Option,{title:$.label,children:[i(s.Text,{size:"sm","data-role":"label",children:$.label}),$.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:$.description})]},$.value))})]})},q1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(N1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u,required:t.required})}),F1=m.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),G1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:F1})});function W1({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const j1=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),R1=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i(j1,{rotate:e?"0":"-90",onClick:r,...a})),Y1=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),Q1=({onClick:e,...t})=>i(Y1,{onClick:e,...t}),U1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),K1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f,required:h,treeCheckStrictly:g})=>{const{classes:y,cx:C}=U1({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,_]=m.useState(!1),D=O=>{_(O)},M=w&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:y.label,children:[l,h&&i("span",{className:y.required,"aria-hidden":"true",children:"*"})]}),M&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(es,{disabled:e,allowClear:!0,treeCheckStrictly:g,className:C(y.root,"check-select"),dropdownClassName:C(y.dropdown,""),onDropdownVisibleChange:D,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:R1,treeIcon:Q1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(sl,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:es.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:O=>`${O.length} selected`})]})},X1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(K1,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),J1=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(G1,{...r,...a,config:t});case"multi-select":return i(q1,{...r,...a,config:t});case"tree-select":return i(X1,{...r,...a,config:t});case"text-input":return i(W1,{...r,...a,config:t});case"date-range":return i(al,{...r,...a,config:t});case"checkbox":return i(B1,{...r,...a,config:t});default:return null}}),Z1=k.observer(m.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Ee,{children:i(J1,{filter:e,formFieldProps:t})})}))),H1=({disabled:e})=>{const{searchButtonProps:t}=ms(),{children:n="Search",type:r,...a}=t;return i(s.Button,{color:"blue",size:"sm",type:"submit",...a,disabled:e||a.disabled,children:n})};function eS(e){const t=le();m.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const ol=k.observer(function({view:t}){const n=ye(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});m.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),eS(l);const u=n.filters.visibleInView(t.id),c=m.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=m.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=m.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,y)=>(C,w)=>{y(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:y})=>i(Z1,{filter:g,value:y.value,onChange:h(g,y.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(H1,{disabled:f})})]})})}),tS={viewPanelInFullScreen:x.noop,inFullScreen:!1},or=m.createContext(tS),ll=b.types.model("MockContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function ul(e){return{current:e}}const nS=b.types.model("PanelLayoutMeta",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),rS=b.types.model("PanelStyleBorderMeta",{enabled:b.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),iS=b.types.model("PanelStyleMeta",{border:rS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),aS=b.types.model("VariableMeta",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}),b.types.model({type:b.types.literal("custom"),config:b.types.model({func:b.types.string})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),sS=b.types.model("PanelVizMeta",{type:b.types.string,conf:b.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),oS=b.types.model("PanelTitleMeta",{show:b.types.optional(b.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),lS=b.types.model({id:b.types.string,name:b.types.optional(b.types.string,""),title:oS,description:b.types.string,layout:nS,queryIDs:b.types.array(b.types.string),viz:sS,style:iS,variables:b.types.optional(b.types.array(aS),[])}).views(e=>({get json(){const{id:t,name:n,title:r,description:a,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:n,style:e.style.json,title:r,layout:e.layout.json,queryIDs:[...o],variables:e.variables.map(l=>l.json),description:a}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=b.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=b.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),lr=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return te.toJS(t)});var Ne=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Ne||{});const uS=b.types.model("QueryMeta",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[Ne.Postgresql,Ne.MySQL,Ne.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Ne.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return lr({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),cS=b.types.model("SQLSnippetMeta",{key:b.types.string,value:b.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var ve=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ve||{});const cl=b.types.model("FilterCheckboxConfigMeta",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),dS=()=>cl.create({_name:"checkbox",description:"",default_value:!1});function dl(e,t){return e.map(n=>{try{return n?U.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const pS=b.types.model("FilterDateRangeConfigMeta",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:dl(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=b.getParent(e);b.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),pl=b.types.snapshotProcessor(pS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:U.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:dl(t,n.inputFormat)}}}),hS=()=>pl.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),fS=b.types.model({label:b.types.string,value:b.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Li=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(fS),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0),required:b.types.optional(b.types.boolean,!1)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),hl=b.types.compose("FilterMultiSelectConfigMeta",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),Li).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return lr({_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),gS=()=>hl.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),fl=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,width:b.types.optional(b.types.string,"")}),Li).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return lr({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t},getSelectOption(t){return e.options.find(n=>n.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),mS=()=>fl.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),gl=b.types.model("FilterTextInputConfigMeta",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),ml=()=>gl.create({_name:"text-input",required:!1,default_value:""});function yS(e){return Yu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function bS(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=m.createElement("div",{},[m.createElement(s.Text,{key:0,title:t.label},t.label),m.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const yl=b.types.compose("FilterTreeSelectConfigMeta",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[]),treeCheckStrictly:b.types.optional(b.types.boolean,!1)}),Li).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=e;return{_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get treeData(){const{data:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id),n=bS(t);return yS(n)},get errorMessage(){const{error:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=b.getParent(e,1).key;b.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){b.addDisposer(e,te.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),vS=()=>yl.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),bl=b.types.model("FilterMeta",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[ve.Select,ve.MultiSelect,ve.TreeSelect,ve.TextInput,ve.Checkbox,ve.DateRange]),config:b.types.union(fl,hl,yl,gl,cl,pl)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==ve.TreeSelect},get auto_submit_supported(){return[ve.Select,ve.Checkbox,ve.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:te.toJS(o)}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case ve.Select:e.config=mS();break;case ve.MultiSelect:e.config=gS();break;case ve.TreeSelect:e.config=vS();break;case ve.TextInput:e.config=ml();break;case ve.Checkbox:e.config=dS();break;case ve.DateRange:e.config=hS();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var j=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(j||{});const vl=b.types.model("ViewDivisionConfig",{_name:b.types.literal(j.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),xS=()=>vl.create({_name:j.Division}),wS=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=b.getParent(e,2),a=b.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),Pi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
440
|
+
`)},xl=b.types.model("ViewModalConfig",{_name:b.types.literal(j.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(wS,Pi)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),CS=()=>xl.create({_name:j.Modal,width:"90vw",height:"90vh"}),SS=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),wl=b.types.model("ViewTabsConfig",{_name:b.types.literal(j.Modal),tabs:b.types.optional(b.types.array(SS),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=_e.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),_S=()=>wl.create({_name:j.Modal,tabs:[]}),kS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[j.Division,j.Modal,j.Tabs]),config:b.types.union(vl,xl,wl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case j.Division:e.config=xS();break;case j.Modal:e.config=CS();break;case j.Tabs:e.config=_S();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),Cl=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[Ne.HTTP,Ne.MySQL,Ne.Postgresql]),key:b.types.string,config:b.types.frozen()}),TS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(Cl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),DS=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}),Sl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(DS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Oi=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function _l(e){return Oi.create({current:e})}const IS=b.types.compose("ViewRenderModel",kS,b.types.model({tab:b.types.optional(b.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==j.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==j.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return b.getParent(e,3)},get panels(){if(e.type!==j.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===j.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){b.addDisposer(e,te.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),kl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(IS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>lr(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function MS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const Tl=lS.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function AS(e){return{id:e,name:e,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Ci.name,conf:Ci.createConfig()},style:{border:{enabled:!0}}}}const Dl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(Tl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function Il(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:U.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function zS(e){return e.reduce((t,n)=>(t[n.key]=Il(n.config.default_value,n.config),t),{})}const Ml=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(bl),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function Al(e){return{current:e,values:zS(e)}}const ES=new Qu.AsyncParser({withBOM:!0});async function zl(e){return!Array.isArray(e)||e.length===0?"":await ES.parse(e).promise()}async function $S(e,t){const n=await zl(t),r=new Blob([n],{type:"text/csv"});vr.saveAs(r,`${e}.csv`)}function El(e){const t=new Uu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,zl(r))}),t.generateAsync({type:"blob"}).then(n=>{vr.saveAs(n,"dashboard_data.zip")})}function $l(e,t){const n=new Blob([t],{type:"application/json"});vr.saveAs(n,`${e}.json`)}function LS(e,t){return new Function(`return ${e}`)()(t,At)}function PS(e,t,n){return LS(e,{context:t,filters:n})}function OS(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,At)}catch(n){return console.error(n),t}}function BS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,At)}function VS(e,t,n){return e?new Function(`return ${e}`)()(t,At,n):t}const NS=uS.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}},get queries(){return b.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)}})),qS=b.types.compose("QueryRenderModel",NS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.frozen([]),[]),error:b.types.frozen()})).views(e=>({get rootModel(){return b.getRoot(e)},get contentModel(){return this.rootModel.content},get payload(){return this.contentModel.payloadForSQL},get formattedSQL(){return wr(e.sql,this.payload)},get typedAsSQL(){return[Ne.Postgresql,Ne.MySQL].includes(e.type)},get typedAsHTTP(){return[Ne.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return this.rootModel.datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:a}=e.json,o=PS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo(e.id)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=e.payload;e.data=yield*b.toGenerator(uc({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!pt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=OS(e.datasource,o);const l=yield*b.toGenerator(cc({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),u=BS(e.datasource,l),c=VS(a,u,e.contentModel.dashboardState);e.data=c,e.state="idle",e.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ll=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(qS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get contentModel(){return b.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(u=>{r.push(...u.queryIDs)})});const a=x.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const u=x.get(l,"config.options_query_id");if(!u)return;a.some(d=>l.visibleInViewsIDSet.has(d))&&r.push(u)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));El(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));El(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n;$S(r,a)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData(!0)}}));function FS(e){return{current:e}}const GS=cS.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),Pl=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(GS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function WS(e){return{current:e}}function ur(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=xr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class jS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),te.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const RS=e=>new jS(e),YS=k.observer(({view:e})=>{const t=ue(),n=le(),r=Fe.useModals(),{panel:a,downloadPanelScreenshot:o}=Qe(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=m.useContext(or),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=m.useCallback(()=>{u(l)},[l,u]),y=!c&&e.type!==j.Modal;return i(B,{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%"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),y&&i(s.Menu.Item,{onClick:g,icon:i(I.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(I.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(I.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(I.Trash,{size:14}),children:"Delete"})]})]})})})});function QS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Bi=k.observer(()=>{const[e,t]=m.useState(!1),{panel:n}=Ct();return QS(n.description)?null:p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.name,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Yn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(I.InfoCircle,{size:20})})})]})}),PM="",US=k.observer(function(){const{panel:t}=Ct(),{name:n,title:r}=t;return r.show?i(s.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function KS(e){const t=m.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;ts.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var Ol=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Ol||{}),cr=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(cr||{});class XS{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(be.instanceScope.panelModel),this.vizInstance=t.getRequired(be.instanceScope.vizInstance),this.operationManager=t.getRequired(be.instanceScope.operationManager),this.triggerManager=t.getRequired(be.instanceScope.triggerManager),this.vizManager=t.getRequired(be.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Bl(e){const{panel:t}=Ct();return m.useCallback(n=>{const r=n.getRequired(be.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(be.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const l=o.getRequired(be.instanceScope.vizInstance);return new Or(l,a,$n)}).provideFactory(be.instanceScope.operationManager,o=>o.getRequired(be.instanceScope.interactionManager).operationManager).provideFactory(be.instanceScope.triggerManager,o=>o.getRequired(be.instanceScope.interactionManager).triggerManager).provideValue(be.instanceScope.panelModel,t).provideFactory(be.instanceScope.migrator,o=>new XS(o))},[e.viz.type,e.viz.conf])}function Vl(e){const[t,n]=m.useState(!1),r=il().getRequired(be.instanceScope.migrator);return Q.useAsyncEffect(async()=>{const a=r.status===cr.notStarted;n(r.status===cr.done),r.status===cr.notStarted&&r.runMigration().then(o=>{o===Ol.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Nl(e,t){const n=il().getRequired(be.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function JS({setVizConf:e,...t}){const{panel:n}=t,r=Nl(e,n),a=Vl(()=>{Tn.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Q.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(fc,{...t}):i(s.Text,{children:"Checking update..."})}function ZS(e){const{panel:t,setVizConf:n}=e;Nl(n,t);const{inEditMode:r}=m.useContext(zn);return Vl(()=>{r&&Tn.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(hc,{...e}):i(s.Text,{children:"Checking update"})}const OM="";function HS(e,t){const{vizManager:n}=m.useContext(ct),{panel:{viz:r,title:a,id:o,name:l,description:u,queryIDs:c,variables:d}}=Ct(),f={id:o,name:l,title:a,description:u,queryIDs:c,viz:r,layout:t},h=Bl(f);try{return n.resolveComponent(r.type),i(sr,{configure:h,children:i(ZS,{setVizConf:r.setConf,panel:f,data:e,variables:d,vizManager:n})})}catch(g){return console.info(x.get(g,"message")),null}}const ql=k.observer(function({data:t}){const{ref:n,width:r,height:a}=_e.useElementSize(),o=HS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:i(s.Box,{sx:{width:r,height:a,overflow:"hidden"},children:l&&i(Ee,{children:o})})})}),Fl=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Vi=k.observer(({panel:e})=>p(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(Fl,{panel:e}),e.canRenderViz&&i(ql,{data:e.data})]})),e_={border:"1px solid #e9ecef"},Gl=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=KS(e);return e.title.show,i(Er,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...e_,...t},children:[i(s.Box,{className:"panel-description-popover-wrapper",children:i(Bi,{})}),n,i(US,{}),i(Vi,{panel:e})]})})}),t_={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function n_(e){return e.style.border.enabled?{}:t_}const Wl=k.observer(function({panel:t,view:n}){const r=n_(t);return i(Gl,{panel:t,panelStyle:r,dropdownContent:i(YS,{view:n})})});function r_(e){return!["richText","button"].includes(e)}const i_=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=Ct(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=m.useContext(or),l=m.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==j.Modal;return r_(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target"})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(I.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function a_(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ni=k.observer(({panel:e,view:t})=>{const n=a_(e);return i(Gl,{panel:e,panelStyle:n,dropdownContent:i(i_,{view:t})})}),s_={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},jl=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(I.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:s_,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Ni,{view:t,panel:n})})})});function Rl(e,t,n){const{panels:r}=ye(),a=e.id==="Main",[o,l]=m.useState(()=>a&&r.findByID(t)?t:null),u=m.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=m.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const BM="",o_=m.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(I.ArrowsMove,{size:16})})),l_=m.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(I.ChevronDownRight,{size:16})})),u_=Dn.WidthProvider(Dn),c_=k.observer(({view:e,className:t="layout"})=>{const n=ye(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=m.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(u_,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(l_,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(o_,{h:u.layout.h}),i(Wl,{view:e,panel:u})]},u.id))})}),d_=Dn.WidthProvider(Dn),p_=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=ye().panels.panelsByIDs(t.panelIDs);return i(d_,{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(Ni,{view:t,panel:o})},o.id))})});function qi(e){const t=m.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;ts.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const h_=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=Mr(),o=ye(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;$l(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i(E.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Yl=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=qi(t);return p(B,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(h_,{downloadScreenShot:a})]})}),Ql=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i(E.IconCamera,{size:14})})),f_=k.observer(({children:e,view:t})=>{const n=ye(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=qi(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Ql,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),g_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},m_=k.observer(({view:e})=>{const t=ye(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:e.tab,onTabChange:e.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:g_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(dr,{view:a})},r.id):null})]})}),y_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(f_,{view:e,children:t});case j.Tabs:return i(m_,{view:e});case j.Division:default:return i(Yl,{view:e,children:t})}}),b_=k.observer(({children:e,view:t})=>i(Yl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function Ul(e){return e.replace(/(vw|vh)/,"%")}const v_=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=m.useMemo(()=>({width:Ul(n.width),height:Ul(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=qi(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Ql,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),x_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},w_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},C_=k.observer(({view:e})=>{const t=Fe.useModals(),n=le(),r=m.useMemo(()=>n.views.options.filter(u=>u.type===j.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:e.tab,onTabChange:e.setTab,styles:x_(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:w_(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(I.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(E.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(dr,{view:d})]},u.id)})]})}),S_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(v_,{view:e,children:t});case j.Tabs:return i(C_,{view:e});case j.Division:default:return i(b_,{view:e,children:t})}}),Kl=k.observer(function({view:t}){return i(or.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(S_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:t})}),i(c_,{view:t})]})})})})}),dr=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ws(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Rl(t,n,r);return i(or.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===j.Modal?"0 !important":"100%"},children:[l&&i(jl,{view:t,panel:u,exitFullScreen:o}),i(y_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:t})}),!l&&i(p_,{view:t})]})})]})})});var Xl=(e=>(e.Use="use",e.Edit="edit",e))(Xl||{});const __={[j.Division]:"Division",[j.Tabs]:"Tabs",[j.Modal]:"Modal"},Jl={[j.Division]:"rgba(255, 0, 0, 0.2)",[j.Modal]:"rgba(0, 0, 0, 0.2)",[j.Tabs]:"rgba(255, 200, 100, 0.4)"},k_={[j.Division]:"#ff4000",[j.Modal]:"#000",[j.Tabs]:"#ffad18"},T_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:j.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function D_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Zl=b.types.compose("FiltersModel",Ml,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===ve.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){D_(e.current,bl,(n,r)=>{if(n==="setType"){const a=Il(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Hl=Ll.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.id)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.id)),e.current=b.cast(r)}})),eu=Pl.views(e=>({get sortedList(){return x.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},removeByKeys(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.key)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.key)),e.current=b.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),I_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),M_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),A_=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(e=>({get keywords(){return b.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=b.getParent(e,1);return`${n}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
|
|
441
441
|
SELECT count(*) AS total
|
|
442
442
|
FROM ${n}.${t}
|
|
443
|
-
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,te.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),z_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),E_=b.types.compose("DataSourceModel",Cl,b.types.model({tables:b.types.optional(z_,{}),columns:b.types.optional(I_,{}),tableData:b.types.optional(A_,{}),indexes:b.types.optional(M_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).views(e=>({get sqlDataSourceType(){return e.type},get reloadConditionString(){const{type:t,table_name:n,table_schema:r}=e;return`${t};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(at.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!pt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(at.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(r){if(pt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(at.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(pt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(at.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:a}]=yield*b.toGenerator(at.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));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(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,te.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),$_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(E_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function Kt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function L_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const P_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:E.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:E.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:E.IconFilter,children:[...n.options,Kt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:E.IconCopy,children:[Kt("_SQL_SNIPPETS_SETTINGS_"),...a.options,Kt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:E.IconDatabase,children:[Kt("_QUERIES_SETTINGS_"),...o.options,Kt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:E.IconBoxMultiple,children:[...r.editorOptions,Kt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=L_(t);n&&e.setPath(n)}})),tu=Tl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),nu=b.types.compose("PanelsModel",Dl,b.types.model({list:b.types.optional(b.types.array(tu),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),ru=b.types.compose("ViewsModel",kl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,j.Division,j.Division,{_name:j.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function qi(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const O_=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:Zl,queries:Hl,sqlSnippets:eu,views:ru,panels:nu,mock_context:ll,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(e.views.json,x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ur(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ur(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(a=>{a.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const u="panel",c=l.name,d=[{id:a.id,label:a.name}];l.queryIDs.forEach(f=>{n.push({id:o,queryID:f,type:u,label:c,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(a=>!!x.get(a,"config.options_query_id")).map(a=>({type:"filter",id:a.id,queryID:x.get(a,"config.options_query_id"),label:a.label,views:a.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})),x.groupBy(n,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[],n=new RegExp("(?<=sql_snippets\\.)([^}.]+)","gm");return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;x.uniq(r.sql.match(n)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),x.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),n=e.queries.current.filter(r=>!t.has(r.id)).map(r=>r.id);e.queries.removeQueries(n)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),n=e.sqlSnippets.current.filter(r=>!t.has(r.key)).map(r=>r.key);e.sqlSnippets.removeByKeys(n)},duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(AS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,qi(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),Fi=b.types.snapshotProcessor(O_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function B_(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function iu({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Fi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Al(u),queries:{current:f},sqlSnippets:{current:h},mock_context:ul(g),views:qi(c),panels:{list:d}})}const au=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Fi,content_id:b.types.string,datasources:$_,globalSQLSnippets:Sl,context:Pi,editor:P_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function su({id:e,name:t,group:n,content_id:r},a,o,l,u){return au.create({id:e,name:t,group:n,content_id:r,content:iu(a),datasources:{list:o},globalSQLSnippets:{list:l},context:_l(u),editor:{}})}function ou(e,t){m.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),m.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),m.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),m.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,y=>{if(l&&typeof y=="string")return encodeURIComponent(y)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function lu(e){return m.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const VM="",V_=k.observer(()=>{const e=Ir(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;$l(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(E.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),N_=k.observer(({saveDashboardChanges:e})=>{const t=Fe.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.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(E.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(E.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(E.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),q_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Ku.useNavigate(),r=ue(),a=()=>{n(`/dashboard/${r.id}`)},o=Fe.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i(E.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(N_,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(V_,{})]})]})})}),F_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},G_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===j.Tabs;return i(s.Box,{sx:F_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i(E.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,{})]})})}),W_=k.observer(e=>p(B,{children:[i(q_,{...e}),i(G_,{})]})),NM="";function j_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:y}=h,{config:C}=y;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function R_(e,t){const n=e.filters.keyLabelMap;return{edges:j_(e.panels.list,t,n),edgeNodes:[]}}function uu(e,t,n){return e*t+e*n}function Y_(e,t,n){return e*t+(e-1)*n}const pr=25,Gi=40,cu=25,Wi=350,Q_=150,U_=150,du=150,pu=300,hr=40,hu=25,K_=300;function X_(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=uu(u,hr,hu)+Gi,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:pr,y:c},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,style:{width:pu,height:hr}});return}const f=d.name;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:pr,y:c},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,style:{width:pu,height:hr}})})}),r}const J_={[j.Division]:"Div",[j.Modal]:"Modal",[j.Tabs]:"Tabs"},Z_=Jl;function H_(e){return e.current.map((n,r)=>{const a=Y_(n.panelIDs.length,hr,hu)+Gi+cu;let o=[];return n.type===j.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${J_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,className:"light",style:{backgroundColor:Z_[n.type],width:Wi,height:a}}})}function ek(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==j.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function tk(e){const t=H_(e.views);ek(t);const n=X_(e.views,e.panels.list);return[...t,...n]}function nk({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==j.Tabs||(r.sourcePosition=Ie.Position.Bottom,r.style.width=Wi+pr*2,r.style.height=cu+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=pr;const u=l.style.height;return a+u+20},Gi))})}function rk({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function ik({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+K_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Ie.Position.Left,l.targetPosition=Ie.Position.Right,l.position.x*=-1);const g=l.position.x,y=x.get(r,g,0);l.position.y=y,r[g]=y+d+du}})}function ak({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=uu(u,Wi,U_),l.position.y=0-Q_-du})}function sk({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return ak(r),rk(r),nk(r),ik(r),{nodes:t,edges:n}}function ok(e){const t=tk(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=R_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return sk(u)}const qM="",ji={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(E.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleOff,{size:14})})};function lk(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:ji[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:ji[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:ji[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const uk=m.memo(({data:e,isConnectable:t,sourcePosition:n=Ie.Position.Right,targetPosition:r=Ie.Position.Left,...a})=>{const o=m.useMemo(()=>lk(e.interactions),[e.interactions]);return p(B,{children:[i(Ie.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(I.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Ie.Handle,{type:"source",position:n,isConnectable:t})]})}),FM="",ck={interaction:uk},dk=k.observer(()=>{const e=ye(),{edges:t,nodes:n}=ok(e);return p(Ie,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:ck,children:[i(Ie.MiniMap,{}),i(Ie.Controls,{}),i(Ie.Background,{})]})}),pk=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:i(dk,{})})),hk={"> 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 fk({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(E.IconAdjustments,{size:16})})})]})}const gk=k.observer(()=>{const e=ue(),t=le(),n=m.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(fk,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),mk=k.observer(()=>{const e=ue(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=m.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:{...hk,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(E.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(E.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(E.IconLink,{size:18})})})]}),i(pk,{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(gk,{})}),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(E.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),yk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(gi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),bk=[{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"}],vk=k.observer(function({config:t}){return p(B,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:bk,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(al,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Ri=k.observer(({value:e,onChange:t})=>{const n=ue(),r=le(),a=m.useMemo(()=>r.queries.options,[r.queries.current]),o=a.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return i(s.Select,{label:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Use query data as options"}),e&&i(s.Button,{size:"xs",leftIcon:i(E.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:a,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),xk=`
|
|
443
|
+
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,te.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),z_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),E_=b.types.compose("DataSourceModel",Cl,b.types.model({tables:b.types.optional(z_,{}),columns:b.types.optional(I_,{}),tableData:b.types.optional(A_,{}),indexes:b.types.optional(M_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).views(e=>({get sqlDataSourceType(){return e.type},get reloadConditionString(){const{type:t,table_name:n,table_schema:r}=e;return`${t};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(at.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!pt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(at.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(r){if(pt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(at.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(pt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(at.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:a}]=yield*b.toGenerator(at.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));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(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,te.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),$_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(E_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function Kt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function L_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const P_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:E.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:E.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:E.IconFilter,children:[...n.options,Kt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:E.IconCopy,children:[Kt("_SQL_SNIPPETS_SETTINGS_"),...a.options,Kt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:E.IconDatabase,children:[Kt("_QUERIES_SETTINGS_"),...o.options,Kt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:E.IconBoxMultiple,children:[...r.editorOptions,Kt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=L_(t);n&&e.setPath(n)}})),tu=Tl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),nu=b.types.compose("PanelsModel",Dl,b.types.model({list:b.types.optional(b.types.array(tu),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),ru=b.types.compose("ViewsModel",kl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,j.Division,j.Division,{_name:j.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Fi(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const O_=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:Zl,queries:Hl,sqlSnippets:eu,views:ru,panels:nu,mock_context:ll,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(e.views.json,x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ur(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ur(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return Sr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(a=>{a.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const u="panel",c=l.name,d=[{id:a.id,label:a.name}];l.queryIDs.forEach(f=>{n.push({id:o,queryID:f,type:u,label:c,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(a=>!!x.get(a,"config.options_query_id")).map(a=>({type:"filter",id:a.id,queryID:x.get(a,"config.options_query_id"),label:a.label,views:a.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})),x.groupBy(n,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[],n=new RegExp("(?<=sql_snippets\\.)([^}.]+)","gm");return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;x.uniq(r.sql.match(n)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),x.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),n=e.queries.current.filter(r=>!t.has(r.id)).map(r=>r.id);e.queries.removeQueries(n)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),n=e.sqlSnippets.current.filter(r=>!t.has(r.key)).map(r=>r.key);e.sqlSnippets.removeByKeys(n)},duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(AS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,Fi(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),Gi=b.types.snapshotProcessor(O_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function B_(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function iu({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Gi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Al(u),queries:{current:f},sqlSnippets:{current:h},mock_context:ul(g),views:Fi(c),panels:{list:d}})}const au=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Gi,content_id:b.types.string,datasources:$_,globalSQLSnippets:Sl,context:Oi,editor:P_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function su({id:e,name:t,group:n,content_id:r},a,o,l,u){return au.create({id:e,name:t,group:n,content_id:r,content:iu(a),datasources:{list:o},globalSQLSnippets:{list:l},context:_l(u),editor:{}})}function ou(e,t){m.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),m.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),m.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),m.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,y=>{if(l&&typeof y=="string")return encodeURIComponent(y)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function lu(e){return m.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const VM="",V_=k.observer(()=>{const e=Mr(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;$l(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(E.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),N_=k.observer(({saveDashboardChanges:e})=>{const t=Fe.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.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(E.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(E.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(E.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),q_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Ku.useNavigate(),r=ue(),a=()=>{n(`/dashboard/${r.id}`)},o=Fe.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i(E.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(N_,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(V_,{})]})]})})}),F_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},G_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===j.Tabs;return i(s.Box,{sx:F_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i(E.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,{})]})})}),W_=k.observer(e=>p(B,{children:[i(q_,{...e}),i(G_,{})]})),NM="";function j_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:y}=h,{config:C}=y;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function R_(e,t){const n=e.filters.keyLabelMap;return{edges:j_(e.panels.list,t,n),edgeNodes:[]}}function uu(e,t,n){return e*t+e*n}function Y_(e,t,n){return e*t+(e-1)*n}const pr=25,Wi=40,cu=25,ji=350,Q_=150,U_=150,du=150,pu=300,hr=40,hu=25,K_=300;function X_(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=uu(u,hr,hu)+Wi,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:pr,y:c},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,style:{width:pu,height:hr}});return}const f=d.name;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:pr,y:c},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,style:{width:pu,height:hr}})})}),r}const J_={[j.Division]:"Div",[j.Modal]:"Modal",[j.Tabs]:"Tabs"},Z_=Jl;function H_(e){return e.current.map((n,r)=>{const a=Y_(n.panelIDs.length,hr,hu)+Wi+cu;let o=[];return n.type===j.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${J_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,className:"light",style:{backgroundColor:Z_[n.type],width:ji,height:a}}})}function ek(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==j.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function tk(e){const t=H_(e.views);ek(t);const n=X_(e.views,e.panels.list);return[...t,...n]}function nk({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==j.Tabs||(r.sourcePosition=Ie.Position.Bottom,r.style.width=ji+pr*2,r.style.height=cu+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=pr;const u=l.style.height;return a+u+20},Wi))})}function rk({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function ik({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+K_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Ie.Position.Left,l.targetPosition=Ie.Position.Right,l.position.x*=-1);const g=l.position.x,y=x.get(r,g,0);l.position.y=y,r[g]=y+d+du}})}function ak({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=uu(u,ji,U_),l.position.y=0-Q_-du})}function sk({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return ak(r),rk(r),nk(r),ik(r),{nodes:t,edges:n}}function ok(e){const t=tk(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=R_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return sk(u)}const qM="",Ri={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(E.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleOff,{size:14})})};function lk(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Ri[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Ri[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Ri[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const uk=m.memo(({data:e,isConnectable:t,sourcePosition:n=Ie.Position.Right,targetPosition:r=Ie.Position.Left,...a})=>{const o=m.useMemo(()=>lk(e.interactions),[e.interactions]);return p(B,{children:[i(Ie.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(I.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Ie.Handle,{type:"source",position:n,isConnectable:t})]})}),FM="",ck={interaction:uk},dk=k.observer(()=>{const e=ye(),{edges:t,nodes:n}=ok(e);return p(Ie,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:ck,children:[i(Ie.MiniMap,{}),i(Ie.Controls,{}),i(Ie.Background,{})]})}),pk=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:i(dk,{})})),hk={"> 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 fk({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(E.IconAdjustments,{size:16})})})]})}const gk=k.observer(()=>{const e=ue(),t=le(),n=m.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(fk,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),mk=k.observer(()=>{const e=ue(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=m.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:{...hk,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(E.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(E.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(E.IconLink,{size:18})})})]}),i(pk,{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(gk,{})}),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(E.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),yk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(mi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),bk=[{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"}],vk=k.observer(function({config:t}){return p(B,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:bk,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(al,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Yi=k.observer(({value:e,onChange:t})=>{const n=ue(),r=le(),a=m.useMemo(()=>r.queries.options,[r.queries.current]),o=a.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return i(s.Select,{label:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Use query data as options"}),e&&i(s.Button,{size:"xs",leftIcon:i(E.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:a,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),xk=`
|
|
444
444
|
// row
|
|
445
445
|
{
|
|
446
446
|
label: string;
|
|
447
447
|
value: string;
|
|
448
448
|
description?: string; // optional
|
|
449
449
|
}
|
|
450
|
-
`,fu=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:xk})})]})},wk=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[...r];return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",description:"At least 160px",value:t.min_width,onChange:o=>t.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:[t.usingQuery&&p(B,{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:[...t.default_value],onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(I.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(I.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:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(
|
|
450
|
+
`,fu=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:xk})})]})},wk=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[...r];return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",description:"At least 160px",value:t.min_width,onChange:o=>t.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:[t.usingQuery&&p(B,{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:[...t.default_value],onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(I.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(I.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:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Yi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(fu,{})]})}),Ck=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[{label:"No default selection",value:""},...r];return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:t.width,onChange:o=>t.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:[t.usingQuery&&p(B,{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:t.default_value,onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(I.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(I.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:t.default_selection_count===1,onChange:o=>t.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(Yi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(fu,{})]})}),Sk=k.observer(function({config:t}){return p(B,{children:[i(s.TextInput,{label:"Default Value",value:t.default_value,onChange:n=>{t.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"})]})}),_k=`
|
|
451
451
|
// row
|
|
452
452
|
{
|
|
453
453
|
label: string;
|
|
@@ -455,7 +455,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
455
455
|
parent_value: string;
|
|
456
456
|
description?: string;
|
|
457
457
|
}
|
|
458
|
-
`,kk=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:_k})})]})},Tk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Ri,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(kk,{})]})}),Dk=k.observer(function({filter:t}){return p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),i(Mt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Ik={select:Ck,"multi-select":wk,"tree-select":Tk,"text-input":Sk,checkbox:yk,"date-range":vk},Mk=[{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"}],Ak=k.observer(function({filter:t}){const n=le(),r=m.useMemo(()=>Ik[t.type],[t.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:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:a=>t.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:a=>{t.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:a=>{t.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:Mk,required:!0,value:t.type,onChange:t.setType}),i(r,{config:t.config})]})]}),i(Dk,{filter:t})]})}),zk=k.observer(({id:e})=>{const t=Fe.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.filters.findByID(e);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),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(I.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(Ak,{filter:a})})]})}),Ek=k.observer(()=>{const e=le(),[t,n]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Tn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.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:t,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(I.DeviceFloppy,{size:20})})]})]})}),$k=k.observer(()=>{const{panel:e}=Qe();return i(gi,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Lk=k.observer(()=>{const{panel:e}=Qe(),{style:t}=e;return p(B,{children:[i(s.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),p(s.Stack,{spacing:20,children:[p(s.Group,{grow:!0,align:"top",children:[i(s.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:i(s.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),i(s.NumberInput,{label:"Height",rightSection:i(s.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),i(s.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Pk=()=>p("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Ok=k.observer(()=>{const{panel:e}=Qe(),{name:t}=e,[n,r]=_e.useInputState(t),a=t!==n,o=m.useCallback(()=>{a&&e.setName(n)},[a,n]);m.useEffect(()=>{r(t)},[t]);const l=!n.trim();return p(s.Stack,{spacing:4,children:[p(s.Group,{align:"center",children:[p(s.Text,{size:14,fw:500,children:["Panel Name",i(Pk,{})]}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!a||l,onClick:o,children:i(E.IconDeviceFloppy,{size:18})})]}),i(s.TextInput,{value:n,onChange:r,required:!0})]})}),Bk=k.observer(()=>{const{panel:e}=Qe();return i(s.Stack,{spacing:6,mb:10,children:p(s.Group,{pl:6,position:"left",spacing:20,children:[i(s.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),i(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function Vk(){return p(s.Stack,{sx:{height:"100%"},children:[i(Lk,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(Ok,{}),i(Bk,{}),i($k,{})]})}const Nk={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 gu({data:e}){const t=m.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=et.createColumnHelper();return Object.keys(e[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[e]),n=et.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:et.getCoreRowModel()});return e.length===0?i(s.Box,{sx:{height:"5em"}}):i(Ee,{children:p(s.Table,{sx:Nk,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:et.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(I.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Ee,{children:et.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const qk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Fk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Gk=({data:e,page:t,setPage:n,limit:r,setLimit:a})=>{const o=e.length,l=Math.ceil(o/r),u=d=>{n(1),a(Number(d))};if(o===0)return null;const c=l===1&&o<=10;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[l>1&&i(s.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!c&&i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Fk,data:qk,value:String(r),onChange:u})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},Wk=({data:e,loading:t})=>{const[n,r]=m.useState(1),[a,o]=m.useState(20),l=m.useMemo(()=>{const u=(n-1)*a,c=u+a;return e.slice(u,c)},[e,n,a]);return p(Ee,{children:[i(Gk,{data:e,page:n,setPage:r,limit:a,setLimit:o}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t,overlayBlur:2}),i(gu,{data:l})]})]})},jk=({queryID:e})=>{const t=ye(),{state:n,error:r}=t.getDataStuffByID(e),a=m.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?i(s.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{mt:10,color:"gray",align:"center",children:a.stateMessage}):null},Yi=k.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ye(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=m.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),c=()=>{r.queries.downloadDataByQueryID(e)};m.useEffect(()=>{n&&u()},[u,n]);const d=!Array.isArray(a)||a.length===0;return p(s.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Group,{position:"left",children:i(s.Text,{weight:500,children:"Preview Data"})}),p(s.Group,{pr:15,children:[t,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(I.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:c,children:i(I.Download,{size:16})})]})]}),p(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[i(jk,{queryID:e}),i(Wk,{data:a,loading:l})]})]})}),Rk=k.observer(function(){const t=ue(),n=le(),{panel:r}=Qe(),[a,o]=m.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return p(B,{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(E.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Yi,{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(E.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(Yi,{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(E.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),Yk=k.observer(()=>{const{panel:e}=Ct();return i(Ee,{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:e.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(Oi,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:i(Bi,{panel:e})})]})})})}),Qi={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 Qk{constructor(t){q(this,"panel");q(this,"selected");this.panel=t,te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Qi.name)).length;this.panel.addVariable(x.cloneDeep({...Qi,name:`${Qi.name}${t||""}`})),this.selected=x.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function Uk(){const{panel:e}=Qe();return Q.useCreation(()=>new Qk(e),[e])}const mu=s.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),Kk=m.forwardRef(function({value:t,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(t);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:t.name,onChange:u=>l("name",u.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),i(Un,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),t.aggregation.type!=="custom"&&p(B,{children:[i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Ge,{value:t.formatter,onChange:u=>l("formatter",u)})]}),a&&i(oo,{value:t,onChange:n})]})}),Xk=e=>{const{uiModel:t}=e;return i(s.Stack,{className:"var-list",children:t.variables.map(n=>i(s.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},Jk=k.observer(Xk),Zk=({variable:e,data:t})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:lo(e,t)})}),Hk=k.observer(Zk),eT=e=>{const t=Q.useCreation(()=>RS(e.variable),[e.variable]),{classes:n}=mu(),{data:r}=Qe();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:!t.changed,color:"primary",onClick:t.commit,children:i(E.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:i(E.IconTrash,{size:18})})]}),i(Kk,{value:b.getSnapshot(t.copy),onChange:t.update,data:r})]}),i(Hk,{variable:b.getSnapshot(t.copy),data:r})]})},tT=k.observer(eT),nT=()=>{const e=Uk(),{classes:t}=mu();return p(s.Group,{className:t.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:e.addNew,fullWidth:!0,children:"Add Variable"})}),i(Jk,{uiModel:e})]})}),e.selected?i(B,{children:i(tT,{uiModel:e,variable:e.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},rT=k.observer(nT);function iT(){const{vizManager:e}=m.useContext(ct);return m.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const aT=k.observer(({value:e,submit:t})=>{const[n,r]=_e.useInputState(e);m.useEffect(()=>{r(e)},[e]);const a=iT(),o=e!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>t(n),children:i(I.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),yu=[];function sT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function oT(){const{data:e,panel:{variables:t,viz:n,title:r,name:a,queryIDs:o,description:l,id:u}}=Qe(),{vizManager:c}=m.useContext(ct),d={name:a,title:r,description:l,viz:n,queryIDs:o,id:u},f=Bl(d);try{return c.resolveComponent(d.viz.type),i(sr,{configure:f,children:i(JS,{variables:t,setVizConf:n.setConf,panel:d,vizManager:c,data:e})})}catch(h){return console.info(x.get(h,"message")),null}}const lT=k.observer(()=>{const{data:e,panel:{viz:t}}=Qe(),{vizManager:n}=m.useContext(ct),r=m.useCallback(d=>{if(d===t.type)return;const f=sT(n,d);t.setType(d),t.setConf(f||{})},[t.type]),a=d=>{try{t.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=m.useMemo(()=>{var d;return(d=yu.find(f=>f.value===t.type))==null?void 0:d.Panel},[t.type,yu]),l=oT(),u=o?m.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(aT,{submit:r,value:t.type}),p(Ee,{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(t.conf,null,2),onChange:a})]})]})}),uT=k.observer(({panel:e,sourceViewID:t})=>{const n=le(),[r,a]=m.useState(t);m.useEffect(()=>{a(t)},[t]);const[o,{open:l,close:u}]=_e.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return p(B,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(E.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(E.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(E.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),cT={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},bu=({children:e})=>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:e}),i(Yk,{})]});function dT(e){return!["richText","button"].includes(e)}const pT=k.observer(({panel:e})=>{const t=Fe.useModals(),n=ue(),r=le(),[a,o]=m.useState("Data"),l=e.queries,c=dT(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,f=n.editor.path[1];m.useEffect(()=>{o(y=>d&&y==="Visualization"?"Data":y)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(zr,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[i(s.Text,{pt:9,pb:8,children:e.name}),p(s.Group,{position:"right",noWrap:!0,children:[i(uT,{panel:e,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:cT,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(Rk,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(bu,{children:i(Vk,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(rT,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Ee,{children:i(bu,{children:i(lT,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Ee,{children:i(kd,{})})})]})]})}),hT=k.observer(({viewID:e,panelID:t})=>{const n=le();if(!n.views.findByID(e))return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const a=n.panels.findByID(t);return a?i(pT,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),fT=e=>{const{queryModel:t}=e,n=ue(),r=le(),o=r.findQueryUsage(t.id).length>0,l=Fe.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.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(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},gT=k.observer(fT),vu=({width:e="calc(100% - 32px)",lastWidth:t="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:e,height:n,radius:"xs"},u)),i(s.Skeleton,{width:t,height:n,radius:"xs"})]}),xn=({value:e})=>e===null||e===""?null:i(s.Tooltip,{label:e,disabled:!e,multiline:!0,children:i(s.ActionIcon,{children:i(E.IconInfoCircle,{size:14})})}),mT=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:t})}):null},yT=k.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?i(vu,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.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:t.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(xn,{value:n.column_comment})}),i("td",{children:i(mT,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(xn,{value:n.column_default})})]},n.column_name))})]})}),bT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.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))})]})}),vT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.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(xn,{value:r.index_definition})}),i("td",{children:i(xn,{value:r.condition})}),i("td",{children:i(xn,{value:r.comment})})]},r.index_name))})]})}),xT=k.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===Ne.MySQL?i(bT,{dataSource:e}):e.type===Ne.Postgresql?i(vT,{dataSource:e}):null}),wT=k.observer(({dataSource:e})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Ee,{children:i(yT,{dataSource:e})}),i(Ee,{children:i(xT,{dataSource:e})})]}));function CT({table_type:e}){return e==="VIEW"?i(E.IconEye,{size:14}):e==="BASE TABLE"?i(E.IconTable,{size:14}):null}const ST=k.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?i(vu,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(E.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(CT,{table_type:a.table_type}),onClick:()=>{e.setKeywords(n,a.table_name)},active:e.table_name===a.table_name},a.table_name))},n))})}),_T=({visible:e})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:e})}),kT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],TT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},DT=k.observer(({dataSource:e})=>{const{tableData:t}=e;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[t.maxPage>1&&i(s.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:TT,data:kT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),IT=k.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?i(_T,{visible:!0}):p(Ee,{children:[i(DT,{dataSource:e}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t.loading,overlayBlur:2}),i(gu,{data:t.data})]})]})}),MT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},AT=k.observer(({dataSource:e})=>(m.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Ee,{children:i(ST,{dataSource:e})})}),p(s.Tabs,{defaultValue:"structure",styles:MT,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(E.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(E.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(wT,{dataSource:e})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(IT,{dataSource:e})})]})]}))),zT={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"}},xu=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=m.useState(!1);return e.type==="http"?null:p(B,{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:e.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:zT,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(AT,{dataSource:e})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),ET=m.forwardRef(({label:e,type:t,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:e}),i(s.Text,{children:t})]})),$T=k.observer(({value:e,onChange:t})=>{const n=ue(),{data:r=[],loading:a}=Q.useRequest(Sr,{refreshDeps:[]},[]),o=m.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=m.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=m.useMemo(()=>n.datasources.find(e),[n,e]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(xu,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:ET,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:e.key,onChange:u})}),wu=m.forwardRef((e,t)=>{const{label:n,description:r,...a}=e;return i("div",{ref:t,...a,children:p(s.Group,{position:"apart",noWrap:!0,children:[i(s.Text,{children:n}),i(s.Text,{size:"xs",color:"dimmed",children:r})]})})}),LT=k.observer(({queryModel:e})=>{const[t,n]=m.useState(e.name);return m.useEffect(()=>{n(e.name)},[e.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:t,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:i(E.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),i($T,{value:{type:e.type,key:e.key},onChange:({type:r,key:a})=>{e.setKey(a),e.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:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:wu,maxDropdownHeight:500}),e.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:wu,maxDropdownHeight:500}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(gT,{queryModel:e})]})})});function PT({content:e}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(E.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(Mt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const OT=k.observer(()=>{const t=[...ue().globalSQLSnippets.list];return t.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:t.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(PT,{content:a})})]},r)})})]})}),BT=`
|
|
458
|
+
`,kk=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:_k})})]})},Tk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Yi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(kk,{})]})}),Dk=k.observer(function({filter:t}){return p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),i(Mt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Ik={select:Ck,"multi-select":wk,"tree-select":Tk,"text-input":Sk,checkbox:yk,"date-range":vk},Mk=[{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"}],Ak=k.observer(function({filter:t}){const n=le(),r=m.useMemo(()=>Ik[t.type],[t.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:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:a=>t.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:a=>{t.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:a=>{t.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:Mk,required:!0,value:t.type,onChange:t.setType}),i(r,{config:t.config})]})]}),i(Dk,{filter:t})]})}),zk=k.observer(({id:e})=>{const t=Fe.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.filters.findByID(e);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),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(I.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(Ak,{filter:a})})]})}),Ek=k.observer(()=>{const e=le(),[t,n]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Tn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.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:t,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(I.DeviceFloppy,{size:20})})]})]})}),$k=k.observer(()=>{const{panel:e}=Qe();return i(mi,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Lk=k.observer(()=>{const{panel:e}=Qe(),{style:t}=e;return p(B,{children:[i(s.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),p(s.Stack,{spacing:20,children:[p(s.Group,{grow:!0,align:"top",children:[i(s.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:i(s.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),i(s.NumberInput,{label:"Height",rightSection:i(s.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),i(s.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Pk=()=>p("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Ok=k.observer(()=>{const{panel:e}=Qe(),{name:t}=e,[n,r]=_e.useInputState(t),a=t!==n,o=m.useCallback(()=>{a&&e.setName(n)},[a,n]);m.useEffect(()=>{r(t)},[t]);const l=!n.trim();return p(s.Stack,{spacing:4,children:[p(s.Group,{align:"center",children:[p(s.Text,{size:14,fw:500,children:["Panel Name",i(Pk,{})]}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!a||l,onClick:o,children:i(E.IconDeviceFloppy,{size:18})})]}),i(s.TextInput,{value:n,onChange:r,required:!0})]})}),Bk=k.observer(()=>{const{panel:e}=Qe();return i(s.Stack,{spacing:6,mb:10,children:p(s.Group,{pl:6,position:"left",spacing:20,children:[i(s.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),i(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function Vk(){return p(s.Stack,{sx:{height:"100%"},children:[i(Lk,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(Ok,{}),i(Bk,{}),i($k,{})]})}const Nk={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 gu({data:e}){const t=m.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=et.createColumnHelper();return Object.keys(e[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[e]),n=et.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:et.getCoreRowModel()});return e.length===0?i(s.Box,{sx:{height:"5em"}}):i(Ee,{children:p(s.Table,{sx:Nk,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:et.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(I.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Ee,{children:et.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const qk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Fk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Gk=({data:e,page:t,setPage:n,limit:r,setLimit:a})=>{const o=e.length,l=Math.ceil(o/r),u=d=>{n(1),a(Number(d))};if(o===0)return null;const c=l===1&&o<=10;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[l>1&&i(s.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!c&&i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Fk,data:qk,value:String(r),onChange:u})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},Wk=({data:e,loading:t})=>{const[n,r]=m.useState(1),[a,o]=m.useState(20),l=m.useMemo(()=>{const u=(n-1)*a,c=u+a;return e.slice(u,c)},[e,n,a]);return p(Ee,{children:[i(Gk,{data:e,page:n,setPage:r,limit:a,setLimit:o}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t,overlayBlur:2}),i(gu,{data:l})]})]})},jk=({queryID:e})=>{const t=ye(),{state:n,error:r}=t.getDataStuffByID(e),a=m.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?i(s.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{mt:10,color:"gray",align:"center",children:a.stateMessage}):null},Qi=k.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ye(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=m.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),c=()=>{r.queries.downloadDataByQueryID(e)};m.useEffect(()=>{n&&u()},[u,n]);const d=!Array.isArray(a)||a.length===0;return p(s.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Group,{position:"left",children:i(s.Text,{weight:500,children:"Preview Data"})}),p(s.Group,{pr:15,children:[t,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(I.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:c,children:i(I.Download,{size:16})})]})]}),p(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[i(jk,{queryID:e}),i(Wk,{data:a,loading:l})]})]})}),Rk=k.observer(function(){const t=ue(),n=le(),{panel:r}=Qe(),[a,o]=m.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return p(B,{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(E.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Qi,{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(E.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(Qi,{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(E.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),Yk=k.observer(()=>{const{panel:e}=Ct();return i(Ee,{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:e.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(Bi,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:i(Vi,{panel:e})})]})})})}),Ui={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 Qk{constructor(t){q(this,"panel");q(this,"selected");this.panel=t,te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Ui.name)).length;this.panel.addVariable(x.cloneDeep({...Ui,name:`${Ui.name}${t||""}`})),this.selected=x.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function Uk(){const{panel:e}=Qe();return Q.useCreation(()=>new Qk(e),[e])}const mu=s.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),Kk=m.forwardRef(function({value:t,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(t);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:t.name,onChange:u=>l("name",u.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),i(Un,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),t.aggregation.type!=="custom"&&p(B,{children:[i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Ge,{value:t.formatter,onChange:u=>l("formatter",u)})]}),a&&i(oo,{value:t,onChange:n})]})}),Xk=e=>{const{uiModel:t}=e;return i(s.Stack,{className:"var-list",children:t.variables.map(n=>i(s.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},Jk=k.observer(Xk),Zk=({variable:e,data:t})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:lo(e,t)})}),Hk=k.observer(Zk),eT=e=>{const t=Q.useCreation(()=>RS(e.variable),[e.variable]),{classes:n}=mu(),{data:r}=Qe();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:!t.changed,color:"primary",onClick:t.commit,children:i(E.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:i(E.IconTrash,{size:18})})]}),i(Kk,{value:b.getSnapshot(t.copy),onChange:t.update,data:r})]}),i(Hk,{variable:b.getSnapshot(t.copy),data:r})]})},tT=k.observer(eT),nT=()=>{const e=Uk(),{classes:t}=mu();return p(s.Group,{className:t.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:e.addNew,fullWidth:!0,children:"Add Variable"})}),i(Jk,{uiModel:e})]})}),e.selected?i(B,{children:i(tT,{uiModel:e,variable:e.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},rT=k.observer(nT);function iT(){const{vizManager:e}=m.useContext(ct);return m.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const aT=k.observer(({value:e,submit:t})=>{const[n,r]=_e.useInputState(e);m.useEffect(()=>{r(e)},[e]);const a=iT(),o=e!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>t(n),children:i(I.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),yu=[];function sT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function oT(){const{data:e,panel:{variables:t,viz:n,title:r,name:a,queryIDs:o,description:l,id:u}}=Qe(),{vizManager:c}=m.useContext(ct),d={name:a,title:r,description:l,viz:n,queryIDs:o,id:u},f=Bl(d);try{return c.resolveComponent(d.viz.type),i(sr,{configure:f,children:i(JS,{variables:t,setVizConf:n.setConf,panel:d,vizManager:c,data:e})})}catch(h){return console.info(x.get(h,"message")),null}}const lT=k.observer(()=>{const{data:e,panel:{viz:t}}=Qe(),{vizManager:n}=m.useContext(ct),r=m.useCallback(d=>{if(d===t.type)return;const f=sT(n,d);t.setType(d),t.setConf(f||{})},[t.type]),a=d=>{try{t.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=m.useMemo(()=>{var d;return(d=yu.find(f=>f.value===t.type))==null?void 0:d.Panel},[t.type,yu]),l=oT(),u=o?m.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(aT,{submit:r,value:t.type}),p(Ee,{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(t.conf,null,2),onChange:a})]})]})}),uT=k.observer(({panel:e,sourceViewID:t})=>{const n=le(),[r,a]=m.useState(t);m.useEffect(()=>{a(t)},[t]);const[o,{open:l,close:u}]=_e.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return p(B,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(E.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(E.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(E.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),cT={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},bu=({children:e})=>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:e}),i(Yk,{})]});function dT(e){return!["richText","button"].includes(e)}const pT=k.observer(({panel:e})=>{const t=Fe.useModals(),n=ue(),r=le(),[a,o]=m.useState("Data"),l=e.queries,c=dT(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,f=n.editor.path[1];m.useEffect(()=>{o(y=>d&&y==="Visualization"?"Data":y)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Er,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[i(s.Text,{pt:9,pb:8,children:e.name}),p(s.Group,{position:"right",noWrap:!0,children:[i(uT,{panel:e,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:cT,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(Rk,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(bu,{children:i(Vk,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(rT,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Ee,{children:i(bu,{children:i(lT,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Ee,{children:i(kd,{})})})]})]})}),hT=k.observer(({viewID:e,panelID:t})=>{const n=le();if(!n.views.findByID(e))return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const a=n.panels.findByID(t);return a?i(pT,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),fT=e=>{const{queryModel:t}=e,n=ue(),r=le(),o=r.findQueryUsage(t.id).length>0,l=Fe.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.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(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},gT=k.observer(fT),vu=({width:e="calc(100% - 32px)",lastWidth:t="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:e,height:n,radius:"xs"},u)),i(s.Skeleton,{width:t,height:n,radius:"xs"})]}),xn=({value:e})=>e===null||e===""?null:i(s.Tooltip,{label:e,disabled:!e,multiline:!0,children:i(s.ActionIcon,{children:i(E.IconInfoCircle,{size:14})})}),mT=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:t})}):null},yT=k.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?i(vu,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.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:t.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(xn,{value:n.column_comment})}),i("td",{children:i(mT,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(xn,{value:n.column_default})})]},n.column_name))})]})}),bT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.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))})]})}),vT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.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(xn,{value:r.index_definition})}),i("td",{children:i(xn,{value:r.condition})}),i("td",{children:i(xn,{value:r.comment})})]},r.index_name))})]})}),xT=k.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===Ne.MySQL?i(bT,{dataSource:e}):e.type===Ne.Postgresql?i(vT,{dataSource:e}):null}),wT=k.observer(({dataSource:e})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Ee,{children:i(yT,{dataSource:e})}),i(Ee,{children:i(xT,{dataSource:e})})]}));function CT({table_type:e}){return e==="VIEW"?i(E.IconEye,{size:14}):e==="BASE TABLE"?i(E.IconTable,{size:14}):null}const ST=k.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?i(vu,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(E.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(CT,{table_type:a.table_type}),onClick:()=>{e.setKeywords(n,a.table_name)},active:e.table_name===a.table_name},a.table_name))},n))})}),_T=({visible:e})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:e})}),kT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],TT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},DT=k.observer(({dataSource:e})=>{const{tableData:t}=e;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[t.maxPage>1&&i(s.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:TT,data:kT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),IT=k.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?i(_T,{visible:!0}):p(Ee,{children:[i(DT,{dataSource:e}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t.loading,overlayBlur:2}),i(gu,{data:t.data})]})]})}),MT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},AT=k.observer(({dataSource:e})=>(m.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Ee,{children:i(ST,{dataSource:e})})}),p(s.Tabs,{defaultValue:"structure",styles:MT,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(E.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(E.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(wT,{dataSource:e})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(IT,{dataSource:e})})]})]}))),zT={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"}},xu=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=m.useState(!1);return e.type==="http"?null:p(B,{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:e.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:zT,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(AT,{dataSource:e})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),ET=m.forwardRef(({label:e,type:t,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:e}),i(s.Text,{children:t})]})),$T=k.observer(({value:e,onChange:t})=>{const n=ue(),{data:r=[],loading:a}=Q.useRequest(_r,{refreshDeps:[]},[]),o=m.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=m.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=m.useMemo(()=>n.datasources.find(e),[n,e]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(xu,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:ET,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:e.key,onChange:u})}),wu=m.forwardRef((e,t)=>{const{label:n,description:r,...a}=e;return i("div",{ref:t,...a,children:p(s.Group,{position:"apart",noWrap:!0,children:[i(s.Text,{children:n}),i(s.Text,{size:"xs",color:"dimmed",children:r})]})})}),LT=k.observer(({queryModel:e})=>{const[t,n]=m.useState(e.name);return m.useEffect(()=>{n(e.name)},[e.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:t,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:i(E.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),i($T,{value:{type:e.type,key:e.key},onChange:({type:r,key:a})=>{e.setKey(a),e.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:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:wu,maxDropdownHeight:500}),e.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:wu,maxDropdownHeight:500}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(gT,{queryModel:e})]})})});function PT({content:e}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(E.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(Mt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const OT=k.observer(()=>{const t=[...ue().globalSQLSnippets.list];return t.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:t.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(PT,{content:a})})]},r)})})]})}),BT=`
|
|
459
459
|
-- You may reference query variables in SQL or VizConfig.
|
|
460
460
|
SELECT *
|
|
461
461
|
FROM commit
|
|
@@ -468,8 +468,8 @@ WHERE
|
|
|
468
468
|
AND \${sql_snippets.author_email_condition}
|
|
469
469
|
-- Global SQL snippets (shared between dashboards)
|
|
470
470
|
AND \${global_sql_snippets.account_condition}
|
|
471
|
-
`,Cu=k.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=ue(),a=le(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return t&&(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(E.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(E.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(E.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(Mt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:BT})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(Mt.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(E.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(OT,{})]})})]})})}),
|
|
471
|
+
`,Cu=k.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=ue(),a=le(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return t&&(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(E.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(E.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(E.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(Mt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:BT})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(Mt.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(E.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(OT,{})]})})]})})}),Ki=k.observer(()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:"Query Variables",zIndex:320,size:"800px",children:i(Cu,{})}),i(s.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Su={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
|
|
472
472
|
`),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
|
|
473
|
-
`)},VT=k.observer(({queryModel:e})=>e.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(
|
|
473
|
+
`)},VT=k.observer(({queryModel:e})=>e.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ki,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(mn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Su.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(mn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Su.post})})]}):null),NT=k.observer(({queryID:e,usage:t})=>{const n=ue().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:t.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Xi=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{t==null||t(u??"")},l=!t;return i(Te,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},qT=({value:e,onChange:t,defaultValue:n})=>{const[r,a]=m.useState(e),o=()=>{t(r)},l=()=>{a(e)},u=()=>{a(n)};m.useEffect(()=>{a(e)},[e]);const c=r!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(s.Button,{onClick:u,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:l,color:"red",size:"xs",disabled:!c,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:o,disabled:!c,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(Xi,{height:"100%",value:r,onChange:a,theme:"sql-dark",defaultLanguage:"sql"})]})},FT=({value:e,height:t="200px",defaultLanguage:n="sql"})=>i(Te,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),GT=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=m.useMemo(()=>wr(e,n),[e,n]);return i(FT,{height:"100%",value:r})}),_u={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
474
474
|
`),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
|
|
475
|
-
`)},WT=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ui,{}),e.datasource&&i(xu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(qT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(GT,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(mn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:_u.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(mn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:_u.post})})]}):null),fr={height:"calc(100% - 44px)",padding:0},jT=k.observer(({queryModel:e})=>{const t=le(),n=m.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=m.useState(n);m.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(LT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:fr,children:i(s.Stack,{sx:{height:"100%"},children:i(WT,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:fr,children:i(s.Stack,{sx:{height:"100%"},children:i(VT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...fr,overflow:"hidden"},children:i(Yi,{id:e.id,moreActions:null,refreshOnMount:!0})}),i(s.Tabs.Panel,{value:"Usage",sx:{...fr,overflow:"hidden"},children:i(NT,{queryID:e.id,usage:o})})]})}),RT=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(jT,{queryModel:n}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),YT=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=m.useMemo(()=>wr(e,n),[e,n]);return i(Ki,{height:"100%",value:r})}),QT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=m.useState("SQL"),[o,l]=m.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=m.useState(e.value),g=()=>{e.setValue(f)};m.useEffect(()=>{l(e.key),h(e.value)},[e]);const y=f!==e.value,C=Fe.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(I.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Ui,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!y,sx:{position:"absolute",top:0,right:10},children:i(I.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Ki,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(YT,{value:f})})]})]})}),UT=k.observer(({id:e})=>{const t=ue(),n=le(),r=m.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(QT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),KT=k.observer(({view:e})=>!e||e.type!==j.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"})]})),XT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],JT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],ZT=k.observer(({view:e})=>{if(!e||e.type!==j.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:XT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:JT}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),HT=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},eD=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e??Li),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:y}=o,C={enabled:g,func_content:y};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(y=>({...y,func_content:g}))},h=()=>{f(Li.func_content)};return p(B,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(I.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(HT,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},tD=k.observer(({view:e})=>{if(!e||e.type!==j.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(eD,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),nD=k.observer(({view:e})=>p(B,{children:[i(KT,{view:e}),i(tD,{view:e}),i(ZT,{view:e})]})),rD=[{label:"Division",value:j.Division},{label:"Modal",value:j.Modal},{label:"Tabs",value:j.Tabs}],iD=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:rD}),i(nD,{view:e})]}):null),aD=k.observer(({id:e})=>{const t=Fe.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(iD,{view:a})})]})});function sD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function oD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function lD(e){return e.length===2&&e[0]==="_FILTERS_"}function uD(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function cD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function dD(e){return e.length===2&&e[0]==="_QUERIES_"}function pD(e){return e.length===1&&e[0]==="_QUERIES_"}function hD(e){return e.length===2&&e[0]==="_VIEWS_"}function fD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const gD=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(Cu,{})})),mD=k.observer(()=>{const e=Fe.useModals(),t=ue(),n=o=>{t.editor.setPath(["_QUERIES_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed queries?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},a=t.content.queriesUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedQueries,onClick:r,children:"Delete unused queries"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Name"}),i("th",{style:{width:"200px"},children:"Data Source"}),i("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.queries.sortedList.map(o=>{var u;const l=((u=a[o.id])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.name}),i("td",{children:o.key}),i("td",{style:{textAlign:"right"},children:o.type}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.id),children:"Open"})})]},o.id)})})]})})]})}),yD=k.observer(()=>{const e=Fe.useModals(),t=ue(),n=o=>{t.editor.setPath(["_SQL_SNIPPETS_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed SQL snippets?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},a=t.content.sqlSnippetsUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedSQLSnippets,onClick:r,children:"Delete unused SQL snippets"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.sqlSnippets.sortedList.map(o=>{var u;const l=((u=a[o.key])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.key}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.key),children:"Open"})})]},o.key)})})]})})]})}),bD=k.observer(()=>{const e=ue().editor,t=e.path;return sD(t)?i(gD,{}):oD(t)?i(Ek,{}):lD(t)?i(s.Box,{p:"xs",pl:20,children:i(zk,{id:t[1]})}):uD(t)?i(yD,{}):cD(t)?i(UT,{id:t[1]}):pD(t)?i(mD,{}):dD(t)?i(RT,{id:t[1]}):hD(t)?i(s.Box,{p:"xs",pl:20,children:i(aD,{id:t[1]})}):fD(t)?i(hT,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),vD=k.observer(()=>i(bD,{})),xD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:ve.TextInput,config:ml(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),wD=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===j.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),CD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Ne.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),SD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),_D=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),kD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),TD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),DD=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(xD,{}):e==="_Add_A_SQL_SNIPPET_"?i(SD,{}):e==="_Add_A_QUERY_"?i(CD,{}):e==="_Add_A_VIEW_"?i(_D,{}):e==="_Add_A_PANEL_"?i(wD,{parentID:t}):e==="_QUERIES_SETTINGS_"?i(kD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?i(TD,{}):null),ku=k.observer(({option:e})=>{var d;const t=ue().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=m.useState(l);return m.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(DD,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(ku,{option:f},f.value))},e.label)}),ID=k.observer(()=>{const e=ue();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(ku,{option:t},t.value))})}),MD=k.observer(()=>{const e=ue();return p(s.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},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(ID,{})}),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(E.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),AD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1000px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},zD=k.observer(()=>{const e=ue().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:i(s.AppShell,{padding:0,navbar:i(MD,{}),styles:AD,children:i(vD,{})})})}),ED=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function $D(e){m.useEffect(()=>{if(Te.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=ED(e);Te.loader.config({paths:{vs:n}}),Te.loader.init().then(r=>console.log("monaco instance:",r))},[])}wo();const LD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},PD=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{$D(o.monacoPath),Cr(o);const{data:d=[]}=Q.useRequest(Sr),{data:f=[]}=Q.useRequest(us),h=m.useMemo(()=>su(t,n,d,f,e),[t,n]);m.useImperativeHandle(c,()=>h,[h]),ou(h.content,!0),m.useEffect(()=>{h.context.replace(e)},[e]),m.useEffect(()=>{h.datasources.replace(d)},[d]),m.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),m.useEffect(()=>te.reaction(()=>te.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},y=Q.useCreation(zi,[]),C=lu(y);return i(Fe.ModalsProvider,{children:i(Mr,{value:{searchButtonProps:o.searchButtonProps},children:i(Tr,{value:h,children:i(Ar,{value:h.content,children:i(zn.Provider,{value:{inEditMode:!0},children:i(ct.Provider,{value:y,children:p(sr,{configure:C,children:[i(s.AppShell,{padding:0,header:i(W_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(mk,{}),styles:LD,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Kl,{view:w},w.id))})}),i(zD,{})]})})})})})})})},OD=k.observer(m.forwardRef(PD)),GM="",Tu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Ml,queries:Ll,sqlSnippets:Pl,views:kl,panels:Dl,mock_context:ll}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ur(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ur(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return ls(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function BD({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Tu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Al(u),queries:FS(f),sqlSnippets:WS(h),mock_context:ul(g),views:MS(c),panels:{list:d}})}const VD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Tu,content_id:b.types.string,datasources:TS,globalSQLSnippets:Sl,context:Pi});function ND({id:e,name:t,group:n,content_id:r},a,o,l,u){return VD.create({id:e,name:t,group:n,content_id:r,content:BD(a),datasources:{list:o},globalSQLSnippets:{list:l},context:_l(u)})}wo();const qD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Cr(a);const{data:u=[]}=Q.useRequest(Sr),{data:c=[]}=Q.useRequest(us),d=m.useMemo(()=>ND(t,n,u,c,e),[t,n]);ou(d.content,!1),m.useEffect(()=>{d.context.replace(e)},[e]),m.useEffect(()=>{d.datasources.replace(u)},[u]),m.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=Q.useCreation(zi,[]),h=lu(f);return i(Fe.ModalsProvider,{children:i(Mr,{value:{searchButtonProps:a.searchButtonProps},children:i(Tr,{value:d,children:i(Ar,{value:d.content,children:i(Er.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(zn.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ct.Provider,{value:f,children:i(sr,{configure:h,children:d.content.views.visibleViews.map(g=>i(dr,{view:g},g.id))})})})})})})})})})});var Xi={},FD={get exports(){return Xi},set exports(e){Xi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(FD);const GD=Xi;var Ji={},WD={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(WD);const jD=Ji;var Zi={},RD={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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),y=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,y.concat(["0"]))});return o.bind(this)(c)}}})})(RD);const YD=Zi;var Hi={},QD={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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",y=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[y]||l[y];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(QD);const UD=Hi;var ea={},KD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var D=_.match(/([+-]|\d\d)/g),M=60*D[1]+(+D[2]||0);return M===0?0:D[0]==="+"?-M:M}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var D,M=u.meridiem;if(M){for(var O=1;O<=24;O+=1)if(w.indexOf(M(O,0,_))>-1){D=O>12;break}}else D=w===(_?"pm":"PM");return D},y={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,D=w.match(/\d+/);if(this.day=D[0],_)for(var M=1;M<=31;M+=1)_(M).replace(/\[|\]/g,"")===w&&(this.day=M)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),D=(h("monthsShort")||_.map(function(M){return M.slice(0,3)})).indexOf(w)+1;if(D<1)throw new Error;this.month=D%12||D}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,D;_=w,D=u&&u.formats;for(var M=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,Y,H){var se=H&&H.toUpperCase();return Y||D[H]||n[H]||D[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(de,xe,Le){return xe||Le.slice(1)})})).match(r),O=M.length,G=0;G<O;G+=1){var $=M[G],L=y[$],A=L&&L[0],N=L&&L[1];M[G]=N?{regex:A,parser:N}:$.replace(/^\[|\]$/g,"")}return function(K){for(var Y={},H=0,se=0;H<O;H+=1){var de=M[H];if(typeof de=="string")se+=de.length;else{var xe=de.regex,Le=de.parser,bt=K.slice(se),Ye=xe.exec(bt)[0];Le.call(Y,Ye),K=K.replace(Ye,"")}}return function(dt){var qe=dt.afternoon;if(qe!==void 0){var vt=dt.hours;qe?vt<12&&(dt.hours+=12):vt===12&&(dt.hours=0),delete dt.afternoon}}(Y),Y}}return function(w,_,D){D.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var M=_.prototype,O=M.parse;M.parse=function(G){var $=G.date,L=G.utc,A=G.args;this.$u=L;var N=A[1];if(typeof N=="string"){var K=A[2]===!0,Y=A[3]===!0,H=K||Y,se=A[2];Y&&(se=A[2]),u=this.$locale(),!K&&se&&(u=D.Ls[se]),this.$d=function(bt,Ye,dt){try{if(["x","X"].indexOf(Ye)>-1)return new Date((Ye==="X"?1e3:1)*bt);var qe=C(Ye)(bt),vt=qe.year,Bt=qe.month,gr=qe.day,mr=qe.hours,Ma=qe.minutes,Aa=qe.seconds,wn=qe.milliseconds,Xt=qe.zone,kt=new Date,Vt=gr||(vt||Bt?1:kt.getDate()),Tt=vt||kt.getFullYear(),Jt=0;vt&&!Bt||(Jt=Bt>0?Bt-1:kt.getMonth());var Zt=mr||0,Cn=Ma||0,Sn=Aa||0,Dt=wn||0;return Xt?new Date(Date.UTC(Tt,Jt,Vt,Zt,Cn,Sn,Dt+60*Xt.offset*1e3)):dt?new Date(Date.UTC(Tt,Jt,Vt,Zt,Cn,Sn,Dt)):new Date(Tt,Jt,Vt,Zt,Cn,Sn,Dt)}catch{return new Date("")}}($,N,L),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),H&&$!=this.format(N)&&(this.$d=new Date("")),u={}}else if(N instanceof Array)for(var de=N.length,xe=1;xe<=de;xe+=1){A[1]=N[xe-1];var Le=D.apply(this,A);if(Le.isValid()){this.$d=Le.$d,this.$L=Le.$L,this.init();break}xe===de&&(this.$d=new Date(""))}else O.call(this,G)}}})})(KD);const XD=ea;var ta={},JD={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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")}}})})(JD);const ZD=ta;var na={},HD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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},y=function($){return $ instanceof G},C=function($,L,A){return new G($,A,L.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},D=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},O=function($,L){return $?_($)?{negative:!0,format:""+M($)+L}:{negative:!1,format:""+$+L}:{negative:!1,format:""}},G=function(){function $(A,N,K){var Y=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return C(A*g[w(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(de){Y.$d[w(de)]=A[de]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var se=H.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var L=$.prototype;return L.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,K){return N+(A.$d[K]||0)*g[K]},0)},L.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=D(A/d),A%=d,this.$d.months=D(A/f),A%=f,this.$d.days=D(A/u),A%=u,this.$d.hours=D(A/l),A%=l,this.$d.minutes=D(A/o),A%=o,this.$d.seconds=D(A/a),A%=a,this.$d.milliseconds=A},L.toISOString=function(){var A=O(this.$d.years,"Y"),N=O(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var Y=O(K,"D"),H=O(this.$d.hours,"H"),se=O(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var xe=O(de,"S"),Le=A.negative||N.negative||Y.negative||H.negative||se.negative||xe.negative,bt=H.format||se.format||xe.format?"T":"",Ye=(Le?"-":"")+"P"+A.format+N.format+Y.format+bt+H.format+se.format+xe.format;return Ye==="P"||Ye==="-P"?"P0D":Ye},L.toJSON=function(){return this.toISOString()},L.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",K={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 N.replace(c,function(Y,H){return H||String(K[Y])})},L.as=function(A){return this.$ms/g[w(A)]},L.get=function(A){var N=this.$ms,K=w(A);return K==="milliseconds"?N%=1e3:N=K==="weeks"?D(N/g[K]):this.$d[K],N===0?0:N},L.add=function(A,N,K){var Y;return Y=N?A*g[w(N)]:y(A)?A.$ms:C(A,this).$ms,C(this.$ms+Y*(K?-1:1),this)},L.subtract=function(A,N){return this.add(A,N,!0)},L.locale=function(A){var N=this.clone();return N.$l=A,N},L.clone=function(){return C(this.$ms,this)},L.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},L.milliseconds=function(){return this.get("milliseconds")},L.asMilliseconds=function(){return this.as("milliseconds")},L.seconds=function(){return this.get("seconds")},L.asSeconds=function(){return this.as("seconds")},L.minutes=function(){return this.get("minutes")},L.asMinutes=function(){return this.as("minutes")},L.hours=function(){return this.get("hours")},L.asHours=function(){return this.as("hours")},L.days=function(){return this.get("days")},L.asDays=function(){return this.as("days")},L.weeks=function(){return this.get("weeks")},L.asWeeks=function(){return this.as("weeks")},L.months=function(){return this.get("months")},L.asMonths=function(){return this.as("months")},L.years=function(){return this.get("years")},L.asYears=function(){return this.as("years")},$}();return function($,L,A){n=A,r=A().$utils(),A.duration=function(Y,H){var se=A.locale();return C(Y,{$l:se},H)},A.isDuration=y;var N=L.prototype.add,K=L.prototype.subtract;L.prototype.add=function(Y,H){return y(Y)&&(Y=Y.asMilliseconds()),N.bind(this)(Y,H)},L.prototype.subtract=function(Y,H){return y(Y)&&(Y=Y.asMilliseconds()),K.bind(this)(Y,H)}}})})(HD);const eI=na;var ra={},tI={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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))}}})})(tI);const nI=ra;var ia={},rI={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(rI);const iI=ia;var aa={},aI={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(aI);const sI=aa;var sa={},oI={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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,y,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),y=4-g.isoWeekday(),g.isoWeekday()>4&&(y+=7),g.add(y,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(oI);const lI=sa;var oa={},uI={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}})})(uI);const cI=oa;var la={},dI={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(dI);const pI=la;var ua={},hI={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(hI);const fI=ua;var ca={},gI={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(gI);const mI=ca;var da={},yI={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(yI);const bI=da;var pa={},vI={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(vI);const xI=pa;var ha={},wI={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,y,C,w){var _=h.name?h:h.$locale(),D=l(_[g]),M=l(_[y]),O=D||M.map(function($){return $.slice(0,C)});if(!w)return O;var G=_.weekStart;return O.map(function($,L){return O[(L+(G||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(y){return y.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(wI);const CI=ha;var fa={},SI={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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(y,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(D,M,O){return M||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(SI);const _I=fa;var ga={},kI={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(kI);const TI=ga;var ma={},DI={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(g){var y,C=g.date,w=g.utc,_={};if(!((y=C)instanceof Date||y instanceof Array||o.$utils().u(y)||y.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var D=w?a.utc():a();Object.keys(C).forEach(function(K){var Y,H;_[Y=K,H=o.$utils().p(Y),H==="date"?"day":H]=C[K]});var M=_.day||(_.year||_.month>=0?1:D.date()),O=_.year||D.year(),G=_.month>=0?_.month:_.year||_.day?0:D.month(),$=_.hour||0,L=_.minute||0,A=_.second||0,N=_.millisecond||0;return w?new Date(Date.UTC(O,G,M,$,L,A,N)):new Date(O,G,M,$,L,A,N)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,y,C,w){w===void 0&&(w=1);var _=Object.keys(y),D=this;return _.forEach(function(M){D=g.bind(D)(y[M]*w,M)}),D};o.set=function(g,y){return y=y===void 0?g:y,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},y,g):c.bind(this)(g,y)},o.add=function(g,y){return g.constructor.name==="Object"?h.bind(this)(d,g,y):d.bind(this)(g,y)},o.subtract=function(g,y){return g.constructor.name==="Object"?h.bind(this)(d,g,y,-1):f.bind(this)(g,y)}}})})(DI);const II=ma;var ya={},MI={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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$/,"")]})}})})(MI);const AI=ya;var ba={},zI={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)})}})})(zI);const EI=ba;var va={},$I={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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 y=this.quarter()-1;return g?this.month(3*y).startOf(n).startOf("day"):this.month(3*y+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})($I);const LI=va;var xa={},PI={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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,y){for(var C,w,_,D=h.$locale().relativeTime||l,M=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=M.length,G=0;G<O;G+=1){var $=M[G];$.d&&(C=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var L=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,L<=$.r||!$.r){L<=1&&G>0&&($=M[G-1]);var A=D[$.l];y&&(L=y(""+L)),w=typeof A=="string"?A.replace("%d",L):A(L,f,$.l,_);break}}if(f)return w;var N=_?D.future:D.past;return typeof N=="function"?N(w):N.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(PI);const OI=xa;var wa={},BI={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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,y,C){C===void 0&&(C={});var w=new Date(g),_=function(D,M){M===void 0&&(M={});var O=M.timeZoneName||"short",G=D+"|"+O,$=r[G];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[G]=$),$}(y,C);return _.formatToParts(w)},d=function(g,y){for(var C=c(g,y),w=[],_=0;_<C.length;_+=1){var D=C[_],M=D.type,O=D.value,G=n[M];G>=0&&(w[G]=parseInt(O,10))}var $=w[3],L=$===24?0:$,A=w[0]+"-"+w[1]+"-"+w[2]+" "+L+":"+w[4]+":"+w[5]+":000",N=+g;return(l.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(g,y){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),D=Math.round((w-new Date(_))/1e3/60),M=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-D,!0);if(y){var O=M.utcOffset();M=M.add(C-O,"minute")}return M.$x.$timezone=g,M},f.offsetName=function(g){var y=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),y,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,y){if(!this.$x||!this.$x.$timezone)return h.call(this,g,y);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,y).tz(this.$x.$timezone,!0)},l.tz=function(g,y,C){var w=C&&y,_=C||y||u,D=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var M=function(L,A,N){var K=L-60*A*1e3,Y=d(K,N);if(A===Y)return[K,A];var H=d(K-=60*(Y-A)*1e3,N);return Y===H?[K,Y]:[L-60*Math.min(Y,H)*1e3,Math.max(Y,H)]}(l.utc(g,w).valueOf(),D,_),O=M[0],G=M[1],$=l(O).utcOffset(G);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(BI);const VI=wa;var Ca={},NI={get exports(){return Ca},set exports(e){Ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(NI);const qI=Ca;var Sa={},FI={get exports(){return Sa},set exports(e){Sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}}})})(FI);const GI=Sa;var _a={},WI={get exports(){return _a},set exports(e){_a=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}})})(WI);const jI=_a;var ka={},RI={get exports(){return ka},set exports(e){ka=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var D=this.$utils().u;if(D(w))return this.$u?0:D(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function($){$===void 0&&($="");var L=$.match(r);if(!L)return null;var A=(""+L[0]).match(a)||["-",0,0],N=A[0],K=60*+A[1]+ +A[2];return K===0?0:N==="+"?K:-K}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,O=this;if(_)return O.$offset=M,O.$u=w===0,O;if(w!==0){var G=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(M+G,n)).$offset=M,O.$x.$localOffset=G}else O=this.utc();return O};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var y=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():y.call(this)};var C=c.diff;c.diff=function(w,_,D){if(w&&this.$u===w.$u)return C.call(this,w,_,D);var M=this.local(),O=u(w).local();return C.call(M,O,_,D)}}})})(RI);const YI=ka;var Ta={},QI={get exports(){return Ta},set exports(e){Ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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")}}})})(QI);const UI=Ta;var Da={},KI={get exports(){return Da},set exports(e){Da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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"),y=this.diff(g,n,!0);return y<0?l(this).startOf("week").week():Math.ceil(y)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(KI);const XI=Da;var Ia={},JI={get exports(){return Ia},set exports(e){Ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}})})(JI);const ZI=Ia;U.extend(GD),U.extend(jD),U.extend(YD),U.extend(UD),U.extend(XD),U.extend(ZD),U.extend(eI),U.extend(nI),U.extend(iI),U.extend(sI),U.extend(pI),U.extend(fI),U.extend(mI),U.extend(bI),U.extend(xI),U.extend(lI),U.extend(cI),U.extend(CI),U.extend(_I),U.extend(TI),U.extend(II),U.extend(AI),U.extend(EI),U.extend(LI),U.extend(OI),U.extend(VI),U.extend(qI),U.extend(GI),U.extend(jI),U.extend(YI),U.extend(XI),U.extend(ZI),U.extend(UI),U.tz.setDefault("UTC");const HI=()=>Promise.resolve().then(()=>Cc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));T.APIClient=at,T.ContentModel=Fi,T.ContentModelContextProvider=Ar,T.DashboardApiClient=is,T.DashboardApiFacadeClient=as,T.DashboardEditor=OD,T.DashboardFilterType=ve,T.DashboardMode=Xl,T.DashboardModel=au,T.DashboardModelContextProvider=Tr,T.DashboardThemeContextProvider=Mr,T.DashboardViewEditor=Kl,T.DashboardViewRender=dr,T.DefaultApiClient=rs,T.DescriptionPopover=Oi,T.FacadeApiClient=lc,T.FiltersModel=Zl,T.FullScreenPanel=jl,T.FullScreenPanelContext=Er,T.LayoutStateContext=zn,T.Panel=Wl,T.PanelContextProvider=zr,T.PanelErrorOrStateMessage=Fl,T.PanelModel=tu,T.PanelRender=Vi,T.PanelVizSection=Bi,T.PanelsModel=nu,T.QueriesModel=Hl,T.ReadOnlyDashboard=qD,T.SQLSnippetsModel=eu,T.ViewComponentTypeBackground=Jl,T.ViewComponentTypeColor=k_,T.ViewComponentTypeName=__,T.ViewsModel=ru,T.Viz=ql,T.applyPartialDashboard=B_,T.configureAPIClient=Cr,T.createContentModel=iu,T.createDashboardModel=su,T.facadeApiClient=ss,T.getInitialDashboardViewsModel=qi,T.getVersion=HI,T.initialDashboardContent=T_,T.useDashboardContext=Dr,T.useDashboardThemeContext=ms,T.useEditContentModelContext=le,T.useEditDashboardContext=ue,T.useEditPanelContext=Qe,T.useFullScreenPanelContext=ws,T.usePanelFullScreen=Rl,T.useRenderContentModelContext=ye,T.useRenderDashboardContext=Ir,T.useRenderPanelContext=Ct,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
|
475
|
+
`)},WT=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ki,{}),e.datasource&&i(xu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(qT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(GT,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(mn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:_u.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(mn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:_u.post})})]}):null),fr={height:"calc(100% - 44px)",padding:0},jT=k.observer(({queryModel:e})=>{const t=le(),n=m.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=m.useState(n);m.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(LT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:fr,children:i(s.Stack,{sx:{height:"100%"},children:i(WT,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:fr,children:i(s.Stack,{sx:{height:"100%"},children:i(VT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...fr,overflow:"hidden"},children:i(Qi,{id:e.id,moreActions:null,refreshOnMount:!0})}),i(s.Tabs.Panel,{value:"Usage",sx:{...fr,overflow:"hidden"},children:i(NT,{queryID:e.id,usage:o})})]})}),RT=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(jT,{queryModel:n}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),YT=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=m.useMemo(()=>wr(e,n),[e,n]);return i(Xi,{height:"100%",value:r})}),QT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=m.useState("SQL"),[o,l]=m.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=m.useState(e.value),g=()=>{e.setValue(f)};m.useEffect(()=>{l(e.key),h(e.value)},[e]);const y=f!==e.value,C=Fe.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(I.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Ki,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!y,sx:{position:"absolute",top:0,right:10},children:i(I.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Xi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(YT,{value:f})})]})]})}),UT=k.observer(({id:e})=>{const t=ue(),n=le(),r=m.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(QT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),KT=k.observer(({view:e})=>!e||e.type!==j.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"})]})),XT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],JT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],ZT=k.observer(({view:e})=>{if(!e||e.type!==j.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:XT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:JT}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),HT=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},eD=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e??Pi),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:y}=o,C={enabled:g,func_content:y};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(y=>({...y,func_content:g}))},h=()=>{f(Pi.func_content)};return p(B,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(I.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(HT,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},tD=k.observer(({view:e})=>{if(!e||e.type!==j.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(eD,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),nD=k.observer(({view:e})=>p(B,{children:[i(KT,{view:e}),i(tD,{view:e}),i(ZT,{view:e})]})),rD=[{label:"Division",value:j.Division},{label:"Modal",value:j.Modal},{label:"Tabs",value:j.Tabs}],iD=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:rD}),i(nD,{view:e})]}):null),aD=k.observer(({id:e})=>{const t=Fe.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(iD,{view:a})})]})});function sD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function oD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function lD(e){return e.length===2&&e[0]==="_FILTERS_"}function uD(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function cD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function dD(e){return e.length===2&&e[0]==="_QUERIES_"}function pD(e){return e.length===1&&e[0]==="_QUERIES_"}function hD(e){return e.length===2&&e[0]==="_VIEWS_"}function fD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const gD=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(Cu,{})})),mD=k.observer(()=>{const e=Fe.useModals(),t=ue(),n=o=>{t.editor.setPath(["_QUERIES_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed queries?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},a=t.content.queriesUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedQueries,onClick:r,children:"Delete unused queries"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Name"}),i("th",{style:{width:"200px"},children:"Data Source"}),i("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.queries.sortedList.map(o=>{var u;const l=((u=a[o.id])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.name}),i("td",{children:o.key}),i("td",{style:{textAlign:"right"},children:o.type}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.id),children:"Open"})})]},o.id)})})]})})]})}),yD=k.observer(()=>{const e=Fe.useModals(),t=ue(),n=o=>{t.editor.setPath(["_SQL_SNIPPETS_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed SQL snippets?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},a=t.content.sqlSnippetsUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedSQLSnippets,onClick:r,children:"Delete unused SQL snippets"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.sqlSnippets.sortedList.map(o=>{var u;const l=((u=a[o.key])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.key}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.key),children:"Open"})})]},o.key)})})]})})]})}),bD=k.observer(()=>{const e=ue().editor,t=e.path;return sD(t)?i(gD,{}):oD(t)?i(Ek,{}):lD(t)?i(s.Box,{p:"xs",pl:20,children:i(zk,{id:t[1]})}):uD(t)?i(yD,{}):cD(t)?i(UT,{id:t[1]}):pD(t)?i(mD,{}):dD(t)?i(RT,{id:t[1]}):hD(t)?i(s.Box,{p:"xs",pl:20,children:i(aD,{id:t[1]})}):fD(t)?i(hT,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),vD=k.observer(()=>i(bD,{})),xD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:ve.TextInput,config:ml(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),wD=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===j.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),CD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Ne.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),SD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),_D=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),kD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),TD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),DD=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(xD,{}):e==="_Add_A_SQL_SNIPPET_"?i(SD,{}):e==="_Add_A_QUERY_"?i(CD,{}):e==="_Add_A_VIEW_"?i(_D,{}):e==="_Add_A_PANEL_"?i(wD,{parentID:t}):e==="_QUERIES_SETTINGS_"?i(kD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?i(TD,{}):null),ku=k.observer(({option:e})=>{var d;const t=ue().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=m.useState(l);return m.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(DD,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(ku,{option:f},f.value))},e.label)}),ID=k.observer(()=>{const e=ue();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(ku,{option:t},t.value))})}),MD=k.observer(()=>{const e=ue();return p(s.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},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(ID,{})}),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(E.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),AD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1000px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},zD=k.observer(()=>{const e=ue().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:i(s.AppShell,{padding:0,navbar:i(MD,{}),styles:AD,children:i(vD,{})})})}),ED=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function $D(e){m.useEffect(()=>{if(Te.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=ED(e);Te.loader.config({paths:{vs:n}}),Te.loader.init().then(r=>console.log("monaco instance:",r))},[])}wo();const LD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},PD=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{$D(o.monacoPath),Cr(o);const{data:d=[]}=Q.useRequest(_r),{data:f=[]}=Q.useRequest(us),h=m.useMemo(()=>su(t,n,d,f,e),[t,n]);m.useImperativeHandle(c,()=>h,[h]),ou(h.content,!0),m.useEffect(()=>{h.context.replace(e)},[e]),m.useEffect(()=>{h.datasources.replace(d)},[d]),m.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),m.useEffect(()=>te.reaction(()=>te.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},y=Q.useCreation(Ei,[]),C=lu(y);return i(Fe.ModalsProvider,{children:i(Ar,{value:{searchButtonProps:o.searchButtonProps},children:i(Dr,{value:h,children:i(zr,{value:h.content,children:i(zn.Provider,{value:{inEditMode:!0},children:i(ct.Provider,{value:y,children:p(sr,{configure:C,children:[i(s.AppShell,{padding:0,header:i(W_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(mk,{}),styles:LD,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Kl,{view:w},w.id))})}),i(zD,{})]})})})})})})})},OD=k.observer(m.forwardRef(PD)),GM="",Tu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Ml,queries:Ll,sqlSnippets:Pl,views:kl,panels:Dl,mock_context:ll}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ur(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ur(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return Sr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function BD({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Tu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Al(u),queries:FS(f),sqlSnippets:WS(h),mock_context:ul(g),views:MS(c),panels:{list:d}})}const VD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Tu,content_id:b.types.string,datasources:TS,globalSQLSnippets:Sl,context:Oi});function ND({id:e,name:t,group:n,content_id:r},a,o,l,u){return VD.create({id:e,name:t,group:n,content_id:r,content:BD(a),datasources:{list:o},globalSQLSnippets:{list:l},context:_l(u)})}wo();const qD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Cr(a);const{data:u=[]}=Q.useRequest(_r),{data:c=[]}=Q.useRequest(us),d=m.useMemo(()=>ND(t,n,u,c,e),[t,n]);ou(d.content,!1),m.useEffect(()=>{d.context.replace(e)},[e]),m.useEffect(()=>{d.datasources.replace(u)},[u]),m.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=Q.useCreation(Ei,[]),h=lu(f);return i(Fe.ModalsProvider,{children:i(Ar,{value:{searchButtonProps:a.searchButtonProps},children:i(Dr,{value:d,children:i(zr,{value:d.content,children:i($r.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(zn.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ct.Provider,{value:f,children:i(sr,{configure:h,children:d.content.views.visibleViews.map(g=>i(dr,{view:g},g.id))})})})})})})})})})});var Ji={},FD={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(FD);const GD=Ji;var Zi={},WD={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(WD);const jD=Zi;var Hi={},RD={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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),y=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,y.concat(["0"]))});return o.bind(this)(c)}}})})(RD);const YD=Hi;var ea={},QD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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",y=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[y]||l[y];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(QD);const UD=ea;var ta={},KD={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var D=_.match(/([+-]|\d\d)/g),M=60*D[1]+(+D[2]||0);return M===0?0:D[0]==="+"?-M:M}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var D,M=u.meridiem;if(M){for(var O=1;O<=24;O+=1)if(w.indexOf(M(O,0,_))>-1){D=O>12;break}}else D=w===(_?"pm":"PM");return D},y={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,D=w.match(/\d+/);if(this.day=D[0],_)for(var M=1;M<=31;M+=1)_(M).replace(/\[|\]/g,"")===w&&(this.day=M)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),D=(h("monthsShort")||_.map(function(M){return M.slice(0,3)})).indexOf(w)+1;if(D<1)throw new Error;this.month=D%12||D}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,D;_=w,D=u&&u.formats;for(var M=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,Y,H){var se=H&&H.toUpperCase();return Y||D[H]||n[H]||D[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(de,xe,Le){return xe||Le.slice(1)})})).match(r),O=M.length,G=0;G<O;G+=1){var $=M[G],L=y[$],A=L&&L[0],N=L&&L[1];M[G]=N?{regex:A,parser:N}:$.replace(/^\[|\]$/g,"")}return function(K){for(var Y={},H=0,se=0;H<O;H+=1){var de=M[H];if(typeof de=="string")se+=de.length;else{var xe=de.regex,Le=de.parser,bt=K.slice(se),Ye=xe.exec(bt)[0];Le.call(Y,Ye),K=K.replace(Ye,"")}}return function(dt){var qe=dt.afternoon;if(qe!==void 0){var vt=dt.hours;qe?vt<12&&(dt.hours+=12):vt===12&&(dt.hours=0),delete dt.afternoon}}(Y),Y}}return function(w,_,D){D.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var M=_.prototype,O=M.parse;M.parse=function(G){var $=G.date,L=G.utc,A=G.args;this.$u=L;var N=A[1];if(typeof N=="string"){var K=A[2]===!0,Y=A[3]===!0,H=K||Y,se=A[2];Y&&(se=A[2]),u=this.$locale(),!K&&se&&(u=D.Ls[se]),this.$d=function(bt,Ye,dt){try{if(["x","X"].indexOf(Ye)>-1)return new Date((Ye==="X"?1e3:1)*bt);var qe=C(Ye)(bt),vt=qe.year,Bt=qe.month,gr=qe.day,mr=qe.hours,Aa=qe.minutes,za=qe.seconds,wn=qe.milliseconds,Xt=qe.zone,kt=new Date,Vt=gr||(vt||Bt?1:kt.getDate()),Tt=vt||kt.getFullYear(),Jt=0;vt&&!Bt||(Jt=Bt>0?Bt-1:kt.getMonth());var Zt=mr||0,Cn=Aa||0,Sn=za||0,Dt=wn||0;return Xt?new Date(Date.UTC(Tt,Jt,Vt,Zt,Cn,Sn,Dt+60*Xt.offset*1e3)):dt?new Date(Date.UTC(Tt,Jt,Vt,Zt,Cn,Sn,Dt)):new Date(Tt,Jt,Vt,Zt,Cn,Sn,Dt)}catch{return new Date("")}}($,N,L),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),H&&$!=this.format(N)&&(this.$d=new Date("")),u={}}else if(N instanceof Array)for(var de=N.length,xe=1;xe<=de;xe+=1){A[1]=N[xe-1];var Le=D.apply(this,A);if(Le.isValid()){this.$d=Le.$d,this.$L=Le.$L,this.init();break}xe===de&&(this.$d=new Date(""))}else O.call(this,G)}}})})(KD);const XD=ta;var na={},JD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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")}}})})(JD);const ZD=na;var ra={},HD={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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},y=function($){return $ instanceof G},C=function($,L,A){return new G($,A,L.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},D=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},O=function($,L){return $?_($)?{negative:!0,format:""+M($)+L}:{negative:!1,format:""+$+L}:{negative:!1,format:""}},G=function(){function $(A,N,K){var Y=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return C(A*g[w(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(de){Y.$d[w(de)]=A[de]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var se=H.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var L=$.prototype;return L.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,K){return N+(A.$d[K]||0)*g[K]},0)},L.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=D(A/d),A%=d,this.$d.months=D(A/f),A%=f,this.$d.days=D(A/u),A%=u,this.$d.hours=D(A/l),A%=l,this.$d.minutes=D(A/o),A%=o,this.$d.seconds=D(A/a),A%=a,this.$d.milliseconds=A},L.toISOString=function(){var A=O(this.$d.years,"Y"),N=O(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var Y=O(K,"D"),H=O(this.$d.hours,"H"),se=O(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var xe=O(de,"S"),Le=A.negative||N.negative||Y.negative||H.negative||se.negative||xe.negative,bt=H.format||se.format||xe.format?"T":"",Ye=(Le?"-":"")+"P"+A.format+N.format+Y.format+bt+H.format+se.format+xe.format;return Ye==="P"||Ye==="-P"?"P0D":Ye},L.toJSON=function(){return this.toISOString()},L.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",K={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 N.replace(c,function(Y,H){return H||String(K[Y])})},L.as=function(A){return this.$ms/g[w(A)]},L.get=function(A){var N=this.$ms,K=w(A);return K==="milliseconds"?N%=1e3:N=K==="weeks"?D(N/g[K]):this.$d[K],N===0?0:N},L.add=function(A,N,K){var Y;return Y=N?A*g[w(N)]:y(A)?A.$ms:C(A,this).$ms,C(this.$ms+Y*(K?-1:1),this)},L.subtract=function(A,N){return this.add(A,N,!0)},L.locale=function(A){var N=this.clone();return N.$l=A,N},L.clone=function(){return C(this.$ms,this)},L.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},L.milliseconds=function(){return this.get("milliseconds")},L.asMilliseconds=function(){return this.as("milliseconds")},L.seconds=function(){return this.get("seconds")},L.asSeconds=function(){return this.as("seconds")},L.minutes=function(){return this.get("minutes")},L.asMinutes=function(){return this.as("minutes")},L.hours=function(){return this.get("hours")},L.asHours=function(){return this.as("hours")},L.days=function(){return this.get("days")},L.asDays=function(){return this.as("days")},L.weeks=function(){return this.get("weeks")},L.asWeeks=function(){return this.as("weeks")},L.months=function(){return this.get("months")},L.asMonths=function(){return this.as("months")},L.years=function(){return this.get("years")},L.asYears=function(){return this.as("years")},$}();return function($,L,A){n=A,r=A().$utils(),A.duration=function(Y,H){var se=A.locale();return C(Y,{$l:se},H)},A.isDuration=y;var N=L.prototype.add,K=L.prototype.subtract;L.prototype.add=function(Y,H){return y(Y)&&(Y=Y.asMilliseconds()),N.bind(this)(Y,H)},L.prototype.subtract=function(Y,H){return y(Y)&&(Y=Y.asMilliseconds()),K.bind(this)(Y,H)}}})})(HD);const eI=ra;var ia={},tI={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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))}}})})(tI);const nI=ia;var aa={},rI={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(rI);const iI=aa;var sa={},aI={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(aI);const sI=sa;var oa={},oI={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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,y,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),y=4-g.isoWeekday(),g.isoWeekday()>4&&(y+=7),g.add(y,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(oI);const lI=oa;var la={},uI={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}})})(uI);const cI=la;var ua={},dI={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(dI);const pI=ua;var ca={},hI={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(hI);const fI=ca;var da={},gI={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(gI);const mI=da;var pa={},yI={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(yI);const bI=pa;var ha={},vI={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(vI);const xI=ha;var fa={},wI={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,y,C,w){var _=h.name?h:h.$locale(),D=l(_[g]),M=l(_[y]),O=D||M.map(function($){return $.slice(0,C)});if(!w)return O;var G=_.weekStart;return O.map(function($,L){return O[(L+(G||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(y){return y.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(wI);const CI=fa;var ga={},SI={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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(y,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(D,M,O){return M||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(SI);const _I=ga;var ma={},kI={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)}}})})(kI);const TI=ma;var ya={},DI={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(g){var y,C=g.date,w=g.utc,_={};if(!((y=C)instanceof Date||y instanceof Array||o.$utils().u(y)||y.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var D=w?a.utc():a();Object.keys(C).forEach(function(K){var Y,H;_[Y=K,H=o.$utils().p(Y),H==="date"?"day":H]=C[K]});var M=_.day||(_.year||_.month>=0?1:D.date()),O=_.year||D.year(),G=_.month>=0?_.month:_.year||_.day?0:D.month(),$=_.hour||0,L=_.minute||0,A=_.second||0,N=_.millisecond||0;return w?new Date(Date.UTC(O,G,M,$,L,A,N)):new Date(O,G,M,$,L,A,N)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,y,C,w){w===void 0&&(w=1);var _=Object.keys(y),D=this;return _.forEach(function(M){D=g.bind(D)(y[M]*w,M)}),D};o.set=function(g,y){return y=y===void 0?g:y,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},y,g):c.bind(this)(g,y)},o.add=function(g,y){return g.constructor.name==="Object"?h.bind(this)(d,g,y):d.bind(this)(g,y)},o.subtract=function(g,y){return g.constructor.name==="Object"?h.bind(this)(d,g,y,-1):f.bind(this)(g,y)}}})})(DI);const II=ya;var ba={},MI={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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$/,"")]})}})})(MI);const AI=ba;var va={},zI={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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)})}})})(zI);const EI=va;var xa={},$I={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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 y=this.quarter()-1;return g?this.month(3*y).startOf(n).startOf("day"):this.month(3*y+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})($I);const LI=xa;var wa={},PI={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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,y){for(var C,w,_,D=h.$locale().relativeTime||l,M=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=M.length,G=0;G<O;G+=1){var $=M[G];$.d&&(C=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var L=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,L<=$.r||!$.r){L<=1&&G>0&&($=M[G-1]);var A=D[$.l];y&&(L=y(""+L)),w=typeof A=="string"?A.replace("%d",L):A(L,f,$.l,_);break}}if(f)return w;var N=_?D.future:D.past;return typeof N=="function"?N(w):N.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(PI);const OI=wa;var Ca={},BI={get exports(){return Ca},set exports(e){Ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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,y,C){C===void 0&&(C={});var w=new Date(g),_=function(D,M){M===void 0&&(M={});var O=M.timeZoneName||"short",G=D+"|"+O,$=r[G];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[G]=$),$}(y,C);return _.formatToParts(w)},d=function(g,y){for(var C=c(g,y),w=[],_=0;_<C.length;_+=1){var D=C[_],M=D.type,O=D.value,G=n[M];G>=0&&(w[G]=parseInt(O,10))}var $=w[3],L=$===24?0:$,A=w[0]+"-"+w[1]+"-"+w[2]+" "+L+":"+w[4]+":"+w[5]+":000",N=+g;return(l.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(g,y){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),D=Math.round((w-new Date(_))/1e3/60),M=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-D,!0);if(y){var O=M.utcOffset();M=M.add(C-O,"minute")}return M.$x.$timezone=g,M},f.offsetName=function(g){var y=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),y,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,y){if(!this.$x||!this.$x.$timezone)return h.call(this,g,y);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,y).tz(this.$x.$timezone,!0)},l.tz=function(g,y,C){var w=C&&y,_=C||y||u,D=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var M=function(L,A,N){var K=L-60*A*1e3,Y=d(K,N);if(A===Y)return[K,A];var H=d(K-=60*(Y-A)*1e3,N);return Y===H?[K,Y]:[L-60*Math.min(Y,H)*1e3,Math.max(Y,H)]}(l.utc(g,w).valueOf(),D,_),O=M[0],G=M[1],$=l(O).utcOffset(G);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(BI);const VI=Ca;var Sa={},NI={get exports(){return Sa},set exports(e){Sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(NI);const qI=Sa;var _a={},FI={get exports(){return _a},set exports(e){_a=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}}})})(FI);const GI=_a;var ka={},WI={get exports(){return ka},set exports(e){ka=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}})})(WI);const jI=ka;var Ta={},RI={get exports(){return Ta},set exports(e){Ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var D=this.$utils().u;if(D(w))return this.$u?0:D(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function($){$===void 0&&($="");var L=$.match(r);if(!L)return null;var A=(""+L[0]).match(a)||["-",0,0],N=A[0],K=60*+A[1]+ +A[2];return K===0?0:N==="+"?K:-K}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,O=this;if(_)return O.$offset=M,O.$u=w===0,O;if(w!==0){var G=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(M+G,n)).$offset=M,O.$x.$localOffset=G}else O=this.utc();return O};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var y=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():y.call(this)};var C=c.diff;c.diff=function(w,_,D){if(w&&this.$u===w.$u)return C.call(this,w,_,D);var M=this.local(),O=u(w).local();return C.call(M,O,_,D)}}})})(RI);const YI=Ta;var Da={},QI={get exports(){return Da},set exports(e){Da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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")}}})})(QI);const UI=Da;var Ia={},KI={get exports(){return Ia},set exports(e){Ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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"),y=this.diff(g,n,!0);return y<0?l(this).startOf("week").week():Math.ceil(y)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(KI);const XI=Ia;var Ma={},JI={get exports(){return Ma},set exports(e){Ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,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}}})})(JI);const ZI=Ma;U.extend(GD),U.extend(jD),U.extend(YD),U.extend(UD),U.extend(XD),U.extend(ZD),U.extend(eI),U.extend(nI),U.extend(iI),U.extend(sI),U.extend(pI),U.extend(fI),U.extend(mI),U.extend(bI),U.extend(xI),U.extend(lI),U.extend(cI),U.extend(CI),U.extend(_I),U.extend(TI),U.extend(II),U.extend(AI),U.extend(EI),U.extend(LI),U.extend(OI),U.extend(VI),U.extend(qI),U.extend(GI),U.extend(jI),U.extend(YI),U.extend(XI),U.extend(ZI),U.extend(UI),U.tz.setDefault("UTC");const HI=()=>Promise.resolve().then(()=>Cc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));T.APIClient=at,T.ContentModel=Gi,T.ContentModelContextProvider=zr,T.DashboardApiClient=as,T.DashboardApiFacadeClient=ss,T.DashboardEditor=OD,T.DashboardFilterType=ve,T.DashboardMode=Xl,T.DashboardModel=au,T.DashboardModelContextProvider=Dr,T.DashboardThemeContextProvider=Ar,T.DashboardViewEditor=Kl,T.DashboardViewRender=dr,T.DefaultApiClient=is,T.DescriptionPopover=Bi,T.FacadeApiClient=lc,T.FiltersModel=Zl,T.FullScreenPanel=jl,T.FullScreenPanelContext=$r,T.LayoutStateContext=zn,T.Panel=Wl,T.PanelContextProvider=Er,T.PanelErrorOrStateMessage=Fl,T.PanelModel=tu,T.PanelRender=Ni,T.PanelVizSection=Vi,T.PanelsModel=nu,T.QueriesModel=Hl,T.ReadOnlyDashboard=qD,T.SQLSnippetsModel=eu,T.ViewComponentTypeBackground=Jl,T.ViewComponentTypeColor=k_,T.ViewComponentTypeName=__,T.ViewsModel=ru,T.Viz=ql,T.applyPartialDashboard=B_,T.configureAPIClient=Cr,T.createContentModel=iu,T.createDashboardModel=su,T.facadeApiClient=os,T.getInitialDashboardViewsModel=Fi,T.getVersion=HI,T.initialDashboardContent=T_,T.useDashboardContext=Ir,T.useDashboardThemeContext=ms,T.useEditContentModelContext=le,T.useEditDashboardContext=ue,T.useEditPanelContext=Qe,T.useFullScreenPanelContext=ws,T.usePanelFullScreen=Rl,T.useRenderContentModelContext=ye,T.useRenderDashboardContext=Mr,T.useRenderPanelContext=Ct,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|