@devtable/dashboard 9.2.1 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard.es.js +1180 -1137
- package/dist/dashboard.umd.js +28 -28
- package/dist/plugins/viz-components/stats/type.d.ts +3 -2
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(D,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx-react-lite"),require("lodash"),require("react-hook-form"),require("@tabler/icons"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@mantine/dates"),require("dayjs"),require("tabler-icons-react"),require("rc-select"),require("performant-array-to-tree"),require("rc-tree-select"),require("react-grid-layout"),require("mobx"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("numbro"),require("echarts/charts"),require("@mantine/hooks"),require("@mantine/notifications"),require("d3-array"),require("mathjs"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("axios"),require("mobx-state-tree"),require("jszip"),require("file-saver"),require("crypto-js"),require("@faker-js/faker"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx-react-lite","lodash","react-hook-form","@tabler/icons","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@mantine/dates","dayjs","tabler-icons-react","rc-select","performant-array-to-tree","rc-tree-select","react-grid-layout","mobx","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","numbro","echarts/charts","@mantine/hooks","@mantine/notifications","d3-array","mathjs","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","axios","mobx-state-tree","jszip","file-saver","crypto-js","@faker-js/faker","react-router-dom","reactflow"],b):(D=typeof globalThis<"u"?globalThis:D||self,b(D.dashboard={},D.react,D["@mantine/core"],D["@mantine/modals"],D.ahooks,D["mobx-react-lite"],D._,D["react-hook-form"],D["@tabler/icons"],D["@mantine/tiptap"],D["@tiptap/extension-color"],D["@tiptap/extension-highlight"],D["@tiptap/extension-placeholder"],D["@tiptap/extension-subscript"],D["@tiptap/extension-superscript"],D["@tiptap/extension-text-align"],D["@tiptap/extension-text-style"],D["@tiptap/extension-table"],D["@tiptap/extension-table-cell"],D["@tiptap/extension-table-header"],D["@tiptap/extension-table-row"],D["@tiptap/extension-underline"],D["@tiptap/react"],D["@tiptap/starter-kit"],D["@mantine/dates"],D.dayjs,D["tabler-icons-react"],D["rc-select"],D["performant-array-to-tree"],D["rc-tree-select"],D["react-grid-layout"],D.mobx,D.eventemitter2,D["chroma-js"],D["echarts-gl"],D["echarts/core"],D["echarts/components"],D["echarts/renderers"],D["echarts-for-react/lib/core"],D.numbro,D["echarts/charts"],D["@mantine/hooks"],D["@mantine/notifications"],D["d3-array"],D.mathjs,D.popmotion,D["@monaco-editor/react"],D["d3-regression"],D["@mantine/prism"],D["@tanstack/react-table"],D["react-virtual"],D.axios,D["mobx-state-tree"],D.jszip,D["file-saver"],D.CryptoJS,D["@faker-js/faker"],D["react-router-dom"],D.reactflow))})(this,function(D,b,a,Le,Z,T,v,x,V,X,ci,pi,hi,fi,gi,mi,bi,yi,vi,xi,Ci,wi,_i,Si,uo,j,k,Ti,co,ki,Ot,se,Di,je,
|
|
1
|
+
(function(D,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx-react-lite"),require("lodash"),require("react-hook-form"),require("@tabler/icons"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@mantine/dates"),require("dayjs"),require("tabler-icons-react"),require("rc-select"),require("performant-array-to-tree"),require("rc-tree-select"),require("react-grid-layout"),require("mobx"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("numbro"),require("echarts/charts"),require("@mantine/hooks"),require("@mantine/notifications"),require("d3-array"),require("mathjs"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("axios"),require("mobx-state-tree"),require("jszip"),require("file-saver"),require("crypto-js"),require("@faker-js/faker"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx-react-lite","lodash","react-hook-form","@tabler/icons","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@mantine/dates","dayjs","tabler-icons-react","rc-select","performant-array-to-tree","rc-tree-select","react-grid-layout","mobx","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","numbro","echarts/charts","@mantine/hooks","@mantine/notifications","d3-array","mathjs","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","axios","mobx-state-tree","jszip","file-saver","crypto-js","@faker-js/faker","react-router-dom","reactflow"],b):(D=typeof globalThis<"u"?globalThis:D||self,b(D.dashboard={},D.react,D["@mantine/core"],D["@mantine/modals"],D.ahooks,D["mobx-react-lite"],D._,D["react-hook-form"],D["@tabler/icons"],D["@mantine/tiptap"],D["@tiptap/extension-color"],D["@tiptap/extension-highlight"],D["@tiptap/extension-placeholder"],D["@tiptap/extension-subscript"],D["@tiptap/extension-superscript"],D["@tiptap/extension-text-align"],D["@tiptap/extension-text-style"],D["@tiptap/extension-table"],D["@tiptap/extension-table-cell"],D["@tiptap/extension-table-header"],D["@tiptap/extension-table-row"],D["@tiptap/extension-underline"],D["@tiptap/react"],D["@tiptap/starter-kit"],D["@mantine/dates"],D.dayjs,D["tabler-icons-react"],D["rc-select"],D["performant-array-to-tree"],D["rc-tree-select"],D["react-grid-layout"],D.mobx,D.eventemitter2,D["chroma-js"],D["echarts-gl"],D["echarts/core"],D["echarts/components"],D["echarts/renderers"],D["echarts-for-react/lib/core"],D.numbro,D["echarts/charts"],D["@mantine/hooks"],D["@mantine/notifications"],D["d3-array"],D.mathjs,D.popmotion,D["@monaco-editor/react"],D["d3-regression"],D["@mantine/prism"],D["@tanstack/react-table"],D["react-virtual"],D.axios,D["mobx-state-tree"],D.jszip,D["file-saver"],D.CryptoJS,D["@faker-js/faker"],D["react-router-dom"],D.reactflow))})(this,function(D,b,a,Le,Z,T,v,x,V,X,ci,pi,hi,fi,gi,mi,bi,yi,vi,xi,Ci,wi,_i,Si,uo,j,k,Ti,co,ki,Ot,se,Di,je,L1,po,N,Ie,Ae,te,de,ve,Vt,vt,ho,st,_e,fo,ot,Pe,go,Xe,y,mo,gn,Mi,bo,yo,xe){"use strict";var z1=Object.defineProperty;var E1=(D,b,a)=>b in D?z1(D,b,{enumerable:!0,configurable:!0,writable:!0,value:a}):D[b]=a;var O=(D,b,a)=>(E1(D,typeof b!="symbol"?b+"":b,a),a);function Bt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const le=Bt(po),vo=Bt(vt),Nt=Bt(ho),Ze=Bt(fo);var H=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},xt={},xo={get exports(){return xt},set exports(e){xt=e}},Ct={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
`+ft+_}}var at=!1,nt;{var gt=typeof WeakMap=="function"?WeakMap:Map;nt=new gt}function mt(_,M){if(!_||at)return"";{var E=nt.get(_);if(E!==void 0)return E}var Y;at=!0;var ae=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ue;ue=$t.current,$t.current=null,ii();try{if(M){var ee=function(){throw Error()};if(Object.defineProperty(ee.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ee,[])}catch(Ue){Y=Ue}Reflect.construct(_,[],ee)}else{try{ee.call()}catch(Ue){Y=Ue}_.call(ee.prototype)}}else{try{throw Error()}catch(Ue){Y=Ue}_()}}catch(Ue){if(Ue&&Y&&typeof Ue.stack=="string"){for(var J=Ue.stack.split(`
|
|
19
19
|
`),Me=Y.stack.split(`
|
|
20
20
|
`),ge=J.length-1,ye=Me.length-1;ge>=1&&ye>=0&&J[ge]!==Me[ye];)ye--;for(;ge>=1&&ye>=0;ge--,ye--)if(J[ge]!==Me[ye]){if(ge!==1||ye!==1)do if(ge--,ye--,ye<0||J[ge]!==Me[ye]){var Ee=`
|
|
21
|
-
`+J[ge].replace(" at new "," at ");return _.displayName&&Ee.includes("<anonymous>")&&(Ee=Ee.replace("<anonymous>",_.displayName)),typeof _=="function"&&nt.set(_,Ee),Ee}while(ge>=1&&ye>=0);break}}}finally{at=!1,$t.current=ue,ai(),Error.prepareStackTrace=ae}var yt=_?_.displayName||_.name:"",lo=yt?tt(yt):"";return typeof _=="function"&&nt.set(_,lo),lo}function zt(_,M,E){return mt(_,!1)}function Et(_){var M=_.prototype;return!!(M&&M.isReactComponent)}function rt(_,M,E){if(_==null)return"";if(typeof _=="function")return mt(_,Et(_));if(typeof _=="string")return tt(_);switch(_){case c:return tt("Suspense");case f:return tt("SuspenseList")}if(typeof _=="object")switch(_.$$typeof){case d:return zt(_.render);case g:return rt(_.type,M,E);case h:{var Y=_,ae=Y._payload,ue=Y._init;try{return rt(ue(ae),M,E)}catch{}}}return""}var Lt=Object.prototype.hasOwnProperty,Zs={},Ks=I.ReactDebugCurrentFrame;function fn(_){if(_){var M=_._owner,E=rt(_.type,_._source,M?M.type:null);Ks.setExtraStackFrame(E)}else Ks.setExtraStackFrame(null)}function
|
|
21
|
+
`+J[ge].replace(" at new "," at ");return _.displayName&&Ee.includes("<anonymous>")&&(Ee=Ee.replace("<anonymous>",_.displayName)),typeof _=="function"&&nt.set(_,Ee),Ee}while(ge>=1&&ye>=0);break}}}finally{at=!1,$t.current=ue,ai(),Error.prepareStackTrace=ae}var yt=_?_.displayName||_.name:"",lo=yt?tt(yt):"";return typeof _=="function"&&nt.set(_,lo),lo}function zt(_,M,E){return mt(_,!1)}function Et(_){var M=_.prototype;return!!(M&&M.isReactComponent)}function rt(_,M,E){if(_==null)return"";if(typeof _=="function")return mt(_,Et(_));if(typeof _=="string")return tt(_);switch(_){case c:return tt("Suspense");case f:return tt("SuspenseList")}if(typeof _=="object")switch(_.$$typeof){case d:return zt(_.render);case g:return rt(_.type,M,E);case h:{var Y=_,ae=Y._payload,ue=Y._init;try{return rt(ue(ae),M,E)}catch{}}}return""}var Lt=Object.prototype.hasOwnProperty,Zs={},Ks=I.ReactDebugCurrentFrame;function fn(_){if(_){var M=_._owner,E=rt(_.type,_._source,M?M.type:null);Ks.setExtraStackFrame(E)}else Ks.setExtraStackFrame(null)}function p1(_,M,E,Y,ae){{var ue=Function.call.bind(Lt);for(var ee in _)if(ue(_,ee)){var J=void 0;try{if(typeof _[ee]!="function"){var Me=Error((Y||"React class")+": "+E+" type `"+ee+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof _[ee]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Me.name="Invariant Violation",Me}J=_[ee](M,ee,Y,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ge){J=ge}J&&!(J instanceof Error)&&(fn(ae),$("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Y||"React class",E,ee,typeof J),fn(null)),J instanceof Error&&!(J.message in Zs)&&(Zs[J.message]=!0,fn(ae),$("Failed %s type: %s",E,J.message),fn(null))}}}var h1=Array.isArray;function si(_){return h1(_)}function f1(_){{var M=typeof Symbol=="function"&&Symbol.toStringTag,E=M&&_[Symbol.toStringTag]||_.constructor.name||"Object";return E}}function g1(_){try{return Js(_),!1}catch{return!0}}function Js(_){return""+_}function Hs(_){if(g1(_))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",f1(_)),Js(_)}var Pt=I.ReactCurrentOwner,m1={key:!0,ref:!0,__self:!0,__source:!0},eo,to,oi;oi={};function b1(_){if(Lt.call(_,"ref")){var M=Object.getOwnPropertyDescriptor(_,"ref").get;if(M&&M.isReactWarning)return!1}return _.ref!==void 0}function y1(_){if(Lt.call(_,"key")){var M=Object.getOwnPropertyDescriptor(_,"key").get;if(M&&M.isReactWarning)return!1}return _.key!==void 0}function v1(_,M){if(typeof _.ref=="string"&&Pt.current&&M&&Pt.current.stateNode!==M){var E=oe(Pt.current.type);oi[E]||($('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',oe(Pt.current.type),_.ref),oi[E]=!0)}}function x1(_,M){{var E=function(){eo||(eo=!0,$("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(_,"key",{get:E,configurable:!0})}}function C1(_,M){{var E=function(){to||(to=!0,$("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(_,"ref",{get:E,configurable:!0})}}var w1=function(_,M,E,Y,ae,ue,ee){var J={$$typeof:t,type:_,key:M,ref:E,props:ee,_owner:ue};return J._store={},Object.defineProperty(J._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(J,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Y}),Object.defineProperty(J,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ae}),Object.freeze&&(Object.freeze(J.props),Object.freeze(J)),J};function _1(_,M,E,Y,ae){{var ue,ee={},J=null,Me=null;E!==void 0&&(Hs(E),J=""+E),y1(M)&&(Hs(M.key),J=""+M.key),b1(M)&&(Me=M.ref,v1(M,ae));for(ue in M)Lt.call(M,ue)&&!m1.hasOwnProperty(ue)&&(ee[ue]=M[ue]);if(_&&_.defaultProps){var ge=_.defaultProps;for(ue in ge)ee[ue]===void 0&&(ee[ue]=ge[ue])}if(J||Me){var ye=typeof _=="function"?_.displayName||_.name||"Unknown":_;J&&x1(ee,ye),Me&&C1(ee,ye)}return w1(_,J,Me,ae,Y,Pt.current,ee)}}var li=I.ReactCurrentOwner,no=I.ReactDebugCurrentFrame;function bt(_){if(_){var M=_._owner,E=rt(_.type,_._source,M?M.type:null);no.setExtraStackFrame(E)}else no.setExtraStackFrame(null)}var ui;ui=!1;function di(_){return typeof _=="object"&&_!==null&&_.$$typeof===t}function ro(){{if(li.current){var _=oe(li.current.type);if(_)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+_+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+_+"`."}return""}}function S1(_){{if(_!==void 0){var M=_.fileName.replace(/^.*[\\\/]/,""),E=_.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+M+":"+E+"."}return""}}var io={};function
|
|
25
|
+
Check your code at `+M+":"+E+"."}return""}}var io={};function T1(_){{var M=ro();if(!M){var E=typeof _=="string"?_:_.displayName||_.name;E&&(M=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(!_._store||_._store.validated||_.key!=null)return;_._store.validated=!0;var E=C1(M);if(io[E])return;io[E]=!0;var Y="";_&&_._owner&&_._owner!==li.current&&(Y=" It was passed a child from "+oe(_._owner.type)+"."),bt(_),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,Y),bt(null)}}function so(_,M){{if(typeof _!="object")return;if(si(_))for(var E=0;E<_.length;E++){var Y=_[E];di(Y)&&ao(Y,M)}else if(di(_))_._store&&(_._store.validated=!0);else if(_){var ae=S(_);if(typeof ae=="function"&&ae!==_.entries)for(var ue=ae.call(_),ee;!(ee=ue.next()).done;)di(ee.value)&&ao(ee.value,M)}}}function w1(_){{var M=_.type;if(M==null||typeof M=="string")return;var E;if(typeof M=="function")E=M.propTypes;else if(typeof M=="object"&&(M.$$typeof===d||M.$$typeof===g))E=M.propTypes;else return;if(E){var Y=oe(M);l1(E,_.props,"prop",Y,_)}else if(M.PropTypes!==void 0&&!ui){ui=!0;var ae=oe(M);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ae||"Unknown")}typeof M.getDefaultProps=="function"&&!M.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function _1(_){{for(var M=Object.keys(_.props),E=0;E<M.length;E++){var Y=M[E];if(Y!=="children"&&Y!=="key"){bt(_),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Y),bt(null);break}}_.ref!==null&&(bt(_),$("Invalid attribute `ref` supplied to `React.Fragment`."),bt(null))}}function oo(_,M,E,Y,ae,ue){{var ee=Q(_);if(!ee){var J="";(_===void 0||typeof _=="object"&&_!==null&&Object.keys(_).length===0)&&(J+=" 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 Me=x1(ae);Me?J+=Me:J+=ro();var ge;_===null?ge="null":si(_)?ge="array":_!==void 0&&_.$$typeof===t?(ge="<"+(oe(_.type)||"Unknown")+" />",J=" Did you accidentally export a JSX literal instead of a component?"):ge=typeof _,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ge,J)}var ye=v1(_,M,E,ae,ue);if(ye==null)return ye;if(ee){var Ee=M.children;if(Ee!==void 0)if(Y)if(si(Ee)){for(var yt=0;yt<Ee.length;yt++)so(Ee[yt],_);Object.freeze&&Object.freeze(Ee)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else so(Ee,_)}return _===i?_1(ye):w1(ye),ye}}function S1(_,M,E){return oo(_,M,E,!0)}function T1(_,M,E){return oo(_,M,E,!1)}var k1=T1,D1=S1;wt.Fragment=i,wt.jsx=k1,wt.jsxs=D1}()),wt}(function(e){process.env.NODE_ENV==="production"?e.exports=Co():e.exports=wo()})(xo);const B=xt.Fragment,n=xt.jsx,p=xt.jsxs;function $i(e,t){b.useEffect(()=>{const r=i=>{console.log(i);const{viewID:s}=i.detail;if(!s){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(s),t&&e.views.setIDOfVIE(s)};return window.addEventListener("open-view",r),()=>{window.removeEventListener("open-view",r)}},[e,t]),b.useEffect(()=>{const r=i=>{console.log(i);const{dictionary:s,payload:o}=i.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(s).forEach(([u,l])=>{e.filters.setValueByKey(u,v.get(o,l))})};return window.addEventListener("set-filter-values",r),()=>{window.removeEventListener("set-filter-values",r)}},[e]),b.useEffect(()=>{function r(s){return Array.isArray(s)?[]:typeof s=="object"?{}:typeof s=="boolean"?!1:typeof s=="string"?"":typeof s=="number"?0:s}const i=s=>{console.log(s);const{filter_keys:o}=s.detail;o.forEach(u=>{const l=v.get(e.filters.values,u),d=r(l);console.log(`${u}: ${d}`),e.filters.setValueByKey(u,d)})};return window.addEventListener("clear-filter-values",i),()=>{window.removeEventListener("clear-filter-values",i)}},[e]),b.useEffect(()=>{const r=i=>{console.log(i);const{urlTemplate:s,openInNewTab:o,enableEncoding:u=!1,payload:l}=i.detail;if(!s){console.error(new Error("[Open Link] URL is empty"));return}function d(g){return v.cloneDeepWith(g,m=>{if(u&&typeof m=="string")return encodeURIComponent(m)})}const f=v.template(s||"")(d({...l,filters:e.payloadForSQL.filterValues,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",r),()=>{window.removeEventListener("open-link",r)}},[e])}class _o{constructor(t){O(this,"symbol");this.symbol=Symbol(t)}}function Re(e){return new _o(e)}class mn{constructor(){O(this,"parent");O(this,"factoryRegistry",new Map);O(this,"instanceRegistry",new Map)}createScoped(){const t=new mn;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 r=this.factoryRegistry.get(t.symbol);if(r){const i=r(this);return this.instanceRegistry.set(t.symbol,i),i}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=v.get(t,"dispose");v.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const bn=b.createContext(null);function Gt(e){const t=b.useContext(bn),r=Z.useCreation(()=>e.configure(t||new mn),[e.configure]),i=Z.usePrevious(r);return i&&i!==r&&i.dispose(),n(bn.Provider,{value:r,children:e.children})}function zi(){return b.useContext(bn)}const So={viewPanelInFullScreen:v.noop,inFullScreen:!1},yn=b.createContext(So),Ei=b.createContext(null),vn=Ei.Provider;function me(){const e=b.useContext(Ei);if(!e)throw new Error("Please use ModelContextProvider");return e}const Li=b.createContext(null),xn=Li.Provider;function F(){const e=b.useContext(Li);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const To={layoutFrozen:!1,freezeLayout:v.noop,inEditMode:!1},Ke=b.createContext(To),Pi=b.createContext({panel:null,data:[],loading:!1}),Cn=Pi.Provider;function Ce(){const e=b.useContext(Pi);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const ko={fullScreenPanelID:"",setFullScreenPanelID:v.noop},wn=b.createContext(ko);function Oi(){const e=b.useContext(wn);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}class ke extends b.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return p(a.Box,{children:[n(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}const _n={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"}},qt=({value:e,styles:t={}})=>{const r=_i.useEditor({extensions:[Si,wi,X.Link,gi,fi,pi,yi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ci,xi,vi,mi.configure({types:["heading","paragraph"]}),hi.configure({placeholder:"This is placeholder"}),bi,ci.Color],content:e,editable:!1});b.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=b.useMemo(()=>v.defaultsDeep({},{content:_n},t),[t]);return n(X.RichTextEditor,{editor:r,styles:i,children:n(X.RichTextEditor.Content,{})})},Do=({description:e,isDescriptionEmpty:t})=>t?null:n(a.Tooltip,{color:"white",label:n(qt,{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:n(a.Box,{sx:{height:"16px",alignSelf:"center"},children:n(V.IconInfoCircle,{size:16,color:"gray"})})}),Mo=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:i,...s},value:o,onChange:u})=>p(a.Box,{children:[n(a.Text,{children:" "}),n(a.Checkbox,{label:p(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[n(a.Box,{sx:{flexGrow:1},children:e}),n(Do,{description:r,isDescriptionEmpty:i})]}),checked:o||!1,onChange:l=>u(l.currentTarget.checked),...s,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Vi=T.observer(({label:e,config:t,value:r=[null,null],onChange:i})=>{const s=Array.isArray(r)?r.map(d=>d?j(d).toDate():null):[null,null],o=d=>{i(d.map(c=>c&&j(c).format(t.inputFormat)))},u=t.getMinDate(s[0]),l=t.getMaxDate(s[0]);return n(uo.DateRangePicker,{label:e,value:s,onChange:o,icon:n(k.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:u,maxDate:l,styles:{input:{borderColor:"#e9ecef"}},...t})}),Io=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{flexGrow:1}}}})),Ao=({disabled:e,classNames:t,styles:r,unstyled:i,radius:s,style:o,label:u,value:l,onChange:d,options:c})=>{const{classes:f,cx:g}=Io({radius:s},{name:"MultiSelectWidget",classNames:t,styles:r,unstyled:i}),[h,m]=b.useState((l==null?void 0:l.length)>0),w=P=>{m(P)},C=h&&(l==null?void 0:l.length)>0,[S,I]=b.useState(""),$=b.useMemo(()=>{if(!S)return c;const P=S.toLowerCase(),q=L=>L.description.toLowerCase().includes(P)||L.label.toLowerCase().includes(P);return c.filter(q)},[S,c]);return p(a.Stack,{spacing:3,children:[p(a.Group,{position:"apart",children:[n(a.Text,{className:f.label,children:u}),C&&n(a.Tooltip,{label:`${l.length} selected`,children:n(a.Badge,{children:l.length})})]}),n(Ti,{disabled:e,allowClear:!0,className:g(f.root,"check-select"),dropdownClassName:g(f.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>n(a.CloseButton,{}),value:l,onChange:d,onSelect:console.log,mode:"multiple",maxTagCount:0,maxTagTextLength:10,maxTagPlaceholder:P=>`${P.length} selected`,searchValue:S,onSearch:I,filterOption:!1,children:$.map(P=>n(Ti.Option,{children:n(a.Group,{noWrap:!0,children:p("div",{children:[n(a.Text,{size:"sm","data-role":"label",children:P.label}),n(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:P.description})]})})},P.value))})]})},$o=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading",d=t.min_width?t.min_width:"200px",c=o?l:!1;return n(Ao,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:c?d:"unset",borderColor:"#e9ecef"},disabled:c,value:r,onChange:i})}),zo=b.forwardRef(({label:e,description:t,...r},i)=>n("div",{ref:i,...r,children:n(a.Group,{noWrap:!0,children:p("div",{children:[n(a.Text,{size:"sm","data-role":"label",children:e}),n(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),Eo=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading";return b.useEffect(()=>{var f;const{default_selection_count:d}=t;if(!d)return;const c=((f=t.options[0])==null?void 0:f.value)??"";console.log("Selecting the first option by default. New value: ",c),i(c,!0)},[t.default_selection_count,t.options]),n(a.Select,{label:e,data:t.options,disabled:o?l:!1,value:r,onChange:i,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:zo})});function Lo({label:e,config:t,value:r,onChange:i}){return n(a.TextInput,{label:e,value:r||"",onChange:s=>i(s.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}function Po(e){return co.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}const Oo=({rotate:e,onClick:t})=>n("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:n("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"})}),Vo=({expanded:e,isLeaf:t,value:r,onClick:i,...s})=>(r==="0-0-value"&&console.log(s),t?n("span",{style:{width:"14px",display:"inline-block"}}):n(Oo,{rotate:e?"0":"-90",onClick:i,...s})),Bo=({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:[n("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),No=({onClick:e,...t})=>n(Bo,{onClick:e,...t}),Go=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),qo=({disabled:e,classNames:t,styles:r,unstyled:i,radius:s,style:o,label:u,value:l,onChange:d,treeData:c})=>{const{classes:f,cx:g}=Go({radius:s},{name:"FilterTreeSelectWidget",classNames:t,styles:r,unstyled:i}),[h,m]=b.useState((l==null?void 0:l.length)>0),w=S=>{m(S)},C=h&&(l==null?void 0:l.length)>0;return p(a.Stack,{spacing:3,children:[p(a.Group,{position:"apart",children:[n(a.Text,{className:f.label,children:u}),C&&n(a.Tooltip,{label:`${l.length} selected`,children:n(a.Badge,{children:l.length})})]}),n(ki,{disabled:e,allowClear:!0,className:g(f.root,"check-select"),dropdownClassName:g(f.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>n(a.CloseButton,{}),switcherIcon:Vo,treeIcon:No,maxTagTextLength:10,value:l,treeData:c,treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:ki.SHOW_PARENT,onChange:d,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:S=>`${S.length} selected`})]})};function Fo(e){return e.map(t=>{const{label:r,description:i,...s}=t,o={...s,filterBasis:`${r}___${i??""}`,description:i,label:r};return i&&(o.label=p("div",{children:[n(a.Text,{title:t.label,children:t.label}),n(a.Text,{className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description,children:t.description})]})),o})}const Wo=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),{state:o,dataProxy:u,len:l}=s.getDataStuffByID(t.options_query_id),d=o==="loading",c=b.useMemo(()=>{if(!u)return[];const m=[...u],w=Fo(m);return Po(w)},[u,l]);b.useEffect(()=>{const{default_selection_count:m}=t;if(!m)return;if(c.length===0){console.log("[filter.tree-select] Resetting to empty"),i([],!0);return}const w=c.slice(0,m).map(C=>C.value);console.log(`[filter.tree-select] Selecting first ${m} option(s)`),i(w,!0)},[t.default_selection_count,c]);const f=t.min_width?t.min_width:"200px",h=!!t.options_query_id?d:!1;return n(qo,{disabled:h,style:{minWidth:"160px",width:f,maxWidth:h?f:"unset",borderColor:"#e9ecef"},value:r,onChange:m=>i(m,!1),treeData:c,label:e})}),jo=T.observer(({filter:{type:e,config:t,key:r,...i},formFieldProps:s})=>{switch(e){case"select":return n(Eo,{...i,...s,config:t});case"multi-select":return n($o,{...i,...s,config:t});case"tree-select":return n(Wo,{...i,...s,config:t});case"text-input":return n(Lo,{...i,...s,config:t});case"date-range":return n(Vi,{...i,...s,config:t});case"checkbox":return n(Mo,{...i,...s,config:t});default:return null}}),Bi=T.observer(b.forwardRef(({filter:e,...t},r)=>n("div",{className:"filter-root",ref:r,children:n(ke,{children:n(jo,{filter:e,formFieldProps:t})})}))),Ni=T.observer(function({view:t}){const r=F(),{control:i,handleSubmit:s,reset:o}=x.useForm({defaultValues:r.filters.values,reValidateMode:"onBlur"}),u=x.useWatch({control:i});b.useEffect(()=>{o(r.filters.values)},[r.filters.values,o]),b.useEffect(()=>{r.filters.updatePreviewValues(u)},[u]);const l=r.filters.visibleInView(t.id),d=b.useMemo(()=>l.every(h=>h.should_auto_submit),[l]),c=b.useMemo(()=>l.filter(h=>v.get(h,"config.required",!1)),[l]),f=b.useMemo(()=>c.length===0?!1:c.some(h=>!h.requiredAndPass(u[h.key])),[u,c]);if(l.length===0)return null;const g=(h,m)=>(w,C)=>{m(w),(h.should_auto_submit||C)&&r.filters.setValueByKey(h.key,w)};return n("form",{onSubmit:s(r.filters.setValues),children:p(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:d?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n(a.Group,{align:"flex-start",children:l.map(h=>n(x.Controller,{name:h.key,control:i,render:({field:m})=>n(Bi,{filter:h,value:m.value,onChange:g(h,m.onChange)})},h.id))}),!d&&n(a.Group,{sx:{alignSelf:"flex-end"},children:n(a.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),$1="";function Ro(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Gi=T.observer(()=>{const{freezeLayout:e}=b.useContext(Ke),[t,r]=b.useState(!1),{panel:i}=Ce();return b.useEffect(()=>{e(t)},[t]),Ro(i.description)?null:p(B,{children:[n(a.Modal,{opened:t,onClose:()=>r(!1),title:i.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:n(qt,{value:i.description,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(s=>!s),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n(k.InfoCircle,{size:20})})})]})}),Yo=T.observer(({view:e})=>{const t=me(),r=F(),i=Le.useModals(),{panel:s}=Ce(),{id:o,query:u}=s,{inEditMode:l}=b.useContext(Ke),d=()=>u==null?void 0:u.fetchData(),{viewPanelInFullScreen:c,inFullScreen:f}=b.useContext(yn),g=()=>{r.duplicatePanelByID(o,e.id)},h=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},m=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),w=b.useCallback(()=>{c(o)},[o,c]),C=!f&&e.type!==K.Modal;return n(B,{children:n(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(a.Menu,{withinPortal:!0,children:[n(a.Menu.Target,{children:n(a.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{onClick:d,icon:n(k.Refresh,{size:14}),children:"Refresh"}),n(a.Menu.Item,{onClick:()=>r.queries.downloadDataByQueryID((u==null?void 0:u.id)??""),icon:n(k.Download,{size:14}),children:"Download Data"}),C&&n(a.Menu.Item,{onClick:w,icon:n(k.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(B,{children:[n(a.Divider,{label:"Edit",labelPosition:"center"}),n(a.Menu.Item,{onClick:h,icon:n(k.Settings,{size:14}),children:"Settings"}),n(a.Menu.Item,{onClick:g,icon:n(k.Copy,{size:14}),children:"Duplicate"}),n(a.Menu.Item,{color:"red",onClick:m,icon:n(k.Trash,{size:14}),children:"Delete"})]})]})]})})})}),z1="",Qo=T.observer(function(){const{panel:t}=Ce(),{title:r}=t;return r?n(a.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:n(a.Text,{align:"center",lineClamp:1,weight:"bold",children:r})}):null}),Ne=(e,t)=>{const[r,i]=b.useState([]);return b.useEffect(()=>e.watchTriggerSnapshotList(s=>i(s.filter(o=>o.schemaRef===t))),[]),r};class lt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,v.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:v.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[t]:r})}return await this.getItem(t)}watchItem(t,r,i){return t===null?this.root.watchItem(this.path,(s,o)=>{r(s,o)},i):this.root.watchItem(this.path,(s,o)=>{const u=v.get(s,t),l=v.get(o,t);u!==l&&r(u,l)},i)}}class Sn{constructor(t,r,i){O(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=i,this.attachmentStorage=new lt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new lt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new lt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(v.values(t).map(r=>this.constructInstance(new lt(this.attachmentStorage,r.id))))}}class qi{constructor(t){O(this,"rootRef");this.rootRef=se.observable({current:t})}async deleteItem(t){se.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?se.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(v.isObject(r))se.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else se.runInAction(()=>{v.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,i){return se.reaction(()=>this.getValueFromRoot(t),(s,o)=>{r(s,o)},{requiresObservable:!0,fireImmediately:v.get(i,"fireImmediately",!1)})}}class Uo{constructor(){O(this,"channels",new Map);O(this,"globalChannel",new Di)}getChannel(t){const r=this.channels.get(t);if(r)return r;const i=new Di;return this.channels.set(t,i),i}}class Xo{constructor(t){O(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 r=this.instances.get(t.id);if(r)return r;const i={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Uo,instanceData:new qi(t.viz.conf)};return this.instances.set(t.id,i),i}}function Fi(e,t,r,i){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new qi({}),colorPalette:{getColor(){return()=>""}},data:t,variables:i}}const Zo=e=>{const{panel:t,vizManager:r,data:i,variables:s}=e,o=r.resolveComponent(t.viz.type),u=r.getOrCreateInstance(t),l={...Fi(u,i,r,s),viewport:{width:t.layout.w,height:t.layout.h}},d=o.viewRender;return n(d,{context:l,instance:u,...v.omit(e,["panel","vizManager","data"])})},Ko=e=>{const{vizManager:t,panel:r,panelInfoEditor:i,data:s,variables:o}=e,u=t.resolveComponent(r.viz.type),l=t.getOrCreateInstance(r),d={...Fi(l,s,t,o),panelInfoEditor:i},c=u.configRender;return n(c,{context:d,instance:l,...v.omit(e,["panel","vizManager","data","panelInfoEditor"])})},Wi=(e,t)=>{const r=je.bezier(e),i=je.bezier(t);return function(s){return s<50?r(s*2/100).hex():i((s-50)*2/100).hex()}},Ft=e=>{const t=je.bezier(e);return function(r){return t(r/100).hex()}},Jo={type:"interpolation",displayName:"Red / Green",getColor:Wi(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ho={type:"interpolation",displayName:"Yellow / Blue",getColor:Wi(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},el={type:"interpolation",displayName:"Red",getColor:Ft(["#fff7f1","darkred"]),name:"red",category:"sequential"},tl={type:"interpolation",displayName:"Green",getColor:Ft(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},nl={type:"interpolation",displayName:"Blue",getColor:Ft(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},rl={type:"interpolation",displayName:"Orange",getColor:Ft(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},ji="@devtable/dashboard",Tn="9.2.1",Ri="Apache-2.0",Yi={access:"public",registry:"https://registry.npmjs.org/"},Qi=["dist"],Ui="./dist/dashboard.umd.js",Xi="./dist/dashboard.es.js",Zi="./dist/index.d.ts",Ki={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},Ji={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},Hi={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5",mathjs:"11.8.0","monaco-editor":"0.36.0","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-select":"14.1.0","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},ea={"@emotion/babel-plugin":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@testing-library/cypress":"^9.0.0","@testing-library/jest-dom":"^5.16.4","@testing-library/react":"^13.3.0","@testing-library/react-hooks":"^8.0.1","@testing-library/user-event":"^14.3.0","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.4","@types/eventemitter2":"^4.1.0","@types/file-saver":"2.0.5","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2",ahooks:"^3.3.11",ajv:"8.12.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^12.9.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",jsdom:"^20.0.0","jsdom-testing-mocks":"^1.5.0",lodash:"^4.17.21",lowlight:"^2.8.0",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","rollup-plugin-visualizer":"5.6.0","tabler-icons-react":"^1.48.0",typescript:"^4.6.3","vite-plugin-static-copy":"0.13.1"},ta={"@emotion/react":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@tanstack/react-table":"^8.5.13","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","crypto-js":"^4.1.1","d3-array":"3.2.3","d3-regression":"1.3.10",dayjs:"1.11.7",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",eventemitter2:"^6.4.6",jszip:"3.10.1",lodash:"^4.17.21",lowlight:"^2.8.0",mobx:"^6.6.1","mobx-react-lite":"^3.4.0","mobx-state-tree":"^5.1.5",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","react-router-dom":"^6.3.0","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},il=Object.freeze(Object.defineProperty({__proto__:null,default:{name:ji,version:Tn,license:Ri,publishConfig:Yi,files:Qi,main:Ui,module:Xi,types:Zi,exports:Ki,scripts:Ji,dependencies:Hi,devDependencies:ea,peerDependencies:ta},dependencies:Hi,devDependencies:ea,exports:Ki,files:Qi,license:Ri,main:Ui,module:Xi,name:ji,peerDependencies:ta,publishConfig:Yi,scripts:Ji,types:Zi,version:Tn},Symbol.toStringTag,{value:"Module"}));class al{constructor(t){O(this,"staticColors",new Map);O(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(i=>{this.register(i)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&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(r,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 sl{constructor(){O(this,"plugins",new Map);O(this,"vizComponents",new Map);O(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;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 r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class ol{constructor(){O(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,i){var u;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const s=this.migrations.filter(l=>l.version>t.from&&l.version<=t.to),o=v.orderBy(s,"version","asc");if(((u=v.last(o))==null?void 0:u.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((l,d)=>d.handler(l,i),r)}}class he extends ol{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(i,s)=>({version:t,...r(i,s)}))}async migrate({configData:t,panelModel:r}){const i=await t.getItem(null),s=v.get(i,"version",0),o=this.run({from:s,to:this.VERSION},i,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return v.get(r,"version",0)<this.VERSION}}const W=(e,t)=>{const[r,{setFalse:i}]=Z.useBoolean(!0),[s,o]=b.useState();b.useEffect(()=>(e.getItem(t).then(l=>{o(l),i()}),e.watchItem(t,l=>{o(l)})));const u=b.useCallback(async l=>{await e.setItem(t,l),o(l)},[e,t]);return{loading:r,value:s,set:u}},kn={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"}};le.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer]);function ll({context:e}){const{value:t}=W(e.instanceData,"config"),r=e.data,{width:i,height:s}=e.viewport,{x_axis_data_key:o,y_axis_data_key:u,z_axis_data_key:l,xAxis3D:d,yAxis3D:c,zAxis3D:f}=v.defaults({},t,kn),g=b.useMemo(()=>{const w=v.minBy(r,C=>C[l]);return v.get(w,l)},[r,l]),h=b.useMemo(()=>{const w=v.maxBy(r,C=>C[l]);return v.get(w,l)},[r,l]),m={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:g,max:h,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:d,yAxis3D:c,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:r.map(w=>[w[o],w[u],w[l]])}]};return t?n(Ae,{echarts:le,option:m,style:{width:i,height:s},notMerge:!0,theme:"merico-light"}):null}function ul({label:e,required:t,value:r,onChange:i,data:s,clearable:o=!1,sx:u,...l},d){const c=b.useMemo(()=>{if(!Array.isArray(s)||s.length===0)return[];const g=Object.keys(s[0]).map(h=>({label:h,value:h}));return o?g.concat([{label:"unset",value:""}]):g},[s]);return n(a.Select,{ref:d,label:e,data:c,value:r,onChange:i,required:t,sx:u,...l})}const R=b.forwardRef(ul);function dl({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=v.defaults({},t,kn),{control:o,handleSubmit:u,reset:l}=x.useForm({defaultValues:s});return b.useEffect(()=>{l(s)},[t]),t?n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[n(a.Text,{children:"X Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"x_axis_data_key",control:o,render:({field:d})=>n(R,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"xAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Y Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"y_axis_data_key",control:o,render:({field:d})=>n(R,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"yAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Z Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"z_axis_data_key",control:o,render:({field:d})=>n(R,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"zAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(a.Button,{color:"blue",type:"submit",children:[n(k.DeviceFloppy,{size:20}),n(a.Text,{ml:"md",children:"Save"})]})})]})}):null}class cl extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const pl={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new cl,name:"bar-3d",viewRender:ll,configRender:dl,createConfig(){return{version:1,config:v.cloneDeep(kn)}}},Se={mantissa:0,output:"number",trimMantissa:!1,average:!1};function hl({value:e,onChange:t},r){const i=l=>{t({...e,output:l})},s=l=>{const d=l===0?!1:e.trimMantissa;t({...e,mantissa:l,trimMantissa:d})},o=l=>{t({...e,trimMantissa:l.currentTarget.checked})},u=l=>{t({...e,average:l.currentTarget.checked})};return p(a.Stack,{ref:r,children:[p(a.Group,{grow:!0,children:[n(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),n(a.Switch,{label:p(a.Stack,{spacing:0,children:[n(a.Text,{children:"Average"}),n(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:u,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(a.Group,{grow:!0,children:[n(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:s}),n(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(a.Stack,{spacing:0,children:[n(a.Text,{weight:"bold",children:"Preview"}),n(ke,{children:p(a.Group,{position:"apart",children:[p(a.Text,{size:12,color:"gray",children:["123456789 ",n(k.ArrowRight,{size:9})," ",te(123456789).format(e)]}),p(a.Text,{size:12,color:"gray",children:["1234 ",n(k.ArrowRight,{size:9})," ",te(1234).format(e)]}),p(a.Text,{size:12,color:"gray",children:["0.1234 ",n(k.ArrowRight,{size:9})," ",te(.1234).format(e)]})]})})]})]})}const Oe=b.forwardRef(hl),Ge={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
27
|
+
Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(!_._store||_._store.validated||_.key!=null)return;_._store.validated=!0;var E=T1(M);if(io[E])return;io[E]=!0;var Y="";_&&_._owner&&_._owner!==li.current&&(Y=" It was passed a child from "+oe(_._owner.type)+"."),bt(_),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,Y),bt(null)}}function so(_,M){{if(typeof _!="object")return;if(si(_))for(var E=0;E<_.length;E++){var Y=_[E];di(Y)&&ao(Y,M)}else if(di(_))_._store&&(_._store.validated=!0);else if(_){var ae=S(_);if(typeof ae=="function"&&ae!==_.entries)for(var ue=ae.call(_),ee;!(ee=ue.next()).done;)di(ee.value)&&ao(ee.value,M)}}}function k1(_){{var M=_.type;if(M==null||typeof M=="string")return;var E;if(typeof M=="function")E=M.propTypes;else if(typeof M=="object"&&(M.$$typeof===d||M.$$typeof===g))E=M.propTypes;else return;if(E){var Y=oe(M);p1(E,_.props,"prop",Y,_)}else if(M.PropTypes!==void 0&&!ui){ui=!0;var ae=oe(M);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ae||"Unknown")}typeof M.getDefaultProps=="function"&&!M.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function D1(_){{for(var M=Object.keys(_.props),E=0;E<M.length;E++){var Y=M[E];if(Y!=="children"&&Y!=="key"){bt(_),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Y),bt(null);break}}_.ref!==null&&(bt(_),$("Invalid attribute `ref` supplied to `React.Fragment`."),bt(null))}}function oo(_,M,E,Y,ae,ue){{var ee=Q(_);if(!ee){var J="";(_===void 0||typeof _=="object"&&_!==null&&Object.keys(_).length===0)&&(J+=" 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 Me=S1(ae);Me?J+=Me:J+=ro();var ge;_===null?ge="null":si(_)?ge="array":_!==void 0&&_.$$typeof===t?(ge="<"+(oe(_.type)||"Unknown")+" />",J=" Did you accidentally export a JSX literal instead of a component?"):ge=typeof _,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ge,J)}var ye=_1(_,M,E,ae,ue);if(ye==null)return ye;if(ee){var Ee=M.children;if(Ee!==void 0)if(Y)if(si(Ee)){for(var yt=0;yt<Ee.length;yt++)so(Ee[yt],_);Object.freeze&&Object.freeze(Ee)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else so(Ee,_)}return _===i?D1(ye):k1(ye),ye}}function M1(_,M,E){return oo(_,M,E,!0)}function I1(_,M,E){return oo(_,M,E,!1)}var A1=I1,$1=M1;wt.Fragment=i,wt.jsx=A1,wt.jsxs=$1}()),wt}(function(e){process.env.NODE_ENV==="production"?e.exports=Co():e.exports=wo()})(xo);const B=xt.Fragment,n=xt.jsx,p=xt.jsxs;function $i(e,t){b.useEffect(()=>{const r=i=>{console.log(i);const{viewID:s}=i.detail;if(!s){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(s),t&&e.views.setIDOfVIE(s)};return window.addEventListener("open-view",r),()=>{window.removeEventListener("open-view",r)}},[e,t]),b.useEffect(()=>{const r=i=>{console.log(i);const{dictionary:s,payload:o}=i.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(s).forEach(([u,l])=>{e.filters.setValueByKey(u,v.get(o,l))})};return window.addEventListener("set-filter-values",r),()=>{window.removeEventListener("set-filter-values",r)}},[e]),b.useEffect(()=>{function r(s){return Array.isArray(s)?[]:typeof s=="object"?{}:typeof s=="boolean"?!1:typeof s=="string"?"":typeof s=="number"?0:s}const i=s=>{console.log(s);const{filter_keys:o}=s.detail;o.forEach(u=>{const l=v.get(e.filters.values,u),d=r(l);console.log(`${u}: ${d}`),e.filters.setValueByKey(u,d)})};return window.addEventListener("clear-filter-values",i),()=>{window.removeEventListener("clear-filter-values",i)}},[e]),b.useEffect(()=>{const r=i=>{console.log(i);const{urlTemplate:s,openInNewTab:o,enableEncoding:u=!1,payload:l}=i.detail;if(!s){console.error(new Error("[Open Link] URL is empty"));return}function d(g){return v.cloneDeepWith(g,m=>{if(u&&typeof m=="string")return encodeURIComponent(m)})}const f=v.template(s||"")(d({...l,filters:e.payloadForSQL.filterValues,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",r),()=>{window.removeEventListener("open-link",r)}},[e])}class _o{constructor(t){O(this,"symbol");this.symbol=Symbol(t)}}function Re(e){return new _o(e)}class mn{constructor(){O(this,"parent");O(this,"factoryRegistry",new Map);O(this,"instanceRegistry",new Map)}createScoped(){const t=new mn;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 r=this.factoryRegistry.get(t.symbol);if(r){const i=r(this);return this.instanceRegistry.set(t.symbol,i),i}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=v.get(t,"dispose");v.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const bn=b.createContext(null);function Gt(e){const t=b.useContext(bn),r=Z.useCreation(()=>e.configure(t||new mn),[e.configure]),i=Z.usePrevious(r);return i&&i!==r&&i.dispose(),n(bn.Provider,{value:r,children:e.children})}function zi(){return b.useContext(bn)}const So={viewPanelInFullScreen:v.noop,inFullScreen:!1},yn=b.createContext(So),Ei=b.createContext(null),vn=Ei.Provider;function me(){const e=b.useContext(Ei);if(!e)throw new Error("Please use ModelContextProvider");return e}const Li=b.createContext(null),xn=Li.Provider;function F(){const e=b.useContext(Li);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const To={layoutFrozen:!1,freezeLayout:v.noop,inEditMode:!1},Ke=b.createContext(To),Pi=b.createContext({panel:null,data:[],loading:!1}),Cn=Pi.Provider;function Ce(){const e=b.useContext(Pi);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const ko={fullScreenPanelID:"",setFullScreenPanelID:v.noop},wn=b.createContext(ko);function Oi(){const e=b.useContext(wn);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}class ke extends b.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return p(a.Box,{children:[n(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}const _n={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"}},qt=({value:e,styles:t={}})=>{const r=_i.useEditor({extensions:[Si,wi,X.Link,gi,fi,pi,yi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ci,xi,vi,mi.configure({types:["heading","paragraph"]}),hi.configure({placeholder:"This is placeholder"}),bi,ci.Color],content:e,editable:!1});b.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=b.useMemo(()=>v.defaultsDeep({},{content:_n},t),[t]);return n(X.RichTextEditor,{editor:r,styles:i,children:n(X.RichTextEditor.Content,{})})},Do=({description:e,isDescriptionEmpty:t})=>t?null:n(a.Tooltip,{color:"white",label:n(qt,{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:n(a.Box,{sx:{height:"16px",alignSelf:"center"},children:n(V.IconInfoCircle,{size:16,color:"gray"})})}),Mo=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:i,...s},value:o,onChange:u})=>p(a.Box,{children:[n(a.Text,{children:" "}),n(a.Checkbox,{label:p(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[n(a.Box,{sx:{flexGrow:1},children:e}),n(Do,{description:r,isDescriptionEmpty:i})]}),checked:o||!1,onChange:l=>u(l.currentTarget.checked),...s,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Vi=T.observer(({label:e,config:t,value:r=[null,null],onChange:i})=>{const s=Array.isArray(r)?r.map(d=>d?j(d).toDate():null):[null,null],o=d=>{i(d.map(c=>c&&j(c).format(t.inputFormat)))},u=t.getMinDate(s[0]),l=t.getMaxDate(s[0]);return n(uo.DateRangePicker,{label:e,value:s,onChange:o,icon:n(k.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:u,maxDate:l,styles:{input:{borderColor:"#e9ecef"}},...t})}),Io=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{flexGrow:1}}}})),Ao=({disabled:e,classNames:t,styles:r,unstyled:i,radius:s,style:o,label:u,value:l,onChange:d,options:c})=>{const{classes:f,cx:g}=Io({radius:s},{name:"MultiSelectWidget",classNames:t,styles:r,unstyled:i}),[h,m]=b.useState((l==null?void 0:l.length)>0),w=P=>{m(P)},C=h&&(l==null?void 0:l.length)>0,[S,I]=b.useState(""),$=b.useMemo(()=>{if(!S)return c;const P=S.toLowerCase(),q=L=>L.description.toLowerCase().includes(P)||L.label.toLowerCase().includes(P);return c.filter(q)},[S,c]);return p(a.Stack,{spacing:3,children:[p(a.Group,{position:"apart",children:[n(a.Text,{className:f.label,children:u}),C&&n(a.Tooltip,{label:`${l.length} selected`,children:n(a.Badge,{children:l.length})})]}),n(Ti,{disabled:e,allowClear:!0,className:g(f.root,"check-select"),dropdownClassName:g(f.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>n(a.CloseButton,{}),value:l,onChange:d,onSelect:console.log,mode:"multiple",maxTagCount:0,maxTagTextLength:10,maxTagPlaceholder:P=>`${P.length} selected`,searchValue:S,onSearch:I,filterOption:!1,children:$.map(P=>n(Ti.Option,{children:n(a.Group,{noWrap:!0,children:p("div",{children:[n(a.Text,{size:"sm","data-role":"label",children:P.label}),n(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:P.description})]})})},P.value))})]})},$o=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading",d=t.min_width?t.min_width:"200px",c=o?l:!1;return n(Ao,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:c?d:"unset",borderColor:"#e9ecef"},disabled:c,value:r,onChange:i})}),zo=b.forwardRef(({label:e,description:t,...r},i)=>n("div",{ref:i,...r,children:n(a.Group,{noWrap:!0,children:p("div",{children:[n(a.Text,{size:"sm","data-role":"label",children:e}),n(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),Eo=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading";return b.useEffect(()=>{var f;const{default_selection_count:d}=t;if(!d)return;const c=((f=t.options[0])==null?void 0:f.value)??"";console.log("Selecting the first option by default. New value: ",c),i(c,!0)},[t.default_selection_count,t.options]),n(a.Select,{label:e,data:t.options,disabled:o?l:!1,value:r,onChange:i,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:zo})});function Lo({label:e,config:t,value:r,onChange:i}){return n(a.TextInput,{label:e,value:r||"",onChange:s=>i(s.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}function Po(e){return co.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}const Oo=({rotate:e,onClick:t})=>n("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:n("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"})}),Vo=({expanded:e,isLeaf:t,value:r,onClick:i,...s})=>(r==="0-0-value"&&console.log(s),t?n("span",{style:{width:"14px",display:"inline-block"}}):n(Oo,{rotate:e?"0":"-90",onClick:i,...s})),Bo=({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:[n("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),No=({onClick:e,...t})=>n(Bo,{onClick:e,...t}),Go=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),qo=({disabled:e,classNames:t,styles:r,unstyled:i,radius:s,style:o,label:u,value:l,onChange:d,treeData:c})=>{const{classes:f,cx:g}=Go({radius:s},{name:"FilterTreeSelectWidget",classNames:t,styles:r,unstyled:i}),[h,m]=b.useState((l==null?void 0:l.length)>0),w=S=>{m(S)},C=h&&(l==null?void 0:l.length)>0;return p(a.Stack,{spacing:3,children:[p(a.Group,{position:"apart",children:[n(a.Text,{className:f.label,children:u}),C&&n(a.Tooltip,{label:`${l.length} selected`,children:n(a.Badge,{children:l.length})})]}),n(ki,{disabled:e,allowClear:!0,className:g(f.root,"check-select"),dropdownClassName:g(f.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>n(a.CloseButton,{}),switcherIcon:Vo,treeIcon:No,maxTagTextLength:10,value:l,treeData:c,treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:ki.SHOW_PARENT,onChange:d,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:S=>`${S.length} selected`})]})};function Fo(e){return e.map(t=>{const{label:r,description:i,...s}=t,o={...s,filterBasis:`${r}___${i??""}`,description:i,label:r};return i&&(o.label=p("div",{children:[n(a.Text,{title:t.label,children:t.label}),n(a.Text,{className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description,children:t.description})]})),o})}const Wo=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),{state:o,dataProxy:u,len:l}=s.getDataStuffByID(t.options_query_id),d=o==="loading",c=b.useMemo(()=>{if(!u)return[];const m=[...u],w=Fo(m);return Po(w)},[u,l]);b.useEffect(()=>{const{default_selection_count:m}=t;if(!m)return;if(c.length===0){console.log("[filter.tree-select] Resetting to empty"),i([],!0);return}const w=c.slice(0,m).map(C=>C.value);console.log(`[filter.tree-select] Selecting first ${m} option(s)`),i(w,!0)},[t.default_selection_count,c]);const f=t.min_width?t.min_width:"200px",h=!!t.options_query_id?d:!1;return n(qo,{disabled:h,style:{minWidth:"160px",width:f,maxWidth:h?f:"unset",borderColor:"#e9ecef"},value:r,onChange:m=>i(m,!1),treeData:c,label:e})}),jo=T.observer(({filter:{type:e,config:t,key:r,...i},formFieldProps:s})=>{switch(e){case"select":return n(Eo,{...i,...s,config:t});case"multi-select":return n($o,{...i,...s,config:t});case"tree-select":return n(Wo,{...i,...s,config:t});case"text-input":return n(Lo,{...i,...s,config:t});case"date-range":return n(Vi,{...i,...s,config:t});case"checkbox":return n(Mo,{...i,...s,config:t});default:return null}}),Bi=T.observer(b.forwardRef(({filter:e,...t},r)=>n("div",{className:"filter-root",ref:r,children:n(ke,{children:n(jo,{filter:e,formFieldProps:t})})}))),Ni=T.observer(function({view:t}){const r=F(),{control:i,handleSubmit:s,reset:o}=x.useForm({defaultValues:r.filters.values,reValidateMode:"onBlur"}),u=x.useWatch({control:i});b.useEffect(()=>{o(r.filters.values)},[r.filters.values,o]),b.useEffect(()=>{r.filters.updatePreviewValues(u)},[u]);const l=r.filters.visibleInView(t.id),d=b.useMemo(()=>l.every(h=>h.should_auto_submit),[l]),c=b.useMemo(()=>l.filter(h=>v.get(h,"config.required",!1)),[l]),f=b.useMemo(()=>c.length===0?!1:c.some(h=>!h.requiredAndPass(u[h.key])),[u,c]);if(l.length===0)return null;const g=(h,m)=>(w,C)=>{m(w),(h.should_auto_submit||C)&&r.filters.setValueByKey(h.key,w)};return n("form",{onSubmit:s(r.filters.setValues),children:p(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:d?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n(a.Group,{align:"flex-start",children:l.map(h=>n(x.Controller,{name:h.key,control:i,render:({field:m})=>n(Bi,{filter:h,value:m.value,onChange:g(h,m.onChange)})},h.id))}),!d&&n(a.Group,{sx:{alignSelf:"flex-end"},children:n(a.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),P1="";function Ro(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Gi=T.observer(()=>{const{freezeLayout:e}=b.useContext(Ke),[t,r]=b.useState(!1),{panel:i}=Ce();return b.useEffect(()=>{e(t)},[t]),Ro(i.description)?null:p(B,{children:[n(a.Modal,{opened:t,onClose:()=>r(!1),title:i.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:n(qt,{value:i.description,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(s=>!s),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n(k.InfoCircle,{size:20})})})]})}),Yo=T.observer(({view:e})=>{const t=me(),r=F(),i=Le.useModals(),{panel:s}=Ce(),{id:o,query:u}=s,{inEditMode:l}=b.useContext(Ke),d=()=>u==null?void 0:u.fetchData(),{viewPanelInFullScreen:c,inFullScreen:f}=b.useContext(yn),g=()=>{r.duplicatePanelByID(o,e.id)},h=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},m=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),w=b.useCallback(()=>{c(o)},[o,c]),C=!f&&e.type!==K.Modal;return n(B,{children:n(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(a.Menu,{withinPortal:!0,children:[n(a.Menu.Target,{children:n(a.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{onClick:d,icon:n(k.Refresh,{size:14}),children:"Refresh"}),n(a.Menu.Item,{onClick:()=>r.queries.downloadDataByQueryID((u==null?void 0:u.id)??""),icon:n(k.Download,{size:14}),children:"Download Data"}),C&&n(a.Menu.Item,{onClick:w,icon:n(k.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(B,{children:[n(a.Divider,{label:"Edit",labelPosition:"center"}),n(a.Menu.Item,{onClick:h,icon:n(k.Settings,{size:14}),children:"Settings"}),n(a.Menu.Item,{onClick:g,icon:n(k.Copy,{size:14}),children:"Duplicate"}),n(a.Menu.Item,{color:"red",onClick:m,icon:n(k.Trash,{size:14}),children:"Delete"})]})]})]})})})}),O1="",Qo=T.observer(function(){const{panel:t}=Ce(),{title:r}=t;return r?n(a.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:n(a.Text,{align:"center",lineClamp:1,weight:"bold",children:r})}):null}),Ne=(e,t)=>{const[r,i]=b.useState([]);return b.useEffect(()=>e.watchTriggerSnapshotList(s=>i(s.filter(o=>o.schemaRef===t))),[]),r};class lt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,v.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:v.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[t]:r})}return await this.getItem(t)}watchItem(t,r,i){return t===null?this.root.watchItem(this.path,(s,o)=>{r(s,o)},i):this.root.watchItem(this.path,(s,o)=>{const u=v.get(s,t),l=v.get(o,t);u!==l&&r(u,l)},i)}}class Sn{constructor(t,r,i){O(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=i,this.attachmentStorage=new lt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new lt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new lt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(v.values(t).map(r=>this.constructInstance(new lt(this.attachmentStorage,r.id))))}}class qi{constructor(t){O(this,"rootRef");this.rootRef=se.observable({current:t})}async deleteItem(t){se.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?se.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(v.isObject(r))se.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else se.runInAction(()=>{v.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,i){return se.reaction(()=>this.getValueFromRoot(t),(s,o)=>{r(s,o)},{requiresObservable:!0,fireImmediately:v.get(i,"fireImmediately",!1)})}}class Uo{constructor(){O(this,"channels",new Map);O(this,"globalChannel",new Di)}getChannel(t){const r=this.channels.get(t);if(r)return r;const i=new Di;return this.channels.set(t,i),i}}class Xo{constructor(t){O(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 r=this.instances.get(t.id);if(r)return r;const i={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Uo,instanceData:new qi(t.viz.conf)};return this.instances.set(t.id,i),i}}function Fi(e,t,r,i){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new qi({}),colorPalette:{getColor(){return()=>""}},data:t,variables:i}}const Zo=e=>{const{panel:t,vizManager:r,data:i,variables:s}=e,o=r.resolveComponent(t.viz.type),u=r.getOrCreateInstance(t),l={...Fi(u,i,r,s),viewport:{width:t.layout.w,height:t.layout.h}},d=o.viewRender;return n(d,{context:l,instance:u,...v.omit(e,["panel","vizManager","data"])})},Ko=e=>{const{vizManager:t,panel:r,panelInfoEditor:i,data:s,variables:o}=e,u=t.resolveComponent(r.viz.type),l=t.getOrCreateInstance(r),d={...Fi(l,s,t,o),panelInfoEditor:i},c=u.configRender;return n(c,{context:d,instance:l,...v.omit(e,["panel","vizManager","data","panelInfoEditor"])})},Wi=(e,t)=>{const r=je.bezier(e),i=je.bezier(t);return function(s){return s<50?r(s*2/100).hex():i((s-50)*2/100).hex()}},Ft=e=>{const t=je.bezier(e);return function(r){return t(r/100).hex()}},Jo={type:"interpolation",displayName:"Red / Green",getColor:Wi(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ho={type:"interpolation",displayName:"Yellow / Blue",getColor:Wi(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},el={type:"interpolation",displayName:"Red",getColor:Ft(["#fff7f1","darkred"]),name:"red",category:"sequential"},tl={type:"interpolation",displayName:"Green",getColor:Ft(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},nl={type:"interpolation",displayName:"Blue",getColor:Ft(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},rl={type:"interpolation",displayName:"Orange",getColor:Ft(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},ji="@devtable/dashboard",Tn="9.3.0",Ri="Apache-2.0",Yi={access:"public",registry:"https://registry.npmjs.org/"},Qi=["dist"],Ui="./dist/dashboard.umd.js",Xi="./dist/dashboard.es.js",Zi="./dist/index.d.ts",Ki={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},Ji={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},Hi={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5",mathjs:"11.8.0","monaco-editor":"0.36.0","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-select":"14.1.0","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},ea={"@emotion/babel-plugin":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@testing-library/cypress":"^9.0.0","@testing-library/jest-dom":"^5.16.4","@testing-library/react":"^13.3.0","@testing-library/react-hooks":"^8.0.1","@testing-library/user-event":"^14.3.0","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.4","@types/eventemitter2":"^4.1.0","@types/file-saver":"2.0.5","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2",ahooks:"^3.3.11",ajv:"8.12.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^12.9.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",jsdom:"^20.0.0","jsdom-testing-mocks":"^1.5.0",lodash:"^4.17.21",lowlight:"^2.8.0",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","rollup-plugin-visualizer":"5.6.0","tabler-icons-react":"^1.48.0",typescript:"^4.6.3","vite-plugin-static-copy":"0.13.1"},ta={"@emotion/react":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"1.119.0","@tanstack/react-table":"^8.5.13","@tiptap/extension-code-block-lowlight":"2.0.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","crypto-js":"^4.1.1","d3-array":"3.2.3","d3-regression":"1.3.10",dayjs:"1.11.7",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",eventemitter2:"^6.4.6",jszip:"3.10.1",lodash:"^4.17.21",lowlight:"^2.8.0",mobx:"^6.6.1","mobx-react-lite":"^3.4.0","mobx-state-tree":"^5.1.5",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","react-router-dom":"^6.3.0","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},il=Object.freeze(Object.defineProperty({__proto__:null,default:{name:ji,version:Tn,license:Ri,publishConfig:Yi,files:Qi,main:Ui,module:Xi,types:Zi,exports:Ki,scripts:Ji,dependencies:Hi,devDependencies:ea,peerDependencies:ta},dependencies:Hi,devDependencies:ea,exports:Ki,files:Qi,license:Ri,main:Ui,module:Xi,name:ji,peerDependencies:ta,publishConfig:Yi,scripts:Ji,types:Zi,version:Tn},Symbol.toStringTag,{value:"Module"}));class al{constructor(t){O(this,"staticColors",new Map);O(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(i=>{this.register(i)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&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(r,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 sl{constructor(){O(this,"plugins",new Map);O(this,"vizComponents",new Map);O(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;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 r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class ol{constructor(){O(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,i){var u;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const s=this.migrations.filter(l=>l.version>t.from&&l.version<=t.to),o=v.orderBy(s,"version","asc");if(((u=v.last(o))==null?void 0:u.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((l,d)=>d.handler(l,i),r)}}class he extends ol{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(i,s)=>({version:t,...r(i,s)}))}async migrate({configData:t,panelModel:r}){const i=await t.getItem(null),s=v.get(i,"version",0),o=this.run({from:s,to:this.VERSION},i,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return v.get(r,"version",0)<this.VERSION}}const W=(e,t)=>{const[r,{setFalse:i}]=Z.useBoolean(!0),[s,o]=b.useState();b.useEffect(()=>(e.getItem(t).then(l=>{o(l),i()}),e.watchItem(t,l=>{o(l)})));const u=b.useCallback(async l=>{await e.setItem(t,l),o(l)},[e,t]);return{loading:r,value:s,set:u}},kn={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"}};le.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer]);function ll({context:e}){const{value:t}=W(e.instanceData,"config"),r=e.data,{width:i,height:s}=e.viewport,{x_axis_data_key:o,y_axis_data_key:u,z_axis_data_key:l,xAxis3D:d,yAxis3D:c,zAxis3D:f}=v.defaults({},t,kn),g=b.useMemo(()=>{const w=v.minBy(r,C=>C[l]);return v.get(w,l)},[r,l]),h=b.useMemo(()=>{const w=v.maxBy(r,C=>C[l]);return v.get(w,l)},[r,l]),m={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:g,max:h,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:d,yAxis3D:c,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:r.map(w=>[w[o],w[u],w[l]])}]};return t?n(Ae,{echarts:le,option:m,style:{width:i,height:s},notMerge:!0,theme:"merico-light"}):null}function ul({label:e,required:t,value:r,onChange:i,data:s,clearable:o=!1,sx:u,...l},d){const c=b.useMemo(()=>{if(!Array.isArray(s)||s.length===0)return[];const g=Object.keys(s[0]).map(h=>({label:h,value:h}));return o?g.concat([{label:"unset",value:""}]):g},[s]);return n(a.Select,{ref:d,label:e,data:c,value:r,onChange:i,required:t,sx:u,...l})}const R=b.forwardRef(ul);function dl({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=v.defaults({},t,kn),{control:o,handleSubmit:u,reset:l}=x.useForm({defaultValues:s});return b.useEffect(()=>{l(s)},[t]),t?n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[n(a.Text,{children:"X Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"x_axis_data_key",control:o,render:({field:d})=>n(R,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"xAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Y Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"y_axis_data_key",control:o,render:({field:d})=>n(R,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"yAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Z Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"z_axis_data_key",control:o,render:({field:d})=>n(R,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"zAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(a.Button,{color:"blue",type:"submit",children:[n(k.DeviceFloppy,{size:20}),n(a.Text,{ml:"md",children:"Save"})]})})]})}):null}class cl extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const pl={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new cl,name:"bar-3d",viewRender:ll,configRender:dl,createConfig(){return{version:1,config:v.cloneDeep(kn)}}},Se={mantissa:0,output:"number",trimMantissa:!1,average:!1};function hl({value:e,onChange:t},r){const i=l=>{t({...e,output:l})},s=l=>{const d=l===0?!1:e.trimMantissa;t({...e,mantissa:l,trimMantissa:d})},o=l=>{t({...e,trimMantissa:l.currentTarget.checked})},u=l=>{t({...e,average:l.currentTarget.checked})};return p(a.Stack,{ref:r,children:[p(a.Group,{grow:!0,children:[n(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),n(a.Switch,{label:p(a.Stack,{spacing:0,children:[n(a.Text,{children:"Average"}),n(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:u,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(a.Group,{grow:!0,children:[n(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:s}),n(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(a.Stack,{spacing:0,children:[n(a.Text,{weight:"bold",children:"Preview"}),n(ke,{children:p(a.Group,{position:"apart",children:[p(a.Text,{size:12,color:"gray",children:["123456789 ",n(k.ArrowRight,{size:9})," ",te(123456789).format(e)]}),p(a.Text,{size:12,color:"gray",children:["1234 ",n(k.ArrowRight,{size:9})," ",te(1234).format(e)]}),p(a.Text,{size:12,color:"gray",children:["0.1234 ",n(k.ArrowRight,{size:9})," ",te(.1234).format(e)]})]})})]})]})}const Oe=b.forwardRef(hl),Ge={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
28
28
|
`)},na={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:gl,configRender:fl,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 fl(e){return n(B,{})}function gl(e){return n(a.Text,{children:"Click chart's series"})}const ml=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Wt=b.forwardRef(({sectionTitle:e,value:t,onChange:r},i)=>{const s=o=>u=>{const l=v.cloneDeep(t);v.set(l,o,u),r(l)};return p(a.Stack,{spacing:0,children:[e&&n(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(a.Group,{grow:!0,noWrap:!0,children:[n(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:s("width")}),n(a.Select,{label:"Overflow",data:ml,value:t.overflow,onChange:s("overflow")}),n(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Je=b.forwardRef(({value:e,onChange:t},r)=>{const i=o=>{t({...e,on_axis:o})},s=o=>{t({...e,in_tooltip:o})};return p(a.Stack,{ref:r,spacing:0,children:[n(Wt,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:i}),n(Wt,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:s})]})}),Ve={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function He({overflow:e,width:t}){const r={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],i=e==="truncate"?"nowrap":"initial",s={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
|
|
29
29
|
max-width: ${t}px;
|
|
30
30
|
word-break: ${r};
|
|
@@ -223,7 +223,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
223
223
|
<tbody>${c.join("")}</tbody>
|
|
224
224
|
</table>
|
|
225
225
|
`}}}function _h(e,t){const r=t.every(s=>!Number.isNaN(Number(s))),{axisLabel:i}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:r?"value":"category",axisLabel:{...i,formatter:Ta(i.formatter)}}]}function Sh(e,t){return e.y_axes.map(({nameAlignment:r,min:i,max:s,...o},u)=>{let l=o.position;return l||(l=u>0?"right":"left"),{...o,min:i||void 0,max:s||void 0,position:l,axisLabel:{show:!0,formatter:t[u]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}function Th(){return{show:!1,bottom:0,left:"center",type:"scroll"}}const kh={tooltip:{trigger:"axis"},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 Dh(e,t,r){const i=r.reduce((c,f)=>{const g=ut(f,t);return c[f.name]=et(f,g),c},{}),s=e.y_axes.reduce((c,{label_formatter:f},g)=>(c[g]=function(m){let w=m;if(typeof m=="object"&&(Array.isArray(m.value)&&m.value.length===2?w=m.value[1]:w=m.value),!f)return w;try{return te(w).format(f)}catch(C){return console.error(C),w}},c),{default:({value:c})=>c}),o=v.uniq(t.map(c=>c[e.x_axis.data_key])),u=o.every(c=>!Number.isNaN(Number(c))),l=vh(e,o,u,t,s,r,i),d={xAxis:_h(e,o),yAxis:Sh(e,s),series:l,dataset:[{source:t}],tooltip:wh(e,s),grid:hh(e),legend:Th(),dataZoom:En(e.dataZoom)};return v.defaultsDeep({},d,kh)}le.use([N.DataZoomComponent,de.BarChart,de.LineChart,de.ScatterChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer,N.MarkLineComponent,N.MarkAreaComponent]);function ka(e){return e.trim().length>0}function Mh({conf:e,data:t,width:r,height:i,interactionManager:s,variables:o}){const u=b.useMemo(()=>v.keyBy(t,e.x_axis.data_key),[t,e.x_axis.data_key]),l=Ne(s.triggerManager,wa.id),d=b.useCallback(g=>{const h=g.value[0],m=v.get(u,h,{error:"rowData is not found"});l.forEach(w=>{s.runInteraction(w.id,{...g,rowData:m})})},[u,l,s]),c=b.useMemo(()=>({click:d}),[d]),f=b.useMemo(()=>Dh(e,t,o),[e,t]);return!r||!i?null:n(Ae,{echarts:le,option:f,style:{width:r,height:i},onEvents:c,notMerge:!0,theme:"merico-light"})}function Ih({context:e,instance:t}){const r=Fe({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=b.useMemo(()=>v.defaults({},i,jn),[i]),u=e.data,{width:l,height:d}=e.viewport,{ref:c,height:f}=ve.useElementSize(),{ref:g,height:h}=ve.useElementSize(),m=b.useMemo(()=>{const{stats:{templates:C}}=o;return{top:kt(C.top,s,u),bottom:kt(C.bottom,s,u)}},[o,u]),w=Math.max(0,d-f-h);return p(a.Box,{children:[n(a.Text,{ref:c,align:"left",size:"xs",pl:"sm",sx:{display:ka(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),n(Mh,{variables:s,width:l,height:w,data:u,conf:o,interactionManager:r}),n(a.Text,{ref:g,align:"left",size:"xs",pl:"sm",sx:{display:ka(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const Ah=b.forwardRef(({value:e,onChange:t,xAxisOptions:r,yAxisOptions:i,variableOptions:s},o)=>{const u=(l,d)=>{const c=v.cloneDeep(e);v.set(c,l,d),t(c)};return p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(a.TextInput,{label:"Content Text",value:e.content.text,onChange:l=>u("content.text",l.currentTarget.value)}),n(Bn,{label:"Text Position",value:e.label.position,onChange:l=>u("label.position",l)})]}),n(a.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(a.Group,{grow:!0,noWrap:!0,children:[r&&n(a.Select,{label:"X Axis",data:r,value:e.xAxisIndex,onChange:l=>u("xAxisIndex",l)}),i&&n(a.Select,{label:"Y Axis",data:i,value:e.yAxisIndex,onChange:l=>u("xAxisIndex",l)})]}),p(a.Stack,{spacing:0,children:[n(a.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(a.Select,{icon:n(a.Text,{children:"x"}),data:s,value:e.leftBottomPoint.x_data_key,onChange:l=>u("leftBottomPoint.x_data_key",l??""),clearable:!0}),n(a.Select,{icon:n(a.Text,{children:"y"}),data:s,value:e.leftBottomPoint.y_data_key,onChange:l=>u("leftBottomPoint.y_data_key",l??""),clearable:!0})]})]}),p(a.Stack,{spacing:0,children:[n(a.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(a.Select,{icon:n(a.Text,{children:"x"}),data:s,value:e.rightTopPoint.x_data_key,onChange:l=>u("rightTopPoint.x_data_key",l??""),clearable:!0}),n(a.Select,{icon:n(a.Text,{children:"y"}),data:s,value:e.rightTopPoint.y_data_key,onChange:l=>u("rightTopPoint.y_data_key",l??""),clearable:!0})]})]}),n(a.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:14,children:"Background Color"}),n(De,{value:e.itemStyle.color,onChange:l=>u("itemStyle.color",l)})]}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:14,children:"Text Color"}),n(De,{value:e.label.color,onChange:l=>u("label.color",l)})]})]})});function $h(){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 zh({control:e,watch:t,variables:r}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_areas"}),u=t("reference_areas"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>{const h=$h();s(h)},c=b.useMemo(()=>r.map(h=>({label:h.name,value:h.name})),[r]),f=t("y_axes"),g=b.useMemo(()=>f.map(({name:h},m)=>({label:h,value:m.toString()})),[f]);return p(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:m.toString(),children:m+1},m)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:m.toString(),children:n(x.Controller,{name:`reference_areas.${m}`,control:e,render:({field:w})=>p(a.Stack,{children:[n(Ah,{variableOptions:c,yAxisOptions:g,...w}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(V.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const Eh=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Lh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Ph({control:e,index:t,remove:r,watch:i,variableOptions:s,yAxisOptions:o}){const u=i(`reference_lines.${t}.orientation`);return p(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:l})=>n(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...l})}),n(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:l})=>n(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...l})})]}),n(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:l})=>n(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...l})}),p(a.Group,{grow:!0,children:[p(a.Stack,{children:[n(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:l})=>n(a.Select,{label:"Orientation",data:Lh,required:!0,sx:{flex:1},...l})}),u==="vertical"&&n(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),u==="horizontal"&&n(x.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:d,...c}})=>n(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:f=>{if(!f){d(0);return}d(Number(f))},sx:{flex:1}})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:l})=>n(a.Select,{label:"Line Type",data:Eh,sx:{flexGrow:1},...l})}),n(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:l})=>n(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:"sm",children:"Color"}),n(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:l})=>n(De,{...l})})]}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Oh({control:e,watch:t,variables:r}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),u=t("reference_lines"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>{const h={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:je.random().css()},show_in_legend:!1,yAxisIndex:0};s(h)},c=b.useMemo(()=>r.map(h=>({label:h.name,value:h.name})),[r]),f=t("y_axes"),g=b.useMemo(()=>f.map(({name:h},m)=>({label:h,value:m.toString()})),[f]);return p(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:m.toString(),children:m+1},m)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:m.toString(),children:n(Ph,{control:e,index:m,remove:o,watch:t,variableOptions:c,yAxisOptions:g})},m))]})}const Vh=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{children:n(_e,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Bh=({value:e,onChange:t,data:r})=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o();const{type:h,func_content:m}=u,w={type:h,func_content:m};l(w),t(w)},c=()=>{o(),l(e)},f=h=>{l(m=>({...m,func_content:h}))},g=()=>{f(Dt.dynamic.func_content)};return p(B,{children:[n(a.Box,{sx:{width:"50%"},children:n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Setup"})}),n(a.Modal,{size:800,title:"Setup dynamic color",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),n(Vh,{value:u.func_content,onChange:f}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},Nh=({value:e,onChange:t,data:r})=>e.type!=="dynamic"?null:n(Bh,{value:e,onChange:t,data:r}),Gh=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=i=>{t({...e,color:i})};return n(a.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:r})},qh=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Fh=b.forwardRef(({label:e="Color",value:t,onChange:r,data:i},s)=>{const o=u=>{r({...Dt[u]})};return p(a.SimpleGrid,{cols:2,children:[n(a.Select,{ref:s,label:e,data:qh,value:t.type,onChange:o,sx:{flexGrow:1}}),n(Gh,{value:t,onChange:r}),n(Nh,{value:t,onChange:r,data:i})]})}),Wh=b.forwardRef(({value:e,onChange:t},r)=>{const i=o=>{t({...e,label:o})},s=o=>{t({...e,tooltip:o})};return p(a.Stack,{ref:r,spacing:0,children:[n(Wt,{sectionTitle:"Overflow on Chart",value:e.label,onChange:i}),n(Wt,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:s})]})}),jh=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{children:n(_e,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Da={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
226
|
-
`)}},Rh=({value:e,onChange:t,data:r})=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o();const{type:h,func_content:m}=u,w={type:h,func_content:m};l(w),t(w)},c=()=>{o(),l(e)},f=h=>{l(m=>({...m,func_content:h}))},g=()=>{f(Da.dynamic.func_content)};return p(B,{children:[n(a.Box,{sx:{width:"50%"},children:n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Setup"})}),n(a.Modal,{size:800,title:"Setup dynamic size",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),n(jh,{value:u.func_content,onChange:f}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},Yh=({value:e,onChange:t,data:r})=>e.type!=="dynamic"?null:n(Rh,{value:e,onChange:t,data:r}),Qh=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=i=>{t({...e,size:i})};return n(B,{children:n(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:r})})},Uh=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Xh=b.forwardRef(({label:e="Size",value:t,onChange:r,data:i},s)=>{const o=u=>{r({...Da[u]})};return p(a.SimpleGrid,{cols:2,children:[n(a.Select,{ref:s,label:e,data:Uh,value:t.type,onChange:o,sx:{flexGrow:1}}),n(Qh,{value:t,onChange:r}),n(Yh,{value:t,onChange:r,data:i})]})}),Zh=[{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 Kh({data:e,control:t,watch:r}){return r(["scatter"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"scatter.name_data_key",control:t,render:({field:i})=>n(R,{label:"Name Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"scatter.y_data_key",control:t,render:({field:i})=>n(R,{label:"Value Data Field",required:!0,data:e,sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"Style",labelPosition:"center"}),n(x.Controller,{name:"scatter.symbolSize",control:t,render:({field:i})=>n(Xh,{label:"Size",data:e,...i})}),n(x.Controller,{name:"scatter.color",control:t,render:({field:i})=>n(Fh,{data:e,...i})}),n(a.Divider,{mb:-15,label:"Label",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"scatter.label_position",control:t,render:({field:i})=>n(a.Select,{label:"Label Position",data:Zh,...i})})}),n(x.Controller,{name:"scatter.label_overflow",control:t,render:({field:i})=>n(Wh,{...i})})]})}function Jh({control:e,watch:t}){return t("stats"),n(a.Stack,{children:p(a.Stack,{spacing:0,children:[n(x.Controller,{name:"stats.templates.top",control:e,render:({field:r})=>n(_t,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...r})}),n(x.Controller,{name:"stats.templates.bottom",control:e,render:({field:r})=>n(_t,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...r})})]})})}const Hh=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`tooltip.metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`tooltip.metrics.${r}.data_key`,control:e,render:({field:s})=>n(R,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),ef=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"tooltip.metrics"}),u=t("tooltip.metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(Hh,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function tf({data:e,control:t,watch:r}){return n(ef,{control:t,watch:r,data:e})}const nf=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},rf=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e);b.useEffect(()=>{l(e)},[e]);const d=m=>{l({...u,enabled:m})},c=()=>{o();const{enabled:m,func_content:w}=u,C={enabled:m,func_content:w};l(C),t(C)},f=()=>{o(),l(e)},g=m=>{l(w=>({...w,func_content:m}))},h=()=>{g(_a.func_content)};return p(B,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),n(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:m=>d(m.currentTarget.checked)}),n(nf,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:h,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:c,children:"OK"})]})]})]})})]})});function af({data:e,control:t,watch:r}){return r(["x_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.data_key",control:t,render:({field:i})=>n(R,{label:"Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"x_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"Name",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:i})=>n(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:n(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...i})}),n(x.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:i})=>n(rf,{data:e,...i})})]})]})}const sf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],of=[{label:"left",value:"left"},{label:"right",value:"right"}];function lf({control:e,index:t,remove:r}){return p(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:i})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),n(x.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:i})=>n(a.Select,{label:"Align",required:!0,data:sf,sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:i})=>n(a.Select,{label:"Position",required:!0,data:of,sx:{flex:1},...i})})}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),n(x.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:i})=>n(Oe,{...i})})]}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:i})=>n(a.TextInput,{label:"Min",...i})}),n(x.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:i})=>n(a.TextInput,{label:"Max",...i})})]})]}),n(a.Button,{mt:20,leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),disabled:t===0,children:"Delete this YAxis"})]})}function uf({control:e,watch:t}){const{fields:r,append:i,remove:s}=x.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),u=r.map((d,c)=>({...d,...o[c]})),l=()=>i({name:"",label_formatter:Se});return p(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[u.map((d,c)=>n(a.Tabs.Tab,{value:c.toString(),children:c+1},c)),n(a.Tabs.Tab,{onClick:l,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),u.map((d,c)=>n(a.Tabs.Panel,{value:c.toString(),children:n(lf,{control:e,index:c,remove:s})},c))]})}function df(e){return e||{templates:{top:"",bottom:""}}}function cf({reference_lines:e=[],stats:t,...r}){return{reference_lines:e,stats:df(t),...r}}function pf({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,o=b.useMemo(()=>v.defaultsDeep({},t,jn),[t]),u=b.useMemo(()=>cf(o),[o]);b.useEffect(()=>{!v.isEqual(o,u)&&(console.log("config malformed, resetting to defaults",o,u),r(u))},[o,u]);const{control:l,handleSubmit:d,watch:c,getValues:f,reset:g}=x.useForm({defaultValues:u});b.useEffect(()=>{g(u)},[u]);const h=f(),m=b.useMemo(()=>!v.isEqual(h,o),[h,o]);return c(["dataZoom"]),n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:d(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!m,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),n(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),n(a.Tabs.Tab,{value:"Scatter",children:"Scatter"}),n(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),n(a.Tabs.Tab,{value:"Stats",children:"Stats"}),n(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),n(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),n(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),n(a.Tabs.Panel,{value:"X Axis",children:n(af,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Y Axes",children:n(uf,{control:l,watch:c})}),n(a.Tabs.Panel,{value:"Scatter",children:n(Kh,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Tooltip",children:n(tf,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Stats",children:n(Jh,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Reference Lines",children:n(Oh,{variables:i,control:l,watch:c})}),n(a.Tabs.Panel,{value:"Reference Areas",children:n(zh,{variables:i,control:l,watch:c})}),n(a.Tabs.Panel,{value:"Zooming",children:n(x.Controller,{name:"dataZoom",control:l,render:({field:w})=>n(Pn,{...w})})})]})]})})}function hf(e){const{dataZoom:t=ct,...r}=e;return{...r,dataZoom:t}}function ff(e){const t={scatter:{label_overflow:Sa}};return v.defaultsDeep(t,e)}function gf(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...Dt.static,color:t}}}:e}function mf(e){const t=e.reference_lines.map(r=>{const{lineStyle:i={type:"dashed",width:1,color:je.random().css()},show_in_legend:s=!1,yAxisIndex:o=0}=r;return{...r,lineStyle:i,show_in_legend:s,yAxisIndex:o}});return{...e,reference_lines:t}}class bf extends he{constructor(){super(...arguments);O(this,"VERSION",7)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{tooltip:i={metrics:[]},...s}=r.config;return{...r,version:2,config:{...s,tooltip:i}}}),this.version(3,r=>({...r,version:3,config:hf(r.config)})),this.version(4,r=>{const{config:i}=r;return{...r,version:5,config:ff(i)}}),this.version(6,r=>{const{config:i}=r;return{...r,version:6,config:gf(i)}}),this.version(7,r=>{const{config:i}=r;return{...r,version:7,config:mf(i)}})}}const yf={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new bf,name:"scatterChart",viewRender:Ih,configRender:pf,createConfig(){return{version:7,config:v.cloneDeep(jn)}},triggers:[wa]},Rn={align:"center",template:"The variable ${value} is defined in Variables section"};function vf(e){if("variables"in e)return e;const{align:t,size:r,weight:i,color:s,content:{prefix:o="",data_field:u="value",formatter:l={output:"number",mantissa:0},postfix:d=""}={}}=e;return{align:t,template:`${o} \${value} ${d}`,variables:[{name:"value",data_field:u,aggregation:{type:"none",config:{}},formatter:l,color:s,weight:i,size:r}]}}function xf(e){return v.omit(e,["variables"])}function Cf(e){const t=v.cloneDeep(e),r=v.get(t,"color.valueRange");return r!==void 0&&v.set(t,"color.valueRange",r.map(i=>Number(i))),t}class wf extends he{constructor(){super(...arguments);O(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:vf(r)})),this.version(2,(r,{panelModel:i})=>{const{config:s}=r;return(s.variables||[]).forEach(u=>{i.variables.find(l=>l.name===u.name)||i.addVariable(Cf(u))}),{...r,version:2,config:xf(s)}})}}const _f=T.observer(({context:e})=>{const t=F(),{value:r=Rn}=W(e.instanceData,"config"),{variables:i}=e,{template:s,align:o}=r,u=b.useMemo(()=>{try{const d={filters:t.payloadForSQL.filterValues,context:t.payloadForSQL.context};return v.template(s)(d)}catch{return s}},[t.payloadForSQL,s]),l=b.useMemo(()=>kt(u,i,e.data),[u,i,e.data,e]);return n(a.Text,{align:o,children:Object.values(l).map((d,c)=>n(b.Fragment,{children:d},c))})}),Sf=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Tf({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=b.useMemo(()=>{const{align:g,template:h=""}=v.defaultsDeep({},t,Rn);return{template:h,align:g}},[t]),{control:s,handleSubmit:o,watch:u,getValues:l,reset:d}=x.useForm({defaultValues:i});b.useEffect(()=>{d(i)},[i]),u(["template","align"]);const c=l(),f=b.useMemo(()=>!v.isEqual(c,t),[c,t]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:o(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{weight:500,children:"Stats Configurations"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:n(k.DeviceFloppy,{size:20})})]}),n(x.Controller,{name:"template",control:s,render:({field:g})=>n(_t,{label:"Template",py:"md",sx:{flexGrow:1},...g})}),n(x.Controller,{name:"align",control:s,render:({field:g})=>n(a.Select,{label:"Horizontal Alignment",data:Sf,...g})})]})})}const kf={createConfig(){return{version:2,config:Rn}},displayName:"Stats",displayGroup:"Others",migrator:new wf,name:"stats",viewRender:_f,configRender:Tf},Yn={label_key:"",value_key:"",group_key:"",levels:[]};function Df(e){const t=new Set(e.map(i=>i.parent_id)),r=new Set(e.map(i=>i.id));return t.forEach(i=>{i===null||r.has(i)||e.push({id:i,name:i,parent_id:null})}),e}function Mf(e){const t=Df(e).map(s=>({...s,children:[]})),r=v.keyBy(t,s=>s.id),i=[];return t.forEach(s=>{if(!s.parent_id||!r[s.parent_id]){i.push(s);return}r[s.parent_id].children.push(s)}),i}function If(e,t){const{label_key:r,value_key:i,group_key:s}=e,o=r,u=t.map(l=>({...l,id:l[o],parent_id:l[s],name:l[r],value:l[i]?Number(l[i]):l[i]}));return s?Mf(u):u}const Af=e=>({treePathInfo:t,name:r,value:i})=>{if(t.length===1||!e)return r;try{const s=t[t.length-2].value;if(i/s<e)return" "}catch{return r}};function $f(e){const{levels:t}=e;return t.map(r=>{const{show_label_tolerance:i,...s}=r.label;return{...r,label:{...s,formatter:Af(i)}}})}function zf(){return({treePathInfo:e,name:t,value:r,color:i,marker:s,...o})=>{const u=e.slice(0,e.length-1),l=[`<tr>
|
|
226
|
+
`)}},Rh=({value:e,onChange:t,data:r})=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o();const{type:h,func_content:m}=u,w={type:h,func_content:m};l(w),t(w)},c=()=>{o(),l(e)},f=h=>{l(m=>({...m,func_content:h}))},g=()=>{f(Da.dynamic.func_content)};return p(B,{children:[n(a.Box,{sx:{width:"50%"},children:n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Setup"})}),n(a.Modal,{size:800,title:"Setup dynamic size",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),n(jh,{value:u.func_content,onChange:f}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},Yh=({value:e,onChange:t,data:r})=>e.type!=="dynamic"?null:n(Rh,{value:e,onChange:t,data:r}),Qh=({value:e,onChange:t})=>{if(e.type!=="static")return null;const r=i=>{t({...e,size:i})};return n(B,{children:n(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:r})})},Uh=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Xh=b.forwardRef(({label:e="Size",value:t,onChange:r,data:i},s)=>{const o=u=>{r({...Da[u]})};return p(a.SimpleGrid,{cols:2,children:[n(a.Select,{ref:s,label:e,data:Uh,value:t.type,onChange:o,sx:{flexGrow:1}}),n(Qh,{value:t,onChange:r}),n(Yh,{value:t,onChange:r,data:i})]})}),Zh=[{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 Kh({data:e,control:t,watch:r}){return r(["scatter"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"scatter.name_data_key",control:t,render:({field:i})=>n(R,{label:"Name Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"scatter.y_data_key",control:t,render:({field:i})=>n(R,{label:"Value Data Field",required:!0,data:e,sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"Style",labelPosition:"center"}),n(x.Controller,{name:"scatter.symbolSize",control:t,render:({field:i})=>n(Xh,{label:"Size",data:e,...i})}),n(x.Controller,{name:"scatter.color",control:t,render:({field:i})=>n(Fh,{data:e,...i})}),n(a.Divider,{mb:-15,label:"Label",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"scatter.label_position",control:t,render:({field:i})=>n(a.Select,{label:"Label Position",data:Zh,...i})})}),n(x.Controller,{name:"scatter.label_overflow",control:t,render:({field:i})=>n(Wh,{...i})})]})}function Jh({control:e,watch:t}){return t("stats"),n(a.Stack,{children:p(a.Stack,{spacing:0,children:[n(x.Controller,{name:"stats.templates.top",control:e,render:({field:r})=>n(_t,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...r})}),n(x.Controller,{name:"stats.templates.bottom",control:e,render:({field:r})=>n(_t,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...r})})]})})}const Hh=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`tooltip.metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`tooltip.metrics.${r}.data_key`,control:e,render:({field:s})=>n(R,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),ef=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"tooltip.metrics"}),u=t("tooltip.metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(Hh,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function tf({data:e,control:t,watch:r}){return n(ef,{control:t,watch:r,data:e})}const nf=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},rf=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e);b.useEffect(()=>{l(e)},[e]);const d=m=>{l({...u,enabled:m})},c=()=>{o();const{enabled:m,func_content:w}=u,C={enabled:m,func_content:w};l(C),t(C)},f=()=>{o(),l(e)},g=m=>{l(w=>({...w,func_content:m}))},h=()=>{g(_a.func_content)};return p(B,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),n(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:m=>d(m.currentTarget.checked)}),n(nf,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:h,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:c,children:"OK"})]})]})]})})]})});function af({data:e,control:t,watch:r}){return r(["x_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.data_key",control:t,render:({field:i})=>n(R,{label:"Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"x_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"Name",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:i})=>n(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:n(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...i})}),n(x.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:i})=>n(rf,{data:e,...i})})]})]})}const sf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],of=[{label:"left",value:"left"},{label:"right",value:"right"}];function lf({control:e,index:t,remove:r}){return p(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:i})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),n(x.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:i})=>n(a.Select,{label:"Align",required:!0,data:sf,sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:i})=>n(a.Select,{label:"Position",required:!0,data:of,sx:{flex:1},...i})})}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),n(x.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:i})=>n(Oe,{...i})})]}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:i})=>n(a.TextInput,{label:"Min",...i})}),n(x.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:i})=>n(a.TextInput,{label:"Max",...i})})]})]}),n(a.Button,{mt:20,leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),disabled:t===0,children:"Delete this YAxis"})]})}function uf({control:e,watch:t}){const{fields:r,append:i,remove:s}=x.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),u=r.map((d,c)=>({...d,...o[c]})),l=()=>i({name:"",label_formatter:Se});return p(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[u.map((d,c)=>n(a.Tabs.Tab,{value:c.toString(),children:c+1},c)),n(a.Tabs.Tab,{onClick:l,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),u.map((d,c)=>n(a.Tabs.Panel,{value:c.toString(),children:n(lf,{control:e,index:c,remove:s})},c))]})}function df(e){return e||{templates:{top:"",bottom:""}}}function cf({reference_lines:e=[],stats:t,...r}){return{reference_lines:e,stats:df(t),...r}}function pf({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,o=b.useMemo(()=>v.defaultsDeep({},t,jn),[t]),u=b.useMemo(()=>cf(o),[o]);b.useEffect(()=>{!v.isEqual(o,u)&&(console.log("config malformed, resetting to defaults",o,u),r(u))},[o,u]);const{control:l,handleSubmit:d,watch:c,getValues:f,reset:g}=x.useForm({defaultValues:u});b.useEffect(()=>{g(u)},[u]);const h=f(),m=b.useMemo(()=>!v.isEqual(h,o),[h,o]);return c(["dataZoom"]),n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:d(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!m,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),n(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),n(a.Tabs.Tab,{value:"Scatter",children:"Scatter"}),n(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),n(a.Tabs.Tab,{value:"Stats",children:"Stats"}),n(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),n(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),n(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),n(a.Tabs.Panel,{value:"X Axis",children:n(af,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Y Axes",children:n(uf,{control:l,watch:c})}),n(a.Tabs.Panel,{value:"Scatter",children:n(Kh,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Tooltip",children:n(tf,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Stats",children:n(Jh,{control:l,watch:c,data:s})}),n(a.Tabs.Panel,{value:"Reference Lines",children:n(Oh,{variables:i,control:l,watch:c})}),n(a.Tabs.Panel,{value:"Reference Areas",children:n(zh,{variables:i,control:l,watch:c})}),n(a.Tabs.Panel,{value:"Zooming",children:n(x.Controller,{name:"dataZoom",control:l,render:({field:w})=>n(Pn,{...w})})})]})]})})}function hf(e){const{dataZoom:t=ct,...r}=e;return{...r,dataZoom:t}}function ff(e){const t={scatter:{label_overflow:Sa}};return v.defaultsDeep(t,e)}function gf(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...Dt.static,color:t}}}:e}function mf(e){const t=e.reference_lines.map(r=>{const{lineStyle:i={type:"dashed",width:1,color:je.random().css()},show_in_legend:s=!1,yAxisIndex:o=0}=r;return{...r,lineStyle:i,show_in_legend:s,yAxisIndex:o}});return{...e,reference_lines:t}}class bf extends he{constructor(){super(...arguments);O(this,"VERSION",7)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{tooltip:i={metrics:[]},...s}=r.config;return{...r,version:2,config:{...s,tooltip:i}}}),this.version(3,r=>({...r,version:3,config:hf(r.config)})),this.version(4,r=>{const{config:i}=r;return{...r,version:5,config:ff(i)}}),this.version(6,r=>{const{config:i}=r;return{...r,version:6,config:gf(i)}}),this.version(7,r=>{const{config:i}=r;return{...r,version:7,config:mf(i)}})}}const yf={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new bf,name:"scatterChart",viewRender:Ih,configRender:pf,createConfig(){return{version:7,config:v.cloneDeep(jn)}},triggers:[wa]},Rn={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function vf(e){if("variables"in e)return e;const{align:t,size:r,weight:i,color:s,content:{prefix:o="",data_field:u="value",formatter:l={output:"number",mantissa:0},postfix:d=""}={}}=e;return{align:t,template:`${o} \${value} ${d}`,variables:[{name:"value",data_field:u,aggregation:{type:"none",config:{}},formatter:l,color:s,weight:i,size:r}]}}function xf(e){return v.omit(e,["variables"])}function Cf(e){const{align:t,...r}=e;return{horizontal_align:t,vertical_align:"center",...r}}function wf(e){const t=v.cloneDeep(e),r=v.get(t,"color.valueRange");return r!==void 0&&v.set(t,"color.valueRange",r.map(i=>Number(i))),t}class _f extends he{constructor(){super(...arguments);O(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:vf(r)})),this.version(2,(r,{panelModel:i})=>{const{config:s}=r;return(s.variables||[]).forEach(u=>{i.variables.find(l=>l.name===u.name)||i.addVariable(wf(u))}),{...r,version:2,config:xf(s)}}),this.version(3,r=>{const{config:i}=r;return{...r,version:3,config:Cf(i)}})}}const Sf={left:"flex-start",center:"center",right:"flex-end"},Tf={top:"flex-start",center:"center",bottom:"flex-end"},kf=T.observer(({context:e})=>{const t=F(),{value:r=Rn}=W(e.instanceData,"config"),{variables:i}=e,{template:s,horizontal_align:o,vertical_align:u}=r,{width:l,height:d}=e.viewport,c=b.useMemo(()=>{try{const g={filters:t.payloadForSQL.filterValues,context:t.payloadForSQL.context};return v.template(s)(g)}catch{return s}},[t.payloadForSQL,s]),f=b.useMemo(()=>kt(c,i,e.data),[c,i,e.data,e]);return n(a.Center,{sx:{width:l,height:d,justifyContent:Sf[o],alignItems:Tf[u]},children:n(a.Box,{children:Object.values(f).map((g,h)=>n(b.Fragment,{children:g},h))})})}),Df=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Mf=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function If({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=b.useMemo(()=>v.defaultsDeep({},t,Rn),[t]),{control:s,handleSubmit:o,watch:u,getValues:l,reset:d}=x.useForm({defaultValues:i});b.useEffect(()=>{d(i)},[i]),u(["template","horizontal_align","vertical_align"]);const c=l(),f=b.useMemo(()=>!v.isEqual(c,t),[c,t]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:o(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{weight:500,children:"Stats Configurations"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:n(k.DeviceFloppy,{size:20})})]}),n(x.Controller,{name:"template",control:s,render:({field:g})=>n(_t,{label:"Template",py:"md",sx:{flexGrow:1},...g})}),p(a.SimpleGrid,{cols:2,children:[n(x.Controller,{name:"horizontal_align",control:s,render:({field:g})=>n(a.Select,{label:"Horizontal Alignment",data:Df,...g})}),n(x.Controller,{control:s,name:"vertical_align",render:({field:g})=>n(a.Select,{label:"Vertical Alignment",data:Mf,...g})})]})]})})}const Af={createConfig(){return{version:3,config:Rn}},displayName:"Stats",displayGroup:"Others",migrator:new _f,name:"stats",viewRender:kf,configRender:If},Yn={label_key:"",value_key:"",group_key:"",levels:[]};function $f(e){const t=new Set(e.map(i=>i.parent_id)),r=new Set(e.map(i=>i.id));return t.forEach(i=>{i===null||r.has(i)||e.push({id:i,name:i,parent_id:null})}),e}function zf(e){const t=$f(e).map(s=>({...s,children:[]})),r=v.keyBy(t,s=>s.id),i=[];return t.forEach(s=>{if(!s.parent_id||!r[s.parent_id]){i.push(s);return}r[s.parent_id].children.push(s)}),i}function Ef(e,t){const{label_key:r,value_key:i,group_key:s}=e,o=r,u=t.map(l=>({...l,id:l[o],parent_id:l[s],name:l[r],value:l[i]?Number(l[i]):l[i]}));return s?zf(u):u}const Lf=e=>({treePathInfo:t,name:r,value:i})=>{if(t.length===1||!e)return r;try{const s=t[t.length-2].value;if(i/s<e)return" "}catch{return r}};function Pf(e){const{levels:t}=e;return t.map(r=>{const{show_label_tolerance:i,...s}=r.label;return{...r,label:{...s,formatter:Lf(i)}}})}function Of(){return({treePathInfo:e,name:t,value:r,color:i,marker:s,...o})=>{const u=e.slice(0,e.length-1),l=[`<tr>
|
|
227
227
|
<th style="text-align: right; padding: 0 1em;">Value</th>
|
|
228
228
|
<td style="text-align: left; padding: 0 1em;">${r}</td>
|
|
229
229
|
</tr>
|
|
@@ -241,9 +241,9 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
241
241
|
<table style="width: auto">
|
|
242
242
|
<tbody>${l.join("")}</tbody>
|
|
243
243
|
</table>
|
|
244
|
-
`}}function
|
|
245
|
-
`),Qn={columns:[],fontSize:"1rem",highlightOnHover:!1,horizontalSpacing:"1em",id_field:"",striped:!1,use_raw_columns:!0,verticalSpacing:"1em"},Ia={left:"flex-start",center:"center",right:"flex-end"},Uf=({header:e,cx:t})=>{const r=v.get(e.column.columnDef.meta,"align","left");return p(a.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:r,sx:{justifyContent:Ia[r]},children:[e.isPlaceholder?null:Pe.flexRender(e.column.columnDef.header,e.getContext()),n(Xf,{direction:e.column.getIsSorted()})]})},Xf=({direction:e})=>{switch(e){case"asc":return n(V.IconArrowUp,{size:16});case"desc":return n(V.IconArrowDown,{size:"1em"});default:return null}},Un={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:eg,configRender:Jf,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"}]},Zf={column:""};function Aa(e){const{value:t}=W(e.instanceData,"config");return t?t.columns.map((r,i)=>({label:r.label,value:i.toString()})):[]}function Kf(e){return v.isEmpty(e)?[]:Object.keys(e[0]).map(t=>({label:t,value:t}))}function Jf(e){const t=Aa(e.instance),r=Kf(e.sampleData),i=t.length>0?t:r,{value:s,set:o}=W(e.trigger.triggerData,"config"),{column:u}=v.defaults({},s,Zf),l=d=>{isNaN(+d)?o({column:d}):o({column:+d})};return n(a.Select,{clearable:!1,data:i,label:"Choose a column",value:u.toString(),onChange:l})}function Hf(e,t){return e?v.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function eg(e){const t=Aa(e.instance),{value:r}=W(e.trigger.triggerData,"config");return n(a.Text,{children:Hf(r,t)})}const tg=a.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10,"&::after":{content:'" "',display:"block",background:"white",position:"absolute",left:0,right:0,top:0,bottom:0,zIndex:-1}},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),ng={tableLayout:"fixed","th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}};function $a(e,t,r){return Math.min(Math.max(e,t),r)}class rg{constructor(t){this.steps=t;const r=[],i=new Set;for(const s of t)i.has(s.to)||(r.push(s),i.add(s.to));if(r.sort((s,o)=>s.from-o.from),r.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=r}getLinearFunction(t,r){const i=(r.to-t.to)/(r.from-t.from),s=t.to-i*t.from;return o=>i*o+s}getStepFunctionForValue(t){let r=v.findLastIndex(this.steps,i=>i.from<=t);return r=$a(r,0,this.steps.length-2),this.getLinearFunction(this.steps[r],this.steps[r+1])}mapValue(t){return $a(this.getStepFunctionForValue(t)(t),0,100)}}class ig{constructor(t,r,i,s,o){this.getColIndex=t,this.cell=r,this.triggers=i,this.interactionManager=s,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const r={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const i of t)this.interactionManager.runInteraction(i.id,r)}}getRelatedTrigger(){return this.triggers.filter(r=>r.schemaRef===Un.id).filter(r=>{const i=this.getColIndex(this.cell),s=v.get(this.cell.column.columnDef.meta,"value_field"),o=v.get(r.config,"column");return o==i||o==s})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(v.isString(t))return t;const r=+this.cell.getValue();if(isFinite(r)){const i=this.colorManager.decodeInterpolation(t.interpolation),o=new rg(t.steps).mapValue(r);return i==null?void 0:i.getColor(o)}}}const ag=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:Ia[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function sg(e){return e?je(e).oklch()[0]>.7?"black":"white":"inherit"}function og(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:sg(t)}}function pt(e){const t=e.tableCellContext.isClickable(),r=ag({clickable:t,align:e.align});return n("div",{className:r.classes.content,style:{...og(e)},children:n(a.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:n("span",{title:e.children,children:e.children})})})}function lg(e){return n(pt,{...e,children:e.value})}function ug(e){const t=te(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return n(pt,{...e,children:t})}function dg(e){const t=te(e.value).format({thousandSeparated:!0});return n(pt,{...e,children:t})}function cg(e){const t=te(e.value).format({output:"percent",mantissa:3});return n(pt,{...e,children:t})}function pg(e){const t=e.value,r=e.func_content;if(!r)return n(pt,{...e,children:t});const i=new Function(`return ${r}`)()({value:t});return n(pt,{...e,children:i})}function hg(e){switch(e.type){case Be.string:return n(lg,{...e});case Be.eloc:return n(ug,{...e});case Be.number:return n(dg,{...e});case Be.percentage:return n(cg,{...e});case Be.custom:return n(pg,{...e})}}const fg=e=>{const t=Fe(e),r=Ne(t.triggerManager,Un.id),{colorManager:i}=b.useContext(qe);return b.useCallback(s=>new ig(e.getColIndex,s,r,t,i),[r,t,e.getColIndex])};function gg({context:e,instance:t}){var ie,oe;const r=e.data??[],{height:i,width:s}=e.viewport,{value:o=Qn}=W(e.instanceData,"config"),{use_raw_columns:u,columns:l,...d}=o,{classes:c,cx:f}=tg(),g=b.useMemo(()=>u?!Array.isArray(r)||r.length===0?[]:Object.keys(r[0]).map(re=>({id:re,label:re,value_field:re,value_type:Be.string,align:"left"})):l,[u,l,r]),h=fg({getColIndex:b.useCallback(re=>g.indexOf(re.column.columnDef.meta),[g]),vizManager:e.vizManager,instance:t}),m=b.useMemo(()=>{const re=Pe.createColumnHelper();return g.map(fe=>re.accessor(fe.value_field,{cell:Te=>n(hg,{tableCellContext:h(Te.cell),value:Te.getValue(),type:fe.value_type,...fe}),header:fe.label,enableSorting:!0,meta:fe,size:fe.width,minSize:fe.width}))},[g,h]),[w,C]=b.useState([]),S=Pe.useReactTable({data:r,state:{sorting:w},onSortingChange:C,columns:m,getCoreRowModel:Pe.getCoreRowModel(),getSortedRowModel:Pe.getSortedRowModel()}),{rows:I}=S.getRowModel(),$=b.useRef(null),P=go.useVirtual({parentRef:$,size:I.length,estimateSize:b.useCallback(()=>28,[]),overscan:20}),{virtualItems:q,totalSize:L}=P,z=q.length>0&&((ie=q==null?void 0:q[0])==null?void 0:ie.start)||0,A=q.length>0?L-(((oe=q==null?void 0:q[q.length-1])==null?void 0:oe.end)||0):0,G=I.length,U=G>0,Q=U?i-22:i,ne=U?22:0;return!Array.isArray(r)||r.length===0?n(a.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:$,style:{height:i,width:s},"data-enable-scrollbar":!0,className:f(c.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[G>0&&n(a.Box,{className:c.info_bar,sx:{height:22},children:p(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",G]})}),p(a.Table,{sx:{...ng,maxHeight:Q},...d,striped:o.striped,children:[n("thead",{className:c.thead,style:{top:ne},children:S.getHeaderGroups().map(re=>n("tr",{children:re.headers.map(pe=>n("th",{style:{width:pe.getSize()},children:n(Uf,{header:pe,cx:f})},pe.id))},re.id))}),p("tbody",{children:[z>0&&n("tr",{children:n("td",{style:{height:`${z}px`}})}),q.map(re=>{const pe=I[re.index];return n("tr",{children:pe.getVisibleCells().map(fe=>n("td",{children:Pe.flexRender(fe.column.columnDef.cell,fe.getContext())},fe.id))},pe.id)}),A>0&&n("tr",{children:n("td",{style:{height:`${A}px`}})})]})]})]})}const za=a.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),mg=[{from:0,to:0},{from:100,to:100}];class bg{constructor(){O(this,"steps",new Map);O(this,"interpolation");O(this,"onChange");se.makeAutoObservable(this,{steps:se.observable},{deep:!1}),se.reaction(()=>se.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const r of t)this.steps.set(r.to,r.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([r,i])=>({to:r,from:i})).sort((r,i)=>r.to-i.to||r.from-i.from))}fromProps(t){t.steps.length<2?this.setSteps(mg):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,r){t==null?this.steps.delete(r):this.steps.set(r,t)}getStepFromValue(t){return this.steps.get(t)}}function yg(e){const{onChange:t,color:r,index:i,value:s}=e,{classes:o}=za(),[u,l]=b.useState(s),[d,{setTrue:c,setFalse:f}]=Z.useBoolean(!1),g=i%2===1,h=g&&s!=null,m=!g&&s!=null,w=`map ${s} to color ${i}`,C=()=>{l(s),f()},S=()=>{f(),t==null||t(u)},I=te(s).format({average:!0});return p("div",{"data-testid":`palette-item-${i}`,className:o.paletteItem,children:[n(a.Text,{title:w,style:{opacity:h?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),p(a.Popover,{width:200,trapFocus:!0,opened:d,onClose:f,children:[n(a.Popover.Target,{children:n("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:c,style:{"--shadow-color":je(r).alpha(.5).hex(),backgroundColor:r}})}),n(a.Popover.Dropdown,{children:p(a.Stack,{children:[n(a.NumberInput,{size:"xs",label:"Map a value to this color",value:u,onChange:l}),p(a.Group,{position:"right",children:[n(a.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),n(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:S,children:"OK"})]})]})})]}),n(a.Text,{title:w,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const vg=T.observer(({model:e})=>{const{classes:t}=za(),r=v.range(0,13,1).map(i=>100/12*i).map(i=>[e.interpolation.getColor(i),i]);return n("div",{className:t.palette,children:r.map(([i,s],o)=>n(yg,{index:o,color:i,value:e.getStepFromValue(s),onChange:u=>e.changeStep(u,s)},i))})}),xg=T.observer(function(t){const r=Z.useCreation(()=>new bg,[]);return b.useEffect(()=>{r.fromProps(t)}),r.interpolation==null?null:n(vg,{model:r})}),Cg=e=>{const{value:t,onChange:r,colorManager:i}=e,s=i.getColorInterpolations(),[o,u]=b.useState(t),l=i.decodeInterpolation(o.interpolation)||s[0],[d,{setTrue:c,setFalse:f}]=Z.useBoolean(),g=s.map(S=>({label:S.displayName,value:i.encodeColor(S),group:S.category}));function h(S){S&&u(I=>({...I,interpolation:S}))}const m=()=>{f(),r==null||r(se.toJS(o))};function w(S){u(I=>({...I,steps:S}))}const C=()=>{f(),u(t)};return p(B,{children:[n(a.Button,{variant:"outline",onClick:c,children:l==null?void 0:l.displayName}),n(a.Modal,{size:508,title:"Setup color interpolation",opened:d,onClose:f,zIndex:320,children:d&&p(a.Stack,{"data-testid":"color-interpolation-modal",children:[n(a.Select,{label:"Color style",value:o.interpolation,data:g,onChange:h}),n(xg,{steps:o.steps,interpolation:l,onChange:w}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:m,children:"OK"})]})]})})]})},wg=["static","interpolation","none"].map(e=>({label:v.capitalize(e),value:e})),_g=[{from:0,to:0},{from:100,to:100}];function Ea(e){return e?v.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Sg(e,t){var r;return Ea(t)==="static"?t:(r=e.getStaticColors()[0])==null?void 0:r.value}function Tg(e,t){return v.isObject(t)?t:{steps:_g,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const kg=b.forwardRef((e,t)=>{const{colorManager:r}=b.useContext(qe),[i,s]=b.useState(Ea(e.value)),[o,u]=b.useState(Sg(r,e.value)),l=Z.useLatest(o),[d,c]=b.useState(Tg(r,e.value)),f=Z.useLatest(d),g=w=>{var C,S,I;s(w||"none"),w==="static"?(C=e.onChange)==null||C.call(e,l.current):w==="none"||!w?(S=e.onChange)==null||S.call(e,"none"):(I=e.onChange)==null||I.call(e,f.current)},h=w=>{var C;u(w),(C=e.onChange)==null||C.call(e,w)},m=w=>{var C;c(w),(C=e.onChange)==null||C.call(e,w)};return p(a.Stack,{align:"stretch",children:[n(a.Select,{label:"Cell background",value:i||"none",onChange:g,data:wg}),i==="static"&&n(De,{value:o,onChange:h}),i==="interpolation"&&n(Cg,{colorManager:r,value:d,onChange:m})]})}),Dg={[Be.eloc]:"ELOC"},Mg=Object.values(Be).map(e=>({label:v.get(Dg,e,v.capitalize(e)),value:e})),Ig=b.forwardRef(({label:e,value:t,onChange:r,sx:i},s)=>n(a.Select,{ref:s,label:e,data:Mg,value:t,onChange:r,sx:i})),Ag=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o(),t(u)},c=()=>{o(),l(e)},f=()=>{l(Ma)};return b.useEffect(()=>{l(e)},[e]),p(B,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Custom Cell Content"}),n(a.Modal,{size:800,title:"Custom cell content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Box,{sx:{position:"relative"},children:n(_e,{height:"500px",defaultLanguage:"javascript",value:u,onChange:g=>l(g??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:f,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),$g=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Xn=()=>n(a.Text,{color:"dimmed",size:12,children:"px"}),zg=({control:e,index:t,watch:r,remove:i,column:s,data:o})=>{const u=r(`columns.${t}.value_type`);return p(a.Stack,{my:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,children:[n(x.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>n(a.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),n(x.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>n(R,{label:"Value Field",required:!0,data:o,...l})})]}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>n(Ig,{label:"Value Type",sx:{flex:1},...l})}),u===Be.custom&&n(x.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>n(Ag,{value:l.value??Ma,onChange:d=>l.onChange(d??"")})})]}),n(a.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(a.NumberInput,{hideControls:!0,label:"Min Width",rightSection:n(Xn,{}),disabled:!0}),n(x.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>n(a.NumberInput,{hideControls:!0,label:"Width",rightSection:n(Xn,{}),...l})}),n(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:n(Xn,{}),disabled:!0})]}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>n(a.Select,{label:"Alignment",data:$g,...l})})}),n(x.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>n(kg,{...l})}),n(a.Divider,{mb:4,mt:12,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(t),children:"Delete this column"})]})},Eg=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o,update:u}=x.useFieldArray({control:e,name:"columns"}),l=()=>{const c=ve.randomId();s({id:c,label:c,value_field:"value",value_type:Be.string})};t("columns");const d=t("use_raw_columns");return p(B,{children:[n(x.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>n(a.Switch,{mt:20,label:"Use Original Data Columns",checked:c.value,onChange:f=>c.onChange(f.currentTarget.checked)})}),n(a.Divider,{mt:20,mb:10,variant:"dashed"}),!d&&p(a.Stack,{children:[n(a.Text,{my:0,children:"Custom Columns"}),p(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[i.map((c,f)=>n(a.Tabs.Tab,{value:f.toString(),children:f+1},c.id)),n(a.Tabs.Tab,{onClick:l,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),i.map((c,f)=>n(a.Tabs.Panel,{value:f.toString(),children:n(zg,{control:e,watch:t,index:f,column:c,data:r,remove:o},f)},c.id))]})]})]})};function Lg({control:e,watch:t,data:r}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(a.Stack,{spacing:"xs",children:[p(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[n(x.Controller,{name:"horizontalSpacing",control:e,render:({field:i})=>n(a.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...i})}),n(x.Controller,{name:"verticalSpacing",control:e,render:({field:i})=>n(a.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...i})})]}),n(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:n(x.Controller,{name:"fontSize",control:e,render:({field:i})=>n(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...i})})}),p(a.Group,{position:"apart",grow:!0,children:[n(x.Controller,{name:"striped",control:e,render:({field:i})=>n(a.Switch,{label:"Striped",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),n(x.Controller,{name:"highlightOnHover",control:e,render:({field:i})=>n(a.Switch,{label:"Highlight on hover",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})})]})]})}function Pg({columns:e,...t}){return{...t,columns:e.map(({id:r,...i})=>({id:r??ve.randomId(),...i}))}}function Og({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,Qn),[t]),o=b.useMemo(()=>Pg(s),[s]);b.useEffect(()=>{!v.isEqual(s,o)&&(console.log("config malformed, resetting to defaults",s,o),r(o))},[s,o]);const{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,s),[g,s]);return d(["id_field"]),p("form",{onSubmit:l(r),children:[p(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Table Config"}),n(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",children:"Data"}),n(a.Tabs.Tab,{value:"Style",children:"Style"}),n(a.Tabs.Tab,{value:"Columns",children:"Columns"})]}),n(a.Tabs.Panel,{value:"Data",children:n(x.Controller,{name:"id_field",control:u,render:({field:m})=>n(R,{label:"ID Field",required:!0,data:i,...m})})}),n(a.Tabs.Panel,{value:"Style",children:n(Lg,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Columns",children:n(Eg,{control:u,watch:d,data:i})})]})]})}function Vg(e){const{columns:t,...r}=e;return{...e,columns:t.map(i=>({...i,align:i.align??"left"}))}}class Bg extends he{constructor(){super(...arguments);O(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{columns:i,...s}=r.config;return{...r,version:2,config:{...s,columns:i.map(({id:o,...u})=>({id:o??ve.randomId(),...u}))}}}),this.version(3,r=>({...r,version:3,config:Vg(r.config)}))}}const Zn={createConfig(){return{version:3,config:v.cloneDeep(Qn)}},displayName:"Table",displayGroup:"Others",migrator:new Bg,name:"table",viewRender:gg,configRender:Og,triggers:[Un]},La=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
246
|
-
`),Kn={func_content:La,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Ng=T.observer(({context:e})=>{const t=F(),{value:r=Kn}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,{func_content:o,horizontal_align:u,font_size:l,font_weight:d}=r,c=b.useMemo(()=>i.reduce((g,h)=>{const m=ut(h,s);return g[h.name]=et(h,m),g},{}),[i,s]),f=b.useMemo(()=>new Function(`return ${o}`)()({data:s,variables:c,filters:t.payloadForSQL.filterValues,context:t.payloadForSQL.context}),[o,s,c,t.payloadForSQL]);return n(a.Text,{align:u,weight:d,sx:{fontSize:l},children:f})}),Gg=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{sx:{position:"relative"},children:n(_e,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},qg=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o(),t(u)},c=()=>{o(),l(e)},f=()=>{l(La)};return b.useEffect(()=>{l(e)},[e]),p(B,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Edit Content"}),n(a.Modal,{size:800,title:"Text content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(Gg,{value:u,onChange:l}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:f,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Fg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Wg({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=b.useMemo(()=>v.defaultsDeep({},t,Kn),[t]),s=b.useMemo(()=>{const{func_content:h,horizontal_align:m,font_size:w,font_weight:C}=i;return{func_content:h,horizontal_align:m,font_size:w,font_weight:C}},[i]);b.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),r(s))},[i,s]);const{control:o,handleSubmit:u,watch:l,getValues:d,reset:c}=x.useForm({defaultValues:s});b.useEffect(()=>{c(s)},[s]),l(["func_content","horizontal_align","font_size","font_weight"]);const f=d(),g=b.useMemo(()=>!v.isEqual(f,i),[f,i]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{weight:500,children:"Configurations"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Stack,{spacing:10,children:[n(x.Controller,{name:"func_content",control:o,render:({field:h})=>n(qg,{...h})}),n(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),n(x.Controller,{name:"horizontal_align",control:o,render:({field:h})=>n(a.Select,{label:"Horizontal Alignment",data:Fg,...h})}),n(x.Controller,{name:"font_size",control:o,render:({field:h})=>n(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...h})}),n(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:n(x.Controller,{name:"font_weight",control:o,render:({field:h})=>n(ra,{label:"Font Weight",...h})})})]})]})})}class jg extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Rg={displayName:"Text",displayGroup:"Others",migrator:new jg,name:"text",viewRender:Ng,configRender:Wg,createConfig(){return{version:1,config:v.cloneDeep(Kn)}}},Yg=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[n("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"}),n("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),n("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 Pa(e,t){const r=v.get(e,t,"");if(r)throw new Error(r)}async function Qg(e,t,r,i={}){const s={"X-Requested-With":"XMLHttpRequest","Content-Type":i.string?"application/x-www-form-urlencoded":"application/json",...i.headers},o={baseURL:e,method:"POST",url:t,params:i.params,headers:s};return o.data=i.string?JSON.stringify(r):r,Xe(o).then(u=>u.data).catch(u=>Promise.reject(u))}const Ug=({conf:e,data:t})=>async()=>{const{expertSystemURL:r,path:i,goal:s,question:o}=e;if(!i||!s||!o)return;const u={dashboard:s,panel:o,data:t};try{const l=r.startsWith("http")?r:window.location.origin;return await Qg(l,`/expert/v3/devtable/${i}`,u,{})}catch(l){throw Pa(l,"response.data.detail"),Pa(l,"response.data.error"),console.error(l),l}},Jn={expertSystemURL:"",path:"",goal:"",question:""},Hn={height:"100%",overflowY:"auto",..._n},Oa=({message:e})=>n(a.Box,{sx:Hn,children:n("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Xg=({error:e,width:t,height:r})=>{const i=e.message;if(i.startsWith("<"))return n(Oa,{message:i});const o=r-25-20-30;return n(a.Center,{sx:{width:"100%",height:o},children:p(a.Stack,{align:"center",spacing:20,children:[n(Yg,{}),n(Oa,{message:i})]})})};function Zg({context:e}){const{value:t}=W(e.instanceData,"config"),r=b.useMemo(()=>v.defaultsDeep({},t,Jn),[t]),{width:i,height:s}=e.viewport,o=e.data??[],{data:u,error:l,loading:d}=Z.useRequest(Ug({conf:r,data:o}),{refreshDeps:[o,r]});return!i||!s||!r?null:d?n(a.Box,{sx:{position:"relative",height:s},children:n(a.LoadingOverlay,{visible:!0})}):l?n(a.Box,{sx:Hn,"data-enable-scrollbar":!0,children:n(Xg,{error:l,width:i,height:s})}):!u||!Array.isArray(u.replies)||u.replies.length===0?null:n(a.Box,{sx:Hn,"data-enable-scrollbar":!0,children:u.replies.map((c,f)=>n("div",{dangerouslySetInnerHTML:{__html:c.interpretation.html}},f))})}function Kg({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=b.useMemo(()=>v.defaultsDeep({},t,Jn),[t]),{control:s,handleSubmit:o,watch:u,getValues:l,reset:d}=x.useForm({defaultValues:i});b.useEffect(()=>{d(i)},[i]),u(["expertSystemURL","goal","path","question"]);const c=l(),f=b.useMemo(()=>!v.isEqual(c,i),[c,i]);return n("form",{onSubmit:o(r),children:p(a.Stack,{children:[p(a.Group,{grow:!0,children:[n(x.Controller,{name:"expertSystemURL",control:s,render:({field:g})=>n(a.TextInput,{label:"Expert System URL",...g})}),n(x.Controller,{name:"path",control:s,render:({field:g})=>n(a.TextInput,{label:"Path",required:!0,...g})})]}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:"goal",control:s,render:({field:g})=>n(a.TextInput,{label:"Goal",required:!0,...g})}),n(x.Controller,{name:"question",control:s,render:({field:g})=>n(a.TextInput,{label:"Question",required:!0,...g})})]}),n(a.Divider,{variant:"dashed",mt:16,mb:8}),n(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:n(k.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Jg extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Hg={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Jg,name:"mericoGQM",viewRender:Zg,configRender:Kg,createConfig(){return{version:1,config:v.cloneDeep(Jn)}}};function em(e,t,r){if(!e)return r[0];try{return[t,j(t).add(1,"year").subtract(1,"day").valueOf()]}catch(i){return console.error(i),r[0]}}function tm(e,t,r){const i=em(e,t,r);return{top:50,left:25,right:5,cellSize:["auto",13],range:i,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function nm(e){return{heat_block:function(i){if(!e.heat_block.value_formatter)return i;try{return te(i).format(e.heat_block.value_formatter)}catch(s){return console.error(s),i}}}}function rm(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(r=>({name:r,icon:"circle"}))}}function im(e,t,r,i){const{calendar:s,heat_block:o}=e;return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:i.map(u=>[v.get(u,s.data_key),v.get(u,o.data_key)])}:Object.entries(r).map(([u,l])=>({type:"heatmap",name:u,coordinateSystem:"calendar",calendarIndex:0,data:l.map(d=>[v.get(d,s.data_key),v.get(d,o.data_key)])}))}const am=e=>{try{return te(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function sm({conf:e,valueFormatters:t,dataDict:r,params:i}){const{value:s}=i,[o,u]=s,d=[{label:e.heat_block.name,value:t.heat_block(u),style:{label:"",value:""}}],c=r[o];return c&&e.tooltip.metrics.forEach(f=>{d.push({label:f.name,value:am(v.get(c,f.data_key,"")),style:{label:"",value:""}})}),d}function om(e,t,r){const i=v.keyBy(t,e.calendar.data_key);return{confine:!0,formatter:function(s){const u=sm({conf:e,valueFormatters:r,dataDict:i,params:s}).map(c=>`
|
|
244
|
+
`}}function Vf(){return{show:!0,trigger:"item",confine:!0,formatter:Of()}}const Bf={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Nf(e,t,r){r.reduce((o,u)=>{const l=ut(u,t);return o[u.name]=et(u,l),o},{});const s={series:{data:Ef(e,t),levels:Pf(e)},tooltip:Vf()};return v.defaultsDeep({},s,Bf)}le.use([de.SunburstChart,Ie.CanvasRenderer]);function Gf({context:e}){const{variables:t}=e,{value:r}=W(e.instanceData,"config"),i=b.useMemo(()=>v.defaults({},r,Yn),[r]),s=e.data,{width:o,height:u}=e.viewport,l=b.useMemo(()=>Nf(i,s,t),[i,s,t]);return!o||!u?null:n(Ae,{echarts:le,option:l,style:{width:o,height:u},notMerge:!0,theme:"merico-light"})}function qf({data:e,control:t,watch:r}){return r(["label_key","value_key","group_key"]),p(a.Stack,{children:[n(x.Controller,{name:"label_key",control:t,render:({field:i})=>n(R,{label:"Label Key",required:!0,data:e,...i})}),n(x.Controller,{name:"value_key",control:t,render:({field:i})=>n(R,{label:"Value Key",required:!0,data:e,...i})}),n(x.Controller,{name:"group_key",control:t,render:({field:i})=>n(R,{label:"Group Key",data:e,clearable:!0,...i})})]})}const Ff=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Wf=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],jf=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`levels.${r}.r0`,control:e,render:({field:s})=>n(a.TextInput,{label:"Inside Radius",placeholder:"0%",...s})}),n(x.Controller,{name:`levels.${r}.r`,control:e,render:({field:s})=>n(a.TextInput,{label:"Outside Radius",placeholder:"50%",...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),n(x.Controller,{name:`levels.${r}.label.show_label_tolerance`,control:e,render:({field:s})=>n(a.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...s})}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`levels.${r}.label.rotate`,control:e,render:({field:s})=>n(a.Select,{label:"Rotate",data:Ff,...s})}),n(x.Controller,{name:`levels.${r}.label.align`,control:e,render:({field:s})=>n(a.Select,{label:"Align",data:Wf,...s})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`levels.${r}.label.position`,control:e,render:({field:s})=>n(Bn,{label:"Position",...s})}),n(x.Controller,{name:`levels.${r}.label.padding`,control:e,render:({field:s})=>n(a.NumberInput,{label:"Padding",min:0,hideControls:!0,...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Level"})]}),Rf=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"levels"}),u=t("levels"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=t("levels.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(jf,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function Yf({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,Yn),[t]),o=b.useMemo(()=>v.clone(s),[s]),{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,s),[g,s]);d(["label_key","value_key","group_key","levels"]);const[m,w]=b.useState("Data");return n("form",{onSubmit:l(r),children:p(a.Stack,{spacing:"xs",children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Sunburst Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{value:m,onTabChange:w,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",children:"Data"}),n(a.Tabs.Tab,{value:"Levels",children:"Levels"})]}),n(a.Tabs.Panel,{value:"Data",children:n(qf,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Levels",children:n(Rf,{control:u,watch:d,data:i})})]})]})})}function Qf(e){const{label_field:t,value_field:r,...i}=e;return{...i,label_key:t,value_key:r}}function Uf(e){const{group_key:t="",...r}=e;return{...r,group_key:t}}function Xf(e){const{levels:t=[],...r}=e;return{...r,levels:t}}class Zf extends he{constructor(){super(...arguments);O(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:Qf(r.config)})),this.version(3,r=>({...r,version:3,config:Uf(r.config)})),this.version(4,r=>({...r,version:4,config:Xf(r.config)}))}}const Kf={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Zf,name:"sunburst",viewRender:Gf,configRender:Yf,createConfig(){return{version:4,config:v.cloneDeep(Yn)}}};var Be=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(Be||{});const Ma=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
|
|
245
|
+
`),Qn={columns:[],fontSize:"1rem",highlightOnHover:!1,horizontalSpacing:"1em",id_field:"",striped:!1,use_raw_columns:!0,verticalSpacing:"1em"},Ia={left:"flex-start",center:"center",right:"flex-end"},Jf=({header:e,cx:t})=>{const r=v.get(e.column.columnDef.meta,"align","left");return p(a.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:r,sx:{justifyContent:Ia[r]},children:[e.isPlaceholder?null:Pe.flexRender(e.column.columnDef.header,e.getContext()),n(Hf,{direction:e.column.getIsSorted()})]})},Hf=({direction:e})=>{switch(e){case"asc":return n(V.IconArrowUp,{size:16});case"desc":return n(V.IconArrowDown,{size:"1em"});default:return null}},Un={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:ig,configRender:ng,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"}]},eg={column:""};function Aa(e){const{value:t}=W(e.instanceData,"config");return t?t.columns.map((r,i)=>({label:r.label,value:i.toString()})):[]}function tg(e){return v.isEmpty(e)?[]:Object.keys(e[0]).map(t=>({label:t,value:t}))}function ng(e){const t=Aa(e.instance),r=tg(e.sampleData),i=t.length>0?t:r,{value:s,set:o}=W(e.trigger.triggerData,"config"),{column:u}=v.defaults({},s,eg),l=d=>{isNaN(+d)?o({column:d}):o({column:+d})};return n(a.Select,{clearable:!1,data:i,label:"Choose a column",value:u.toString(),onChange:l})}function rg(e,t){return e?v.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function ig(e){const t=Aa(e.instance),{value:r}=W(e.trigger.triggerData,"config");return n(a.Text,{children:rg(r,t)})}const ag=a.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10,"&::after":{content:'" "',display:"block",background:"white",position:"absolute",left:0,right:0,top:0,bottom:0,zIndex:-1}},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),sg={tableLayout:"fixed","th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}};function $a(e,t,r){return Math.min(Math.max(e,t),r)}class og{constructor(t){this.steps=t;const r=[],i=new Set;for(const s of t)i.has(s.to)||(r.push(s),i.add(s.to));if(r.sort((s,o)=>s.from-o.from),r.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=r}getLinearFunction(t,r){const i=(r.to-t.to)/(r.from-t.from),s=t.to-i*t.from;return o=>i*o+s}getStepFunctionForValue(t){let r=v.findLastIndex(this.steps,i=>i.from<=t);return r=$a(r,0,this.steps.length-2),this.getLinearFunction(this.steps[r],this.steps[r+1])}mapValue(t){return $a(this.getStepFunctionForValue(t)(t),0,100)}}class lg{constructor(t,r,i,s,o){this.getColIndex=t,this.cell=r,this.triggers=i,this.interactionManager=s,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const r={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const i of t)this.interactionManager.runInteraction(i.id,r)}}getRelatedTrigger(){return this.triggers.filter(r=>r.schemaRef===Un.id).filter(r=>{const i=this.getColIndex(this.cell),s=v.get(this.cell.column.columnDef.meta,"value_field"),o=v.get(r.config,"column");return o==i||o==s})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(v.isString(t))return t;const r=+this.cell.getValue();if(isFinite(r)){const i=this.colorManager.decodeInterpolation(t.interpolation),o=new og(t.steps).mapValue(r);return i==null?void 0:i.getColor(o)}}}const ug=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:Ia[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function dg(e){return e?je(e).oklch()[0]>.7?"black":"white":"inherit"}function cg(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:dg(t)}}function pt(e){const t=e.tableCellContext.isClickable(),r=ug({clickable:t,align:e.align});return n("div",{className:r.classes.content,style:{...cg(e)},children:n(a.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:n("span",{title:e.children,children:e.children})})})}function pg(e){return n(pt,{...e,children:e.value})}function hg(e){const t=te(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return n(pt,{...e,children:t})}function fg(e){const t=te(e.value).format({thousandSeparated:!0});return n(pt,{...e,children:t})}function gg(e){const t=te(e.value).format({output:"percent",mantissa:3});return n(pt,{...e,children:t})}function mg(e){const t=e.value,r=e.func_content;if(!r)return n(pt,{...e,children:t});const i=new Function(`return ${r}`)()({value:t});return n(pt,{...e,children:i})}function bg(e){switch(e.type){case Be.string:return n(pg,{...e});case Be.eloc:return n(hg,{...e});case Be.number:return n(fg,{...e});case Be.percentage:return n(gg,{...e});case Be.custom:return n(mg,{...e})}}const yg=e=>{const t=Fe(e),r=Ne(t.triggerManager,Un.id),{colorManager:i}=b.useContext(qe);return b.useCallback(s=>new lg(e.getColIndex,s,r,t,i),[r,t,e.getColIndex])};function vg({context:e,instance:t}){var ie,oe;const r=e.data??[],{height:i,width:s}=e.viewport,{value:o=Qn}=W(e.instanceData,"config"),{use_raw_columns:u,columns:l,...d}=o,{classes:c,cx:f}=ag(),g=b.useMemo(()=>u?!Array.isArray(r)||r.length===0?[]:Object.keys(r[0]).map(re=>({id:re,label:re,value_field:re,value_type:Be.string,align:"left"})):l,[u,l,r]),h=yg({getColIndex:b.useCallback(re=>g.indexOf(re.column.columnDef.meta),[g]),vizManager:e.vizManager,instance:t}),m=b.useMemo(()=>{const re=Pe.createColumnHelper();return g.map(fe=>re.accessor(fe.value_field,{cell:Te=>n(bg,{tableCellContext:h(Te.cell),value:Te.getValue(),type:fe.value_type,...fe}),header:fe.label,enableSorting:!0,meta:fe,size:fe.width,minSize:fe.width}))},[g,h]),[w,C]=b.useState([]),S=Pe.useReactTable({data:r,state:{sorting:w},onSortingChange:C,columns:m,getCoreRowModel:Pe.getCoreRowModel(),getSortedRowModel:Pe.getSortedRowModel()}),{rows:I}=S.getRowModel(),$=b.useRef(null),P=go.useVirtual({parentRef:$,size:I.length,estimateSize:b.useCallback(()=>28,[]),overscan:20}),{virtualItems:q,totalSize:L}=P,z=q.length>0&&((ie=q==null?void 0:q[0])==null?void 0:ie.start)||0,A=q.length>0?L-(((oe=q==null?void 0:q[q.length-1])==null?void 0:oe.end)||0):0,G=I.length,U=G>0,Q=U?i-22:i,ne=U?22:0;return!Array.isArray(r)||r.length===0?n(a.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:$,style:{height:i,width:s},"data-enable-scrollbar":!0,className:f(c.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[G>0&&n(a.Box,{className:c.info_bar,sx:{height:22},children:p(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",G]})}),p(a.Table,{sx:{...sg,maxHeight:Q},...d,striped:o.striped,children:[n("thead",{className:c.thead,style:{top:ne},children:S.getHeaderGroups().map(re=>n("tr",{children:re.headers.map(pe=>n("th",{style:{width:pe.getSize()},children:n(Jf,{header:pe,cx:f})},pe.id))},re.id))}),p("tbody",{children:[z>0&&n("tr",{children:n("td",{style:{height:`${z}px`}})}),q.map(re=>{const pe=I[re.index];return n("tr",{children:pe.getVisibleCells().map(fe=>n("td",{children:Pe.flexRender(fe.column.columnDef.cell,fe.getContext())},fe.id))},pe.id)}),A>0&&n("tr",{children:n("td",{style:{height:`${A}px`}})})]})]})]})}const za=a.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),xg=[{from:0,to:0},{from:100,to:100}];class Cg{constructor(){O(this,"steps",new Map);O(this,"interpolation");O(this,"onChange");se.makeAutoObservable(this,{steps:se.observable},{deep:!1}),se.reaction(()=>se.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const r of t)this.steps.set(r.to,r.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([r,i])=>({to:r,from:i})).sort((r,i)=>r.to-i.to||r.from-i.from))}fromProps(t){t.steps.length<2?this.setSteps(xg):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,r){t==null?this.steps.delete(r):this.steps.set(r,t)}getStepFromValue(t){return this.steps.get(t)}}function wg(e){const{onChange:t,color:r,index:i,value:s}=e,{classes:o}=za(),[u,l]=b.useState(s),[d,{setTrue:c,setFalse:f}]=Z.useBoolean(!1),g=i%2===1,h=g&&s!=null,m=!g&&s!=null,w=`map ${s} to color ${i}`,C=()=>{l(s),f()},S=()=>{f(),t==null||t(u)},I=te(s).format({average:!0});return p("div",{"data-testid":`palette-item-${i}`,className:o.paletteItem,children:[n(a.Text,{title:w,style:{opacity:h?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),p(a.Popover,{width:200,trapFocus:!0,opened:d,onClose:f,children:[n(a.Popover.Target,{children:n("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:c,style:{"--shadow-color":je(r).alpha(.5).hex(),backgroundColor:r}})}),n(a.Popover.Dropdown,{children:p(a.Stack,{children:[n(a.NumberInput,{size:"xs",label:"Map a value to this color",value:u,onChange:l}),p(a.Group,{position:"right",children:[n(a.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),n(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:S,children:"OK"})]})]})})]}),n(a.Text,{title:w,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const _g=T.observer(({model:e})=>{const{classes:t}=za(),r=v.range(0,13,1).map(i=>100/12*i).map(i=>[e.interpolation.getColor(i),i]);return n("div",{className:t.palette,children:r.map(([i,s],o)=>n(wg,{index:o,color:i,value:e.getStepFromValue(s),onChange:u=>e.changeStep(u,s)},i))})}),Sg=T.observer(function(t){const r=Z.useCreation(()=>new Cg,[]);return b.useEffect(()=>{r.fromProps(t)}),r.interpolation==null?null:n(_g,{model:r})}),Tg=e=>{const{value:t,onChange:r,colorManager:i}=e,s=i.getColorInterpolations(),[o,u]=b.useState(t),l=i.decodeInterpolation(o.interpolation)||s[0],[d,{setTrue:c,setFalse:f}]=Z.useBoolean(),g=s.map(S=>({label:S.displayName,value:i.encodeColor(S),group:S.category}));function h(S){S&&u(I=>({...I,interpolation:S}))}const m=()=>{f(),r==null||r(se.toJS(o))};function w(S){u(I=>({...I,steps:S}))}const C=()=>{f(),u(t)};return p(B,{children:[n(a.Button,{variant:"outline",onClick:c,children:l==null?void 0:l.displayName}),n(a.Modal,{size:508,title:"Setup color interpolation",opened:d,onClose:f,zIndex:320,children:d&&p(a.Stack,{"data-testid":"color-interpolation-modal",children:[n(a.Select,{label:"Color style",value:o.interpolation,data:g,onChange:h}),n(Sg,{steps:o.steps,interpolation:l,onChange:w}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:m,children:"OK"})]})]})})]})},kg=["static","interpolation","none"].map(e=>({label:v.capitalize(e),value:e})),Dg=[{from:0,to:0},{from:100,to:100}];function Ea(e){return e?v.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Mg(e,t){var r;return Ea(t)==="static"?t:(r=e.getStaticColors()[0])==null?void 0:r.value}function Ig(e,t){return v.isObject(t)?t:{steps:Dg,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Ag=b.forwardRef((e,t)=>{const{colorManager:r}=b.useContext(qe),[i,s]=b.useState(Ea(e.value)),[o,u]=b.useState(Mg(r,e.value)),l=Z.useLatest(o),[d,c]=b.useState(Ig(r,e.value)),f=Z.useLatest(d),g=w=>{var C,S,I;s(w||"none"),w==="static"?(C=e.onChange)==null||C.call(e,l.current):w==="none"||!w?(S=e.onChange)==null||S.call(e,"none"):(I=e.onChange)==null||I.call(e,f.current)},h=w=>{var C;u(w),(C=e.onChange)==null||C.call(e,w)},m=w=>{var C;c(w),(C=e.onChange)==null||C.call(e,w)};return p(a.Stack,{align:"stretch",children:[n(a.Select,{label:"Cell background",value:i||"none",onChange:g,data:kg}),i==="static"&&n(De,{value:o,onChange:h}),i==="interpolation"&&n(Tg,{colorManager:r,value:d,onChange:m})]})}),$g={[Be.eloc]:"ELOC"},zg=Object.values(Be).map(e=>({label:v.get($g,e,v.capitalize(e)),value:e})),Eg=b.forwardRef(({label:e,value:t,onChange:r,sx:i},s)=>n(a.Select,{ref:s,label:e,data:zg,value:t,onChange:r,sx:i})),Lg=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o(),t(u)},c=()=>{o(),l(e)},f=()=>{l(Ma)};return b.useEffect(()=>{l(e)},[e]),p(B,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Custom Cell Content"}),n(a.Modal,{size:800,title:"Custom cell content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Box,{sx:{position:"relative"},children:n(_e,{height:"500px",defaultLanguage:"javascript",value:u,onChange:g=>l(g??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:f,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Pg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Xn=()=>n(a.Text,{color:"dimmed",size:12,children:"px"}),Og=({control:e,index:t,watch:r,remove:i,column:s,data:o})=>{const u=r(`columns.${t}.value_type`);return p(a.Stack,{my:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,children:[n(x.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>n(a.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),n(x.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>n(R,{label:"Value Field",required:!0,data:o,...l})})]}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>n(Eg,{label:"Value Type",sx:{flex:1},...l})}),u===Be.custom&&n(x.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>n(Lg,{value:l.value??Ma,onChange:d=>l.onChange(d??"")})})]}),n(a.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(a.NumberInput,{hideControls:!0,label:"Min Width",rightSection:n(Xn,{}),disabled:!0}),n(x.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>n(a.NumberInput,{hideControls:!0,label:"Width",rightSection:n(Xn,{}),...l})}),n(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:n(Xn,{}),disabled:!0})]}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>n(a.Select,{label:"Alignment",data:Pg,...l})})}),n(x.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>n(Ag,{...l})}),n(a.Divider,{mb:4,mt:12,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(t),children:"Delete this column"})]})},Vg=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o,update:u}=x.useFieldArray({control:e,name:"columns"}),l=()=>{const c=ve.randomId();s({id:c,label:c,value_field:"value",value_type:Be.string})};t("columns");const d=t("use_raw_columns");return p(B,{children:[n(x.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>n(a.Switch,{mt:20,label:"Use Original Data Columns",checked:c.value,onChange:f=>c.onChange(f.currentTarget.checked)})}),n(a.Divider,{mt:20,mb:10,variant:"dashed"}),!d&&p(a.Stack,{children:[n(a.Text,{my:0,children:"Custom Columns"}),p(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[i.map((c,f)=>n(a.Tabs.Tab,{value:f.toString(),children:f+1},c.id)),n(a.Tabs.Tab,{onClick:l,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),i.map((c,f)=>n(a.Tabs.Panel,{value:f.toString(),children:n(Og,{control:e,watch:t,index:f,column:c,data:r,remove:o},f)},c.id))]})]})]})};function Bg({control:e,watch:t,data:r}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(a.Stack,{spacing:"xs",children:[p(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[n(x.Controller,{name:"horizontalSpacing",control:e,render:({field:i})=>n(a.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...i})}),n(x.Controller,{name:"verticalSpacing",control:e,render:({field:i})=>n(a.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...i})})]}),n(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:n(x.Controller,{name:"fontSize",control:e,render:({field:i})=>n(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...i})})}),p(a.Group,{position:"apart",grow:!0,children:[n(x.Controller,{name:"striped",control:e,render:({field:i})=>n(a.Switch,{label:"Striped",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),n(x.Controller,{name:"highlightOnHover",control:e,render:({field:i})=>n(a.Switch,{label:"Highlight on hover",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})})]})]})}function Ng({columns:e,...t}){return{...t,columns:e.map(({id:r,...i})=>({id:r??ve.randomId(),...i}))}}function Gg({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,Qn),[t]),o=b.useMemo(()=>Ng(s),[s]);b.useEffect(()=>{!v.isEqual(s,o)&&(console.log("config malformed, resetting to defaults",s,o),r(o))},[s,o]);const{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,s),[g,s]);return d(["id_field"]),p("form",{onSubmit:l(r),children:[p(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Table Config"}),n(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",children:"Data"}),n(a.Tabs.Tab,{value:"Style",children:"Style"}),n(a.Tabs.Tab,{value:"Columns",children:"Columns"})]}),n(a.Tabs.Panel,{value:"Data",children:n(x.Controller,{name:"id_field",control:u,render:({field:m})=>n(R,{label:"ID Field",required:!0,data:i,...m})})}),n(a.Tabs.Panel,{value:"Style",children:n(Bg,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Columns",children:n(Vg,{control:u,watch:d,data:i})})]})]})}function qg(e){const{columns:t,...r}=e;return{...e,columns:t.map(i=>({...i,align:i.align??"left"}))}}class Fg extends he{constructor(){super(...arguments);O(this,"VERSION",3)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{columns:i,...s}=r.config;return{...r,version:2,config:{...s,columns:i.map(({id:o,...u})=>({id:o??ve.randomId(),...u}))}}}),this.version(3,r=>({...r,version:3,config:qg(r.config)}))}}const Zn={createConfig(){return{version:3,config:v.cloneDeep(Qn)}},displayName:"Table",displayGroup:"Others",migrator:new Fg,name:"table",viewRender:vg,configRender:Gg,triggers:[Un]},La=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
246
|
+
`),Kn={func_content:La,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Wg=T.observer(({context:e})=>{const t=F(),{value:r=Kn}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,{func_content:o,horizontal_align:u,font_size:l,font_weight:d}=r,c=b.useMemo(()=>i.reduce((g,h)=>{const m=ut(h,s);return g[h.name]=et(h,m),g},{}),[i,s]),f=b.useMemo(()=>new Function(`return ${o}`)()({data:s,variables:c,filters:t.payloadForSQL.filterValues,context:t.payloadForSQL.context}),[o,s,c,t.payloadForSQL]);return n(a.Text,{align:u,weight:d,sx:{fontSize:l},children:f})}),jg=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{sx:{position:"relative"},children:n(_e,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Rg=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e),d=()=>{o(),t(u)},c=()=>{o(),l(e)},f=()=>{l(La)};return b.useEffect(()=>{l(e)},[e]),p(B,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Edit Content"}),n(a.Modal,{size:800,title:"Text content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(jg,{value:u,onChange:l}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:f,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Yg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Qg({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=b.useMemo(()=>v.defaultsDeep({},t,Kn),[t]),s=b.useMemo(()=>{const{func_content:h,horizontal_align:m,font_size:w,font_weight:C}=i;return{func_content:h,horizontal_align:m,font_size:w,font_weight:C}},[i]);b.useEffect(()=>{!v.isEqual(i,s)&&(console.log("config malformed, resetting to defaults",i,s),r(s))},[i,s]);const{control:o,handleSubmit:u,watch:l,getValues:d,reset:c}=x.useForm({defaultValues:s});b.useEffect(()=>{c(s)},[s]),l(["func_content","horizontal_align","font_size","font_weight"]);const f=d(),g=b.useMemo(()=>!v.isEqual(f,i),[f,i]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{weight:500,children:"Configurations"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Stack,{spacing:10,children:[n(x.Controller,{name:"func_content",control:o,render:({field:h})=>n(Rg,{...h})}),n(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),n(x.Controller,{name:"horizontal_align",control:o,render:({field:h})=>n(a.Select,{label:"Horizontal Alignment",data:Yg,...h})}),n(x.Controller,{name:"font_size",control:o,render:({field:h})=>n(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...h})}),n(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:n(x.Controller,{name:"font_weight",control:o,render:({field:h})=>n(ra,{label:"Font Weight",...h})})})]})]})})}class Ug extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Xg={displayName:"Text",displayGroup:"Others",migrator:new Ug,name:"text",viewRender:Wg,configRender:Qg,createConfig(){return{version:1,config:v.cloneDeep(Kn)}}},Zg=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[n("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"}),n("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),n("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 Pa(e,t){const r=v.get(e,t,"");if(r)throw new Error(r)}async function Kg(e,t,r,i={}){const s={"X-Requested-With":"XMLHttpRequest","Content-Type":i.string?"application/x-www-form-urlencoded":"application/json",...i.headers},o={baseURL:e,method:"POST",url:t,params:i.params,headers:s};return o.data=i.string?JSON.stringify(r):r,Xe(o).then(u=>u.data).catch(u=>Promise.reject(u))}const Jg=({conf:e,data:t})=>async()=>{const{expertSystemURL:r,path:i,goal:s,question:o}=e;if(!i||!s||!o)return;const u={dashboard:s,panel:o,data:t};try{const l=r.startsWith("http")?r:window.location.origin;return await Kg(l,`/expert/v3/devtable/${i}`,u,{})}catch(l){throw Pa(l,"response.data.detail"),Pa(l,"response.data.error"),console.error(l),l}},Jn={expertSystemURL:"",path:"",goal:"",question:""},Hn={height:"100%",overflowY:"auto",..._n},Oa=({message:e})=>n(a.Box,{sx:Hn,children:n("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Hg=({error:e,width:t,height:r})=>{const i=e.message;if(i.startsWith("<"))return n(Oa,{message:i});const o=r-25-20-30;return n(a.Center,{sx:{width:"100%",height:o},children:p(a.Stack,{align:"center",spacing:20,children:[n(Zg,{}),n(Oa,{message:i})]})})};function em({context:e}){const{value:t}=W(e.instanceData,"config"),r=b.useMemo(()=>v.defaultsDeep({},t,Jn),[t]),{width:i,height:s}=e.viewport,o=e.data??[],{data:u,error:l,loading:d}=Z.useRequest(Jg({conf:r,data:o}),{refreshDeps:[o,r]});return!i||!s||!r?null:d?n(a.Box,{sx:{position:"relative",height:s},children:n(a.LoadingOverlay,{visible:!0})}):l?n(a.Box,{sx:Hn,"data-enable-scrollbar":!0,children:n(Hg,{error:l,width:i,height:s})}):!u||!Array.isArray(u.replies)||u.replies.length===0?null:n(a.Box,{sx:Hn,"data-enable-scrollbar":!0,children:u.replies.map((c,f)=>n("div",{dangerouslySetInnerHTML:{__html:c.interpretation.html}},f))})}function tm({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=b.useMemo(()=>v.defaultsDeep({},t,Jn),[t]),{control:s,handleSubmit:o,watch:u,getValues:l,reset:d}=x.useForm({defaultValues:i});b.useEffect(()=>{d(i)},[i]),u(["expertSystemURL","goal","path","question"]);const c=l(),f=b.useMemo(()=>!v.isEqual(c,i),[c,i]);return n("form",{onSubmit:o(r),children:p(a.Stack,{children:[p(a.Group,{grow:!0,children:[n(x.Controller,{name:"expertSystemURL",control:s,render:({field:g})=>n(a.TextInput,{label:"Expert System URL",...g})}),n(x.Controller,{name:"path",control:s,render:({field:g})=>n(a.TextInput,{label:"Path",required:!0,...g})})]}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:"goal",control:s,render:({field:g})=>n(a.TextInput,{label:"Goal",required:!0,...g})}),n(x.Controller,{name:"question",control:s,render:({field:g})=>n(a.TextInput,{label:"Question",required:!0,...g})})]}),n(a.Divider,{variant:"dashed",mt:16,mb:8}),n(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:n(k.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class nm extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const rm={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new nm,name:"mericoGQM",viewRender:em,configRender:tm,createConfig(){return{version:1,config:v.cloneDeep(Jn)}}};function im(e,t,r){if(!e)return r[0];try{return[t,j(t).add(1,"year").subtract(1,"day").valueOf()]}catch(i){return console.error(i),r[0]}}function am(e,t,r){const i=im(e,t,r);return{top:50,left:25,right:5,cellSize:["auto",13],range:i,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function sm(e){return{heat_block:function(i){if(!e.heat_block.value_formatter)return i;try{return te(i).format(e.heat_block.value_formatter)}catch(s){return console.error(s),i}}}}function om(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(r=>({name:r,icon:"circle"}))}}function lm(e,t,r,i){const{calendar:s,heat_block:o}=e;return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:i.map(u=>[v.get(u,s.data_key),v.get(u,o.data_key)])}:Object.entries(r).map(([u,l])=>({type:"heatmap",name:u,coordinateSystem:"calendar",calendarIndex:0,data:l.map(d=>[v.get(d,s.data_key),v.get(d,o.data_key)])}))}const um=e=>{try{return te(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function dm({conf:e,valueFormatters:t,dataDict:r,params:i}){const{value:s}=i,[o,u]=s,d=[{label:e.heat_block.name,value:t.heat_block(u),style:{label:"",value:""}}],c=r[o];return c&&e.tooltip.metrics.forEach(f=>{d.push({label:f.name,value:um(v.get(c,f.data_key,"")),style:{label:"",value:""}})}),d}function cm(e,t,r){const i=v.keyBy(t,e.calendar.data_key);return{confine:!0,formatter:function(s){const u=dm({conf:e,valueFormatters:r,dataDict:i,params:s}).map(c=>`
|
|
247
247
|
<tr>
|
|
248
248
|
<th style="text-align: right;">
|
|
249
249
|
<div style="${c.style.label}">${c.label}</div>
|
|
@@ -269,13 +269,13 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
269
269
|
</thead>
|
|
270
270
|
<tbody>${u.join("")}</tbody>
|
|
271
271
|
</table>
|
|
272
|
-
`}}}function lm(e,t){return{min:e.heat_block.min??0,max:e.heat_block.max??100,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const um={tooltip:{confine:!0},grid:{containLabel:!0}},dm=e=>j(e).get("year");function cm(e,t){const r=e.calendar.data_key,i=v.groupBy(t,d=>dm(d[r])),s=Object.keys(i),o=t.map(d=>j(d[r]).valueOf()),u=v.min(o),l=v.max(o);return{minDate:u??0,maxDate:l??0,dateSpan:j(l).diff(u,"day"),dataByYear:i,years:s}}function pm(e,t,r){const i=nm(e),{dateSpan:s,minDate:o,dataByYear:u,years:l}=cm(e,t),d=s<=366,c={calendar:tm(d,o,l),series:im(e,d,u,t),tooltip:om(e,t,i),visualMap:lm(e,d),legend:rm(d,l)};return v.defaultsDeep({},c,um)}function hm(e){return n(B,{})}function fm(e){return n(a.Text,{children:"Click heat block"})}const Va={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:fm,configRender:hm,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"}]},er={calendar:{data_key:"",locale:"EN"},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:Se},tooltip:{metrics:[]}};le.use([N.DataZoomComponent,de.BarChart,de.LineChart,de.HeatmapChart,N.CalendarComponent,N.GridComponent,N.LegendComponent,N.TooltipComponent,N.VisualMapComponent,Ie.CanvasRenderer]);function gm({name:e},t){const r=t.getOption();r.calendar.forEach(i=>{i.range=e}),t.setOption(r)}function mm({conf:e,data:t,width:r,height:i,interactionManager:s,variables:o}){const u=b.useMemo(()=>{const g=e.calendar.data_key;return v.keyBy(t,g)},[t,e.calendar.data_key]),l=Ne(s.triggerManager,Va.id),d=b.useCallback(g=>{const[h,m]=g.value,w=v.get(u,h,{error:"rowData is not found"});l.forEach(C=>{s.runInteraction(C.id,{...g,rowData:w})})},[u,l,s]),c=b.useMemo(()=>({click:d,legendselectchanged:gm}),[d]),f=b.useMemo(()=>pm(e,t),[e,t]);return!r||!i?null:n(Ae,{echarts:le,option:f,style:{width:r,height:i},onEvents:c,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function bm({context:e,instance:t}){const r=Fe({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=b.useMemo(()=>v.defaults({},i,er),[i]),u=e.data,{width:l,height:d}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:n(a.Box,{children:n(mm,{variables:s,width:l,height:d,data:u,conf:o,interactionManager:r})})}function ym({data:e,control:t,watch:r}){return r(["heat_block"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"heat_block.data_key",control:t,render:({field:i})=>n(R,{label:"Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"heat_block.name",control:t,render:({field:i})=>n(a.TextInput,{label:"Name",sx:{flex:1},...i})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"heat_block.min",control:t,render:({field:i})=>n(a.NumberInput,{label:"Min Value",...i})}),n(x.Controller,{name:"heat_block.max",control:t,render:({field:i})=>n(a.NumberInput,{label:"Max Value",...i})})]}),n(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),n(x.Controller,{name:"heat_block.value_formatter",control:t,render:({field:i})=>n(Oe,{...i})})]})}const vm=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`tooltip.metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`tooltip.metrics.${r}.data_key`,control:e,render:({field:s})=>n(R,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),xm=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"tooltip.metrics"}),u=t("tooltip.metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(vm,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function Cm({data:e,control:t,watch:r}){return n(xm,{control:t,watch:r,data:e})}const wm=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function _m({data:e,control:t,watch:r}){return r(["calendar"]),p(a.Stack,{children:[n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"calendar.data_key",control:t,render:({field:i})=>n(R,{label:"Data Field",required:!0,data:e,sx:{flex:1},...i})})}),n(x.Controller,{name:"calendar.locale",control:t,render:({field:i})=>n(a.Select,{label:"Language",required:!0,data:wm,sx:{flex:1},...i})})]})}function Sm({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,er),[t]),o=b.useMemo(()=>v.cloneDeep(s),[s]);b.useEffect(()=>{!v.isEqual(s,o)&&(console.log("config malformed, resetting to defaults",s,o),r(o))},[s,o]);const{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,s),[g,s]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:l(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Calendar Heatmap Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Calendar",children:"Calendar"}),n(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),n(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),n(a.Tabs.Panel,{value:"Calendar",children:n(_m,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Heat Block",children:n(ym,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Tooltip",children:n(Cm,{control:u,watch:d,data:i})})]})]})})}class Tm extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const km={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Tm,name:"calendarHeatmap",viewRender:bm,configRender:Sm,createConfig:()=>({version:1,config:er}),triggers:[Va]};function Dm(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let r=0;t&&(r+=15);const i=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let s=0;return i&&(s+=15),e.series.some(o=>!o.hide_in_legend)&&(s+=20),{top:r,right:5,bottom:s,left:5,containLabel:!0}}function Mm(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function Im(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(r=>!r.hide_in_legend).map(({name:r,type:i})=>({name:r,icon:Mm(i)})),t}function Am(e,t,r,i){return e.map(s=>{const o=s.orientation==="horizontal",u=o?"yAxis":"xAxis",l=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,xAxisIndex:s.xAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[u]:Number(r[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Yt(s.template,t,i):""},position:l}}}})}function tr(e,t,r){return e.map(i=>[i[r],i[t]])}function $m(e,t,r,i){const s=tr(t,r,i);return v.unionBy(s,e,0)}function zm({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:s}){return s?$m(e,t,r,i):t.map(o=>[o[i],o[r]])}function Em({dataTemplate:e,data:t,aggregation_on_value:r,name_data_key:i,value_data_key:s,valueTypedXAxis:o}){if(!r||r.type==="none")return zm({dataTemplate:e,data:t,name_data_key:i,value_data_key:s,valueTypedXAxis:o});const u=tr(t,i,s),l=v.groupBy(u,"0");return Object.entries(l).map(([c,f])=>{const g=Tt(f,"1",r);return[c,g]})}function Lm({group_by_key:e,data:t,value_data_key:r,name_data_key:i}){const s=v.groupBy(t,e);return Object.entries(s).forEach(([o,u])=>{s[o]=tr(u,i,r)}),s}function Pm({y_axis:e},{data_key:t,xAxisIndex:r,label_position:i,name:s,group_by_key:o,aggregation_on_value:u,stack:l,color:d,hide_in_legend:c,invisible:f,id:g,...h},m,w,C,S,I){const $={label:{show:!!i,position:i,formatter:I[r??"default"]},name:s,yAxisId:"main-y-axis",xAxisIndex:r,stack:l,color:f?"transparent":d,hide_in_legend:c,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...h};if(!o||o===e.data_key)return $.data=Em({dataTemplate:m,data:C,aggregation_on_value:u,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:w}),$;const P=Lm({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(P).map(([q,L])=>{const z=v.cloneDeep($);return z.name=q,z.color=void 0,z.data=L,z})}function Om(e,t,r,i,s,o,u){const l=t.map(c=>[c,0]);return e.series.map(c=>Pm(e,c,l,r,i,u,s)).flat().concat(Am(e.reference_lines,o,u,i))}function Vm(e,t){const r=e.find(l=>l.axisDim==="y"&&l.axisId==="main-y-axis");if(!r)return"";const{name:i,axisType:s,axisValue:o,axisIndex:u}=r;return s==="yAxis.category"?i:dt(t.y_axis.axisLabel.formatter)(o,u)}function Bm(e,t,r){const i=t.reduce((s,{xAxisIndex:o,name:u})=>(s[u]=o,s),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(s){const o=Array.isArray(s)?s:[s];if(o.length===0)return"";const u=o.map(({seriesName:c,marker:f,value:g})=>{if(Array.isArray(g)&&g.length===2&&(g=g[0]),!c)return g;const h=i[c],m=r[h]??r.default;return`
|
|
272
|
+
`}}}function pm(e,t){return{min:e.heat_block.min??0,max:e.heat_block.max??100,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const hm={tooltip:{confine:!0},grid:{containLabel:!0}},fm=e=>j(e).get("year");function gm(e,t){const r=e.calendar.data_key,i=v.groupBy(t,d=>fm(d[r])),s=Object.keys(i),o=t.map(d=>j(d[r]).valueOf()),u=v.min(o),l=v.max(o);return{minDate:u??0,maxDate:l??0,dateSpan:j(l).diff(u,"day"),dataByYear:i,years:s}}function mm(e,t,r){const i=sm(e),{dateSpan:s,minDate:o,dataByYear:u,years:l}=gm(e,t),d=s<=366,c={calendar:am(d,o,l),series:lm(e,d,u,t),tooltip:cm(e,t,i),visualMap:pm(e,d),legend:om(d,l)};return v.defaultsDeep({},c,hm)}function bm(e){return n(B,{})}function ym(e){return n(a.Text,{children:"Click heat block"})}const Va={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:ym,configRender:bm,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"}]},er={calendar:{data_key:"",locale:"EN"},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:Se},tooltip:{metrics:[]}};le.use([N.DataZoomComponent,de.BarChart,de.LineChart,de.HeatmapChart,N.CalendarComponent,N.GridComponent,N.LegendComponent,N.TooltipComponent,N.VisualMapComponent,Ie.CanvasRenderer]);function vm({name:e},t){const r=t.getOption();r.calendar.forEach(i=>{i.range=e}),t.setOption(r)}function xm({conf:e,data:t,width:r,height:i,interactionManager:s,variables:o}){const u=b.useMemo(()=>{const g=e.calendar.data_key;return v.keyBy(t,g)},[t,e.calendar.data_key]),l=Ne(s.triggerManager,Va.id),d=b.useCallback(g=>{const[h,m]=g.value,w=v.get(u,h,{error:"rowData is not found"});l.forEach(C=>{s.runInteraction(C.id,{...g,rowData:w})})},[u,l,s]),c=b.useMemo(()=>({click:d,legendselectchanged:vm}),[d]),f=b.useMemo(()=>mm(e,t),[e,t]);return!r||!i?null:n(Ae,{echarts:le,option:f,style:{width:r,height:i},onEvents:c,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function Cm({context:e,instance:t}){const r=Fe({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=b.useMemo(()=>v.defaults({},i,er),[i]),u=e.data,{width:l,height:d}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:n(a.Box,{children:n(xm,{variables:s,width:l,height:d,data:u,conf:o,interactionManager:r})})}function wm({data:e,control:t,watch:r}){return r(["heat_block"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"heat_block.data_key",control:t,render:({field:i})=>n(R,{label:"Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"heat_block.name",control:t,render:({field:i})=>n(a.TextInput,{label:"Name",sx:{flex:1},...i})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"heat_block.min",control:t,render:({field:i})=>n(a.NumberInput,{label:"Min Value",...i})}),n(x.Controller,{name:"heat_block.max",control:t,render:({field:i})=>n(a.NumberInput,{label:"Max Value",...i})})]}),n(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),n(x.Controller,{name:"heat_block.value_formatter",control:t,render:({field:i})=>n(Oe,{...i})})]})}const _m=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`tooltip.metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`tooltip.metrics.${r}.data_key`,control:e,render:({field:s})=>n(R,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),Sm=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"tooltip.metrics"}),u=t("tooltip.metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(_m,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function Tm({data:e,control:t,watch:r}){return n(Sm,{control:t,watch:r,data:e})}const km=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Dm({data:e,control:t,watch:r}){return r(["calendar"]),p(a.Stack,{children:[n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"calendar.data_key",control:t,render:({field:i})=>n(R,{label:"Data Field",required:!0,data:e,sx:{flex:1},...i})})}),n(x.Controller,{name:"calendar.locale",control:t,render:({field:i})=>n(a.Select,{label:"Language",required:!0,data:km,sx:{flex:1},...i})})]})}function Mm({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,er),[t]),o=b.useMemo(()=>v.cloneDeep(s),[s]);b.useEffect(()=>{!v.isEqual(s,o)&&(console.log("config malformed, resetting to defaults",s,o),r(o))},[s,o]);const{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,s),[g,s]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:l(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Calendar Heatmap Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Calendar",children:"Calendar"}),n(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),n(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),n(a.Tabs.Panel,{value:"Calendar",children:n(Dm,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Heat Block",children:n(wm,{control:u,watch:d,data:i})}),n(a.Tabs.Panel,{value:"Tooltip",children:n(Tm,{control:u,watch:d,data:i})})]})]})})}class Im extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Am={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Im,name:"calendarHeatmap",viewRender:Cm,configRender:Mm,createConfig:()=>({version:1,config:er}),triggers:[Va]};function $m(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let r=0;t&&(r+=15);const i=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let s=0;return i&&(s+=15),e.series.some(o=>!o.hide_in_legend)&&(s+=20),{top:r,right:5,bottom:s,left:5,containLabel:!0}}function zm(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function Em(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(r=>!r.hide_in_legend).map(({name:r,type:i})=>({name:r,icon:zm(i)})),t}function Lm(e,t,r,i){return e.map(s=>{const o=s.orientation==="horizontal",u=o?"yAxis":"xAxis",l=o?"insideEndTop":"end";return{name:s.name,type:"line",hide_in_legend:!s.show_in_legend,xAxisIndex:s.xAxisIndex,data:[],lineStyle:s.lineStyle,markLine:{data:[{name:s.name,[u]:Number(r[s.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:s.lineStyle,label:{formatter:function(){return s.template?Yt(s.template,t,i):""},position:l}}}})}function tr(e,t,r){return e.map(i=>[i[r],i[t]])}function Pm(e,t,r,i){const s=tr(t,r,i);return v.unionBy(s,e,0)}function Om({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:s}){return s?Pm(e,t,r,i):t.map(o=>[o[i],o[r]])}function Vm({dataTemplate:e,data:t,aggregation_on_value:r,name_data_key:i,value_data_key:s,valueTypedXAxis:o}){if(!r||r.type==="none")return Om({dataTemplate:e,data:t,name_data_key:i,value_data_key:s,valueTypedXAxis:o});const u=tr(t,i,s),l=v.groupBy(u,"0");return Object.entries(l).map(([c,f])=>{const g=Tt(f,"1",r);return[c,g]})}function Bm({group_by_key:e,data:t,value_data_key:r,name_data_key:i}){const s=v.groupBy(t,e);return Object.entries(s).forEach(([o,u])=>{s[o]=tr(u,i,r)}),s}function Nm({y_axis:e},{data_key:t,xAxisIndex:r,label_position:i,name:s,group_by_key:o,aggregation_on_value:u,stack:l,color:d,hide_in_legend:c,invisible:f,id:g,...h},m,w,C,S,I){const $={label:{show:!!i,position:i,formatter:I[r??"default"]},name:s,yAxisId:"main-y-axis",xAxisIndex:r,stack:l,color:f?"transparent":d,hide_in_legend:c,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...h};if(!o||o===e.data_key)return $.data=Vm({dataTemplate:m,data:C,aggregation_on_value:u,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:w}),$;const P=Bm({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(P).map(([q,L])=>{const z=v.cloneDeep($);return z.name=q,z.color=void 0,z.data=L,z})}function Gm(e,t,r,i,s,o,u){const l=t.map(c=>[c,0]);return e.series.map(c=>Nm(e,c,l,r,i,u,s)).flat().concat(Lm(e.reference_lines,o,u,i))}function qm(e,t){const r=e.find(l=>l.axisDim==="y"&&l.axisId==="main-y-axis");if(!r)return"";const{name:i,axisType:s,axisValue:o,axisIndex:u}=r;return s==="yAxis.category"?i:dt(t.y_axis.axisLabel.formatter)(o,u)}function Fm(e,t,r){const i=t.reduce((s,{xAxisIndex:o,name:u})=>(s[u]=o,s),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(s){const o=Array.isArray(s)?s:[s];if(o.length===0)return"";const u=o.map(({seriesName:c,marker:f,value:g})=>{if(Array.isArray(g)&&g.length===2&&(g=g[0]),!c)return g;const h=i[c],m=r[h]??r.default;return`
|
|
273
273
|
<tr>
|
|
274
274
|
<td>${f}</td>
|
|
275
275
|
<th style="text-align: right; padding: 0 1em;">${c}</th>
|
|
276
276
|
<td style="text-align: left; padding: 0 1em;">${m({value:g})}</td>
|
|
277
277
|
</tr>
|
|
278
|
-
`}),l=He(e.y_axis.axisLabel.overflow.in_tooltip),d=
|
|
278
|
+
`}),l=He(e.y_axis.axisLabel.overflow.in_tooltip),d=qm(o,e);return`
|
|
279
279
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
280
280
|
<div style="${l}">${d}</div>
|
|
281
281
|
</div>
|
|
@@ -284,7 +284,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
284
284
|
${u.join("")}
|
|
285
285
|
</tbody>
|
|
286
286
|
</table>
|
|
287
|
-
`}}}function Nm(e){return e.x_axes.reduce((r,{label_formatter:i},s)=>(r[s]=function(u){let l=u;if(typeof u=="object"&&(Array.isArray(u.value)&&u.value.length===2?l=u.value[0]:l=u.value),!i)return l;try{return te(l).format(i)}catch(d){return console.error(d),l}},r),{default:({value:r})=>r})}function Gm(e,t){const r={};return t.map(i=>{const s=ut(i,e);r[i.name]=et(i,s)}),r}function qm(e,t){return e.x_axes.map(({min:r,max:i,...s},o)=>{let u=s.position;return u||(u=o>0?"bottom":"top"),{...s,type:"value",min:r||void 0,max:i||void 0,position:u,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 Fm(e,t){const r=t.every(u=>!Number.isNaN(Number(u))),{overflow:i,...s}=e.y_axis.axisLabel,o=Ye(i.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:r?"value":"category",axisLabel:{...s,...o,formatter:dt(s.formatter)},z:5}]}function Wm(e,t,r){const i=Gm(t,r),s=Nm(e),o=v.uniq(t.map(c=>c[e.y_axis.data_key])),u=o.every(c=>!Number.isNaN(Number(c))),l=Om(e,o,u,t,s,r,i);return{xAxis:qm(e,s),yAxis:Fm(e,o),series:l,tooltip:Bm(e,l,s),grid:Dm(e),legend:Im(l)}}const nr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:Se,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ge},overflow:Ve},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function jm(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:Se,show:!0}}function Rm(){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:St,xAxisIndex:"0"}}function Ym(){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"}}le.use([N.DataZoomComponent,de.BarChart,de.LineChart,de.ScatterChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer,N.MarkLineComponent,N.MarkAreaComponent]);function Qm({conf:e,data:t,width:r,height:i,interactionManager:s,variables:o}){const u=b.useMemo(()=>v.keyBy(t,e.y_axis.data_key),[t,e.y_axis.data_key]),l=Ne(s.triggerManager,$n.id),d=b.useCallback(g=>{const h=v.get(u,g.name,{error:"rowData is not found"});l.forEach(m=>{s.runInteraction(m.id,{...g,rowData:h})})},[u,l,s]),c=b.useMemo(()=>({click:d}),[d]),f=b.useMemo(()=>Wm(e,t,o),[e,t]);return!r||!i?null:n(Ae,{echarts:le,option:f,style:{width:r,height:i},onEvents:c,notMerge:!0,theme:"merico-light"})}function Um({context:e,instance:t}){const r=Fe({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=b.useMemo(()=>v.defaults({},i,nr),[i]),u=e.data,{width:l,height:d}=e.viewport;return n(a.Box,{children:n(Qm,{variables:s,width:l,height:d,data:u,conf:o,interactionManager:r})})}const Xm=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Zm=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Km({control:e,index:t,remove:r,watch:i,variableOptions:s,xAxisOptions:o}){const u=i(`reference_lines.${t}.orientation`);return p(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:l})=>n(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...l})}),n(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:l})=>n(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...l})})]}),n(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:l})=>n(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...l})}),p(a.Group,{grow:!0,children:[p(a.Stack,{children:[n(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:l})=>n(a.Select,{label:"Orientation",data:Zm,required:!0,sx:{flex:1},...l})}),u==="vertical"&&n(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),u==="horizontal"&&n(x.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:l})=>n(a.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...l})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:l})=>n(a.Select,{label:"Line Type",data:Xm,sx:{flexGrow:1},...l})}),n(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:l})=>n(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:"sm",children:"Color"}),n(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:l})=>n(De,{...l})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),n(x.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:l})=>n(a.Checkbox,{label:"Show in legend",checked:l.value,onChange:d=>l.onChange(d.currentTarget.checked)})}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Jm({control:e,watch:t,variables:r}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),u=t("reference_lines"),l=i.map((m,w)=>({...m,...u[w]})),d=()=>{const m=Ym();s(m)},c=b.useMemo(()=>r.map(m=>({label:m.name,value:m.name})),[r]),f=t("x_axes"),g=b.useMemo(()=>f.map(({name:m},w)=>({label:m,value:w.toString()})),[f]),h=l.length>0?l[0].id:"0";return p(a.Tabs,{defaultValue:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[l.map((m,w)=>n(a.Tabs.Tab,{value:m.id,children:m.name},w)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((m,w)=>n(a.Tabs.Panel,{value:m.id,children:n(Km,{control:e,index:w,remove:o,watch:t,variableOptions:c,xAxisOptions:g})},w))]})}function Hm(e){const[t,r]=b.useState(e);return b.useEffect(()=>{r(e)},[e]),{tab:t,setTab:r}}const eb=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function tb({control:e,index:t,seriesItem:r}){const i=!!r.barWidth.trim();return p(B,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.stack`,control:e,render:({field:s})=>n(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...s})}),n(x.Controller,{name:`series.${t}.barGap`,control:e,render:({field:s})=>n(a.Select,{label:"Bar Gap",data:eb,sx:{flexGrow:1},...s})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:s})=>n(a.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...s})}),n(x.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:s})=>n(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...s})}),n(x.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:s})=>n(a.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...s})})]})]})}const nb=[{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 rb({control:e,index:t,remove:r,seriesItem:i,xAxisOptions:s,data:o}){return p(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.name`,control:e,render:({field:u})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...u})}),n(x.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:u})=>n(a.Select,{label:"X Axis",data:s,disabled:s.length===0,sx:{flex:1},...u})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.data_key`,control:e,render:({field:u})=>n(R,{label:"Value Field",required:!0,data:o,sx:{flex:1},...u})}),n(x.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:u})=>n(jt,{label:"Aggregation on Value",value:u.value??St,onChange:u.onChange,pt:0})})]}),n(a.Group,{grow:!0,children:n(x.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:u})=>n(R,{label:"Split into multiple series by this key...",data:o,clearable:!0,sx:{flex:1},...u})})}),n(tb,{index:t,control:e,seriesItem:i}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),n(x.Controller,{name:`series.${t}.label_position`,control:e,render:({field:u})=>n(a.Select,{label:"Label Position",data:nb,...u})}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:"sm",children:"Color"}),n(x.Controller,{name:`series.${t}.color`,control:e,render:({field:u})=>n(De,{...u})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),n(x.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:u})=>n(a.Checkbox,{label:"Hide in legend",checked:u.value,onChange:l=>u.onChange(l.currentTarget.checked)})}),n(x.Controller,{name:`series.${t}.invisible`,control:e,render:({field:u})=>n(a.Checkbox,{label:"Invisible",checked:u.value,onChange:l=>u.onChange(l.currentTarget.checked)})}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function ib({control:e,watch:t,data:r}){var m;const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"series"}),u=t("series"),l=i.map((w,C)=>({...w,...u[C]})),d=()=>{const w=Rm();s(w)},c=t("x_axes"),f=b.useMemo(()=>c.map(({name:w},C)=>({label:w,value:C.toString()})),[c]),{tab:g,setTab:h}=Hm((m=l[0])==null?void 0:m.id);return p(a.Tabs,{value:g,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map(w=>n(a.Tabs.Tab,{value:w.id,children:w.name},w.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((w,C)=>n(a.Tabs.Panel,{value:w.id,children:n(rb,{control:e,index:C,remove:o,seriesItem:w,xAxisOptions:f,data:r},w.id)},w.id))]})}const ab=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function sb({control:e,index:t,remove:r}){return p(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:i})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})})}),n(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:i})=>n(a.Select,{label:"Position",required:!0,data:ab,sx:{flex:1},...i})})}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),n(x.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:i})=>n(Oe,{...i})})]}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:i})=>n(a.TextInput,{label:"Min",...i})}),n(x.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:i})=>n(a.TextInput,{label:"Max",...i})})]})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),n(x.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:i})=>n(a.Checkbox,{label:"Visible",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),n(a.Button,{mt:20,leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),disabled:t===0,children:"Delete this X Axis"})]})}function ob({control:e,watch:t}){const{fields:r,append:i,remove:s}=x.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),u=r.map((c,f)=>({...c,...o[f]})),l=()=>{const c=jm();i(c)},d=u.length>0?u[0].id:"0";return p(a.Tabs,{defaultValue:d,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[u.map(c=>n(a.Tabs.Tab,{value:c.id,children:c.name},c.id)),n(a.Tabs.Tab,{onClick:l,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),u.map((c,f)=>n(a.Tabs.Panel,{value:c.id,children:n(sb,{control:e,index:f,remove:s})},c.id))]})}function lb({data:e,control:t,watch:r}){return r(["y_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"y_axis.data_key",control:t,render:({field:i})=>n(R,{label:"Y Axis Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"y_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"X Axis Name",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:i})=>n(Qt,{data:e,...i})})}),n(x.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:i})=>n(Je,{...i})})]})}function ub({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,o=b.useMemo(()=>v.defaultsDeep({},t,nr),[t]),{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]),d([]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,o),[g,o]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:l(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Horizontal Bar Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axes",children:"X Axes"}),n(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),n(a.Tabs.Tab,{value:"Series",children:"Series"}),n(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),n(a.Tabs.Panel,{value:"X Axes",children:n(ob,{control:u,watch:d})}),n(a.Tabs.Panel,{value:"Y Axis",children:n(lb,{control:u,watch:d,data:s})}),n(a.Tabs.Panel,{value:"Series",children:n(ib,{control:u,watch:d,data:s})}),n(a.Tabs.Panel,{value:"Reference Lines",children:n(Jm,{variables:i,control:u,watch:d})})]})]})})}class db extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const cb={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new db,name:"horizontalBarChart",viewRender:Um,configRender:ub,createConfig:()=>({version:1,config:nr})};function pb(){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 Ba=({value:e})=>{try{return te(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function hb(e,t,r){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(s=>{const o=r[s].length,d=(v.countBy(r[s],c=>c.level.diff===0).true??0)/o;return[s,"_y",d]}),label:{show:!0,formatter:Ba},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:s,value:o})=>`
|
|
287
|
+
`}}}function Wm(e){return e.x_axes.reduce((r,{label_formatter:i},s)=>(r[s]=function(u){let l=u;if(typeof u=="object"&&(Array.isArray(u.value)&&u.value.length===2?l=u.value[0]:l=u.value),!i)return l;try{return te(l).format(i)}catch(d){return console.error(d),l}},r),{default:({value:r})=>r})}function jm(e,t){const r={};return t.map(i=>{const s=ut(i,e);r[i.name]=et(i,s)}),r}function Rm(e,t){return e.x_axes.map(({min:r,max:i,...s},o)=>{let u=s.position;return u||(u=o>0?"bottom":"top"),{...s,type:"value",min:r||void 0,max:i||void 0,position:u,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 Ym(e,t){const r=t.every(u=>!Number.isNaN(Number(u))),{overflow:i,...s}=e.y_axis.axisLabel,o=Ye(i.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:r?"value":"category",axisLabel:{...s,...o,formatter:dt(s.formatter)},z:5}]}function Qm(e,t,r){const i=jm(t,r),s=Wm(e),o=v.uniq(t.map(c=>c[e.y_axis.data_key])),u=o.every(c=>!Number.isNaN(Number(c))),l=Gm(e,o,u,t,s,r,i);return{xAxis:Rm(e,s),yAxis:Ym(e,o),series:l,tooltip:Fm(e,l,s),grid:$m(e),legend:Em(l)}}const nr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:Se,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ge},overflow:Ve},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Um(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:Se,show:!0}}function Xm(){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:St,xAxisIndex:"0"}}function Zm(){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"}}le.use([N.DataZoomComponent,de.BarChart,de.LineChart,de.ScatterChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer,N.MarkLineComponent,N.MarkAreaComponent]);function Km({conf:e,data:t,width:r,height:i,interactionManager:s,variables:o}){const u=b.useMemo(()=>v.keyBy(t,e.y_axis.data_key),[t,e.y_axis.data_key]),l=Ne(s.triggerManager,$n.id),d=b.useCallback(g=>{const h=v.get(u,g.name,{error:"rowData is not found"});l.forEach(m=>{s.runInteraction(m.id,{...g,rowData:h})})},[u,l,s]),c=b.useMemo(()=>({click:d}),[d]),f=b.useMemo(()=>Qm(e,t,o),[e,t]);return!r||!i?null:n(Ae,{echarts:le,option:f,style:{width:r,height:i},onEvents:c,notMerge:!0,theme:"merico-light"})}function Jm({context:e,instance:t}){const r=Fe({vizManager:e.vizManager,instance:t}),{value:i}=W(e.instanceData,"config"),{variables:s}=e,o=b.useMemo(()=>v.defaults({},i,nr),[i]),u=e.data,{width:l,height:d}=e.viewport;return n(a.Box,{children:n(Km,{variables:s,width:l,height:d,data:u,conf:o,interactionManager:r})})}const Hm=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],eb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function tb({control:e,index:t,remove:r,watch:i,variableOptions:s,xAxisOptions:o}){const u=i(`reference_lines.${t}.orientation`);return p(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:l})=>n(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...l})}),n(x.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:l})=>n(a.Select,{label:"Value",required:!0,data:s,sx:{flex:1},...l})})]}),n(x.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:l})=>n(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...l})}),p(a.Group,{grow:!0,children:[p(a.Stack,{children:[n(x.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:l})=>n(a.Select,{label:"Orientation",data:eb,required:!0,sx:{flex:1},...l})}),u==="vertical"&&n(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),u==="horizontal"&&n(x.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:l})=>n(a.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...l})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:l})=>n(a.Select,{label:"Line Type",data:Hm,sx:{flexGrow:1},...l})}),n(x.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:l})=>n(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:"sm",children:"Color"}),n(x.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:l})=>n(De,{...l})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),n(x.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:l})=>n(a.Checkbox,{label:"Show in legend",checked:l.value,onChange:d=>l.onChange(d.currentTarget.checked)})}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function nb({control:e,watch:t,variables:r}){const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"reference_lines"}),u=t("reference_lines"),l=i.map((m,w)=>({...m,...u[w]})),d=()=>{const m=Zm();s(m)},c=b.useMemo(()=>r.map(m=>({label:m.name,value:m.name})),[r]),f=t("x_axes"),g=b.useMemo(()=>f.map(({name:m},w)=>({label:m,value:w.toString()})),[f]),h=l.length>0?l[0].id:"0";return p(a.Tabs,{defaultValue:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[l.map((m,w)=>n(a.Tabs.Tab,{value:m.id,children:m.name},w)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((m,w)=>n(a.Tabs.Panel,{value:m.id,children:n(tb,{control:e,index:w,remove:o,watch:t,variableOptions:c,xAxisOptions:g})},w))]})}function rb(e){const[t,r]=b.useState(e);return b.useEffect(()=>{r(e)},[e]),{tab:t,setTab:r}}const ib=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function ab({control:e,index:t,seriesItem:r}){const i=!!r.barWidth.trim();return p(B,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.stack`,control:e,render:({field:s})=>n(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...s})}),n(x.Controller,{name:`series.${t}.barGap`,control:e,render:({field:s})=>n(a.Select,{label:"Bar Gap",data:ib,sx:{flexGrow:1},...s})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:s})=>n(a.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...s})}),n(x.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:s})=>n(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...s})}),n(x.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:s})=>n(a.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...s})})]})]})}const sb=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function ob({control:e,index:t,remove:r,seriesItem:i,xAxisOptions:s,data:o}){return p(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.name`,control:e,render:({field:u})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...u})}),n(x.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:u})=>n(a.Select,{label:"X Axis",data:s,disabled:s.length===0,sx:{flex:1},...u})})]}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`series.${t}.data_key`,control:e,render:({field:u})=>n(R,{label:"Value Field",required:!0,data:o,sx:{flex:1},...u})}),n(x.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:u})=>n(jt,{label:"Aggregation on Value",value:u.value??St,onChange:u.onChange,pt:0})})]}),n(a.Group,{grow:!0,children:n(x.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:u})=>n(R,{label:"Split into multiple series by this key...",data:o,clearable:!0,sx:{flex:1},...u})})}),n(ab,{index:t,control:e,seriesItem:i}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),n(x.Controller,{name:`series.${t}.label_position`,control:e,render:({field:u})=>n(a.Select,{label:"Label Position",data:sb,...u})}),p(a.Stack,{spacing:4,children:[n(a.Text,{size:"sm",children:"Color"}),n(x.Controller,{name:`series.${t}.color`,control:e,render:({field:u})=>n(De,{...u})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),n(x.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:u})=>n(a.Checkbox,{label:"Hide in legend",checked:u.value,onChange:l=>u.onChange(l.currentTarget.checked)})}),n(x.Controller,{name:`series.${t}.invisible`,control:e,render:({field:u})=>n(a.Checkbox,{label:"Invisible",checked:u.value,onChange:l=>u.onChange(l.currentTarget.checked)})}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function lb({control:e,watch:t,data:r}){var m;const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"series"}),u=t("series"),l=i.map((w,C)=>({...w,...u[C]})),d=()=>{const w=Xm();s(w)},c=t("x_axes"),f=b.useMemo(()=>c.map(({name:w},C)=>({label:w,value:C.toString()})),[c]),{tab:g,setTab:h}=rb((m=l[0])==null?void 0:m.id);return p(a.Tabs,{value:g,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map(w=>n(a.Tabs.Tab,{value:w.id,children:w.name},w.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((w,C)=>n(a.Tabs.Panel,{value:w.id,children:n(ob,{control:e,index:C,remove:o,seriesItem:w,xAxisOptions:f,data:r},w.id)},w.id))]})}const ub=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function db({control:e,index:t,remove:r}){return p(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[n(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:i})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})})}),n(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:i})=>n(a.Select,{label:"Position",required:!0,data:ub,sx:{flex:1},...i})})}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),n(x.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:i})=>n(Oe,{...i})})]}),p(a.Stack,{children:[n(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(a.Group,{grow:!0,children:[n(x.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:i})=>n(a.TextInput,{label:"Min",...i})}),n(x.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:i})=>n(a.TextInput,{label:"Max",...i})})]})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),n(x.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:i})=>n(a.Checkbox,{label:"Visible",checked:i.value,onChange:s=>i.onChange(s.currentTarget.checked)})}),n(a.Button,{mt:20,leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),disabled:t===0,children:"Delete this X Axis"})]})}function cb({control:e,watch:t}){const{fields:r,append:i,remove:s}=x.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),u=r.map((c,f)=>({...c,...o[f]})),l=()=>{const c=Um();i(c)},d=u.length>0?u[0].id:"0";return p(a.Tabs,{defaultValue:d,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(a.Tabs.List,{children:[u.map(c=>n(a.Tabs.Tab,{value:c.id,children:c.name},c.id)),n(a.Tabs.Tab,{onClick:l,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),u.map((c,f)=>n(a.Tabs.Panel,{value:c.id,children:n(db,{control:e,index:f,remove:s})},c.id))]})}function pb({data:e,control:t,watch:r}){return r(["y_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"y_axis.data_key",control:t,render:({field:i})=>n(R,{label:"Y Axis Data Field",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"y_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"X Axis Name",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:i})=>n(Qt,{data:e,...i})})}),n(x.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:i})=>n(Je,{...i})})]})}function hb({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),{variables:i}=e,s=e.data,o=b.useMemo(()=>v.defaultsDeep({},t,nr),[t]),{control:u,handleSubmit:l,watch:d,getValues:c,reset:f}=x.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]),d([]);const g=c(),h=b.useMemo(()=>!v.isEqual(g,o),[g,o]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:l(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Horizontal Bar Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axes",children:"X Axes"}),n(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),n(a.Tabs.Tab,{value:"Series",children:"Series"}),n(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),n(a.Tabs.Panel,{value:"X Axes",children:n(cb,{control:u,watch:d})}),n(a.Tabs.Panel,{value:"Y Axis",children:n(pb,{control:u,watch:d,data:s})}),n(a.Tabs.Panel,{value:"Series",children:n(lb,{control:u,watch:d,data:s})}),n(a.Tabs.Panel,{value:"Reference Lines",children:n(nb,{variables:i,control:u,watch:d})})]})]})})}class fb extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const gb={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new fb,name:"horizontalBarChart",viewRender:Jm,configRender:hb,createConfig:()=>({version:1,config:nr})};function mb(){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 Ba=({value:e})=>{try{return te(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function bb(e,t,r){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(s=>{const o=r[s].length,d=(v.countBy(r[s],c=>c.level.diff===0).true??0)/o;return[s,"_y",d]}),label:{show:!0,formatter:Ba},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:s,value:o})=>`
|
|
288
288
|
<table style="width: auto">
|
|
289
289
|
<thead>
|
|
290
290
|
<tr colspan="2">
|
|
@@ -306,7 +306,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
306
306
|
</tr>
|
|
307
307
|
</tbody>
|
|
308
308
|
</table>
|
|
309
|
-
`},show_in_legend:!1}}function Na(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function
|
|
309
|
+
`},show_in_legend:!1}}function Na(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function yb([e,t]){const r={x:e,v:`${t}`};try{r.v=te(t).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return r}function vb(e,t,r,i){var d,c;const s=t.map(f=>{const g=r[f],h=v.sumBy(g,m=>m.level.diff);return[f,h/g.length]}),o=Number(((d=v.maxBy(s,f=>f[1]))==null?void 0:d[1])??0),u=Number(((c=v.minBy(s,f=>f[1]))==null?void 0:c[1])??0),l=st.interpolate([o,0,u],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...i,data:s,itemStyle:{color:({value:f})=>{try{return l(f[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:f})=>{try{return te(f[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return f[1]}}},tooltip:{trigger:"item",formatter:({color:f,value:g})=>{const{x:h,v:m}=yb(g);return`
|
|
310
310
|
<table style="width: auto">
|
|
311
311
|
<thead>
|
|
312
312
|
<tr colspan="2">
|
|
@@ -328,7 +328,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
328
328
|
</tr>
|
|
329
329
|
</tbody>
|
|
330
330
|
</table>
|
|
331
|
-
`}},show_in_legend:!1}}function
|
|
331
|
+
`}},show_in_legend:!1}}function xb([e,t,r,i]){const s={x:e,percentage:`${t}`,count:r,sum:i};try{s.percentage=te(t).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return s}function Cb(e,t,r,i){const s={};t.forEach(f=>{const g=v.countBy(r[f],m=>m.level.diff),h=v.sum(Object.values(g));Object.entries(g).forEach(([m,w])=>{s[m]||(s[m]=[]);const C=w/h;s[m].push([f,C,w,h])})});const o=Object.entries(s).map(([f])=>Number(f)).sort((f,g)=>f-g),u=Math.max(...o),l=Math.min(...o),d=st.interpolate([u,0,l],["#D15A40","#FFF","#418AAF"]);return o.map(f=>({type:"bar",name:f,xAxisIndex:2,yAxisIndex:2,stack:1,...i,color:d(f),data:s[f],tooltip:{trigger:"item",formatter:({color:g,value:h})=>{const{x:m,percentage:w,count:C,sum:S}=xb(h);return`
|
|
332
332
|
<table style="width: auto">
|
|
333
333
|
<thead>
|
|
334
334
|
<tr colspan="2">
|
|
@@ -363,8 +363,8 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
363
363
|
</tr>
|
|
364
364
|
</tbody>
|
|
365
365
|
</table>
|
|
366
|
-
`}},show_in_legend:!0}))}function yb(e,t,r,i){const s=t.data_key,o=t.name,u=r.map(l=>{const d=v.sumBy(i[l],s);return[l,d]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:u,show_in_legend:!1}}function vb(e,t,r,i){const u={barMinWidth:5,barMaxWidth:20};return[hb(e,r,i),gb(e,r,i,u),...bb(e,r,i,u),yb(e,t,r,i)]}function xb(e,t){const{axisLabel:r}=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:{...r,formatter:ya(r.formatter)},axisLine:{show:!1}}]}function Cb(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 rr(e){return e==1||e==2?1:rr(e-2)+rr(e-1)}const wb=Array.from(new Array(20),(e,t)=>rr(t+1));function Ga(e){return e<=1?e:wb.findIndex(t=>e<=t)-1}function _b(e,t){const{estimated_value:r,actual_value:i}=e.deviation.data_keys;return t.map(s=>{const o=Ga(s[r]),u=Ga(s[i]),l=o-u;return{...s,level:{estimated:o,actual:u,diff:l}}})}function Sb(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function Tb(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(r=>r.show_in_legend).reverse().map(r=>({name:`${r.name}`,color:r.color,itemStyle:Sb(r.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const kb={tooltip:{trigger:"axis"}};function Db(e,t){const{deviation:r,metrics:i}=e,s=i.find(u=>u.data_key===t);if(s)return s;const o=r.data_keys.actual_value;return{id:o,name:r.name,data_key:o}}function Mb(e,t,r){const i=_b(e,r),s=v.uniqBy(r,e.x_axis.data_key).map(c=>c[e.x_axis.data_key]),o=v.groupBy(i,e.x_axis.data_key),u=Db(e,t),l=vb(e,u,s,o),d={xAxis:xb(e,s),yAxis:Cb(u),series:l,grid:pb(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:Tb(l)};return v.defaultsDeep({},d,kb)}const ir={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Jt}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]},Ib={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},Ab=({conf:e,metricKey:t,setMetricKey:r})=>{const{deviation:i,metrics:s}=e,o=b.useMemo(()=>{const u=s.map(l=>({label:l.name,value:l.data_key}));return u.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),u},[i,s]);return p(a.Group,{spacing:1,children:[n(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),n(a.NativeSelect,{size:"xs",data:o,value:t,onChange:u=>r(u.currentTarget.value),styles:Ib})]})},$b={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function zb(){return p(a.HoverCard,{width:400,shadow:"md",children:[n(a.HoverCard.Target,{children:n(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:n(V.IconInfoCircle,{size:14}),children:"指标说明"})}),n(a.HoverCard.Dropdown,{children:n(a.Table,{fontSize:14,sx:$b,children:p("tbody",{children:[p("tr",{children:[n("th",{children:"估算偏差"}),n("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[n("th",{children:"准确估算比例"}),n("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function Eb(e){return p(a.Group,{position:"apart",children:[n(zb,{}),n(Ab,{...e})]})}le.use([de.BarChart,de.LineChart,de.HeatmapChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer,N.VisualMapComponent]);function Lb({conf:e,data:t,width:r,height:i,metricKey:s}){const o=b.useMemo(()=>Mb(e,s,t),[e,t,s]);return!r||!i?null:n(Ae,{echarts:le,option:o,style:{width:r,height:i},notMerge:!0,theme:"merico-light"})}function Pb({context:e}){const{value:t}=W(e.instanceData,"config"),r=b.useMemo(()=>v.defaults({},t,ir),[t]),i=e.data,{width:s,height:o}=e.viewport,{x_axis:u,deviation:l}=r,{estimated_value:d,actual_value:c}=l.data_keys,[f,g]=b.useState(c);if(b.useEffect(()=>{g(w=>w||c)},[c]),!u.data_key||!d||!c)return null;const h=Math.max(s,300),m=Math.max(o,370);return p(a.Box,{sx:{overflow:"hidden",height:m,width:h},children:[n(Eb,{conf:r,metricKey:f,setMetricKey:g}),n(Lb,{width:h,height:m-30,data:i,conf:r,metricKey:f})]})}function Ob({data:e,control:t,watch:r}){return r(["x_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.data_key",control:t,render:({field:i})=>n(R,{label:"数据字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"x_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"X轴名称",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:i})=>n(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:n(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...i})}),n(x.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:i})=>n(Ca,{data:e,...i})})]})]})}function Vb({data:e,control:t,watch:r}){return r(["deviation"]),p(a.Stack,{children:[n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"deviation.name",control:t,render:({field:i})=>n(a.TextInput,{label:"指标名称",sx:{flex:1},...i})})}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:i})=>n(R,{label:"估算值字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:i})=>n(R,{label:"实际值字段",required:!0,data:e,sx:{flex:1},...i})})]})]})}const Bb=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`metrics.${r}.data_key`,control:e,render:({field:s})=>n(R,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),Nb=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"metrics"}),u=t("metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(Bb,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function Gb({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,ir),[t]),{control:o,handleSubmit:u,watch:l,getValues:d,reset:c}=x.useForm({defaultValues:s});b.useEffect(()=>{c(s)},[s]),l([]);const f=d(),g=b.useMemo(()=>!v.isEqual(f,s),[f,s]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Merico Estimation Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),n(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),n(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),n(a.Tabs.Panel,{value:"X Axis",children:n(Ob,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Deviation",children:n(Vb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Additional Metrics",children:n(Nb,{control:o,watch:l,data:i})})]})]})})}class qb extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Fb={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new qb,name:"mericoEstimationChart",viewRender:Pb,configRender:Gb,createConfig:()=>({version:1,config:ir})},Wb=[{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"})),jb=[Jo,Ho,nl,tl,el,rl],qa=()=>({id:"dashboard",version:Tn,manifest:{viz:[Zn,kf,Rg,dh,Qf,gp,cb,pl,eu,ic,zc,km,dp,Od,yf,$p,ah,Hg,Fb,fu],color:[...Wb,...jb]}}),Mt=new sl,be={pluginManager:Re("pluginManager"),vizManager:Re("vizManager"),colorManager:Re("colorManager"),instanceScope:{panelModel:Re("panelModel"),vizInstance:Re("vizInstance"),interactionManager:Re("interactionManager"),migrator:Re("migrator"),operationManager:Re("operationManager"),triggerManager:Re("triggerManager")}},ar=()=>{try{Mt.install(qa())}catch{}const e=new Xo(Mt),t=new al(Mt);return{pluginManager:Mt,vizManager:e,colorManager:t}},qe=b.createContext(ar());try{Mt.install(qa())}catch{}function Rb(e,t){const{value:r,set:i}=W(e.operation.operationData,"config"),[s,o]=b.useState(v.defaults({},r,t)),u=async()=>{await i(s)};return b.useEffect(()=>{o(v.defaults({},r,t))},[r]),{config:s,setConfig:o,commit:u}}function Yb(e){const{config:t,setConfig:r,commit:i}=Rb(e,{urlTemplate:"",openInNewTab:!0});async function s(){await i()}async function o(l){r({...t,openInNewTab:l}),await i()}const u=l=>r({...t,urlTemplate:l.currentTarget.value});return p(a.Stack,{children:[n(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:u,onBlur:s}),n(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:l=>o(l.currentTarget.checked)})]})}async function Qb(e,t){const{urlTemplate:r,openInNewTab:i}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:i,payload:e}}))}class Ub extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const Xb={displayName:"Open Link",id:"builtin:op:open-link",configRender:Yb,run:Qb,migrator:new Ub,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Zb(e){const{value:t,set:r}=W(e.operationData,"config"),i=s=>void r({template:s});return[(t==null?void 0:t.template)||"",i]}function Kb(e){const[t,r]=Zb(e.operation);return n(a.TextInput,{defaultValue:t,onBlur:i=>r(i.currentTarget.value),label:"console.log"})}async function Jb(e,t){const r=await t.operationData.getItem("config"),i=v.template(r.template||"");console.log("run with payload",e),console.log(i(e))}const Hb={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Kb,run:Jb},ey=T.observer(e=>{const t=F(),{value:r,set:i}=W(e.operation.operationData,"config");console.log({value:r,viewID:r==null?void 0:r.viewID});const s=(r==null?void 0:r.viewID)||"",o=u=>void i({viewID:u});return n(a.Select,{defaultValue:s,value:s,onChange:o,label:"View",data:t.views.options})});async function ty(e,t){const i=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const ny={displayName:"Open View",id:"builtin:op:open_view",configRender:ey,run:ty},ry={dictionary:{}},iy=T.observer(e=>{const t=F(),{value:r=ry,set:i}=W(e.operation.operationData,"config"),{dictionary:s={}}=r,o=(d,c)=>{i({dictionary:{...s,[d]:c}})},u=()=>{o(t.filters.firstFilterValueKey,"")},l=d=>{const c={...s};delete c[d],i({dictionary:c})};return p(a.Stack,{spacing:10,children:[n(a.Text,{children:"Mapping Rules"}),Object.entries(s).map(([d,c])=>p(a.Flex,{justify:"space-between",gap:10,children:[n(a.TextInput,{label:"Payload key",value:c,onChange:f=>{o(d,f.currentTarget.value)},sx:{flexGrow:1}}),n(R,{data:[t.filters.values],value:d,onChange:f=>{o(f,c)},label:"Filter key",sx:{flexGrow:1}}),n(a.ActionIcon,{onClick:()=>l(d),sx:{marginTop:"26px",flexGrow:0},children:n(k.Trash,{size:14,color:"red"})})]},d)),n(a.Button,{size:"xs",onClick:u,sx:{alignSelf:"center",width:"300px"},children:"Add one mapping rule"})]})});async function ay(e,t){const i=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:e}}))}const sy={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:iy,run:ay},oy={filter_keys:[]},ly=T.observer(e=>{const t=F(),{value:r=oy,set:i}=W(e.operation.operationData,"config"),{filter_keys:s=[]}=r,o=l=>{i({filter_keys:[...l]})},u=b.useMemo(()=>t.filters.current.map(l=>({label:l.label,value:l.key})),[t.filters.values]);return n(a.Stack,{spacing:10,children:n(a.MultiSelect,{label:"Select Filters to Clear",data:u,value:s,onChange:o})})});async function uy(e,t){const i=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:e}}))}const tn=[Hb,Xb,ny,sy,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:ly,run:uy}];class dy{constructor(t,r=tn){O(this,"attachments");this.operations=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,operationData:new lt(s,"data")}};this.attachments=new Sn(t,"__OPERATIONS",i)}async runOperation(t,r){const i=await this.attachments.getInstance(t);if(!i){console.warn(`Operation '${t}' is not defined`);return}const s=this.tryGetSchema(i.schemaRef);if(!s){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await s.run(r,i)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;return u&&await u.needMigration(s)});return(await Promise.all(r)).some(i=>i)}async runMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;u&&await u.needMigration(s)&&await u.migrate(s)});await Promise.all(r)}async createOrGetOperation(t,r){var u;if(!this.getOperationSchemaList().some(l=>l.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const s=await this.attachments.getInstance(t);return!s||s.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((u=r.createDefaultConfig)==null?void 0:u.call(r))??{}}):s}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Fa="__TRIGGERS";class cy{constructor(t,r){O(this,"attachments");this.instance=t,this.component=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,triggerData:new lt(s,"data")}};this.attachments=new Sn(t,Fa,i)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Fa,r=>{const i=v.values(r).map(s=>({id:v.get(s,"id"),schemaRef:v.get(s,"schemaRef"),config:se.toJS(v.get(s,"data.config"))}));t(i)},{fireImmediately:!0})}async createOrGetTrigger(t,r,i={recreate:!1}){var l;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||i.recreate||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((l=r==null?void 0:r.createDefaultConfig)==null?void 0:l.call(r))||{}}):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 r=(await this.getTriggerList()).map(async i=>{const s=this.getTriggerSchemaList().find(l=>l.id===i.schemaRef),o=s==null?void 0:s.migrator,u={configData:i.triggerData};return o&&await o.needMigration(u)?()=>o.migrate(u):null});return Promise.all(r).then(i=>i.filter(s=>s))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class sr{constructor(t,r,i){O(this,"operationManager");O(this,"triggerManager");O(this,"attachments");this.operationManager=new dy(t,i),this.triggerManager=new cy(t,r);const s=async o=>{const{id:u,triggerRef:l,operationRef:d}=await o.getItem(null);return{id:u,triggerRef:l,operationRef:d}};this.attachments=new Sn(t,"__INTERACTIONS",s)}async addInteraction(t,r){const i=t.id,s=r.id,o=`[${i}]:[${s}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:s})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:i,operationRef:s}=r;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(s)<=1&&await this.operationManager.removeOperation(s),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(i=>i.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(i=>i.triggerRef===t).length}async runInteraction(t,r){const s=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(s.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,r)}catch(u){console.warn(`Failed to run operation '${o.operationRef}'`,u)}}))}}const Fe=({vizManager:e,instance:t})=>Z.useCreation(()=>new sr(t,e.resolveComponent(t.type),tn),[t,e]),Wa=e=>{const{title:t="Variables",variables:r}=e,i=ve.useClipboard(),s=o=>{i.copy(o),Vt.showNotification({color:"green",message:"Copied to clipboard"})};return p(a.Paper,{withBorder:!0,p:"sm",children:[n(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),n(a.Stack,{style:{maxHeight:"500px"},children:r.map(o=>p(a.Text,{size:"sm",children:[p(a.Code,{color:"teal",children:["// ",o.description]}),n("br",{}),p(a.Code,{onClick:()=>s(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class py{constructor(t,r){O(this,"operationId");O(this,"operation");O(this,"operationSchema");O(this,"variables",[]);this.operationManager=t,this.instance=r,se.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const i=await this.operationManager.retrieveTrigger(t),s=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));se.runInAction(()=>{this.operationId=t,this.operation=i,this.operationSchema=s,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function hy(e){return!!e.operationId}const fy=T.observer(({model:e,onClick:t})=>{var i;const r=(i=e.operationSchema)==null?void 0:i.displayName;return n(a.Button,{variant:"outline",onClick:t,children:r})}),gy=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return b.createElement(e.operationSchema.configRender,t)});function my({model:e}){const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Operation",data:r,onChange:i,value:e.operationSchema.id})}const by=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),{operationManager:s,operationId:o,instance:u,variables:l}=e,d=Z.useCreation(()=>new py(s,u),[s,u]);return Z.useAsyncEffect(async()=>{await d.configOperation(o,l)},[o,d]),hy(d)?p(B,{children:[n(fy,{model:d,onClick:r}),n(a.Modal,{size:600,opened:t,onClose:i,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:p(a.Stack,{children:[n(my,{model:d}),n(gy,{model:d}),n(Wa,{title:"Variables",variables:d.variables})]})})]}):null});class yy{constructor(t,r){O(this,"triggerId");O(this,"trigger");O(this,"triggerSchema");O(this,"sampleData");this.triggerManager=t,this.instance=r,se.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const i=await this.triggerManager.retrieveTrigger(t),s=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));se.runInAction(()=>{this.triggerId=t,this.trigger=i,this.triggerSchema=s,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return vy(this)}}function vy(e){return!!e.triggerId&&!!e.triggerSchema}function xy(e,t){return Z.useCreation(()=>new yy(e,t),[e,t])}const Cy=T.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,i={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n(a.Button,{variant:"outline",onClick:t,children:b.createElement(r,i)})}),wy=T.observer(({model:e})=>{const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Trigger",data:r,value:e.triggerSchema.id,onChange:i})}),_y=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return b.createElement(e.triggerSchema.configRender,t)}),Sy=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),s=e.model;return p(B,{children:[n(a.Modal,{opened:t,onClose:i,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:p(a.Stack,{children:[n(wy,{model:s}),n(_y,{model:s}),n(Wa,{title:"Payload",variables:s.triggerSchema.payload})]})}),n(Cy,{onClick:r,model:s})]})});function Ty(e,t){const[r,i]=b.useState([]);return Z.useAsyncEffect(async()=>{const s=await e.getInteractionList();i(s)},[t,e]),r}const ky=T.observer(({item:e,manager:t,instance:r,sampleData:i,variables:s,onRemove:o})=>{const{triggerRef:u,operationRef:l}=e,d=xy(t.triggerManager,r);if(Z.useAsyncEffect(async()=>{await d.configTrigger(u,i)},[d,u,i]),d.isReady()){const c=[...d.triggerSchema.payload,...s];return p(a.Group,{children:[n(Sy,{model:d}),n(by,{instance:r,operationId:l,variables:c,operationManager:t.operationManager}),n(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:n(k.Trash,{size:16})})]})}return null}),Dy=e=>{const[t,r]=b.useState(0),{interactionManager:i,instance:s,sampleData:o,variables:u}=e,l=Ty(i,t),d=async()=>{const h=await i.triggerManager.createOrGetTrigger(ve.randomId(),i.triggerManager.getTriggerSchemaList()[0]),m=await i.operationManager.createOrGetOperation(ve.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(h,m),r(w=>w+1)};async function c(h){await i.removeInteraction(h.id),r(m=>m+1)}const{data:f=0,loading:g}=Z.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(a.Stack,{children:[n(a.LoadingOverlay,{visible:g}),f===0&&n(a.Alert,{icon:n(k.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),l.map(h=>n(ky,{onRemove:c,instance:s,sampleData:o,variables:u,item:h,manager:e.interactionManager},h.id)),n(a.Button,{style:{width:"fit-content"},onClick:()=>d(),disabled:f===0,children:"Add interaction"})]})},My=()=>{const{panel:e,data:t}=Ce(),r=e.viz,{vizManager:i}=b.useContext(qe),s=e.json,o=Z.useCreation(()=>i.getOrCreateInstance(s),[i,s]),u=Z.useCreation(()=>new sr(o,i.resolveComponent(r.type),tn),[o,r.type]);return b.useEffect(()=>o.instanceData.watchItem(null,v.throttle(l=>{e.viz.setConf(l)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:u,sampleData:t,variables:[]}},Iy=()=>{const e=My();return n(Dy,{...e})};var ja=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(ja||{}),nn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(nn||{});class Ay{constructor(t){O(this,"vizInstance");O(this,"operationManager");O(this,"triggerManager");O(this,"vizManager");O(this,"runningMigration");O(this,"panelModel");O(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(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"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),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Ra(e){const{panel:t}=Ce();return b.useCallback(r=>{const i=r.getRequired(be.vizManager),s=i.resolveComponent(e.viz.type);return r.createScoped().provideFactory(be.instanceScope.vizInstance,()=>i.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const u=o.getRequired(be.instanceScope.vizInstance);return new sr(u,s,tn)}).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 Ay(o))},[e.viz.type,e.viz.conf])}function Ya(e){const[t,r]=b.useState(!1),i=zi().getRequired(be.instanceScope.migrator);return Z.useAsyncEffect(async()=>{const s=i.status===nn.notStarted;r(i.status===nn.done),i.status===nn.notStarted&&i.runMigration().then(o=>{o===ja.migrated&&s&&(e==null||e())}).finally(()=>{r(!0)})},[i]),t}function Qa(e,t){const r=zi().getRequired(be.instanceScope.vizInstance);return b.useEffect(()=>(r.instanceData.setItem(null,t.viz.conf),r.instanceData.watchItem(null,i=>{e(i)})),[e,t.viz.type]),r}function $y({setVizConf:e,...t}){const{panel:r}=t,i=Qa(e,r),s=Ya(()=>{Vt.showNotification({title:`${r.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Z.useAsyncEffect(async()=>{await i.instanceData.setItem(null,r.viz.conf)},[i,r.viz.type]),s?n(Ko,{...t}):n(a.Text,{children:"Checking update..."})}function zy(e){const{panel:t,setVizConf:r}=e;Qa(r,t);const{inEditMode:i}=b.useContext(Ke);return Ya(()=>{i&&Vt.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n(Zo,{...e}):n(a.Text,{children:"Checking update"})}const P1="";function Ey(e,t){const{vizManager:r}=b.useContext(qe),{panel:{viz:i,title:s,id:o,description:u,queryID:l,variables:d}}=Ce(),c={title:s,id:o,description:u,queryID:l,viz:i,layout:t},f=Ra(c);try{return r.resolveComponent(i.type),n(Gt,{configure:f,children:n(zy,{setVizConf:i.setConf,panel:c,data:e,variables:d,vizManager:r})})}catch(g){return console.info(v.get(g,"message")),null}}const Ly=["richText","button"],Ua=T.observer(function({height:t,viz:r,data:i,loading:s,error:o,query:u}){const{ref:l,width:d,height:c}=ve.useElementSize(),f=Ey(i,{w:d,h:c});if(Ly.includes(r.type))return n("div",{className:"viz-root",style:{height:t},ref:l,children:n(ke,{children:f})});if(s)return n("div",{className:"viz-root",style:{height:t,position:"relative"},ref:l,children:n(a.LoadingOverlay,{visible:s,exitTransitionDuration:0})});const h=!!o,m=!h&&!!(u!=null&&u.stateMessage),w=!h&&!m;return p("div",{className:"viz-root",style:{height:t},ref:l,children:[h&&n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:o}),m&&n(a.Text,{color:"gray",align:"center",children:u.stateMessage}),w&&n(ke,{children:f})]})});function Py(e){return!["richText","button"].includes(e)}const Oy={border:"1px solid #e9ecef"},Xa={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function Vy(e,t,r){return e.style.border.enabled?Oy:r||t?Xa:{border:"1px dashed transparent"}}const rn=T.observer(function({panel:t,view:r}){const i=F(),{inEditMode:s}=b.useContext(Ke),{data:o,state:u,error:l}=i.getDataStuffByID(t.queryID),d=i.queries.findByID(t.queryID),c=Py(t.viz.type),f=c&&u==="loading",g=t.title?"calc(100% - 25px - 5px)":"100%",h=Vy(t,c,s),m=c||s;return n(Cn,{value:{panel:t,data:o,loading:f},children:p(a.Box,{className:"panel-root",p:5,pt:0,sx:{...h},children:[n(a.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:n(Gi,{})}),m&&n(Yo,{view:r}),n(Qo,{}),n(Ua,{viz:t.viz,data:o,loading:f,error:l,height:g,query:d})]})})}),O1="",By=b.forwardRef(({h:e},t)=>n(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n(k.ArrowsMove,{size:16})})),Ny=b.forwardRef(({handleAxis:e,...t},r)=>n(a.ActionIcon,{ref:r,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:n(k.ChevronDownRight,{size:16})})),Gy=Ot.WidthProvider(Ot),qy=T.observer(({view:e,className:t="layout"})=>{const r=F(),{panels:i,layouts:s}=r.panels.panelsByIDs(e.panelIDs),o=b.useCallback(l=>{l.forEach(({i:d,...c})=>{const f=r.panels.findByID(d);f&&f.layout.set(c)})},[r]),u=(l,d,c,f)=>{c.h<30&&(c.h=30,f.h=30),c.w<4&&(c.w=4,f.w=4)};return n(Gy,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:s,draggableHandle:".react-grid-customDragHandle",resizeHandle:n(Ny,{}),onResize:u,children:i.map((l,d)=>p("div",{"data-grid":{...l.layout},className:"panel-grid-item",children:[n(By,{h:l.layout.h}),n(rn,{view:e,panel:l})]},l.id))})}),Fy=Ot.WidthProvider(Ot),Wy=T.observer(function({view:t,className:r="layout"}){const{panels:i,layouts:s}=F().panels.panelsByIDs(t.panelIDs);return n(Fy,{className:`dashboard-layout ${r}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:s,children:i.map(o=>n("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:n(rn,{view:t,panel:o})},o.id))})});var Za=(e=>(e.Use="use",e.Edit="edit",e))(Za||{}),K=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(K||{});const jy={div:"Division",tabs:"Tabs",modal:"Modal"},Ka={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},Ry={div:"#ff4000",modal:"#000",tabs:"#ffad18"},Yy={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"8.57.0"};var or=(e=>(e.Select="select",e.TreeSelect="tree-select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(or||{});const Qy=T.observer(({children:e})=>n(a.Box,{pt:10,pb:100,children:e})),Uy=T.observer(({children:e,view:t})=>{const r=t.config;return n(a.Modal,{size:r.width,overflow:"inside",opened:!0,onClose:v.noop,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),Xy=({variant:e,orientation:t})=>{const r={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},Zy=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Ky=T.observer(({children:e,view:t})=>{const r=Le.useModals(),i=F(),s=b.useMemo(()=>i.views.options.filter(d=>d.type===K.Division),[t.id,i.views.options]),o=t.config,u=d=>r.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(d)},confirmProps:{color:"red"},zIndex:320}),l=o.tabs.length===0;return p(a.Box,{className:"preview-view-tabs",children:[p(a.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:Xy(o),children:[p(a.Tabs.List,{grow:o.grow,children:[o.tabs.map(d=>n(a.Tabs.Tab,{value:d.id,sx:Zy(d),children:d.name??d.id},d.id)),n(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n(k.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((d,c)=>{const f=i.views.findByID(d.view_id);return p(a.Tabs.Panel,{value:d.id,sx:{position:"relative"},children:[p(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n(a.TextInput,{label:"Tab Name",value:d.name,onChange:g=>d.setName(g.currentTarget.value)}),n(a.Select,{label:"View",value:d.view_id,onChange:d.setViewID,data:s}),n(a.ColorInput,{label:"Color",value:d.color,onChange:d.setColor,disabled:o.variant!=="default"}),f&&p(a.Button,{mt:20,variant:"gradient",leftIcon:n(V.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>i.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),n(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>u(c),disabled:l,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&n(an,{view:f})]},d.id)})]}),e]})}),Jy=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(Uy,{view:e,children:t});case K.Tabs:return n(Ky,{view:e,children:t});case K.Division:default:return n(Qy,{children:t})}}),Ja=T.observer(function({view:t}){return n(yn.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:n(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:n(Jy,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Ni,{view:t})}),n(qy,{view:t})]})})})})}),Hy={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},ev=T.observer(function({view:t,panel:r,exitFullScreen:i}){return n(a.Modal,{opened:!0,fullScreen:!0,onClose:i,title:n(a.Button,{color:"blue",size:"xs",onClick:i,leftIcon:n(k.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:Hy,children:n(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n(rn,{view:t,panel:r})})})});function tv(e,t,r){const{panels:i}=F(),s=e.id==="Main",[o,u]=b.useState(()=>s&&i.findByID(t)?t:null),l=b.useCallback(g=>{u(g),s&&r(g)},[s,r]),d=b.useCallback(()=>{u(null),s&&r("")},[s,r]),c=o?i.findByID(o):null;return{viewPanelInFullScreen:l,exitFullScreen:d,inFullScreen:!!c,fullScreenPanel:c}}const nv=T.observer(({children:e})=>n(a.Box,{children:e})),rv=T.observer(({children:e,view:t})=>{const r=F(),i=t.config,s=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id);return n(a.Modal,{size:i.width,centered:!0,overflow:"inside",opened:s,onClose:o,withCloseButton:!1,title:i.custom_modal_title.value,trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:i.height,overflow:"auto"}},transitionDuration:0,children:e})}),iv=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},av=T.observer(({children:e,view:t})=>{const r=F(),i=t.config;return p(a.Box,{className:"render-view-tabs",children:[p(a.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:{panel:{padding:i.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[n(a.Tabs.List,{grow:i.grow,children:i.tabs.map(s=>n(a.Tabs.Tab,{value:s.id,sx:iv(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),i.tabs.map(s=>{const o=r.views.findByID(s.view_id);return o?n(a.Tabs.Panel,{value:s.id,children:n(an,{view:o})},s.id):null})]}),e]})}),sv=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(rv,{view:e,children:t});case K.Tabs:return n(av,{view:e,children:t});case K.Division:default:return n(nv,{children:t})}}),an=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:i}=Oi(),{viewPanelInFullScreen:s,exitFullScreen:o,inFullScreen:u,fullScreenPanel:l}=tv(t,r,i);return n(yn.Provider,{value:{viewPanelInFullScreen:s,inFullScreen:u},children:p(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[u&&n(ev,{view:t,panel:l,exitFullScreen:o}),n(sv,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[!u&&n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Ni,{view:t})}),!u&&n(Wy,{view:t})]})})]})})});function ov(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let i=0;i<t.length;i++){const s=t[i];if(s!="authentication"&&e[s])r.push(t[i]+"="+(typeof e[s]=="object"?JSON.stringify(e[s]):e[s]));else{const o=Object.keys(e[s]).sort();for(let u=0;u<o.length;u++){const l=o[u];l!="sign"&&e[s][l]&&r.push(o[u]+"="+(typeof e[s][l]=="object"?JSON.stringify(e[s][l]):e[s][l]))}}}return r.sort().join("&")}function lv(e,t){let r=ov(e);return r+="&key="+t,Mi.MD5(r).toString().toUpperCase()}const ze={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:lv({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(r,i,s={})=>{const o=window.localStorage.getItem("token"),u={"X-Requested-With":"XMLHttpRequest","Content-Type":s.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...s.headers},l={baseURL:this.baseURL,method:e,url:r,params:e==="GET"?i:s.params,headers:u,signal:t};return["POST","PUT"].includes(e)&&(l.data=s.string?JSON.stringify(i):i,l.data.authentication=this.getAuthentication(l.data)),Xe(l).then(d=>d.data).catch(d=>Promise.reject(d))}}};function Ha(e){ze.baseURL!==e.apiBaseURL&&(ze.baseURL=e.apiBaseURL),e.app_id&&(ze.app_id=e.app_id),e.app_secret&&(ze.app_secret=e.app_secret)}const es=y.types.model("FilterConfigModel_Checkbox",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:i}=e;return{_name:t,description:r,default_value:i}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),uv=()=>es.create({_name:"checkbox",description:"",default_value:!1});var ce=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(ce||{}),we=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(we||{});y.types.model({type:y.types.enumeration("DataSourceType",[ce.Postgresql,ce.MySQL,ce.HTTP]),key:y.types.string,sql:y.types.string});function ts(e,t){return e.map(r=>{try{return r?j.tz(r,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const dv=y.types.model("FilterConfigModel_DateRange",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:u,allowSingleDateInRange:l}=e;return{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:ts(u,o),allowSingleDateInRange:l}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(r=>!!r)}})).views(e=>({getMaxDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").add(r,"days").toDate()},getMinDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").subtract(r,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const r=y.getParent(e);y.getRoot(e).filters.setValueByKey(r.key,t)}catch(r){console.error(r)}}})).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}})),ns=y.types.snapshotProcessor(dv,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:j.tz(r,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:ts(t,r.inputFormat)}}}),cv=()=>ns.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),pv=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),lr=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(pv),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.types.number,0)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:r,error:i}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return r==="idle"?t:[]}})).actions(e=>({addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),sn=e=>v.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return se.toJS(t)}),rs=y.types.compose("FilterConfigModel_MultiSelect",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),lr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return sn({_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,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}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,r=y.getParent(e).key;t.setValueByKey(r,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>se.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),hv=()=>rs.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),is=y.types.compose("FilterConfigModel_TreeSelect",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),lr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return{_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,default_selection_count:u}}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t}})),fv=()=>is.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),as=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),lr).views(e=>({get json(){const{_name:t,default_value:r,required:i,width:s,static_options:o,options_query_id:u,default_selection_count:l}=e;return sn({_name:t,width:s,required:i,default_value:r,static_options:o,options_query_id:u,default_selection_count:l})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),gv=()=>as.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ss=y.types.model("FilterConfigModel_TextInput",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:i}=e;return{_name:t,required:r,default_value:i}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),os=()=>ss.create({_name:"text-input",required:!1,default_value:""}),ur=y.types.model("FilterModel",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[we.Select,we.MultiSelect,we.TreeSelect,we.TextInput,we.Checkbox,we.DateRange]),config:y.types.union(as,rs,is,ss,es,ns)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==we.TreeSelect},get auto_submit_supported(){return[we.Select,we.Checkbox,we.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:i,order:s,visibleInViewsIDs:o,auto_submit:u,type:l,config:d}=e;return{id:t,key:r,type:l,label:i,order:s,config:d.json,auto_submit:u,visibleInViewsIDs:se.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case we.Select:e.config=gv();break;case we.MultiSelect:e.config=hv();break;case we.TreeSelect:e.config=fv();break;case we.TextInput:e.config=os();break;case we.Checkbox:e.config=uv();break;case we.DateRange:e.config=cv();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));function ls(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...r]=e;return r.map(i=>i===null?i:j.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),e}return e}function us(e){return e.reduce((t,r)=>(t[r.key]=ls(r.config.default_value,r.config),t),{})}function mv(e,t,r){y.addDisposer(e,y.addMiddleware(e,(i,s)=>{s(i,()=>{y.getType(i.context)===t&&i.type==="action"&&r(i.name,i.context)})}))}const ds=y.types.model("FiltersModel",{current:y.types.optional(y.types.array(ur),[]),values:y.types.optional(y.types.frozen(),{}),previewValues:y.types.optional(y.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},get inOrder(){return v.sortBy(e.current,"order")},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get empty(){return e.current.length===0},visibleInView(t){return v.sortBy(e.current.filter(r=>r.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r>=0&&e.current.splice(r,1)},setValues(t){e.values=t},setValueByKey(t,r){e.values={...e.values,[t]:r}},getValueByKey(t){return e.values[t]},refreshValues(){console.log("refreshing values"),e.values=us(e.current)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){mv(e.current,ur,(r,i)=>{if(r==="setType"){const s=ls(i.config.default_value,i.config);e.setValueByKey(i.key,s),e.updatePreviewValues({...e.previewValues,[i.key]:s})}})}return{afterCreate(){t()}}});function cs(e){return{current:e,values:us(e)}}const ps="\uFEFF";function bv(e,t){const r=new Blob([ps+t],{type:"text/csv"});gn.saveAs(r,`${e}.csv`)}function yv(e,t){const r=new Blob([t],{type:"application/json"});gn.saveAs(r,`${e}.json`)}function vv(e){const t=new mo;e.forEach(({id:r,data:i})=>{t.file(`${r}.csv`,fs(i))}),t.generateAsync({type:"blob"}).then(r=>{gn.saveAs(r,"dashboard_data.zip")})}function hs(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function fs(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],r=Object.keys(e[0]).map(hs);return t.push(r.join(",")),e.forEach(i=>{const s=Object.values(i).map(hs).join(",");t.push(s)}),ps+t.join(`
|
|
367
|
-
`)}const ht={CryptoJS:Mi,d3Array:vo,dayjs:j,lodash:v,numbro:te,mathjs:Nt,faker:bo.faker},
|
|
366
|
+
`}},show_in_legend:!0}))}function wb(e,t,r,i){const s=t.data_key,o=t.name,u=r.map(l=>{const d=v.sumBy(i[l],s);return[l,d]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:u,show_in_legend:!1}}function _b(e,t,r,i){const u={barMinWidth:5,barMaxWidth:20};return[bb(e,r,i),vb(e,r,i,u),...Cb(e,r,i,u),wb(e,t,r,i)]}function Sb(e,t){const{axisLabel:r}=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:{...r,formatter:ya(r.formatter)},axisLine:{show:!1}}]}function Tb(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 rr(e){return e==1||e==2?1:rr(e-2)+rr(e-1)}const kb=Array.from(new Array(20),(e,t)=>rr(t+1));function Ga(e){return e<=1?e:kb.findIndex(t=>e<=t)-1}function Db(e,t){const{estimated_value:r,actual_value:i}=e.deviation.data_keys;return t.map(s=>{const o=Ga(s[r]),u=Ga(s[i]),l=o-u;return{...s,level:{estimated:o,actual:u,diff:l}}})}function Mb(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function Ib(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(r=>r.show_in_legend).reverse().map(r=>({name:`${r.name}`,color:r.color,itemStyle:Mb(r.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const Ab={tooltip:{trigger:"axis"}};function $b(e,t){const{deviation:r,metrics:i}=e,s=i.find(u=>u.data_key===t);if(s)return s;const o=r.data_keys.actual_value;return{id:o,name:r.name,data_key:o}}function zb(e,t,r){const i=Db(e,r),s=v.uniqBy(r,e.x_axis.data_key).map(c=>c[e.x_axis.data_key]),o=v.groupBy(i,e.x_axis.data_key),u=$b(e,t),l=_b(e,u,s,o),d={xAxis:Sb(e,s),yAxis:Tb(u),series:l,grid:mb(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:Ib(l)};return v.defaultsDeep({},d,Ab)}const ir={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Jt}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]},Eb={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},Lb=({conf:e,metricKey:t,setMetricKey:r})=>{const{deviation:i,metrics:s}=e,o=b.useMemo(()=>{const u=s.map(l=>({label:l.name,value:l.data_key}));return u.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),u},[i,s]);return p(a.Group,{spacing:1,children:[n(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),n(a.NativeSelect,{size:"xs",data:o,value:t,onChange:u=>r(u.currentTarget.value),styles:Eb})]})},Pb={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ob(){return p(a.HoverCard,{width:400,shadow:"md",children:[n(a.HoverCard.Target,{children:n(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:n(V.IconInfoCircle,{size:14}),children:"指标说明"})}),n(a.HoverCard.Dropdown,{children:n(a.Table,{fontSize:14,sx:Pb,children:p("tbody",{children:[p("tr",{children:[n("th",{children:"估算偏差"}),n("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[n("th",{children:"准确估算比例"}),n("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function Vb(e){return p(a.Group,{position:"apart",children:[n(Ob,{}),n(Lb,{...e})]})}le.use([de.BarChart,de.LineChart,de.HeatmapChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,Ie.CanvasRenderer,N.VisualMapComponent]);function Bb({conf:e,data:t,width:r,height:i,metricKey:s}){const o=b.useMemo(()=>zb(e,s,t),[e,t,s]);return!r||!i?null:n(Ae,{echarts:le,option:o,style:{width:r,height:i},notMerge:!0,theme:"merico-light"})}function Nb({context:e}){const{value:t}=W(e.instanceData,"config"),r=b.useMemo(()=>v.defaults({},t,ir),[t]),i=e.data,{width:s,height:o}=e.viewport,{x_axis:u,deviation:l}=r,{estimated_value:d,actual_value:c}=l.data_keys,[f,g]=b.useState(c);if(b.useEffect(()=>{g(w=>w||c)},[c]),!u.data_key||!d||!c)return null;const h=Math.max(s,300),m=Math.max(o,370);return p(a.Box,{sx:{overflow:"hidden",height:m,width:h},children:[n(Vb,{conf:r,metricKey:f,setMetricKey:g}),n(Bb,{width:h,height:m-30,data:i,conf:r,metricKey:f})]})}function Gb({data:e,control:t,watch:r}){return r(["x_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.data_key",control:t,render:({field:i})=>n(R,{label:"数据字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"x_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"X轴名称",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:i})=>n(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:n(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...i})}),n(x.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:i})=>n(Ca,{data:e,...i})})]})]})}function qb({data:e,control:t,watch:r}){return r(["deviation"]),p(a.Stack,{children:[n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"deviation.name",control:t,render:({field:i})=>n(a.TextInput,{label:"指标名称",sx:{flex:1},...i})})}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:i})=>n(R,{label:"估算值字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:i})=>n(R,{label:"实际值字段",required:!0,data:e,sx:{flex:1},...i})})]})]})}const Fb=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`metrics.${r}.data_key`,control:e,render:({field:s})=>n(R,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),Wb=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"metrics"}),u=t("metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(B,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(Fb,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function jb({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,ir),[t]),{control:o,handleSubmit:u,watch:l,getValues:d,reset:c}=x.useForm({defaultValues:s});b.useEffect(()=>{c(s)},[s]),l([]);const f=d(),g=b.useMemo(()=>!v.isEqual(f,s),[f,s]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Merico Estimation Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),n(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),n(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),n(a.Tabs.Panel,{value:"X Axis",children:n(Gb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Deviation",children:n(qb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Additional Metrics",children:n(Wb,{control:o,watch:l,data:i})})]})]})})}class Rb extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Yb={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new Rb,name:"mericoEstimationChart",viewRender:Nb,configRender:jb,createConfig:()=>({version:1,config:ir})},Qb=[{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"})),Ub=[Jo,Ho,nl,tl,el,rl],qa=()=>({id:"dashboard",version:Tn,manifest:{viz:[Zn,Af,Xg,dh,Kf,gp,gb,pl,eu,ic,zc,Am,dp,Od,yf,$p,ah,rm,Yb,fu],color:[...Qb,...Ub]}}),Mt=new sl,be={pluginManager:Re("pluginManager"),vizManager:Re("vizManager"),colorManager:Re("colorManager"),instanceScope:{panelModel:Re("panelModel"),vizInstance:Re("vizInstance"),interactionManager:Re("interactionManager"),migrator:Re("migrator"),operationManager:Re("operationManager"),triggerManager:Re("triggerManager")}},ar=()=>{try{Mt.install(qa())}catch{}const e=new Xo(Mt),t=new al(Mt);return{pluginManager:Mt,vizManager:e,colorManager:t}},qe=b.createContext(ar());try{Mt.install(qa())}catch{}function Xb(e,t){const{value:r,set:i}=W(e.operation.operationData,"config"),[s,o]=b.useState(v.defaults({},r,t)),u=async()=>{await i(s)};return b.useEffect(()=>{o(v.defaults({},r,t))},[r]),{config:s,setConfig:o,commit:u}}function Zb(e){const{config:t,setConfig:r,commit:i}=Xb(e,{urlTemplate:"",openInNewTab:!0});async function s(){await i()}async function o(l){r({...t,openInNewTab:l}),await i()}const u=l=>r({...t,urlTemplate:l.currentTarget.value});return p(a.Stack,{children:[n(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:u,onBlur:s}),n(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:l=>o(l.currentTarget.checked)})]})}async function Kb(e,t){const{urlTemplate:r,openInNewTab:i}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:i,payload:e}}))}class Jb extends he{constructor(){super(...arguments);O(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const Hb={displayName:"Open Link",id:"builtin:op:open-link",configRender:Zb,run:Kb,migrator:new Jb,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function ey(e){const{value:t,set:r}=W(e.operationData,"config"),i=s=>void r({template:s});return[(t==null?void 0:t.template)||"",i]}function ty(e){const[t,r]=ey(e.operation);return n(a.TextInput,{defaultValue:t,onBlur:i=>r(i.currentTarget.value),label:"console.log"})}async function ny(e,t){const r=await t.operationData.getItem("config"),i=v.template(r.template||"");console.log("run with payload",e),console.log(i(e))}const ry={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:ty,run:ny},iy=T.observer(e=>{const t=F(),{value:r,set:i}=W(e.operation.operationData,"config");console.log({value:r,viewID:r==null?void 0:r.viewID});const s=(r==null?void 0:r.viewID)||"",o=u=>void i({viewID:u});return n(a.Select,{defaultValue:s,value:s,onChange:o,label:"View",data:t.views.options})});async function ay(e,t){const i=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const sy={displayName:"Open View",id:"builtin:op:open_view",configRender:iy,run:ay},oy={dictionary:{}},ly=T.observer(e=>{const t=F(),{value:r=oy,set:i}=W(e.operation.operationData,"config"),{dictionary:s={}}=r,o=(d,c)=>{i({dictionary:{...s,[d]:c}})},u=()=>{o(t.filters.firstFilterValueKey,"")},l=d=>{const c={...s};delete c[d],i({dictionary:c})};return p(a.Stack,{spacing:10,children:[n(a.Text,{children:"Mapping Rules"}),Object.entries(s).map(([d,c])=>p(a.Flex,{justify:"space-between",gap:10,children:[n(a.TextInput,{label:"Payload key",value:c,onChange:f=>{o(d,f.currentTarget.value)},sx:{flexGrow:1}}),n(R,{data:[t.filters.values],value:d,onChange:f=>{o(f,c)},label:"Filter key",sx:{flexGrow:1}}),n(a.ActionIcon,{onClick:()=>l(d),sx:{marginTop:"26px",flexGrow:0},children:n(k.Trash,{size:14,color:"red"})})]},d)),n(a.Button,{size:"xs",onClick:u,sx:{alignSelf:"center",width:"300px"},children:"Add one mapping rule"})]})});async function uy(e,t){const i=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:e}}))}const dy={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:ly,run:uy},cy={filter_keys:[]},py=T.observer(e=>{const t=F(),{value:r=cy,set:i}=W(e.operation.operationData,"config"),{filter_keys:s=[]}=r,o=l=>{i({filter_keys:[...l]})},u=b.useMemo(()=>t.filters.current.map(l=>({label:l.label,value:l.key})),[t.filters.values]);return n(a.Stack,{spacing:10,children:n(a.MultiSelect,{label:"Select Filters to Clear",data:u,value:s,onChange:o})})});async function hy(e,t){const i=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:e}}))}const tn=[ry,Hb,sy,dy,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:py,run:hy}];class fy{constructor(t,r=tn){O(this,"attachments");this.operations=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,operationData:new lt(s,"data")}};this.attachments=new Sn(t,"__OPERATIONS",i)}async runOperation(t,r){const i=await this.attachments.getInstance(t);if(!i){console.warn(`Operation '${t}' is not defined`);return}const s=this.tryGetSchema(i.schemaRef);if(!s){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await s.run(r,i)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;return u&&await u.needMigration(s)});return(await Promise.all(r)).some(i=>i)}async runMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;u&&await u.needMigration(s)&&await u.migrate(s)});await Promise.all(r)}async createOrGetOperation(t,r){var u;if(!this.getOperationSchemaList().some(l=>l.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const s=await this.attachments.getInstance(t);return!s||s.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((u=r.createDefaultConfig)==null?void 0:u.call(r))??{}}):s}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Fa="__TRIGGERS";class gy{constructor(t,r){O(this,"attachments");this.instance=t,this.component=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,triggerData:new lt(s,"data")}};this.attachments=new Sn(t,Fa,i)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Fa,r=>{const i=v.values(r).map(s=>({id:v.get(s,"id"),schemaRef:v.get(s,"schemaRef"),config:se.toJS(v.get(s,"data.config"))}));t(i)},{fireImmediately:!0})}async createOrGetTrigger(t,r,i={recreate:!1}){var l;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||i.recreate||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((l=r==null?void 0:r.createDefaultConfig)==null?void 0:l.call(r))||{}}):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 r=(await this.getTriggerList()).map(async i=>{const s=this.getTriggerSchemaList().find(l=>l.id===i.schemaRef),o=s==null?void 0:s.migrator,u={configData:i.triggerData};return o&&await o.needMigration(u)?()=>o.migrate(u):null});return Promise.all(r).then(i=>i.filter(s=>s))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class sr{constructor(t,r,i){O(this,"operationManager");O(this,"triggerManager");O(this,"attachments");this.operationManager=new fy(t,i),this.triggerManager=new gy(t,r);const s=async o=>{const{id:u,triggerRef:l,operationRef:d}=await o.getItem(null);return{id:u,triggerRef:l,operationRef:d}};this.attachments=new Sn(t,"__INTERACTIONS",s)}async addInteraction(t,r){const i=t.id,s=r.id,o=`[${i}]:[${s}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:s})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:i,operationRef:s}=r;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(s)<=1&&await this.operationManager.removeOperation(s),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(i=>i.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(i=>i.triggerRef===t).length}async runInteraction(t,r){const s=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(s.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,r)}catch(u){console.warn(`Failed to run operation '${o.operationRef}'`,u)}}))}}const Fe=({vizManager:e,instance:t})=>Z.useCreation(()=>new sr(t,e.resolveComponent(t.type),tn),[t,e]),Wa=e=>{const{title:t="Variables",variables:r}=e,i=ve.useClipboard(),s=o=>{i.copy(o),Vt.showNotification({color:"green",message:"Copied to clipboard"})};return p(a.Paper,{withBorder:!0,p:"sm",children:[n(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),n(a.Stack,{style:{maxHeight:"500px"},children:r.map(o=>p(a.Text,{size:"sm",children:[p(a.Code,{color:"teal",children:["// ",o.description]}),n("br",{}),p(a.Code,{onClick:()=>s(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class my{constructor(t,r){O(this,"operationId");O(this,"operation");O(this,"operationSchema");O(this,"variables",[]);this.operationManager=t,this.instance=r,se.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const i=await this.operationManager.retrieveTrigger(t),s=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));se.runInAction(()=>{this.operationId=t,this.operation=i,this.operationSchema=s,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function by(e){return!!e.operationId}const yy=T.observer(({model:e,onClick:t})=>{var i;const r=(i=e.operationSchema)==null?void 0:i.displayName;return n(a.Button,{variant:"outline",onClick:t,children:r})}),vy=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return b.createElement(e.operationSchema.configRender,t)});function xy({model:e}){const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Operation",data:r,onChange:i,value:e.operationSchema.id})}const Cy=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),{operationManager:s,operationId:o,instance:u,variables:l}=e,d=Z.useCreation(()=>new my(s,u),[s,u]);return Z.useAsyncEffect(async()=>{await d.configOperation(o,l)},[o,d]),by(d)?p(B,{children:[n(yy,{model:d,onClick:r}),n(a.Modal,{size:600,opened:t,onClose:i,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:p(a.Stack,{children:[n(xy,{model:d}),n(vy,{model:d}),n(Wa,{title:"Variables",variables:d.variables})]})})]}):null});class wy{constructor(t,r){O(this,"triggerId");O(this,"trigger");O(this,"triggerSchema");O(this,"sampleData");this.triggerManager=t,this.instance=r,se.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const i=await this.triggerManager.retrieveTrigger(t),s=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));se.runInAction(()=>{this.triggerId=t,this.trigger=i,this.triggerSchema=s,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return _y(this)}}function _y(e){return!!e.triggerId&&!!e.triggerSchema}function Sy(e,t){return Z.useCreation(()=>new wy(e,t),[e,t])}const Ty=T.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,i={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n(a.Button,{variant:"outline",onClick:t,children:b.createElement(r,i)})}),ky=T.observer(({model:e})=>{const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Trigger",data:r,value:e.triggerSchema.id,onChange:i})}),Dy=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return b.createElement(e.triggerSchema.configRender,t)}),My=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),s=e.model;return p(B,{children:[n(a.Modal,{opened:t,onClose:i,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:p(a.Stack,{children:[n(ky,{model:s}),n(Dy,{model:s}),n(Wa,{title:"Payload",variables:s.triggerSchema.payload})]})}),n(Ty,{onClick:r,model:s})]})});function Iy(e,t){const[r,i]=b.useState([]);return Z.useAsyncEffect(async()=>{const s=await e.getInteractionList();i(s)},[t,e]),r}const Ay=T.observer(({item:e,manager:t,instance:r,sampleData:i,variables:s,onRemove:o})=>{const{triggerRef:u,operationRef:l}=e,d=Sy(t.triggerManager,r);if(Z.useAsyncEffect(async()=>{await d.configTrigger(u,i)},[d,u,i]),d.isReady()){const c=[...d.triggerSchema.payload,...s];return p(a.Group,{children:[n(My,{model:d}),n(Cy,{instance:r,operationId:l,variables:c,operationManager:t.operationManager}),n(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:n(k.Trash,{size:16})})]})}return null}),$y=e=>{const[t,r]=b.useState(0),{interactionManager:i,instance:s,sampleData:o,variables:u}=e,l=Iy(i,t),d=async()=>{const h=await i.triggerManager.createOrGetTrigger(ve.randomId(),i.triggerManager.getTriggerSchemaList()[0]),m=await i.operationManager.createOrGetOperation(ve.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(h,m),r(w=>w+1)};async function c(h){await i.removeInteraction(h.id),r(m=>m+1)}const{data:f=0,loading:g}=Z.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(a.Stack,{children:[n(a.LoadingOverlay,{visible:g}),f===0&&n(a.Alert,{icon:n(k.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),l.map(h=>n(Ay,{onRemove:c,instance:s,sampleData:o,variables:u,item:h,manager:e.interactionManager},h.id)),n(a.Button,{style:{width:"fit-content"},onClick:()=>d(),disabled:f===0,children:"Add interaction"})]})},zy=()=>{const{panel:e,data:t}=Ce(),r=e.viz,{vizManager:i}=b.useContext(qe),s=e.json,o=Z.useCreation(()=>i.getOrCreateInstance(s),[i,s]),u=Z.useCreation(()=>new sr(o,i.resolveComponent(r.type),tn),[o,r.type]);return b.useEffect(()=>o.instanceData.watchItem(null,v.throttle(l=>{e.viz.setConf(l)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:u,sampleData:t,variables:[]}},Ey=()=>{const e=zy();return n($y,{...e})};var ja=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(ja||{}),nn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(nn||{});class Ly{constructor(t){O(this,"vizInstance");O(this,"operationManager");O(this,"triggerManager");O(this,"vizManager");O(this,"runningMigration");O(this,"panelModel");O(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(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"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),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Ra(e){const{panel:t}=Ce();return b.useCallback(r=>{const i=r.getRequired(be.vizManager),s=i.resolveComponent(e.viz.type);return r.createScoped().provideFactory(be.instanceScope.vizInstance,()=>i.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const u=o.getRequired(be.instanceScope.vizInstance);return new sr(u,s,tn)}).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 Ly(o))},[e.viz.type,e.viz.conf])}function Ya(e){const[t,r]=b.useState(!1),i=zi().getRequired(be.instanceScope.migrator);return Z.useAsyncEffect(async()=>{const s=i.status===nn.notStarted;r(i.status===nn.done),i.status===nn.notStarted&&i.runMigration().then(o=>{o===ja.migrated&&s&&(e==null||e())}).finally(()=>{r(!0)})},[i]),t}function Qa(e,t){const r=zi().getRequired(be.instanceScope.vizInstance);return b.useEffect(()=>(r.instanceData.setItem(null,t.viz.conf),r.instanceData.watchItem(null,i=>{e(i)})),[e,t.viz.type]),r}function Py({setVizConf:e,...t}){const{panel:r}=t,i=Qa(e,r),s=Ya(()=>{Vt.showNotification({title:`${r.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Z.useAsyncEffect(async()=>{await i.instanceData.setItem(null,r.viz.conf)},[i,r.viz.type]),s?n(Ko,{...t}):n(a.Text,{children:"Checking update..."})}function Oy(e){const{panel:t,setVizConf:r}=e;Qa(r,t);const{inEditMode:i}=b.useContext(Ke);return Ya(()=>{i&&Vt.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n(Zo,{...e}):n(a.Text,{children:"Checking update"})}const N1="";function Vy(e,t){const{vizManager:r}=b.useContext(qe),{panel:{viz:i,title:s,id:o,description:u,queryID:l,variables:d}}=Ce(),c={title:s,id:o,description:u,queryID:l,viz:i,layout:t},f=Ra(c);try{return r.resolveComponent(i.type),n(Gt,{configure:f,children:n(Oy,{setVizConf:i.setConf,panel:c,data:e,variables:d,vizManager:r})})}catch(g){return console.info(v.get(g,"message")),null}}const By=["richText","button"],Ua=T.observer(function({height:t,viz:r,data:i,loading:s,error:o,query:u}){const{ref:l,width:d,height:c}=ve.useElementSize(),f=Vy(i,{w:d,h:c});if(By.includes(r.type))return n("div",{className:"viz-root",style:{height:t},ref:l,children:n(ke,{children:f})});if(s)return n("div",{className:"viz-root",style:{height:t,position:"relative"},ref:l,children:n(a.LoadingOverlay,{visible:s,exitTransitionDuration:0})});const h=!!o,m=!h&&!!(u!=null&&u.stateMessage),w=!h&&!m;return p("div",{className:"viz-root",style:{height:t},ref:l,children:[h&&n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:o}),m&&n(a.Text,{color:"gray",align:"center",children:u.stateMessage}),w&&n(ke,{children:f})]})});function Ny(e){return!["richText","button"].includes(e)}const Gy={border:"1px solid #e9ecef"},Xa={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function qy(e,t,r){return e.style.border.enabled?Gy:r||t?Xa:{border:"1px dashed transparent"}}const rn=T.observer(function({panel:t,view:r}){const i=F(),{inEditMode:s}=b.useContext(Ke),{data:o,state:u,error:l}=i.getDataStuffByID(t.queryID),d=i.queries.findByID(t.queryID),c=Ny(t.viz.type),f=c&&u==="loading",g=t.title?"calc(100% - 25px - 5px)":"100%",h=qy(t,c,s),m=c||s;return n(Cn,{value:{panel:t,data:o,loading:f},children:p(a.Box,{className:"panel-root",p:5,pt:0,sx:{...h},children:[n(a.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:n(Gi,{})}),m&&n(Yo,{view:r}),n(Qo,{}),n(Ua,{viz:t.viz,data:o,loading:f,error:l,height:g,query:d})]})})}),G1="",Fy=b.forwardRef(({h:e},t)=>n(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n(k.ArrowsMove,{size:16})})),Wy=b.forwardRef(({handleAxis:e,...t},r)=>n(a.ActionIcon,{ref:r,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:n(k.ChevronDownRight,{size:16})})),jy=Ot.WidthProvider(Ot),Ry=T.observer(({view:e,className:t="layout"})=>{const r=F(),{panels:i,layouts:s}=r.panels.panelsByIDs(e.panelIDs),o=b.useCallback(l=>{l.forEach(({i:d,...c})=>{const f=r.panels.findByID(d);f&&f.layout.set(c)})},[r]),u=(l,d,c,f)=>{c.h<30&&(c.h=30,f.h=30),c.w<4&&(c.w=4,f.w=4)};return n(jy,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:s,draggableHandle:".react-grid-customDragHandle",resizeHandle:n(Wy,{}),onResize:u,children:i.map((l,d)=>p("div",{"data-grid":{...l.layout},className:"panel-grid-item",children:[n(Fy,{h:l.layout.h}),n(rn,{view:e,panel:l})]},l.id))})}),Yy=Ot.WidthProvider(Ot),Qy=T.observer(function({view:t,className:r="layout"}){const{panels:i,layouts:s}=F().panels.panelsByIDs(t.panelIDs);return n(Yy,{className:`dashboard-layout ${r}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:s,children:i.map(o=>n("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:n(rn,{view:t,panel:o})},o.id))})});var Za=(e=>(e.Use="use",e.Edit="edit",e))(Za||{}),K=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(K||{});const Uy={div:"Division",tabs:"Tabs",modal:"Modal"},Ka={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},Xy={div:"#ff4000",modal:"#000",tabs:"#ffad18"},Zy={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"8.57.0"};var or=(e=>(e.Select="select",e.TreeSelect="tree-select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(or||{});const Ky=T.observer(({children:e})=>n(a.Box,{pt:10,pb:100,children:e})),Jy=T.observer(({children:e,view:t})=>{const r=t.config;return n(a.Modal,{size:r.width,overflow:"inside",opened:!0,onClose:v.noop,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),Hy=({variant:e,orientation:t})=>{const r={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},ev=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},tv=T.observer(({children:e,view:t})=>{const r=Le.useModals(),i=F(),s=b.useMemo(()=>i.views.options.filter(d=>d.type===K.Division),[t.id,i.views.options]),o=t.config,u=d=>r.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(d)},confirmProps:{color:"red"},zIndex:320}),l=o.tabs.length===0;return p(a.Box,{className:"preview-view-tabs",children:[p(a.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:Hy(o),children:[p(a.Tabs.List,{grow:o.grow,children:[o.tabs.map(d=>n(a.Tabs.Tab,{value:d.id,sx:ev(d),children:d.name??d.id},d.id)),n(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n(k.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((d,c)=>{const f=i.views.findByID(d.view_id);return p(a.Tabs.Panel,{value:d.id,sx:{position:"relative"},children:[p(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n(a.TextInput,{label:"Tab Name",value:d.name,onChange:g=>d.setName(g.currentTarget.value)}),n(a.Select,{label:"View",value:d.view_id,onChange:d.setViewID,data:s}),n(a.ColorInput,{label:"Color",value:d.color,onChange:d.setColor,disabled:o.variant!=="default"}),f&&p(a.Button,{mt:20,variant:"gradient",leftIcon:n(V.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>i.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),n(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>u(c),disabled:l,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&n(an,{view:f})]},d.id)})]}),e]})}),nv=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(Jy,{view:e,children:t});case K.Tabs:return n(tv,{view:e,children:t});case K.Division:default:return n(Ky,{children:t})}}),Ja=T.observer(function({view:t}){return n(yn.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:n(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:n(nv,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Ni,{view:t})}),n(Ry,{view:t})]})})})})}),rv={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},iv=T.observer(function({view:t,panel:r,exitFullScreen:i}){return n(a.Modal,{opened:!0,fullScreen:!0,onClose:i,title:n(a.Button,{color:"blue",size:"xs",onClick:i,leftIcon:n(k.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:rv,children:n(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n(rn,{view:t,panel:r})})})});function av(e,t,r){const{panels:i}=F(),s=e.id==="Main",[o,u]=b.useState(()=>s&&i.findByID(t)?t:null),l=b.useCallback(g=>{u(g),s&&r(g)},[s,r]),d=b.useCallback(()=>{u(null),s&&r("")},[s,r]),c=o?i.findByID(o):null;return{viewPanelInFullScreen:l,exitFullScreen:d,inFullScreen:!!c,fullScreenPanel:c}}const sv=T.observer(({children:e})=>n(a.Box,{children:e})),ov=T.observer(({children:e,view:t})=>{const r=F(),i=t.config,s=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id);return n(a.Modal,{size:i.width,centered:!0,overflow:"inside",opened:s,onClose:o,withCloseButton:!1,title:i.custom_modal_title.value,trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:i.height,overflow:"auto"}},transitionDuration:0,children:e})}),lv=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},uv=T.observer(({children:e,view:t})=>{const r=F(),i=t.config;return p(a.Box,{className:"render-view-tabs",children:[p(a.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:{panel:{padding:i.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[n(a.Tabs.List,{grow:i.grow,children:i.tabs.map(s=>n(a.Tabs.Tab,{value:s.id,sx:lv(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),i.tabs.map(s=>{const o=r.views.findByID(s.view_id);return o?n(a.Tabs.Panel,{value:s.id,children:n(an,{view:o})},s.id):null})]}),e]})}),dv=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(ov,{view:e,children:t});case K.Tabs:return n(uv,{view:e,children:t});case K.Division:default:return n(sv,{children:t})}}),an=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:i}=Oi(),{viewPanelInFullScreen:s,exitFullScreen:o,inFullScreen:u,fullScreenPanel:l}=av(t,r,i);return n(yn.Provider,{value:{viewPanelInFullScreen:s,inFullScreen:u},children:p(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[u&&n(iv,{view:t,panel:l,exitFullScreen:o}),n(dv,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[!u&&n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Ni,{view:t})}),!u&&n(Qy,{view:t})]})})]})})});function cv(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let i=0;i<t.length;i++){const s=t[i];if(s!="authentication"&&e[s])r.push(t[i]+"="+(typeof e[s]=="object"?JSON.stringify(e[s]):e[s]));else{const o=Object.keys(e[s]).sort();for(let u=0;u<o.length;u++){const l=o[u];l!="sign"&&e[s][l]&&r.push(o[u]+"="+(typeof e[s][l]=="object"?JSON.stringify(e[s][l]):e[s][l]))}}}return r.sort().join("&")}function pv(e,t){let r=cv(e);return r+="&key="+t,Mi.MD5(r).toString().toUpperCase()}const ze={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:pv({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(r,i,s={})=>{const o=window.localStorage.getItem("token"),u={"X-Requested-With":"XMLHttpRequest","Content-Type":s.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...s.headers},l={baseURL:this.baseURL,method:e,url:r,params:e==="GET"?i:s.params,headers:u,signal:t};return["POST","PUT"].includes(e)&&(l.data=s.string?JSON.stringify(i):i,l.data.authentication=this.getAuthentication(l.data)),Xe(l).then(d=>d.data).catch(d=>Promise.reject(d))}}};function Ha(e){ze.baseURL!==e.apiBaseURL&&(ze.baseURL=e.apiBaseURL),e.app_id&&(ze.app_id=e.app_id),e.app_secret&&(ze.app_secret=e.app_secret)}const es=y.types.model("FilterConfigModel_Checkbox",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:i}=e;return{_name:t,description:r,default_value:i}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),hv=()=>es.create({_name:"checkbox",description:"",default_value:!1});var ce=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(ce||{}),we=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(we||{});y.types.model({type:y.types.enumeration("DataSourceType",[ce.Postgresql,ce.MySQL,ce.HTTP]),key:y.types.string,sql:y.types.string});function ts(e,t){return e.map(r=>{try{return r?j.tz(r,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const fv=y.types.model("FilterConfigModel_DateRange",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:u,allowSingleDateInRange:l}=e;return{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:ts(u,o),allowSingleDateInRange:l}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(r=>!!r)}})).views(e=>({getMaxDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").add(r,"days").toDate()},getMinDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").subtract(r,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const r=y.getParent(e);y.getRoot(e).filters.setValueByKey(r.key,t)}catch(r){console.error(r)}}})).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}})),ns=y.types.snapshotProcessor(fv,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:j.tz(r,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:ts(t,r.inputFormat)}}}),gv=()=>ns.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),mv=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),lr=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(mv),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.types.number,0)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:r,error:i}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return r==="idle"?t:[]}})).actions(e=>({addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),sn=e=>v.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return se.toJS(t)}),rs=y.types.compose("FilterConfigModel_MultiSelect",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),lr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return sn({_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,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}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,r=y.getParent(e).key;t.setValueByKey(r,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>se.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),bv=()=>rs.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),is=y.types.compose("FilterConfigModel_TreeSelect",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),lr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return{_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,default_selection_count:u}}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t}})),yv=()=>is.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),as=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),lr).views(e=>({get json(){const{_name:t,default_value:r,required:i,width:s,static_options:o,options_query_id:u,default_selection_count:l}=e;return sn({_name:t,width:s,required:i,default_value:r,static_options:o,options_query_id:u,default_selection_count:l})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),vv=()=>as.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ss=y.types.model("FilterConfigModel_TextInput",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:i}=e;return{_name:t,required:r,default_value:i}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),os=()=>ss.create({_name:"text-input",required:!1,default_value:""}),ur=y.types.model("FilterModel",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[we.Select,we.MultiSelect,we.TreeSelect,we.TextInput,we.Checkbox,we.DateRange]),config:y.types.union(as,rs,is,ss,es,ns)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==we.TreeSelect},get auto_submit_supported(){return[we.Select,we.Checkbox,we.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:i,order:s,visibleInViewsIDs:o,auto_submit:u,type:l,config:d}=e;return{id:t,key:r,type:l,label:i,order:s,config:d.json,auto_submit:u,visibleInViewsIDs:se.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case we.Select:e.config=vv();break;case we.MultiSelect:e.config=bv();break;case we.TreeSelect:e.config=yv();break;case we.TextInput:e.config=os();break;case we.Checkbox:e.config=hv();break;case we.DateRange:e.config=gv();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));function ls(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...r]=e;return r.map(i=>i===null?i:j.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),e}return e}function us(e){return e.reduce((t,r)=>(t[r.key]=ls(r.config.default_value,r.config),t),{})}function xv(e,t,r){y.addDisposer(e,y.addMiddleware(e,(i,s)=>{s(i,()=>{y.getType(i.context)===t&&i.type==="action"&&r(i.name,i.context)})}))}const ds=y.types.model("FiltersModel",{current:y.types.optional(y.types.array(ur),[]),values:y.types.optional(y.types.frozen(),{}),previewValues:y.types.optional(y.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},get inOrder(){return v.sortBy(e.current,"order")},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get empty(){return e.current.length===0},visibleInView(t){return v.sortBy(e.current.filter(r=>r.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r>=0&&e.current.splice(r,1)},setValues(t){e.values=t},setValueByKey(t,r){e.values={...e.values,[t]:r}},getValueByKey(t){return e.values[t]},refreshValues(){console.log("refreshing values"),e.values=us(e.current)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){xv(e.current,ur,(r,i)=>{if(r==="setType"){const s=ls(i.config.default_value,i.config);e.setValueByKey(i.key,s),e.updatePreviewValues({...e.previewValues,[i.key]:s})}})}return{afterCreate(){t()}}});function cs(e){return{current:e,values:us(e)}}const ps="\uFEFF";function Cv(e,t){const r=new Blob([ps+t],{type:"text/csv"});gn.saveAs(r,`${e}.csv`)}function wv(e,t){const r=new Blob([t],{type:"application/json"});gn.saveAs(r,`${e}.json`)}function _v(e){const t=new mo;e.forEach(({id:r,data:i})=>{t.file(`${r}.csv`,fs(i))}),t.generateAsync({type:"blob"}).then(r=>{gn.saveAs(r,"dashboard_data.zip")})}function hs(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function fs(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],r=Object.keys(e[0]).map(hs);return t.push(r.join(",")),e.forEach(i=>{const s=Object.values(i).map(hs).join(",");t.push(s)}),ps+t.join(`
|
|
367
|
+
`)}const ht={CryptoJS:Mi,d3Array:vo,dayjs:j,lodash:v,numbro:te,mathjs:Nt,faker:bo.faker},Sv=[{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"}],Tv=e=>`
|
|
368
368
|
<tr>
|
|
369
369
|
<td><code>${e.name}</code></td>
|
|
370
370
|
<td>
|
|
@@ -376,7 +376,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
376
376
|
>
|
|
377
377
|
</td>
|
|
378
378
|
</tr>
|
|
379
|
-
`,
|
|
379
|
+
`,kv=`
|
|
380
380
|
<p>
|
|
381
381
|
Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
|
|
382
382
|
</p>
|
|
@@ -388,10 +388,10 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
388
388
|
</tr>
|
|
389
389
|
</thead>
|
|
390
390
|
<tbody>
|
|
391
|
-
${
|
|
391
|
+
${Sv.map(Tv).join("")}
|
|
392
392
|
</tbody>
|
|
393
393
|
</table>
|
|
394
|
-
`;function
|
|
394
|
+
`;function Dv(e,t){return new Function(`return ${e}`)()(t,ht)}function Mv(e,t,r){return{context:{...t,...e},filters:r}}function Iv(e,t,r,i){const s=Mv(t,r,i);return Dv(e,s)}function Av(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,ht)}catch(r){return console.error(r),t}}function $v(e,t){try{return new Function(`return ${e.config.processing.post}`)()(t,ht)}catch(r){return console.error(r),t}}function zv(e,t){try{return new Function(`return ${e}`)()(t,ht)}catch(r){return console.error(r),t}}function Ev(e,t,r,i){const s=cr(t,r,[],i),o=Object.keys(s),u=Object.values(s);try{return new Function(...o,`return \`${e}\`;`)(...u)}catch(l){return console.info(l),l.message}}function dr(e,t={}){const r=Object.keys(t),i=Object.values(t);try{return new Function(...r,`return \`${e}\`;`)(...i)}catch(s){throw r.length===0&&e.includes("$")?new Error("[formatSQL] insufficient params"):s}}function cr(e,t,r,i){const s={...t,...e},o={context:s,filters:i},u=r.reduce((l,d)=>(l[d.key]=dr(d.value,o),l),{});return v.merge({},{context:s,filters:i,sql_snippets:u})}function gs(e,t,r,i,s){try{const o=cr(t,r,i,s);return dr(e,o)}catch(o){return console.error(o),o.message}}function Lv({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},ht)}catch(r){return console.error(r),e}}function Pv(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,ht)}catch(r){return console.error(r),t}}async function Ov({context:e,mock_context:t,sqlSnippets:r,query:i,filterValues:s},o){if(!i.sql)return[];const{type:u,key:l,sql:d,pre_process:c,post_process:f}=i,g=cr(e,t,r,s),h=dr(d,g),m=Lv({sql:h,pre_process:c});let w=await ze.getRequest("POST",o)("/query",{type:u,key:l,query:m},{});return w=Pv(f,w),w}async function Vv({context:e,mock_context:t,query:r,filterValues:i,datasource:s},o){const{type:u,key:l,name:d,pre_process:c,post_process:f}=r;let g=Iv(c,e,t,i);console.groupCollapsed(`Request config for: ${d}`),console.log(g),console.groupEnd(),g=Av(s,g);const h=JSON.stringify(g),m=await ze.getRequest("POST",o)("/query",{type:u,key:l,query:h},{});let w=$v(s,m);return w=zv(f,w),w}async function pr(){try{return(await ze.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}const Bv=y.types.model("QueryModel",{id:y.types.string,name:y.types.string,type:y.types.enumeration("DataSourceType",[ce.Postgresql,ce.MySQL,ce.HTTP]),key:y.types.string,sql:y.types.string,pre_process:y.types.optional(y.types.string,""),post_process:y.types.optional(y.types.string,""),run_by:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===ce.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:r,type:i,key:s,sql:o,run_by:u,pre_process:l,post_process:d}=e;return sn({id:t,key:s,sql:o,name:r,type:i,run_by:u,pre_process:l,post_process:d})},get conditionOptions(){if(!y.isAlive(e))return[];const{context:t,mock_context:r,filterValues:i}=y.getRoot(e).content.payloadForSQL,s=Object.keys({...r,...t}).map(l=>`context.${l}`),o=Object.keys(i).map(l=>`filters.${l}`);return[...s,...o].map(l=>({label:l.split(".")[1],value:l,group:v.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!y.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const{context:r,mock_context:i,filterValues:s}=y.getRoot(e).content.payloadForSQL,o={context:{...i,...r},filters:s};return t.filter(u=>{const l=v.get(o,u);return Array.isArray(l)?l.length===0:typeof l=="number"?Number.isNaN(l):!l})}})).views(e=>({get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=y.getRoot(e).content.filters,r=e.unmetRunByConditions.filter(s=>s.startsWith("context.")).map(s=>s.split("context.")[0]),i=e.unmetRunByConditions.filter(s=>s.startsWith("filters.")).map(s=>v.get({filters:t},s)).filter(s=>!!s);return{context:r,filters:i}}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),ms=y.types.compose("QueryModel",Bv,y.types.model({state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),data:y.types.optional(y.types.array(y.types.frozen()),[]),error:y.types.frozen()})).views(e=>({get formattedSQL(){const{context:t,mock_context:r,sqlSnippets:i,filterValues:s}=y.getRoot(e).content.payloadForSQL;return gs(e.sql,t,r,i,s)},get typedAsSQL(){return[ce.Postgresql,ce.MySQL].includes(e.type)},get typedAsHTTP(){return[ce.HTTP].includes(e.type)},get datasource(){const{key:t,type:r}=e;return y.getRoot(e).datasources.find({type:r,key:t})}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:r}=e.conditionNames;if(t.length===0&&r.length===0)return"Waiting";const i=[];return t.length>0&&i.push(`context: ${t.join(", ")}`),r.length>0&&i.push(`filter${r.length>1?"s":""}: ${r.join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:y.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{context:r,mock_context:i,sqlSnippets:s,filterValues:o}=y.getRoot(e).content.payloadForSQL;e.data=yield*y.toGenerator(Ov({context:r,mock_context:i,sqlSnippets:s,title:e.name,query:e.json,filterValues:o},e.controller.signal)),e.state="idle",e.error=null}catch(r){if(!Xe.isCancel(r)){e.data.length=0;const i=v.get(r,"message","unkown error");e.error=v.get(r,"response.data.detail.message",i),e.state="error"}}}}),runHTTP:y.flow(function*(){var t;if(console.log("runHTTP, ",e.datasource),!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{context:r,mock_context:i,filterValues:s}=y.getRoot(e).content.payloadForSQL;e.data=yield*y.toGenerator(Vv({context:r,mock_context:i,query:e.json,filterValues:s,datasource:e.datasource},e.controller.signal)),e.state="idle",e.error=null}catch(r){if(console.error(r),!Xe.isCancel(r)){e.data.length=0;const i=v.get(r,"message","unkown error");e.error=v.get(r,"response.data.detail.message",i),e.state="error"}}}})})).actions(e=>({fetchData:e.typedAsHTTP?e.runHTTP:e.runSQL,beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>{var t,r;return e.typedAsHTTP?`${e.id}--${e.key}--${e.pre_process}--${e.post_process}--${(t=e.datasource)==null?void 0:t.id}`:`${e.id}--${e.key}--${e.formattedSQL}--${e.pre_process}--${e.post_process}--${(r=e.datasource)==null?void 0:r.id}`},e.fetchData,{fireImmediately:!0,delay:0}))}})),bs=y.types.model("QueriesModel",{current:y.types.optional(y.types.array(ms),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return v.sortBy(t,r=>r.label.toLowerCase())}})).views(e=>({get json(){return e.current.filter(t=>t.id).map(t=>t.json)}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},downloadAllData(){const t=e.current.map(({name:r,data:i})=>({id:r,data:i.toJSON()}));_v(t)},downloadDataByQueryID(t){const r=e.findByID(t);if(!r){console.log("[downloadDataByQueryID] query not found");return}const{name:i,data:s}=r,o=fs(s);Cv(i,o)},refetchDataByQueryID(t){const r=e.findByID(t);if(!r){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return r.fetchData()},removeQuery(t){const r=e.current.find(i=>i.id===t);r&&(y.detach(r),e.current.remove(r))}})),ys=y.types.model("SQLSnippetModel",{key:y.types.string,value:y.types.string}).views(e=>({get json(){const{key:t,value:r}=e;return{key:t,value:r}},isADuplicatedKey(t){return!t||t===e.key?!1:!!y.getParent(e,2).findByKey(t)}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}})),vs=y.types.model("SQLSnippetsModel",{current:y.types.optional(y.types.array(ys),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get options(){const t=e.current.map(r=>({label:r.key,value:r.key,_type:"sql_snippet"}));return v.sortBy(t,r=>r.label.toLowerCase())},get record(){return e.current.reduce((t,r)=>(t[r.key]=r.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(r=>r.key===t)}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const r=e.current.findIndex(i=>i.key===t);r>=0&&e.current.splice(r,1)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),xs=y.types.model("ContextModel",{current:y.types.optional(y.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}})),Nv=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=y.getParent(e,1),{type:r,table_name:i,table_schema:s}=t;if(r===ce.MySQL)return`
|
|
395
395
|
SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
|
|
396
396
|
FROM information_schema.columns
|
|
397
397
|
WHERE table_name = '${i}' AND table_schema = '${s}'
|
|
@@ -412,7 +412,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
412
412
|
LEFT JOIN pg_constraint pc ON pc.conrelid = ${o} AND ordinal_position = any(pc.conkey)
|
|
413
413
|
WHERE
|
|
414
414
|
table_name = '${i}' AND table_schema = '${s}';
|
|
415
|
-
`}return""}})),
|
|
415
|
+
`}return""}})),Gv=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=y.getParent(e,1),{type:r,table_name:i,table_schema:s}=t;return r===ce.MySQL?`
|
|
416
416
|
SELECT
|
|
417
417
|
sub_part AS index_length,
|
|
418
418
|
index_name AS index_name,
|
|
@@ -447,22 +447,22 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
447
447
|
JOIN pg_am AS am ON ix.relam = am.oid
|
|
448
448
|
WHERE
|
|
449
449
|
t.relname = '${i}' AND n.nspname = '${s}';
|
|
450
|
-
`:""}})),
|
|
450
|
+
`:""}})),qv=y.types.model({data:y.types.optional(y.types.frozen(),{}),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get sql(){const t=y.getParent(e,1).type;return t===ce.MySQL||t===ce.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),Fv=y.types.model({page:y.types.optional(y.types.number,1),limit:y.types.optional(y.types.number,20),data:y.types.optional(y.types.frozen(),[]),total:y.types.optional(y.types.number,0),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get keywords(){return y.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:r}=y.getParent(e,1);return`${r}||${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 sql(){const t=y.getParent(e,1),{table_name:r,table_schema:i}=t;return`
|
|
451
451
|
SELECT *
|
|
452
452
|
FROM ${i}.${r}
|
|
453
453
|
LIMIT ${e.limit} OFFSET ${(e.page-1)*e.limit}
|
|
454
454
|
`},get countSql(){const{table_name:t,table_schema:r}=e.keywords;return`
|
|
455
455
|
SELECT count(*) AS total
|
|
456
456
|
FROM ${r}.${t}
|
|
457
|
-
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(e,se.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),Nv=y.types.model("DataSourceModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[ce.HTTP,ce.MySQL,ce.Postgresql]),key:y.types.string,config:y.types.frozen(),tables:y.types.optional(Vv,{}),columns:y.types.optional(Pv,{}),tableData:y.types.optional(Bv,{}),indexes:y.types.optional(Ov,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=y.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const i=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tables.signal)("/query",{type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=v.groupBy(i,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(i){if(!Xe.isCancel(i)){e.tables.data={};const s=v.get(i,"message","unkown error");e.tables.error=v.get(i,"response.data.detail.message",s),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:y.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.columns.signal)("/query",{type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(i){if(Xe.isCancel(i))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const s=v.get(i,"message","unkown error");e.columns.error=v.get(i,"response.data.detail.message",s),e.columns.state="error"}}}),loadIndexes:y.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.indexes.signal)("/query",{type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(i){if(Xe.isCancel(i))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const s=v.get(i,"message","unkown error");e.indexes.error=v.get(i,"response.data.detail.message",s),e.indexes.state="error"}}}),loadTableData:y.flow(function*(){var i;(i=e.controllers.tableData)==null||i.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tableData.signal)("/query",{type:e.type,key:e.key,query:r.sql},{}));const[{total:s}]=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tableData.signal)("/query",{type:e.type,key:e.key,query:r.countSql},{}));r.total=Number(s),r.state="idle",r.error=null}catch(s){if(Xe.isCancel(s))r.state="idle",r.error=null;else{r.data=[];const o=v.get(s,"message","unkown error");r.error=v.get(s,"response.data.detail.message",o),r.state="error"}}})}}).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(e,se.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),Gv=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(Nv),[])}).views(e=>({find({type:t,key:r}){return e.list.find(i=>i.key===r&&i.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function on(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function qv(e){switch(e._type){case"GROUP":case"ACTION":return null;case"global_variables":return["_GLOBAL_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 Fv=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=y.getRoot(e),{filters:r,views:i,sqlSnippets:s,queries:o}=t;return[{label:"Global Variables",value:"_GLOBAL_VARS_",_type:"global_variables",Icon:V.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:V.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:V.IconFilter,children:[...r.options,on("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:V.IconCopy,children:[...s.options,on("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:V.IconDatabase,children:[...o.options,on("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:V.IconBoxMultiple,children:[...i.editorOptions,on("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.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 r=qv(t);r&&e.setPath(r)}})),Wv=y.types.model("MockContextModel",{current:y.types.optional(y.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}})),jv=y.types.model("VariableModel",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}))}).views(e=>({get json(){const{name:t,size:r,weight:i,color:s,formatter:o,data_field:u,aggregation:l}=e;return v.cloneDeep({name:t,size:r,color:s,weight:i,formatter:o,data_field:u,aggregation:l})}}));class Rv{constructor(t){O(this,"origin");O(this,"copy");this.origin=t,this.copy=y.clone(t),se.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!v.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(t){y.applySnapshot(this.copy,t)}}const Yv=e=>new Rv(e),Qv=y.types.model("PanelLayoutModel",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:r,w:i,h:s,moved:o}=e;return{h:s,w:i,x:t,y:r===null?0:r,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:r,y:i,w:s,h:o,moved:u}=t;e.x=r,e.y=i,e.w=s,e.h=o,e.moved=!!u,e.static=!!t.static}})),Uv=y.types.model("PanelStyleBorderModel",{enabled:y.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Xv=y.types.model("PanelStyleModel",{border:Uv}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Zv=y.types.model("PanelVizModel",{type:y.types.string,conf:y.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),Cs=y.types.model({id:y.types.string,title:y.types.string,description:y.types.string,layout:Qv,queryID:y.types.string,viz:Zv,style:Xv,variables:y.types.optional(y.types.array(jv),[])}).views(e=>({get query(){return y.getParentOfType(e,It).queries.findByID(e.queryID)},get json(){const{id:t,title:r,description:i,queryID:s}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:r,layout:e.layout.json,queryID:s,variables:e.variables.map(o=>o.json),description:i}}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},setQueryID(t){if(y.getParentOfType(e,It).queries.findByID(t))e.queryID=t;else throw new Error(`Query with id ${t} does not exist`)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)},removeSelf(){y.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){y.getRoot(e).content.views.findByID(t).removePanelID(e.id),y.getRoot(e).content.views.findByID(r).appendPanelID(e.id),y.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}}));function ws(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryID:"",viz:{type:Zn.name,conf:Zn.createConfig()},style:{border:{enabled:!0}}}}const _s=y.types.model("PanelsModel",{list:y.types.optional(y.types.array(Cs),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];t.forEach(s=>{const o=e.idMap.get(s);o?r.push(o):console.warn(`Panel is not found, id:${s}`)});const i=r.map(s=>({...s.layout.json,i:s.id}));return{panels:r,layouts:i}}})).views(e=>({editorOptions(t,r){const{panels:i}=e.panelsByIDs(r);i.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const s=i.map(u=>({label:u.title?u.title:v.capitalize(u.viz.type),value:u.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return s.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),s}})).actions(e=>({replace(t){e.list=y.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(i=>i.id===t);r!==-1&&e.list.splice(r,1)},duplicateByID(t){const r=e.list.find(s=>s.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const i=new Date().getTime().toString();return e.list.push({...r.json,id:i,layout:{...r.layout,y:1/0,moved:!1}}),i},replaceByIndex(t,r){e.list.splice(t,1,r)}})),Ss=y.types.model("ViewModel_Division",{_name:y.types.literal(K.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),Kv=()=>Ss.create({_name:K.Division}),hr={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
458
|
-
`)},Jv=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,i=y.getParent(e,2),s=y.getRoot(e);if(!t)return i.name;try{const o={filters:s.filters.values,context:s.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),i.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),Ts=y.types.model("ViewModel_Modal",{_name:y.types.literal(K.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(Jv,hr)}).views(e=>({get json(){const{_name:t,width:r,height:i,custom_modal_title:s}=e;return{_name:t,width:r,height:i,custom_modal_title:s.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Hv=()=>Ts.create({_name:K.Modal,width:"90vw",height:"90vh"}),ex=y.types.model("ViewModel_Tabs_Tab",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:r,view_id:i,color:s}=e;return{id:t,name:r,color:s,view_id:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),ks=y.types.model("ViewModel_Tabs",{_name:y.types.literal(K.Modal),tabs:y.types.optional(y.types.array(ex),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:i,tabs:s,grow:o}=e;return{grow:o,tabs:s.map(u=>u.json),_name:t,variant:r,orientation:i}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=y.cast(t)},addTab(){const t=ve.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),tx=()=>ks.create({_name:K.Modal,tabs:[]}),Ds=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[K.Division,K.Modal,K.Tabs]),config:y.types.union(Ss,Ts,ks),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:i,config:s}=e;return{id:t,name:r,type:i,config:s.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case K.Division:e.config=Kv();break;case K.Modal:e.config=Hv();break;case K.Tabs:e.config=tx();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const r=e.panelIDs.filter(i=>i!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})).actions(e=>({})),Ms=y.types.model("ViewsModel",{current:y.types.optional(y.types.array(Ds),[]),visibleViewIDs:y.types.array(y.types.string),idOfVIE:y.types.string}).views(e=>({get json(){return e.current.map(t=>sn(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=y.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))}})).actions(e=>({replace(t){e.current.replace(t)},addANewView(t,r,i,s){e.current.push({id:t,name:r,type:i,config:s,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r!==-1&&e.current.splice(r,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},appendToVisibles(t){new Set(e.visibleViewIDs.map(i=>i)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=new Date().getTime().toString();e.addANewView(t,K.Division,K.Division,{_name:K.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(i=>i===t);r!==-1&&e.visibleViewIDs.splice(r,1)}}));function fr(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(s=>{const{_name:o=s.type}=s.config;return{...s,config:{...s.config,_name:o},panelIDs:s.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const nx=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:ds,queries:bs,sqlSnippets:vs,views:Ms,panels:_s,mock_context:Wv,origin:y.types.maybe(y.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=y.getSnapshot(v.get(e,t)).map(i=>v.pick(i,["id","name","key","type","sql","run_by","pre_process","post_process"]));return!v.isEqual(r,v.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get viewsChanged(){const t="views.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!v.isEqual(v.get(e,t),v.get(e.origin,t))},get payloadForSQL(){return{context:y.getParent(e).context.current,mock_context:e.mock_context.current,sqlSnippets:e.sqlSnippets.current,filterValues: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:r,data:i})=>({id:r,data:i})).reduce((r,i)=>(r[i.id]=i.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data.toJSON(),dataProxy:r.data,len:r.data.length,state:r.state,error:r.error}:{data:[],dataProxy:null,len:0,state:"idle",error:void 0}},getDataStateByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.state)??[]},getDataErrorByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.error)??[]}})).views(e=>({findQueryUsage(t){const r=e.panels.idMap,i=e.views.current.flatMap(u=>u.panelIDs.map(l=>r.get(l)).filter(l=>(l==null?void 0:l.queryID)===t).map(l=>({type:"panel",id:l.id,label:l.title?l.title:l.viz.type,views:[{id:u.id,label:u.name}]}))),s=e.views.idMap,o=e.filters.current.filter(u=>v.get(u,"config.options_query_id")===t).map(u=>({type:"filter",id:u.id,label:u.label,views:u.visibleInViewsIDs.map(l=>{var d;return{id:l,label:((d=s.get(l))==null?void 0:d.name)??l}})}));return i.concat(o)}})).actions(e=>({duplicatePanelByID(t,r){var s;const i=e.panels.duplicateByID(t);i&&((s=e.views.findByID(r))==null||s.appendPanelID(i))},removePanelByID(t,r){var i;e.panels.removeByID(t),(i=e.views.findByID(r))==null||i.removePanelID(t)},addANewPanel(t){var i;const r=new Date().getTime().toString();e.panels.append(ws(r)),(i=e.views.findByID(t))==null||i.appendPanelID(r)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:i,content:s}=t;if(!s)throw new Error("unexpected null content when updating a content model");const{version:o,filters:u,views:l,panels:d,definition:{queries:c,sqlSnippets:f,mock_context:g={}}}=s;e.id=r,e.name=i,e.version=o,y.applySnapshot(e.filters.current,u),y.applySnapshot(e.views.current,fr(l).current),y.applySnapshot(e.panels.list,d),y.applySnapshot(e.queries.current,c),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=g}})),It=y.types.snapshotProcessor(nx,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(r=>v.pick(r,["id","key","type","sql"])));return v.defaults({},{queries:{current:t}},e)}});function rx(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function Is({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:l,views:d,panels:c,definition:{queries:f,sqlSnippets:g,mock_context:h={}}}=o;return It.create({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,version:u,filters:cs(l),queries:{current:f},sqlSnippets:{current:g},mock_context:{current:h},views:fr(d),panels:{list:c}})}const As=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:It,content_id:y.types.string,datasources:Gv,context:xs,editor:Fv}).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,r){const{id:i,name:s,group:o,content_id:u}=t;e.id=i,e.name=s,e.group=o,e.content_id=u,this.updateCurrentContent(r)}}));function gr({id:e,name:t,group:r,content_id:i},s,o,u){return As.create({id:e,name:t,group:r,content_id:i,content:Is(s),datasources:{list:o},context:{current:u},editor:{}})}function mr(e){return b.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const V1="",ix=T.observer(({headerMenuItems:e=null})=>{const t=me(),r=F(),i=()=>{const s=JSON.stringify(r.json,null,2),o=`${t.name}__${r.name}`;yv(o,s)};return p(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"light",color:"blue",children:n(V.IconMenu2,{size:14})})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{icon:n(V.IconDownload,{size:14}),onClick:r.queries.downloadAllData,children:"Download Data"}),n(a.Menu.Item,{icon:n(V.IconCode,{size:14}),onClick:i,children:"Download Schema"}),e]})]})}),ax=T.observer(({saveDashboardChanges:e})=>{const t=Le.useModals(),r=F(),i=()=>{t.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},s=r.changed;return p(a.Group,{spacing:0,children:[n(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:n(V.IconDeviceFloppy,{size:18}),onClick:e,disabled:!s,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!s,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"default",disabled:!s,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n(V.IconCaretDown,{size:18})})}),n(a.Menu.Dropdown,{children:n(a.Menu.Item,{icon:n(V.IconRecycle,{size:14,color:"red"}),disabled:!s,onClick:i,children:"Revert Changes"})})]})]})}),sx=T.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:r})=>{const i=yo.useNavigate(),s=me(),o=()=>{i(`/dashboard/${s.id}`)},u=Le.useModals(),l=()=>{u.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},d=s.content.changed;return n(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(a.Group,{children:[n(a.Button,{size:"xs",color:d?"red":"green",leftIcon:n(V.IconArrowLeft,{size:20}),onClick:d?l:o,children:p(a.Group,{spacing:4,children:["End Editing",n(a.Text,{td:"underline",children:s.name})]})}),n(ax,{saveDashboardChanges:e})]}),p(a.Group,{position:"right",sx:{flexGrow:1},children:[t,n(ix,{headerMenuItems:r})]})]})})}),ox={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},lx=T.observer(()=>{const e=F();return n(a.Box,{sx:ox,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(a.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[n(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:n(V.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"}),n(a.Box,{}),n(a.Box,{})]})})}),ux=T.observer(e=>p(B,{children:[n(sx,{...e}),n(lx,{})]})),B1="";function dx(e,t,r){const i=[];return e.filter(s=>"__INTERACTIONS"in s.viz.conf).forEach((s,o)=>{const u=t[s.id];u.data.interactions=v.get(u,"data.interactions",[]);const{__INTERACTIONS:l,__OPERATIONS:d,__TRIGGERS:c}=s.viz.conf;Object.entries(d).forEach(([f,g])=>{const{schemaRef:h,data:m}=g,{config:w}=m;switch(h){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),u.type="interaction",u.data.interactions.push({schemaRef:h,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":i.push({id:`OPERATION--${f}`,source:s.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:Object.keys(w.dictionary).map(S=>({key:S,label:r[S]}))});return;case"builtin:op:clear_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:w.filter_keys.map(S=>({key:S,label:r[S]}))});return;default:return}})}),i}function cx(e,t){const r=e.filters.keyLabelMap;return{edges:dx(e.panels.list,t,r),edgeNodes:[]}}function $s(e,t,r){return e*t+e*r}function px(e,t,r){return e*t+(e-1)*r}const ln=25,br=40,zs=25,yr=350,hx=150,fx=150,Es=150,Ls=300,un=40,Ps=25,gx=300;function mx(e,t){const r=v.keyBy(t,s=>s.id),i=[];return e.current.forEach((s,o)=>{s.panelIDs.forEach((u,l)=>{const d=$s(l,un,Ps)+br,c=r[u];if(!c){i.push({id:u,_node_type:"panel",parentNode:s.id,data:{label:`!: ${u}`},position:{x:ln,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Ls,height:un}});return}const f=c.title.trim()?`${c.title}`:c.viz.type;i.push({id:c.id,_node_type:"panel",parentNode:s.id,data:{label:f},position:{x:ln,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Ls,height:un}})})}),i}const bx={[K.Division]:"Div",[K.Modal]:"Modal",[K.Tabs]:"Tabs"},yx=Ka;function vx(e){return e.current.map((r,i)=>{const s=px(r.panelIDs.length,un,Ps)+br+zs;let o=[];return r.type===K.Tabs&&(o=r.config.tabs.map(l=>l.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${bx[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,className:"light",style:{backgroundColor:yx[r.type],width:yr,height:s}}})}function xx(e){const t=v.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==K.Tabs||r._tab_view_ids.forEach(i=>{t[i].parentNode=r.id})})}function Cx(e){const t=vx(e.views);xx(t);const r=mx(e.views,e.panels.list);return[...t,...r]}function wx({nodeMap:e,nodes:t,edges:r}){t.forEach(i=>{i._node_type!=="view-root"||i._view_type!==K.Tabs||(i.sourcePosition=xe.Position.Bottom,i.style.width=yr+ln*2,i.style.height=zs+i._tab_view_ids.reduce((s,o)=>{const u=e[o];u.position.y=s,u.position.x=ln;const l=u.style.height;return s+l+20},br))})}function _x({nodeMap:e,nodes:t,edges:r}){r.filter(i=>i.label==="Open View").forEach(i=>{const s=e[i.source],o=e[i.target];if(!s||!o||!s.parentNode)return;const u=e[s.parentNode];u._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+u._view_level,u._sub_view_ids.push(o.id))}),t.sort((i,s)=>i._node_type==="view-root"&&s._node_type==="view-root"?i._view_level-s._view_level:i._node_type!=="view-root"&&s._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function Sx({nodeMap:e,nodes:t,edges:r}){const i={};r.forEach(s=>{if(s.label!=="Open View")return;const o=e[s.source],u=e[s.target];if(o&&u&&o.parentNode){const l=e[o.parentNode],d=l.position.x,c=Number(v.get(u,"style.height",0)),f=Number(l.style.width);u.position.x=d+f+gx,l._view_level===0&&u._sub_view_ids.length===0&&(o.sourcePosition=xe.Position.Left,u.targetPosition=xe.Position.Right,u.position.x*=-1);const h=u.position.x,m=v.get(i,h,0);u.position.y=m,i[h]=m+c+Es}})}function Tx({nodeMap:e,nodes:t,edges:r}){const i=new Set,s=new Set;r.forEach(u=>{i.add(u.source),s.add(u.target)}),t.filter(u=>u._node_type!=="view-root"||u.id==="Main"||u.parentNode?!1:!i.has(u.id)&&!s.has(u.id)).forEach((u,l)=>{u.position.x=$s(l,yr,fx),u.position.y=0-hx-Es})}function kx({nodeMap:e,nodes:t,edges:r}){const i={nodeMap:e,nodes:t,edges:r};return Tx(i),_x(i),wx(i),Sx(i),{nodes:t,edges:r}}function Dx(e){const t=Cx(e),r=v.keyBy(t,d=>d.id),{edges:i,edgeNodes:s}=cx(e,r),o=[...t,...s],u=v.keyBy(o,d=>d.id),l={edges:v.uniqBy(i,d=>d.id),nodes:o,nodeMap:u};return kx(l)}const N1="",vr={"builtin:op:open-link":n(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n(V.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleOff,{size:14})})};function Mx(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:vr[r.schemaRef],text:p(a.Group,{spacing:4,children:[n(a.Text,{children:"Open: "}),n(a.Text,{color:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:vr[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Set Filter: ",s]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:vr[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Clear Filter: ",s]})})})});return}}),t}const Ix=b.memo(({data:e,isConnectable:t,sourcePosition:r=xe.Position.Right,targetPosition:i=xe.Position.Left,...s})=>{const o=b.useMemo(()=>Mx(e.interactions),[e.interactions]);return p(B,{children:[n(xe.Handle,{type:"target",position:i,isConnectable:t}),n(a.Box,{sx:{position:"absolute",top:0,right:0},children:n(k.ChevronsUpRight,{size:12})}),p(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[n(a.HoverCard.Target,{children:n(a.Text,{children:e.label})}),n(a.HoverCard.Dropdown,{children:n(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(u=>n(a.List.Item,{icon:u.icon,children:u.text},u.key))})})]}),n(xe.Handle,{type:"source",position:r,isConnectable:t})]})}),G1="",Ax={interaction:Ix},$x=T.observer(()=>{const e=F(),{edges:t,nodes:r}=Dx(e);return p(xe,{nodes:r,edges:t,onNodesChange:v.noop,onEdgesChange:v.noop,onConnect:v.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Ax,children:[n(xe.MiniMap,{}),n(xe.Controls,{}),n(xe.Background,{})]})}),zx=T.observer(({opened:e,close:t})=>{const{freezeLayout:r}=b.useContext(Ke);return b.useEffect(()=>{r(e)},[e]),n(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:n($x,{})})}),Ex={"> 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 Lx({onClick:e,name:t,active:r,openSettings:i}){return p(a.Box,{sx:{position:"relative"},children:[n(a.UnstyledButton,{sx:s=>({display:"block",width:"100%",padding:s.spacing.xs,borderRadius:0,position:"relative",color:s.black,"&:hover":{backgroundColor:s.colors.gray[0]},backgroundColor:r?s.colors.gray[2]:"transparent"}),children:n(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n(a.Text,{size:"sm",children:t})})}),r&&n(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n(a.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n(V.IconAdjustments,{size:16})})})]})}const Px=T.observer(()=>{const e=me(),t=F(),r=b.useCallback(s=>()=>t.views.setIDOfVIE(s),[t]),i=s=>{e.editor.open(["_VIEWS_",s])};return p(a.Box,{sx:{position:"relative"},children:[t.views.options.map(s=>n(Lx,{active:t.views.idOfVIE===s.value,name:s.label,onClick:r(s.value),openSettings:()=>i(s.value)},s.value)),n(a.Divider,{variant:"dashed"}),n(a.Button,{variant:"subtle",rightIcon:n(V.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"})]})}),Ox=T.observer(()=>{const e=me(),t=F(),r=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},i=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[s,o]=b.useState(!1),u=()=>o(!0),l=()=>o(!1);return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(a.Navbar.Section,{children:[p(a.Group,{grow:!0,spacing:0,sx:{...Ex,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n(a.Tooltip,{label:"Filters",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:n(V.IconFilter,{size:20})})}),n(a.Tooltip,{label:"Queries",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:n(V.IconDatabase,{size:20})})}),n(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:u,children:n(V.IconLink,{size:20})})})]}),n(zx,{opened:s,close:l})]}),n(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(Px,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",leftIcon:n(V.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),Vx=T.observer(function({config:t}){return p(B,{children:[n(a.Checkbox,{checked:t.default_value,onChange:r=>t.setDefaultValue(r.currentTarget.checked),label:"Default Checked"}),n(Wn,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),Bx=[{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"}],Nx=T.observer(function({config:t}){return p(B,{children:[p(a.Group,{children:[n(a.Checkbox,{checked:t.required,onChange:r=>t.setRequired(r.currentTarget.checked),label:"Required"}),n(a.Checkbox,{checked:t.clearable,onChange:r=>t.setClearable(r.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),n(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:r=>t.setAllowSingleDateInRange(r.currentTarget.checked),label:"Allow choosing 1 day"})]}),n(a.Select,{data:Bx,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),n(Vi,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),n(a.NumberInput,{label:"Max Days",description:p(a.Group,{position:"apart",children:[n(a.Text,{children:"Set 0 to disable."}),p(a.Group,{spacing:4,children:[n(a.Text,{children:"This feature requires"}),n(a.Text,{color:"blue",children:"Clearable"}),n(a.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),xr=T.observer(({value:e,onChange:t})=>{const r=F(),i=b.useMemo(()=>r.queries.options,[r.queries.current]),s=i.length===0;return n(a.Select,{label:"Pick a query",data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:s,error:s?"You need to add a query in Data Settings":void 0})}),Gx=`
|
|
457
|
+
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(e,se.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),Wv=y.types.model("DataSourceModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[ce.HTTP,ce.MySQL,ce.Postgresql]),key:y.types.string,config:y.types.frozen(),tables:y.types.optional(qv,{}),columns:y.types.optional(Nv,{}),tableData:y.types.optional(Fv,{}),indexes:y.types.optional(Gv,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=y.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const i=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tables.signal)("/query",{type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=v.groupBy(i,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(i){if(!Xe.isCancel(i)){e.tables.data={};const s=v.get(i,"message","unkown error");e.tables.error=v.get(i,"response.data.detail.message",s),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:y.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.columns.signal)("/query",{type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(i){if(Xe.isCancel(i))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const s=v.get(i,"message","unkown error");e.columns.error=v.get(i,"response.data.detail.message",s),e.columns.state="error"}}}),loadIndexes:y.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.indexes.signal)("/query",{type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(i){if(Xe.isCancel(i))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const s=v.get(i,"message","unkown error");e.indexes.error=v.get(i,"response.data.detail.message",s),e.indexes.state="error"}}}),loadTableData:y.flow(function*(){var i;(i=e.controllers.tableData)==null||i.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tableData.signal)("/query",{type:e.type,key:e.key,query:r.sql},{}));const[{total:s}]=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tableData.signal)("/query",{type:e.type,key:e.key,query:r.countSql},{}));r.total=Number(s),r.state="idle",r.error=null}catch(s){if(Xe.isCancel(s))r.state="idle",r.error=null;else{r.data=[];const o=v.get(s,"message","unkown error");r.error=v.get(s,"response.data.detail.message",o),r.state="error"}}})}}).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){y.addDisposer(e,se.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(e,se.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),jv=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(Wv),[])}).views(e=>({find({type:t,key:r}){return e.list.find(i=>i.key===r&&i.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function on(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function Rv(e){switch(e._type){case"GROUP":case"ACTION":return null;case"global_variables":return["_GLOBAL_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 Yv=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=y.getRoot(e),{filters:r,views:i,sqlSnippets:s,queries:o}=t;return[{label:"Global Variables",value:"_GLOBAL_VARS_",_type:"global_variables",Icon:V.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:V.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:V.IconFilter,children:[...r.options,on("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:V.IconCopy,children:[...s.options,on("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:V.IconDatabase,children:[...o.options,on("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:V.IconBoxMultiple,children:[...i.editorOptions,on("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.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 r=Rv(t);r&&e.setPath(r)}})),Qv=y.types.model("MockContextModel",{current:y.types.optional(y.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}})),Uv=y.types.model("VariableModel",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}))}).views(e=>({get json(){const{name:t,size:r,weight:i,color:s,formatter:o,data_field:u,aggregation:l}=e;return v.cloneDeep({name:t,size:r,color:s,weight:i,formatter:o,data_field:u,aggregation:l})}}));class Xv{constructor(t){O(this,"origin");O(this,"copy");this.origin=t,this.copy=y.clone(t),se.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!v.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(t){y.applySnapshot(this.copy,t)}}const Zv=e=>new Xv(e),Kv=y.types.model("PanelLayoutModel",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:r,w:i,h:s,moved:o}=e;return{h:s,w:i,x:t,y:r===null?0:r,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:r,y:i,w:s,h:o,moved:u}=t;e.x=r,e.y=i,e.w=s,e.h=o,e.moved=!!u,e.static=!!t.static}})),Jv=y.types.model("PanelStyleBorderModel",{enabled:y.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Hv=y.types.model("PanelStyleModel",{border:Jv}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),ex=y.types.model("PanelVizModel",{type:y.types.string,conf:y.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),Cs=y.types.model({id:y.types.string,title:y.types.string,description:y.types.string,layout:Kv,queryID:y.types.string,viz:ex,style:Hv,variables:y.types.optional(y.types.array(Uv),[])}).views(e=>({get query(){return y.getParentOfType(e,It).queries.findByID(e.queryID)},get json(){const{id:t,title:r,description:i,queryID:s}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:r,layout:e.layout.json,queryID:s,variables:e.variables.map(o=>o.json),description:i}}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},setQueryID(t){if(y.getParentOfType(e,It).queries.findByID(t))e.queryID=t;else throw new Error(`Query with id ${t} does not exist`)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)},removeSelf(){y.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){y.getRoot(e).content.views.findByID(t).removePanelID(e.id),y.getRoot(e).content.views.findByID(r).appendPanelID(e.id),y.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}}));function ws(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryID:"",viz:{type:Zn.name,conf:Zn.createConfig()},style:{border:{enabled:!0}}}}const _s=y.types.model("PanelsModel",{list:y.types.optional(y.types.array(Cs),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];t.forEach(s=>{const o=e.idMap.get(s);o?r.push(o):console.warn(`Panel is not found, id:${s}`)});const i=r.map(s=>({...s.layout.json,i:s.id}));return{panels:r,layouts:i}}})).views(e=>({editorOptions(t,r){const{panels:i}=e.panelsByIDs(r);i.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const s=i.map(u=>({label:u.title?u.title:v.capitalize(u.viz.type),value:u.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return s.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),s}})).actions(e=>({replace(t){e.list=y.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(i=>i.id===t);r!==-1&&e.list.splice(r,1)},duplicateByID(t){const r=e.list.find(s=>s.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const i=new Date().getTime().toString();return e.list.push({...r.json,id:i,layout:{...r.layout,y:1/0,moved:!1}}),i},replaceByIndex(t,r){e.list.splice(t,1,r)}})),Ss=y.types.model("ViewModel_Division",{_name:y.types.literal(K.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),tx=()=>Ss.create({_name:K.Division}),hr={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
458
|
+
`)},nx=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,i=y.getParent(e,2),s=y.getRoot(e);if(!t)return i.name;try{const o={filters:s.filters.values,context:s.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),i.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),Ts=y.types.model("ViewModel_Modal",{_name:y.types.literal(K.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(nx,hr)}).views(e=>({get json(){const{_name:t,width:r,height:i,custom_modal_title:s}=e;return{_name:t,width:r,height:i,custom_modal_title:s.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),rx=()=>Ts.create({_name:K.Modal,width:"90vw",height:"90vh"}),ix=y.types.model("ViewModel_Tabs_Tab",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:r,view_id:i,color:s}=e;return{id:t,name:r,color:s,view_id:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),ks=y.types.model("ViewModel_Tabs",{_name:y.types.literal(K.Modal),tabs:y.types.optional(y.types.array(ix),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:i,tabs:s,grow:o}=e;return{grow:o,tabs:s.map(u=>u.json),_name:t,variant:r,orientation:i}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=y.cast(t)},addTab(){const t=ve.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),ax=()=>ks.create({_name:K.Modal,tabs:[]}),Ds=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[K.Division,K.Modal,K.Tabs]),config:y.types.union(Ss,Ts,ks),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:i,config:s}=e;return{id:t,name:r,type:i,config:s.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case K.Division:e.config=tx();break;case K.Modal:e.config=rx();break;case K.Tabs:e.config=ax();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const r=e.panelIDs.filter(i=>i!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})).actions(e=>({})),Ms=y.types.model("ViewsModel",{current:y.types.optional(y.types.array(Ds),[]),visibleViewIDs:y.types.array(y.types.string),idOfVIE:y.types.string}).views(e=>({get json(){return e.current.map(t=>sn(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=y.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))}})).actions(e=>({replace(t){e.current.replace(t)},addANewView(t,r,i,s){e.current.push({id:t,name:r,type:i,config:s,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r!==-1&&e.current.splice(r,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},appendToVisibles(t){new Set(e.visibleViewIDs.map(i=>i)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=new Date().getTime().toString();e.addANewView(t,K.Division,K.Division,{_name:K.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(i=>i===t);r!==-1&&e.visibleViewIDs.splice(r,1)}}));function fr(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(s=>{const{_name:o=s.type}=s.config;return{...s,config:{...s.config,_name:o},panelIDs:s.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const sx=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:ds,queries:bs,sqlSnippets:vs,views:Ms,panels:_s,mock_context:Qv,origin:y.types.maybe(y.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=y.getSnapshot(v.get(e,t)).map(i=>v.pick(i,["id","name","key","type","sql","run_by","pre_process","post_process"]));return!v.isEqual(r,v.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get viewsChanged(){const t="views.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!v.isEqual(v.get(e,t),v.get(e.origin,t))},get payloadForSQL(){return{context:y.getParent(e).context.current,mock_context:e.mock_context.current,sqlSnippets:e.sqlSnippets.current,filterValues: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:r,data:i})=>({id:r,data:i})).reduce((r,i)=>(r[i.id]=i.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data.toJSON(),dataProxy:r.data,len:r.data.length,state:r.state,error:r.error}:{data:[],dataProxy:null,len:0,state:"idle",error:void 0}},getDataStateByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.state)??[]},getDataErrorByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.error)??[]}})).views(e=>({findQueryUsage(t){const r=e.panels.idMap,i=e.views.current.flatMap(u=>u.panelIDs.map(l=>r.get(l)).filter(l=>(l==null?void 0:l.queryID)===t).map(l=>({type:"panel",id:l.id,label:l.title?l.title:l.viz.type,views:[{id:u.id,label:u.name}]}))),s=e.views.idMap,o=e.filters.current.filter(u=>v.get(u,"config.options_query_id")===t).map(u=>({type:"filter",id:u.id,label:u.label,views:u.visibleInViewsIDs.map(l=>{var d;return{id:l,label:((d=s.get(l))==null?void 0:d.name)??l}})}));return i.concat(o)}})).actions(e=>({duplicatePanelByID(t,r){var s;const i=e.panels.duplicateByID(t);i&&((s=e.views.findByID(r))==null||s.appendPanelID(i))},removePanelByID(t,r){var i;e.panels.removeByID(t),(i=e.views.findByID(r))==null||i.removePanelID(t)},addANewPanel(t){var i;const r=new Date().getTime().toString();e.panels.append(ws(r)),(i=e.views.findByID(t))==null||i.appendPanelID(r)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:i,content:s}=t;if(!s)throw new Error("unexpected null content when updating a content model");const{version:o,filters:u,views:l,panels:d,definition:{queries:c,sqlSnippets:f,mock_context:g={}}}=s;e.id=r,e.name=i,e.version=o,y.applySnapshot(e.filters.current,u),y.applySnapshot(e.views.current,fr(l).current),y.applySnapshot(e.panels.list,d),y.applySnapshot(e.queries.current,c),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=g}})),It=y.types.snapshotProcessor(sx,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(r=>v.pick(r,["id","key","type","sql"])));return v.defaults({},{queries:{current:t}},e)}});function ox(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function Is({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:l,views:d,panels:c,definition:{queries:f,sqlSnippets:g,mock_context:h={}}}=o;return It.create({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,version:u,filters:cs(l),queries:{current:f},sqlSnippets:{current:g},mock_context:{current:h},views:fr(d),panels:{list:c}})}const As=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:It,content_id:y.types.string,datasources:jv,context:xs,editor:Yv}).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,r){const{id:i,name:s,group:o,content_id:u}=t;e.id=i,e.name=s,e.group=o,e.content_id=u,this.updateCurrentContent(r)}}));function gr({id:e,name:t,group:r,content_id:i},s,o,u){return As.create({id:e,name:t,group:r,content_id:i,content:Is(s),datasources:{list:o},context:{current:u},editor:{}})}function mr(e){return b.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const q1="",lx=T.observer(({headerMenuItems:e=null})=>{const t=me(),r=F(),i=()=>{const s=JSON.stringify(r.json,null,2),o=`${t.name}__${r.name}`;wv(o,s)};return p(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"light",color:"blue",children:n(V.IconMenu2,{size:14})})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{icon:n(V.IconDownload,{size:14}),onClick:r.queries.downloadAllData,children:"Download Data"}),n(a.Menu.Item,{icon:n(V.IconCode,{size:14}),onClick:i,children:"Download Schema"}),e]})]})}),ux=T.observer(({saveDashboardChanges:e})=>{const t=Le.useModals(),r=F(),i=()=>{t.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},s=r.changed;return p(a.Group,{spacing:0,children:[n(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:n(V.IconDeviceFloppy,{size:18}),onClick:e,disabled:!s,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!s,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"default",disabled:!s,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n(V.IconCaretDown,{size:18})})}),n(a.Menu.Dropdown,{children:n(a.Menu.Item,{icon:n(V.IconRecycle,{size:14,color:"red"}),disabled:!s,onClick:i,children:"Revert Changes"})})]})]})}),dx=T.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:r})=>{const i=yo.useNavigate(),s=me(),o=()=>{i(`/dashboard/${s.id}`)},u=Le.useModals(),l=()=>{u.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},d=s.content.changed;return n(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(a.Group,{children:[n(a.Button,{size:"xs",color:d?"red":"green",leftIcon:n(V.IconArrowLeft,{size:20}),onClick:d?l:o,children:p(a.Group,{spacing:4,children:["End Editing",n(a.Text,{td:"underline",children:s.name})]})}),n(ux,{saveDashboardChanges:e})]}),p(a.Group,{position:"right",sx:{flexGrow:1},children:[t,n(lx,{headerMenuItems:r})]})]})})}),cx={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},px=T.observer(()=>{const e=F();return n(a.Box,{sx:cx,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(a.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[n(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:n(V.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"}),n(a.Box,{}),n(a.Box,{})]})})}),hx=T.observer(e=>p(B,{children:[n(dx,{...e}),n(px,{})]})),F1="";function fx(e,t,r){const i=[];return e.filter(s=>"__INTERACTIONS"in s.viz.conf).forEach((s,o)=>{const u=t[s.id];u.data.interactions=v.get(u,"data.interactions",[]);const{__INTERACTIONS:l,__OPERATIONS:d,__TRIGGERS:c}=s.viz.conf;Object.entries(d).forEach(([f,g])=>{const{schemaRef:h,data:m}=g,{config:w}=m;switch(h){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),u.type="interaction",u.data.interactions.push({schemaRef:h,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":i.push({id:`OPERATION--${f}`,source:s.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:Object.keys(w.dictionary).map(S=>({key:S,label:r[S]}))});return;case"builtin:op:clear_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:w.filter_keys.map(S=>({key:S,label:r[S]}))});return;default:return}})}),i}function gx(e,t){const r=e.filters.keyLabelMap;return{edges:fx(e.panels.list,t,r),edgeNodes:[]}}function $s(e,t,r){return e*t+e*r}function mx(e,t,r){return e*t+(e-1)*r}const ln=25,br=40,zs=25,yr=350,bx=150,yx=150,Es=150,Ls=300,un=40,Ps=25,vx=300;function xx(e,t){const r=v.keyBy(t,s=>s.id),i=[];return e.current.forEach((s,o)=>{s.panelIDs.forEach((u,l)=>{const d=$s(l,un,Ps)+br,c=r[u];if(!c){i.push({id:u,_node_type:"panel",parentNode:s.id,data:{label:`!: ${u}`},position:{x:ln,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Ls,height:un}});return}const f=c.title.trim()?`${c.title}`:c.viz.type;i.push({id:c.id,_node_type:"panel",parentNode:s.id,data:{label:f},position:{x:ln,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Ls,height:un}})})}),i}const Cx={[K.Division]:"Div",[K.Modal]:"Modal",[K.Tabs]:"Tabs"},wx=Ka;function _x(e){return e.current.map((r,i)=>{const s=mx(r.panelIDs.length,un,Ps)+br+zs;let o=[];return r.type===K.Tabs&&(o=r.config.tabs.map(l=>l.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${Cx[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,className:"light",style:{backgroundColor:wx[r.type],width:yr,height:s}}})}function Sx(e){const t=v.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==K.Tabs||r._tab_view_ids.forEach(i=>{t[i].parentNode=r.id})})}function Tx(e){const t=_x(e.views);Sx(t);const r=xx(e.views,e.panels.list);return[...t,...r]}function kx({nodeMap:e,nodes:t,edges:r}){t.forEach(i=>{i._node_type!=="view-root"||i._view_type!==K.Tabs||(i.sourcePosition=xe.Position.Bottom,i.style.width=yr+ln*2,i.style.height=zs+i._tab_view_ids.reduce((s,o)=>{const u=e[o];u.position.y=s,u.position.x=ln;const l=u.style.height;return s+l+20},br))})}function Dx({nodeMap:e,nodes:t,edges:r}){r.filter(i=>i.label==="Open View").forEach(i=>{const s=e[i.source],o=e[i.target];if(!s||!o||!s.parentNode)return;const u=e[s.parentNode];u._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+u._view_level,u._sub_view_ids.push(o.id))}),t.sort((i,s)=>i._node_type==="view-root"&&s._node_type==="view-root"?i._view_level-s._view_level:i._node_type!=="view-root"&&s._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function Mx({nodeMap:e,nodes:t,edges:r}){const i={};r.forEach(s=>{if(s.label!=="Open View")return;const o=e[s.source],u=e[s.target];if(o&&u&&o.parentNode){const l=e[o.parentNode],d=l.position.x,c=Number(v.get(u,"style.height",0)),f=Number(l.style.width);u.position.x=d+f+vx,l._view_level===0&&u._sub_view_ids.length===0&&(o.sourcePosition=xe.Position.Left,u.targetPosition=xe.Position.Right,u.position.x*=-1);const h=u.position.x,m=v.get(i,h,0);u.position.y=m,i[h]=m+c+Es}})}function Ix({nodeMap:e,nodes:t,edges:r}){const i=new Set,s=new Set;r.forEach(u=>{i.add(u.source),s.add(u.target)}),t.filter(u=>u._node_type!=="view-root"||u.id==="Main"||u.parentNode?!1:!i.has(u.id)&&!s.has(u.id)).forEach((u,l)=>{u.position.x=$s(l,yr,yx),u.position.y=0-bx-Es})}function Ax({nodeMap:e,nodes:t,edges:r}){const i={nodeMap:e,nodes:t,edges:r};return Ix(i),Dx(i),kx(i),Mx(i),{nodes:t,edges:r}}function $x(e){const t=Tx(e),r=v.keyBy(t,d=>d.id),{edges:i,edgeNodes:s}=gx(e,r),o=[...t,...s],u=v.keyBy(o,d=>d.id),l={edges:v.uniqBy(i,d=>d.id),nodes:o,nodeMap:u};return Ax(l)}const W1="",vr={"builtin:op:open-link":n(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n(V.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleOff,{size:14})})};function zx(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:vr[r.schemaRef],text:p(a.Group,{spacing:4,children:[n(a.Text,{children:"Open: "}),n(a.Text,{color:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:vr[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Set Filter: ",s]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:vr[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Clear Filter: ",s]})})})});return}}),t}const Ex=b.memo(({data:e,isConnectable:t,sourcePosition:r=xe.Position.Right,targetPosition:i=xe.Position.Left,...s})=>{const o=b.useMemo(()=>zx(e.interactions),[e.interactions]);return p(B,{children:[n(xe.Handle,{type:"target",position:i,isConnectable:t}),n(a.Box,{sx:{position:"absolute",top:0,right:0},children:n(k.ChevronsUpRight,{size:12})}),p(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[n(a.HoverCard.Target,{children:n(a.Text,{children:e.label})}),n(a.HoverCard.Dropdown,{children:n(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(u=>n(a.List.Item,{icon:u.icon,children:u.text},u.key))})})]}),n(xe.Handle,{type:"source",position:r,isConnectable:t})]})}),j1="",Lx={interaction:Ex},Px=T.observer(()=>{const e=F(),{edges:t,nodes:r}=$x(e);return p(xe,{nodes:r,edges:t,onNodesChange:v.noop,onEdgesChange:v.noop,onConnect:v.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Lx,children:[n(xe.MiniMap,{}),n(xe.Controls,{}),n(xe.Background,{})]})}),Ox=T.observer(({opened:e,close:t})=>{const{freezeLayout:r}=b.useContext(Ke);return b.useEffect(()=>{r(e)},[e]),n(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:n(Px,{})})}),Vx={"> 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 Bx({onClick:e,name:t,active:r,openSettings:i}){return p(a.Box,{sx:{position:"relative"},children:[n(a.UnstyledButton,{sx:s=>({display:"block",width:"100%",padding:s.spacing.xs,borderRadius:0,position:"relative",color:s.black,"&:hover":{backgroundColor:s.colors.gray[0]},backgroundColor:r?s.colors.gray[2]:"transparent"}),children:n(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n(a.Text,{size:"sm",children:t})})}),r&&n(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n(a.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n(V.IconAdjustments,{size:16})})})]})}const Nx=T.observer(()=>{const e=me(),t=F(),r=b.useCallback(s=>()=>t.views.setIDOfVIE(s),[t]),i=s=>{e.editor.open(["_VIEWS_",s])};return p(a.Box,{sx:{position:"relative"},children:[t.views.options.map(s=>n(Bx,{active:t.views.idOfVIE===s.value,name:s.label,onClick:r(s.value),openSettings:()=>i(s.value)},s.value)),n(a.Divider,{variant:"dashed"}),n(a.Button,{variant:"subtle",rightIcon:n(V.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"})]})}),Gx=T.observer(()=>{const e=me(),t=F(),r=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},i=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[s,o]=b.useState(!1),u=()=>o(!0),l=()=>o(!1);return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(a.Navbar.Section,{children:[p(a.Group,{grow:!0,spacing:0,sx:{...Vx,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n(a.Tooltip,{label:"Filters",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:n(V.IconFilter,{size:20})})}),n(a.Tooltip,{label:"Queries",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:n(V.IconDatabase,{size:20})})}),n(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:u,children:n(V.IconLink,{size:20})})})]}),n(Ox,{opened:s,close:l})]}),n(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(Nx,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",leftIcon:n(V.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),qx=T.observer(function({config:t}){return p(B,{children:[n(a.Checkbox,{checked:t.default_value,onChange:r=>t.setDefaultValue(r.currentTarget.checked),label:"Default Checked"}),n(Wn,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),Fx=[{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"}],Wx=T.observer(function({config:t}){return p(B,{children:[p(a.Group,{children:[n(a.Checkbox,{checked:t.required,onChange:r=>t.setRequired(r.currentTarget.checked),label:"Required"}),n(a.Checkbox,{checked:t.clearable,onChange:r=>t.setClearable(r.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),n(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:r=>t.setAllowSingleDateInRange(r.currentTarget.checked),label:"Allow choosing 1 day"})]}),n(a.Select,{data:Fx,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),n(Vi,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),n(a.NumberInput,{label:"Max Days",description:p(a.Group,{position:"apart",children:[n(a.Text,{children:"Set 0 to disable."}),p(a.Group,{spacing:4,children:[n(a.Text,{children:"This feature requires"}),n(a.Text,{color:"blue",children:"Clearable"}),n(a.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),xr=T.observer(({value:e,onChange:t})=>{const r=F(),i=b.useMemo(()=>r.queries.options,[r.queries.current]),s=i.length===0;return n(a.Select,{label:"Pick a query",data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:s,error:s?"You need to add a query in Data Settings":void 0})}),jx=`
|
|
459
459
|
// row
|
|
460
460
|
{
|
|
461
461
|
label: string;
|
|
462
462
|
value: string;
|
|
463
463
|
description?: string; // optional
|
|
464
464
|
}
|
|
465
|
-
`,Os=()=>{const[e,t]=b.useState(!1);return p(B,{children:[n(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(r=>!r),children:e?"Close":"Click to see expected data structure"}),n(a.Collapse,{in:e,children:n(ot.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:
|
|
465
|
+
`,Os=()=>{const[e,t]=b.useState(!1);return p(B,{children:[n(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(r=>!r),children:e?"Close":"Click to see expected data structure"}),n(a.Collapse,{in:e,children:n(ot.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:jx})})]})},Rx=T.observer(function({config:t}){const r=()=>{t.addStaticOption({label:"",value:""})},i=t.static_options,s=[...i];return p(B,{children:[n(a.TextInput,{label:"Width",description:"At least 160px",value:t.min_width,onChange:o=>t.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),n(a.Divider,{label:"Configure options",labelPosition:"center"}),p(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.usingQuery&&p(B,{children:[n(a.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n(a.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&n(a.MultiSelect,{label:"Default Selection",data:s,value:[...t.default_value],onChange:t.setDefaultValue}),i.map((o,u)=>p(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n(a.TextInput,{label:"Label",required:!0,value:t.static_options[u].label,onChange:l=>{t.static_options[u].setLabel(l.currentTarget.value)},sx:{flexGrow:1}}),n(a.TextInput,{label:"Value",required:!0,value:t.static_options[u].value,onChange:l=>{t.static_options[u].setValue(l.currentTarget.value)},sx:{flexGrow:1}}),n(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:n(k.Trash,{size:16})})]},u)),n(a.Button,{mt:10,size:"xs",color:"blue",leftIcon:n(k.PlaylistAdd,{size:20}),onClick:r,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),n(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),n(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),n(xr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),n(Os,{})]})}),Yx=T.observer(function({config:t}){const r=()=>{t.addStaticOption({label:"",value:""})},i=t.static_options,s=[{label:"No default selection",value:""},...i];return p(B,{children:[n(a.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),n(a.TextInput,{label:"Width",value:t.width,onChange:o=>t.setWidth(o.currentTarget.value),placeholder:"200px"}),n(a.Divider,{label:"Configure options",labelPosition:"center"}),p(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.usingQuery&&p(B,{children:[n(a.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n(a.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&n(a.Select,{label:"Default Selection",data:s,value:t.default_value,onChange:t.setDefaultValue}),i.map((o,u)=>p(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n(a.TextInput,{label:"Label",required:!0,value:t.static_options[u].label,onChange:l=>{t.static_options[u].setLabel(l.currentTarget.value)},sx:{flexGrow:1}}),n(a.TextInput,{label:"Value",required:!0,value:t.static_options[u].value,onChange:l=>{t.static_options[u].setValue(l.currentTarget.value)},sx:{flexGrow:1}}),n(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:n(k.Trash,{size:16})})]},u)),n(a.Button,{size:"xs",color:"blue",leftIcon:n(k.PlaylistAdd,{size:20}),onClick:r,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),n(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),n(a.Checkbox,{checked:t.default_selection_count===1,onChange:o=>t.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),n(xr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),n(Os,{})]})}),Qx=T.observer(function({config:t}){return p(B,{children:[n(a.TextInput,{label:"Default Value",value:t.default_value,onChange:r=>{t.setDefaultValue(r.currentTarget.value)}}),n(a.Checkbox,{checked:t.required,onChange:r=>t.setRequired(r.currentTarget.checked),label:"Required"})]})}),Ux=`
|
|
466
466
|
// row
|
|
467
467
|
{
|
|
468
468
|
label: string;
|
|
@@ -470,7 +470,7 @@ Check the top-level render call using <`+E+">.")}return M}}function ao(_,M){{if(
|
|
|
470
470
|
parent_value: string;
|
|
471
471
|
description?: string;
|
|
472
472
|
}
|
|
473
|
-
`,Rx=()=>{const[e,t]=b.useState(!1);return p(B,{children:[n(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(r=>!r),children:e?"Close":"Click to see expected data structure"}),n(a.Collapse,{in:e,children:n(ot.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:jx})})]})},Yx=T.observer(function({config:t}){return p(B,{children:[n(a.TextInput,{label:"Min-width",value:t.min_width,onChange:r=>t.setMinWidth(r.currentTarget.value),placeholder:"200px"}),n(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),n(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),n(xr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),n(Rx,{})]})}),Qx=T.observer(function({filter:t}){const[r,i]=b.useState(t.plainDefaultValue);return b.useEffect(()=>{i(t.plainDefaultValue)},[t]),p(a.Box,{sx:{maxWidth:"480px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Preview"}),n(Bi,{filter:t,value:r,onChange:i}),n(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),n(ot.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Ux={select:Fx,"multi-select":qx,"tree-select":Yx,"text-input":Wx,checkbox:Vx,"date-range":Nx},Xx=[{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"}],Zx=T.observer(function({filter:t}){const r=F(),i=b.useMemo(()=>Ux[t.type],[t.type]);return p(a.Group,{grow:!0,spacing:20,align:"top",children:[p(a.Box,{sx:{maxWidth:"600px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Edit"}),p(a.Stack,{children:[p(a.Group,{noWrap:!0,children:[n(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&n(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:s=>t.setAutoSubmit(s.currentTarget.checked),mt:22})]}),n(a.MultiSelect,{label:"Visible in...",data:r.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),n(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:s=>{t.setKey(s.currentTarget.value)}}),n(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:s=>{t.setLabel(s.currentTarget.value)}}),n(a.Select,{label:"Widget",data:Xx,required:!0,value:t.type,onChange:t.setType}),n(i,{config:t.config})]})]}),n(Qx,{filter:t})]})}),Kx=T.observer(({id:e})=>{const t=Le.useModals(),r=me(),i=F();if(e==="")return null;const s=i.filters.findByID(e);if(!s)return p(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_FILTERS_",""])},u=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this filter"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(Zx,{filter:s})})]})}),Jx=T.observer(()=>{const e=F(),[t,r]=b.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Vt.showNotification({title:"Failed",message:o.message,color:"red"})}},s=b.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n(a.Text,{weight:500,children:"Mock Context"})}),p(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[n(a.Text,{children:"A valid json string is required"}),n(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:r,sx:{flexGrow:1}})]}),n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!s,onClick:i,children:n(k.DeviceFloppy,{size:20})})]})]})}),Hx=T.observer(()=>{const{panel:e}=Ce();return n(Wn,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),e0=T.observer(()=>{const{panel:e}=Ce(),{style:t}=e;return n(B,{children:n(a.Switch,{label:"Border",checked:t.border.enabled,onChange:r=>t.border.setEnabled(r.currentTarget.checked)})})}),t0=T.observer(()=>{const{panel:e}=Ce(),{title:t,setTitle:r}=e,[i,s]=ve.useInputState(t),o=t!==i,u=b.useCallback(()=>{o&&r(i)},[o,i]);return b.useEffect(()=>{s(t)},[t]),n(a.TextInput,{value:i,onChange:s,label:p(a.Group,{children:[n(a.Text,{children:"Panel Title"}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:u,children:n(k.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function n0(){return p(a.Stack,{sx:{height:"100%"},children:[n(a.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),n(e0,{}),n(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),n(t0,{}),n(Hx,{})]})}const r0=({queryID:e})=>{const t=F(),{state:r,error:i}=t.getDataStuffByID(e),s=b.useMemo(()=>t.queries.findByID(e),[t,e]);return r==="loading"?null:i?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):s!=null&&s.stateMessage?n(a.Text,{color:"gray",align:"center",children:s.stateMessage}):null},i0={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Vs({data:e}){const t=b.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const i=Pe.createColumnHelper();return Object.keys(e[0]).map(s=>i.accessor(s,{cell:o=>o.getValue()}))},[e]),r=Pe.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Pe.getCoreRowModel()});return e.length===0?n(a.Box,{sx:{height:"5em"}}):n(ke,{children:p(a.Table,{sx:i0,children:[n("thead",{children:r.getHeaderGroups().map(i=>n("tr",{children:i.headers.map(s=>p("th",{style:{width:s.getSize()},children:[s.isPlaceholder?null:Pe.flexRender(s.column.columnDef.header,s.getContext()),n(a.ActionIcon,{onMouseDown:s.getResizeHandler(),onTouchStart:s.getResizeHandler(),className:`resizer ${s.column.getIsResizing()?"isResizing":""}`,children:n(k.ArrowBarToRight,{})})]},s.id))},i.id))}),n("tbody",{children:r.getRowModel().rows.map(i=>n("tr",{children:i.getVisibleCells().map(s=>n("td",{children:n(ke,{children:Pe.flexRender(s.column.columnDef.cell,s.getContext())})},s.id))},i.id))})]})})}const Bs=T.observer(function({id:t}){const r=F(),{data:i,state:s}=r.getDataStuffByID(t),o=s==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},l=()=>{r.queries.downloadDataByQueryID(t)},d=b.useMemo(()=>Array.isArray(i)?i.slice(0,10):[],[i]),c=!Array.isArray(i)||i.length===0;return p(a.Stack,{sx:{border:"1px solid #eee"},children:[p(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(a.Group,{position:"left",children:[n(a.Text,{weight:500,children:"Preview Data"}),i.length>10&&p(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",i.length]})]}),p(a.Group,{pr:15,children:[n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o,onClick:u,children:n(k.Refresh,{size:15})}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o||c,onClick:l,children:n(k.Download,{size:15})})]})]}),p(a.Box,{sx:{position:"relative",overflow:"auto"},children:[n(a.LoadingOverlay,{visible:o}),n(r0,{queryID:t}),n(Vs,{data:d})]})]})}),a0=T.observer(function(){const t=me(),r=F(),{panel:{queryID:i,setQueryID:s}}=Ce(),o=()=>{t.editor.setPath(["_QUERIES_",i])};return p(a.Stack,{children:[p(a.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[n(a.Text,{children:"Use query"}),n(a.Select,{data:r.queries.options,value:i,onChange:s,allowDeselect:!1,clearable:!1,sx:{flexGrow:"1 !important"},maxDropdownHeight:300,rightSection:i&&n(a.Tooltip,{label:"Open this query",children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:o,children:n(V.IconArrowCurveRight,{size:16})})})})]}),n(Bs,{id:i})]})}),s0=T.observer(({height:e})=>{const t=F(),{data:r,loading:i,error:s,panel:{viz:o,queryID:u}}=Ce(),l=t.queries.findByID(u);return n(Ua,{viz:o,data:r,loading:i,error:s,query:l,height:e})}),o0=T.observer(()=>{const{panel:{title:e,style:{border:t}}}=Ce();return n(ke,{children:n(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.enabled?"1px":"0px"},children:[p(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[n(a.Group,{children:n(Gi,{})}),n(a.Group,{grow:!0,position:"center",children:n(a.Text,{lineClamp:1,weight:"bold",children:e})}),n(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),n(a.Group,{px:5,pb:5,sx:{flexGrow:1},children:n(s0,{height:"410px"})})]})})})}),Cr={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 l0{constructor(t){O(this,"panel");O(this,"selected");this.panel=t,se.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(Cr.name)).length;this.panel.addVariable(v.cloneDeep({...Cr,name:`${Cr.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const i=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[i]}}}function u0(){const{panel:e}=Ce();return Z.useCreation(()=>new l0(e),[e])}const d0=b.forwardRef(function({value:t,onChange:r,data:i,withStyle:s=!0},o){const u=(l,d)=>{const c=v.cloneDeep(t);v.set(c,l,d),r(c)};return p(a.Box,{px:"sm",py:"md",ref:o,children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>u("name",l.currentTarget.value)}),n(R,{label:"Data Field",required:!0,data:i,value:t.data_field,onChange:l=>u("data_field",l)})]}),n(jt,{label:"Aggregation",value:t.aggregation,onChange:l=>u("aggregation",l)}),n(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),n(Oe,{value:t.formatter,onChange:l=>u("formatter",l)}),s&&n(ia,{value:t,onChange:r})]})}),Ns=a.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),c0=e=>{const{uiModel:t}=e;return n(a.Stack,{className:"var-list",children:t.variables.map(r=>n(a.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})},p0=T.observer(c0),h0=({variable:e,data:t})=>n(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:n(a.Paper,{withBorder:!0,p:"md",children:aa(e,t)})}),f0=T.observer(h0),g0=e=>{const t=Z.useCreation(()=>Yv(e.variable),[e.variable]),{classes:r}=Ns(),{data:i}=Ce();return p(a.Group,{style:{height:"100%"},align:"start",children:[p(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:r.config,children:[p(a.Group,{position:"right",children:[n(a.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:n(V.IconDeviceFloppy,{size:18})}),n(a.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:n(V.IconTrash,{size:18})})]}),n(d0,{value:y.getSnapshot(t.copy),onChange:t.update,data:i})]}),n(f0,{variable:y.getSnapshot(t.copy),data:i})]})},m0=T.observer(g0),b0=()=>{const e=u0(),{classes:t}=Ns();return p(a.Group,{className:t.root,noWrap:!0,align:"start",children:[n(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(a.Stack,{justify:"space-between",children:[n(a.Box,{className:"var-list-actions",children:n(a.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),n(p0,{uiModel:e})]})}),e.selected?n(B,{children:n(m0,{uiModel:e,variable:e.selected})}):n("span",{children:"Select or create a new variable on right side"})]})},y0=T.observer(b0);function v0(){const{vizManager:e}=b.useContext(qe);return b.useMemo(()=>{const t=e.availableVizList.map(r=>({value:r.name,label:r.displayName??r.name,group:r.displayGroup??""}));return v.orderBy(t,[r=>r.group,r=>r.label],["asc","asc"])},[e])}const x0=T.observer(({value:e,submit:t})=>{const[r,i]=ve.useInputState(e);b.useEffect(()=>{i(e)},[e]);const s=v0(),o=e!==r;return n(a.Select,{label:"Visualization",value:r,searchable:!0,onChange:i,data:s,rightSection:n(a.ActionIcon,{disabled:!o,onClick:()=>t(r),children:n(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Gs=[];function C0(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function w0(){const{data:e,panel:{variables:t,viz:r,title:i,queryID:s,description:o,setDescription:u,setTitle:l,setQueryID:d,id:c}}=Ce(),{vizManager:f}=b.useContext(qe),g={title:i,description:o,viz:r,queryID:s,id:c},h={setDescription:u,setQueryID:d,setTitle:l},m=Ra(g);try{return f.resolveComponent(g.viz.type),n(Gt,{configure:m,children:n($y,{variables:t,setVizConf:r.setConf,panel:g,panelInfoEditor:h,vizManager:f,data:e})})}catch(w){return console.info(v.get(w,"message")),null}}const _0=T.observer(()=>{const{data:e,panel:{viz:t}}=Ce(),{vizManager:r}=b.useContext(qe),i=b.useCallback(c=>{if(c===t.type)return;const f=C0(r,c);t.setType(c),t.setConf(f||{})},[t.type]),s=c=>{try{t.setConf(JSON.parse(c))}catch(f){console.error(f)}},o=b.useMemo(()=>{var c;return(c=Gs.find(f=>f.value===t.type))==null?void 0:c.Panel},[t.type,Gs]),u=w0(),l=o?b.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=u||l;return p(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n(x0,{submit:i,value:t.type}),p(ke,{children:[n(a.Stack,{pb:50,sx:{flexGrow:1,maxHeight:"calc(100% - 80px)",overflow:"auto"},children:d}),!d&&n(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})]})}),S0=T.observer(({panel:e,sourceViewID:t})=>{const r=F(),[i,s]=b.useState(t);b.useEffect(()=>{s(t)},[t]);const[o,{open:u,close:l}]=ve.useDisclosure(!1),d=()=>{e.moveToView(t,i),l()};return p(B,{children:[n(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:u,leftIcon:n(V.IconBoxMultiple,{size:14}),children:"Move into Another View"}),n(a.Modal,{opened:o,onClose:l,title:"Move panel into another view",zIndex:320,overflow:"inside",children:p(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n(a.Radio.Group,{value:i,onChange:s,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n(a.Stack,{spacing:"xs",children:r.views.options.map(c=>n(a.Radio,{value:c.value,label:c.label},c.value))})}),p(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:14}),onClick:l,children:"Cancel"}),n(a.Button,{size:"xs",color:"blue",leftIcon:n(V.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:"Confirm"})]})]})})]})}),T0={root:{flexGrow:1,width:"100%",height:"100%"},panel:{width:"100%",height:"100%",padding:10}},qs=({children:e})=>p(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"calc(100% - 36px)"},children:[n(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n(o0,{})]});function k0(e){return!["richText","button"].includes(e)}const D0=T.observer(({panel:e})=>{const t=Le.useModals(),r=me(),i=F(),[s,o]=b.useState("Data"),{data:u,state:l,error:d}=i.getDataStuffByID(e.queryID),c=i.queries.findByID(e.queryID),g=k0(e.viz.type)&&l==="loading",h=g||d||!c||!!c.stateMessage,m=r.editor.path[1];b.useEffect(()=>{o(S=>h&&S==="Visualization"?"Data":S)},[e.id,h]);const w=()=>{r.editor.setPath(["_VIEWS_",m])},C=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,m),w()},confirmProps:{color:"red"},zIndex:320});return p(Cn,{value:{panel:e,data:u,loading:g,error:d},children:[p(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(a.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(a.Group,{position:"right",noWrap:!0,children:[n(S0,{panel:e,sourceViewID:m}),n(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:C,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(a.Tabs,{value:s,onTabChange:o,keepMounted:!1,styles:T0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",disabled:g,children:"Data"}),n(a.Tabs.Tab,{value:"Panel",children:"Panel"}),n(a.Tabs.Tab,{value:"Variables",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Variables"})})}),n(a.Tabs.Tab,{value:"Visualization",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Visualization"})})}),n(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(a.Tabs.Panel,{value:"Data",children:[n(a.LoadingOverlay,{visible:g,exitTransitionDuration:0}),n(a0,{})]}),n(a.Tabs.Panel,{value:"Panel",children:n(qs,{children:n(n0,{})})}),n(a.Tabs.Panel,{value:"Variables",children:n(y0,{})}),n(a.Tabs.Panel,{value:"Visualization",children:n(ke,{children:n(qs,{children:n(_0,{})})})}),n(a.Tabs.Panel,{value:"Interactions",children:n(ke,{children:n(Iy,{})})})]})]})}),M0=T.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const s=r.panels.findByID(t);return s?n(D0,{panel:s}):p(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Fs=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:i,spacing:s=16,pl:o=0})=>p(a.Stack,{spacing:s,mt:6,pl:o,children:[Array.from(new Array(i-1),(u,l)=>n(a.Skeleton,{width:e,height:r,radius:"xs"},l)),n(a.Skeleton,{width:t,height:r,radius:"xs"})]}),At=({value:e})=>e===null||e===""?null:n(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:n(a.ActionIcon,{children:n(V.IconInfoCircle,{size:14})})}),I0=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n(a.Tooltip,{label:r,disabled:!r,children:n(a.Badge,{children:t})}):null},A0=T.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?n(Fs,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:50}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:30}}),n("col",{style:{width:70}}),n("col",{style:{minWidth:300}}),n("col",{style:{minWidth:80,width:80}}),n("col",{style:{minWidth:120,width:120}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"#"}),n("th",{children:"Column Name"}),n("th",{}),n("th",{}),n("th",{children:"Type"}),n("th",{children:"Nullable"}),n("th",{children:"Default Value"})]})}),n("tbody",{children:t.data.map(r=>p("tr",{children:[n("td",{children:r.ordinal_position}),n("td",{children:r.column_name}),n("td",{children:n(At,{value:r.column_comment})}),n("td",{children:n(I0,{column:r})}),n("td",{children:r.column_type}),n("td",{children:r.is_nullable}),n("td",{children:n(At,{value:r.column_default})})]},r.column_name))})]})}),$0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:100}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:150}}),n("col",{style:{width:250}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Length"}),n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Column Name"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_length}),n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:i.column_name})]},i.index_name))})]})}),z0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Definition"}),n("th",{children:"Condition"}),n("th",{children:"Comment"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:n(At,{value:i.index_definition})}),n("td",{children:n(At,{value:i.condition})}),n("td",{children:n(At,{value:i.comment})})]},i.index_name))})]})}),E0=T.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ce.MySQL?n($0,{dataSource:e}):e.type===ce.Postgresql?n(z0,{dataSource:e}):null}),L0=T.observer(({dataSource:e})=>p(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n(ke,{children:n(A0,{dataSource:e})}),n(ke,{children:n(E0,{dataSource:e})})]}));function P0({table_type:e}){return e==="VIEW"?n(V.IconEye,{size:14}):e==="BASE TABLE"?n(V.IconTable,{size:14}):null}const O0=T.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?n(Fs,{height:"24px",lastWidth:"50%",count:15}):n(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([r,i])=>n(a.NavLink,{label:r,icon:n(V.IconDatabase,{size:14}),defaultOpened:e.table_schema===r,pl:0,childrenOffset:14,children:i.map(s=>n(a.NavLink,{label:s.table_name,icon:n(P0,{table_type:s.table_type}),onClick:()=>{e.setKeywords(r,s.table_name)},active:e.table_name===s.table_name},s.table_name))},r))})}),V0=({visible:e})=>n(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n(a.LoadingOverlay,{visible:e})}),B0=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],N0={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},G0=T.observer(({dataSource:e})=>{const{tableData:t}=e;return p(a.Group,{pt:10,px:10,position:"apart",children:[p(a.Group,{position:"left",children:[t.maxPage>1&&n(a.Pagination,{size:"sm",page:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{item:{height:"30px"}}}),n(a.Select,{icon:n(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:N0,data:B0,value:String(t.limit),onChange:r=>t.setLimit(Number(r))})]}),n(a.Group,{position:"right",children:p(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),q0=T.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?n(V0,{visible:!0}):p(ke,{children:[n(G0,{dataSource:e}),p(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),n(Vs,{data:t.data})]})]})}),F0={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},W0=T.observer(({dataSource:e})=>(b.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(a.Flex,{sx:{height:"100%"},children:[n(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n(ke,{children:n(O0,{dataSource:e})})}),p(a.Tabs,{defaultValue:"structure",styles:F0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"structure",icon:n(V.IconColumns,{size:14}),children:"Structure"}),n(a.Tabs.Tab,{value:"data",icon:n(V.IconDatabase,{size:14}),children:"Data"})]}),n(a.Tabs.Panel,{value:"structure",children:n(L0,{dataSource:e})}),n(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n(q0,{dataSource:e})})]})]}))),j0={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Ws=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[r,i]=b.useState(!1);return p(B,{children:[n(a.Modal,{opened:r,onClose:()=>i(!1),title:p(a.Group,{position:"apart",sx:{flexGrow:1},children:[n(a.Text,{fw:500,children:"Explorer Data Source"}),p(a.Group,{spacing:7,children:[n(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:j0,children:n(a.Box,{sx:{height:"calc(100vh - 220px)"},children:n(W0,{dataSource:e})})}),n(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),R0=b.forwardRef(({label:e,type:t,...r},i)=>p(a.Group,{position:"apart",ref:i,...r,children:[n(a.Text,{children:e}),n(a.Text,{children:t})]})),Y0=T.observer(({value:e,onChange:t})=>{const r=me(),{data:i=[],loading:s}=Z.useRequest(pr,{refreshDeps:[]},[]),o=b.useMemo(()=>i.map(c=>({label:c.key,value:c.key,type:c.type})),[i]),u=b.useMemo(()=>o.reduce((c,f)=>(c[f.value]=f.type,c),{}),[o]),l=c=>{c!==null&&t({key:c,type:u[c]})},d=b.useMemo(()=>r.datasources.find(e),[r,e]);return n(a.Select,{data:o,label:p(a.Group,{position:"apart",children:[n(a.Box,{children:"Data Source"}),d&&n(Ws,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:R0,rightSection:d?n(a.Text,{size:"xs",color:"dimmed",children:d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",".mantine-Text-root":{userSelect:"none"}}},disabled:s,value:e.key,onChange:l})}),Q0=e=>{const{queryModel:t}=e,r=me(),i=F(),o=i.findQueryUsage(t.id).length>0,u=Le.useModals(),l=()=>{u.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(t.id),r.editor.setPath(["_QUERIES_",""])},zIndex:320})};return o?n(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:n(a.Button,{color:"gray",size:"xs",leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):n(a.Button,{color:"red",size:"xs",onClick:l,leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},U0=T.observer(Q0),X0=T.observer(({queryModel:e})=>n(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(a.Stack,{spacing:10,sx:{width:"100%"},children:[n(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),n(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(Y0,{value:{type:e.type,key:e.key},onChange:({type:t,key:r})=>{e.setKey(r),e.setType(t)}}),n(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),n(a.MultiSelect,{label:"Run query when these are truthy",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),n(a.Divider,{mt:20,mb:10,variant:"dashed"}),n(U0,{queryModel:e})]})}));function Z0(){const[e,{open:t,close:r}]=ve.useDisclosure(!1);return p(B,{children:[n(a.Modal,{opened:e,onClose:r,title:"About FunctionUtils",zIndex:320,children:n(qt,{value:wv,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:n(V.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const K0=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{sx:{position:"relative",flexGrow:1},children:n(_e,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},dn=b.forwardRef(({value:e,onChange:t,label:r,defaultValue:i},s)=>{const[o,u]=b.useState(e),l=()=>{t(o)},d=()=>{u(e)},c=()=>{u(i)};b.useEffect(()=>{u(e)},[e]);const f=o!==e;return p(a.Stack,{spacing:4,sx:{height:"100%"},children:[p(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[n(a.Group,{position:"left",children:n(Z0,{})}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,size:"xs",variant:"default",leftIcon:n(V.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),n(a.Button,{onClick:d,color:"red",size:"xs",disabled:!f,leftIcon:n(V.IconRecycle,{size:16}),children:"Revert Changes"}),n(a.Button,{size:"xs",onClick:l,disabled:!f,leftIcon:n(V.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),n(a.Text,{size:14,children:r}),n(K0,{value:o,onChange:u})]})}),J0=`
|
|
473
|
+
`,Xx=()=>{const[e,t]=b.useState(!1);return p(B,{children:[n(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(r=>!r),children:e?"Close":"Click to see expected data structure"}),n(a.Collapse,{in:e,children:n(ot.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Ux})})]})},Zx=T.observer(function({config:t}){return p(B,{children:[n(a.TextInput,{label:"Min-width",value:t.min_width,onChange:r=>t.setMinWidth(r.currentTarget.value),placeholder:"200px"}),n(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),n(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),n(xr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),n(Xx,{})]})}),Kx=T.observer(function({filter:t}){const[r,i]=b.useState(t.plainDefaultValue);return b.useEffect(()=>{i(t.plainDefaultValue)},[t]),p(a.Box,{sx:{maxWidth:"480px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Preview"}),n(Bi,{filter:t,value:r,onChange:i}),n(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),n(ot.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Jx={select:Yx,"multi-select":Rx,"tree-select":Zx,"text-input":Qx,checkbox:qx,"date-range":Wx},Hx=[{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"}],e0=T.observer(function({filter:t}){const r=F(),i=b.useMemo(()=>Jx[t.type],[t.type]);return p(a.Group,{grow:!0,spacing:20,align:"top",children:[p(a.Box,{sx:{maxWidth:"600px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Edit"}),p(a.Stack,{children:[p(a.Group,{noWrap:!0,children:[n(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&n(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:s=>t.setAutoSubmit(s.currentTarget.checked),mt:22})]}),n(a.MultiSelect,{label:"Visible in...",data:r.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),n(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:s=>{t.setKey(s.currentTarget.value)}}),n(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:s=>{t.setLabel(s.currentTarget.value)}}),n(a.Select,{label:"Widget",data:Hx,required:!0,value:t.type,onChange:t.setType}),n(i,{config:t.config})]})]}),n(Kx,{filter:t})]})}),t0=T.observer(({id:e})=>{const t=Le.useModals(),r=me(),i=F();if(e==="")return null;const s=i.filters.findByID(e);if(!s)return p(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_FILTERS_",""])},u=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this filter"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(e0,{filter:s})})]})}),n0=T.observer(()=>{const e=F(),[t,r]=b.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Vt.showNotification({title:"Failed",message:o.message,color:"red"})}},s=b.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n(a.Text,{weight:500,children:"Mock Context"})}),p(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[n(a.Text,{children:"A valid json string is required"}),n(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:r,sx:{flexGrow:1}})]}),n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!s,onClick:i,children:n(k.DeviceFloppy,{size:20})})]})]})}),r0=T.observer(()=>{const{panel:e}=Ce();return n(Wn,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),i0=T.observer(()=>{const{panel:e}=Ce(),{style:t}=e;return n(B,{children:n(a.Switch,{label:"Border",checked:t.border.enabled,onChange:r=>t.border.setEnabled(r.currentTarget.checked)})})}),a0=T.observer(()=>{const{panel:e}=Ce(),{title:t,setTitle:r}=e,[i,s]=ve.useInputState(t),o=t!==i,u=b.useCallback(()=>{o&&r(i)},[o,i]);return b.useEffect(()=>{s(t)},[t]),n(a.TextInput,{value:i,onChange:s,label:p(a.Group,{children:[n(a.Text,{children:"Panel Title"}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:u,children:n(k.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function s0(){return p(a.Stack,{sx:{height:"100%"},children:[n(a.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),n(i0,{}),n(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),n(a0,{}),n(r0,{})]})}const o0=({queryID:e})=>{const t=F(),{state:r,error:i}=t.getDataStuffByID(e),s=b.useMemo(()=>t.queries.findByID(e),[t,e]);return r==="loading"?null:i?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):s!=null&&s.stateMessage?n(a.Text,{color:"gray",align:"center",children:s.stateMessage}):null},l0={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Vs({data:e}){const t=b.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const i=Pe.createColumnHelper();return Object.keys(e[0]).map(s=>i.accessor(s,{cell:o=>o.getValue()}))},[e]),r=Pe.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Pe.getCoreRowModel()});return e.length===0?n(a.Box,{sx:{height:"5em"}}):n(ke,{children:p(a.Table,{sx:l0,children:[n("thead",{children:r.getHeaderGroups().map(i=>n("tr",{children:i.headers.map(s=>p("th",{style:{width:s.getSize()},children:[s.isPlaceholder?null:Pe.flexRender(s.column.columnDef.header,s.getContext()),n(a.ActionIcon,{onMouseDown:s.getResizeHandler(),onTouchStart:s.getResizeHandler(),className:`resizer ${s.column.getIsResizing()?"isResizing":""}`,children:n(k.ArrowBarToRight,{})})]},s.id))},i.id))}),n("tbody",{children:r.getRowModel().rows.map(i=>n("tr",{children:i.getVisibleCells().map(s=>n("td",{children:n(ke,{children:Pe.flexRender(s.column.columnDef.cell,s.getContext())})},s.id))},i.id))})]})})}const Bs=T.observer(function({id:t}){const r=F(),{data:i,state:s}=r.getDataStuffByID(t),o=s==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},l=()=>{r.queries.downloadDataByQueryID(t)},d=b.useMemo(()=>Array.isArray(i)?i.slice(0,10):[],[i]),c=!Array.isArray(i)||i.length===0;return p(a.Stack,{sx:{border:"1px solid #eee"},children:[p(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(a.Group,{position:"left",children:[n(a.Text,{weight:500,children:"Preview Data"}),i.length>10&&p(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",i.length]})]}),p(a.Group,{pr:15,children:[n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o,onClick:u,children:n(k.Refresh,{size:15})}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o||c,onClick:l,children:n(k.Download,{size:15})})]})]}),p(a.Box,{sx:{position:"relative",overflow:"auto"},children:[n(a.LoadingOverlay,{visible:o}),n(o0,{queryID:t}),n(Vs,{data:d})]})]})}),u0=T.observer(function(){const t=me(),r=F(),{panel:{queryID:i,setQueryID:s}}=Ce(),o=()=>{t.editor.setPath(["_QUERIES_",i])};return p(a.Stack,{children:[p(a.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[n(a.Text,{children:"Use query"}),n(a.Select,{data:r.queries.options,value:i,onChange:s,allowDeselect:!1,clearable:!1,sx:{flexGrow:"1 !important"},maxDropdownHeight:300,rightSection:i&&n(a.Tooltip,{label:"Open this query",children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:o,children:n(V.IconArrowCurveRight,{size:16})})})})]}),n(Bs,{id:i})]})}),d0=T.observer(({height:e})=>{const t=F(),{data:r,loading:i,error:s,panel:{viz:o,queryID:u}}=Ce(),l=t.queries.findByID(u);return n(Ua,{viz:o,data:r,loading:i,error:s,query:l,height:e})}),c0=T.observer(()=>{const{panel:{title:e,style:{border:t}}}=Ce();return n(ke,{children:n(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.enabled?"1px":"0px"},children:[p(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[n(a.Group,{children:n(Gi,{})}),n(a.Group,{grow:!0,position:"center",children:n(a.Text,{lineClamp:1,weight:"bold",children:e})}),n(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),n(a.Group,{px:5,pb:5,sx:{flexGrow:1},children:n(d0,{height:"410px"})})]})})})}),Cr={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 p0{constructor(t){O(this,"panel");O(this,"selected");this.panel=t,se.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(Cr.name)).length;this.panel.addVariable(v.cloneDeep({...Cr,name:`${Cr.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const i=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[i]}}}function h0(){const{panel:e}=Ce();return Z.useCreation(()=>new p0(e),[e])}const f0=b.forwardRef(function({value:t,onChange:r,data:i,withStyle:s=!0},o){const u=(l,d)=>{const c=v.cloneDeep(t);v.set(c,l,d),r(c)};return p(a.Box,{px:"sm",py:"md",ref:o,children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>u("name",l.currentTarget.value)}),n(R,{label:"Data Field",required:!0,data:i,value:t.data_field,onChange:l=>u("data_field",l)})]}),n(jt,{label:"Aggregation",value:t.aggregation,onChange:l=>u("aggregation",l)}),n(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),n(Oe,{value:t.formatter,onChange:l=>u("formatter",l)}),s&&n(ia,{value:t,onChange:r})]})}),Ns=a.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),g0=e=>{const{uiModel:t}=e;return n(a.Stack,{className:"var-list",children:t.variables.map(r=>n(a.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})},m0=T.observer(g0),b0=({variable:e,data:t})=>n(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:n(a.Paper,{withBorder:!0,p:"md",children:aa(e,t)})}),y0=T.observer(b0),v0=e=>{const t=Z.useCreation(()=>Zv(e.variable),[e.variable]),{classes:r}=Ns(),{data:i}=Ce();return p(a.Group,{style:{height:"100%"},align:"start",children:[p(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:r.config,children:[p(a.Group,{position:"right",children:[n(a.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:n(V.IconDeviceFloppy,{size:18})}),n(a.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:n(V.IconTrash,{size:18})})]}),n(f0,{value:y.getSnapshot(t.copy),onChange:t.update,data:i})]}),n(y0,{variable:y.getSnapshot(t.copy),data:i})]})},x0=T.observer(v0),C0=()=>{const e=h0(),{classes:t}=Ns();return p(a.Group,{className:t.root,noWrap:!0,align:"start",children:[n(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(a.Stack,{justify:"space-between",children:[n(a.Box,{className:"var-list-actions",children:n(a.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),n(m0,{uiModel:e})]})}),e.selected?n(B,{children:n(x0,{uiModel:e,variable:e.selected})}):n("span",{children:"Select or create a new variable on right side"})]})},w0=T.observer(C0);function _0(){const{vizManager:e}=b.useContext(qe);return b.useMemo(()=>{const t=e.availableVizList.map(r=>({value:r.name,label:r.displayName??r.name,group:r.displayGroup??""}));return v.orderBy(t,[r=>r.group,r=>r.label],["asc","asc"])},[e])}const S0=T.observer(({value:e,submit:t})=>{const[r,i]=ve.useInputState(e);b.useEffect(()=>{i(e)},[e]);const s=_0(),o=e!==r;return n(a.Select,{label:"Visualization",value:r,searchable:!0,onChange:i,data:s,rightSection:n(a.ActionIcon,{disabled:!o,onClick:()=>t(r),children:n(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Gs=[];function T0(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function k0(){const{data:e,panel:{variables:t,viz:r,title:i,queryID:s,description:o,setDescription:u,setTitle:l,setQueryID:d,id:c}}=Ce(),{vizManager:f}=b.useContext(qe),g={title:i,description:o,viz:r,queryID:s,id:c},h={setDescription:u,setQueryID:d,setTitle:l},m=Ra(g);try{return f.resolveComponent(g.viz.type),n(Gt,{configure:m,children:n(Py,{variables:t,setVizConf:r.setConf,panel:g,panelInfoEditor:h,vizManager:f,data:e})})}catch(w){return console.info(v.get(w,"message")),null}}const D0=T.observer(()=>{const{data:e,panel:{viz:t}}=Ce(),{vizManager:r}=b.useContext(qe),i=b.useCallback(c=>{if(c===t.type)return;const f=T0(r,c);t.setType(c),t.setConf(f||{})},[t.type]),s=c=>{try{t.setConf(JSON.parse(c))}catch(f){console.error(f)}},o=b.useMemo(()=>{var c;return(c=Gs.find(f=>f.value===t.type))==null?void 0:c.Panel},[t.type,Gs]),u=k0(),l=o?b.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=u||l;return p(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n(S0,{submit:i,value:t.type}),p(ke,{children:[n(a.Stack,{pb:50,sx:{flexGrow:1,maxHeight:"calc(100% - 80px)",overflow:"auto"},children:d}),!d&&n(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})]})}),M0=T.observer(({panel:e,sourceViewID:t})=>{const r=F(),[i,s]=b.useState(t);b.useEffect(()=>{s(t)},[t]);const[o,{open:u,close:l}]=ve.useDisclosure(!1),d=()=>{e.moveToView(t,i),l()};return p(B,{children:[n(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:u,leftIcon:n(V.IconBoxMultiple,{size:14}),children:"Move into Another View"}),n(a.Modal,{opened:o,onClose:l,title:"Move panel into another view",zIndex:320,overflow:"inside",children:p(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n(a.Radio.Group,{value:i,onChange:s,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n(a.Stack,{spacing:"xs",children:r.views.options.map(c=>n(a.Radio,{value:c.value,label:c.label},c.value))})}),p(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:14}),onClick:l,children:"Cancel"}),n(a.Button,{size:"xs",color:"blue",leftIcon:n(V.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:"Confirm"})]})]})})]})}),I0={root:{flexGrow:1,width:"100%",height:"100%"},panel:{width:"100%",height:"100%",padding:10}},qs=({children:e})=>p(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"calc(100% - 36px)"},children:[n(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n(c0,{})]});function A0(e){return!["richText","button"].includes(e)}const $0=T.observer(({panel:e})=>{const t=Le.useModals(),r=me(),i=F(),[s,o]=b.useState("Data"),{data:u,state:l,error:d}=i.getDataStuffByID(e.queryID),c=i.queries.findByID(e.queryID),g=A0(e.viz.type)&&l==="loading",h=g||d||!c||!!c.stateMessage,m=r.editor.path[1];b.useEffect(()=>{o(S=>h&&S==="Visualization"?"Data":S)},[e.id,h]);const w=()=>{r.editor.setPath(["_VIEWS_",m])},C=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,m),w()},confirmProps:{color:"red"},zIndex:320});return p(Cn,{value:{panel:e,data:u,loading:g,error:d},children:[p(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(a.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(a.Group,{position:"right",noWrap:!0,children:[n(M0,{panel:e,sourceViewID:m}),n(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:C,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(a.Tabs,{value:s,onTabChange:o,keepMounted:!1,styles:I0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",disabled:g,children:"Data"}),n(a.Tabs.Tab,{value:"Panel",children:"Panel"}),n(a.Tabs.Tab,{value:"Variables",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Variables"})})}),n(a.Tabs.Tab,{value:"Visualization",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Visualization"})})}),n(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(a.Tabs.Panel,{value:"Data",children:[n(a.LoadingOverlay,{visible:g,exitTransitionDuration:0}),n(u0,{})]}),n(a.Tabs.Panel,{value:"Panel",children:n(qs,{children:n(s0,{})})}),n(a.Tabs.Panel,{value:"Variables",children:n(w0,{})}),n(a.Tabs.Panel,{value:"Visualization",children:n(ke,{children:n(qs,{children:n(D0,{})})})}),n(a.Tabs.Panel,{value:"Interactions",children:n(ke,{children:n(Ey,{})})})]})]})}),z0=T.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const s=r.panels.findByID(t);return s?n($0,{panel:s}):p(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Fs=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:i,spacing:s=16,pl:o=0})=>p(a.Stack,{spacing:s,mt:6,pl:o,children:[Array.from(new Array(i-1),(u,l)=>n(a.Skeleton,{width:e,height:r,radius:"xs"},l)),n(a.Skeleton,{width:t,height:r,radius:"xs"})]}),At=({value:e})=>e===null||e===""?null:n(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:n(a.ActionIcon,{children:n(V.IconInfoCircle,{size:14})})}),E0=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n(a.Tooltip,{label:r,disabled:!r,children:n(a.Badge,{children:t})}):null},L0=T.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?n(Fs,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:50}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:30}}),n("col",{style:{width:70}}),n("col",{style:{minWidth:300}}),n("col",{style:{minWidth:80,width:80}}),n("col",{style:{minWidth:120,width:120}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"#"}),n("th",{children:"Column Name"}),n("th",{}),n("th",{}),n("th",{children:"Type"}),n("th",{children:"Nullable"}),n("th",{children:"Default Value"})]})}),n("tbody",{children:t.data.map(r=>p("tr",{children:[n("td",{children:r.ordinal_position}),n("td",{children:r.column_name}),n("td",{children:n(At,{value:r.column_comment})}),n("td",{children:n(E0,{column:r})}),n("td",{children:r.column_type}),n("td",{children:r.is_nullable}),n("td",{children:n(At,{value:r.column_default})})]},r.column_name))})]})}),P0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:100}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:150}}),n("col",{style:{width:250}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Length"}),n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Column Name"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_length}),n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:i.column_name})]},i.index_name))})]})}),O0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Definition"}),n("th",{children:"Condition"}),n("th",{children:"Comment"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:n(At,{value:i.index_definition})}),n("td",{children:n(At,{value:i.condition})}),n("td",{children:n(At,{value:i.comment})})]},i.index_name))})]})}),V0=T.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ce.MySQL?n(P0,{dataSource:e}):e.type===ce.Postgresql?n(O0,{dataSource:e}):null}),B0=T.observer(({dataSource:e})=>p(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n(ke,{children:n(L0,{dataSource:e})}),n(ke,{children:n(V0,{dataSource:e})})]}));function N0({table_type:e}){return e==="VIEW"?n(V.IconEye,{size:14}):e==="BASE TABLE"?n(V.IconTable,{size:14}):null}const G0=T.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?n(Fs,{height:"24px",lastWidth:"50%",count:15}):n(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([r,i])=>n(a.NavLink,{label:r,icon:n(V.IconDatabase,{size:14}),defaultOpened:e.table_schema===r,pl:0,childrenOffset:14,children:i.map(s=>n(a.NavLink,{label:s.table_name,icon:n(N0,{table_type:s.table_type}),onClick:()=>{e.setKeywords(r,s.table_name)},active:e.table_name===s.table_name},s.table_name))},r))})}),q0=({visible:e})=>n(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n(a.LoadingOverlay,{visible:e})}),F0=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],W0={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},j0=T.observer(({dataSource:e})=>{const{tableData:t}=e;return p(a.Group,{pt:10,px:10,position:"apart",children:[p(a.Group,{position:"left",children:[t.maxPage>1&&n(a.Pagination,{size:"sm",page:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{item:{height:"30px"}}}),n(a.Select,{icon:n(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:W0,data:F0,value:String(t.limit),onChange:r=>t.setLimit(Number(r))})]}),n(a.Group,{position:"right",children:p(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),R0=T.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?n(q0,{visible:!0}):p(ke,{children:[n(j0,{dataSource:e}),p(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),n(Vs,{data:t.data})]})]})}),Y0={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},Q0=T.observer(({dataSource:e})=>(b.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(a.Flex,{sx:{height:"100%"},children:[n(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n(ke,{children:n(G0,{dataSource:e})})}),p(a.Tabs,{defaultValue:"structure",styles:Y0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"structure",icon:n(V.IconColumns,{size:14}),children:"Structure"}),n(a.Tabs.Tab,{value:"data",icon:n(V.IconDatabase,{size:14}),children:"Data"})]}),n(a.Tabs.Panel,{value:"structure",children:n(B0,{dataSource:e})}),n(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n(R0,{dataSource:e})})]})]}))),U0={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Ws=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[r,i]=b.useState(!1);return p(B,{children:[n(a.Modal,{opened:r,onClose:()=>i(!1),title:p(a.Group,{position:"apart",sx:{flexGrow:1},children:[n(a.Text,{fw:500,children:"Explorer Data Source"}),p(a.Group,{spacing:7,children:[n(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:U0,children:n(a.Box,{sx:{height:"calc(100vh - 220px)"},children:n(Q0,{dataSource:e})})}),n(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),X0=b.forwardRef(({label:e,type:t,...r},i)=>p(a.Group,{position:"apart",ref:i,...r,children:[n(a.Text,{children:e}),n(a.Text,{children:t})]})),Z0=T.observer(({value:e,onChange:t})=>{const r=me(),{data:i=[],loading:s}=Z.useRequest(pr,{refreshDeps:[]},[]),o=b.useMemo(()=>i.map(c=>({label:c.key,value:c.key,type:c.type})),[i]),u=b.useMemo(()=>o.reduce((c,f)=>(c[f.value]=f.type,c),{}),[o]),l=c=>{c!==null&&t({key:c,type:u[c]})},d=b.useMemo(()=>r.datasources.find(e),[r,e]);return n(a.Select,{data:o,label:p(a.Group,{position:"apart",children:[n(a.Box,{children:"Data Source"}),d&&n(Ws,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:X0,rightSection:d?n(a.Text,{size:"xs",color:"dimmed",children:d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",".mantine-Text-root":{userSelect:"none"}}},disabled:s,value:e.key,onChange:l})}),K0=e=>{const{queryModel:t}=e,r=me(),i=F(),o=i.findQueryUsage(t.id).length>0,u=Le.useModals(),l=()=>{u.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(t.id),r.editor.setPath(["_QUERIES_",""])},zIndex:320})};return o?n(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:n(a.Button,{color:"gray",size:"xs",leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):n(a.Button,{color:"red",size:"xs",onClick:l,leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},J0=T.observer(K0),H0=T.observer(({queryModel:e})=>n(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(a.Stack,{spacing:10,sx:{width:"100%"},children:[n(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),n(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(Z0,{value:{type:e.type,key:e.key},onChange:({type:t,key:r})=>{e.setKey(r),e.setType(t)}}),n(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),n(a.MultiSelect,{label:"Run query when these are truthy",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),n(a.Divider,{mt:20,mb:10,variant:"dashed"}),n(J0,{queryModel:e})]})}));function eC(){const[e,{open:t,close:r}]=ve.useDisclosure(!1);return p(B,{children:[n(a.Modal,{opened:e,onClose:r,title:"About FunctionUtils",zIndex:320,children:n(qt,{value:kv,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:n(V.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const tC=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{sx:{position:"relative",flexGrow:1},children:n(_e,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},dn=b.forwardRef(({value:e,onChange:t,label:r,defaultValue:i},s)=>{const[o,u]=b.useState(e),l=()=>{t(o)},d=()=>{u(e)},c=()=>{u(i)};b.useEffect(()=>{u(e)},[e]);const f=o!==e;return p(a.Stack,{spacing:4,sx:{height:"100%"},children:[p(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[n(a.Group,{position:"left",children:n(eC,{})}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,size:"xs",variant:"default",leftIcon:n(V.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),n(a.Button,{onClick:d,color:"red",size:"xs",disabled:!f,leftIcon:n(V.IconRecycle,{size:16}),children:"Revert Changes"}),n(a.Button,{size:"xs",onClick:l,disabled:!f,leftIcon:n(V.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),n(a.Text,{size:14,children:r}),n(tC,{value:o,onChange:u})]})}),nC=`
|
|
474
474
|
-- You may reference global variables in SQL or VizConfig.
|
|
475
475
|
SELECT *
|
|
476
476
|
FROM commit
|
|
@@ -482,8 +482,8 @@ WHERE
|
|
|
482
482
|
-- SQL snippets
|
|
483
483
|
AND \${sql_snippets.author_email_condition}
|
|
484
484
|
\${sql_snippets.order_by_clause}
|
|
485
|
-
`,js=T.observer(function({showSQLSnippets:t=!0,sx:r={}}){const i=me(),s=F(),o=i.context.current,u=(()=>{const l={context:{...s.mock_context.current,...o},filters:s.filters.previewValues};return t&&(l.sql_snippets=s.sqlSnippets.record),JSON.stringify(l,null,2)})();return n(a.Stack,{sx:{overflow:"hidden",...r},children:p(a.Stack,{sx:{width:"100%"},children:[n(a.Text,{weight:500,sx:{flexGrow:0},children:"Guide"}),n(ot.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:
|
|
485
|
+
`,js=T.observer(function({showSQLSnippets:t=!0,sx:r={}}){const i=me(),s=F(),o=i.context.current,u=(()=>{const l={context:{...s.mock_context.current,...o},filters:s.filters.previewValues};return t&&(l.sql_snippets=s.sqlSnippets.record),JSON.stringify(l,null,2)})();return n(a.Stack,{sx:{overflow:"hidden",...r},children:p(a.Stack,{sx:{width:"100%"},children:[n(a.Text,{weight:500,sx:{flexGrow:0},children:"Guide"}),n(ot.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:nC}),n(a.Text,{weight:500,sx:{flexGrow:0},children:"Current Values"}),n(ot.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:u})]})})}),wr=T.observer(()=>{const[e,t]=b.useState(!1);return p(B,{children:[n(a.Modal,{opened:e,onClose:()=>t(!1),title:"Global Variables",zIndex:320,size:"800px",children:n(js,{})}),n(a.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Global Variables"})]})}),Rs={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method, url, params, headers, data }","}"].join(`
|
|
486
486
|
`),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
|
|
487
|
-
`)},
|
|
487
|
+
`)},rC=T.observer(({queryModel:e})=>e.typedAsHTTP?p(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(wr,{})]}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(dn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Rs.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(dn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Rs.post})})]}):null),iC=T.observer(({queryID:e,usage:t})=>{const r=me().editor,i=o=>{if(o.type==="filter"){r.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const u=o.views[0].id;r.setPath(["_VIEWS_",u,"_PANELS_",o.id]);return}},s=o=>{r.setPath(["_VIEWS_",o])};return n(a.Stack,{py:"sm",px:"md",children:p(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n("thead",{children:p("tr",{children:[n("th",{style:{width:100},children:"Type"}),n("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),n("th",{children:"In View(s)"})]})}),n("tbody",{children:t.map(o=>p("tr",{children:[n("td",{children:v.capitalize(o.type)}),n("td",{children:n(a.Anchor,{component:"button",type:"button",onClick:()=>i(o),children:o.label})}),n("td",{children:p(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(u=>n(a.Anchor,{component:"button",type:"button",onClick:()=>s(u.id),children:n(a.Box,{children:u.label})})),o.views.length===0&&n(a.Box,{children:"--"})]})})]},o.id))})]})})}),_r=({value:e,onChange:t,height:r="200px",defaultLanguage:i="sql"})=>{const s=u=>{console.log("changing"),t==null||t(u??"")},o=!t;return n(_e,{className:"minimal-monaco-editor",height:r,defaultLanguage:i,value:e,onChange:o?void 0:s,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:o||!t}})},aC=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n(_e,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:r,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),sC=T.observer(({value:e})=>{const r=F().payloadForSQL,i=b.useMemo(()=>{const{context:s,mock_context:o,sqlSnippets:u,filterValues:l}=r;return gs(e,s,o,u,l)},[e,r]);return n(aC,{height:"100%",value:i})}),Ys={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
488
488
|
`),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
|
|
489
|
-
`)},rC=T.observer(({queryModel:e})=>{const[t,r]=b.useState(e.sql);b.useEffect(()=>{r(o=>o!==e.sql?e.sql:o)},[e.sql]);const i=t!==e.sql,s=()=>{e.setSQL(t)};return e.typedAsSQL?p(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Edit",children:p(a.Group,{spacing:14,position:"apart",children:["Edit SQL",n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!i,onClick:s,children:n(k.DeviceFloppy,{size:20})})]})}),n(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),n(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(wr,{}),e.datasource&&n(Ws,{dataSource:e.datasource})]}),n(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n(_r,{height:"100%",value:t,onChange:r})}),n(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n(nC,{value:e.sql})}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(dn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Ys.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(dn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Ys.post})})]}):null}),cn={height:"calc(100% - 44px)",padding:0},iC=T.observer(({queryModel:e})=>{const t=F(),r=b.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),i=t.findQueryUsage(e.id),s=i.length===0;return n(a.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(a.Tabs,{defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(a.Tabs.List,{grow:!0,children:[n(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&n(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&n(a.Tabs.Tab,{value:"HTTP",children:"Request"}),n(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:n(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:n(a.Text,{children:"Data"})})}),n(a.Tabs.Tab,{value:"Usage",disabled:s,children:n(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!s,withinPortal:!0,children:n(a.Text,{children:"Usage"})})})]}),n(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n(X0,{queryModel:e})}),e.typedAsSQL&&n(a.Tabs.Panel,{value:"SQL",sx:cn,children:n(a.Stack,{sx:{height:"100%"},children:n(rC,{queryModel:e})})}),e.typedAsHTTP&&n(a.Tabs.Panel,{value:"HTTP",sx:cn,children:n(a.Stack,{sx:{height:"100%"},children:n(H0,{queryModel:e})})}),n(a.Tabs.Panel,{value:"Data",sx:{...cn,overflow:"hidden"},children:n(Bs,{id:e.id})}),n(a.Tabs.Panel,{value:"Usage",sx:{...cn,overflow:"hidden"},children:n(eC,{queryID:e.id,usage:i})})]})})}),aC=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?n(a.Stack,{sx:{height:"100%"},spacing:"sm",children:n(iC,{queryModel:r})}):n(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),sC=T.observer(({value:e})=>{const t=F(),{context:r,mock_context:i,filterValues:s}=t.payloadForSQL,o=Iv(e,r,i,s);return n(_r,{height:"100%",value:o})}),oC=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const[i,s]=b.useState("SQL"),[o,u]=b.useState(e.key),l=()=>{e.setKey(o),r(o)},d=o!==e.key,c=e.isADuplicatedKey(o),[f,g]=b.useState(e.value),h=()=>{e.setValue(f)};b.useEffect(()=>{u(e.key),g(e.value)},[e]);const m=f!==e.value,w=Le.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,zIndex:320})};return p(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(a.Group,{sx:{alignItems:"end"},spacing:40,children:[n(a.TextInput,{label:c?"This key is occupied by another snippet":"Key",value:o,onChange:S=>{u(S.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n(a.ActionIcon,{color:"blue",variant:"subtle",onClick:l,disabled:!d||c,children:n(k.DeviceFloppy,{size:16})}),error:c}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(a.Tabs,{value:i,onTabChange:s,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(a.Tabs.List,{sx:{position:"relative"},children:[n(a.Tabs.Tab,{value:"SQL",children:"SQL"}),n(a.Tabs.Tab,{value:"Preview",children:"Preview"}),n(wr,{}),n(a.ActionIcon,{color:"blue",variant:"filled",onClick:h,disabled:!m,sx:{position:"absolute",top:0,right:10},children:n(k.DeviceFloppy,{size:18})})]}),n(a.Tabs.Panel,{value:"SQL",pt:"sm",children:n(_r,{height:"100%",value:f,onChange:g})}),n(a.Tabs.Panel,{value:"Preview",pt:"sm",children:n(sC,{value:f})})]})]})}),lC=T.observer(({id:e})=>{const t=me(),r=F(),i=b.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!i)return p(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const s=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return n(oC,{item:i,remove:()=>{r.sqlSnippets.removeByKey(e),s()},onKeyChanged:l=>{t.editor.setPath(["_SQL_SNIPPETS_",l])}})}),uC=T.observer(({view:e})=>!e||e.type!==K.Division?null:p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),n(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),dC=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],cC=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],pC=T.observer(({view:e})=>{if(!e||e.type!==K.Tabs)return null;const t=e.config;return p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),n(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:dC}),n(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:cC}),n(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:r=>t.setGrow(r.currentTarget.checked)})]})}),hC=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},fC=({value:e,onChange:t})=>{const[r,{setTrue:i,setFalse:s}]=Z.useBoolean(),[o,u]=b.useState(e??hr),l=h=>{u({...o,enabled:h})},d=()=>{s();const{enabled:h,func_content:m}=o,w={enabled:h,func_content:m};u(w),t(w)},c=()=>{s(),u(e)},f=h=>{u(m=>({...m,func_content:h}))},g=()=>{f(hr.func_content)};return p(B,{children:[n(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:n(k.Settings,{size:14})}),n(a.Modal,{size:800,title:"Customize modal title",opened:r,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:h=>l(h.currentTarget.checked)}),n(hC,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},gC=T.observer(({view:e})=>{if(!e||e.type!==K.Modal)return null;const t=e.config,r=t.custom_modal_title.value;return p(a.Stack,{children:[n(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(a.Flex,{gap:10,children:[n(a.TextInput,{label:"Modal Title",value:r,onChange:v.noop,disabled:!0,sx:{flexGrow:1}}),n(fC,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(a.Group,{grow:!0,children:[n(a.TextInput,{label:"Width",value:t.width,onChange:i=>t.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),n(a.TextInput,{label:"Height",value:t.height,onChange:i=>t.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),mC=T.observer(({view:e})=>p(B,{children:[n(uC,{view:e}),n(gC,{view:e}),n(pC,{view:e})]})),bC=[{label:"Division",value:K.Division},{label:"Modal",value:K.Modal},{label:"Tabs",value:K.Tabs}],yC=T.observer(({view:e})=>e?p(a.Stack,{sx:{position:"relative"},children:[n(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(a.Select,{label:"Type",withinPortal:!0,value:e.type,onChange:e.setType,data:bC}),n(mC,{view:e})]}):null),vC=T.observer(({id:e})=>{const t=Le.useModals(),r=me(),i=F();if(e==="")return null;const s=i.views.findByID(e);if(!s)return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_VIEWS_",""])},u=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this view"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(yC,{view:s})})]})});function xC(e){return e.length===1&&e[0]==="_GLOBAL_VARS_"}function CC(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function wC(e){return e.length===2&&e[0]==="_FILTERS_"}function _C(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function SC(e){return e.length===2&&e[0]==="_QUERIES_"}function TC(e){return e.length===2&&e[0]==="_VIEWS_"}function kC(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const DC=T.observer(()=>n(a.Stack,{sx:{height:"100%"},p:"sm",children:n(js,{})})),MC=T.observer(()=>{const e=me().editor,t=e.path;return xC(t)?n(DC,{}):CC(t)?n(Jx,{}):wC(t)?n(a.Box,{p:"xs",pl:20,children:n(Kx,{id:t[1]})}):_C(t)?n(lC,{id:t[1]}):SC(t)?n(aC,{id:t[1]}):TC(t)?n(a.Box,{p:"xs",pl:20,children:n(vC,{id:t[1]})}):kC(t)?n(M0,{viewID:t[1],panelID:t[3]}):n(a.Box,{children:e.path})}),IC=T.observer(()=>n(MC,{})),AC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:e.filters.current.length+1,type:or.TextInput,config:os(),visibleInViewsIDs:["Main"],auto_submit:!1};e.filters.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),$C=T.observer(({parentID:e})=>{const t=F();if(!e)return null;const r=t.views.findByID(e);return r?n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),zC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:ce.Postgresql,key:"",sql:""};e.queries.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),EC=T.observer(()=>{const e=F(),t=()=>{const i={key:new Date().getTime().toString(),value:""};e.sqlSnippets.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),LC=T.observer(()=>{const e=F();return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),PC=T.observer(({action_type:e,parentID:t})=>(F(),e==="_Add_A_Filter_"?n(AC,{}):e==="_Add_A_SQL_SNIPPET_"?n(EC,{}):e==="_Add_A_QUERY_"?n(zC,{}):e==="_Add_A_VIEW_"?n(LC,{}):e==="_Add_A_PANEL_"?n($C,{parentID:t}):null)),Qs=T.observer(({option:e})=>{var c;const t=me().editor,r=t.isOptionActive,i=r(t.path,e),s=t.isOptionOpened,o=t.navigate,u=s(e),[l,d]=b.useState(u);return b.useEffect(()=>{d(u)},[u]),n(a.NavLink,{active:i,defaultOpened:u,opened:l,onChange:d,label:e.label,onClick:()=>o(e),icon:e.Icon?n(e.Icon,{size:18}):null,children:(c=e.children)==null?void 0:c.map(f=>f._type==="ACTION"?n(PC,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n(Qs,{option:f},f.value))},e.label)}),OC=T.observer(()=>{const e=me();return n(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n(Qs,{option:t},t.value))})}),VC=T.observer(()=>{const e=me();return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[n(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(OC,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),BC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},NC=T.observer(()=>{const e=me().editor;return n(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:n(a.AppShell,{padding:0,navbar:n(VC,{}),styles:BC,children:n(IC,{})})})}),GC=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function qC(e){b.useEffect(()=>{if(_e.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=GC(e);_e.loader.config({paths:{vs:r}}),_e.loader.init().then(i=>console.log("monaco instance:",i))},[])}const Us={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 FC(){le.registerTheme("merico-light",{color:Object.values(Us.graphics.multiple),visualMap:{color:Object.values(Us.graphics.depth).reverse()}})}function Xs(){FC()}Xs();const WC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},jC=({context:e,dashboard:t,content:r,update:i,className:s="dashboard",config:o,onChange:u,headerSlot:l,headerMenuItems:d},c)=>{qC(o.monacoPath),Ha(o);const{data:f=[]}=Z.useRequest(pr),[g,h]=b.useState(!1),m=b.useMemo(()=>gr(t,r,f,e),[t,r]);b.useImperativeHandle(c,()=>m,[m]),$i(m.content,!0),b.useEffect(()=>{m.context.replace(e)},[e]),b.useEffect(()=>{m.datasources.replace(f)},[f]),b.useEffect(()=>se.reaction(()=>se.toJS(m.json),I=>{u==null||u(I)}),[m]);const w=async()=>{await i(m.json,m.content.json)},C=Z.useCreation(ar,[]),S=mr(C);return n(Le.ModalsProvider,{children:n(vn,{value:m,children:n(xn,{value:m.content,children:n(Ke.Provider,{value:{layoutFrozen:g,freezeLayout:h,inEditMode:!0},children:n(qe.Provider,{value:C,children:p(Gt,{configure:S,children:[n(a.AppShell,{padding:0,header:n(ux,{saveDashboardChanges:w,headerSlot:l,headerMenuItems:d}),navbar:n(Ox,{}),styles:WC,children:n(a.Box,{className:`${s} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n(Ja,{view:I},I.id))})}),n(NC,{})]})})})})})})},RC=T.observer(b.forwardRef(jC)),q1="";Xs();const YC=T.observer(({context:e,dashboard:t,content:r,className:i="dashboard",config:s,fullScreenPanelID:o,setFullScreenPanelID:u})=>{Ha(s);const{data:l=[]}=Z.useRequest(pr),d=b.useMemo(()=>gr(t,r,l,e),[t,r]);$i(d.content,!1),b.useEffect(()=>{d.context.replace(e)},[e]),b.useEffect(()=>{d.datasources.replace(l)},[l]);const c=Z.useCreation(ar,[]),f=mr(c);return n(Le.ModalsProvider,{children:n(vn,{value:d,children:n(xn,{value:d.content,children:n(wn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:u},children:n(Ke.Provider,{value:{layoutFrozen:!0,freezeLayout:v.noop,inEditMode:!1},children:n(a.Box,{className:`${i} dashboard-root`,children:n(qe.Provider,{value:c,children:n(Gt,{configure:f,children:d.content.views.visibleViews.map(g=>n(an,{view:g},g.id))})})})})})})})})});var Sr={},QC={get exports(){return Sr},set exports(e){Sr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=o.format;s.en.ordinal=function(l){var d=["th","st","nd","rd"],c=l%100;return"["+l+(d[(c-20)%10]||d[c]||d[0])+"]"},o.format=function(l){var d=this,c=this.$locale();if(!this.isValid())return u.bind(this)(l);var f=this.$utils(),g=(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((d.$M+1)/3);case"Do":return c.ordinal(d.$D);case"gggg":return d.weekYear();case"GGGG":return d.isoWeekYear();case"wo":return c.ordinal(d.week(),"W");case"w":case"ww":return f.s(d.week(),h==="w"?1:2,"0");case"W":case"WW":return f.s(d.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return f.s(String(d.$H===0?24:d.$H),h==="k"?1:2,"0");case"X":return Math.floor(d.$d.getTime()/1e3);case"x":return d.$d.getTime();case"z":return"["+d.offsetName()+"]";case"zzz":return"["+d.offsetName("long")+"]";default:return h}});return u.bind(this)(g)}}})})(QC);const UC=Sr;var Tr={},XC={get exports(){return Tr},set exports(e){Tr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(d){var c=d.date,f=d.utc;return Array.isArray(c)?f?c.length?new Date(Date.UTC.apply(null,c)):new Date:c.length===1?s(String(c[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(c))):c},l=o.parse;o.parse=function(d){d.date=u.bind(this)(d),l.bind(this)(d)}}})})(XC);const ZC=Tr;var kr={},KC={get exports(){return kr},set exports(e){kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;s.$g=function(h,m,w){return this.$utils().u(h)?this[m]:this.$set(w,h)},s.set=function(h,m){return this.$set(h,m)};var o=s.startOf;s.startOf=function(h,m){return this.$d=o.bind(this)(h,m).toDate(),this.init(),this};var u=s.add;s.add=function(h,m){return this.$d=u.bind(this)(h,m).toDate(),this.init(),this};var l=s.locale;s.locale=function(h,m){return h?(this.$L=l.bind(this)(h,m).$L,this):this.$L};var d=s.daysInMonth;s.daysInMonth=function(){return d.bind(this.clone())()};var c=s.isSame;s.isSame=function(h,m){return c.bind(this.clone())(h,m)};var f=s.isBefore;s.isBefore=function(h,m){return f.bind(this.clone())(h,m)};var g=s.isAfter;s.isAfter=function(h,m){return g.bind(this.clone())(h,m)}}})})(KC);const JC=kr;var Dr={},HC={get exports(){return Dr},set exports(e){Dr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype,o=s.format;s.format=function(u){var l=this,d=(u||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(c,f){var g,h=String(l.$y+543),m=c==="BB"?[h.slice(-2),2]:[h,4];return f||(g=l.$utils()).s.apply(g,m.concat(["0"]))});return o.bind(this)(d)}}})})(HC);const ew=Dr;var Mr={},tw={get exports(){return Mr},set exports(e){Mr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o="h:mm A",u={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};i.prototype.calendar=function(l,d){var c=d||this.$locale().calendar||u,f=s(l||void 0).startOf("d"),g=this.diff(f,"d",!0),h="sameElse",m=g<-6?h:g<-1?"lastWeek":g<0?"lastDay":g<1?"sameDay":g<2?"nextDay":g<7?"nextWeek":h,w=c[m]||u[m];return typeof w=="function"?w.call(this,s()):this.format(w)}}})})(tw);const nw=Mr;var Ir={},rw={get exports(){return Ir},set exports(e){Ir=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},i=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d\d/,o=/\d\d?/,u=/\d*[^-_:/,()\s\d]+/,l={},d=function(C){return(C=+C)+(C>68?1900:2e3)},c=function(C){return function(S){this[C]=+S}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(S){if(!S||S==="Z")return 0;var I=S.match(/([+-]|\d\d)/g),$=60*I[1]+(+I[2]||0);return $===0?0:I[0]==="+"?-$:$}(C)}],g=function(C){var S=l[C];return S&&(S.indexOf?S:S.s.concat(S.f))},h=function(C,S){var I,$=l.meridiem;if($){for(var P=1;P<=24;P+=1)if(C.indexOf($(P,0,S))>-1){I=P>12;break}}else I=C===(S?"pm":"PM");return I},m={A:[u,function(C){this.afternoon=h(C,!1)}],a:[u,function(C){this.afternoon=h(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[s,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,c("seconds")],ss:[o,c("seconds")],m:[o,c("minutes")],mm:[o,c("minutes")],H:[o,c("hours")],h:[o,c("hours")],HH:[o,c("hours")],hh:[o,c("hours")],D:[o,c("day")],DD:[s,c("day")],Do:[u,function(C){var S=l.ordinal,I=C.match(/\d+/);if(this.day=I[0],S)for(var $=1;$<=31;$+=1)S($).replace(/\[|\]/g,"")===C&&(this.day=$)}],M:[o,c("month")],MM:[s,c("month")],MMM:[u,function(C){var S=g("months"),I=(g("monthsShort")||S.map(function($){return $.slice(0,3)})).indexOf(C)+1;if(I<1)throw new Error;this.month=I%12||I}],MMMM:[u,function(C){var S=g("months").indexOf(C)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,c("year")],YY:[s,function(C){this.year=d(C)}],YYYY:[/\d{4}/,c("year")],Z:f,ZZ:f};function w(C){var S,I;S=C,I=l&&l.formats;for(var $=(C=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Q,ne){var ie=ne&&ne.toUpperCase();return Q||I[ne]||r[ne]||I[ie].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(oe,re,pe){return re||pe.slice(1)})})).match(i),P=$.length,q=0;q<P;q+=1){var L=$[q],z=m[L],A=z&&z[0],G=z&&z[1];$[q]=G?{regex:A,parser:G}:L.replace(/^\[|\]$/g,"")}return function(U){for(var Q={},ne=0,ie=0;ne<P;ne+=1){var oe=$[ne];if(typeof oe=="string")ie+=oe.length;else{var re=oe.regex,pe=oe.parser,fe=U.slice(ie),Te=re.exec(fe)[0];pe.call(Q,Te),U=U.replace(Te,"")}}return function(We){var $e=We.afternoon;if($e!==void 0){var Qe=We.hours;$e?Qe<12&&(We.hours+=12):Qe===12&&(We.hours=0),delete We.afternoon}}(Q),Q}}return function(C,S,I){I.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(d=C.parseTwoDigitYear);var $=S.prototype,P=$.parse;$.parse=function(q){var L=q.date,z=q.utc,A=q.args;this.$u=z;var G=A[1];if(typeof G=="string"){var U=A[2]===!0,Q=A[3]===!0,ne=U||Q,ie=A[2];Q&&(ie=A[2]),l=this.$locale(),!U&&ie&&(l=I.Ls[ie]),this.$d=function(fe,Te,We){try{if(["x","X"].indexOf(Te)>-1)return new Date((Te==="X"?1e3:1)*fe);var $e=w(Te)(fe),Qe=$e.year,it=$e.month,pn=$e.day,hn=$e.hours,ii=$e.minutes,ai=$e.seconds,$t=$e.milliseconds,ft=$e.zone,tt=new Date,at=pn||(Qe||it?1:tt.getDate()),nt=Qe||tt.getFullYear(),gt=0;Qe&&!it||(gt=it>0?it-1:tt.getMonth());var mt=hn||0,zt=ii||0,Et=ai||0,rt=$t||0;return ft?new Date(Date.UTC(nt,gt,at,mt,zt,Et,rt+60*ft.offset*1e3)):We?new Date(Date.UTC(nt,gt,at,mt,zt,Et,rt)):new Date(nt,gt,at,mt,zt,Et,rt)}catch{return new Date("")}}(L,G,z),this.init(),ie&&ie!==!0&&(this.$L=this.locale(ie).$L),ne&&L!=this.format(G)&&(this.$d=new Date("")),l={}}else if(G instanceof Array)for(var oe=G.length,re=1;re<=oe;re+=1){A[1]=G[re-1];var pe=I.apply(this,A);if(pe.isValid()){this.$d=pe.$d,this.$L=pe.$L,this.init();break}re===oe&&(this.$d=new Date(""))}else P.call(this,q)}}})})(rw);const iw=Ir;var Ar={},aw={get exports(){return Ar},set exports(e){Ar=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.dayOfYear=function(o){var u=Math.round((s(this).startOf("day")-s(this).startOf("year"))/864e5)+1;return o==null?u:this.add(o-u,"day")}}})})(aw);const sw=Ar;var $r={},ow={get exports(){return $r},set exports(e){$r=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r,i,s=1e3,o=6e4,u=36e5,l=864e5,d=/\[([^\]]+)]|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,c=31536e6,f=2592e6,g=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,h={years:c,months:f,days:l,hours:u,minutes:o,seconds:s,milliseconds:1,weeks:6048e5},m=function(L){return L instanceof q},w=function(L,z,A){return new q(L,A,z.$l)},C=function(L){return i.p(L)+"s"},S=function(L){return L<0},I=function(L){return S(L)?Math.ceil(L):Math.floor(L)},$=function(L){return Math.abs(L)},P=function(L,z){return L?S(L)?{negative:!0,format:""+$(L)+z}:{negative:!1,format:""+L+z}:{negative:!1,format:""}},q=function(){function L(A,G,U){var Q=this;if(this.$d={},this.$l=U,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),G)return w(A*h[C(G)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(oe){Q.$d[C(oe)]=A[oe]}),this.calMilliseconds(),this;if(typeof A=="string"){var ne=A.match(g);if(ne){var ie=ne.slice(2).map(function(oe){return oe!=null?Number(oe):0});return this.$d.years=ie[0],this.$d.months=ie[1],this.$d.weeks=ie[2],this.$d.days=ie[3],this.$d.hours=ie[4],this.$d.minutes=ie[5],this.$d.seconds=ie[6],this.calMilliseconds(),this}}return this}var z=L.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(G,U){return G+(A.$d[U]||0)*h[U]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=I(A/c),A%=c,this.$d.months=I(A/f),A%=f,this.$d.days=I(A/l),A%=l,this.$d.hours=I(A/u),A%=u,this.$d.minutes=I(A/o),A%=o,this.$d.seconds=I(A/s),A%=s,this.$d.milliseconds=A},z.toISOString=function(){var A=P(this.$d.years,"Y"),G=P(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Q=P(U,"D"),ne=P(this.$d.hours,"H"),ie=P(this.$d.minutes,"M"),oe=this.$d.seconds||0;this.$d.milliseconds&&(oe+=this.$d.milliseconds/1e3);var re=P(oe,"S"),pe=A.negative||G.negative||Q.negative||ne.negative||ie.negative||re.negative,fe=ne.format||ie.format||re.format?"T":"",Te=(pe?"-":"")+"P"+A.format+G.format+Q.format+fe+ne.format+ie.format+re.format;return Te==="P"||Te==="-P"?"P0D":Te},z.toJSON=function(){return this.toISOString()},z.format=function(A){var G=A||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return G.replace(d,function(Q,ne){return ne||String(U[Q])})},z.as=function(A){return this.$ms/h[C(A)]},z.get=function(A){var G=this.$ms,U=C(A);return U==="milliseconds"?G%=1e3:G=U==="weeks"?I(G/h[U]):this.$d[U],G===0?0:G},z.add=function(A,G,U){var Q;return Q=G?A*h[C(G)]:m(A)?A.$ms:w(A,this).$ms,w(this.$ms+Q*(U?-1:1),this)},z.subtract=function(A,G){return this.add(A,G,!0)},z.locale=function(A){var G=this.clone();return G.$l=A,G},z.clone=function(){return w(this.$ms,this)},z.humanize=function(A){return r().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},z.milliseconds=function(){return this.get("milliseconds")},z.asMilliseconds=function(){return this.as("milliseconds")},z.seconds=function(){return this.get("seconds")},z.asSeconds=function(){return this.as("seconds")},z.minutes=function(){return this.get("minutes")},z.asMinutes=function(){return this.as("minutes")},z.hours=function(){return this.get("hours")},z.asHours=function(){return this.as("hours")},z.days=function(){return this.get("days")},z.asDays=function(){return this.as("days")},z.weeks=function(){return this.get("weeks")},z.asWeeks=function(){return this.as("weeks")},z.months=function(){return this.get("months")},z.asMonths=function(){return this.as("months")},z.years=function(){return this.get("years")},z.asYears=function(){return this.as("years")},L}();return function(L,z,A){r=A,i=A().$utils(),A.duration=function(Q,ne){var ie=A.locale();return w(Q,{$l:ie},ne)},A.isDuration=m;var G=z.prototype.add,U=z.prototype.subtract;z.prototype.add=function(Q,ne){return m(Q)&&(Q=Q.asMilliseconds()),G.bind(this)(Q,ne)},z.prototype.subtract=function(Q,ne){return m(Q)&&(Q=Q.asMilliseconds()),U.bind(this)(Q,ne)}}})})(ow);const lw=$r;var zr={},uw={get exports(){return zr},set exports(e){zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isBetween=function(o,u,l,d){var c=s(o),f=s(u),g=(d=d||"()")[0]==="(",h=d[1]===")";return(g?this.isAfter(c,l):!this.isBefore(c,l))&&(h?this.isBefore(f,l):!this.isAfter(f,l))||(g?this.isBefore(c,l):!this.isAfter(c,l))&&(h?this.isAfter(f,l):!this.isBefore(f,l))}}})})(uw);const dw=zr;var Er={},cw={get exports(){return Er},set exports(e){Er=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(cw);const pw=Er;var Lr={},hw={get exports(){return Lr},set exports(e){Lr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.isMoment=function(o){return s.isDayjs(o)}}})})(hw);const fw=Lr;var Pr={},gw={get exports(){return Pr},set exports(e){Pr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="day";return function(i,s,o){var u=function(c){return c.add(4-c.isoWeekday(),r)},l=s.prototype;l.isoWeekYear=function(){return u(this).year()},l.isoWeek=function(c){if(!this.$utils().u(c))return this.add(7*(c-this.isoWeek()),r);var f,g,h,m,w=u(this),C=(f=this.isoWeekYear(),g=this.$u,h=(g?o.utc:o)().year(f).startOf("year"),m=4-h.isoWeekday(),h.isoWeekday()>4&&(m+=7),h.add(m,r));return w.diff(C,"week")+1},l.isoWeekday=function(c){return this.$utils().u(c)?this.day()||7:this.day(this.day()%7?c:c-7)};var d=l.startOf;l.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;return g.p(c)==="isoweek"?h?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):d.bind(this)(c,f)}}})})(gw);const mw=Pr;var Or={},bw={get exports(){return Or},set exports(e){Or=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isoWeeksInYear=function(){var s=this.isLeapYear(),o=this.endOf("y").day();return o===4||s&&o===5?53:52}}})})(bw);const yw=Or;var Vr={},vw={get exports(){return Vr},set exports(e){Vr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrAfter=function(s,o){return this.isSame(s,o)||this.isAfter(s,o)}}})})(vw);const xw=Vr;var Br={},Cw={get exports(){return Br},set exports(e){Br=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrBefore=function(s,o){return this.isSame(s,o)||this.isBefore(s,o)}}})})(Cw);const ww=Br;var Nr={},_w={get exports(){return Nr},set exports(e){Nr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isToday=function(){var o="YYYY-MM-DD",u=s();return this.format(o)===u.format(o)}}})})(_w);const Sw=Nr;var Gr={},Tw={get exports(){return Gr},set exports(e){Gr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isTomorrow=function(){var o="YYYY-MM-DD",u=s().add(1,"day");return this.format(o)===u.format(o)}}})})(Tw);const kw=Gr;var qr={},Dw={get exports(){return qr},set exports(e){qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isYesterday=function(){var o="YYYY-MM-DD",u=s().subtract(1,"day");return this.format(o)===u.format(o)}}})})(Dw);const Mw=qr;var Fr={},Iw={get exports(){return Fr},set exports(e){Fr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){return g&&(g.indexOf?g:g.s)},l=function(g,h,m,w,C){var S=g.name?g:g.$locale(),I=u(S[h]),$=u(S[m]),P=I||$.map(function(L){return L.slice(0,w)});if(!C)return P;var q=S.weekStart;return P.map(function(L,z){return P[(z+(q||0))%7]})},d=function(){return s.Ls[s.locale()]},c=function(g,h){return g.formats[h]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,S){return C||S.slice(1)})}(g.formats[h.toUpperCase()])},f=function(){var g=this;return{months:function(h){return h?h.format("MMMM"):l(g,"months")},monthsShort:function(h){return h?h.format("MMM"):l(g,"monthsShort","months",3)},firstDayOfWeek:function(){return g.$locale().weekStart||0},weekdays:function(h){return h?h.format("dddd"):l(g,"weekdays")},weekdaysMin:function(h){return h?h.format("dd"):l(g,"weekdaysMin","weekdays",2)},weekdaysShort:function(h){return h?h.format("ddd"):l(g,"weekdaysShort","weekdays",3)},longDateFormat:function(h){return c(g.$locale(),h)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},s.localeData=function(){var g=d();return{firstDayOfWeek:function(){return g.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(h){return c(g,h)},meridiem:g.meridiem,ordinal:g.ordinal}},s.months=function(){return l(d(),"months")},s.monthsShort=function(){return l(d(),"monthsShort","months",3)},s.weekdays=function(g){return l(d(),"weekdays",null,null,g)},s.weekdaysShort=function(g){return l(d(),"weekdaysShort","weekdays",3,g)},s.weekdaysMin=function(g){return l(d(),"weekdaysMin","weekdays",2,g)}}})})(Iw);const Aw=Fr;var Wr={},$w={get exports(){return Wr},set exports(e){Wr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(i,s,o){var u=s.prototype,l=u.format;o.en.formats=r,u.format=function(d){d===void 0&&(d="YYYY-MM-DDTHH:mm:ssZ");var c=this.$locale().formats,f=function(g,h){return g.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var S=C&&C.toUpperCase();return w||h[C]||r[C]||h[S].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,$,P){return $||P.slice(1)})})}(d,c===void 0?{}:c);return l.call(this,f)}}})})($w);const zw=Wr;var jr={},Ew={get exports(){return jr},set exports(e){jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=function(u,l){if(!l||!l.length||!l[0]||l.length===1&&!l[0].length)return null;var d;l.length===1&&l[0].length>0&&(l=l[0]),d=l[0];for(var c=1;c<l.length;c+=1)l[c].isValid()&&!l[c][u](d)||(d=l[c]);return d};s.max=function(){var u=[].slice.call(arguments,0);return o("isAfter",u)},s.min=function(){var u=[].slice.call(arguments,0);return o("isBefore",u)}}})})(Ew);const Lw=jr;var Rr={},Pw={get exports(){return Rr},set exports(e){Rr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){var h,m=g.date,w=g.utc,C={};if(!((h=m)instanceof Date)&&!(h instanceof Array)&&h instanceof Object){if(!Object.keys(m).length)return new Date;var S=w?s.utc():s();Object.keys(m).forEach(function(G){var U,Q;C[U=G,Q=o.$utils().p(U),Q==="date"?"day":Q]=m[G]});var I=C.day||(C.year||C.month>=0?1:S.date()),$=C.year||S.year(),P=C.month>=0?C.month:C.year||C.day?0:S.month(),q=C.hour||0,L=C.minute||0,z=C.second||0,A=C.millisecond||0;return w?new Date(Date.UTC($,P,I,q,L,z,A)):new Date($,P,I,q,L,z,A)}return m},l=o.parse;o.parse=function(g){g.date=u.bind(this)(g),l.bind(this)(g)};var d=o.set,c=o.add,f=function(g,h,m,w){if(w===void 0&&(w=1),h instanceof Object){var C=Object.keys(h),S=this;return C.forEach(function(I){S=g.bind(S)(h[I]*w,I)}),S}return g.bind(this)(h*w,m)};o.set=function(g,h){return h=h===void 0?g:h,f.bind(this)(function(m,w){return d.bind(this)(w,m)},h,g)},o.add=function(g,h){return f.bind(this)(c,g,h)},o.subtract=function(g,h){return f.bind(this)(c,g,h,-1)}}})})(Pw);const Ow=Rr;var Yr={},Vw={get exports(){return Yr},set exports(e){Yr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){s[o]=s[o.replace(/s$/,"")]})}})})(Vw);const Bw=Yr;var Qr={},Nw={get exports(){return Qr},set exports(e){Qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype.parse;i.prototype.parse=function(l){if(typeof l.date=="string"){var d=this.$locale();l.date=d&&d.preparse?d.preparse(l.date):l.date}return s.bind(this)(l)};var o=i.prototype.format;i.prototype.format=function(){for(var l=arguments.length,d=new Array(l),c=0;c<l;c++)d[c]=arguments[c];var f=o.call.apply(o,[this].concat(d)),g=this.$locale();return g&&g.postformat?g.postformat(f):f};var u=i.prototype.fromToBase;u&&(i.prototype.fromToBase=function(l,d,c,f){var g=this.$locale()||c.$locale();return u.call(this,l,d,c,f,g&&g.postformat)})}})})(Nw);const Gw=Qr;var Ur={},qw={get exports(){return Ur},set exports(e){Ur=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="month",i="quarter";return function(s,o){var u=o.prototype;u.quarter=function(c){return this.$utils().u(c)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(c-1))};var l=u.add;u.add=function(c,f){return c=Number(c),this.$utils().p(f)===i?this.add(3*c,r):l.bind(this)(c,f)};var d=u.startOf;u.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;if(g.p(c)===i){var m=this.quarter()-1;return h?this.month(3*m).startOf(r).startOf("day"):this.month(3*m+2).endOf(r).endOf("day")}return d.bind(this)(c,f)}}})})(qw);const Fw=Ur;var Xr={},Ww={get exports(){return Xr},set exports(e){Xr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){r=r||{};var o=i.prototype,u={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 l(c,f,g,h){return o.fromToBase(c,f,g,h)}s.en.relativeTime=u,o.fromToBase=function(c,f,g,h,m){for(var w,C,S,I=g.$locale().relativeTime||u,$=r.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"}],P=$.length,q=0;q<P;q+=1){var L=$[q];L.d&&(w=h?s(c).diff(g,L.d,!0):g.diff(c,L.d,!0));var z=(r.rounding||Math.round)(Math.abs(w));if(S=w>0,z<=L.r||!L.r){z<=1&&q>0&&(L=$[q-1]);var A=I[L.l];m&&(z=m(""+z)),C=typeof A=="string"?A.replace("%d",z):A(z,f,L.l,S);break}}if(f)return C;var G=S?I.future:I.past;return typeof G=="function"?G(C):G.replace("%s",C)},o.to=function(c,f){return l(c,f,this,!0)},o.from=function(c,f){return l(c,f,this)};var d=function(c){return c.$u?s.utc():s()};o.toNow=function(c){return this.to(d(this),c)},o.fromNow=function(c){return this.from(d(this),c)}}})})(Ww);const jw=Xr;var Zr={},Rw={get exports(){return Zr},set exports(e){Zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={year:0,month:1,day:2,hour:3,minute:4,second:5},i={};return function(s,o,u){var l,d=function(h,m,w){w===void 0&&(w={});var C=new Date(h),S=function(I,$){$===void 0&&($={});var P=$.timeZoneName||"short",q=I+"|"+P,L=i[q];return L||(L=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:I,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:P}),i[q]=L),L}(m,w);return S.formatToParts(C)},c=function(h,m){for(var w=d(h,m),C=[],S=0;S<w.length;S+=1){var I=w[S],$=I.type,P=I.value,q=r[$];q>=0&&(C[q]=parseInt(P,10))}var L=C[3],z=L===24?0:L,A=C[0]+"-"+C[1]+"-"+C[2]+" "+z+":"+C[4]+":"+C[5]+":000",G=+h;return(u.utc(A).valueOf()-(G-=G%1e3))/6e4},f=o.prototype;f.tz=function(h,m){h===void 0&&(h=l);var w=this.utcOffset(),C=this.toDate(),S=C.toLocaleString("en-US",{timeZone:h}),I=Math.round((C-new Date(S))/1e3/60),$=u(S).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-I,!0);if(m){var P=$.utcOffset();$=$.add(w-P,"minute")}return $.$x.$timezone=h,$},f.offsetName=function(h){var m=this.$x.$timezone||u.tz.guess(),w=d(this.valueOf(),m,{timeZoneName:h}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var g=f.startOf;f.startOf=function(h,m){if(!this.$x||!this.$x.$timezone)return g.call(this,h,m);var w=u(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return g.call(w,h,m).tz(this.$x.$timezone,!0)},u.tz=function(h,m,w){var C=w&&m,S=w||m||l,I=c(+u(),S);if(typeof h!="string")return u(h).tz(S);var $=function(z,A,G){var U=z-60*A*1e3,Q=c(U,G);if(A===Q)return[U,A];var ne=c(U-=60*(Q-A)*1e3,G);return Q===ne?[U,Q]:[z-60*Math.min(Q,ne)*1e3,Math.max(Q,ne)]}(u.utc(h,C).valueOf(),I,S),P=$[0],q=$[1],L=u(P).utcOffset(q);return L.$x.$timezone=S,L},u.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},u.tz.setDefault=function(h){l=h}}})})(Rw);const Yw=Zr;var Kr={},Qw={get exports(){return Kr},set exports(e){Kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(Qw);const Uw=Kr;var Jr={},Xw={get exports(){return Jr},set exports(e){Jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(Xw);const Zw=Jr;var Hr={},Kw={get exports(){return Hr},set exports(e){Hr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.updateLocale=function(o,u){var l=s.Ls[o];if(l)return(u?Object.keys(u):[]).forEach(function(d){l[d]=u[d]}),l}}})})(Kw);const Jw=Hr;var ei={},Hw={get exports(){return ei},set exports(e){ei=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="minute",i=/[+-]\d\d(?::?\d\d)?/g,s=/([+-]|\d\d)/g;return function(o,u,l){var d=u.prototype;l.utc=function(C){var S={date:C,utc:!0,args:arguments};return new u(S)},d.utc=function(C){var S=l(this.toDate(),{locale:this.$L,utc:!0});return C?S.add(this.utcOffset(),r):S},d.local=function(){return l(this.toDate(),{locale:this.$L,utc:!1})};var c=d.parse;d.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),c.call(this,C)};var f=d.init;d.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var g=d.utcOffset;d.utcOffset=function(C,S){var I=this.$utils().u;if(I(C))return this.$u?0:I(this.$offset)?g.call(this):this.$offset;if(typeof C=="string"&&(C=function(L){L===void 0&&(L="");var z=L.match(i);if(!z)return null;var A=(""+z[0]).match(s)||["-",0,0],G=A[0],U=60*+A[1]+ +A[2];return U===0?0:G==="+"?U:-U}(C),C===null))return this;var $=Math.abs(C)<=16?60*C:C,P=this;if(S)return P.$offset=$,P.$u=C===0,P;if(C!==0){var q=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(P=this.local().add($+q,r)).$offset=$,P.$x.$localOffset=q}else P=this.utc();return P};var h=d.format;d.format=function(C){var S=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,S)},d.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},d.isUTC=function(){return!!this.$u},d.toISOString=function(){return this.toDate().toISOString()},d.toString=function(){return this.toDate().toUTCString()};var m=d.toDate;d.toDate=function(C){return C==="s"&&this.$offset?l(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=d.diff;d.diff=function(C,S,I){if(C&&this.$u===C.$u)return w.call(this,C,S,I);var $=this.local(),P=l(C).local();return w.call($,P,S,I)}}})})(Hw);const e1=ei;var ti={},t1={get exports(){return ti},set exports(e){ti=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekday=function(s){var o=this.$locale().weekStart||0,u=this.$W,l=(u<o?u+7:u)-o;return this.$utils().u(s)?l:this.subtract(l,"day").add(s,"day")}}})})(t1);const n1=ti;var ni={},r1={get exports(){return ni},set exports(e){ni=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="week",i="year";return function(s,o,u){var l=o.prototype;l.week=function(d){if(d===void 0&&(d=null),d!==null)return this.add(7*(d-this.week()),"day");var c=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=u(this).startOf(i).add(1,i).date(c),g=u(this).endOf(r);if(f.isBefore(g))return 1}var h=u(this).startOf(i).date(c).startOf(r).subtract(1,"millisecond"),m=this.diff(h,r,!0);return m<0?u(this).startOf("week").week():Math.ceil(m)},l.weeks=function(d){return d===void 0&&(d=null),this.week(d)}}})})(r1);const i1=ni;var ri={},a1={get exports(){return ri},set exports(e){ri=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekYear=function(){var s=this.month(),o=this.week(),u=this.year();return o===1&&s===11?u+1:s===0&&o>=52?u-1:u}}})})(a1);const s1=ri;j.extend(UC),j.extend(ZC),j.extend(JC),j.extend(ew),j.extend(nw),j.extend(iw),j.extend(sw),j.extend(lw),j.extend(dw),j.extend(pw),j.extend(fw),j.extend(xw),j.extend(ww),j.extend(Sw),j.extend(kw),j.extend(Mw),j.extend(mw),j.extend(yw),j.extend(Aw),j.extend(zw),j.extend(Lw),j.extend(Ow),j.extend(Bw),j.extend(Gw),j.extend(Fw),j.extend(jw),j.extend(Yw),j.extend(Uw),j.extend(Zw),j.extend(Jw),j.extend(e1),j.extend(i1),j.extend(s1),j.extend(n1),j.tz.setDefault("UTC");const o1=()=>Promise.resolve().then(()=>il).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));D.ContentModel=It,D.ContentModelContextProvider=xn,D.ContextModel=xs,D.DashboardEditor=RC,D.DashboardFilterType=or,D.DashboardMode=Za,D.DashboardModel=As,D.DashboardViewEditor=Ja,D.DashboardViewRender=an,D.EViewComponentType=K,D.FilterModel=ur,D.FiltersModel=ds,D.FullScreenPanelContext=wn,D.LayoutStateContext=Ke,D.ModelContextProvider=vn,D.Panel=rn,D.PanelContextProvider=Cn,D.PanelModel=Cs,D.PanelsModel=_s,D.QueriesModel=bs,D.QueryModel=ms,D.ReadOnlyDashboard=YC,D.SQLSnippetModel=ys,D.SQLSnippetsModel=vs,D.ViewComponentTypeBackground=Ka,D.ViewComponentTypeColor=Ry,D.ViewComponentTypeName=jy,D.ViewModel=Ds,D.ViewsModel=Ms,D.applyPartialDashboard=rx,D.createContentModel=Is,D.createDashboardModel=gr,D.createDashboardViewsModel=fr,D.getInitialFiltersPayload=cs,D.getNewPanel=ws,D.getVersion=o1,D.initialDashboardContent=Yy,D.useContentModelContext=F,D.useFullScreenPanelContext=Oi,D.useModelContext=me,D.usePanelContext=Ce,D.useTopLevelServices=mr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
489
|
+
`)},oC=T.observer(({queryModel:e})=>{const[t,r]=b.useState(e.sql);b.useEffect(()=>{r(o=>o!==e.sql?e.sql:o)},[e.sql]);const i=t!==e.sql,s=()=>{e.setSQL(t)};return e.typedAsSQL?p(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Edit",children:p(a.Group,{spacing:14,position:"apart",children:["Edit SQL",n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!i,onClick:s,children:n(k.DeviceFloppy,{size:20})})]})}),n(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),n(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(wr,{}),e.datasource&&n(Ws,{dataSource:e.datasource})]}),n(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n(_r,{height:"100%",value:t,onChange:r})}),n(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n(sC,{value:e.sql})}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(dn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Ys.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(dn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Ys.post})})]}):null}),cn={height:"calc(100% - 44px)",padding:0},lC=T.observer(({queryModel:e})=>{const t=F(),r=b.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),i=t.findQueryUsage(e.id),s=i.length===0;return n(a.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(a.Tabs,{defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(a.Tabs.List,{grow:!0,children:[n(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&n(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&n(a.Tabs.Tab,{value:"HTTP",children:"Request"}),n(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:n(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:n(a.Text,{children:"Data"})})}),n(a.Tabs.Tab,{value:"Usage",disabled:s,children:n(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!s,withinPortal:!0,children:n(a.Text,{children:"Usage"})})})]}),n(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n(H0,{queryModel:e})}),e.typedAsSQL&&n(a.Tabs.Panel,{value:"SQL",sx:cn,children:n(a.Stack,{sx:{height:"100%"},children:n(oC,{queryModel:e})})}),e.typedAsHTTP&&n(a.Tabs.Panel,{value:"HTTP",sx:cn,children:n(a.Stack,{sx:{height:"100%"},children:n(rC,{queryModel:e})})}),n(a.Tabs.Panel,{value:"Data",sx:{...cn,overflow:"hidden"},children:n(Bs,{id:e.id})}),n(a.Tabs.Panel,{value:"Usage",sx:{...cn,overflow:"hidden"},children:n(iC,{queryID:e.id,usage:i})})]})})}),uC=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?n(a.Stack,{sx:{height:"100%"},spacing:"sm",children:n(lC,{queryModel:r})}):n(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),dC=T.observer(({value:e})=>{const t=F(),{context:r,mock_context:i,filterValues:s}=t.payloadForSQL,o=Ev(e,r,i,s);return n(_r,{height:"100%",value:o})}),cC=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const[i,s]=b.useState("SQL"),[o,u]=b.useState(e.key),l=()=>{e.setKey(o),r(o)},d=o!==e.key,c=e.isADuplicatedKey(o),[f,g]=b.useState(e.value),h=()=>{e.setValue(f)};b.useEffect(()=>{u(e.key),g(e.value)},[e]);const m=f!==e.value,w=Le.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,zIndex:320})};return p(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(a.Group,{sx:{alignItems:"end"},spacing:40,children:[n(a.TextInput,{label:c?"This key is occupied by another snippet":"Key",value:o,onChange:S=>{u(S.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n(a.ActionIcon,{color:"blue",variant:"subtle",onClick:l,disabled:!d||c,children:n(k.DeviceFloppy,{size:16})}),error:c}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(a.Tabs,{value:i,onTabChange:s,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(a.Tabs.List,{sx:{position:"relative"},children:[n(a.Tabs.Tab,{value:"SQL",children:"SQL"}),n(a.Tabs.Tab,{value:"Preview",children:"Preview"}),n(wr,{}),n(a.ActionIcon,{color:"blue",variant:"filled",onClick:h,disabled:!m,sx:{position:"absolute",top:0,right:10},children:n(k.DeviceFloppy,{size:18})})]}),n(a.Tabs.Panel,{value:"SQL",pt:"sm",children:n(_r,{height:"100%",value:f,onChange:g})}),n(a.Tabs.Panel,{value:"Preview",pt:"sm",children:n(dC,{value:f})})]})]})}),pC=T.observer(({id:e})=>{const t=me(),r=F(),i=b.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!i)return p(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const s=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return n(cC,{item:i,remove:()=>{r.sqlSnippets.removeByKey(e),s()},onKeyChanged:l=>{t.editor.setPath(["_SQL_SNIPPETS_",l])}})}),hC=T.observer(({view:e})=>!e||e.type!==K.Division?null:p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),n(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),fC=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],gC=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],mC=T.observer(({view:e})=>{if(!e||e.type!==K.Tabs)return null;const t=e.config;return p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),n(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:fC}),n(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:gC}),n(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:r=>t.setGrow(r.currentTarget.checked)})]})}),bC=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},yC=({value:e,onChange:t})=>{const[r,{setTrue:i,setFalse:s}]=Z.useBoolean(),[o,u]=b.useState(e??hr),l=h=>{u({...o,enabled:h})},d=()=>{s();const{enabled:h,func_content:m}=o,w={enabled:h,func_content:m};u(w),t(w)},c=()=>{s(),u(e)},f=h=>{u(m=>({...m,func_content:h}))},g=()=>{f(hr.func_content)};return p(B,{children:[n(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:n(k.Settings,{size:14})}),n(a.Modal,{size:800,title:"Customize modal title",opened:r,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:h=>l(h.currentTarget.checked)}),n(bC,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},vC=T.observer(({view:e})=>{if(!e||e.type!==K.Modal)return null;const t=e.config,r=t.custom_modal_title.value;return p(a.Stack,{children:[n(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(a.Flex,{gap:10,children:[n(a.TextInput,{label:"Modal Title",value:r,onChange:v.noop,disabled:!0,sx:{flexGrow:1}}),n(yC,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(a.Group,{grow:!0,children:[n(a.TextInput,{label:"Width",value:t.width,onChange:i=>t.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),n(a.TextInput,{label:"Height",value:t.height,onChange:i=>t.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),xC=T.observer(({view:e})=>p(B,{children:[n(hC,{view:e}),n(vC,{view:e}),n(mC,{view:e})]})),CC=[{label:"Division",value:K.Division},{label:"Modal",value:K.Modal},{label:"Tabs",value:K.Tabs}],wC=T.observer(({view:e})=>e?p(a.Stack,{sx:{position:"relative"},children:[n(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(a.Select,{label:"Type",withinPortal:!0,value:e.type,onChange:e.setType,data:CC}),n(xC,{view:e})]}):null),_C=T.observer(({id:e})=>{const t=Le.useModals(),r=me(),i=F();if(e==="")return null;const s=i.views.findByID(e);if(!s)return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_VIEWS_",""])},u=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this view"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(wC,{view:s})})]})});function SC(e){return e.length===1&&e[0]==="_GLOBAL_VARS_"}function TC(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function kC(e){return e.length===2&&e[0]==="_FILTERS_"}function DC(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function MC(e){return e.length===2&&e[0]==="_QUERIES_"}function IC(e){return e.length===2&&e[0]==="_VIEWS_"}function AC(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const $C=T.observer(()=>n(a.Stack,{sx:{height:"100%"},p:"sm",children:n(js,{})})),zC=T.observer(()=>{const e=me().editor,t=e.path;return SC(t)?n($C,{}):TC(t)?n(n0,{}):kC(t)?n(a.Box,{p:"xs",pl:20,children:n(t0,{id:t[1]})}):DC(t)?n(pC,{id:t[1]}):MC(t)?n(uC,{id:t[1]}):IC(t)?n(a.Box,{p:"xs",pl:20,children:n(_C,{id:t[1]})}):AC(t)?n(z0,{viewID:t[1],panelID:t[3]}):n(a.Box,{children:e.path})}),EC=T.observer(()=>n(zC,{})),LC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:e.filters.current.length+1,type:or.TextInput,config:os(),visibleInViewsIDs:["Main"],auto_submit:!1};e.filters.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),PC=T.observer(({parentID:e})=>{const t=F();if(!e)return null;const r=t.views.findByID(e);return r?n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),OC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:ce.Postgresql,key:"",sql:""};e.queries.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),VC=T.observer(()=>{const e=F(),t=()=>{const i={key:new Date().getTime().toString(),value:""};e.sqlSnippets.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),BC=T.observer(()=>{const e=F();return n(a.Button,{variant:"subtle",leftIcon:n(V.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"})}),NC=T.observer(({action_type:e,parentID:t})=>(F(),e==="_Add_A_Filter_"?n(LC,{}):e==="_Add_A_SQL_SNIPPET_"?n(VC,{}):e==="_Add_A_QUERY_"?n(OC,{}):e==="_Add_A_VIEW_"?n(BC,{}):e==="_Add_A_PANEL_"?n(PC,{parentID:t}):null)),Qs=T.observer(({option:e})=>{var c;const t=me().editor,r=t.isOptionActive,i=r(t.path,e),s=t.isOptionOpened,o=t.navigate,u=s(e),[l,d]=b.useState(u);return b.useEffect(()=>{d(u)},[u]),n(a.NavLink,{active:i,defaultOpened:u,opened:l,onChange:d,label:e.label,onClick:()=>o(e),icon:e.Icon?n(e.Icon,{size:18}):null,children:(c=e.children)==null?void 0:c.map(f=>f._type==="ACTION"?n(NC,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n(Qs,{option:f},f.value))},e.label)}),GC=T.observer(()=>{const e=me();return n(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n(Qs,{option:t},t.value))})}),qC=T.observer(()=>{const e=me();return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[n(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(GC,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),FC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},WC=T.observer(()=>{const e=me().editor;return n(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:n(a.AppShell,{padding:0,navbar:n(qC,{}),styles:FC,children:n(EC,{})})})}),jC=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function RC(e){b.useEffect(()=>{if(_e.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=jC(e);_e.loader.config({paths:{vs:r}}),_e.loader.init().then(i=>console.log("monaco instance:",i))},[])}const Us={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 YC(){le.registerTheme("merico-light",{color:Object.values(Us.graphics.multiple),visualMap:{color:Object.values(Us.graphics.depth).reverse()}})}function Xs(){YC()}Xs();const QC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},UC=({context:e,dashboard:t,content:r,update:i,className:s="dashboard",config:o,onChange:u,headerSlot:l,headerMenuItems:d},c)=>{RC(o.monacoPath),Ha(o);const{data:f=[]}=Z.useRequest(pr),[g,h]=b.useState(!1),m=b.useMemo(()=>gr(t,r,f,e),[t,r]);b.useImperativeHandle(c,()=>m,[m]),$i(m.content,!0),b.useEffect(()=>{m.context.replace(e)},[e]),b.useEffect(()=>{m.datasources.replace(f)},[f]),b.useEffect(()=>se.reaction(()=>se.toJS(m.json),I=>{u==null||u(I)}),[m]);const w=async()=>{await i(m.json,m.content.json)},C=Z.useCreation(ar,[]),S=mr(C);return n(Le.ModalsProvider,{children:n(vn,{value:m,children:n(xn,{value:m.content,children:n(Ke.Provider,{value:{layoutFrozen:g,freezeLayout:h,inEditMode:!0},children:n(qe.Provider,{value:C,children:p(Gt,{configure:S,children:[n(a.AppShell,{padding:0,header:n(hx,{saveDashboardChanges:w,headerSlot:l,headerMenuItems:d}),navbar:n(Gx,{}),styles:QC,children:n(a.Box,{className:`${s} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n(Ja,{view:I},I.id))})}),n(WC,{})]})})})})})})},XC=T.observer(b.forwardRef(UC)),R1="";Xs();const ZC=T.observer(({context:e,dashboard:t,content:r,className:i="dashboard",config:s,fullScreenPanelID:o,setFullScreenPanelID:u})=>{Ha(s);const{data:l=[]}=Z.useRequest(pr),d=b.useMemo(()=>gr(t,r,l,e),[t,r]);$i(d.content,!1),b.useEffect(()=>{d.context.replace(e)},[e]),b.useEffect(()=>{d.datasources.replace(l)},[l]);const c=Z.useCreation(ar,[]),f=mr(c);return n(Le.ModalsProvider,{children:n(vn,{value:d,children:n(xn,{value:d.content,children:n(wn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:u},children:n(Ke.Provider,{value:{layoutFrozen:!0,freezeLayout:v.noop,inEditMode:!1},children:n(a.Box,{className:`${i} dashboard-root`,children:n(qe.Provider,{value:c,children:n(Gt,{configure:f,children:d.content.views.visibleViews.map(g=>n(an,{view:g},g.id))})})})})})})})})});var Sr={},KC={get exports(){return Sr},set exports(e){Sr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=o.format;s.en.ordinal=function(l){var d=["th","st","nd","rd"],c=l%100;return"["+l+(d[(c-20)%10]||d[c]||d[0])+"]"},o.format=function(l){var d=this,c=this.$locale();if(!this.isValid())return u.bind(this)(l);var f=this.$utils(),g=(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((d.$M+1)/3);case"Do":return c.ordinal(d.$D);case"gggg":return d.weekYear();case"GGGG":return d.isoWeekYear();case"wo":return c.ordinal(d.week(),"W");case"w":case"ww":return f.s(d.week(),h==="w"?1:2,"0");case"W":case"WW":return f.s(d.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return f.s(String(d.$H===0?24:d.$H),h==="k"?1:2,"0");case"X":return Math.floor(d.$d.getTime()/1e3);case"x":return d.$d.getTime();case"z":return"["+d.offsetName()+"]";case"zzz":return"["+d.offsetName("long")+"]";default:return h}});return u.bind(this)(g)}}})})(KC);const JC=Sr;var Tr={},HC={get exports(){return Tr},set exports(e){Tr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(d){var c=d.date,f=d.utc;return Array.isArray(c)?f?c.length?new Date(Date.UTC.apply(null,c)):new Date:c.length===1?s(String(c[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(c))):c},l=o.parse;o.parse=function(d){d.date=u.bind(this)(d),l.bind(this)(d)}}})})(HC);const ew=Tr;var kr={},tw={get exports(){return kr},set exports(e){kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;s.$g=function(h,m,w){return this.$utils().u(h)?this[m]:this.$set(w,h)},s.set=function(h,m){return this.$set(h,m)};var o=s.startOf;s.startOf=function(h,m){return this.$d=o.bind(this)(h,m).toDate(),this.init(),this};var u=s.add;s.add=function(h,m){return this.$d=u.bind(this)(h,m).toDate(),this.init(),this};var l=s.locale;s.locale=function(h,m){return h?(this.$L=l.bind(this)(h,m).$L,this):this.$L};var d=s.daysInMonth;s.daysInMonth=function(){return d.bind(this.clone())()};var c=s.isSame;s.isSame=function(h,m){return c.bind(this.clone())(h,m)};var f=s.isBefore;s.isBefore=function(h,m){return f.bind(this.clone())(h,m)};var g=s.isAfter;s.isAfter=function(h,m){return g.bind(this.clone())(h,m)}}})})(tw);const nw=kr;var Dr={},rw={get exports(){return Dr},set exports(e){Dr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype,o=s.format;s.format=function(u){var l=this,d=(u||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(c,f){var g,h=String(l.$y+543),m=c==="BB"?[h.slice(-2),2]:[h,4];return f||(g=l.$utils()).s.apply(g,m.concat(["0"]))});return o.bind(this)(d)}}})})(rw);const iw=Dr;var Mr={},aw={get exports(){return Mr},set exports(e){Mr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o="h:mm A",u={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};i.prototype.calendar=function(l,d){var c=d||this.$locale().calendar||u,f=s(l||void 0).startOf("d"),g=this.diff(f,"d",!0),h="sameElse",m=g<-6?h:g<-1?"lastWeek":g<0?"lastDay":g<1?"sameDay":g<2?"nextDay":g<7?"nextWeek":h,w=c[m]||u[m];return typeof w=="function"?w.call(this,s()):this.format(w)}}})})(aw);const sw=Mr;var Ir={},ow={get exports(){return Ir},set exports(e){Ir=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},i=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d\d/,o=/\d\d?/,u=/\d*[^-_:/,()\s\d]+/,l={},d=function(C){return(C=+C)+(C>68?1900:2e3)},c=function(C){return function(S){this[C]=+S}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(S){if(!S||S==="Z")return 0;var I=S.match(/([+-]|\d\d)/g),$=60*I[1]+(+I[2]||0);return $===0?0:I[0]==="+"?-$:$}(C)}],g=function(C){var S=l[C];return S&&(S.indexOf?S:S.s.concat(S.f))},h=function(C,S){var I,$=l.meridiem;if($){for(var P=1;P<=24;P+=1)if(C.indexOf($(P,0,S))>-1){I=P>12;break}}else I=C===(S?"pm":"PM");return I},m={A:[u,function(C){this.afternoon=h(C,!1)}],a:[u,function(C){this.afternoon=h(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[s,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,c("seconds")],ss:[o,c("seconds")],m:[o,c("minutes")],mm:[o,c("minutes")],H:[o,c("hours")],h:[o,c("hours")],HH:[o,c("hours")],hh:[o,c("hours")],D:[o,c("day")],DD:[s,c("day")],Do:[u,function(C){var S=l.ordinal,I=C.match(/\d+/);if(this.day=I[0],S)for(var $=1;$<=31;$+=1)S($).replace(/\[|\]/g,"")===C&&(this.day=$)}],M:[o,c("month")],MM:[s,c("month")],MMM:[u,function(C){var S=g("months"),I=(g("monthsShort")||S.map(function($){return $.slice(0,3)})).indexOf(C)+1;if(I<1)throw new Error;this.month=I%12||I}],MMMM:[u,function(C){var S=g("months").indexOf(C)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,c("year")],YY:[s,function(C){this.year=d(C)}],YYYY:[/\d{4}/,c("year")],Z:f,ZZ:f};function w(C){var S,I;S=C,I=l&&l.formats;for(var $=(C=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Q,ne){var ie=ne&&ne.toUpperCase();return Q||I[ne]||r[ne]||I[ie].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(oe,re,pe){return re||pe.slice(1)})})).match(i),P=$.length,q=0;q<P;q+=1){var L=$[q],z=m[L],A=z&&z[0],G=z&&z[1];$[q]=G?{regex:A,parser:G}:L.replace(/^\[|\]$/g,"")}return function(U){for(var Q={},ne=0,ie=0;ne<P;ne+=1){var oe=$[ne];if(typeof oe=="string")ie+=oe.length;else{var re=oe.regex,pe=oe.parser,fe=U.slice(ie),Te=re.exec(fe)[0];pe.call(Q,Te),U=U.replace(Te,"")}}return function(We){var $e=We.afternoon;if($e!==void 0){var Qe=We.hours;$e?Qe<12&&(We.hours+=12):Qe===12&&(We.hours=0),delete We.afternoon}}(Q),Q}}return function(C,S,I){I.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(d=C.parseTwoDigitYear);var $=S.prototype,P=$.parse;$.parse=function(q){var L=q.date,z=q.utc,A=q.args;this.$u=z;var G=A[1];if(typeof G=="string"){var U=A[2]===!0,Q=A[3]===!0,ne=U||Q,ie=A[2];Q&&(ie=A[2]),l=this.$locale(),!U&&ie&&(l=I.Ls[ie]),this.$d=function(fe,Te,We){try{if(["x","X"].indexOf(Te)>-1)return new Date((Te==="X"?1e3:1)*fe);var $e=w(Te)(fe),Qe=$e.year,it=$e.month,pn=$e.day,hn=$e.hours,ii=$e.minutes,ai=$e.seconds,$t=$e.milliseconds,ft=$e.zone,tt=new Date,at=pn||(Qe||it?1:tt.getDate()),nt=Qe||tt.getFullYear(),gt=0;Qe&&!it||(gt=it>0?it-1:tt.getMonth());var mt=hn||0,zt=ii||0,Et=ai||0,rt=$t||0;return ft?new Date(Date.UTC(nt,gt,at,mt,zt,Et,rt+60*ft.offset*1e3)):We?new Date(Date.UTC(nt,gt,at,mt,zt,Et,rt)):new Date(nt,gt,at,mt,zt,Et,rt)}catch{return new Date("")}}(L,G,z),this.init(),ie&&ie!==!0&&(this.$L=this.locale(ie).$L),ne&&L!=this.format(G)&&(this.$d=new Date("")),l={}}else if(G instanceof Array)for(var oe=G.length,re=1;re<=oe;re+=1){A[1]=G[re-1];var pe=I.apply(this,A);if(pe.isValid()){this.$d=pe.$d,this.$L=pe.$L,this.init();break}re===oe&&(this.$d=new Date(""))}else P.call(this,q)}}})})(ow);const lw=Ir;var Ar={},uw={get exports(){return Ar},set exports(e){Ar=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.dayOfYear=function(o){var u=Math.round((s(this).startOf("day")-s(this).startOf("year"))/864e5)+1;return o==null?u:this.add(o-u,"day")}}})})(uw);const dw=Ar;var $r={},cw={get exports(){return $r},set exports(e){$r=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r,i,s=1e3,o=6e4,u=36e5,l=864e5,d=/\[([^\]]+)]|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,c=31536e6,f=2592e6,g=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,h={years:c,months:f,days:l,hours:u,minutes:o,seconds:s,milliseconds:1,weeks:6048e5},m=function(L){return L instanceof q},w=function(L,z,A){return new q(L,A,z.$l)},C=function(L){return i.p(L)+"s"},S=function(L){return L<0},I=function(L){return S(L)?Math.ceil(L):Math.floor(L)},$=function(L){return Math.abs(L)},P=function(L,z){return L?S(L)?{negative:!0,format:""+$(L)+z}:{negative:!1,format:""+L+z}:{negative:!1,format:""}},q=function(){function L(A,G,U){var Q=this;if(this.$d={},this.$l=U,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),G)return w(A*h[C(G)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(oe){Q.$d[C(oe)]=A[oe]}),this.calMilliseconds(),this;if(typeof A=="string"){var ne=A.match(g);if(ne){var ie=ne.slice(2).map(function(oe){return oe!=null?Number(oe):0});return this.$d.years=ie[0],this.$d.months=ie[1],this.$d.weeks=ie[2],this.$d.days=ie[3],this.$d.hours=ie[4],this.$d.minutes=ie[5],this.$d.seconds=ie[6],this.calMilliseconds(),this}}return this}var z=L.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(G,U){return G+(A.$d[U]||0)*h[U]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=I(A/c),A%=c,this.$d.months=I(A/f),A%=f,this.$d.days=I(A/l),A%=l,this.$d.hours=I(A/u),A%=u,this.$d.minutes=I(A/o),A%=o,this.$d.seconds=I(A/s),A%=s,this.$d.milliseconds=A},z.toISOString=function(){var A=P(this.$d.years,"Y"),G=P(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Q=P(U,"D"),ne=P(this.$d.hours,"H"),ie=P(this.$d.minutes,"M"),oe=this.$d.seconds||0;this.$d.milliseconds&&(oe+=this.$d.milliseconds/1e3);var re=P(oe,"S"),pe=A.negative||G.negative||Q.negative||ne.negative||ie.negative||re.negative,fe=ne.format||ie.format||re.format?"T":"",Te=(pe?"-":"")+"P"+A.format+G.format+Q.format+fe+ne.format+ie.format+re.format;return Te==="P"||Te==="-P"?"P0D":Te},z.toJSON=function(){return this.toISOString()},z.format=function(A){var G=A||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return G.replace(d,function(Q,ne){return ne||String(U[Q])})},z.as=function(A){return this.$ms/h[C(A)]},z.get=function(A){var G=this.$ms,U=C(A);return U==="milliseconds"?G%=1e3:G=U==="weeks"?I(G/h[U]):this.$d[U],G===0?0:G},z.add=function(A,G,U){var Q;return Q=G?A*h[C(G)]:m(A)?A.$ms:w(A,this).$ms,w(this.$ms+Q*(U?-1:1),this)},z.subtract=function(A,G){return this.add(A,G,!0)},z.locale=function(A){var G=this.clone();return G.$l=A,G},z.clone=function(){return w(this.$ms,this)},z.humanize=function(A){return r().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},z.milliseconds=function(){return this.get("milliseconds")},z.asMilliseconds=function(){return this.as("milliseconds")},z.seconds=function(){return this.get("seconds")},z.asSeconds=function(){return this.as("seconds")},z.minutes=function(){return this.get("minutes")},z.asMinutes=function(){return this.as("minutes")},z.hours=function(){return this.get("hours")},z.asHours=function(){return this.as("hours")},z.days=function(){return this.get("days")},z.asDays=function(){return this.as("days")},z.weeks=function(){return this.get("weeks")},z.asWeeks=function(){return this.as("weeks")},z.months=function(){return this.get("months")},z.asMonths=function(){return this.as("months")},z.years=function(){return this.get("years")},z.asYears=function(){return this.as("years")},L}();return function(L,z,A){r=A,i=A().$utils(),A.duration=function(Q,ne){var ie=A.locale();return w(Q,{$l:ie},ne)},A.isDuration=m;var G=z.prototype.add,U=z.prototype.subtract;z.prototype.add=function(Q,ne){return m(Q)&&(Q=Q.asMilliseconds()),G.bind(this)(Q,ne)},z.prototype.subtract=function(Q,ne){return m(Q)&&(Q=Q.asMilliseconds()),U.bind(this)(Q,ne)}}})})(cw);const pw=$r;var zr={},hw={get exports(){return zr},set exports(e){zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isBetween=function(o,u,l,d){var c=s(o),f=s(u),g=(d=d||"()")[0]==="(",h=d[1]===")";return(g?this.isAfter(c,l):!this.isBefore(c,l))&&(h?this.isBefore(f,l):!this.isAfter(f,l))||(g?this.isBefore(c,l):!this.isAfter(c,l))&&(h?this.isAfter(f,l):!this.isBefore(f,l))}}})})(hw);const fw=zr;var Er={},gw={get exports(){return Er},set exports(e){Er=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(gw);const mw=Er;var Lr={},bw={get exports(){return Lr},set exports(e){Lr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.isMoment=function(o){return s.isDayjs(o)}}})})(bw);const yw=Lr;var Pr={},vw={get exports(){return Pr},set exports(e){Pr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="day";return function(i,s,o){var u=function(c){return c.add(4-c.isoWeekday(),r)},l=s.prototype;l.isoWeekYear=function(){return u(this).year()},l.isoWeek=function(c){if(!this.$utils().u(c))return this.add(7*(c-this.isoWeek()),r);var f,g,h,m,w=u(this),C=(f=this.isoWeekYear(),g=this.$u,h=(g?o.utc:o)().year(f).startOf("year"),m=4-h.isoWeekday(),h.isoWeekday()>4&&(m+=7),h.add(m,r));return w.diff(C,"week")+1},l.isoWeekday=function(c){return this.$utils().u(c)?this.day()||7:this.day(this.day()%7?c:c-7)};var d=l.startOf;l.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;return g.p(c)==="isoweek"?h?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):d.bind(this)(c,f)}}})})(vw);const xw=Pr;var Or={},Cw={get exports(){return Or},set exports(e){Or=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isoWeeksInYear=function(){var s=this.isLeapYear(),o=this.endOf("y").day();return o===4||s&&o===5?53:52}}})})(Cw);const ww=Or;var Vr={},_w={get exports(){return Vr},set exports(e){Vr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrAfter=function(s,o){return this.isSame(s,o)||this.isAfter(s,o)}}})})(_w);const Sw=Vr;var Br={},Tw={get exports(){return Br},set exports(e){Br=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrBefore=function(s,o){return this.isSame(s,o)||this.isBefore(s,o)}}})})(Tw);const kw=Br;var Nr={},Dw={get exports(){return Nr},set exports(e){Nr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isToday=function(){var o="YYYY-MM-DD",u=s();return this.format(o)===u.format(o)}}})})(Dw);const Mw=Nr;var Gr={},Iw={get exports(){return Gr},set exports(e){Gr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isTomorrow=function(){var o="YYYY-MM-DD",u=s().add(1,"day");return this.format(o)===u.format(o)}}})})(Iw);const Aw=Gr;var qr={},$w={get exports(){return qr},set exports(e){qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isYesterday=function(){var o="YYYY-MM-DD",u=s().subtract(1,"day");return this.format(o)===u.format(o)}}})})($w);const zw=qr;var Fr={},Ew={get exports(){return Fr},set exports(e){Fr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){return g&&(g.indexOf?g:g.s)},l=function(g,h,m,w,C){var S=g.name?g:g.$locale(),I=u(S[h]),$=u(S[m]),P=I||$.map(function(L){return L.slice(0,w)});if(!C)return P;var q=S.weekStart;return P.map(function(L,z){return P[(z+(q||0))%7]})},d=function(){return s.Ls[s.locale()]},c=function(g,h){return g.formats[h]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,S){return C||S.slice(1)})}(g.formats[h.toUpperCase()])},f=function(){var g=this;return{months:function(h){return h?h.format("MMMM"):l(g,"months")},monthsShort:function(h){return h?h.format("MMM"):l(g,"monthsShort","months",3)},firstDayOfWeek:function(){return g.$locale().weekStart||0},weekdays:function(h){return h?h.format("dddd"):l(g,"weekdays")},weekdaysMin:function(h){return h?h.format("dd"):l(g,"weekdaysMin","weekdays",2)},weekdaysShort:function(h){return h?h.format("ddd"):l(g,"weekdaysShort","weekdays",3)},longDateFormat:function(h){return c(g.$locale(),h)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},s.localeData=function(){var g=d();return{firstDayOfWeek:function(){return g.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(h){return c(g,h)},meridiem:g.meridiem,ordinal:g.ordinal}},s.months=function(){return l(d(),"months")},s.monthsShort=function(){return l(d(),"monthsShort","months",3)},s.weekdays=function(g){return l(d(),"weekdays",null,null,g)},s.weekdaysShort=function(g){return l(d(),"weekdaysShort","weekdays",3,g)},s.weekdaysMin=function(g){return l(d(),"weekdaysMin","weekdays",2,g)}}})})(Ew);const Lw=Fr;var Wr={},Pw={get exports(){return Wr},set exports(e){Wr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(i,s,o){var u=s.prototype,l=u.format;o.en.formats=r,u.format=function(d){d===void 0&&(d="YYYY-MM-DDTHH:mm:ssZ");var c=this.$locale().formats,f=function(g,h){return g.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var S=C&&C.toUpperCase();return w||h[C]||r[C]||h[S].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,$,P){return $||P.slice(1)})})}(d,c===void 0?{}:c);return l.call(this,f)}}})})(Pw);const Ow=Wr;var jr={},Vw={get exports(){return jr},set exports(e){jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=function(u,l){if(!l||!l.length||!l[0]||l.length===1&&!l[0].length)return null;var d;l.length===1&&l[0].length>0&&(l=l[0]),d=l[0];for(var c=1;c<l.length;c+=1)l[c].isValid()&&!l[c][u](d)||(d=l[c]);return d};s.max=function(){var u=[].slice.call(arguments,0);return o("isAfter",u)},s.min=function(){var u=[].slice.call(arguments,0);return o("isBefore",u)}}})})(Vw);const Bw=jr;var Rr={},Nw={get exports(){return Rr},set exports(e){Rr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){var h,m=g.date,w=g.utc,C={};if(!((h=m)instanceof Date)&&!(h instanceof Array)&&h instanceof Object){if(!Object.keys(m).length)return new Date;var S=w?s.utc():s();Object.keys(m).forEach(function(G){var U,Q;C[U=G,Q=o.$utils().p(U),Q==="date"?"day":Q]=m[G]});var I=C.day||(C.year||C.month>=0?1:S.date()),$=C.year||S.year(),P=C.month>=0?C.month:C.year||C.day?0:S.month(),q=C.hour||0,L=C.minute||0,z=C.second||0,A=C.millisecond||0;return w?new Date(Date.UTC($,P,I,q,L,z,A)):new Date($,P,I,q,L,z,A)}return m},l=o.parse;o.parse=function(g){g.date=u.bind(this)(g),l.bind(this)(g)};var d=o.set,c=o.add,f=function(g,h,m,w){if(w===void 0&&(w=1),h instanceof Object){var C=Object.keys(h),S=this;return C.forEach(function(I){S=g.bind(S)(h[I]*w,I)}),S}return g.bind(this)(h*w,m)};o.set=function(g,h){return h=h===void 0?g:h,f.bind(this)(function(m,w){return d.bind(this)(w,m)},h,g)},o.add=function(g,h){return f.bind(this)(c,g,h)},o.subtract=function(g,h){return f.bind(this)(c,g,h,-1)}}})})(Nw);const Gw=Rr;var Yr={},qw={get exports(){return Yr},set exports(e){Yr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){s[o]=s[o.replace(/s$/,"")]})}})})(qw);const Fw=Yr;var Qr={},Ww={get exports(){return Qr},set exports(e){Qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype.parse;i.prototype.parse=function(l){if(typeof l.date=="string"){var d=this.$locale();l.date=d&&d.preparse?d.preparse(l.date):l.date}return s.bind(this)(l)};var o=i.prototype.format;i.prototype.format=function(){for(var l=arguments.length,d=new Array(l),c=0;c<l;c++)d[c]=arguments[c];var f=o.call.apply(o,[this].concat(d)),g=this.$locale();return g&&g.postformat?g.postformat(f):f};var u=i.prototype.fromToBase;u&&(i.prototype.fromToBase=function(l,d,c,f){var g=this.$locale()||c.$locale();return u.call(this,l,d,c,f,g&&g.postformat)})}})})(Ww);const jw=Qr;var Ur={},Rw={get exports(){return Ur},set exports(e){Ur=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="month",i="quarter";return function(s,o){var u=o.prototype;u.quarter=function(c){return this.$utils().u(c)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(c-1))};var l=u.add;u.add=function(c,f){return c=Number(c),this.$utils().p(f)===i?this.add(3*c,r):l.bind(this)(c,f)};var d=u.startOf;u.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;if(g.p(c)===i){var m=this.quarter()-1;return h?this.month(3*m).startOf(r).startOf("day"):this.month(3*m+2).endOf(r).endOf("day")}return d.bind(this)(c,f)}}})})(Rw);const Yw=Ur;var Xr={},Qw={get exports(){return Xr},set exports(e){Xr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){r=r||{};var o=i.prototype,u={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 l(c,f,g,h){return o.fromToBase(c,f,g,h)}s.en.relativeTime=u,o.fromToBase=function(c,f,g,h,m){for(var w,C,S,I=g.$locale().relativeTime||u,$=r.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"}],P=$.length,q=0;q<P;q+=1){var L=$[q];L.d&&(w=h?s(c).diff(g,L.d,!0):g.diff(c,L.d,!0));var z=(r.rounding||Math.round)(Math.abs(w));if(S=w>0,z<=L.r||!L.r){z<=1&&q>0&&(L=$[q-1]);var A=I[L.l];m&&(z=m(""+z)),C=typeof A=="string"?A.replace("%d",z):A(z,f,L.l,S);break}}if(f)return C;var G=S?I.future:I.past;return typeof G=="function"?G(C):G.replace("%s",C)},o.to=function(c,f){return l(c,f,this,!0)},o.from=function(c,f){return l(c,f,this)};var d=function(c){return c.$u?s.utc():s()};o.toNow=function(c){return this.to(d(this),c)},o.fromNow=function(c){return this.from(d(this),c)}}})})(Qw);const Uw=Xr;var Zr={},Xw={get exports(){return Zr},set exports(e){Zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={year:0,month:1,day:2,hour:3,minute:4,second:5},i={};return function(s,o,u){var l,d=function(h,m,w){w===void 0&&(w={});var C=new Date(h),S=function(I,$){$===void 0&&($={});var P=$.timeZoneName||"short",q=I+"|"+P,L=i[q];return L||(L=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:I,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:P}),i[q]=L),L}(m,w);return S.formatToParts(C)},c=function(h,m){for(var w=d(h,m),C=[],S=0;S<w.length;S+=1){var I=w[S],$=I.type,P=I.value,q=r[$];q>=0&&(C[q]=parseInt(P,10))}var L=C[3],z=L===24?0:L,A=C[0]+"-"+C[1]+"-"+C[2]+" "+z+":"+C[4]+":"+C[5]+":000",G=+h;return(u.utc(A).valueOf()-(G-=G%1e3))/6e4},f=o.prototype;f.tz=function(h,m){h===void 0&&(h=l);var w=this.utcOffset(),C=this.toDate(),S=C.toLocaleString("en-US",{timeZone:h}),I=Math.round((C-new Date(S))/1e3/60),$=u(S).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-I,!0);if(m){var P=$.utcOffset();$=$.add(w-P,"minute")}return $.$x.$timezone=h,$},f.offsetName=function(h){var m=this.$x.$timezone||u.tz.guess(),w=d(this.valueOf(),m,{timeZoneName:h}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var g=f.startOf;f.startOf=function(h,m){if(!this.$x||!this.$x.$timezone)return g.call(this,h,m);var w=u(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return g.call(w,h,m).tz(this.$x.$timezone,!0)},u.tz=function(h,m,w){var C=w&&m,S=w||m||l,I=c(+u(),S);if(typeof h!="string")return u(h).tz(S);var $=function(z,A,G){var U=z-60*A*1e3,Q=c(U,G);if(A===Q)return[U,A];var ne=c(U-=60*(Q-A)*1e3,G);return Q===ne?[U,Q]:[z-60*Math.min(Q,ne)*1e3,Math.max(Q,ne)]}(u.utc(h,C).valueOf(),I,S),P=$[0],q=$[1],L=u(P).utcOffset(q);return L.$x.$timezone=S,L},u.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},u.tz.setDefault=function(h){l=h}}})})(Xw);const Zw=Zr;var Kr={},Kw={get exports(){return Kr},set exports(e){Kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(Kw);const Jw=Kr;var Jr={},Hw={get exports(){return Jr},set exports(e){Jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(Hw);const e1=Jr;var Hr={},t1={get exports(){return Hr},set exports(e){Hr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.updateLocale=function(o,u){var l=s.Ls[o];if(l)return(u?Object.keys(u):[]).forEach(function(d){l[d]=u[d]}),l}}})})(t1);const n1=Hr;var ei={},r1={get exports(){return ei},set exports(e){ei=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="minute",i=/[+-]\d\d(?::?\d\d)?/g,s=/([+-]|\d\d)/g;return function(o,u,l){var d=u.prototype;l.utc=function(C){var S={date:C,utc:!0,args:arguments};return new u(S)},d.utc=function(C){var S=l(this.toDate(),{locale:this.$L,utc:!0});return C?S.add(this.utcOffset(),r):S},d.local=function(){return l(this.toDate(),{locale:this.$L,utc:!1})};var c=d.parse;d.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),c.call(this,C)};var f=d.init;d.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var g=d.utcOffset;d.utcOffset=function(C,S){var I=this.$utils().u;if(I(C))return this.$u?0:I(this.$offset)?g.call(this):this.$offset;if(typeof C=="string"&&(C=function(L){L===void 0&&(L="");var z=L.match(i);if(!z)return null;var A=(""+z[0]).match(s)||["-",0,0],G=A[0],U=60*+A[1]+ +A[2];return U===0?0:G==="+"?U:-U}(C),C===null))return this;var $=Math.abs(C)<=16?60*C:C,P=this;if(S)return P.$offset=$,P.$u=C===0,P;if(C!==0){var q=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(P=this.local().add($+q,r)).$offset=$,P.$x.$localOffset=q}else P=this.utc();return P};var h=d.format;d.format=function(C){var S=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,S)},d.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},d.isUTC=function(){return!!this.$u},d.toISOString=function(){return this.toDate().toISOString()},d.toString=function(){return this.toDate().toUTCString()};var m=d.toDate;d.toDate=function(C){return C==="s"&&this.$offset?l(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=d.diff;d.diff=function(C,S,I){if(C&&this.$u===C.$u)return w.call(this,C,S,I);var $=this.local(),P=l(C).local();return w.call($,P,S,I)}}})})(r1);const i1=ei;var ti={},a1={get exports(){return ti},set exports(e){ti=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekday=function(s){var o=this.$locale().weekStart||0,u=this.$W,l=(u<o?u+7:u)-o;return this.$utils().u(s)?l:this.subtract(l,"day").add(s,"day")}}})})(a1);const s1=ti;var ni={},o1={get exports(){return ni},set exports(e){ni=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="week",i="year";return function(s,o,u){var l=o.prototype;l.week=function(d){if(d===void 0&&(d=null),d!==null)return this.add(7*(d-this.week()),"day");var c=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=u(this).startOf(i).add(1,i).date(c),g=u(this).endOf(r);if(f.isBefore(g))return 1}var h=u(this).startOf(i).date(c).startOf(r).subtract(1,"millisecond"),m=this.diff(h,r,!0);return m<0?u(this).startOf("week").week():Math.ceil(m)},l.weeks=function(d){return d===void 0&&(d=null),this.week(d)}}})})(o1);const l1=ni;var ri={},u1={get exports(){return ri},set exports(e){ri=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekYear=function(){var s=this.month(),o=this.week(),u=this.year();return o===1&&s===11?u+1:s===0&&o>=52?u-1:u}}})})(u1);const d1=ri;j.extend(JC),j.extend(ew),j.extend(nw),j.extend(iw),j.extend(sw),j.extend(lw),j.extend(dw),j.extend(pw),j.extend(fw),j.extend(mw),j.extend(yw),j.extend(Sw),j.extend(kw),j.extend(Mw),j.extend(Aw),j.extend(zw),j.extend(xw),j.extend(ww),j.extend(Lw),j.extend(Ow),j.extend(Bw),j.extend(Gw),j.extend(Fw),j.extend(jw),j.extend(Yw),j.extend(Uw),j.extend(Zw),j.extend(Jw),j.extend(e1),j.extend(n1),j.extend(i1),j.extend(l1),j.extend(d1),j.extend(s1),j.tz.setDefault("UTC");const c1=()=>Promise.resolve().then(()=>il).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));D.ContentModel=It,D.ContentModelContextProvider=xn,D.ContextModel=xs,D.DashboardEditor=XC,D.DashboardFilterType=or,D.DashboardMode=Za,D.DashboardModel=As,D.DashboardViewEditor=Ja,D.DashboardViewRender=an,D.EViewComponentType=K,D.FilterModel=ur,D.FiltersModel=ds,D.FullScreenPanelContext=wn,D.LayoutStateContext=Ke,D.ModelContextProvider=vn,D.Panel=rn,D.PanelContextProvider=Cn,D.PanelModel=Cs,D.PanelsModel=_s,D.QueriesModel=bs,D.QueryModel=ms,D.ReadOnlyDashboard=ZC,D.SQLSnippetModel=ys,D.SQLSnippetsModel=vs,D.ViewComponentTypeBackground=Ka,D.ViewComponentTypeColor=Xy,D.ViewComponentTypeName=Uy,D.ViewModel=Ds,D.ViewsModel=Ms,D.applyPartialDashboard=ox,D.createContentModel=Is,D.createDashboardModel=gr,D.createDashboardViewsModel=fr,D.getInitialFiltersPayload=cs,D.getNewPanel=ws,D.getVersion=c1,D.initialDashboardContent=Zy,D.useContentModelContext=F,D.useFullScreenPanelContext=Oi,D.useModelContext=me,D.usePanelContext=Ce,D.useTopLevelServices=mr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|